diff --git a/src/ModuleLoader.ts b/src/ModuleLoader.ts index 226da80ee99..b8d37c610cb 100644 --- a/src/ModuleLoader.ts +++ b/src/ModuleLoader.ts @@ -142,32 +142,31 @@ export class ModuleLoader { this.nextEntryModuleIndex += unresolvedEntryModules.length; const loadNewEntryModulesPromise = Promise.all( unresolvedEntryModules.map( - async ({ fileName, id, name, importer }): Promise => { - 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 => 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++; } diff --git a/test/chunking-form/samples/entry-aliases/_config.js b/test/chunking-form/samples/entry-aliases/_config.js index 35b275f277a..b34e645a489 100644 --- a/test/chunking-form/samples/entry-aliases/_config.js +++ b/test/chunking-form/samples/entry-aliases/_config.js @@ -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: { diff --git a/test/function/samples/bundle-facade-order/_config.js b/test/function/samples/bundle-facade-order/_config.js new file mode 100644 index 00000000000..b202a1b5733 --- /dev/null +++ b/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" + ] + ] + ); + } + } + } +}; diff --git a/test/function/samples/bundle-facade-order/main.js b/test/function/samples/bundle-facade-order/main.js new file mode 100644 index 00000000000..b217470a5f7 --- /dev/null +++ b/test/function/samples/bundle-facade-order/main.js @@ -0,0 +1 @@ +export default 'main1'; diff --git a/test/function/samples/bundle-facade-order/other.js b/test/function/samples/bundle-facade-order/other.js new file mode 100644 index 00000000000..cb63f9eba57 --- /dev/null +++ b/test/function/samples/bundle-facade-order/other.js @@ -0,0 +1 @@ +export default 'main2';