Skip to content

Commit

Permalink
Always copy node_modules/.bin into bundle/programs/server/npm.
Browse files Browse the repository at this point in the history
  • Loading branch information
Ben Newman committed Dec 6, 2016
1 parent b4290d7 commit f42c137
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 13 deletions.
13 changes: 8 additions & 5 deletions tools/isobuild/builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,8 @@ Previous builder: ${previousBuilder.outputPath}, this builder: ${outputPath}`
specificFiles,
symlink,
npmDiscards,
directoryFilter,
// Optional predicate to filter files and directories.
filter,
}) {
if (to.slice(-1) === files.pathSep) {
to = to.slice(0, -1);
Expand Down Expand Up @@ -541,16 +542,18 @@ Previous builder: ${previousBuilder.outputPath}, this builder: ${outputPath}`
return;
}

if (typeof filter === "function" &&
! filter(thisAbsFrom, isDirectory)) {
return;
}

if (npmDiscards instanceof NpmDiscards &&
npmDiscards.shouldDiscard(thisAbsFrom, isDirectory)) {
return;
}

if (isDirectory) {
if (typeof directoryFilter !== "function" ||
directoryFilter(thisAbsFrom)) {
walk(thisAbsFrom, thisRelTo, _currentRealRootDir);
}
walk(thisAbsFrom, thisRelTo, _currentRealRootDir);

} else if (fileStatus.isSymbolicLink()) {
symlinkWithOverwrite(
Expand Down
37 changes: 29 additions & 8 deletions tools/isobuild/bundler.js
Original file line number Diff line number Diff line change
Expand Up @@ -458,18 +458,39 @@ export class NodeModulesDirectory {
maxPartCount = Math.max(parts.length, maxPartCount);
});

return this._prodPackagePredicate = function isWithinProdPackage(dir) {
const parts = files.pathRelative(sourcePath, dir)
return this._prodPackagePredicate = function isWithinProdPackage(path) {
const parts = files.pathRelative(sourcePath, path)
.split(files.pathSep);

let start = parts.lastIndexOf("node_modules") + 1;
// Normalize away trailing files.pathSep characters.
while (parts[parts.length - 1] === "") {
parts.pop();
}

const start = parts.lastIndexOf("node_modules") + 1;

if (parts[start] === ".bin") {
if (start === parts.length - 1) {
// Permit node_modules/.bin directories, so that we can filter
// their contents below.
return true;
}

if (parts.length - start > maxPartCount) {
// We're deep enough inside node_modules that it's safe to
// say we should have returned false earlier.
const real = files.realpath(path);
if (real !== path) {
// If node_modules/.bin/command is a symlink, determine the
// answer by calling isWithinProdPackage(real).
return isWithinProdPackage(real);
}

// If node_modules/.bin/command is not a symlink, then it's hard
// to tell which package is responsible for it, so don't strip it.
return true;
}

// Strip away any parts not related to the package name.
parts.length = start + maxPartCount;

let tree = prodPackageTree;

for (let pos = start; pos < parts.length; ++pos) {
Expand Down Expand Up @@ -2006,8 +2027,8 @@ class JsImage {
// "devDependencies", but it also gets listed in some other
// package's "dependencies", then every copy of that package
// will be copied to the destination directory. A little bit of
// overcopying vastly simplifies the job of directoryFilter.
copyOptions.directoryFilter = prodPackagePredicate;
// overcopying vastly simplifies the job of the filter.
copyOptions.filter = prodPackagePredicate;
}

builder.copyDirectory(copyOptions);
Expand Down

0 comments on commit f42c137

Please sign in to comment.