Skip to content

Commit 60eec6c

Browse files
committed
build: fix failing nightly snapshot tests
1 parent 74e945a commit 60eec6c

File tree

3 files changed

+62
-17
lines changed

3 files changed

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