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(exec): npx to run specified version if multiple version exist globally #7587

Merged
merged 1 commit into from
Jun 14, 2024

Conversation

milaninfy
Copy link
Contributor

@milaninfy milaninfy commented Jun 5, 2024

When multiple version of the same package is exist globally either at top level or at any level as a sub dependency, even though the version specified does not exist at top level it was running top level bin since it matches the bin name.
This fixes checks for depth of the found node along with already existing specs checks.

Fixes: #7486

@milaninfy milaninfy force-pushed the mm/fix-npx-version-issue branch 2 times, most recently from 7f945d2 to 2a9292c Compare June 5, 2024 21:27
@milaninfy milaninfy changed the title fix(exec): fix(exec): npx to run specified version if multiple version exist globally Jun 12, 2024
@milaninfy milaninfy marked this pull request as ready for review June 12, 2024 14:59
@milaninfy milaninfy requested a review from a team as a code owner June 12, 2024 14:59
@@ -41,6 +41,10 @@ const missingFromTree = async ({ spec, tree, flatOptions, isNpxTree }) => {
// registry spec that is not a specific tag.
const nodesBySpec = tree.inventory.query('packageName', spec.name)
for (const node of nodesBySpec) {
// continue if node is not at specified depth, no need to check further
if (depth !== undefined && node.depth !== depth) {
Copy link
Member

Choose a reason for hiding this comment

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

This is a great solution. However we are currently not really using depth so much as telling this function to only look at depth 0.

It would probably make more sense in the future when reading this if this was called something like shallow and was a Boolean. and then if (shallow && node.depth) would be the test for continuing.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Makes sense.. Corrected in latest push.

@milaninfy milaninfy force-pushed the mm/fix-npx-version-issue branch 2 times, most recently from f891839 to f966233 Compare June 12, 2024 18:57
const { manifest: globalManifest } =
await missingFromTree({ spec, tree: globalTree, flatOptions })
if (!globalManifest && await fileExists(`${globalBin}/${args[0]}`)) {
const { node: globalNode } =
Copy link
Member

Choose a reason for hiding this comment

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

Why did we switch from manifest to node here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Initially I kept both, but the missingFromTree function in all code path it returns either { node } or { manifest } not sure if there ever a case if manifest is null and node is null as well, and also later we were checking for !manifest so changed to node, but I think now that you pointed it out it wont make a difference even if I keep it as it was earlier.

@wraithgar wraithgar merged commit 71c6848 into npm:latest Jun 14, 2024
23 checks passed
@github-actions github-actions bot mentioned this pull request Jun 14, 2024
@milaninfy milaninfy deleted the mm/fix-npx-version-issue branch August 26, 2024 19:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants