Skip to content
This repository has been archived by the owner on Oct 9, 2020. It is now read-only.

Commit

Permalink
ensure that entry point canonicalization uses normalize over normaliz…
Browse files Browse the repository at this point in the history
…e sync
  • Loading branch information
guybedford committed Mar 26, 2016
1 parent b5cb4bb commit db663f0
Showing 1 changed file with 57 additions and 37 deletions.
94 changes: 57 additions & 37 deletions lib/compile.js
Expand Up @@ -185,64 +185,84 @@ function compileTree(loader, tree, traceOpts, compileOpts, outputOpts, cache) {

// verify that the tree is a tree
verifyTree(tree);

var ordered = getTreeModulesPostOrder(tree, traceOpts);

// compileOpts.entryPoints can be unnormalized
var inputEntryPoints;
if (compileOpts.entryPoints)
inputEntryPoints = compileOpts.entryPoints.map(function(entryPoint) {
return loader.getCanonicalName(loader.normalizeSync(entryPoint));
});

// get entrypoints from graph algorithm
var entryPoints = inputEntryPoints || [];
var entryPoints;

ordered.entryPoints.forEach(function(entryPoint) {
if (entryPoints.indexOf(entryPoint) == -1)
entryPoints.push(entryPoint);
});

var modules = ordered.modules.filter(function(moduleName) {
var load = tree[moduleName];
if (load.runtimePlugin && compileOpts.static)
throw new TypeError('Plugin ' + load.plugin + ' does not support static builds, compiling ' + load.name + '.');
return load && !load.conditional && !load.runtimePlugin;
});
var modules;

// plugins have the ability to report an asset list during builds
var assetList = [];

if (compileOpts.encodeNames)
entryPoints = entryPoints.map(function(name) {
return getEncoding(name, cache.encodings)
});
var outputs = [];

var outputs = [];

// store plugins with a bundle hook to allow post-processing
var pluginLoads = {};
var compilers = {};

// create load output objects
return Promise.all(modules.map(function(name) {
return Promise.resolve()
.then(function() {
var load = tree[name];
return Promise.resolve()
.then(function() {
// compileOpts.entryPoints can be unnormalized
if (!compileOpts.entryPoints)
return [];

if (load === true)
throw new TypeError(name + ' was defined via a bundle, so can only be used for subtraction or union operations.');
return Promise.all(compileOpts.entryPoints.map(function(entryPoint) {

// store plugin loads for bundle hook
if (load.metadata.loader) {
var pluginLoad = extend({}, load);
pluginLoad.address = loader.baseURL + load.path;
(pluginLoads[load.metadata.loader] = pluginLoads[load.metadata.loader] || []).push(pluginLoad);
}
// NB do we need to check that entry points are conditionally unique?
return loader.normalize(entryPoint)
.then(function(normalized) {
return loader.getCanonicalName(normalized);
});
}));
})
.then(function(inputEntryPoints) {
entryPoints = inputEntryPoints || [];

ordered.entryPoints.forEach(function(entryPoint) {
if (entryPoints.indexOf(entryPoint) == -1)
entryPoints.push(entryPoint);
});

return compileLoad(loader, tree[name], compileOpts, cache);
modules = ordered.modules.filter(function(moduleName) {
var load = tree[moduleName];
if (load.runtimePlugin && compileOpts.static)
throw new TypeError('Plugin ' + load.plugin + ' does not support static builds, compiling ' + load.name + '.');
return load && !load.conditional && !load.runtimePlugin;
});
}))

if (compileOpts.encodeNames)
entryPoints = entryPoints.map(function(name) {
return getEncoding(name, cache.encodings)
});
})

// create load output objects
.then(function() {
return Promise.all(modules.map(function(name) {
return Promise.resolve()
.then(function() {
var load = tree[name];

if (load === true)
throw new TypeError(name + ' was defined via a bundle, so can only be used for subtraction or union operations.');

// store plugin loads for bundle hook
if (load.metadata.loader) {
var pluginLoad = extend({}, load);
pluginLoad.address = loader.baseURL + load.path;
(pluginLoads[load.metadata.loader] = pluginLoads[load.metadata.loader] || []).push(pluginLoad);
}

return compileLoad(loader, tree[name], compileOpts, cache);
});
}));
})
.then(function(compiled) {
outputs = outputs.concat(compiled);
})
Expand Down

0 comments on commit db663f0

Please sign in to comment.