Skip to content

Commit

Permalink
fix: make sure we pack workspace targets, not the link node
Browse files Browse the repository at this point in the history
  • Loading branch information
nlf committed Apr 7, 2022
1 parent 864c1d9 commit 21e7d47
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -321,8 +321,12 @@ class PackWalker extends IgnoreWalker {
const node = this.tree.edgesOut.get(dep).to
// and start building options to be passed to the walker for this package
const walkerOpts = {
// we use node.path for the path because we want the location the node was linked to,
// not where it actually lives on disk
path: node.path,
tree: node,
// but link nodes don't have edgesOut, so we need to pass in the target of the node
// in order to make sure we correctly traverse its dependencies
tree: node.target,
isPackage: true,
ignoreFiles: [],
seen: this.seen, // pass through seen so we can prevent infinite circular loops
Expand Down
54 changes: 54 additions & 0 deletions test/bundled-workspace.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
'use strict'

const t = require('tap')
const packlist = require('../')

t.test('packs workspace dependencies correctly', async (t) => {
const pkg = t.testdir({
'package.json': JSON.stringify({
name: 'root',
version: '1.2.3',
main: 'index.js',
files: ['index.js'],
dependencies: {
foo: '1.0.0',
bar: '1.0.0',
},
bundleDependencies: ['foo', 'bar'],
workspaces: ['./workspaces/*'],
}),
'index.js': '',
workspaces: {
foo: {
'package.json': JSON.stringify({
name: 'foo',
version: '1.0.0',
main: 'index.js',
}),
'index.js': '',
},
bar: {
'package.json': JSON.stringify({
name: 'bar',
version: '1.0.0',
main: 'index.js',
}),
'index.js': '',
},
},
node_modules: {
foo: t.fixture('symlink', '../workspaces/foo'),
bar: t.fixture('symlink', '../workspaces/bar'),
},
})

const files = await packlist({ path: pkg })
t.same(files, [
'index.js',
'node_modules/bar/index.js',
'node_modules/foo/index.js',
'node_modules/bar/package.json',
'node_modules/foo/package.json',
'package.json',
])
})

0 comments on commit 21e7d47

Please sign in to comment.