"bundle exec" style exec command #2460

Closed
wants to merge 6 commits into
from

10 participants

@beefsack

I've created a new command to execute commands using local binaries before global ones. The command auto completes based on which binaries are available in the node_modules/.bin.

Examples:
npm exec jasmine-node spec
npm exec jake build

Tested under Linux (arch) and Windows 7. I don't have an OSX machine to try it out on though.

@andriytyurnikov

feature is totally needed

@mullr

+1: This largely obliviates the need for global module installs during day-to-day development, which is a good thing.

@aq1018

+1

@xMartin

+1

@isaacs isaacs commented on the diff Nov 6, 2012
lib/exec.js
@@ -0,0 +1,38 @@
+module.exports = exec
+
+var npm = require("./npm.js")
+ , output = require("./utils/output.js")
@isaacs
npm member
isaacs added a line comment Nov 6, 2012

utils/output.js has been removed. Either use console.log for "normal" output, or require("npmlog") for log output.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@isaacs isaacs commented on the diff Nov 6, 2012
doc/cli/exec.md
@@ -0,0 +1,15 @@
+npm-exec(1) -- Execute command using local package bin
+====================================
+
+## SYNOPSIS
+
+ npm exec
@isaacs
npm member
isaacs added a line comment Nov 6, 2012

Synopsis should match usage string.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@isaacs
npm member

+1 on the feature, but the implementation is not correct here. For example, if you depend on grunt, and it's provided by a parent package's dependencies, then you won't be able to access the grunt binaries. Also, the npm config settings provided to scripts are not being set, etc.

A better approach would be to abstract out the utils/lifecycle.js module so that it was less scripts-object oriented, but used the same logic in a DRY fashion, rather than constructing a cmd string which sets a PATH environ. (The correct way to set an environment variable is via the env hash passed to child_process.spawn; lifecycle.js does this.)

Then, lifecycle.js can call the exec function with an additional environment variable specifying the scripts-specific stuff. (Ie, the npm_lifecycle_event and npm_lifecycle_script environment vars.)

@Domon

👍

@glenux

+1

@isaacs
npm member

+1 (If the things mentioned in #2460 (comment) are fixed, of course.)

@chakrit

Looked at the code, not sure if I could pull this off. Any chance of this getting implemented (properly) by the core team? :p

@isaacs
npm member

The issue to target for this is #3313

@isaacs isaacs closed this Apr 29, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment