fix: keep renderModule order consistent (#19867)

This commit is contained in:
Xiao 2025-09-05 17:31:05 +08:00 committed by GitHub
parent 50119bb9b0
commit 57a8ebd761
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
14 changed files with 741 additions and 80 deletions

View File

@ -258,7 +258,6 @@ class ModuleExternalInitFragment extends InitFragment {
}
}
const identifier = `__WEBPACK_EXTERNAL_MODULE_${ident}__`;
super(
"",
InitFragment.STAGE_HARMONY_IMPORTS,
@ -268,8 +267,8 @@ class ModuleExternalInitFragment extends InitFragment {
this._ident = ident;
this._request = request;
this._dependencyMeta = dependencyMeta;
this._imported = imported;
this._identifier = identifier;
this._identifier = this.buildIdentifier(ident);
this._imported = this.buildImported(imported);
}
/**
@ -332,6 +331,28 @@ class ModuleExternalInitFragment extends InitFragment {
getNamespaceIdentifier() {
return this._identifier;
}
/**
* @param {string} ident ident
* @returns {string} identifier
*/
buildIdentifier(ident) {
return `__WEBPACK_EXTERNAL_MODULE_${ident}__`;
}
/**
* @param {Imported} imported imported
* @returns {Imported} normalized imported
*/
buildImported(imported) {
if (Array.isArray(imported)) {
return imported.map(([name]) => {
const ident = `${this._ident}_${name}`;
return [name, this.buildIdentifier(ident)];
});
}
return imported;
}
}
register(
@ -428,21 +449,7 @@ const getSourceForModuleExternal = (
imported = [];
break;
default:
imported = [];
if (exportsInfo.isUsed(runtime) === false) {
// no used, only
}
for (const [name] of usedExports.entries()) {
let counter = 0;
let finalName = name;
if (concatenationScope) {
while (!concatenationScope.registerUsedName(finalName)) {
finalName = `${name}_${counter++}`;
}
}
imported.push([name, finalName]);
}
imported = [...usedExports.entries()];
}
}
@ -453,7 +460,24 @@ const getSourceForModuleExternal = (
dependencyMeta,
runtimeTemplate.outputOptions.hashFunction
);
const specifiers = imported === true ? undefined : imported;
const normalizedImported = initFragment.getImported();
const specifiers =
normalizedImported === true
? undefined
: /** @type {[string, string][]} */ (
normalizedImported.map(([name, rawFinalName]) => {
let finalName = rawFinalName;
let counter = 0;
if (concatenationScope) {
while (!concatenationScope.registerUsedName(finalName)) {
finalName = `${finalName}_${counter++}`;
}
}
return [name, finalName];
})
);
const baseAccess = `${initFragment.getNamespaceIdentifier()}${propertyAccess(
moduleAndSpecifiers,
1

View File

@ -10150,9 +10150,9 @@ exports[`ConfigCacheTestCases css webpack-ignore exported tests should compile 1
`;
exports[`ConfigCacheTestCases library concatenate-modules-named-import-externals concatenate-modules-named-import-externals should compile 1`] = `
"import { HomeLayout as lib_HomeLayout_0, a } from \\"externals0\\";
import { HomeLayout as HomeLayout_0, a as a_0 } from \\"externals1\\";
import { default as default_0 } from \\"externals2\\";
"import { HomeLayout as __WEBPACK_EXTERNAL_MODULE_externals0_HomeLayout__, a as __WEBPACK_EXTERNAL_MODULE_externals0_a__ } from \\"externals0\\";
import { HomeLayout as __WEBPACK_EXTERNAL_MODULE_externals1_HomeLayout__, a as __WEBPACK_EXTERNAL_MODULE_externals1_a__ } from \\"externals1\\";
import { default as __WEBPACK_EXTERNAL_MODULE_externals2_default__ } from \\"externals2\\";
import * as __WEBPACK_EXTERNAL_MODULE_externals3__ from \\"externals3\\";
import \\"externals4\\";
/******/ // The require scope
@ -10195,15 +10195,15 @@ const external_externals3_namespaceObject = __WEBPACK_EXTERNAL_MODULE_externals3
;// ./lib.js
const { HomeLayout: lib_HomeLayout = 123 } = {};
console.log({ HomeLayout: lib_HomeLayout });
const { HomeLayout = 123 } = {};
console.log({ HomeLayout });
{
const { HomeLayout = lib_HomeLayout_0 } = {};
const { HomeLayout = __WEBPACK_EXTERNAL_MODULE_externals0_HomeLayout__ } = {};
console.log({ HomeLayout });
}
(() => {
{
const { HomeLayout = lib_HomeLayout_0 } = {};
const { HomeLayout = __WEBPACK_EXTERNAL_MODULE_externals0_HomeLayout__ } = {};
console.log({ HomeLayout });
}
})()
@ -10237,19 +10237,19 @@ console.log({ HomeLayout: lib_HomeLayout });
const HomeLayout_0 = 'HomeLayout_0';
HomeLayout_0;
}
HomeLayout_0;
a;
a_0;
default_0;
__WEBPACK_EXTERNAL_MODULE_externals1_HomeLayout__;
__WEBPACK_EXTERNAL_MODULE_externals0_a__;
__WEBPACK_EXTERNAL_MODULE_externals1_a__;
__WEBPACK_EXTERNAL_MODULE_externals2_default__;
external_externals3_namespaceObject;
export { lib_HomeLayout as HomeLayout, a };
export { HomeLayout, __WEBPACK_EXTERNAL_MODULE_externals0_a__ as a };
"
`;
exports[`ConfigCacheTestCases library concatenate-modules-named-import-externals concatenate-modules-named-import-externals should compile 2`] = `
"import { HomeLayout as lib_HomeLayout_0, a } from \\"externals0\\";
import { HomeLayout as HomeLayout_0, a as a_0 } from \\"externals1\\";
import { default as default_0 } from \\"externals2\\";
"import { HomeLayout as __WEBPACK_EXTERNAL_MODULE_externals0_HomeLayout__, a as __WEBPACK_EXTERNAL_MODULE_externals0_a__ } from \\"externals0\\";
import { HomeLayout as __WEBPACK_EXTERNAL_MODULE_externals1_HomeLayout__, a as __WEBPACK_EXTERNAL_MODULE_externals1_a__ } from \\"externals1\\";
import { default as __WEBPACK_EXTERNAL_MODULE_externals2_default__ } from \\"externals2\\";
import * as __WEBPACK_EXTERNAL_MODULE_externals3__ from \\"externals3\\";
import \\"externals4\\";
/******/ // The require scope
@ -10292,15 +10292,15 @@ const external_externals3_namespaceObject = __WEBPACK_EXTERNAL_MODULE_externals3
;// ./lib.js
const { HomeLayout: lib_HomeLayout = 123 } = {};
console.log({ HomeLayout: lib_HomeLayout });
const { HomeLayout = 123 } = {};
console.log({ HomeLayout });
{
const { HomeLayout = lib_HomeLayout_0 } = {};
const { HomeLayout = __WEBPACK_EXTERNAL_MODULE_externals0_HomeLayout__ } = {};
console.log({ HomeLayout });
}
(() => {
{
const { HomeLayout = lib_HomeLayout_0 } = {};
const { HomeLayout = __WEBPACK_EXTERNAL_MODULE_externals0_HomeLayout__ } = {};
console.log({ HomeLayout });
}
})()
@ -10334,19 +10334,19 @@ console.log({ HomeLayout: lib_HomeLayout });
const HomeLayout_0 = 'HomeLayout_0';
HomeLayout_0;
}
HomeLayout_0;
a;
a_0;
default_0;
__WEBPACK_EXTERNAL_MODULE_externals1_HomeLayout__;
__WEBPACK_EXTERNAL_MODULE_externals0_a__;
__WEBPACK_EXTERNAL_MODULE_externals1_a__;
__WEBPACK_EXTERNAL_MODULE_externals2_default__;
external_externals3_namespaceObject;
export { lib_HomeLayout as HomeLayout, a };
export { HomeLayout, __WEBPACK_EXTERNAL_MODULE_externals0_a__ as a };
"
`;
exports[`ConfigCacheTestCases library concatenate-modules-named-import-externals concatenate-modules-named-import-externals should pre-compile to fill disk cache (1st) 1`] = `
"import { HomeLayout as lib_HomeLayout_0, a } from \\"externals0\\";
import { HomeLayout as HomeLayout_0, a as a_0 } from \\"externals1\\";
import { default as default_0 } from \\"externals2\\";
"import { HomeLayout as __WEBPACK_EXTERNAL_MODULE_externals0_HomeLayout__, a as __WEBPACK_EXTERNAL_MODULE_externals0_a__ } from \\"externals0\\";
import { HomeLayout as __WEBPACK_EXTERNAL_MODULE_externals1_HomeLayout__, a as __WEBPACK_EXTERNAL_MODULE_externals1_a__ } from \\"externals1\\";
import { default as __WEBPACK_EXTERNAL_MODULE_externals2_default__ } from \\"externals2\\";
import * as __WEBPACK_EXTERNAL_MODULE_externals3__ from \\"externals3\\";
import \\"externals4\\";
/******/ // The require scope
@ -10389,15 +10389,15 @@ const external_externals3_namespaceObject = __WEBPACK_EXTERNAL_MODULE_externals3
;// ./lib.js
const { HomeLayout: lib_HomeLayout = 123 } = {};
console.log({ HomeLayout: lib_HomeLayout });
const { HomeLayout = 123 } = {};
console.log({ HomeLayout });
{
const { HomeLayout = lib_HomeLayout_0 } = {};
const { HomeLayout = __WEBPACK_EXTERNAL_MODULE_externals0_HomeLayout__ } = {};
console.log({ HomeLayout });
}
(() => {
{
const { HomeLayout = lib_HomeLayout_0 } = {};
const { HomeLayout = __WEBPACK_EXTERNAL_MODULE_externals0_HomeLayout__ } = {};
console.log({ HomeLayout });
}
})()
@ -10431,19 +10431,19 @@ console.log({ HomeLayout: lib_HomeLayout });
const HomeLayout_0 = 'HomeLayout_0';
HomeLayout_0;
}
HomeLayout_0;
a;
a_0;
default_0;
__WEBPACK_EXTERNAL_MODULE_externals1_HomeLayout__;
__WEBPACK_EXTERNAL_MODULE_externals0_a__;
__WEBPACK_EXTERNAL_MODULE_externals1_a__;
__WEBPACK_EXTERNAL_MODULE_externals2_default__;
external_externals3_namespaceObject;
export { lib_HomeLayout as HomeLayout, a };
export { HomeLayout, __WEBPACK_EXTERNAL_MODULE_externals0_a__ as a };
"
`;
exports[`ConfigCacheTestCases library concatenate-modules-named-import-externals concatenate-modules-named-import-externals should pre-compile to fill disk cache (2nd) 1`] = `
"import { HomeLayout as lib_HomeLayout_0, a } from \\"externals0\\";
import { HomeLayout as HomeLayout_0, a as a_0 } from \\"externals1\\";
import { default as default_0 } from \\"externals2\\";
"import { HomeLayout as __WEBPACK_EXTERNAL_MODULE_externals0_HomeLayout__, a as __WEBPACK_EXTERNAL_MODULE_externals0_a__ } from \\"externals0\\";
import { HomeLayout as __WEBPACK_EXTERNAL_MODULE_externals1_HomeLayout__, a as __WEBPACK_EXTERNAL_MODULE_externals1_a__ } from \\"externals1\\";
import { default as __WEBPACK_EXTERNAL_MODULE_externals2_default__ } from \\"externals2\\";
import * as __WEBPACK_EXTERNAL_MODULE_externals3__ from \\"externals3\\";
import \\"externals4\\";
/******/ // The require scope
@ -10486,15 +10486,15 @@ const external_externals3_namespaceObject = __WEBPACK_EXTERNAL_MODULE_externals3
;// ./lib.js
const { HomeLayout: lib_HomeLayout = 123 } = {};
console.log({ HomeLayout: lib_HomeLayout });
const { HomeLayout = 123 } = {};
console.log({ HomeLayout });
{
const { HomeLayout = lib_HomeLayout_0 } = {};
const { HomeLayout = __WEBPACK_EXTERNAL_MODULE_externals0_HomeLayout__ } = {};
console.log({ HomeLayout });
}
(() => {
{
const { HomeLayout = lib_HomeLayout_0 } = {};
const { HomeLayout = __WEBPACK_EXTERNAL_MODULE_externals0_HomeLayout__ } = {};
console.log({ HomeLayout });
}
})()
@ -10528,12 +10528,12 @@ console.log({ HomeLayout: lib_HomeLayout });
const HomeLayout_0 = 'HomeLayout_0';
HomeLayout_0;
}
HomeLayout_0;
a;
a_0;
default_0;
__WEBPACK_EXTERNAL_MODULE_externals1_HomeLayout__;
__WEBPACK_EXTERNAL_MODULE_externals0_a__;
__WEBPACK_EXTERNAL_MODULE_externals1_a__;
__WEBPACK_EXTERNAL_MODULE_externals2_default__;
external_externals3_namespaceObject;
export { lib_HomeLayout as HomeLayout, a };
export { HomeLayout, __WEBPACK_EXTERNAL_MODULE_externals0_a__ as a };
"
`;
@ -11333,6 +11333,434 @@ export { __webpack_exports__HomeLayout as HomeLayout, __webpack_exports__a as a
"
`;
exports[`ConfigCacheTestCases library render-order-issue render-order-issue should compile 1`] = `
"import { v as __WEBPACK_EXTERNAL_MODULE_externals0_v__ } from \\"externals0\\";
import { v as __WEBPACK_EXTERNAL_MODULE_externals1_v__ } from \\"externals1\\";
/******/ var __webpack_modules__ = ({
/***/ \\"./bar.js\\":
/*!****************************!*\\\\
!*** ./bar.js + 1 modules ***!
\\\\****************************/
/***/ (() => {
;// external \\"externals0\\"
;// ./bar.js
__WEBPACK_EXTERNAL_MODULE_externals0_v__;
/***/ }),
/***/ \\"./entry.js\\":
/*!******************!*\\\\
!*** ./entry.js ***!
\\\\******************/
/***/ ((module, __unused_webpack_exports, __webpack_require__) => {
module.exports.entry1 = __webpack_require__(/*! ./entry1.js */ \\"./entry1.js\\")
module.exports.entry2 = __webpack_require__(/*! ./entry2.js */ \\"./entry2.js\\")
/***/ }),
/***/ \\"./entry1.js\\":
/*!*******************!*\\\\
!*** ./entry1.js ***!
\\\\*******************/
/***/ ((module, __unused_webpack_exports, __webpack_require__) => {
module.exports = __webpack_require__(/*! ./foo */ \\"./foo.js\\")
module.exports.name = \\"entry1\\"
/***/ }),
/***/ \\"./entry2.js\\":
/*!*******************!*\\\\
!*** ./entry2.js ***!
\\\\*******************/
/***/ ((module, __unused_webpack_exports, __webpack_require__) => {
module.exports = __webpack_require__(/*! ./bar */ \\"./bar.js\\")
module.exports.name = \\"entry2\\"
/***/ }),
/***/ \\"./foo.js\\":
/*!****************************!*\\\\
!*** ./foo.js + 1 modules ***!
\\\\****************************/
/***/ (() => {
;// external \\"externals1\\"
;// ./foo.js
__WEBPACK_EXTERNAL_MODULE_externals1_v__;
/***/ })
/******/ });
/************************************************************************/
/******/ // The module cache
/******/ var __webpack_module_cache__ = {};
/******/
/******/ // The require function
/******/ function __webpack_require__(moduleId) {
/******/ // Check if module is in cache
/******/ var cachedModule = __webpack_module_cache__[moduleId];
/******/ if (cachedModule !== undefined) {
/******/ return cachedModule.exports;
/******/ }
/******/ // Create a new module (and put it into the cache)
/******/ var module = __webpack_module_cache__[moduleId] = {
/******/ // no module.id needed
/******/ // no module.loaded needed
/******/ exports: {}
/******/ };
/******/
/******/ // Execute the module function
/******/ __webpack_modules__[moduleId](module, module.exports, __webpack_require__);
/******/
/******/ // Return the exports of the module
/******/ return module.exports;
/******/ }
/******/
/************************************************************************/
/******/
/******/ // startup
/******/ // Load entry module and return exports
/******/ // This entry module used 'module' so it can't be inlined
/******/ var __webpack_exports__ = __webpack_require__(\\"./entry.js\\");
/******/ const __webpack_exports__entry1 = __webpack_exports__.entry1;
/******/ const __webpack_exports__entry2 = __webpack_exports__.entry2;
/******/ export { __webpack_exports__entry1 as entry1, __webpack_exports__entry2 as entry2, __webpack_exports__ as default };
/******/
"
`;
exports[`ConfigCacheTestCases library render-order-issue render-order-issue should compile 2`] = `
"import { v as __WEBPACK_EXTERNAL_MODULE_externals0_v__ } from \\"externals0\\";
import { v as __WEBPACK_EXTERNAL_MODULE_externals1_v__ } from \\"externals1\\";
/******/ var __webpack_modules__ = ({
/***/ \\"./bar.js\\":
/*!****************************!*\\\\
!*** ./bar.js + 1 modules ***!
\\\\****************************/
/***/ (() => {
;// external \\"externals0\\"
;// ./bar.js
__WEBPACK_EXTERNAL_MODULE_externals0_v__;
/***/ }),
/***/ \\"./entry.js\\":
/*!******************!*\\\\
!*** ./entry.js ***!
\\\\******************/
/***/ ((module, __unused_webpack_exports, __webpack_require__) => {
module.exports.entry1 = __webpack_require__(/*! ./entry1.js */ \\"./entry1.js\\")
module.exports.entry2 = __webpack_require__(/*! ./entry2.js */ \\"./entry2.js\\")
/***/ }),
/***/ \\"./entry1.js\\":
/*!*******************!*\\\\
!*** ./entry1.js ***!
\\\\*******************/
/***/ ((module, __unused_webpack_exports, __webpack_require__) => {
module.exports = __webpack_require__(/*! ./foo */ \\"./foo.js\\")
module.exports.name = \\"entry1\\"
/***/ }),
/***/ \\"./entry2.js\\":
/*!*******************!*\\\\
!*** ./entry2.js ***!
\\\\*******************/
/***/ ((module, __unused_webpack_exports, __webpack_require__) => {
module.exports = __webpack_require__(/*! ./bar */ \\"./bar.js\\")
module.exports.name = \\"entry2\\"
/***/ }),
/***/ \\"./foo.js\\":
/*!****************************!*\\\\
!*** ./foo.js + 1 modules ***!
\\\\****************************/
/***/ (() => {
;// external \\"externals1\\"
;// ./foo.js
__WEBPACK_EXTERNAL_MODULE_externals1_v__;
/***/ })
/******/ });
/************************************************************************/
/******/ // The module cache
/******/ var __webpack_module_cache__ = {};
/******/
/******/ // The require function
/******/ function __webpack_require__(moduleId) {
/******/ // Check if module is in cache
/******/ var cachedModule = __webpack_module_cache__[moduleId];
/******/ if (cachedModule !== undefined) {
/******/ return cachedModule.exports;
/******/ }
/******/ // Create a new module (and put it into the cache)
/******/ var module = __webpack_module_cache__[moduleId] = {
/******/ // no module.id needed
/******/ // no module.loaded needed
/******/ exports: {}
/******/ };
/******/
/******/ // Execute the module function
/******/ __webpack_modules__[moduleId](module, module.exports, __webpack_require__);
/******/
/******/ // Return the exports of the module
/******/ return module.exports;
/******/ }
/******/
/************************************************************************/
/******/
/******/ // startup
/******/ // Load entry module and return exports
/******/ // This entry module used 'module' so it can't be inlined
/******/ var __webpack_exports__ = __webpack_require__(\\"./entry.js\\");
/******/ const __webpack_exports__entry1 = __webpack_exports__.entry1;
/******/ const __webpack_exports__entry2 = __webpack_exports__.entry2;
/******/ export { __webpack_exports__entry1 as entry1, __webpack_exports__entry2 as entry2, __webpack_exports__ as default };
/******/
"
`;
exports[`ConfigCacheTestCases library render-order-issue render-order-issue should pre-compile to fill disk cache (1st) 1`] = `
"import { v as __WEBPACK_EXTERNAL_MODULE_externals0_v__ } from \\"externals0\\";
import { v as __WEBPACK_EXTERNAL_MODULE_externals1_v__ } from \\"externals1\\";
/******/ var __webpack_modules__ = ({
/***/ \\"./bar.js\\":
/*!****************************!*\\\\
!*** ./bar.js + 1 modules ***!
\\\\****************************/
/***/ (() => {
;// external \\"externals0\\"
;// ./bar.js
__WEBPACK_EXTERNAL_MODULE_externals0_v__;
/***/ }),
/***/ \\"./entry.js\\":
/*!******************!*\\\\
!*** ./entry.js ***!
\\\\******************/
/***/ ((module, __unused_webpack_exports, __webpack_require__) => {
module.exports.entry1 = __webpack_require__(/*! ./entry1.js */ \\"./entry1.js\\")
module.exports.entry2 = __webpack_require__(/*! ./entry2.js */ \\"./entry2.js\\")
/***/ }),
/***/ \\"./entry1.js\\":
/*!*******************!*\\\\
!*** ./entry1.js ***!
\\\\*******************/
/***/ ((module, __unused_webpack_exports, __webpack_require__) => {
module.exports = __webpack_require__(/*! ./foo */ \\"./foo.js\\")
module.exports.name = \\"entry1\\"
/***/ }),
/***/ \\"./entry2.js\\":
/*!*******************!*\\\\
!*** ./entry2.js ***!
\\\\*******************/
/***/ ((module, __unused_webpack_exports, __webpack_require__) => {
module.exports = __webpack_require__(/*! ./bar */ \\"./bar.js\\")
module.exports.name = \\"entry2\\"
/***/ }),
/***/ \\"./foo.js\\":
/*!****************************!*\\\\
!*** ./foo.js + 1 modules ***!
\\\\****************************/
/***/ (() => {
;// external \\"externals1\\"
;// ./foo.js
__WEBPACK_EXTERNAL_MODULE_externals1_v__;
/***/ })
/******/ });
/************************************************************************/
/******/ // The module cache
/******/ var __webpack_module_cache__ = {};
/******/
/******/ // The require function
/******/ function __webpack_require__(moduleId) {
/******/ // Check if module is in cache
/******/ var cachedModule = __webpack_module_cache__[moduleId];
/******/ if (cachedModule !== undefined) {
/******/ return cachedModule.exports;
/******/ }
/******/ // Create a new module (and put it into the cache)
/******/ var module = __webpack_module_cache__[moduleId] = {
/******/ // no module.id needed
/******/ // no module.loaded needed
/******/ exports: {}
/******/ };
/******/
/******/ // Execute the module function
/******/ __webpack_modules__[moduleId](module, module.exports, __webpack_require__);
/******/
/******/ // Return the exports of the module
/******/ return module.exports;
/******/ }
/******/
/************************************************************************/
/******/
/******/ // startup
/******/ // Load entry module and return exports
/******/ // This entry module used 'module' so it can't be inlined
/******/ var __webpack_exports__ = __webpack_require__(\\"./entry.js\\");
/******/ const __webpack_exports__entry1 = __webpack_exports__.entry1;
/******/ const __webpack_exports__entry2 = __webpack_exports__.entry2;
/******/ export { __webpack_exports__entry1 as entry1, __webpack_exports__entry2 as entry2, __webpack_exports__ as default };
/******/
"
`;
exports[`ConfigCacheTestCases library render-order-issue render-order-issue should pre-compile to fill disk cache (2nd) 1`] = `
"import { v as __WEBPACK_EXTERNAL_MODULE_externals0_v__ } from \\"externals0\\";
import { v as __WEBPACK_EXTERNAL_MODULE_externals1_v__ } from \\"externals1\\";
/******/ var __webpack_modules__ = ({
/***/ \\"./bar.js\\":
/*!****************************!*\\\\
!*** ./bar.js + 1 modules ***!
\\\\****************************/
/***/ (() => {
;// external \\"externals0\\"
;// ./bar.js
__WEBPACK_EXTERNAL_MODULE_externals0_v__;
/***/ }),
/***/ \\"./entry.js\\":
/*!******************!*\\\\
!*** ./entry.js ***!
\\\\******************/
/***/ ((module, __unused_webpack_exports, __webpack_require__) => {
module.exports.entry1 = __webpack_require__(/*! ./entry1.js */ \\"./entry1.js\\")
module.exports.entry2 = __webpack_require__(/*! ./entry2.js */ \\"./entry2.js\\")
/***/ }),
/***/ \\"./entry1.js\\":
/*!*******************!*\\\\
!*** ./entry1.js ***!
\\\\*******************/
/***/ ((module, __unused_webpack_exports, __webpack_require__) => {
module.exports = __webpack_require__(/*! ./foo */ \\"./foo.js\\")
module.exports.name = \\"entry1\\"
/***/ }),
/***/ \\"./entry2.js\\":
/*!*******************!*\\\\
!*** ./entry2.js ***!
\\\\*******************/
/***/ ((module, __unused_webpack_exports, __webpack_require__) => {
module.exports = __webpack_require__(/*! ./bar */ \\"./bar.js\\")
module.exports.name = \\"entry2\\"
/***/ }),
/***/ \\"./foo.js\\":
/*!****************************!*\\\\
!*** ./foo.js + 1 modules ***!
\\\\****************************/
/***/ (() => {
;// external \\"externals1\\"
;// ./foo.js
__WEBPACK_EXTERNAL_MODULE_externals1_v__;
/***/ })
/******/ });
/************************************************************************/
/******/ // The module cache
/******/ var __webpack_module_cache__ = {};
/******/
/******/ // The require function
/******/ function __webpack_require__(moduleId) {
/******/ // Check if module is in cache
/******/ var cachedModule = __webpack_module_cache__[moduleId];
/******/ if (cachedModule !== undefined) {
/******/ return cachedModule.exports;
/******/ }
/******/ // Create a new module (and put it into the cache)
/******/ var module = __webpack_module_cache__[moduleId] = {
/******/ // no module.id needed
/******/ // no module.loaded needed
/******/ exports: {}
/******/ };
/******/
/******/ // Execute the module function
/******/ __webpack_modules__[moduleId](module, module.exports, __webpack_require__);
/******/
/******/ // Return the exports of the module
/******/ return module.exports;
/******/ }
/******/
/************************************************************************/
/******/
/******/ // startup
/******/ // Load entry module and return exports
/******/ // This entry module used 'module' so it can't be inlined
/******/ var __webpack_exports__ = __webpack_require__(\\"./entry.js\\");
/******/ const __webpack_exports__entry1 = __webpack_exports__.entry1;
/******/ const __webpack_exports__entry2 = __webpack_exports__.entry2;
/******/ export { __webpack_exports__entry1 as entry1, __webpack_exports__entry2 as entry2, __webpack_exports__ as default };
/******/
"
`;
exports[`ConfigCacheTestCases source-map extract-source-map exported tests should extract source map - 1 1`] = `
Array [
"webpack:///./external-source-map.txt",

View File

@ -10150,9 +10150,9 @@ exports[`ConfigTestCases css webpack-ignore exported tests should compile 1`] =
`;
exports[`ConfigTestCases library concatenate-modules-named-import-externals concatenate-modules-named-import-externals should compile 1`] = `
"import { HomeLayout as lib_HomeLayout_0, a } from \\"externals0\\";
import { HomeLayout as HomeLayout_0, a as a_0 } from \\"externals1\\";
import { default as default_0 } from \\"externals2\\";
"import { HomeLayout as __WEBPACK_EXTERNAL_MODULE_externals0_HomeLayout__, a as __WEBPACK_EXTERNAL_MODULE_externals0_a__ } from \\"externals0\\";
import { HomeLayout as __WEBPACK_EXTERNAL_MODULE_externals1_HomeLayout__, a as __WEBPACK_EXTERNAL_MODULE_externals1_a__ } from \\"externals1\\";
import { default as __WEBPACK_EXTERNAL_MODULE_externals2_default__ } from \\"externals2\\";
import * as __WEBPACK_EXTERNAL_MODULE_externals3__ from \\"externals3\\";
import \\"externals4\\";
/******/ // The require scope
@ -10195,15 +10195,15 @@ const external_externals3_namespaceObject = __WEBPACK_EXTERNAL_MODULE_externals3
;// ./lib.js
const { HomeLayout: lib_HomeLayout = 123 } = {};
console.log({ HomeLayout: lib_HomeLayout });
const { HomeLayout = 123 } = {};
console.log({ HomeLayout });
{
const { HomeLayout = lib_HomeLayout_0 } = {};
const { HomeLayout = __WEBPACK_EXTERNAL_MODULE_externals0_HomeLayout__ } = {};
console.log({ HomeLayout });
}
(() => {
{
const { HomeLayout = lib_HomeLayout_0 } = {};
const { HomeLayout = __WEBPACK_EXTERNAL_MODULE_externals0_HomeLayout__ } = {};
console.log({ HomeLayout });
}
})()
@ -10237,12 +10237,12 @@ console.log({ HomeLayout: lib_HomeLayout });
const HomeLayout_0 = 'HomeLayout_0';
HomeLayout_0;
}
HomeLayout_0;
a;
a_0;
default_0;
__WEBPACK_EXTERNAL_MODULE_externals1_HomeLayout__;
__WEBPACK_EXTERNAL_MODULE_externals0_a__;
__WEBPACK_EXTERNAL_MODULE_externals1_a__;
__WEBPACK_EXTERNAL_MODULE_externals2_default__;
external_externals3_namespaceObject;
export { lib_HomeLayout as HomeLayout, a };
export { HomeLayout, __WEBPACK_EXTERNAL_MODULE_externals0_a__ as a };
"
`;
@ -10445,6 +10445,113 @@ export { __webpack_exports__HomeLayout as HomeLayout, __webpack_exports__a as a
"
`;
exports[`ConfigTestCases library render-order-issue render-order-issue should compile 1`] = `
"import { v as __WEBPACK_EXTERNAL_MODULE_externals0_v__ } from \\"externals0\\";
import { v as __WEBPACK_EXTERNAL_MODULE_externals1_v__ } from \\"externals1\\";
/******/ var __webpack_modules__ = ({
/***/ \\"./bar.js\\":
/*!****************************!*\\\\
!*** ./bar.js + 1 modules ***!
\\\\****************************/
/***/ (() => {
;// external \\"externals0\\"
;// ./bar.js
__WEBPACK_EXTERNAL_MODULE_externals0_v__;
/***/ }),
/***/ \\"./entry.js\\":
/*!******************!*\\\\
!*** ./entry.js ***!
\\\\******************/
/***/ ((module, __unused_webpack_exports, __webpack_require__) => {
module.exports.entry1 = __webpack_require__(/*! ./entry1.js */ \\"./entry1.js\\")
module.exports.entry2 = __webpack_require__(/*! ./entry2.js */ \\"./entry2.js\\")
/***/ }),
/***/ \\"./entry1.js\\":
/*!*******************!*\\\\
!*** ./entry1.js ***!
\\\\*******************/
/***/ ((module, __unused_webpack_exports, __webpack_require__) => {
module.exports = __webpack_require__(/*! ./foo */ \\"./foo.js\\")
module.exports.name = \\"entry1\\"
/***/ }),
/***/ \\"./entry2.js\\":
/*!*******************!*\\\\
!*** ./entry2.js ***!
\\\\*******************/
/***/ ((module, __unused_webpack_exports, __webpack_require__) => {
module.exports = __webpack_require__(/*! ./bar */ \\"./bar.js\\")
module.exports.name = \\"entry2\\"
/***/ }),
/***/ \\"./foo.js\\":
/*!****************************!*\\\\
!*** ./foo.js + 1 modules ***!
\\\\****************************/
/***/ (() => {
;// external \\"externals1\\"
;// ./foo.js
__WEBPACK_EXTERNAL_MODULE_externals1_v__;
/***/ })
/******/ });
/************************************************************************/
/******/ // The module cache
/******/ var __webpack_module_cache__ = {};
/******/
/******/ // The require function
/******/ function __webpack_require__(moduleId) {
/******/ // Check if module is in cache
/******/ var cachedModule = __webpack_module_cache__[moduleId];
/******/ if (cachedModule !== undefined) {
/******/ return cachedModule.exports;
/******/ }
/******/ // Create a new module (and put it into the cache)
/******/ var module = __webpack_module_cache__[moduleId] = {
/******/ // no module.id needed
/******/ // no module.loaded needed
/******/ exports: {}
/******/ };
/******/
/******/ // Execute the module function
/******/ __webpack_modules__[moduleId](module, module.exports, __webpack_require__);
/******/
/******/ // Return the exports of the module
/******/ return module.exports;
/******/ }
/******/
/************************************************************************/
/******/
/******/ // startup
/******/ // Load entry module and return exports
/******/ // This entry module used 'module' so it can't be inlined
/******/ var __webpack_exports__ = __webpack_require__(\\"./entry.js\\");
/******/ const __webpack_exports__entry1 = __webpack_exports__.entry1;
/******/ const __webpack_exports__entry2 = __webpack_exports__.entry2;
/******/ export { __webpack_exports__entry1 as entry1, __webpack_exports__entry2 as entry2, __webpack_exports__ as default };
/******/
"
`;
exports[`ConfigTestCases source-map extract-source-map exported tests should extract source map - 1 1`] = `
Array [
"webpack:///./external-source-map.txt",

View File

@ -3,7 +3,7 @@ const path = require("path");
it("module-import should correctly get fallback type", function() {
const content = fs.readFileSync(path.resolve(__dirname, "a.js"), "utf-8");
expect(content).toContain(`import { default as default_0 } from "external0"`); // module
expect(content).toContain(`import { default as __WEBPACK_EXTERNAL_MODULE_external0_default__ } from "external0"`); // module
expect(content).toContain(`import * as __WEBPACK_EXTERNAL_MODULE_external1__ from "external1"`); // module
expect(content).toContain(`module.exports = __WEBPACK_EXTERNAL_createRequire(import.meta.url)("external2")`); // node-commonjs
expect(content).toContain(`import * as __WEBPACK_EXTERNAL_MODULE_external3__ from "external3"`); // module

View File

@ -0,0 +1,2 @@
import { v } from "externals0";
v;

View File

@ -0,0 +1,2 @@
module.exports.entry1 = require('./entry1.js')
module.exports.entry2 = require('./entry2.js')

View File

@ -0,0 +1,2 @@
module.exports = require('./foo')
module.exports.name = "entry1"

View File

@ -0,0 +1,2 @@
module.exports = require('./bar')
module.exports.name = "entry2"

View File

@ -0,0 +1,2 @@
import { v } from "externals1";
v;

View File

@ -0,0 +1,3 @@
it('should work', () => {
expect(true).toBe(true);
});

View File

@ -0,0 +1,22 @@
"use strict";
/** @typedef {import("../../../../types").LoaderDefinition} LoaderDefinition */
/**
* @type {LoaderDefinition}
*/
module.exports = function loader(code) {
const request = this.resourcePath;
const callback = this.async();
// You can simulate an unstable async operation by switching the waiting module
// uncomment this 👇 and run again
// if (request.includes("entry1")) {
if (request.includes("entry2")) {
setTimeout(() => {
callback(null, code);
}, 2000);
} else {
callback(null, code);
}
};

View File

@ -0,0 +1,7 @@
"use strict";
module.exports = {
findBundle() {
return ["main.mjs"];
}
};

View File

@ -0,0 +1,58 @@
"use strict";
/** @type {import("../../../../types").Configuration} */
module.exports = {
mode: "development",
devtool: false,
optimization: {
minimize: false,
moduleIds: "named",
concatenateModules: true,
usedExports: true
},
entry: {
main: "./index.js",
entry: "./entry.js"
},
output: {
clean: true,
filename: "[name].mjs",
library: {
type: "module"
}
},
externalsType: "module",
externals: ["externals0", "externals1"],
experiments: {
outputModule: true
},
module: {
rules: [
{
test: /\.js$/,
loader: "./loader",
sideEffects: true
}
]
},
plugins: [
(compiler) => {
compiler.hooks.compilation.tap(
"testcase",
(
/** @type {import("../../../../types").Compilation} */ compilation
) => {
compilation.hooks.afterProcessAssets.tap(
"testcase",
(
/** @type {Record<string, import("webpack-sources").Source>} */ assets
) => {
const source = assets["entry.mjs"].source();
expect(source).toMatchSnapshot();
}
);
}
);
}
]
};

2
types.d.ts vendored
View File

@ -10097,6 +10097,8 @@ declare class ModuleExternalInitFragment extends InitFragment<GenerateContext> {
getImported(): Imported;
setImported(imported: Imported): void;
getNamespaceIdentifier(): string;
buildIdentifier(ident: string): string;
buildImported(imported: Imported): Imported;
static addToSource<Context>(
source: Source,
initFragments: MaybeMergeableInitFragment<Context>[],