|
1 | 1 | const { resolve } = require('path')
|
| 2 | +const fs = require('fs') |
2 | 3 |
|
3 | 4 | const Arborist = require('@npmcli/arborist')
|
4 | 5 | const t = require('tap')
|
@@ -485,6 +486,55 @@ t.test('link pkg already in global space when prefix is a symlink', (t) => {
|
485 | 486 | })
|
486 | 487 | })
|
487 | 488 |
|
| 489 | +t.test('should not prune dependencies when linking packages', async t => { |
| 490 | + const testdir = t.testdir({ |
| 491 | + 'global-prefix': { |
| 492 | + lib: { |
| 493 | + node_modules: { |
| 494 | + linked: t.fixture('symlink', '../../../linked'), |
| 495 | + }, |
| 496 | + }, |
| 497 | + }, |
| 498 | + linked: { |
| 499 | + 'package.json': JSON.stringify({ |
| 500 | + name: 'linked', |
| 501 | + version: '1.0.0', |
| 502 | + }), |
| 503 | + }, |
| 504 | + 'my-project': { |
| 505 | + node_modules: { |
| 506 | + foo: { |
| 507 | + 'package.json': JSON.stringify({ name: 'foo', version: '1.0.0' }), |
| 508 | + }, |
| 509 | + }, |
| 510 | + 'package.json': JSON.stringify({ |
| 511 | + name: 'my-project', |
| 512 | + version: '1.0.0', |
| 513 | + }), |
| 514 | + }, |
| 515 | + }) |
| 516 | + npm.globalDir = resolve(testdir, 'global-prefix', 'lib', 'node_modules') |
| 517 | + npm.prefix = resolve(testdir, 'my-project') |
| 518 | + reifyOutput = () => {} |
| 519 | + |
| 520 | + const _cwd = process.cwd() |
| 521 | + process.chdir(npm.prefix) |
| 522 | + |
| 523 | + await new Promise((res, rej) => { |
| 524 | + link.exec(['linked'], (err) => { |
| 525 | + if (err) |
| 526 | + rej(err) |
| 527 | + res() |
| 528 | + }) |
| 529 | + }) |
| 530 | + |
| 531 | + t.ok( |
| 532 | + fs.statSync(resolve(testdir, 'my-project/node_modules/foo')), |
| 533 | + 'should not prune any extraneous dep when running npm link' |
| 534 | + ) |
| 535 | + process.chdir(_cwd) |
| 536 | +}) |
| 537 | + |
488 | 538 | t.test('completion', async t => {
|
489 | 539 | const testdir = t.testdir({
|
490 | 540 | 'global-prefix': {
|
|
0 commit comments