Skip to content

Commit bcd9f63

Browse files
devversionmmalerba
authored andcommitted
build: ensure project version is set correctly in NPM package output (#19841)
In framework, the version placeholder computation was incorrect in some situations. i.e. the release packages used a version that indicates local changes like `x.x.x-local-changes`. We should ensure that the release output matches the expected version. This is especially becoming relevant when we switch to a shared Bazel workspace status command from the dev-infra package. The workspace status command is responsible for determining the version placeholder value when building with `--config=release`.
1 parent cbefab2 commit bcd9f63

File tree

2 files changed

+33
-9
lines changed

2 files changed

+33
-9
lines changed

tools/release/release-output/check-package.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ import {Version} from '../version-name/parse-version';
66

77
import {
88
checkCdkPackage,
9-
checkMaterialPackage,
10-
checkPackageJsonFile,
11-
checkPackageJsonMigrations,
9+
checkEntryPointPackageJsonFile,
1210
checkJavaScriptOutput,
11+
checkMaterialPackage,
12+
checkPrimaryPackageJson,
1313
checkTypeDefinitionFile
1414
} from './output-validations';
1515

@@ -64,7 +64,7 @@ export function checkReleasePackage(
6464
// Check each "package.json" file in the release output. We want to ensure
6565
// that there are no invalid file references in the entry-point definitions.
6666
packageJsonFiles.forEach(filePath => {
67-
checkPackageJsonFile(filePath).forEach(message => addFailure(message, filePath));
67+
checkEntryPointPackageJsonFile(filePath).forEach(message => addFailure(message, filePath));
6868
});
6969

7070
// Special release validation checks for the "material" release package.
@@ -82,7 +82,7 @@ export function checkReleasePackage(
8282
addFailure('No "README.md" file found in package output.');
8383
}
8484

85-
checkPackageJsonMigrations(join(packagePath, 'package.json'), currentVersion)
85+
checkPrimaryPackageJson(join(packagePath, 'package.json'), currentVersion)
8686
.forEach(f => addFailure(f));
8787

8888
// In case there are failures for this package, we want to print those

tools/release/release-output/output-validations.ts

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@ const bazelManifestPath = /(angular_material|external)\//;
1818
* List of fields which are mandatory in entry-point "package.json" files and refer
1919
* to files in the release output.
2020
*/
21-
const packageJsonPathFields =
22-
['main', 'module', 'typings', 'es2015', 'fesm2015', 'esm2015'];
21+
const packageJsonPathFields = ['main', 'module', 'typings', 'es2015', 'fesm2015', 'esm2015'];
2322

2423
/**
2524
* Checks the specified JavaScript file and ensures that it does not
@@ -45,11 +44,11 @@ export function checkJavaScriptOutput(filePath: string): string[] {
4544
}
4645

4746
/**
48-
* Checks a "package.json" file by ensuring that common fields which are
47+
* Checks an entry-point "package.json" file by ensuring that common fields which are
4948
* specified in the Angular package format are present. Those fields which
5049
* resolve to paths are checked so that they do not refer to non-existent files.
5150
*/
52-
export function checkPackageJsonFile(filePath: string): string[] {
51+
export function checkEntryPointPackageJsonFile(filePath: string): string[] {
5352
const fileContent = readFileSync(filePath, 'utf8');
5453
const parsed = JSON.parse(fileContent);
5554
const packageJsonDir = dirname(filePath);
@@ -111,6 +110,31 @@ export function checkTypeDefinitionFile(filePath: string): string[] {
111110
return failures;
112111
}
113112

113+
/**
114+
* Checks the primary `package.json` file of a release package. Currently we ensure
115+
* that the version and migrations are set up correctly.
116+
*/
117+
export function checkPrimaryPackageJson(
118+
packageJsonPath: string, currentVersion: Version): string[] {
119+
const expectedVersion = currentVersion.format();
120+
const packageJson = JSON.parse(readFileSync(packageJsonPath, 'utf8'));
121+
const failures: string[] = [];
122+
123+
if (!packageJson.version) {
124+
failures.push(`No version set. Expected: ${expectedVersion}`);
125+
} else if (packageJson.version !== expectedVersion) {
126+
failures.push(
127+
`Unexpected package version. Expected: ${expectedVersion} but got: ${packageJson.version}`);
128+
}
129+
130+
if (packageJson['ng-update'] && packageJson['ng-update'].migrations) {
131+
failures.push(...checkMigrationCollection(
132+
packageJson['ng-update'].migrations, dirname(packageJsonPath), currentVersion));
133+
}
134+
135+
return failures;
136+
}
137+
114138
/**
115139
* Checks the ng-update migration setup for the specified "package.json"
116140
* file if present.

0 commit comments

Comments
 (0)