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

Feature support NPM package aliases #45

Conversation

Domantas-wix
Copy link
Contributor

NPM has a poorly documented aliasing feature allowing user to install multiple instances of the same package under different names.
Proposal: https://github.com/npm/rfcs/blob/latest/implemented/0001-package-aliases.md
Implementation: npm/cli#3

Add support for these aliases, checking the installed version and if dependency matches by name.

@whoisbenli
Copy link

@Domantas-wix thanks for your contribution! I ran into this issue as well. @mgol, would love to see this merged =D

Copy link
Owner

@mgol mgol left a comment

Choose a reason for hiding this comment

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

Thanks for the PR! I added a few comments.

lib/check-dependencies.js Outdated Show resolved Hide resolved
lib/check-dependencies.js Outdated Show resolved Hide resolved
lib/check-dependencies.js Outdated Show resolved Hide resolved
Domantas-wix and others added 2 commits August 20, 2020 14:54
Co-authored-by: Michał Gołębiowski-Owczarek <[email protected]>
@Domantas-wix Domantas-wix requested a review from mgol August 20, 2020 14:12
Comment on lines +107 to +108
const supportsPackageAliases = packageManager =>
packageManager === 'npm' || packageManager === 'yarn';
Copy link
Owner

Choose a reason for hiding this comment

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

Do we need this check? I imagine some other package managers like pnpm may also support aliases. We might want to exclude Bower here as that's completely different but in the rest I wouldn't assume lack of support.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@mgol Yes, keeping a whitelist is secure, keeping a blacklist will eventually cause issues. All it takes is one package manager that interprets the colon differently to have huge discrepancies rendering the package unusable. Either way, when support for these other package managers is added code like this can be changed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

By the way, not having sufficient checks like this is what prompted this PR in the first place, you take aliased version structure and pretend to know what it is, causing incorrect behaviour. Care should be taken to keep publicly used code forwards compatible

Copy link
Owner

Choose a reason for hiding this comment

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

pnpm already supports package aliases:
https://pnpm.js.org/en/aliases
and the syntax looks the same as the Yarn/npm one. It looks like the Yarn-originated syntax has become a de-facto standard that all package managers will soon follow. It's not likely that other package managers will implement it differently IMO.

@Domantas-wix Domantas-wix requested a review from mgol August 21, 2020 07:18
whoisbenli added a commit to whoisbenli/check-dependencies that referenced this pull request Oct 1, 2020
Same changes as this other PR, except with the package manager check removed as requested in the PR comments.
mgol#45
@jcsmorais
Copy link

I was about to create a new PR addressing the feedback on this one to see if we could get this merged and released but realized @whoisbenli already attempted that?

@mgol any idea why that didn't work out?
I'd love to get these changes in, let me know if there's anyway I can help that happen 🙂

@mgol
Copy link
Owner

mgol commented Nov 26, 2021

@jcsmorais Hey! I had a remark about an allowlist approach excluding alternative package manager like pnpm plus the fact the Yarn-pioneered syntax for aliases became a de-facto standard so it makes sense to allow it by default and mostly just exclude from bower.

If you could make a PR with commits from this one followed by the requested fixes, I'd be OK with merging this.

IceCreamYou added a commit to IceCreamYou/check-dependencies that referenced this pull request Feb 1, 2022
@IceCreamYou
Copy link
Contributor

Addressed feedback in #50 🙂

@mgol mgol closed this in f145832 Feb 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants