Skip to content
This repository has been archived by the owner on Aug 11, 2022. It is now read-only.

Commit

Permalink
Better explore, and document it.
Browse files Browse the repository at this point in the history
  • Loading branch information
isaacs committed Dec 6, 2010
1 parent 24d3ef9 commit 697744d
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 5 deletions.
16 changes: 16 additions & 0 deletions doc/explore.md
@@ -0,0 +1,16 @@
npm-explore(1) -- Browse an installed package
=============================================

## SYNOPSIS

npm explore <name>[@<version>] [<cmd>]

## DESCRIPTION

Spawn a subshell in the directory of the installed package specified.

If a command is specified, then it is run in the subshell, which then
immediately terminates.

Note that the package is *not* automatically rebuilt afterwards, so be
sure to use `npm rebuild <pkg>` if you make any changes.
16 changes: 11 additions & 5 deletions lib/explore.js
Expand Up @@ -2,7 +2,7 @@
// open a subshell to the package folder.

module.exports = explore
explore.usage = "npm explore <pkg>[@<version>]"
explore.usage = "npm explore <pkg>[@<version>] [<cmd>]"
explore.completion = function (args, index, cb) {
var installedPkgs = require("./utils/completion/installed-packages")
installedPkgs(args, index, true, false, cb)
Expand All @@ -13,12 +13,18 @@ var npm = require("../npm")
, path = require("path")

function explore (args, cb) {
var p = args[0]
if (args.length !== 1 || !p) return cb(edit.usage)
if (args.length < 1 || !args[0]) return cb(explore.usage)
var p = args.shift()
args = args.join(" ").trim()
if (args) args = ["-c", args]
else args = []
p = p.split("@")
var editor = npm.config.get("editor")
, n = p.shift()
, v = p.join("@") || "active"
console.log("Type 'exit' or ^D when finished")
exec("bash", [], null, true, path.join(npm.dir, n, v, "package"), cb)
, cwd = path.join(npm.dir, n, v, "package")
if (!args.length) console.log(
"\nExploring "+cwd+"\n"+
"Type 'exit' or ^D when finished\n")
exec("bash", args, null, true, cwd, cb)
}

0 comments on commit 697744d

Please sign in to comment.