fix resource identifier in Compilation and resolveLoader options

This commit is contained in:
Ivan Kopeykin 2020-05-28 10:10:31 +03:00
parent d4b1819749
commit 4af609a38c
4 changed files with 35 additions and 21 deletions

View File

@ -1134,17 +1134,18 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
const processDependency = dep => {
this.moduleGraph.setParents(dep, currentBlock, module);
const resourceIdent =
dep.category === esmDependencyCategory
? dep.getResourceIdentifier()
: `${dep.category}${dep.getResourceIdentifier()}`;
const resourceIdent = dep.getResourceIdentifier();
if (resourceIdent) {
const cacheKey =
dep.category === esmDependencyCategory
? resourceIdent
: `${dep.category}${resourceIdent}`;
const constructor = dep.constructor;
let innerMap;
let factory;
if (factoryCacheKey === constructor) {
innerMap = factoryCacheValue;
if (listCacheKey === resourceIdent) {
if (listCacheKey === cacheKey) {
listCacheValue.push(dep);
return;
}
@ -1163,9 +1164,9 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
factoryCacheValue = innerMap;
factoryCacheValue2 = factory;
}
let list = innerMap.get(resourceIdent);
let list = innerMap.get(cacheKey);
if (list === undefined) {
innerMap.set(resourceIdent, (list = []));
innerMap.set(cacheKey, (list = []));
sortedDependencies.push({
factory: factoryCacheValue2,
dependencies: list,
@ -1173,7 +1174,7 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
});
}
list.push(dep);
listCacheKey = resourceIdent;
listCacheKey = cacheKey;
listCacheValue = list;
}
};

View File

@ -639,13 +639,10 @@ class WebpackOptionsApply extends OptionsApply {
});
compiler.resolverFactory.hooks.resolveOptions
.for("loader")
.tap("WebpackOptionsApply", (resolveOptions, category) => {
.tap("WebpackOptionsApply", resolveOptions => {
return {
fileSystem: compiler.inputFileSystem,
...cachedCleverMerge(
resolveOptionsByCategory.get(category) || baseResolveOptions,
resolveOptions
)
...cachedCleverMerge(options.resolveLoader, resolveOptions)
};
});
compiler.hooks.afterResolvers.call(compiler);

View File

@ -236,6 +236,20 @@ describe("Defaults", () => {
"aliasFields": Array [
"browser",
],
"byDependency": Object {
"commonjs": Object {
"conditionNames": Array [
"require",
"...",
],
},
"esm": Object {
"conditionNames": Array [
"import",
"...",
],
},
},
"cache": false,
"conditionNames": Array [
"webpack",
@ -264,6 +278,8 @@ describe("Defaults", () => {
"resolveLoader": Object {
"cache": false,
"conditionNames": Array [
"loader",
"require",
"node",
],
"exportsFields": Array [

View File

@ -2826,26 +2826,26 @@ Object {
"resolve-exports-fields": Object {
"configs": Array [
Object {
"description": "Field names from the description file (package.json) which are used to find the exports field entry point.",
"description": "Field name from the description file (usually package.json) which is used to provide entry points of a package.",
"multiple": true,
"path": "resolve.exportsFields[]",
"type": "string",
},
],
"description": "Field names from the description file (package.json) which are used to find the exports field entry point.",
"description": "Field name from the description file (usually package.json) which is used to provide entry points of a package.",
"multiple": true,
"simpleType": "string",
},
"resolve-exports-fields-reset": Object {
"configs": Array [
Object {
"description": "Clear all items provided in configuration. Field names from the description file (package.json) which are used to find the exports field entry point.",
"description": "Clear all items provided in configuration. Field names from the description file (usually package.json) which are used to provide entry points of a package.",
"multiple": false,
"path": "resolve.exportsFields",
"type": "reset",
},
],
"description": "Clear all items provided in configuration. Field names from the description file (package.json) which are used to find the exports field entry point.",
"description": "Clear all items provided in configuration. Field names from the description file (usually package.json) which are used to provide entry points of a package.",
"multiple": false,
"simpleType": "boolean",
},
@ -3056,26 +3056,26 @@ Object {
"resolve-loader-exports-fields": Object {
"configs": Array [
Object {
"description": "Field names from the description file (package.json) which are used to find the exports field entry point.",
"description": "Field name from the description file (usually package.json) which is used to provide entry points of a package.",
"multiple": true,
"path": "resolveLoader.exportsFields[]",
"type": "string",
},
],
"description": "Field names from the description file (package.json) which are used to find the exports field entry point.",
"description": "Field name from the description file (usually package.json) which is used to provide entry points of a package.",
"multiple": true,
"simpleType": "string",
},
"resolve-loader-exports-fields-reset": Object {
"configs": Array [
Object {
"description": "Clear all items provided in configuration. Field names from the description file (package.json) which are used to find the exports field entry point.",
"description": "Clear all items provided in configuration. Field names from the description file (usually package.json) which are used to provide entry points of a package.",
"multiple": false,
"path": "resolveLoader.exportsFields",
"type": "reset",
},
],
"description": "Clear all items provided in configuration. Field names from the description file (package.json) which are used to find the exports field entry point.",
"description": "Clear all items provided in configuration. Field names from the description file (usually package.json) which are used to provide entry points of a package.",
"multiple": false,
"simpleType": "boolean",
},