Skip to content

Commit 72a07fc

Browse files
devversionandrewseguin
authored andcommitted
build: install snapshot builds for angular-devkit and schematics (#24458)
* build: install snapshot builds for angular-devkit and schematics Our snapshot build jobs should also install the snapshots for the devkit and schematics packages (owned by the tooling team). These need to match up with the CLI package that is currently already updated by the snapshot setup script. * fixup! build: install snapshot builds for angular-devkit and schematics Make code a little more readable (cherry picked from commit 1c44c17)
1 parent 652b6ee commit 72a07fc

File tree

1 file changed

+36
-12
lines changed

1 file changed

+36
-12
lines changed

scripts/circleci/setup-angular-snapshots.js

Lines changed: 36 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,18 @@
1414
* Read more here: https://yarnpkg.com/lang/en/docs/package-json/#toc-resolutions
1515
*/
1616

17+
/**
18+
* Array defining the packages we would like to install snapshots for.
19+
*
20+
* Additionally each entry will have a mapping to the corresponding snapshot
21+
* builds repo name. This is necessary as the repository names are inconsistent.
22+
*/
23+
const snapshotPackages = [
24+
{matcher: /^@angular\/(.+)$/, repoName: `angular/$1-builds`},
25+
{matcher: /^@angular-devkit\/(.+)$/, repoName: `angular/angular-devkit-$1-builds`},
26+
{matcher: /^@schematics\/(.+)$/, repoName: `angular/schematics-$1-builds`},
27+
];
28+
1729
/** List of packages which should not be updated to a snapshot build. */
1830
const ignorePackages = [
1931
// Skip update for the shared dev-infra package. We do not want to update to a snapshot
@@ -35,33 +47,45 @@ const packageSuffix = tag ? ` (${tag})` : '';
3547
// See: https://yarnpkg.com/lang/en/docs/package-json/#toc-resolutions for the API.
3648
packageJson['resolutions'] = packageJson['resolutions'] || {};
3749

38-
// List of packages which should be updated to their most recent snapshot version, or
39-
// snapshot version based on the specified tag.
40-
const snapshotPackages = Object.keys({
50+
const packagesToConsider = Object.keys({
4151
...packageJson.dependencies,
4252
...packageJson.devDependencies,
43-
}).filter(
44-
packageName => packageName.startsWith('@angular/') && !ignorePackages.includes(packageName),
45-
);
53+
});
54+
55+
// List of packages which should be updated to their most recent snapshot version, or
56+
// snapshot version based on the specified tag.
57+
const packagesToUpdate = packagesToConsider.reduce((result, name) => {
58+
if (ignorePackages.includes(name)) {
59+
return result;
60+
}
61+
62+
const matchedEntry = snapshotPackages.find(p => p.matcher.test(name));
63+
if (matchedEntry === undefined) {
64+
return result;
65+
}
66+
const repoName = name.replace(matchedEntry.matcher, matchedEntry.repoName);
67+
68+
return result.concat([{name, repoName}]);
69+
}, []);
4670

4771
console.log('Setting up snapshot builds for:\n');
48-
console.log(` ${snapshotPackages.map(n => `${n}${packageSuffix}`).join('\n ')}\n`);
72+
console.log(` ${packagesToUpdate.map(p => `${p.name}${packageSuffix}`).join('\n ')}\n`);
4973

5074
// Setup the snapshot version for each Angular package specified in the "package.json" file.
51-
snapshotPackages.forEach(packageName => {
52-
const buildsUrl = `github:angular/${packageName.split('/')[1]}-builds${tag ? `#${tag}` : ''}`;
75+
packagesToUpdate.forEach(({name, repoName}) => {
76+
const buildsUrl = `github:angular/${repoName}${tag ? `#${tag}` : ''}`;
5377

5478
// Add resolutions for each package in the format "**/{PACKAGE}" so that all
5579
// nested versions of that specific Angular package will have the same version.
56-
packageJson.resolutions[`**/${packageName}`] = buildsUrl;
80+
packageJson.resolutions[`**/${name}`] = buildsUrl;
5781

5882
// Since the resolutions only cover the version of all nested installs, we also need
5983
// to explicitly set the version for the package listed in the project "package.json".
60-
packageJson.dependencies[packageName] = buildsUrl;
84+
packageJson.dependencies[name] = buildsUrl;
6185

6286
// In case this dependency was previously a dev dependency, just remove it because we
6387
// re-added it as a normal dependency for simplicity.
64-
delete packageJson.devDependencies[packageName];
88+
delete packageJson.devDependencies[name];
6589
});
6690

6791
// Write changes to the "packageJson", so that we can install the new versions afterwards.

0 commit comments

Comments
 (0)