From 1ac58371938ea9d183be8386b15d79d360960861 Mon Sep 17 00:00:00 2001 From: Paul Gschwendtner Date: Wed, 11 Mar 2020 10:33:28 +0100 Subject: [PATCH] build: add release output validation for manifest paths Ensures that https://github.com/angular/angular/commit/9581658 fixed all instances, and ensures that we don't regress on the components side. --- tools/release/release-output/check-package.ts | 12 ++++++------ .../release-output/output-validations.ts | 19 +++++++++++++------ 2 files changed, 19 insertions(+), 12 deletions(-) diff --git a/tools/release/release-output/check-package.ts b/tools/release/release-output/check-package.ts index 03a5499467e7..ecdee31ef7ab 100644 --- a/tools/release/release-output/check-package.ts +++ b/tools/release/release-output/check-package.ts @@ -9,12 +9,12 @@ import { checkMaterialPackage, checkPackageJsonFile, checkPackageJsonMigrations, - checkReleaseBundle, + checkJavaScriptOutput, checkTypeDefinitionFile } from './output-validations'; -/** Glob that matches all JavaScript bundle files within a release package. */ -const releaseBundlesGlob = '+(fesm5|fesm2015|esm5|esm2015|bundles)/*.js'; +/** Glob that matches all JavaScript files within a release package. */ +const releaseJsFilesGlob = '+(fesm5|fesm2015|esm5|esm2015|bundles)/**/*.js'; /** Glob that matches all TypeScript definition files within a release package. */ const releaseTypeDefinitionsGlob = '**/*.d.ts'; @@ -46,14 +46,14 @@ export function checkReleasePackage( failures.set(message, filePaths); }; - const bundlePaths = glob(releaseBundlesGlob, {cwd: packagePath, absolute: true}); + const jsFiles = glob(releaseJsFilesGlob, {cwd: packagePath, absolute: true}); const typeDefinitions = glob(releaseTypeDefinitionsGlob, {cwd: packagePath, absolute: true}); const packageJsonFiles = glob(packageJsonFilesGlob, {cwd: packagePath, absolute: true}); // We want to walk through each bundle within the current package and run // release validations that ensure that the bundles are not invalid. - bundlePaths.forEach(bundlePath => { - checkReleaseBundle(bundlePath).forEach(message => addFailure(message, bundlePath)); + jsFiles.forEach(bundlePath => { + checkJavaScriptOutput(bundlePath).forEach(message => addFailure(message, bundlePath)); }); // Run output validations for all TypeScript definition files within the release output. diff --git a/tools/release/release-output/output-validations.ts b/tools/release/release-output/output-validations.ts index ba7ffb4bed73..8425460f5943 100644 --- a/tools/release/release-output/output-validations.ts +++ b/tools/release/release-output/output-validations.ts @@ -11,6 +11,9 @@ const inlineStylesSourcemapRegex = /styles: ?\[["'].*sourceMappingURL=.*["']/; /** RegExp that matches Angular component metadata properties that refer to external resources. */ const externalReferencesRegex = /(templateUrl|styleUrls): *["'[]/; +/** RegExp that matches common Bazel manifest paths in this workspace */ +const bazelManifestPath = /(angular_material|external)\//; + /** * List of fields which are mandatory in entry-point "package.json" files and refer * to files in the release output. @@ -19,21 +22,25 @@ const packageJsonPathFields = ['main', 'module', 'typings', 'es2015', 'fesm5', 'fesm2015', 'esm5', 'esm2015']; /** - * Checks the specified release bundle and ensures that it does not contain - * any external resource URLs. + * Checks the specified JavaScript file and ensures that it does not + * contain any external resource URLs, or Bazel manifest paths. */ -export function checkReleaseBundle(bundlePath: string): string[] { - const bundleContent = readFileSync(bundlePath, 'utf8'); +export function checkJavaScriptOutput(filePath: string): string[] { + const fileContent = readFileSync(filePath, 'utf8'); const failures: string[] = []; - if (inlineStylesSourcemapRegex.exec(bundleContent) !== null) { + if (inlineStylesSourcemapRegex.exec(fileContent) !== null) { failures.push('Found sourcemap references in component styles.'); } - if (externalReferencesRegex.exec(bundleContent) !== null) { + if (externalReferencesRegex.exec(fileContent) !== null) { failures.push('Found external component resource references'); } + if (bazelManifestPath.exec(fileContent) !== null) { + failures.push('Found Bazel manifest path in output.'); + } + return failures; }