-
Notifications
You must be signed in to change notification settings - Fork 29.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
PR-URL: #36543 Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Ruy Adorno <ruyadorno@github.com> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
- Loading branch information
1 parent
0e96dc1
commit d0b1b13
Showing
41 changed files
with
2,217 additions
and
562 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,52 +1,36 @@ | ||
// npm edit <pkg> | ||
// open the package folder in the $EDITOR | ||
|
||
module.exports = edit | ||
edit.usage = 'npm edit <pkg>[/<subpkg>...]' | ||
const { resolve } = require('path') | ||
const fs = require('graceful-fs') | ||
const { spawn } = require('child_process') | ||
const npm = require('./npm.js') | ||
const usageUtil = require('./utils/usage.js') | ||
const splitPackageNames = require('./utils/split-package-names.js') | ||
|
||
edit.completion = require('./utils/completion/installed-shallow.js') | ||
|
||
var npm = require('./npm.js') | ||
var path = require('path') | ||
var fs = require('graceful-fs') | ||
var editor = require('editor') | ||
var noProgressTillDone = require('./utils/no-progress-while-running').tillDone | ||
const usage = usageUtil('edit', 'npm edit <pkg>[/<subpkg>...]') | ||
const completion = require('./utils/completion/installed-shallow.js') | ||
|
||
function edit (args, cb) { | ||
var p = args[0] | ||
if (args.length !== 1 || !p) | ||
return cb(edit.usage) | ||
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('/') | ||
// combine scoped parts | ||
.reduce(function (parts, part) { | ||
if (parts.length === 0) | ||
return [part] | ||
|
||
var lastPart = parts[parts.length - 1] | ||
// check if previous part is the first part of a scoped package | ||
if (lastPart[0] === '@' && !lastPart.includes('/')) | ||
parts[parts.length - 1] += '/' + part | ||
else | ||
parts.push(part) | ||
|
||
return parts | ||
}, []) | ||
.join('/node_modules/') | ||
.replace(/(\/node_modules)+/, '/node_modules') | ||
var f = path.resolve(npm.dir, p) | ||
fs.lstat(f, function (er) { | ||
if (er) | ||
return cb(er) | ||
editor(f, { editor: e }, noProgressTillDone(function (er) { | ||
if (er) | ||
return cb(er) | ||
npm.commands.rebuild(args, cb) | ||
})) | ||
if (args.length !== 1) | ||
return cb(usage) | ||
|
||
const path = splitPackageNames(args[0]) | ||
const dir = resolve(npm.dir, path) | ||
|
||
fs.lstat(dir, (err) => { | ||
if (err) | ||
return cb(err) | ||
|
||
const [bin, ...args] = npm.config.get('editor').split(/\s+/) | ||
const editor = spawn(bin, [...args, dir], { stdio: 'inherit' }) | ||
editor.on('exit', (code) => { | ||
if (code) | ||
return cb(new Error(`editor process exited with code: ${code}`)) | ||
|
||
npm.commands.rebuild([dir], cb) | ||
}) | ||
}) | ||
} | ||
|
||
module.exports = Object.assign(edit, { completion, usage }) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.