Open marvinhagemeister opened 1 year ago
CC @dsherret I don't remember the exact reason why we didn't install devDependencies
by default
In this case, running a binary command like...
deno run -A npm:mocha -r @babel/register
...will not cause an "npm install" of the packages. It will only install npm:mocha
. As for how to cause an npm install, it is lazily done when some code references a bare specifier that matches what's found in a package.json (so in this case, just running deno run -A npm:mocha -r @babel/register
won't work because @babel/register
hasn't had a chance to be installed). The reason it's done is because a lot of people use deno for scripts in npm packages.
Few points:
deno cache package.json
to force an "npm install".require
fails for something that's found in the package.json then it could attempt to do an "npm install" at that point. Issue is this might cause some weird edge cases. Probably better to have the ability to do an explicit "npm install"I've been pondering about this and the more I think I about the more I lean towards to have an npm install
command for npm packages. It would match the expectations folks have around them. URLs should still be downloaded on the fly and for folks who don't want to install npm packages, can use esm.sh
.
We tried the auto install of npm packages thing in Preact team when working onwmr
around 2020 and parcel tried to do that a little later too. Both projects backtracked on that. In wmr
we ran into edge case after edge case and ultimately abandoned the approach around the time we decided to switch to vite
anyway.
Problem is that it can get real messy with postinstall
scripts which can run anything. There are a couple of packages in the tooling space which rely on it. It's a little dangerous to fire postinstall
scripts when the developer accidentally mistyped a popular package name and suddenly it installed a type squatted malicious package and ran their malicious postinstall
script.
But the main issue both projects ran into is that people perceived it as very unexpected behavior. That led to folks asking for a way early on how to disable that. See the parcel issue tracker for lots of vocal users.
But this can also be an opportunity for us to integrate the permission system for running those install scripts. I'm wondering if this distinction would make sense:
npm install
like commandNote that those users were already node users though and familiar with the install
command. I'm not sure how the current deno userbase would react.
I think it's ok if certain edge cases don't work. The convenience of not needing to worry about an explicit install command outweighs the negatives in my opinion and hopefully package authors who run into edge cases we can't handle will adapt to trying to get their packages to work with Deno. For example, we don't support postinstall scripts atm, but a package author can lazily do some initialization on first run.
Btw, I'm not sure how running an explicit npm install
protects against misspelling a package name. Even with npm install --ignore-scripts
, you would still have to notice that the package name was mispelled before you execute node main.js
.
It seems like deno doesn't install all packages listed in
package.json
. There are two packages listed there:@babel/register
mocha
For some reason only
mocha
is installed, not@babel/register
. It's not anywhere innode_modules
ornode_modules/.deno
. This leads to a "module not found" error:Ran into this when trying to use deno to work on https://github.com/preactjs/preact-render-to-string/ .
Steps to reproduce
deno run -A npm:mocha -r @babel/register