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

feat(cli): validate yarn.lock in 'start' and 'build' commands and add 'deduplicate' command #668

Merged
merged 3 commits into from
Oct 7, 2021

Conversation

mediremi
Copy link
Contributor

@mediremi mediremi commented Oct 2, 2021

Closes https://jira.dhis2.org/browse/LIBS-213

  • Validates yarn.lock in start and build commands (warning in start but error in build) by ensuring that there is only one version of @dhis2/app-runtime, @dhis2/d2-i18n, @dhis2/ui, react and styled-jsx
  • Adds a deduplicate command (which runs yarn-deduplicate)

Implementation notes

  • Although LIBS-213 suggested treating i18next as a sensitive singleton dependency, i18next-scanner declares the version of its i18next dependency as "*". This results in two different major versions of i18next (@dhis2/d2-i18n depends on ^10.3, but latest major version is 21), which yarn-deduplicate does not attempt to fix. Therefore, adding i18next would result in yarn build failing for all app-platform apps unless yarn.locks are manually edited.
  • yarn-deduplicate's code is included in this PR directly instead of being added as an npm dependency due to modifications required for listDuplicates and getDuplicatedPackages to work for our use case.

@mediremi mediremi changed the title feat(cli): validate yarn.lock in 'start' and 'build' commands feat(cli): validate yarn.lock in 'start' and 'build' commands and add 'deduplicate' command Oct 4, 2021

const duplicates = listDuplicates(deduped)
if (duplicates.size > 0) {
reporter.error('Failed to deduplicate the following packages:')
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Failing to deduplicate with fixDuplicates may occur if there are multiple major versions of a dependency.

@mediremi mediremi requested review from amcgee and varl and removed request for amcgee October 4, 2021 10:28
Copy link
Contributor

@varl varl left a comment

Choose a reason for hiding this comment

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

Nice one. Tested locally in a few apps and works for me.

` * ${chalk.bold(name)} (found versions ${versions.join(', ')})`
)
}
process.exit(1)
Copy link
Contributor

Choose a reason for hiding this comment

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

You can use exit(code, message) from cli-helpers-engine for consistency.

@mediremi mediremi enabled auto-merge (squash) October 7, 2021 12:45
@mediremi mediremi merged commit 8a8aa4d into master Oct 7, 2021
@mediremi mediremi deleted the LIBS-213 branch October 7, 2021 12:49
dhis2-bot added a commit that referenced this pull request Oct 7, 2021
# [8.2.0](v8.1.2...v8.2.0) (2021-10-07)

### Features

* **cli:** validate yarn.lock in 'start' and 'build' commands and add 'deduplicate' command ([#668](#668)) ([8a8aa4d](8a8aa4d))
@dhis2-bot
Copy link
Contributor

🎉 This PR is included in version 8.2.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

@amcgee
Copy link
Member

amcgee commented Oct 7, 2021

Looks really awesome @mediremi , nice work!

One comment - this will de duplicate in yarn.lock but not in node_modules which requires another yarn install run. This is maybe ok for d2-app-scripts deduplicate, though it would be good to at least tell the user they need to run another install. For the auto-fix in yarn.lock validation, though, this will be more problematic - if the duplicates are fixed before a yarn start, they will then be correct in yarn.lock but the app will still resolve duplicates (silently now) while running. We should probably run yarn install when deduplicating?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

Successfully merging this pull request may close these issues.

None yet

4 participants