It would be nice if npm scripts defined in package.json were able to be automatically detected as tasks (much like gulp, grunt, and jake). It seems like the processRunnerDetector would need to be augmented to add support, parsing the output of npm run or npm run-script (same thing / alias)
Currently I have the following tasks.json defined (credit to David Anson)
{
"version": "0.1.0",
"command": "npm",
"windows": {
"command": "npm.cmd"
},
"tasks": [
{
// Build task, Ctrl+Shift+B
// "npm install --loglevel info"
"taskName": "install",
"isBuildCommand": true,
"args": ["--loglevel", "info"]
},
{
// Test task, Ctrl+Shift+T
// "npm test"
"taskName": "test",
"isTestCommand": true
},
{
// "npm run lint"
"taskName": "lint",
"runtimeArgs": ["run"]
},
{
// "npm run create-migration"
"taskName": "create-migration",
"runtimeArgs": ["run"]
}
]
}
As a side note, I have some scripts that take in user input, either from stdin, or from environment variables. For example I deploy to my cloud provider of choice using VERSION=1.0 npm run deploy so it would be nice if I could specify an environment variable ahead of time. Also, other scripts take in user input on stdin, such as npm run create-migration <name> which requires the user to specify a name for the new database migration file.
A better workaround currently is to use taskSelector because that's what the property is for ;)
The extra windows setting is also not needed. npm test is just a shortcut for npm run test.
{
"version": "0.1.0",
"command": "npm",
"isShellCommand": true,
"taskSelector": "run",
"showOutput": "silent",
"tasks": [
{
"taskName": "watch",
"isWatching": true,
"problemMatcher": "$tsc-watch"
},
{
"taskName": "compile",
"isBuildCommand": true,
"problemMatcher": "$tsc"
},
{
"taskName": "publish",
"showOutput": "always"
}
]
}
But I agree that if VS Code detects Gulp and Grunt tasks, it should also detect npm scripts.
Hmm, I tried setting taskSelector but it doesn't appear to work and just dumps npm help (what you'd get either typing just npm or npm invalidscriptname)
Usage: npm <command>
where <command> is one of:
access, add-user, adduser, apihelp, author, bin, bugs, c,
cache, completion, config, ddp, dedupe, deprecate, dist-tag,
dist-tags, docs, edit, explore, faq, find, find-dupes, get,
help, help-search, home, i, info, init, install, issues, la,
link, list, ll, ln, login, logout, ls, outdated, owner,
pack, ping, prefix, prune, publish, r, rb, rebuild, remove,
repo, restart, rm, root, run-script, s, se, search, set,
show, shrinkwrap, star, stars, start, stop, t, tag, team,
test, tst, un, uninstall, unlink, unpublish, unstar, up,
update, upgrade, v, verison, version, view, whoami
npm <cmd> -h quick help on <cmd>
npm -l display full usage info
npm faq commonly asked questions
npm help <term> search for help on <term>
npm help npm involved overview
Specify configs in the ini-formatted file:
/Users/smlynch/.npmrc
or on the command line via: npm <command> --key value
Config info can be viewed via: npm help config
[email protected] /usr/local/lib/node_modules/npm
:+1: to this - I think it's higher priority than 'would be nice' :)
npm scripts are pretty much a standard "node" feature
Also, it should be trivial to read the package.json
Is this not supported?
Selecting npm generates a task.json for me.

@waderyan I think this thread is all about those npm scripts being detected without generating a task.json
I see. Thanks @slowmove
This extensions is available that offers this functionality: https://marketplace.visualstudio.com/items?itemName=eg2.vscode-npm-script
Is this sufficient?
Why is there build-in auto detection for G ulp, Grunt and Jake - but not for npm ?
[Addressed in new terminal runner]
Will be addressed by the npm extension when the task API is official.
Looks like this went live with 1.14 (June update). I actually came here looking to tone auto-detection down a bit -- it's detecting all my pre/post tasks as well as the ones I actually want to run. It looks like it selects "configured" tasks first, so this isn't a huge issue, but it'd be nice to be able to hide some NPM tasks completely (and/or not show pre/post tasks in the first place).
@egamma please see https://github.com/Microsoft/vscode/issues/1777#issuecomment-314684785. We should not have pre post scripts auto detected.
Assigning to @egamma to address above issue.
@thw0rted oh, I missed that. Mainly as I now use npm from the terminal for all operations :)
Support auto detecting npm scripts is in 1.14. I've extracted the issue raised in https://github.com/Microsoft/vscode/issues/1777#issuecomment-314684785 into a separate issue #30843.
Closing this issue.
Most helpful comment
:+1: to this - I think it's higher priority than 'would be nice' :)
npm scripts are pretty much a standard "node" feature