diff --git a/lib/util/is-package-bin.js b/lib/util/is-package-bin.js index 49a3f73f..dd7a8cf9 100644 --- a/lib/util/is-package-bin.js +++ b/lib/util/is-package-bin.js @@ -10,9 +10,9 @@ const binObj = (name, bin) => typeof bin === 'string' ? { [name]: bin } : bin -const hasBin = (pkg, path) => { +const hasBin = (pkg, path, replace = true) => { const bin = binObj(pkg.name, pkg.bin) - const p = path.replace(/^[^\\/]*\//, '') + const p = replace ? path.replace(/^[^\\/]*\//, '') : path for (const kv of Object.entries(bin)) { if (kv[1] === p) { return true @@ -21,5 +21,5 @@ const hasBin = (pkg, path) => { return false } -module.exports = (pkg, path) => - pkg && pkg.bin ? hasBin(pkg, path) : false +module.exports = (pkg, path, replace) => + pkg && pkg.bin ? hasBin(pkg, path, replace) : false diff --git a/lib/util/tar-create-options.js b/lib/util/tar-create-options.js index d070f0f7..b905de55 100644 --- a/lib/util/tar-create-options.js +++ b/lib/util/tar-create-options.js @@ -17,7 +17,7 @@ const tarCreateOptions = manifest => ({ // anything that is not a regular file, ignored by // .npmignore or package.json "files", etc. filter: (path, stat) => { - if (isPackageBin(manifest, path)) { + if (isPackageBin(manifest, path, false)) { stat.mode |= 0o111 } return true diff --git a/test/util/is-package-bin.js b/test/util/is-package-bin.js index 77bb9f08..eae6095b 100644 --- a/test/util/is-package-bin.js +++ b/test/util/is-package-bin.js @@ -6,3 +6,11 @@ t.ok(isPackageBin({ bin: { bar: 'foo' } }, 'package/foo'), 'finds in obj') t.notOk(isPackageBin(null, 'anything'), 'return false if pkg is not') t.notOk(isPackageBin({ bin: 'foo' }, 'package/bar'), 'not the bin string') t.notOk(isPackageBin({ bin: { bar: 'foo' } }, 'package/bar'), 'not in obj') + +t.test('bin file not recognized without prefix removal', t => { + const testPkg = { name: 'my-package', bin: 'bin/index.js' } + const testFilePath = 'bin/index.js' // includes 'package/' prefix + t.ok(isPackageBin(testPkg, testFilePath, false), + 'correctly recognizes bin file with prefix removal') + t.end() +})