This is definitely interesting. It will be nice not having to deal with that massive directory in each project.
This is definitely interesting. It will be nice not having to deal with that massive directory in each project.
Even the --node-module-dir flag just creates a symlink to your home directory cache so you can't do per-project package fixes (besides forking and rehosting the package)
I'm also not sure how/if it supports packages that require compiling binaries like sqlite or playwright without post-install hooks
https://www.npmjs.com/package/patch-package
You commit your changes as a diff text file and add the patch-package command to your post-install hook so it runs after every install
My main use for it is fixing other packages' package.json exports field and Typescript definitions
Where should one put the text files in the code base? Do you create some root level "patch" directory?
That’s also how I would share any patches: Just apply them when needed during the build process. NPM doesn’t care about what changes inside packages, so you can hack them all you want.
A popular choice if you need some pr's that aren't (going to be) merged.
You can do a patch package by doing something like the following (and then you can move this into a `deno task` https://deno.land/manual@v1.28.0/tools/task_runner when launching your app to ensure it happens):
deno cache --node-modules-dir main.ts
deno run --allow-read=. --allow-write=. scripts/your_patch_script.ts
deno run --node-modules-dir main.tsStill, the end-goal is not the same, IMHO. Outside exceptions (e.g. some developers not packaging their applications and making users install through `pip`/`npm install -g`, which I also really dislike), your typical end-user would not interact with language specific package managers. They're most typically used for development/deployment dependencies, not end-user installation.
Rubygems is usually global.
The granddaddy of them all, CPAN and its cpan install tool, defaults to installing globally, in practice, on most systems.
Pip, as you noted, does it.
I think Maven's typically user-scoped, so not really global, but also not project-scoped like npm. Similar to Go.
You can get around this in most or all cases—sometimes with options or config, sometimes with extra effort or some aliases or scripts, sometimes environment variables, sometimes with 3rd party tools—but the simplest or default mode is global installation, or at least project-global if not user-global in Go's or Maven's cases. And many of those solutions (e.g. rvm) still don't scope installation per-project by default, like npm does.
At the time npm got started, especially, it was definitely an outlier in its default scope. Some others have taken its approach since, and maybe a majority of total language-specific package managers even do, these days, but adjusted for actual use in the wild, I bet NPM's by far the most-used one that operates that way, and that most of the other popular ones scope more broadly—including, often, globally—by default. That is, a language-specific package manager one runs into in the real world, in 2022, usually isn't going to scope packages like NPM does without some extra effort. Global or per-user scoping (the latter being functionally identical on any single-user machine) are more likely.