Skip to content

Commit 0bc28f0

Browse files
ci: fix angular snapshot setup script for pnpm v12 (#33959)
Fixes the doubled `angular/` repository prefix in snapshot build URLs and updates `setup-angular-snapshots.js` to write `overrides` and `blockExoticSubdeps: false` to `pnpm-workspace.yaml` instead of `package.json`.
1 parent a093592 commit 0bc28f0

1 file changed

Lines changed: 22 additions & 8 deletions

File tree

‎scripts/circleci/setup-angular-snapshots.js‎

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,13 @@ const ignorePackages = [
3232
'@angular/bazel',
3333
];
3434

35-
const {writeFileSync} = require('fs');
35+
const {readFileSync, writeFileSync} = require('fs');
3636
const {join} = require('path');
3737

3838
const [tag] = process.argv.slice(2);
3939
const projectDir = join(__dirname, '../../');
4040
const packageJsonPath = join(projectDir, 'package.json');
41+
const pnpmWorkspacePath = join(projectDir, 'pnpm-workspace.yaml');
4142
const packageJson = require(packageJsonPath);
4243
const packageSuffix = tag ? ` (${tag})` : '';
4344

@@ -65,15 +66,17 @@ const packagesToUpdate = packagesToConsider.reduce((result, name) => {
6566
console.log('Setting up snapshot builds for:\n');
6667
console.log(` ${packagesToUpdate.map(p => `${p.name}${packageSuffix}`).join('\n ')}\n`);
6768

69+
const overrideLines = [];
70+
6871
// Setup the snapshot version for each Angular package specified in the "package.json" file.
6972
packagesToUpdate.forEach(({name, repoName}) => {
70-
const buildsUrl = `github:angular/${repoName}${tag ? `#${tag}` : ''}`;
73+
const buildsUrl = `github:${repoName}${tag ? `#${tag}` : ''}`;
7174

72-
// Add overrides for each package in the format "**/{PACKAGE}" so that all
73-
// nested versions of that specific Angular package will have the same version.
74-
packageJson.pnpm.overrides[`**/${name}`] = buildsUrl;
75+
// Add overrides for each package so that all nested versions of that
76+
// specific Angular package will have the same version.
77+
overrideLines.push(` '${name}': '${buildsUrl}'`);
7578

76-
// Since the resolutions only cover the version of all nested installs, we also need
79+
// Since the overrides only cover the version of all nested installs, we also need
7780
// to explicitly set the version for the package listed in the project "package.json".
7881
if (packageJson.devDependencies && packageJson.devDependencies[name]) {
7982
packageJson.devDependencies[name] = buildsUrl;
@@ -83,6 +86,17 @@ packagesToUpdate.forEach(({name, repoName}) => {
8386
});
8487

8588
// Write changes to the "packageJson", so that we can install the new versions afterwards.
86-
writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2));
89+
writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2) + '\n');
90+
91+
// Add the overrides and allow exotic subdependencies in "pnpm-workspace.yaml".
92+
let pnpmWorkspace = readFileSync(pnpmWorkspacePath, 'utf8');
93+
if (!pnpmWorkspace.includes('\noverrides:\n')) {
94+
throw new Error('Could not find "overrides:" section in pnpm-workspace.yaml');
95+
}
96+
pnpmWorkspace = pnpmWorkspace.replace(
97+
'\noverrides:\n',
98+
`\nblockExoticSubdeps: false\noverrides:\n${overrideLines.join('\n')}\n`,
99+
);
100+
writeFileSync(pnpmWorkspacePath, pnpmWorkspace);
87101

88-
console.log('Successfully added the "resolutions" to the "package.json".');
102+
console.log('Successfully added the "overrides" to the "pnpm-workspace.yaml".');

0 commit comments

Comments
 (0)