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:
authornlf <quitlahok@gmail.com>2022-04-14 01:07:01 +0300
committerLuke Karrys <luke@lukekarrys.com>2022-04-20 02:22:20 +0300
commit0ebadf5b603368557e9e837a46ea5c59c2677a81 (patch)
tree41266961691be10397e1dd388fdd2f1476573cc4 /workspaces/arborist/test
parent3d964940f410052918e37a9b05818fe9dc4cd86a (diff)
feat(arborist): add support for installLinks
when set, installLinks instructs arborist to pack and extract a file: dependency rather than creating a symlink to it. this has the effect of also installing the dependencies for the linked dependency, though if local changes are made it also requires the user to reinstall the package
Diffstat (limited to 'workspaces/arborist/test')
-rw-r--r--workspaces/arborist/test/arborist/reify.js165
-rw-r--r--workspaces/arborist/test/dep-valid.js8
-rw-r--r--workspaces/arborist/test/node.js10
3 files changed, 183 insertions, 0 deletions
diff --git a/workspaces/arborist/test/arborist/reify.js b/workspaces/arborist/test/arborist/reify.js
index 9124b4630..813c984ce 100644
--- a/workspaces/arborist/test/arborist/reify.js
+++ b/workspaces/arborist/test/arborist/reify.js
@@ -2652,3 +2652,168 @@ t.test('save package.json on update', t => {
})
t.end()
})
+
+t.test('installLinks', (t) => {
+ t.test('when true, packs and extracts instead of symlinks', async (t) => {
+ const path = t.testdir({
+ a: {
+ 'package.json': JSON.stringify({
+ name: 'a',
+ version: '1.0.0',
+ main: 'index.js',
+ dependencies: {
+ b: 'file:../b',
+ },
+ }),
+ 'index.js': '',
+ },
+ b: {
+ 'package.json': JSON.stringify({
+ name: 'b',
+ version: '1.0.0',
+ main: 'index.js',
+ }),
+ 'index.js': '',
+ },
+ })
+
+ await reify(resolve(path, 'a'), { installLinks: true })
+
+ const installedB = fs.lstatSync(resolve(path, 'a/node_modules/b'))
+ t.ok(installedB.isDirectory(), 'a/node_modules/b is a directory')
+ })
+
+ t.test('when false, symlinks', async (t) => {
+ const path = t.testdir({
+ a: {
+ 'package.json': JSON.stringify({
+ name: 'a',
+ version: '1.0.0',
+ main: 'index.js',
+ dependencies: {
+ b: 'file:../b',
+ },
+ }),
+ 'index.js': '',
+ },
+ b: {
+ 'package.json': JSON.stringify({
+ name: 'b',
+ version: '1.0.0',
+ main: 'index.js',
+ }),
+ 'index.js': '',
+ },
+ })
+
+ await reify(resolve(path, 'a'), { installLinks: false })
+
+ const installedB = fs.lstatSync(resolve(path, 'a/node_modules/b'))
+ t.ok(installedB.isSymbolicLink(), 'a/node_modules/b is a symlink')
+ })
+
+ t.test('when symlinks exist, installLinks set to true replaces them with dirs', async (t) => {
+ const path = t.testdir({
+ a: {
+ 'package.json': JSON.stringify({
+ name: 'a',
+ version: '1.0.0',
+ main: 'index.js',
+ dependencies: {
+ b: 'file:../b',
+ },
+ }),
+ 'index.js': '',
+ },
+ b: {
+ 'package.json': JSON.stringify({
+ name: 'b',
+ version: '1.0.0',
+ main: 'index.js',
+ }),
+ 'index.js': '',
+ },
+ })
+
+ await reify(resolve(path, 'a'), { installLinks: false, save: true })
+
+ const firstB = fs.lstatSync(resolve(path, 'a/node_modules/b'))
+ t.ok(firstB.isSymbolicLink(), 'a/node_modules/b is a symlink')
+
+ await reify(resolve(path, 'a'), { installLinks: true, save: true })
+
+ const secondB = fs.lstatSync(resolve(path, 'a/node_modules/b'))
+ t.ok(secondB.isDirectory(), 'a/node_modules/b is now a directory')
+ })
+
+ t.test('when directories exist, installLinks set to false replaces them with symlinks', async (t) => {
+ const path = t.testdir({
+ a: {
+ 'package.json': JSON.stringify({
+ name: 'a',
+ version: '1.0.0',
+ main: 'index.js',
+ dependencies: {
+ b: 'file:../b',
+ },
+ }),
+ 'index.js': '',
+ },
+ b: {
+ 'package.json': JSON.stringify({
+ name: 'b',
+ version: '1.0.0',
+ main: 'index.js',
+ }),
+ 'index.js': '',
+ },
+ })
+
+ await reify(resolve(path, 'a'), { installLinks: true })
+
+ const firstB = fs.lstatSync(resolve(path, 'a/node_modules/b'))
+ t.ok(firstB.isDirectory(), 'a/node_modules/b is a directory')
+
+ await reify(resolve(path, 'a'), { installLinks: false })
+
+ const secondB = fs.lstatSync(resolve(path, 'a/node_modules/b'))
+ t.ok(secondB.isSymbolicLink(), 'a/node_modules/b is now a symlink')
+ })
+
+ t.test('when installLinks is true, dependencies of links are installed', async (t) => {
+ const path = t.testdir({
+ a: {
+ 'package.json': JSON.stringify({
+ name: 'a',
+ version: '1.0.0',
+ main: 'index.js',
+ dependencies: {
+ b: 'file:../b',
+ },
+ }),
+ 'index.js': '',
+ },
+ b: {
+ 'package.json': JSON.stringify({
+ name: 'b',
+ version: '1.0.0',
+ main: 'index.js',
+ dependencies: {
+ abbrev: '^1.0.0',
+ },
+ }),
+ 'index.js': '',
+ },
+ })
+
+ await reify(resolve(path, 'a'), { installLinks: true })
+
+ const installedB = fs.lstatSync(resolve(path, 'a/node_modules/b'))
+ t.ok(installedB.isDirectory(), 'a/node_modules/b is a directory')
+
+ const abbrev = fs.lstatSync(resolve(path, 'a/node_modules/abbrev'))
+ t.ok(abbrev.isDirectory(), 'abbrev got installed')
+ })
+
+ t.end()
+})
diff --git a/workspaces/arborist/test/dep-valid.js b/workspaces/arborist/test/dep-valid.js
index 3294ea4e8..901325b23 100644
--- a/workspaces/arborist/test/dep-valid.js
+++ b/workspaces/arborist/test/dep-valid.js
@@ -176,3 +176,11 @@ t.test('invalid request all together', t => {
}, 'parent got an error for their invalid request')
t.end()
})
+
+t.test('installLinks makes Link nodes invalid', t => {
+ const requestor = { errors: [], installLinks: true }
+ const child = { isLink: true, name: 'kid' }
+ const request = { type: 'directory' }
+ t.notOk(depValid(child, request, null, requestor))
+ t.end()
+})
diff --git a/workspaces/arborist/test/node.js b/workspaces/arborist/test/node.js
index 80bc21559..73e081893 100644
--- a/workspaces/arborist/test/node.js
+++ b/workspaces/arborist/test/node.js
@@ -328,6 +328,16 @@ t.test('testing with dep tree', t => {
t.equal(prodLink.children.size, 0, 'links do not have child nodes')
t.equal(prodLink.target.children.size, kidCount, 'link target has children')
+ t.equal(newProd.canReplace(prodLink), true, 'node can replace link')
+ const { target } = prodLink
+ newProd.replace(prodLink)
+ t.equal(prodLink.parent, null, 'prodLink removed from tree')
+ t.equal(prodLink.target, null, 'prodLink lost its target')
+ t.equal(prodLink.root, prodLink, 'prodLink removed from tree')
+ t.equal(target.root, target, 'prodLinks old target removed from tree')
+ t.equal(normalizePath(newProd.path), normalizePath(prodLink.path), 'replaced node')
+ t.equal(prodLink.children.size, 0, 'prodLink has no child nodes')
+
t.end()
})