Merge pull request #11144 from webpack/bugfix/provide-no-override-loaded

providing module do not override already loaded modules
This commit is contained in:
Tobias Koppers 2020-07-09 13:16:29 +02:00 committed by GitHub
commit dd24d77c99
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 38 additions and 1 deletions

View File

@ -80,7 +80,7 @@ class ShareRuntimeModule extends RuntimeModule {
[
"var versions = scope[name] = scope[name] || {};",
"var activeVersion = versions[version];",
"if(!activeVersion || uniqueName > activeVersion.from) versions[version] = { get: factory, from: uniqueName };"
"if(!activeVersion || !activeVersion.loaded && uniqueName > activeVersion.from) versions[version] = { get: factory, from: uniqueName };"
]
)};`,
`var initExternal = ${runtimeTemplate.basicFunction("id", [

View File

@ -0,0 +1,13 @@
it("should not override an already loaded shared module version", async () => {
__webpack_share_scopes__.default = {
package: {
"1.0.0": {
get: () => () => 42,
loaded: true,
from: "a"
}
}
};
await __webpack_init_sharing__("default");
expect(require("package")).toBe(42);
});

View File

@ -0,0 +1 @@
module.exports = "package";

View File

@ -0,0 +1,3 @@
{
"version": "1.0.0"
}

View File

@ -0,0 +1,6 @@
{
"version": "0.0.0",
"dependencies": {
"package": "1"
}
}

View File

@ -0,0 +1,14 @@
// eslint-disable-next-line node/no-unpublished-require
const { SharePlugin } = require("../../../../").sharing;
/** @type {import("../../../../").Configuration} */
module.exports = {
output: {
uniqueName: "b"
},
plugins: [
new SharePlugin({
shared: ["package"]
})
]
};