denoland / deno

A modern runtime for JavaScript and TypeScript.
https://deno.com
MIT License
96.13k stars 5.31k forks source link

postinstall script fails because it uses `node` (`deno i --allow-scripts`) #24916

Open alexgleason opened 2 months ago

alexgleason commented 2 months ago

Version: Deno 1.45.5

I am trying to make vitepress (with a package.json) build with Deno using:

DENO_FUTURE=1 deno i --allow-scripts
deno task build

It results in this error:

Error launching 'node': No such file or directory (os error 2)
error: script 'postinstall' in 'vue-demi@0.14.7' failed with exit code 1
Cleaning up project directory and file based variables
00:01
ERROR: Job failed: exit code 1

The problem is that node is used as an executable inside of the postinstall script of the package:

"postinstall": "node -e \"try{require('./scripts/postinstall.js')}catch(e){}\"",

I submitted an MR to vue-demi to skip the postinstall script if node is not found, because it not essential: https://github.com/vueuse/vue-demi/pull/266

I'm not sure if that's the solution, or if we want to make it use the deno executable there. It would improve compatibility.

I was also able to work around it by using --allow-scripts=npm:esbuild to whitelist the only other package with a postinstall script, but it would be frustrating if there was a lot of other packages and no way to blacklist

nathanwhit commented 2 months ago

I'm not sure if that's the solution, or if we want to make it use the deno executable there. It would improve compatibility.

Yeah this should use the deno executable. We actually do this already, it just currently falls back to node if there are flags specified. (In other words, node postinstall.js already works and runs Deno). We just need to handle the -e / —eval flag.

It’s straightforward, the only complication is that we should wrap the eval-ed code to inject a require function (and potentially node globals, though they aren’t strictly required in this particular case).