Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: A files list should not exclude bundled dependencies #46

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
24 changes: 24 additions & 0 deletions tap-snapshots/test-bundled-files.js-TAP.test.js
Original file line number Diff line number Diff line change
@@ -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",
]
`
38 changes: 38 additions & 0 deletions test/bundled-files.js
Original file line number Diff line number Diff line change
@@ -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}))
})