Skip to content
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

fix: Run dedupe during upgrade on yarn 3 #5458

Merged
merged 3 commits into from
May 9, 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
19 changes: 12 additions & 7 deletions packages/cli/src/commands/upgrade.js
Original file line number Diff line number Diff line change
Expand Up @@ -278,24 +278,29 @@ const dedupeDeps = async (task, { verbose }) => {
try {
const yarnVersion = await getCmdMajorVersion('yarn')
const npxVersion = await getCmdMajorVersion('npx')
if (yarnVersion > 1) {
task.skip('Deduplication is only required for <=1.x')
return
}
let npxArgs = []
if (npxVersion > 6) {
npxArgs = ['--yes']
}

await execa('npx', [...npxArgs, 'yarn-deduplicate'], {
const baseExecaArgsForDedupe = {
shell: true,
stdio: verbose ? 'inherit' : 'pipe',
cwd: getPaths().base,
})
}
if (yarnVersion > 1) {
await execa('yarn', ['dedupe'], baseExecaArgsForDedupe)
} else {
Comment on lines +291 to +293
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yarn dedupe was added in v2.2.0 so there is a chance it isn't a valid command.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah gotcha. Great catch—we don't expect users to be on yarn 2, but to be fair we don't have any documentation / checks around that fact, so there's some work to do here. A while back Danny had asked me to make a simple utility for running yarn commands given that we have to support two versions; it's probably time for me to revisit that.

await execa(
'npx',
[...npxArgs, 'yarn-deduplicate'],
baseExecaArgsForDedupe
)
}
} catch (e) {
console.log(c.error(e.message))
throw new Error(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe we can print the correct command based on the yarn version?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can but if for some reason regex fails for semver, that's why I kept it one simple catch.

Copy link
Contributor

@dac09 dac09 May 9, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The one catch is fine, but just suggesting printing different messages

if (yarnVersion > 1) {
 console.log('Failed dedupe step. Run yarn dedupe')
} else {
  console.log('Failed dedupe. run npx yarn-deduplcate')
}

'Could not finish deduplication. If the project is using yarn 1.x, please run `npx yarn-deduplicate`, before continuing'
'Could not finish de-duplication. For yarn 1.x, please run `npx yarn-deduplicate`, or for yarn 3 run `yarn dedupe` before continuing'
)
}
await yarnInstall({ verbose })
Expand Down