diff --git a/tool.go b/tool.go index 0f1632b22..204a3da84 100644 --- a/tool.go +++ b/tool.go @@ -658,6 +658,7 @@ func runNode(script string, args []string, dir string) error { node.Stdin = os.Stdin node.Stdout = os.Stdout node.Stderr = os.Stderr + node.Env = setNodeEnv(dir) err := node.Run() if _, ok := err.(*exec.ExitError); err != nil && !ok { err = fmt.Errorf("could not run Node.js: %s", err.Error()) @@ -665,6 +666,19 @@ func runNode(script string, args []string, dir string) error { return err } +func setNodeEnv(dir string) []string { + nodePath := dir + "/node_modules" + + env := os.Environ() + for i, e := range env { + if strings.HasPrefix(e, "NODE_PATH=") { + env[i] = e + ":" + nodePath + return env + } + } + return append(env, "NODE_PATH="+nodePath) +} + type testFuncs struct { Tests []testFunc Benchmarks []testFunc