Skip to content

Commit 3844c26

Browse files
devversionmmalerba
authored andcommitted
build: fix failing nightly snapshot tests (#14395)
* build: fix failing nightly snapshot tests * Fix comment typos
1 parent 733c8ee commit 3844c26

File tree

3 files changed

+61
-17
lines changed

3 files changed

+61
-17
lines changed

.circleci/config.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ jobs:
279279
- *restore_cache
280280
- *yarn_install
281281

282-
- run: ./scripts/install-angular-snapshots.sh
282+
- run: node ./scripts/circleci/setup-angular-snapshots.js
283283
- run: ./scripts/circleci/run-local-browser-tests.sh
284284

285285
# ----------------------------------------------------------------------------------------
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/**
2+
* Script that sets up the Angular snapshot github builds. We set up the snapshot builds by
3+
* overwriting the versions in the "package.json" and taking advantage of Yarn's resolutions
4+
* feature. Yarn resolutions will be used to flatten nested Angular packages because by default
5+
* Yarn does not flatten any dependency. See:
6+
*
7+
* node_modules/compiler@snapshot
8+
* node_modules/compiler-cli@snapshot
9+
* node_modules/[email protected]
10+
*
11+
* Note that we cannot just use Yarn's `--flat` option because that would mean that it tries
12+
* to flatten **all** dependencies and could cause unexpected results. We **only** want to
13+
* explicitly flatten out all `@angular/*` dependencies. This can be achieved with resolutions.
14+
* Read more here: https://yarnpkg.com/lang/en/docs/package-json/#toc-resolutions
15+
*/
16+
17+
const {yellow, green} = require('chalk');
18+
const {writeFileSync} = require('fs');
19+
const {join} = require('path');
20+
const {execSync} = require('child_process');
21+
22+
const projectDir = join(__dirname, '../../');
23+
const packageJsonPath = join(projectDir, 'package.json');
24+
const packageJson = require(packageJsonPath);
25+
26+
// Initialize the "resolutions" property in case it is not present in the "package.json" yet.
27+
// See: https://yarnpkg.com/lang/en/docs/package-json/#toc-resolutions for the API.
28+
packageJson['resolutions'] = packageJson['resolutions'] || {};
29+
30+
// List that contains the names of all installed Angular packages (e.g. "@angular/core")
31+
const angularPackages = Object.keys({...packageJson.dependencies, ...packageJson.devDependencies})
32+
.filter(packageName => packageName.startsWith('@angular/'));
33+
34+
console.log(green('Setting up snapshot builds for:\n'));
35+
console.log(yellow(` ${angularPackages.join('\n ')}\n`));
36+
37+
// Setup the snapshot version for each Angular package specified in the "package.json" file.
38+
angularPackages.forEach(packageName => {
39+
const buildsUrl = `github:angular/${packageName.split('/')[1]}-builds`;
40+
// Add resolutions for each package in the format "**/{PACKAGE}" so that all
41+
// nested versions of that specific Angular package will have the same version.
42+
packageJson.resolutions[`**/${packageName}`] = buildsUrl;
43+
44+
// Since the resolutions only cover the version of all nested installs, we also need
45+
// to explicitly set the version for the package listed in the project "package.json".
46+
packageJson.dependencies[packageName] = buildsUrl;
47+
48+
// In case this dependency was previously a dev dependency, just remove it because we
49+
// re-added it as a normal dependency for simplicity.
50+
delete packageJson.devDependencies[packageName];
51+
});
52+
53+
// Write changes to the "packageJson", so that we can install the new versions afterwards.
54+
writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2));
55+
56+
console.log(green('Successfully added the "resolutions" to the "package.json".'));
57+
58+
// Run "yarn" in the directory that contains the "package.json". Also pipe all output to the
59+
// current process so that everything can be debugged within CircleCI.
60+
execSync('yarn', {cwd: projectDir, stdio: 'inherit', shell: true});

scripts/install-angular-snapshots.sh

Lines changed: 0 additions & 16 deletions
This file was deleted.

0 commit comments

Comments
 (0)