Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/npm/cli.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRuy Adorno <ruyadorno@hotmail.com>2020-11-27 07:15:14 +0300
committerRuy Adorno <ruyadorno@hotmail.com>2020-11-27 19:38:01 +0300
commit9c3413fbcb37e79fc0b3d980e0b5810d7961277c (patch)
tree0632d73fa6309e0e0c7b6d15f8db449e76430c68
parent523cf69acbda17e13fdbfba068d7231d2d9e8908 (diff)
fix: npm link <pkg> should not save package.json
When running `npm link <pkg>` it should not save the new item to the currrent dependencies of that package.json file. Fixes: #2034 Co-authored-by: Darcy Clarke <darcy@darcyclarke.me> PR-URL: https://github.com/npm/cli/pull/2245 Credit: @ruyadorno Close: #2245 Reviewed-by: @darcyclarke
-rw-r--r--lib/link.js9
-rw-r--r--test/lib/link.js12
2 files changed, 20 insertions, 1 deletions
diff --git a/lib/link.js b/lib/link.js
index bee44d43a..3f0a51808 100644
--- a/lib/link.js
+++ b/lib/link.js
@@ -112,14 +112,23 @@ const linkInstall = async args => {
)
}
+ // npm link should not save=true by default unless you're
+ // using any of --save-dev or other types
+ const save =
+ Boolean(npm.config.find('save') !== 'default' || npm.flatOptions.saveType)
+
// create a new arborist instance for the local prefix and
// reify all the pending names as symlinks there
const localArb = new Arborist({
...npm.flatOptions,
path: npm.prefix,
+ save,
})
await localArb.reify({
+ ...npm.flatOptions,
+ path: npm.prefix,
add: names.map(l => `file:${resolve(globalTop, 'node_modules', l)}`),
+ save,
})
await reifyFinish(localArb)
diff --git a/test/lib/link.js b/test/lib/link.js
index 9b7c5df64..a478259f7 100644
--- a/test/lib/link.js
+++ b/test/lib/link.js
@@ -23,6 +23,7 @@ const npm = {
get () {
return false
},
+ find () {},
},
}
const printLinks = async (opts) => {
@@ -196,7 +197,7 @@ t.test('link global linked pkg to local nm when using args', (t) => {
})
t.test('link pkg already in global space', (t) => {
- t.plan(2)
+ t.plan(3)
const testdir = t.testdir({
'global-prefix': {
@@ -224,17 +225,26 @@ t.test('link pkg already in global space', (t) => {
npm.globalDir = resolve(testdir, 'global-prefix', 'lib', 'node_modules')
npm.prefix = resolve(testdir, 'my-project')
+ npm.config.find = () => 'default'
+
const _cwd = process.cwd()
process.chdir(npm.prefix)
reifyOutput = async () => {
reifyOutput = undefined
process.chdir(_cwd)
+ npm.config.find = () => null
const links = await printLinks({
path: npm.prefix,
})
+ t.equal(
+ require(resolve(testdir, 'my-project', 'package.json')).dependencies,
+ undefined,
+ 'should not save to package.json upon linking'
+ )
+
t.matchSnapshot(links, 'should create a local symlink to global pkg')
}