Skip to content

Commit

Permalink
Only strip devDependencies when buildMode === "production".
Browse files Browse the repository at this point in the history
  • Loading branch information
Ben Newman committed Oct 25, 2016
1 parent 7bcc50c commit 03e798a
Showing 1 changed file with 46 additions and 28 deletions.
74 changes: 46 additions & 28 deletions tools/isobuild/bundler.js
Original file line number Diff line number Diff line change
Expand Up @@ -1811,18 +1811,17 @@ class JsImage {

// Write this image out to disk
//
// options:
// - includeNodeModules: falsy or 'symlink', documented on
// exports.bundle.
//
// Returns an object with the following keys:
// - controlFile: the path (relative to 'builder') of the control file for
// the image
// - nodePath: an array of paths required to be set in the NODE_PATH
// environment variable.
write(builder, options) {
write(builder, {
buildMode,
// falsy or 'symlink', documented on exports.bundle
includeNodeModules,
} = {}) {
var self = this;
options = options || {};

builder.reserve("program.json");

Expand All @@ -1834,15 +1833,15 @@ class JsImage {
// We need to find the actual file system location for the node modules
// this JS Image uses, so that we can add it to nodeModulesDirectories
var modulesPhysicalLocation;
if (! options.includeNodeModules ||
options.includeNodeModules === 'symlink') {
if (! includeNodeModules ||
includeNodeModules === 'symlink') {
modulesPhysicalLocation = nmd.getPreferredBundlePath("bundle");
} else {
// This is some option we didn't expect - someone has added another case
// to the includeNodeModules option but didn't update this if block.
// Fail hard.
throw new Error("Option includeNodeModules wasn't falsy or 'symlink'. " +
"It was: " + options.includeNodeModules);
"It was: " + includeNodeModules);
}

nmd = nmd.copy();
Expand Down Expand Up @@ -1969,10 +1968,11 @@ class JsImage {
from: nmd.sourcePath,
to: nmd.preferredBundlePath,
npmDiscards: nmd.npmDiscards,
symlink: (options.includeNodeModules === 'symlink')
symlink: includeNodeModules === 'symlink'
};

const prodPackagePredicate =
buildMode === "production" &&
nmd.local && // Only filter local node_modules directories.
nmd.getProdPackagePredicate();

Expand Down Expand Up @@ -2139,17 +2139,19 @@ class ServerTarget extends JsImageTarget {
}

// Output the finished target to disk
// options:
// - includeNodeModules: falsy or 'symlink', documented in
// exports.bundle.
// - getRelativeTargetPath: a function that takes {forTarget:
// Target, relativeTo: Target} and return the path of one target
// in the bundle relative to another. hack to get the path of the
// client target.. we'll find a better solution here eventually
//
// Returns the path (relative to 'builder') of the control file for
// the plugin and the required NODE_PATH.
write(builder, options) {
write(builder, {
buildMode,
// falsy or 'symlink', documented in exports.bundle
includeNodeModules,
// a function that takes {forTarget: Target, relativeTo: Target} and
// return the path of one target in the bundle relative to another. hack
// to get the path of the client target.. we'll find a better solution
// here eventually
getRelativeTargetPath,
}) {
var self = this;
var nodePath = [];

Expand All @@ -2161,8 +2163,10 @@ class ServerTarget extends JsImageTarget {
var clientTargetPaths = {};
if (self.clientTargets) {
_.each(self.clientTargets, function (target) {
clientTargetPaths[target.arch] = files.pathJoin(options.getRelativeTargetPath({
forTarget: target, relativeTo: self}), 'program.json');
clientTargetPaths[target.arch] = files.pathJoin(getRelativeTargetPath({
forTarget: target,
relativeTo: self,
}), 'program.json');
});
}

Expand Down Expand Up @@ -2200,11 +2204,11 @@ class ServerTarget extends JsImageTarget {
// This is a hack to make 'meteor run' faster (so you don't have to run 'npm
// install' using the above package.json and npm-shrinkwrap.json on every
// rebuild).
if (options.includeNodeModules === 'symlink') {
if (includeNodeModules === 'symlink') {
builder.write('node_modules', {
symlink: files.pathJoin(files.getDevBundle(), 'server-lib', 'node_modules')
});
} else if (options.includeNodeModules) {
} else if (includeNodeModules) {
// This is some option we didn't expect - someone has added another case
// to the includeNodeModules option but didn't update this if block. Fail
// hard.
Expand All @@ -2214,7 +2218,10 @@ class ServerTarget extends JsImageTarget {
// Linked JavaScript image (including static assets, assuming that there are
// any JS files at all)
var jsImage = self.toJsImage();
jsImage.write(builder, { includeNodeModules: options.includeNodeModules });
jsImage.write(builder, {
buildMode,
includeNodeModules,
});

const toolsDir = files.pathDirname(
files.convertToStandardPath(__dirname));
Expand Down Expand Up @@ -2298,15 +2305,20 @@ var writeTargetToPath = Profile(
includeNodeModules,
getRelativeTargetPath,
previousBuilder,
minifyMode
buildMode,
minifyMode,
}) {
var builder = new Builder({
outputPath: files.pathJoin(outputPath, 'programs', name),
previousBuilder
});

var targetBuild = target.write(
builder, {includeNodeModules, getRelativeTargetPath, minifyMode});
var targetBuild = target.write(builder, {
includeNodeModules,
getRelativeTargetPath,
buildMode,
minifyMode,
});

builder.complete();

Expand Down Expand Up @@ -2354,6 +2366,7 @@ var writeSiteArchive = Profile("bundler writeSiteArchive", function (
releaseName,
getRelativeTargetPath,
previousBuilders,
buildMode,
minifyMode
}) {

Expand Down Expand Up @@ -2439,6 +2452,7 @@ Find out more about Meteor at meteor.com.
releaseName,
getRelativeTargetPath,
previousBuilder,
buildMode,
minifyMode
});

Expand Down Expand Up @@ -2754,7 +2768,9 @@ function bundle({
const previousBuilder = previousBuilders && previousBuilders[name];
var targetBuild = writeTargetToPath(
name, target, outputPath,
_.extend({}, writeOptions, {previousBuilder})
_.extend({
buildMode: buildOptions.buildMode,
}, writeOptions, {previousBuilder})
);
nodePath = nodePath.concat(targetBuild.nodePath);
clientWatchSet.merge(target.getWatchSet());
Expand All @@ -2764,7 +2780,9 @@ function bundle({
starResult = writeSiteArchive(
targets,
outputPath,
_.extend({}, writeOptions, {previousBuilders})
_.extend({
buildMode: buildOptions.buildMode,
}, writeOptions, {previousBuilders})
);

nodePath = nodePath.concat(starResult.nodePath);
Expand Down

0 comments on commit 03e798a

Please sign in to comment.