diff options
author | Nathan Whitaker <17734409+nathanwhit@users.noreply.github.com> | 2024-05-29 17:45:22 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-05-29 17:45:22 -0700 |
commit | a379009bfdddc56d6400740ad7be86f8930952ab (patch) | |
tree | a1198bce9d62d9c2a59073921707c31b894c8eee /tests | |
parent | e084fe10a98556d4630b54bdda2ce23b3b5b8a60 (diff) |
fix(cli): Prefer npm bin entries provided by packages closer to the root (#24024)
Fixes #24012.
In the case of multiple packages providing a binary with a same name, we
were basically leaving the results undefined (since we set up things in
parallel, and whichever got set up first won). In addition, we were
warning about these cases, even though it's a situation that's expected
to occur.
Instead, in the case of a collision in the binary names, we prefer the
binary provided by the package with the least depth in the dependency
tree.
While I was at it, I also took moved more code to `bin_entries.rs` since
it was starting to get a bit cluttered.
Diffstat (limited to 'tests')
9 files changed, 79 insertions, 0 deletions
diff --git a/tests/registry/npm/@denotest/bin/0.7.0/cli-no-ext b/tests/registry/npm/@denotest/bin/0.7.0/cli-no-ext new file mode 100644 index 000000000..1cad127ca --- /dev/null +++ b/tests/registry/npm/@denotest/bin/0.7.0/cli-no-ext @@ -0,0 +1,3 @@ +#!/usr/bin/env -S node + +console.log("@denotest/bin 0.7.0"); diff --git a/tests/registry/npm/@denotest/bin/0.7.0/cli.mjs b/tests/registry/npm/@denotest/bin/0.7.0/cli.mjs new file mode 100644 index 000000000..1cad127ca --- /dev/null +++ b/tests/registry/npm/@denotest/bin/0.7.0/cli.mjs @@ -0,0 +1,3 @@ +#!/usr/bin/env -S node + +console.log("@denotest/bin 0.7.0"); diff --git a/tests/registry/npm/@denotest/bin/0.7.0/package.json b/tests/registry/npm/@denotest/bin/0.7.0/package.json new file mode 100644 index 000000000..d66b6e34d --- /dev/null +++ b/tests/registry/npm/@denotest/bin/0.7.0/package.json @@ -0,0 +1,8 @@ +{ + "name": "@denotest/bin", + "version": "0.7.0", + "bin": { + "cli-esm": "./cli.mjs", + "cli-no-ext": "./cli-no-ext" + } +} diff --git a/tests/registry/npm/@denotest/transitive-bin/1.0.0/cli-cjs.js b/tests/registry/npm/@denotest/transitive-bin/1.0.0/cli-cjs.js new file mode 100644 index 000000000..f517654b9 --- /dev/null +++ b/tests/registry/npm/@denotest/transitive-bin/1.0.0/cli-cjs.js @@ -0,0 +1 @@ +console.log("@denotest/transitive-bin 1.0.0"); diff --git a/tests/registry/npm/@denotest/transitive-bin/1.0.0/package.json b/tests/registry/npm/@denotest/transitive-bin/1.0.0/package.json new file mode 100644 index 000000000..84d780516 --- /dev/null +++ b/tests/registry/npm/@denotest/transitive-bin/1.0.0/package.json @@ -0,0 +1,10 @@ +{ + "name": "@denotest/transitive-bin", + "version": "1.0.0", + "dependencies": { + "@denotest/bin": "1.0.0" + }, + "bin": { + "cli-cjs": "cli-cjs.js" + } +}
\ No newline at end of file diff --git a/tests/specs/npm/bin_entries_prefer_closer/__test__.jsonc b/tests/specs/npm/bin_entries_prefer_closer/__test__.jsonc new file mode 100644 index 000000000..90d788518 --- /dev/null +++ b/tests/specs/npm/bin_entries_prefer_closer/__test__.jsonc @@ -0,0 +1,26 @@ +{ + "envs": { + "DENO_FUTURE": "1" + }, + "tempDir": true, + "steps": [ + { + "args": "install", + "output": "install.out" + }, + { + "args": "task run-esm", + "output": "Task run-esm cli-esm hello world\n@denotest/bin 0.7.0\n" + }, + { + "args": "task run-cjs", + // @denotest/bin 0.7.0 doesn't have a cli-cjs, so it should use the one from @denotest/transitive-bin + // because it's closer than the one from @denotest/bin 1.0.0 + "output": "Task run-cjs cli-cjs hello world\n@denotest/transitive-bin 1.0.0\n" + }, + { + "args": "task run-no-ext", + "output": "Task run-no-ext cli-no-ext hello world\n@denotest/bin 0.7.0\n" + } + ] +} diff --git a/tests/specs/npm/bin_entries_prefer_closer/deno.json b/tests/specs/npm/bin_entries_prefer_closer/deno.json new file mode 100644 index 000000000..176354f98 --- /dev/null +++ b/tests/specs/npm/bin_entries_prefer_closer/deno.json @@ -0,0 +1,3 @@ +{ + "nodeModulesDir": true +} diff --git a/tests/specs/npm/bin_entries_prefer_closer/install.out b/tests/specs/npm/bin_entries_prefer_closer/install.out new file mode 100644 index 000000000..25e06db99 --- /dev/null +++ b/tests/specs/npm/bin_entries_prefer_closer/install.out @@ -0,0 +1,11 @@ +⚠️ `deno install` behavior will change in Deno 2. To preserve the current behavior use the `-g` or `--global` flag. +[UNORDERED_START] +Download http://localhost:4260/@denotest/transitive-bin +Download http://localhost:4260/@denotest/bin +Download http://localhost:4260/@denotest/bin/1.0.0.tgz +Download http://localhost:4260/@denotest/transitive-bin/1.0.0.tgz +Download http://localhost:4260/@denotest/bin/0.7.0.tgz +Initialize @denotest/transitive-bin@1.0.0 +Initialize @denotest/bin@1.0.0 +Initialize @denotest/bin@0.7.0 +[UNORDERED_END] diff --git a/tests/specs/npm/bin_entries_prefer_closer/package.json b/tests/specs/npm/bin_entries_prefer_closer/package.json new file mode 100644 index 000000000..af75632ce --- /dev/null +++ b/tests/specs/npm/bin_entries_prefer_closer/package.json @@ -0,0 +1,14 @@ +{ + "name": "bin_entries_prefer_closer", + "dependencies": { + "@denotest/bin": "0.7.0", + "@denotest/transitive-bin": "1.0.0" + }, + + "scripts": { + "run-esm": "cli-esm hello world", + "run-cjs": "cli-cjs hello world", + "run-no-ext": "cli-no-ext hello world", + "run-ts": "cli-ts" + } +} |