Skip to content

Commit 98d0326

Browse files
devversionjelbourn
authored andcommitted
build: setup primary entry-point package.json files to match release output
The primary entry-point `package.json` files are not generated by the `ng_package` bazel rule. This is by intention because it does not try to overwrite existing `package.json` files in the release output (i.e. to preserve placeholders; dependencies etc.) We need to update the `package.json` fields to match the new release output that is generated by Bazel. Also adds a new release output validation that ensures that those fields in the `package.json` files are resolving to existing files.
1 parent 0fd5afa commit 98d0326

File tree

10 files changed

+103
-29
lines changed

10 files changed

+103
-29
lines changed

src/cdk-experimental/package.json

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,13 @@
33
"version": "0.0.0-PLACEHOLDER",
44
"description": "Experimental components for Angular CDK",
55
"main": "./bundles/cdk-experimental.umd.js",
6-
"module": "./esm5/cdk-experimental.es5.js",
7-
"es2015": "./esm2015/cdk-experimental.js",
8-
"typings": "./cdk-experimental.d.ts",
6+
"fesm5": "./fesm5/cdk-experimental.js",
7+
"fesm2015": "./fesm2015/cdk-experimental.js",
8+
"esm5": "./esm5/cdk-experimental_public_index.js",
9+
"esm2015": "./esm2015/cdk-experimental_public_index.js",
10+
"typings": "./cdk-experimental_public_index.d.ts",
11+
"module": "./fesm5/cdk-experimental.js",
12+
"es2015": "./fesm2015/cdk-experimental.js",
913
"repository": {
1014
"type": "git",
1115
"url": "https://github.com/angular/components.git"

src/cdk/package.json

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,13 @@
33
"version": "0.0.0-PLACEHOLDER",
44
"description": "Angular Material Component Development Kit",
55
"main": "./bundles/cdk.umd.js",
6-
"module": "./esm5/cdk.es5.js",
7-
"es2015": "./esm2015/cdk.js",
8-
"typings": "./cdk.d.ts",
6+
"fesm5": "./fesm5/cdk.js",
7+
"fesm2015": "./fesm2015/cdk.js",
8+
"esm5": "./esm5/cdk_public_index.js",
9+
"esm2015": "./esm2015/cdk_public_index.js",
10+
"typings": "./cdk_public_index.d.ts",
11+
"module": "./fesm5/cdk.js",
12+
"es2015": "./fesm2015/cdk.js",
913
"repository": {
1014
"type": "git",
1115
"url": "https://github.com/angular/components.git"

src/google-maps/package.json

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,13 @@
33
"version": "0.0.0-PLACEHOLDER",
44
"description": "Angular Google Maps",
55
"main": "./bundles/google-maps.umd.js",
6-
"module": "./esm5/google-maps.es5.js",
7-
"es2015": "./esm2015/google-maps.js",
8-
"typings": "./google-maps.d.ts",
6+
"fesm5": "./fesm5/google-maps.js",
7+
"fesm2015": "./fesm2015/google-maps.js",
8+
"esm5": "./esm5/google-maps_public_index.js",
9+
"esm2015": "./esm2015/google-maps_public_index.js",
10+
"typings": "./google-maps_public_index.d.ts",
11+
"module": "./fesm5/google-maps.js",
12+
"es2015": "./fesm2015/google-maps.js",
913
"repository": {
1014
"type": "git",
1115
"url": "https://github.com/angular/components.git"

src/material-examples/package.json

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,13 @@
33
"version": "0.0.0-PLACEHOLDER",
44
"description": "Angular Material Examples",
55
"main": "./bundles/material-examples.umd.js",
6-
"module": "./esm5/material-examples.es5.js",
7-
"es2015": "./esm2015/material-examples.js",
8-
"typings": "./material-examples.d.ts",
6+
"fesm5": "./fesm5/material-examples.js",
7+
"fesm2015": "./fesm2015/material-examples.js",
8+
"esm5": "./esm5/material-examples_public_index.js",
9+
"esm2015": "./esm2015/material-examples_public_index.js",
10+
"typings": "./material-examples_public_index.d.ts",
11+
"module": "./fesm5/material-examples.js",
12+
"es2015": "./fesm2015/material-examples.js",
913
"private": true,
1014
"repository": {
1115
"type": "git",

src/material-experimental/package.json

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,13 @@
33
"version": "0.0.0-PLACEHOLDER",
44
"description": "Experimental components for Angular Material",
55
"main": "./bundles/material-experimental.umd.js",
6-
"module": "./esm5/material-experimental.es5.js",
7-
"es2015": "./esm2015/material-experimental.js",
8-
"typings": "./material-experimental.d.ts",
6+
"fesm5": "./fesm5/material-experimental.js",
7+
"fesm2015": "./fesm2015/material-experimental.js",
8+
"esm5": "./esm5/material-experimental_public_index.js",
9+
"esm2015": "./esm2015/material-experimental_public_index.js",
10+
"typings": "./material-experimental_public_index.d.ts",
11+
"module": "./fesm5/material-experimental.js",
12+
"es2015": "./fesm2015/material-experimental.js",
913
"repository": {
1014
"type": "git",
1115
"url": "https://github.com/angular/components.git"

src/material-moment-adapter/package.json

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,13 @@
33
"version": "0.0.0-PLACEHOLDER",
44
"description": "Angular Material Moment Adapter",
55
"main": "./bundles/material-moment-adapter.umd.js",
6-
"module": "./esm5/material-moment-adapter.es5.js",
7-
"es2015": "./esm2015/material-moment-adapter.js",
8-
"typings": "./material-moment-adapter.d.ts",
6+
"fesm5": "./fesm5/material-moment-adapter.js",
7+
"fesm2015": "./fesm2015/material-moment-adapter.js",
8+
"esm5": "./esm5/material-moment-adapter_public_index.js",
9+
"esm2015": "./esm2015/material-moment-adapter_public_index.js",
10+
"typings": "./material-moment-adapter_public_index.d.ts",
11+
"module": "./fesm5/material-moment-adapter.js",
12+
"es2015": "./fesm2015/material-moment-adapter.js",
913
"repository": {
1014
"type": "git",
1115
"url": "https://github.com/angular/components.git"

src/material/package.json

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,13 @@
33
"version": "0.0.0-PLACEHOLDER",
44
"description": "Angular Material",
55
"main": "./bundles/material.umd.js",
6-
"module": "./esm5/material.es5.js",
7-
"es2015": "./esm2015/material.js",
8-
"typings": "./material.d.ts",
6+
"fesm5": "./fesm5/material.js",
7+
"fesm2015": "./fesm2015/material.js",
8+
"esm5": "./esm5/index.js",
9+
"esm2015": "./esm2015/index.js",
10+
"typings": "./index.d.ts",
11+
"module": "./fesm5/material.js",
12+
"es2015": "./fesm2015/material.js",
913
"repository": {
1014
"type": "git",
1115
"url": "https://github.com/angular/components.git"

src/youtube-player/package.json

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,13 @@
33
"version": "0.0.0-PLACEHOLDER",
44
"description": "Angular YouTube Player",
55
"main": "./bundles/youtube-player.umd.js",
6-
"module": "./esm5/youtube-player.es5.js",
7-
"es2015": "./esm2015/youtube-player.js",
8-
"typings": "./youtube-player.d.ts",
6+
"fesm5": "./fesm5/youtube-player.js",
7+
"fesm2015": "./fesm2015/youtube-player.js",
8+
"esm5": "./esm5/youtube-player_public_index.js",
9+
"esm2015": "./esm2015/youtube-player_public_index.js",
10+
"typings": "./youtube-player_public_index.d.ts",
11+
"module": "./fesm5/youtube-player.js",
12+
"es2015": "./fesm2015/youtube-player.js",
913
"repository": {
1014
"type": "git",
1115
"url": "https://github.com/angular/components.git"

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

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {join} from 'path';
66
import {
77
checkCdkPackage,
88
checkMaterialPackage,
9+
checkPackageJsonFile,
910
checkReleaseBundle,
1011
checkTypeDefinitionFile
1112
} from './output-validations';
@@ -16,6 +17,9 @@ const releaseBundlesGlob = '+(fesm5|fesm2015|esm5|esm2015|bundles)/*.js';
1617
/** Glob that matches all TypeScript definition files within a release package. */
1718
const releaseTypeDefinitionsGlob = '**/*.d.ts';
1819

20+
/** Glob that matches all "package.json" files within a release package. */
21+
const packageJsonFilesGlob = '**/package.json';
22+
1923
/**
2024
* Type that describes a map of package failures. The keys are failure messages and
2125
* their value is an array of specifically affected files.
@@ -41,18 +45,23 @@ export function checkReleasePackage(releasesPath: string, packageName: string):
4145

4246
const bundlePaths = glob(releaseBundlesGlob, {cwd: packagePath, absolute: true});
4347
const typeDefinitions = glob(releaseTypeDefinitionsGlob, {cwd: packagePath, absolute: true});
48+
const packageJsonFiles = glob(packageJsonFilesGlob, {cwd: packagePath, absolute: true});
4449

4550
// We want to walk through each bundle within the current package and run
4651
// release validations that ensure that the bundles are not invalid.
4752
bundlePaths.forEach(bundlePath => {
48-
checkReleaseBundle(bundlePath)
49-
.forEach(message => addFailure(message, bundlePath));
53+
checkReleaseBundle(bundlePath).forEach(message => addFailure(message, bundlePath));
5054
});
5155

5256
// Run output validations for all TypeScript definition files within the release output.
5357
typeDefinitions.forEach(filePath => {
54-
checkTypeDefinitionFile(filePath)
55-
.forEach(message => addFailure(message, filePath));
58+
checkTypeDefinitionFile(filePath).forEach(message => addFailure(message, filePath));
59+
});
60+
61+
// Check each "package.json" file in the release output. We want to ensure
62+
// that there are no invalid file references in the entry-point definitions.
63+
packageJsonFiles.forEach(filePath => {
64+
checkPackageJsonFile(filePath).forEach(message => addFailure(message, filePath));
5665
});
5766

5867
// Special release validation checks for the "material" release package.

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

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import {existsSync, readFileSync} from 'fs';
22
import {sync as glob} from 'glob';
3-
import {dirname, isAbsolute, join, basename} from 'path';
3+
import {basename, dirname, isAbsolute, join} from 'path';
44
import * as ts from 'typescript';
55

66
/** RegExp that matches Angular component inline styles that contain a sourcemap reference. */
@@ -9,6 +9,13 @@ const inlineStylesSourcemapRegex = /styles: ?\[["'].*sourceMappingURL=.*["']/;
99
/** RegExp that matches Angular component metadata properties that refer to external resources. */
1010
const externalReferencesRegex = /(templateUrl|styleUrls): *["'[]/;
1111

12+
/**
13+
* List of fields which are mandatory in entry-point "package.json" files and refer
14+
* to files in the release output.
15+
*/
16+
const packageJsonPathFields =
17+
['main', 'module', 'typings', 'es2015', 'fesm5', 'fesm2015', 'esm5', 'esm2015'];
18+
1219
/**
1320
* Checks the specified release bundle and ensures that it does not contain
1421
* any external resource URLs.
@@ -30,6 +37,32 @@ export function checkReleaseBundle(bundlePath: string): string[] {
3037
return failures;
3138
}
3239

40+
/**
41+
* Checks a "package.json" file by ensuring that common fields which are
42+
* specified in the Angular package format are present. Those fields which
43+
* resolve to paths are checked so that they do not refer to non-existent files.
44+
*/
45+
export function checkPackageJsonFile(filePath: string): string[] {
46+
const fileContent = readFileSync(filePath, 'utf8');
47+
const parsed = JSON.parse(fileContent);
48+
const packageJsonDir = dirname(filePath);
49+
const failures: string[] = [];
50+
51+
packageJsonPathFields.forEach(fieldName => {
52+
if (!parsed[fieldName]) {
53+
failures.push(`Missing field: ${fieldName}`);
54+
}
55+
56+
const resolvedPath = join(packageJsonDir, parsed[fieldName]);
57+
58+
if (!existsSync(resolvedPath)) {
59+
failures.push(`File referenced in "${fieldName}" field does not exist.`);
60+
}
61+
});
62+
63+
return failures;
64+
}
65+
3366
/**
3467
* Checks the specified TypeScript definition file by ensuring it does not contain invalid
3568
* dynamic import statements. There can be invalid type imports paths because we compose the

0 commit comments

Comments
 (0)