diff --git a/index.js b/index.js index 24ec1f3..439f278 100644 --- a/index.js +++ b/index.js @@ -170,6 +170,12 @@ const npmWalker = Class => class Walker extends Class { pkg.files.push(...this.mustHaveFilesFromPackage(pkg)) + // when bundling _and_ explicitly filtering files, + // the root node_modules should always be allowed + if (this.bundled.length) { + pkg.files.push('/node_modules') + } + const patterns = Array.from(new Set(pkg.files)).reduce((set, pattern) => { const excl = pattern.match(/^!+/) if (excl) diff --git a/tap-snapshots/test-bundled-files.js-TAP.test.js b/tap-snapshots/test-bundled-files.js-TAP.test.js new file mode 100644 index 0000000..948f1d0 --- /dev/null +++ b/tap-snapshots/test-bundled-files.js-TAP.test.js @@ -0,0 +1,24 @@ +/* IMPORTANT + * This snapshot file is auto-generated, but designed for humans. + * It should be checked into source control and tracked carefully. + * Re-generate by setting TAP_SNAPSHOT=1 and running tests. + * Make sure to inspect the output below. Do not ignore changes! + */ +'use strict' +exports[`test/bundled-files.js TAP bundles dependencies with explicit files > expect resolving Promise 1`] = ` +Array [ + "eldar.js", + "node_modules/quendi/index.js", + "node_modules/quendi/package.json", + "package.json", +] +` + +exports[`test/bundled-files.js TAP bundles dependencies with explicit files > must match snapshot 1`] = ` +Array [ + "eldar.js", + "node_modules/quendi/index.js", + "node_modules/quendi/package.json", + "package.json", +] +` diff --git a/test/bundled-files.js b/test/bundled-files.js new file mode 100644 index 0000000..1bb896d --- /dev/null +++ b/test/bundled-files.js @@ -0,0 +1,38 @@ +'use strict' + +const t = require('tap') + +const elfJS = ` +module.exports = elf => + console.log("i'm a elf") +` +const pkg = t.testdir({ + 'package.json': JSON.stringify({ + name: 'test-package', + version: '3.1.4', + bundleDependencies: [ + 'quendi', + ], + files: [ + 'eldar.js', + ], + }), + 'eldar.js': elfJS, + 'avari.js': elfJS, + node_modules: { + quendi: { + 'package.json': JSON.stringify({ + name: 'quendi', + version: '1.0.0', + }), + 'index.js': elfJS, + }, + } +}) + +const packlist = require('../') + +t.test('bundles dependencies with explicit files', async t => { + t.matchSnapshot(packlist.sync({path: pkg})) + await t.resolveMatchSnapshot(packlist({path: pkg})) +})