Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Make `npm update` respond to the `--dev` flag #2835

Closed
homme opened this Issue · 3 comments

2 participants

@homme

Making npm update respond to the --dev flag in the same way that npm install currently does would be useful from a development point of view. This is really to do with speeding up multiple invocations of npm test.

As an example the following package.json requires the vows package to be present for running the tests. The presence of the pretest key ensures that running npm test works as expected as vows will be installed. However, vows is installed every time npm test is run:

{
    "name": "mypackage",
    "version": "0.0.1",
    "scripts": {
        "pretest": "npm install vows",
        "test": "./node_modules/.bin/vows --spec ./test/mytest.js"
    },
    "devDependencies": {
        "vows":  "*"
    }
}

The process could be streamlined if the value for pretest could be replaced with npm --dev true update: vows would only be installed the first time npm test was run, speeding up subsequent invocations of npm test.

Alternatively perhaps npm test could do an implicit check and install of devDependencies although that would be definitively tying devDependencies to npm test: devDepencencies might only be used for non test related things like documentation.

This could be solved by forcing npm test do an explicit check of devDependencies by making it aware of --dev in the same way as npm install currently is.

@timoxley
Collaborator

@homme are you this still having this issue? npm update now does update devDependencies if you pass --dev.

But I'm not sure that's the core of your issue here.

The current state of affairs is thus:

when npm install is run inside a module directory, unless the --production flag is also passed, it will always install development dependencies for the current package, (but not any of the modules in node_modules).

So in your case, you shouldn't need the pretest script at all, vows should just be installed.

In addition, you don't need the ./node_modules/.bin/' to callvows, all npm scripts get that automatically added to their$PATH`.

Your package.json should work just fine like so:

{
    "name": "mypackage",
    "version": "0.0.1",
    "scripts": {
        "test": "vows --spec test/mytest.js"
    },
    "devDependencies": {
        "vows":  "*"
    }
}

#4430

@homme homme referenced this issue from a commit in geo-data/node-mapserv
@homme homme Clean up npm test invocation
This implements the suggestions at
<npm/npm#2835 (comment)>.
c33b493
@homme homme referenced this issue from a commit in geo-data/node-mapcache
@homme homme Clean up npm test invocation
This implements the suggestions at
<npm/npm#2835 (comment)>.
8ecf6a1
@homme

@timoxley many thanks for the update and explanation: I've implemented your suggestions and everything seems to run perfectly!

@homme homme closed this
@timoxley
Collaborator

:tada:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.