diff options
author | Nathan Whitaker <17734409+nathanwhit@users.noreply.github.com> | 2024-07-15 12:11:09 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-07-15 12:11:09 -0700 |
commit | 04f9db5b2217fe06f88e76146aac6362ff0b0b86 (patch) | |
tree | aa4becb2529141de3e6bb8d3ba430f3c7e036902 /tests | |
parent | 29186d7e5963f2398b28ee2c043b27e4881075ef (diff) |
fix(node): Fix `--allow-scripts` with no `deno.json` (#24533)
We would resolve the wrong package.json, resulting in an inability to
run CJS (or other node-mode) scripts
Diffstat (limited to 'tests')
6 files changed, 40 insertions, 0 deletions
diff --git a/tests/registry/npm/@denotest/lifecycle-scripts-cjs/1.0.0/package.json b/tests/registry/npm/@denotest/lifecycle-scripts-cjs/1.0.0/package.json new file mode 100644 index 000000000..1924ddef8 --- /dev/null +++ b/tests/registry/npm/@denotest/lifecycle-scripts-cjs/1.0.0/package.json @@ -0,0 +1,11 @@ +{ + "name": "@denotest/lifecycle-scripts-cjs", + "version": "1.0.0", + "scripts": { + "preinstall": "echo preinstall && node preinstall.js", + "install": "echo install && cli-cjs 'hello from install script'" + }, + "dependencies": { + "@denotest/bin": "1.0.0" + } +}
\ No newline at end of file diff --git a/tests/registry/npm/@denotest/lifecycle-scripts-cjs/1.0.0/preinstall.js b/tests/registry/npm/@denotest/lifecycle-scripts-cjs/1.0.0/preinstall.js new file mode 100644 index 000000000..b5511f990 --- /dev/null +++ b/tests/registry/npm/@denotest/lifecycle-scripts-cjs/1.0.0/preinstall.js @@ -0,0 +1,5 @@ +const inspect = require('util').inspect; + +inspect({ + "preinstall": "script" +});
\ No newline at end of file diff --git a/tests/registry/npm/@denotest/node-lifecycle-scripts/1.0.0/preinstall.js b/tests/registry/npm/@denotest/node-lifecycle-scripts/1.0.0/preinstall.js index e3a59c753..f375b5fb3 100644 --- a/tests/registry/npm/@denotest/node-lifecycle-scripts/1.0.0/preinstall.js +++ b/tests/registry/npm/@denotest/node-lifecycle-scripts/1.0.0/preinstall.js @@ -1,4 +1,5 @@ if ("Deno" in globalThis && typeof globalThis.Deno === 'object') { + require('./helper.js'); console.log('deno preinstall.js'); } else { console.log('node preinstall.js'); diff --git a/tests/specs/npm/lifecycle_scripts/__test__.jsonc b/tests/specs/npm/lifecycle_scripts/__test__.jsonc index 5639c83cd..b862b8126 100644 --- a/tests/specs/npm/lifecycle_scripts/__test__.jsonc +++ b/tests/specs/npm/lifecycle_scripts/__test__.jsonc @@ -119,6 +119,19 @@ "output": "" } ] + }, + "lifecycle_scripts_no_deno_json": { + "tempDir": true, + "steps": [ + { + "args": ["eval", "Deno.removeSync('deno.json')"], + "output": "" + }, + { + "args": "cache --allow-scripts --node-modules-dir=true no_deno_json.js", + "output": "no_deno_json.out" + } + ] } } } diff --git a/tests/specs/npm/lifecycle_scripts/no_deno_json.js b/tests/specs/npm/lifecycle_scripts/no_deno_json.js new file mode 100644 index 000000000..2f26eb7e5 --- /dev/null +++ b/tests/specs/npm/lifecycle_scripts/no_deno_json.js @@ -0,0 +1 @@ +import {} from "npm:@denotest/lifecycle-scripts-cjs@1.0.0"; diff --git a/tests/specs/npm/lifecycle_scripts/no_deno_json.out b/tests/specs/npm/lifecycle_scripts/no_deno_json.out new file mode 100644 index 000000000..9609c0790 --- /dev/null +++ b/tests/specs/npm/lifecycle_scripts/no_deno_json.out @@ -0,0 +1,9 @@ +Download http://localhost:4260/@denotest/lifecycle-scripts-cjs +Download http://localhost:4260/@denotest/bin +Download http://localhost:4260/@denotest/lifecycle-scripts-cjs/1.0.0.tgz +Download http://localhost:4260/@denotest/bin/1.0.0.tgz +Initialize @denotest/lifecycle-scripts-cjs@1.0.0 +Initialize @denotest/bin@1.0.0 +preinstall +install +hello from install script |