Live data from Hacker News

Show HN: Auto install npm dependencies as you code

npmjs.com

41–50 of 80 posts

Re: Show HN: Auto install npm dependencies as you code

#41

Dependency installation should be a bit frictional...

That's interesting, tell me more?

I could be wrong, but I think he might mean that people should take care not to add too many dependencies to their project - if it's too easy, then it might result in unnecessary dependencies and brittle code.

However, I'm not sure I agree with the statement - you could use this tool and still have the discipline not to pull in random packages.

Re: Show HN: Auto install npm dependencies as you code

#42

Regular expressions are a very naive way of detecting calls to 'require'. For correctness you're better off recursively walking the AST. I've successfully used Detective in a couple of my personal projects to find all require statements. Relevant issue on Detective: https://github.com/substack/node-detective/issues/8

In practice regex gets all the require calls. And in many situations the very small percent of errors is outweighed by the huge advantage in performance that a simple regex provides.

So i wouldn't call regex a 'very naive' choice, since people making it are aware of tradeoffs and pick regex intentionally.

Re: Show HN: Auto install npm dependencies as you code

#43
post #24
post #16

Earlier quoted context omitted.

It has to open and read a .js file already, it can certainly turn that into the representative AST for said file and then use the data from that. It will be slower, but it will also be more accurate and less likely to turn up false positives or miss things.

It has to parse a javascript file, which isn't trivial. The reason they use regular expression is because implementing a javascript parser isn't an easy problem to solve fast, even though the grammar is available.

You downloading megabytes over network and performing disk IO with it. What's the problem with 100 milliseconds of file parsing?

Re: Show HN: Auto install npm dependencies as you code

#44

Earlier quoted context omitted.

Typos with npm have always allowed RCE. You can have typos while doing $npm install ... .

Right, but when you are running npm install you know you are installing and so you know you should be careful, and only hit return if you are sure it is right. With this, you have to be careful the WHOLE time you are typing. You normally don't worry about hitting return in your editor causing RCE.

Good point, any ideas on handling this better?

Opened an issue here: https://github.com/siddharthkp/auto-install/issues/2

Re: Show HN: Auto install npm dependencies as you code

#45

I mean, wow. I've seen half-baked ideas before, but this takes the cake. Typos now equal remote code execution, and it's even easier to enter dependancy hell, because deps are now implicit.

Exactly how is any of this different than installing via the command line?

Re: Show HN: Auto install npm dependencies as you code

#46

Earlier quoted context omitted.

Right, but when you are running npm install you know you are installing and so you know you should be careful, and only hit return if you are sure it is right. With this, you have to be careful the WHOLE time you are typing. You normally don't worry about hitting return in your editor causing RCE.

Good point, any ideas on handling this better? Opened an issue here: https://github.com/siddharthkp/auto-install/issues/2

I don't really know if there is a way to fix this issue... unless you had some sort of whitelist of acceptable packages, and a prompt if you try to install a non-whitelisted package.

One other possibility is to have a delay, so that it waits an amount of time before installing, to give a chance to catch and fix the typo.

Re: Show HN: Auto install npm dependencies as you code

#47

Regular expressions are a very naive way of detecting calls to 'require'. For correctness you're better off recursively walking the AST. I've successfully used Detective in a couple of my personal projects to find all require statements. Relevant issue on Detective: https://github.com/substack/node-detective/issues/8

Good point, let me look into that.

Re: Show HN: Auto install npm dependencies as you code

#48

Earlier quoted context omitted.

Typos with npm have always allowed RCE. You can have typos while doing $npm install ... .

Right, but when you are running npm install you know you are installing and so you know you should be careful, and only hit return if you are sure it is right. With this, you have to be careful the WHOLE time you are typing. You normally don't worry about hitting return in your editor causing RCE.

If I understand correctly, this doesn't happen while you type, it happens after you save the file. Not much difference in care needed between saving a file or hitting enter IMO, if you are aware of the consequences. Also, its not like you don't know the thing is running - you'll subconsciously double check you typed the repo correctly before you save, knowing it will invoke an install.

Re: Show HN: Auto install npm dependencies as you code

#49

I mean, wow. I've seen half-baked ideas before, but this takes the cake. Typos now equal remote code execution, and it's even easier to enter dependancy hell, because deps are now implicit.

I actually looked at the code for 5 minutes. This module is vulnerable to arbitrary code execution simply by having a malicious JavaScript file in a directory or subdirectory underneath where `auto-install` is run, without the user even needing to make a typo due to its design.

The documentation currently just says 'avoid typos'.

siddharthkp: please give me a way to contact you. see my contact info on my profile.

Post reply on HN