Skip to content

Commit

Permalink
Respect configured entry order and creates facades from later entries
Browse files Browse the repository at this point in the history
  • Loading branch information
lukastaegert committed May 13, 2020
1 parent d0312ff commit 1c97de9
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 19 deletions.
35 changes: 17 additions & 18 deletions src/ModuleLoader.ts
Expand Up @@ -142,32 +142,31 @@ export class ModuleLoader {
this.nextEntryModuleIndex += unresolvedEntryModules.length;
const loadNewEntryModulesPromise = Promise.all(
unresolvedEntryModules.map(
async ({ fileName, id, name, importer }): Promise<Module> => {
const module = await this.loadEntryModule(id, true, importer);
if (fileName !== null) {
module.chunkFileNames.add(fileName);
} else if (name !== null) {
if (module.chunkName === null) {
module.chunkName = name;
}
if (isUserDefined) {
module.userChunkNames.add(name);
}
}
return module;
}
({ id, importer }): Promise<Module> => this.loadEntryModule(id, true, importer)
)
).then(entryModules => {
let moduleIndex = firstEntryModuleIndex;
for (const entryModule of entryModules) {
for (let index = 0; index < entryModules.length; index++) {
const { fileName, name } = unresolvedEntryModules[index];
const entryModule = entryModules[index];
entryModule.isUserDefinedEntryPoint = entryModule.isUserDefinedEntryPoint || isUserDefined;
const existingIndexModule = this.indexedEntryModules.find(
if (fileName !== null) {
entryModule.chunkFileNames.add(fileName);
} else if (name !== null) {
if (entryModule.chunkName === null) {
entryModule.chunkName = name;
}
if (isUserDefined) {
entryModule.userChunkNames.add(name);
}
}
const existingIndexedModule = this.indexedEntryModules.find(
indexedModule => indexedModule.module.id === entryModule.id
);
if (!existingIndexModule) {
if (!existingIndexedModule) {
this.indexedEntryModules.push({ module: entryModule, index: moduleIndex });
} else {
existingIndexModule.index = Math.min(existingIndexModule.index, moduleIndex);
existingIndexedModule.index = Math.min(existingIndexedModule.index, moduleIndex);
}
moduleIndex++;
}
Expand Down
2 changes: 1 addition & 1 deletion test/chunking-form/samples/entry-aliases/_config.js
Expand Up @@ -2,8 +2,8 @@ module.exports = {
description: 'alias module dependency inlining',
options: {
input: {
'main1-alias.js': 'main1.js',
'main1.js': 'main1.js',
'main1-alias.js': 'main1.js',
'main2.js': 'main2.js'
},
output: {
Expand Down
27 changes: 27 additions & 0 deletions test/function/samples/bundle-facade-order/_config.js
@@ -0,0 +1,27 @@
const assert = require('assert');

module.exports = {
description: 'respects the order of entry points when there are additional facades for chunks',
options: {
input: {
main: 'main',
'main-alias': 'main',
other: 'other'
},
plugins: {
generateBundle(options, bundle) {
assert.deepStrictEqual(
Object.keys(bundle).map(id => [id, bundle[id].code]),
[
['main.js', "'use strict';\n\nvar main = 'main1';\n\nmodule.exports = main;\n"],
['other.js', "'use strict';\n\nvar other = 'main2';\n\nmodule.exports = other;\n"],
[
'main-alias.js',
"'use strict';\n\nvar main = require('./main.js');\n\n\n\nmodule.exports = main;\n"
]
]
);
}
}
}
};
1 change: 1 addition & 0 deletions test/function/samples/bundle-facade-order/main.js
@@ -0,0 +1 @@
export default 'main1';
1 change: 1 addition & 0 deletions test/function/samples/bundle-facade-order/other.js
@@ -0,0 +1 @@
export default 'main2';

0 comments on commit 1c97de9

Please sign in to comment.