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: npm pack marks the wrong files as executable #409

Closed
Changes from 2 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
23 changes: 17 additions & 6 deletions lib/util/is-package-bin.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
const path = require('path').posix
// Function to determine whether a path is in the package.bin set.
// Used to prevent issues when people publish a package from a
// windows machine, and then install with --no-bin-links.
Expand All @@ -10,16 +11,26 @@
const binObj = (name, bin) =>
typeof bin === 'string' ? { [name]: bin } : bin

const hasBin = (pkg, path) => {
const hasBin = (pkg, filePath) => {
const bin = binObj(pkg.name, pkg.bin)
const p = path.replace(/^[^\\/]*\//, '')
for (const kv of Object.entries(bin)) {
if (kv[1] === p) {

// Remove 'package/' prefix if present
const relativeFilePath = filePath.startsWith('package/')
kchindam-infy marked this conversation as resolved.
Show resolved Hide resolved
? filePath.slice(8)
: filePath

const normalizedFilePath = path.normalize(relativeFilePath)

for (const binName in bin) {
const binPath = bin[binName]
const normalizedBinPath = path.normalize(binPath)

if (normalizedFilePath === normalizedBinPath) {
return true
}
}
return false
}

module.exports = (pkg, path) =>
pkg && pkg.bin ? hasBin(pkg, path) : false
module.exports = (pkg, filePath) =>
pkg && pkg.bin ? hasBin(pkg, filePath) : false
Loading