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
path: root/test
diff options
context:
space:
mode:
authornlf <quitlahok@gmail.com>2021-01-13 20:12:42 +0300
committerMichael Garvin <gar+gh@danger.computer>2021-01-15 00:21:21 +0300
commit23df96d3394ba0b69a37f416d7f0c26bb9354975 (patch)
treefbf709ce03dc82678b1e152269f14b6f9651a786 /test
parentb0b0edf6de1678de7f4a000700c88daa5f7194ef (diff)
fix(link): already linked packages w/ global prefix
correctly identify already linked packages when global prefix is a symlink PR-URL: https://github.com/npm/cli/pull/2486 Credit: @nlf Close: #2486 Reviewed-by: @wraithgar
Diffstat (limited to 'test')
-rw-r--r--test/lib/link.js58
1 files changed, 58 insertions, 0 deletions
diff --git a/test/lib/link.js b/test/lib/link.js
index a478259f7..c39026a49 100644
--- a/test/lib/link.js
+++ b/test/lib/link.js
@@ -259,6 +259,64 @@ t.test('link pkg already in global space', (t) => {
})
})
+t.test('link pkg already in global space when prefix is a symlink', (t) => {
+ t.plan(3)
+
+ const testdir = t.testdir({
+ 'global-prefix': t.fixture('symlink', './real-global-prefix'),
+ 'real-global-prefix': {
+ lib: {
+ node_modules: {
+ '@myscope': {
+ linked: t.fixture('symlink', '../../../../scoped-linked'),
+ },
+ },
+ },
+ },
+ 'scoped-linked': {
+ 'package.json': JSON.stringify({
+ name: '@myscope/linked',
+ version: '1.0.0',
+ }),
+ },
+ 'my-project': {
+ 'package.json': JSON.stringify({
+ name: 'my-project',
+ version: '1.0.0',
+ }),
+ },
+ })
+ 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')
+ }
+
+ link(['@myscope/linked'], (err) => {
+ t.ifError(err, 'should not error out')
+ })
+})
+
t.test('completion', (t) => {
const testdir = t.testdir({
'global-prefix': {