Skip to content

build: install snapshot builds for angular-devkit and schematics #24458

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 22, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 36 additions & 12 deletions scripts/circleci/setup-angular-snapshots.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,18 @@
* Read more here: https://yarnpkg.com/lang/en/docs/package-json/#toc-resolutions
*/

/**
* Array defining the packages we would like to install snapshots for.
*
* Additionally each entry will have a mapping to the corresponding snapshot
* builds repo name. This is necessary as the repository names are inconsistent.
*/
const snapshotPackages = [
{matcher: /^@angular\/(.+)$/, repoName: `angular/$1-builds`},
{matcher: /^@angular-devkit\/(.+)$/, repoName: `angular/angular-devkit-$1-builds`},
{matcher: /^@schematics\/(.+)$/, repoName: `angular/schematics-$1-builds`},
];

/** List of packages which should not be updated to a snapshot build. */
const ignorePackages = [
// Skip update for the shared dev-infra package. We do not want to update to a snapshot
Expand All @@ -35,33 +47,45 @@ const packageSuffix = tag ? ` (${tag})` : '';
// See: https://yarnpkg.com/lang/en/docs/package-json/#toc-resolutions for the API.
packageJson['resolutions'] = packageJson['resolutions'] || {};

// List of packages which should be updated to their most recent snapshot version, or
// snapshot version based on the specified tag.
const snapshotPackages = Object.keys({
const packagesToConsider = Object.keys({
...packageJson.dependencies,
...packageJson.devDependencies,
}).filter(
packageName => packageName.startsWith('@angular/') && !ignorePackages.includes(packageName),
);
});

// List of packages which should be updated to their most recent snapshot version, or
// snapshot version based on the specified tag.
const packagesToUpdate = packagesToConsider.reduce((result, name) => {
if (ignorePackages.includes(name)) {
return result;
}

const matchedEntry = snapshotPackages.find(p => p.matcher.test(name));
if (matchedEntry === undefined) {
return result;
}
const repoName = name.replace(matchedEntry.matcher, matchedEntry.repoName);

return result.concat([{name, repoName}]);
}, []);

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

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

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

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

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

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