Skip to content
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
37 changes: 32 additions & 5 deletions scripts/update-dependencies.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
const fs = require('fs');
const path = require('path');
const { isEqual, cloneDeep } = require('lodash');
const prompts = require('prompts');
const {
listAllPackages,
runInDir,
Expand All @@ -12,6 +13,8 @@ const {

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

const unsafeForce = process.argv.includes('--unsafe-force-install');

async function hoistSharedDependencies(root, newVersions) {
try {
await withProgress('Cleaning up existing node_modules', async () => {
Expand All @@ -22,7 +25,12 @@ async function hoistSharedDependencies(root, newVersions) {
const packageJsonBkp = await withProgress(
'Updating package-lock to apply package.json changes',
async () => {
await runInDir('npm i --package-lock-only --ignore-scripts', root);
await runInDir(
`npm i --package-lock-only --ignore-scripts${
unsafeForce ? ' --force' : ''
}`,
root
);
return await fs.promises.readFile(path.resolve(root, 'package.json'));
}
);
Expand All @@ -36,7 +44,9 @@ async function hoistSharedDependencies(root, newVersions) {
})
.join(' ');
await runInDir(
`npm i ${versionsToInstall} --package-lock-only --ignore-scripts`,
`npm i ${versionsToInstall} --package-lock-only --ignore-scripts${
unsafeForce ? ' --force' : ''
}`,
root
);
}
Expand All @@ -53,7 +63,8 @@ async function hoistSharedDependencies(root, newVersions) {
}
);
} catch (error) {
console.error(`Error running command: ${error}`);
console.error(`\n${error.message}`);
process.exit(1);
}
}

Expand Down Expand Up @@ -123,7 +134,23 @@ function updateOverrides(overrides, newVersions, parent) {
async function main() {
let dependencies;

const args = process.argv.slice(3);
const args = process.argv.slice(3).filter((arg) => !arg.startsWith('-'));

if (unsafeForce) {
const { confirmed } = await prompts({
type: 'confirm',
name: 'confirmed',
initial: false,
message:
'Using force install is potentially harmful and should be used only ' +
'if you are absolutely sure what you are doing. If in doubt, reach ' +
'out to the team for advice.\n\nDo you want to proceed?',
});
if (!confirmed) {
console.log('Exiting...');
return;
}
}

if (args.length === 0) {
throw new Error(
Expand Down Expand Up @@ -179,7 +206,7 @@ async function main() {
});

const newVersions = await withProgress(
`Collection version information for packages...`,
`Collecting version information for packages...`,
() => {
return Promise.all(
dependencies.map((depSpec) => {
Expand Down
Loading