Skip to content

Commit

Permalink
build: add release output validation for manifest paths
Browse files Browse the repository at this point in the history
Ensures that angular/angular@9581658 fixed all instances, and
ensures that we don't regress on the components side.
  • Loading branch information
devversion committed Mar 12, 2020
1 parent ceab335 commit 1ac5837
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 12 deletions.
12 changes: 6 additions & 6 deletions tools/release/release-output/check-package.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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.
Expand Down
19 changes: 13 additions & 6 deletions tools/release/release-output/output-validations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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;
}

Expand Down

0 comments on commit 1ac5837

Please sign in to comment.