News for hackers. Stuff that matters.
Re:Kotlin for JavaScript by egeozcan on Sunday March 27, 2022 @01:52AM (#30818038)
NPM has had package locking since what feels like a million releases.

I wish the Java community (which I'm actually also a part of) would stop rejecting everything that's not "the Java/enterprise way" and be humbled by exploring better alternatives, or alternatives with different tradeoffs for once.

Re:Kotlin for JavaScript by Larrikin on Sunday March 27, 2022 @02:42AM (#30818257)
I think his point was more of a cultural difference. My IDE actually lints non pinned dependencies as a potential source of errors, whereas in the JS world it seems very common to not pin.
Re:Kotlin for JavaScript by egeozcan on Sunday March 27, 2022 @03:57AM (#30818543)
npm uses locks per default, and to disable that, you need to create a file called .npmrc at the root of the project and add package-lock=false to it. I don't think any popular project does that.

It's also a common practice to use npm ci in all build scripts to never update packages even if they declared a version range in package.json, and package.lock not being able to satisfy package.json won't cause lock to get overwritten.

Re:Kotlin for JavaScript by gkop on Sunday March 27, 2022 @11:54AM (#30821227)
The fact that npm ci does what npm i should do (well, except for starting from scratch each time [0]), says it all. npm is a joke.

[0] Yes, that's right. npm doesn't allow to to install incrementally respecting the lockfile. You can install incrementally with npm i and roll the dice, or install from scratch with npm ci to respect the lockfile. Basically the npm authors took the rm -rf node_modules/ workaround and productized it.

Re:Kotlin for JavaScript by egeozcan on Sunday March 27, 2022 @12:43PM (#30821669)
If you have a package.json and you run npm i it generates a package-lock.json from it.

If you run npm i against that package.json and package-lock.json, the latter will never be updated, even if the package.json would be happy with newer versions.

If you manually edit your package.json to have different ranges and run npm i and those ranges aren't compatible with your package-lock.json then the latter will be updated with version that are compatible with your package.json. Further runs of npm i will be as with 2 above.

But of course you may think this behavior is a joke, I do not.

Re:Kotlin for JavaScript by gkop on Sunday March 27, 2022 @03:05PM (#30823040)
How can I incrementally install exactly what’s in the lockfile, raising an error if it’s incompatible with package.json? This is what I expect npm i to do, but as far as I can tell, npm simply doesn’t support.
Re:Kotlin for JavaScript by egeozcan on Sunday March 27, 2022 @06:13PM (#30824675)
> raising an error if it’s incompatible with package.json

How? Why? What's your use-case?

Re:Kotlin for JavaScript by gkop on Sunday March 27, 2022 @07:29PM (#30825224)
Two essential use cases:

1) For local development, I’m seeking a command I can use after pulling, to safely and quickly install any needed dependencies that have been added by others. Currently I use npm ci but it’s absurdly overkill (and therefore very slow).

2) For CI itself. I cache node_modules/ across builds, which significantly speeds up my builds. Currently I npm i, and check if lockfile changed, and if it did, checkout lockfile and npm ci.

I shouldn’t need to npm ci ever unless my node_modules/ became corrupt for some reason. Because npm ci ALWAYS blows away node_modules/, it’s not a reasonable piece of everyday functionality, it’s just a semantically ambiguous way to rm -rf node_modules/ && npm i -—respect-lockfile (made up flag I wish existed). The obvious explanation is that the npm developers couldn’t figure out how to reliably reconcile node_modules/ with the lockfile, so just gave up and shipped npm ci.

Or if the rm -rf node_modules/ isn’t strictly necessary for npm ci, then give me npm ci —-skip-drop-node-modules, that would be equivalent and fine for my purposes.

Re:Kotlin for JavaScript by egeozcan on Monday March 28, 2022 @02:06AM (#30827580)
if npm i is overwriting the lock file, it means someone updated the package.json, and didn't update the lock file (as in, did not install the update).

btw ci is super fast (caching) unless you have one of those modules that download the whole effing chromium after install (brain dead behavior).

Re:Kotlin for JavaScript by gkop on Monday March 28, 2022 @10:49AM (#30831049)
I wish it were so simple. Maybe I’ve just been bit by too many bugs in npm over time, but I repeatedly see npm i change the lockfile when incrementally installing a new package that was correctly locked. Fortunately at least npm ci has always been reliable.

What do you mean ci is super fast? Is it intended to be caching the packages somewhere other than node_modules?

Re:Kotlin for JavaScript by egeozcan on Monday March 28, 2022 @01:42PM (#30833272)
> I repeatedly see npm i change the lockfile when incrementally installing a new package that was correctly locked

There's been some bugs in the implementation but never had anything in the last few years, other than some people accidentally committing unapplied package.json changes, and built a precommit hook and a server-side check for that in many projects.

> What do you mean ci is super fast? Is it intended to be caching the packages somewhere other than node_modules?

Yes: https://docs.npmjs.com/cli/v6/commands/npm-cache#configurati... . If you want a more Java-like (to be more accurate, artifactory-like) experience, you can also opt-in for Verdaccio: https://verdaccio.org/ You can also use the artifactory itself: https://www.jfrog.com/confluence/display/RTF/Npm+Registry

I had more success with verdaccio though.

Quality of the packages has been discussed to death, say about that anything you like, but npm has been rock-solid for me in the last few years. Definitely not a joke IMHO.

Re:Kotlin for JavaScript by catdog on Sunday March 27, 2022 @02:40AM (#30818249)
Re:Kotlin for JavaScript by egeozcan on Sunday March 27, 2022 @03:51AM (#30818510)
I wasn't arguing that gradle didn't have such a mechanism but thanks :)