Skip to content

Commit

Permalink
Eliminate shared module cache for builder
Browse files Browse the repository at this point in the history
And use strict mode for builder
  • Loading branch information
kriskowal authored and cdebost committed Jan 30, 2019
1 parent 6d6fdca commit 3ad4a40
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 19 deletions.
32 changes: 15 additions & 17 deletions build.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//"use strict";

var Promise = require("bluebird");
var FS = require("fs");
Expand All @@ -10,39 +11,36 @@ module.exports = build;
function build(path) {
return Require.findPackageLocationAndModuleId(path)
.then(function (arg) {
var cache = {};
return Promise.try(function () {
return Require.loadPackage(arg.location, {
overlays: ["node"],
cache: cache,
production: false
});
})
.then(function (preprocessorPackage) {
return Require.loadPackage(arg.location, {
overlays: ["browser"],
cache: cache,
production: true,
preprocessorPackage: preprocessorPackage
});
})
.then(function (package) {
return package.deepLoad(arg.id)
.then(function (pkg) {
return pkg.deepLoad(arg.id)
.then(function () {
return package;
return pkg;
});
});
})
.then(function (package) {
.then(function (pkg) {

var bundle = [];
var packages = package.packages;
var pkgs = pkg.packages;

// Ensure that the entry point comes first in the bundle
for (var location in packages) {
if (Object.prototype.hasOwnProperty.call(packages, location)) {
package = packages[location];
var modules = package.modules;
for (var location in pkgs) {
if (Object.prototype.hasOwnProperty.call(pkgs, location)) {
pkg = pkgs[location];
var modules = pkg.modules;
for (var id in modules) {
if (Object.prototype.hasOwnProperty.call(modules, id)) {
var module = modules[id];
Expand All @@ -59,13 +57,13 @@ function build(path) {

// Otherwise, ensure that the modules are in lexicographic order to
// ensure that each build from the same sources is consistent.
Object.keys(packages).sort(function (a, b) {
a = packages[a].config.name || a;
b = packages[b].config.name || b;
Object.keys(pkgs).sort(function (a, b) {
a = pkgs[a].config.name || a;
b = pkgs[b].config.name || b;
return a === b ? 0 : a < b ? -1 : 1;
}).forEach(function (location) {
var package = packages[location];
var modules = package.modules;
var pkg = pkgs[location];
var modules = pkg.modules;
Object.keys(modules).sort().forEach(function (id) {
var module = modules[id];
if (module.error) {
Expand Down
5 changes: 3 additions & 2 deletions common.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,14 @@ Require.makeRequire = function (config) {
} else {
type = "js";
}
modules[lookupId] = {
var module = {
id: id,
extension: extension,
type: type,
display: (config.name || config.location) + "#" + id,
require: makeRequire(id)
};
modules[lookupId] = module;
}
return modules[lookupId];
}
Expand Down Expand Up @@ -100,7 +101,7 @@ Require.makeRequire = function (config) {
module.exports === void 0 &&
module.redirect === void 0
) {
return Q(config.load).call(void 0, topId, module);
return config.load(topId, module);
}
})
.then(function () {
Expand Down

0 comments on commit 3ad4a40

Please sign in to comment.