diff --git a/tools/builder.js b/tools/builder.js index b5ca62b0ad..26ec869c96 100644 --- a/tools/builder.js +++ b/tools/builder.js @@ -340,15 +340,15 @@ _.extend(Builder.prototype, { // Returns a new Builder-compatible object that works just like a // Builder, but interprets all paths relative to 'relPath', a path - // relative to the bundle root. + // relative to the bundle root which should not start with a '/'. // // The sub-builder returned does not have all Builder methods (for // example, complete() wouldn't make sense) and you should not rely - // on it beig instanceof Builder. + // on it being instanceof Builder. enter: function (relPath) { var self = this; - var methods = ["write", "writeJson", "reserve", "copyDirectory", - "enter"]; + var methods = ["write", "writeJson", "reserve", "generateFilename", + "copyDirectory", "enter"]; var ret = {}; _.each(methods, function (method) { @@ -366,7 +366,20 @@ _.extend(Builder.prototype, { args[0].to = path.join(relPath, args[0].to); } - return self[method].apply(self, args); + var ret = self[method].apply(self, args); + + if (method === "generateFilename") { + // fix up the returned path to be relative to the + // sub-bundle, not the parent bundle + if (ret.substr(0, 1) === '/') + ret = ret.substr(1); + if (ret.substr(0, relPath.length) !== relPath) + throw new Error("generateFilename returned path outside of " + + "sub-bundle?"); + ret = ret.substr(relPath.length); + } + + return ret; }; }); diff --git a/tools/bundler.js b/tools/bundler.js index 0981b36b71..a672d1ee24 100644 --- a/tools/bundler.js +++ b/tools/bundler.js @@ -167,7 +167,7 @@ var NodeModulesDirectory = function (options) { // The path (relative to the bundle root) where we would preferably // like the node_modules to be output (essentially cosmetic.) - self.preferredBundlePath = options.bundlePath; + self.preferredBundlePath = options.preferredBundlePath; }; /////////////////////////////////////////////////////////////////////////////// @@ -349,11 +349,11 @@ _.extend(Target.prototype, { if (typeof p === "string") return library.getSlices(p, self.arch); else - return pkg.getDefaultSlices(self.arch); + return p.getDefaultSlices(self.arch); }), _.map(options.test || [], function (p) { - var pkg = (p === "string" ? library.get(p) : p); - return p.getTestSlices(self.arch); + var pkg = (typeof p === "string" ? library.get(p) : p); + return pkg.getTestSlices(self.arch); }) ]); _.each(rootSlices, function (slice) {