Browse files

Use editor module

  • Loading branch information...
1 parent e2fab09 commit be097b9b785a3391e6b52ff74897732905a79e63 @isaacs isaacs committed Apr 28, 2013
Showing with 11 additions and 11 deletions.
  1. +2 −2 lib/config.js
  2. +6 −6 lib/edit.js
  3. +3 −3 lib/explore.js
View
4 lib/config.js
@@ -16,6 +16,7 @@ var log = require("npmlog")
, npmconf = require("npmconf")
, types = npmconf.defs.types
, ini = require("ini")
+ , editor = require("editor")
config.completion = function (opts, cb) {
var argv = opts.conf.argv.remain
@@ -93,8 +94,7 @@ function edit (cb) {
, "utf8"
, function (er) {
if (er) return cb(er)
- var editor = spawn(e, [f], {env: process.env, stdio: "inherit"})
- editor.on("close", cb)
+ editor(f, { editor: e }, cb)
}
)
})
View
12 lib/edit.js
@@ -10,21 +10,21 @@ var npm = require("./npm.js")
, spawn = require("child_process").spawn
, path = require("path")
, fs = require("graceful-fs")
+ , editor = require("editor")
function edit (args, cb) {
var p = args[0]
if (args.length !== 1 || !p) return cb(edit.usage)
- var editor = npm.config.get("editor")
- if (!editor) return cb(new Error(
+ var e = npm.config.get("editor")
+ if (!e) return cb(new Error(
"No editor set. Set the 'editor' config, or $EDITOR environ."))
p = p.split("/")
.join("/node_modules/")
.replace(/(\/node_modules)+/, "/node_modules")
- fs.lstat(path.resolve(npm.dir, p), function (er) {
+ var f = path.resolve(npm.dir, p)
+ fs.lstat(f, function (er) {
if (er) return cb(er)
-
- var ed = spawn(editor, [path.resolve(npm.dir, p)], {stdio: "inherit"})
- ed.on("close", function (er) {
+ editor(f, { editor: e }, function (er) {
if (er) return cb(er)
npm.commands.rebuild(args, cb)
})
View
6 lib/explore.js
@@ -17,16 +17,16 @@ function explore (args, cb) {
if (args) args = ["-c", args]
else args = []
- var editor = npm.config.get("editor")
- , cwd = path.resolve(npm.dir, p)
+ var cwd = path.resolve(npm.dir, p)
+ var s = npm.config.get("shell")
fs.stat(cwd, function (er, s) {
if (er || !s.isDirectory()) return cb(new Error(
"It doesn't look like "+p+" is installed."))
if (!args.length) console.log(
"\nExploring "+cwd+"\n"+
"Type 'exit' or ^D when finished\n")
- var shell = spawn(npm.config.get("shell"), args, {cwd: cwd, stdio: "inherit"})
+ var shell = spawn(s, args, {cwd: cwd, stdio: "inherit"})
shell.on("close", function (er) {
// only fail if non-interactive.
if (!args.length) return cb()

0 comments on commit be097b9

Please sign in to comment.