1 // npm explore <pkg>[@<version>]
2 // open a subshell to the package folder.
4 module.exports = explore
5 explore.usage = "npm explore <pkg> [ -- <cmd>]"
6 explore.completion = require("./utils/completion/installed-shallow.js")
8 var npm = require("./npm.js")
9 , spawn = require("./utils/spawn")
10 , path = require("path")
11 , fs = require("graceful-fs")
13 function explore (args, cb) {
14 if (args.length < 1 || !args[0]) return cb(explore.usage)
16 args = args.join(" ").trim()
17 if (args) args = ["-c", args]
20 var cwd = path.resolve(npm.dir, p)
21 var sh = npm.config.get("shell")
22 fs.stat(cwd, function (er, s) {
23 if (er || !s.isDirectory()) return cb(new Error(
24 "It doesn't look like "+p+" is installed."))
25 if (!args.length) console.log(
26 "\nExploring "+cwd+"\n"+
27 "Type 'exit' or ^D when finished\n")
30 var shell = spawn(sh, args, { cwd: cwd, stdio: "inherit" })
31 shell.on("close", function (er) {
32 // only fail if non-interactive.
33 if (!args.length) return cb()