Live data from Hacker News

Show HN: Auto install npm dependencies as you code

npmjs.com

11–20 of 80 posts

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

#11

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

The AST? What AST is that? You don't get access to an AST.

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

#13
post #4

So I can make a malicious module called expres and another one called expresss and screw with ppls machines?

This. I love that the Node community enjoys innovating for convenience, but ideas like this one are less than half-baked from a security perspective. Just make a few typo'd popular packages, and use npm install scripts [1] and you have a very easy remote code execution vector on developer workstations. The bigger problem I see is that npm is a circus. No package signing and a ridiculous debate on why that's been goin…

> It's not usually core, it's all the plugins by authors of unknown provenance and skill.

This is otherwise known as an active developer community and is a good thing. In any open library ecosystem, it's ultimately up to the developer to carefully choose and vet third-party modules. There isn't any substitute for that.

The alternative is a tightly controlled standard library, but that isn't npm's stated goal. Such a controlled, curated, audited standard library is, however, something that could be built on top of npm, but obviously not vice versa.

So npm being a circus is, in the grander scheme of things, a good thing. Novice programmers will necessarily produce novice code.

edit: if it wasn't clear, I completely agree about the security risks of this project.

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

#14
post #11

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

The AST? What AST is that? You don't get access to an AST.

The AST you get from any of a wide variety of parsers, of which esprima may still be only the most popular of many.

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

#15
post #4

So I can make a malicious module called expres and another one called expresss and screw with ppls machines?

This is one of the benefits of using a container-based system like the one we designed for https://tonicdev.com . On Tonic, you get the same conveniences displayed here (actually better since all the packages already exist, so no install-wait time), but the entire development process happens in a container. Once you're ready to move on, you can download the project with shrink-wrap to get identical behavior, but until then you can more freely try whatever you'd like.

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

#16
post #11

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

The AST? What AST is that? You don't get access to an AST.

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.

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

#17

I am very interested in this for projects that I'm just starting and don't expect to run on anything but my machine. It's an annoying break of flow to be writing code and say "Crap, I need request or lodash" and have to stop, npm install --save, require, then go back to what I'm doing. Yes I still have to require it in but for side projects/one-offs I find this pretty cool.

This might just be a question of workflow optimization. Have you considered waiting to do the installs until you've paused in writing code anyway, or using your editor's shell command execution capability (if any) to fire off these installs and let them run in background while you continue to work?

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

#18

Given that in npm v3 the order of installation determines where things are installed, this seems like it might cause some interesting bugs that never happen on the developer's machine. :)

I'm not sure how this could happen as one shouldn't be depending on the directory structure in the node_modules/ folder anyway. Do you have an example of where this might cause issues?

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

#20
post #13

Earlier quoted context omitted.

This. I love that the Node community enjoys innovating for convenience, but ideas like this one are less than half-baked from a security perspective. Just make a few typo'd popular packages, and use npm install scripts [1] and you have a very easy remote code execution vector on developer workstations. The bigger problem I see is that npm is a circus. No package signing and a ridiculous debate on why that's been goin…

> It's not usually core, it's all the plugins by authors of unknown provenance and skill. This is otherwise known as an active developer community and is a good thing. In any open library ecosystem, it's ultimately up to the developer to carefully choose and vet third-party modules. There isn't any substitute for that. The alternative is a tightly controlled standard library, but that isn't npm's stated goal. Such a…

What kind of vetting is occurring when you're automatically installing npm modules as you code?

But, "Novice programmers will necessarily produce novice code."

Having had my own variety of experience with CPAN, PEAR, Tcl's package thing, C by way of building my own RPMs and DEBs, and now watching the ongoing trainwreck that is npm, yes. You're right about that.

Post reply on HN