From 21e7d4791b94d61038bfb6b439ec2aae3ec64b86 Mon Sep 17 00:00:00 2001 From: nlf Date: Thu, 7 Apr 2022 11:15:24 -0700 Subject: [PATCH] fix: make sure we pack workspace targets, not the link node --- lib/index.js | 6 ++++- test/bundled-workspace.js | 54 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 59 insertions(+), 1 deletion(-) create mode 100644 test/bundled-workspace.js diff --git a/lib/index.js b/lib/index.js index 8cf1efd..5212c87 100644 --- a/lib/index.js +++ b/lib/index.js @@ -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 diff --git a/test/bundled-workspace.js b/test/bundled-workspace.js new file mode 100644 index 0000000..bd2cd5a --- /dev/null +++ b/test/bundled-workspace.js @@ -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', + ]) +})