News for hackers. Stuff that matters.
Re:Node_modules: One character saved 50 GB of disk space by eric4smith on Friday September 30, 2022 @05:47PM (#33041229)
The worst part about all these node modules is the little small silly ones that do something really inane - like to just get the current year.

I said the same thing about some ruby gems years ago and thankfully that’s a little bit sane now.

I don’t use JS that often. But recently I looked at the dependencies for some library I was using and I was astonished at the literally hundreds of tiny modules that were being used.

And it gets even worse - those tiny little modules have their dependencies too.

Amazing.

Re:Node_modules: One character saved 50 GB of disk space by torgard on Friday September 30, 2022 @06:25PM (#33041552)
Someone linked me to 1-liners[0], which is - you guessed it - a bunch of one-liners. I think it's nice to have as a reference. But a dependency? Really?

My least favorite is assign.

Not only does JavaScript feature that natively (though I suppose the library may predate widespread support for Object.assign), the 1-liner assign flips the order of the parameters!

    assign({ a: true }, { a: false }) -> { a: true }
    Object.assign({ a: true }, { a: false }) -> { a: false }
And most of them are just straight-up pointless! Like, let's introduce a dependency for decrement lol

EDIT: In looking up whether the 1-liners assign predated widespread Object.assign support, I found that their implementation - confusingly named extend[1] at first - literally used Object.assign from the very beginning. And they still chose to mess with the parameter order. For shame lol

[0] https://github.com/1-liners/1-liners

[1] https://github.com/1-liners/1-liners/blob/7c1f8d51df4b4b3e0a...

Re:Node_modules: One character saved 50 GB of disk space by jeroenhd on Friday September 30, 2022 @07:15PM (#33041922)
> Like, let's introduce a dependency for decrement lol

Here's a package that basically does that: https://www.npmjs.com/package/number-precision

Not entirely unreasonable as all `number`s are floats by default in JS, but the implementation of the entire package (https://github.com/nefe/number-precision/blob/master/src/ind...) is less than 100 lines of code and actually contains a method called "minus".

The very worst JS packages I've seen have got to be is-odd and is-even. 430,796 and 202,268 downloads every week, I kid you not!

Re:Node_modules: One character saved 50 GB of disk space by viraptor on Friday September 30, 2022 @07:35PM (#33042091)
Seems like a perfect candidate for a drive by fix. If you see it in your dependency tree, fix it in the project that uses it.
Re:Node_modules: One character saved 50 GB of disk space by samatman on Friday September 30, 2022 @07:37PM (#33042119)
It would appear this argument order is due to Principle 5: Data comes last, for consistent currying.

You might not like it, or the library (I don't write JS on purpose, so no opinion), but it's right there in the README.

Re:Node_modules: One character saved 50 GB of disk space by torgard on Saturday October 01, 2022 @08:40PM (#33051578)
I was not aware of the data-last convention. Thanks! Makes a lot of sense.

My mental model of assign was backwards, and it took me a while to comprehend why their implementation would be data-last.

So, the data is the object that is being modified? And the idea is it lets you write stuff like this more easily:

    const addStuffToObject = stuff -> object -> assign({ "some_stuff": stuff }, object);
    const addWeirdStuff = addStuffToObject("weird stuff");
    const weirdObj = addWeirdStuff({ "foo": "bar" });
Re:Node_modules: One character saved 50 GB of disk space by samatman on Sunday October 02, 2022 @07:22AM (#33054944)
Yes, and this sort of application (pun intended) is what the one-liner library is for.

If you have a function isEqualTo(a, b), you can curry(isEqualTo, 5) and filter with it.

`assign` could be used in the same way for assigning/overwriting the same field in an array of Objects, and so on.

Re:Node_modules: One character saved 50 GB of disk space by abraham on Friday September 30, 2022 @08:53PM (#33042657)
It's got 2-3000 installs/week so not many people are using it.

https://www.npmjs.com/package/1-liners

Re:Node_modules: One character saved 50 GB of disk space by alpaca128 on Friday September 30, 2022 @05:57PM (#33041335)
A project I've been working on has roughly 40 dependencies. If you run `npm install` it'll pull about 1050 npm packages.

Change one minor version number and everything breaks. Forget one dependency and npm will not tell you that a dependency is missing but instead it'll complain that Steam has a broken link in the home directory (this is a known open issue for years and the only two solutions are to uninstall Steam or to use a Docker container)

Needless to say I am not a fan of large web projects.

Re:Node_modules: One character saved 50 GB of disk space by rglover on Friday September 30, 2022 @06:21PM (#33041522)
I don't understand why you're getting downvoted. I'm a JS developer (and framework developer) and what you describe is a serious problem. It's great that there's so many problems solved, but some stuff is just a one or two liner that should be in your own app's /lib, not a dependency.

This is one reason I like Deno's idea of having a standard library (I just wish Ryan would have proposed that for Node directly instead of creating a brand new runtime).

Re:Node_modules: One character saved 50 GB of disk space by monlockandkey on Friday September 30, 2022 @06:26PM (#33041559)
The solution to all this dependency mess if for NPM to make a standard library. Yeah that sounds crazy and weird. But they are in the best place to make a unified standard library for Javascript. This would bypass all the junk transitive dependencies and have more libraries rely on a centralised but standard library.
Re:Node_modules: One character saved 50 GB of disk space by comprev on Friday September 30, 2022 @06:01PM (#33041374)
Anyone who's run a CI platform for more than a few devs and NodeJS projects quickly bumps into inode problems unless they thought about build server filesystems in advance. Very quickly you end up with hundreds of thousands of minuscule files filling up the disk.
Re:Node_modules: One character saved 50 GB of disk space by encryptluks2 on Friday September 30, 2022 @05:47PM (#33041238)
Imagine how easy it would be to exploit one of those too.
Re:Node_modules: One character saved 50 GB of disk space by simonw on Friday September 30, 2022 @06:09PM (#33041447)
Right - every single dependency adds potentially another human maintainer who, if bribed or threatened, could release an update that exploits your project.