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-09-11 00:24:13 +0300
committerRuy Adorno <ruyadorno@hotmail.com>2020-09-16 18:18:48 +0300
commit7b3cfbd91b48bec0b3812339f3eeef79fec7f326 (patch)
tree78caed127d20b10eafbeb045588c7c9a590cf7dd /test/lib/link.js
parent2019abdf159eb13c9fb3a2bd2f35897a8f52b0d9 (diff)
fix: reenable npm link from registry
Being able to npm link a package that is not currently available in the global space should still be a supported feature, this change puts that functionality back in place but also improves it by avoiding reify any package that may already be found in the global directory.
Diffstat (limited to 'test/lib/link.js')
-rw-r--r--test/lib/link.js77
1 files changed, 75 insertions, 2 deletions
diff --git a/test/lib/link.js b/test/lib/link.js
index 056b0d3d6..aafdb8188 100644
--- a/test/lib/link.js
+++ b/test/lib/link.js
@@ -28,9 +28,11 @@ const printLinks = async (opts) => {
const arb = new Arborist(opts)
const tree = await arb.loadActual()
const linkedItems = [...tree.inventory.values()]
+ .sort((a, b) => a.pkgid.localeCompare(b.pkgid))
for (const item of linkedItems) {
- if (item.target)
+ if (item.target) {
res += `${item.path} -> ${item.target.path}\n`
+ }
}
return res
}
@@ -128,6 +130,12 @@ t.test('link global linked pkg to local nm when using args', (t) => {
version: '1.0.0'
})
},
+ 'link-me-too': {
+ 'package.json': JSON.stringify({
+ name: 'link-me-too',
+ version: '1.0.0'
+ })
+ },
'scoped-linked': {
'package.json': JSON.stringify({
name: '@myscope/linked',
@@ -155,8 +163,72 @@ t.test('link global linked pkg to local nm when using args', (t) => {
npm.globalDir = resolve(testdir, 'global-prefix', 'lib', 'node_modules')
npm.prefix = resolve(testdir, 'my-project')
+ const _cwd = process.cwd()
+ process.chdir(npm.prefix)
+
+ reifyOutput = async () => {
+ reifyOutput = undefined
+ process.chdir(_cwd)
+
+ const links = await printLinks({
+ path: npm.prefix
+ })
+
+ t.matchSnapshot(links, 'should create a local symlink to global pkg')
+ }
+
+ // installs examples for:
+ // - test-pkg-link: pkg linked to globalDir from local fs
+ // - @myscope/linked: scoped pkg linked to globalDir from local fs
+ // - @myscope/bar: prev installed scoped package available in globalDir
+ // - a: prev installed package available in globalDir
+ // - file:./link-me-too: pkg that needs to be reified in globalDir first
+ link([
+ 'test-pkg-link',
+ '@myscope/linked',
+ '@myscope/bar',
+ 'a',
+ 'file:../link-me-too'
+ ], (err) => {
+ t.ifError(err, 'should not error out')
+ })
+})
+
+t.test('link pkg already in global space', (t) => {
+ t.plan(2)
+
+ const testdir = t.testdir({
+ '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')
+
+ const _cwd = process.cwd()
+ process.chdir(npm.prefix)
+
reifyOutput = async () => {
reifyOutput = undefined
+ process.chdir(_cwd)
const links = await printLinks({
path: npm.prefix
@@ -170,7 +242,8 @@ t.test('link global linked pkg to local nm when using args', (t) => {
// - @myscope/linked: scoped pkg linked to globalDir from local fs
// - @myscope/bar: prev installed scoped package available in globalDir
// - a: prev installed package available in globalDir
- link(['test-pkg-link', '@myscope/linked', '@myscope/bar', 'a'], (err) => {
+ // - file:./link-me-too: pkg that needs to be reified in globalDir first
+ link(['@myscope/linked'], (err) => {
t.ifError(err, 'should not error out')
})
})