Skip to content

Commit d4f6ccf

Browse files
authored
chore(scripts): allow to pass force flag when updating via script (#7242)
1 parent 5a26679 commit d4f6ccf

File tree

1 file changed

+32
-5
lines changed

1 file changed

+32
-5
lines changed

scripts/update-dependencies.js

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
const fs = require('fs');
33
const path = require('path');
44
const { isEqual, cloneDeep } = require('lodash');
5+
const prompts = require('prompts');
56
const {
67
listAllPackages,
78
runInDir,
@@ -12,6 +13,8 @@ const {
1213

1314
const UPDATE_CONFIGS = require('./update-dependencies-config');
1415

16+
const unsafeForce = process.argv.includes('--unsafe-force-install');
17+
1518
async function hoistSharedDependencies(root, newVersions) {
1619
try {
1720
await withProgress('Cleaning up existing node_modules', async () => {
@@ -22,7 +25,12 @@ async function hoistSharedDependencies(root, newVersions) {
2225
const packageJsonBkp = await withProgress(
2326
'Updating package-lock to apply package.json changes',
2427
async () => {
25-
await runInDir('npm i --package-lock-only --ignore-scripts', root);
28+
await runInDir(
29+
`npm i --package-lock-only --ignore-scripts${
30+
unsafeForce ? ' --force' : ''
31+
}`,
32+
root
33+
);
2634
return await fs.promises.readFile(path.resolve(root, 'package.json'));
2735
}
2836
);
@@ -36,7 +44,9 @@ async function hoistSharedDependencies(root, newVersions) {
3644
})
3745
.join(' ');
3846
await runInDir(
39-
`npm i ${versionsToInstall} --package-lock-only --ignore-scripts`,
47+
`npm i ${versionsToInstall} --package-lock-only --ignore-scripts${
48+
unsafeForce ? ' --force' : ''
49+
}`,
4050
root
4151
);
4252
}
@@ -53,7 +63,8 @@ async function hoistSharedDependencies(root, newVersions) {
5363
}
5464
);
5565
} catch (error) {
56-
console.error(`Error running command: ${error}`);
66+
console.error(`\n${error.message}`);
67+
process.exit(1);
5768
}
5869
}
5970

@@ -123,7 +134,23 @@ function updateOverrides(overrides, newVersions, parent) {
123134
async function main() {
124135
let dependencies;
125136

126-
const args = process.argv.slice(3);
137+
const args = process.argv.slice(3).filter((arg) => !arg.startsWith('-'));
138+
139+
if (unsafeForce) {
140+
const { confirmed } = await prompts({
141+
type: 'confirm',
142+
name: 'confirmed',
143+
initial: false,
144+
message:
145+
'Using force install is potentially harmful and should be used only ' +
146+
'if you are absolutely sure what you are doing. If in doubt, reach ' +
147+
'out to the team for advice.\n\nDo you want to proceed?',
148+
});
149+
if (!confirmed) {
150+
console.log('Exiting...');
151+
return;
152+
}
153+
}
127154

128155
if (args.length === 0) {
129156
throw new Error(
@@ -179,7 +206,7 @@ async function main() {
179206
});
180207

181208
const newVersions = await withProgress(
182-
`Collection version information for packages...`,
209+
`Collecting version information for packages...`,
183210
() => {
184211
return Promise.all(
185212
dependencies.map((depSpec) => {

0 commit comments

Comments
 (0)