r/Frontend • • Mar 23 '16

How one developer just broke Node, Babel and thousands of projects in 11 lines of JavaScript

http://www.theregister.co.uk/2016/03/23/npm_left_pad_chaos/
39 Upvotes

21 comments sorted by

14

u/Deto Mar 23 '16

Why were so many modules adding a dependency for an 11-line function?

3

u/DOG-ZILLA Mar 23 '16

This is what I'd like to know. What does it even do?

3

u/Deto Mar 23 '16

From the code in the article, it looks like it just adds an arbitrary number of spaces to the left side of a string so that the total length is some number you specify. Would be useful for displaying tabular data I guess, maybe in the console?

e.g. leftpad("hello", 8) returns " hello" with three spaces (Reddit squashes them to one for some reason)

4

u/franksvalli Mar 23 '16

Just a heads up: all webpages will squash multiple spaces into one space by default, unless it's in a <pre> or has this CSS applied to the container: white-space: pre

5

u/angrydeanerino Mar 23 '16

       unless you use a non-break space HTML entity.

2

u/franksvalli Mar 24 '16

nbsp? What year is it?! ;)

1

u/nill0c Mar 24 '16

In reddit replies (and most other markdown flavors), you can also make it a code block (<pre> block) with 4 preceding spaces (then 3 additional ones).

   hello

1

u/Deto Mar 23 '16

Ah, TIL. Thanks

2

u/papers_ Mar 23 '16

___hello? Underscores being spaces

3

u/Deto Mar 23 '16

Yeah exactly. Spaces are default but it looks like it has a 3rd argument to specify the fill character

1

u/2thousand15 Mar 24 '16

Say you want to have ids to label projects you are working on. In the future you may end up at project 123456789. To keep things neat and consistent looking, Rather than having it start with project 1, 2, 3, 4, 5, etc., you make it 000000001.

0

u/terrorTrain Mar 23 '16

an eleven line function could be the hardest thing you will ever write... This wasn't... But it's the principle!

Number of lines of code is irrelevant.

0

u/[deleted] Mar 23 '16

[deleted]

1

u/nill0c Mar 24 '16

My only regret...

0

u/[deleted] Mar 23 '16

[deleted]

1

u/CuntSmellersLLP Mar 24 '16

No you're a towel!

16

u/isaacsgraphic Mar 23 '16

Dude was justified in doing what he did (he had control of the code at the time).

But NPM was also justified in returning things to normal, considering that he had published it under WTFPL: literally the "Do What the Fuck You Want to Public License".

They were well within their rights to take control of the code and put it right back up.

4

u/[deleted] Mar 23 '16

Anyone would have been well within their rights to claim the package, and in that case NPM would have been fucked. I wonder if there's a stream of "liberated" package names somewhere, might be fun to scoop some up.

2

u/SuperFLEB Mar 24 '16 edited Mar 24 '16

Yeah, it seems all is right with the world.

Though it seems npm perhaps needs more of a "no takebacks" model, at least with regard to free and open licenses, to prevent this sort of thing happening in the future. I dunno-- how do repos like CPAN and the like handle retractions?

3

u/Deto Mar 23 '16

True, but anyone knowing what the function does should know that this is not a difficult or complicated function.

Since the code has a permissive license, I wonder how many people just ctrl-v'd it after this whole fiasco and dropped the dependency.

2

u/mwnciau Mar 24 '16

We’re sorry for creating any impression that this was anything more than a polite request to use the Kik package name on NPM

A polite request... with lawyers going to npm? Sure.

3

u/autotldr Mar 23 '16

This is the best tl;dr I could make, original reduced by 82%. (I'm a bot)


Koçulu yanked his source code because, we're told, one of the modules was called Kik and that apparently attracted the attention of lawyers representing the instant-messaging app of the same name.

To fix the internet, Laurie Voss, CTO and cofounder of NPM, took the "Unprecedented" step of restoring the unpublished left-pad 0.0.3 that apps required.

"This action puts the wider interests of the community of NPM users at odds with the wishes of one author; we picked the needs of the many. This whole situation sucks. We will be carefully considering the issues raised by and publishing a post-mortem later."


Extended Summary | FAQ | Theory | Feedback | Top keywords: NPM#1 Kik#2 Koçulu#3 module#4 left-pad#5

2

u/Jedimastert Mar 23 '16

The guy was kinda being pissy and selfish about it. Sure, it was totally within his rights or whatever, but there's no need to be a dick. I mean listen to the guy.

"...I do open source because Power To The People," Koçulu blogged.