Skip to content

Commit 7d832ae

Browse files
gkalpakatscott
authored andcommitted
build(docs-infra): use local version of Zone.js when testing against local packages (#35780)
In some cases, we want to test the AIO app or docs examples against the locally built Angular packages (for example to ensure that the changes in a commit do not introduce a breaking change). In order to achieve this, we have the `ng-packages-installer` script that handles updating a project's `package.json` file to use the locally built Angular packages (and appropriate versions for their (dev-/peer-)dependencies). Previously, `ng-packages-installer` would only consider the locally built Angular packages (from `dist/packages-dist/`). However, given that Zone.js is now part of the `angular/angular` repo, it makes sense to also use the locally built Zone.js package (from `dist/zone.js-dist/`). Otherwise, the tests might fail for commits that update both the Angular packages (and related docs examples) and the Zone.js package. An example of such a simultaneous change (that would have broken tests) is #33838. This commit updates the script to install the locally built Zone.js package (in addition to the Angular ones). The commit ensures that the Zone.js package will always be available alongside the Angular packages (i.e. that the Zone.js package will be built by the same script that builds the Angular packages and that the `dist/zone.js-dist/` directory will be cached on CI). Note: This problem was discovered while enabling docs examples unit tests in #34374. PR Close #35780
1 parent 4c7d833 commit 7d832ae

4 files changed

Lines changed: 120 additions & 70 deletions

File tree

.circleci/config.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -552,6 +552,7 @@ jobs:
552552
root: *workspace_location
553553
paths:
554554
- ng/dist/packages-dist-ivy-aot
555+
- ng/dist/zone.js-dist
555556

556557
# We run a subset of the integration tests outside of Bazel that track
557558
# payload size.

aio/tools/ng-packages-installer/index.js

Lines changed: 29 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,12 @@ const LOCAL_MARKER_PATH = 'node_modules/_local_.json';
1414

1515
const ANGULAR_ROOT_DIR = path.resolve(__dirname, '../../..');
1616
const ANGULAR_DIST_PACKAGES_DIR = path.join(ANGULAR_ROOT_DIR, 'dist/packages-dist');
17+
const ZONEJS_DIST_PACKAGES_DIR = path.join(ANGULAR_ROOT_DIR, 'dist/zone.js-dist');
1718
const DIST_PACKAGES_BUILD_SCRIPT = path.join(ANGULAR_ROOT_DIR, 'scripts/build/build-packages-dist.js');
1819
const DIST_PACKAGES_BUILD_CMD = `"${process.execPath}" "${DIST_PACKAGES_BUILD_SCRIPT}"`;
1920

2021
/**
21-
* A tool that can install Angular dependencies for a project from NPM or from the
22+
* A tool that can install Angular/Zone.js dependencies for a project from NPM or from the
2223
* locally built distributables.
2324
*
2425
* This tool is used to change dependencies of the `aio` application and the example
@@ -33,7 +34,7 @@ class NgPackagesInstaller {
3334
* @param {object} options - a hash of options for the install:
3435
* * `debug` (`boolean`) - whether to display debug messages.
3536
* * `force` (`boolean`) - whether to force a local installation even if there is a local marker file.
36-
* * `buildPackages` (`boolean`) - whether to build the local Angular packages before using them.
37+
* * `buildPackages` (`boolean`) - whether to build the local Angular/Zone.js packages before using them.
3738
* (NOTE: Building the packages is currently not supported on Windows, so a message is printed instead.)
3839
* * `ignorePackages` (`string[]`) - a collection of names of packages that should not be copied over.
3940
*/
@@ -52,7 +53,7 @@ class NgPackagesInstaller {
5253

5354
/**
5455
* Check whether the dependencies have been overridden with locally built
55-
* Angular packages. This is done by checking for the `_local_.json` marker file.
56+
* Angular/Zone.js packages. This is done by checking for the `_local_.json` marker file.
5657
* This will emit a warning to the console if the dependencies have been overridden.
5758
*/
5859
checkDependencies() {
@@ -62,8 +63,8 @@ class NgPackagesInstaller {
6263
}
6364

6465
/**
65-
* Install locally built Angular dependencies, overriding the dependencies in the package.json
66-
* This will also write a "marker" file (`_local_.json`), which contains the overridden package.json
66+
* Install locally built Angular/Zone.js dependencies, overriding the dependencies in the `package.json`.
67+
* This will also write a "marker" file (`_local_.json`), which contains the overridden `package.json`
6768
* contents and acts as an indicator that dependencies have been overridden.
6869
*/
6970
installLocalDependencies() {
@@ -86,13 +87,13 @@ class NgPackagesInstaller {
8687
// Prevent accidental publishing of the package, if something goes wrong.
8788
tmpConfig.private = true;
8889

89-
// Overwrite project dependencies/devDependencies to Angular packages with local files.
90+
// Overwrite project dependencies/devDependencies to Angular/Zone.js packages with local files.
9091
['dependencies', 'devDependencies'].forEach(prop => {
9192
const deps = tmpConfig[prop] || {};
9293
Object.keys(deps).forEach(key2 => {
9394
const pkg2 = packages[key2];
9495
if (pkg2) {
95-
// point the core Angular packages at the distributable folder
96+
// point the local packages at the distributable folder
9697
deps[key2] = `file:${pkg2.packageDir}`;
9798
this._log(`Overriding dependency of local ${key} with local package: ${key2}: ${deps[key2]}`);
9899
}
@@ -125,8 +126,8 @@ class NgPackagesInstaller {
125126
fs.writeFileSync(pathToPackageConfig, packageConfigFile);
126127
}
127128
} finally {
128-
// Restore local Angular packages dependencies to other Angular packages.
129-
this._log(`Restoring original ${PACKAGE_JSON} for local Angular packages.`);
129+
// Restore local Angular/Zone.js packages dependencies to other Angular packages.
130+
this._log(`Restoring original ${PACKAGE_JSON} for local packages.`);
130131
Object.keys(packages).forEach(key => {
131132
const pkg = packages[key];
132133
fs.writeFileSync(pkg.packageJsonPath, JSON.stringify(pkg.config, null, 2));
@@ -167,7 +168,7 @@ class NgPackagesInstaller {
167168
}
168169

169170
/**
170-
* Build the local Angular packages.
171+
* Build the local Angular/Zone.js packages.
171172
*
172173
* NOTE:
173174
* Building the packages is currently not supported on Windows, so a message is printed instead, prompting the user to
@@ -177,14 +178,14 @@ class NgPackagesInstaller {
177178
const canBuild = process.platform !== 'win32';
178179

179180
if (canBuild) {
180-
this._log(`Building the Angular packages with: ${DIST_PACKAGES_BUILD_SCRIPT}`);
181+
this._log(`Building the local packages with: ${DIST_PACKAGES_BUILD_SCRIPT}`);
181182
shelljs.exec(DIST_PACKAGES_BUILD_CMD);
182183
} else {
183184
this._warn([
184-
'Automatically building the local Angular packages is currently not supported on Windows.',
185-
`Please, ensure '${ANGULAR_DIST_PACKAGES_DIR}' exists and is up-to-date (e.g. by running ` +
186-
`'${DIST_PACKAGES_BUILD_SCRIPT}' in Git Bash for Windows, Windows Subsystem for Linux or a Linux docker ` +
187-
'container or VM).',
185+
'Automatically building the local Angular/Zone.js packages is currently not supported on Windows.',
186+
`Please, ensure '${ANGULAR_DIST_PACKAGES_DIR}' and '${ZONEJS_DIST_PACKAGES_DIR}' exist and are up-to-date ` +
187+
`(e.g. by running '${DIST_PACKAGES_BUILD_SCRIPT}' in Git Bash for Windows, Windows Subsystem for Linux or ` +
188+
'a Linux docker container or VM).',
188189
'',
189190
'Proceeding anyway...',
190191
].join('\n'));
@@ -204,7 +205,7 @@ class NgPackagesInstaller {
204205
// grab peer dependencies
205206
const sourcePackagePeerDeps = sourcePackage.config.peerDependencies || {};
206207
Object.keys(sourcePackagePeerDeps)
207-
// ignore peerDependencies which are already core Angular packages
208+
// ignore peerDependencies which are already core Angular/Zone.js packages
208209
.filter(key => !packages[key])
209210
.forEach(key => peerDependencies[key] = sourcePackagePeerDeps[key]);
210211
}
@@ -214,11 +215,13 @@ class NgPackagesInstaller {
214215
}
215216

216217
/**
217-
* A hash of Angular package configs.
218-
* (Detected as directories in '/dist/packages-dist/' that contain a top-level 'package.json' file.)
218+
* A hash of Angular/Zone.js package configs.
219+
* (Detected as directories in '/dist/packages-dist/' and '/dist/zone.js-dist/' that contain a top-level
220+
* 'package.json' file.)
219221
*/
220222
_getDistPackages() {
221223
this._log(`Angular distributable directory: ${ANGULAR_DIST_PACKAGES_DIR}.`);
224+
this._log(`Zone.js distributable directory: ${ZONEJS_DIST_PACKAGES_DIR}.`);
222225

223226
if (this.buildPackages) {
224227
this._buildDistPackages();
@@ -254,7 +257,10 @@ class NgPackagesInstaller {
254257
return packages;
255258
};
256259

257-
const packageConfigs = collectPackages(ANGULAR_DIST_PACKAGES_DIR);
260+
const packageConfigs = {
261+
...collectPackages(ANGULAR_DIST_PACKAGES_DIR),
262+
...collectPackages(ZONEJS_DIST_PACKAGES_DIR),
263+
};
258264

259265
this._log('Found the following Angular distributables:', Object.keys(packageConfigs).map(key => `\n - ${key}`));
260266
return packageConfigs;
@@ -343,7 +349,7 @@ class NgPackagesInstaller {
343349

344350
// Log a warning.
345351
this._warn([
346-
`The project at "${absoluteProjectDir}" is running against the local Angular build.`,
352+
`The project at "${absoluteProjectDir}" is running against the local Angular/Zone.js build.`,
347353
'',
348354
'To restore the npm packages run:',
349355
'',
@@ -396,10 +402,10 @@ function main() {
396402

397403
.option('debug', { describe: 'Print additional debug information.', default: false })
398404
.option('force', { describe: 'Force the command to execute even if not needed.', default: false })
399-
.option('build-packages', { describe: 'Build the local Angular packages, before using them.', default: false })
400-
.option('ignore-packages', { describe: 'List of Angular packages that should not be used in local mode.', default: [], array: true })
405+
.option('build-packages', { describe: 'Build the local Angular/Zone.js packages, before using them.', default: false })
406+
.option('ignore-packages', { describe: 'List of Angular/Zone.js packages that should not be used in local mode.', default: [], array: true })
401407

402-
.command('overwrite <projectDir> [--force] [--debug] [--ignore-packages package1 package2]', 'Install dependencies from the locally built Angular distributables.', () => {}, argv => {
408+
.command('overwrite <projectDir> [--force] [--debug] [--ignore-packages package1 package2]', 'Install dependencies from the locally built Angular/Zone.js distributables.', () => {}, argv => {
403409
createInstaller(argv).installLocalDependencies();
404410
})
405411
.command('restore <projectDir> [--debug]', 'Install dependencies from the npm registry.', () => {}, argv => {

0 commit comments

Comments
 (0)