Skip to content

Commit 416d167

Browse files
authored
Merge pull request backstage#26895 from backstage/rugvip/pin
scripts: add pin-workspace-versions
2 parents 230ff9f + f43634f commit 416d167

File tree

1 file changed

+59
-0
lines changed

1 file changed

+59
-0
lines changed

scripts/pin-workspace-versions.js

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
#!/usr/bin/env node
2+
/*
3+
* Copyright 2024 The Backstage Authors
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
// This switches all `workspace:^` dependencies in the project to instead use `workspace:*`
19+
// This is used for next releases in order to avoid the `^` range that is otherwise likely to cause issues.
20+
// For example, a `^0.5.0-next.0` range will match `0.5.0-next.0`, `0.5.0-next.1`, and even `0.5.2`.
21+
// This can often lead to issues as there might be breaking changes across these versions, and in practice
22+
// it will only be possible to install the most recent release without a lot of hassle.
23+
24+
const fs = require('fs-extra');
25+
const { getPackages } = require('@manypkg/get-packages');
26+
const { resolve } = require('path');
27+
28+
const depTypes = ['dependencies', 'devDependencies', 'peerDependencies'];
29+
30+
async function main() {
31+
const rootPath = resolve(__dirname, '..');
32+
const { packages } = await getPackages(rootPath);
33+
34+
for (const pkg of packages) {
35+
let changed = false;
36+
for (const depType of depTypes) {
37+
const deps = pkg.packageJson[depType];
38+
if (deps) {
39+
for (const depName of Object.keys(deps)) {
40+
if (deps[depName] === 'workspace:^') {
41+
deps[depName] = 'workspace:*';
42+
changed = true;
43+
}
44+
}
45+
}
46+
}
47+
48+
if (changed) {
49+
await fs.writeJson(resolve(pkg.dir, 'package.json'), pkg.packageJson, {
50+
spaces: 2,
51+
});
52+
}
53+
}
54+
}
55+
56+
main(process.argv.slice(2)).catch(error => {
57+
console.error(error.stack || error);
58+
process.exit(1);
59+
});

0 commit comments

Comments
 (0)