Unverified Commit 4d50ff30 authored by Tobias Koppers's avatar Tobias Koppers Committed by GitHub

update webpack (#29738)

parent fcdba560
......@@ -38,7 +38,7 @@ module.exports = JSON.parse("{\"application/1d-interleaved-parityfec\":{\"source
/***/ (function(module) {
"use strict";
module.exports = {"i8":"5.58.0"};
module.exports = {"i8":"5.58.1"};
/***/ }),
......@@ -23127,201 +23127,6 @@ class Chunk {
module.exports = Chunk;
/***/ }),
/***/ 70359:
/***/ (function(module, __unused_webpack_exports, __webpack_require__) {
"use strict";
/*
MIT License http://www.opensource.org/licenses/mit-license.php
Author Tobias Koppers @sokra
*/
const SortableSet = __webpack_require__(67563);
/** @typedef {import("./Chunk")} Chunk */
/**
* @template T
* @param {SortableSet<T>} set the set
* @returns {T[]} set as array
*/
const getArray = set => {
return Array.from(set);
};
let debugId = 1;
class ChunkCombination {
constructor() {
this.debugId = debugId++;
this.size = 0;
/**
* (do not modify)
* @type {SortableSet<Chunk>}
*/
this._chunks = new SortableSet();
/** @type {ChunkCombination} */
this._parent = undefined;
this._lastChunk = undefined;
/** @type {WeakMap<Chunk, ChunkCombination>} */
this._addMap = new WeakMap();
/** @type {WeakMap<Chunk, ChunkCombination>} */
this._removeCache = new WeakMap();
}
/**
* @returns {Iterable<Chunk>} iterable of chunks
*/
get chunksIterable() {
return this._chunks;
}
/**
* @param {Chunk} chunk chunk to add
* @returns {ChunkCombination} new chunk combination
*/
with(chunk) {
if (this._chunks.has(chunk)) return this;
let next = this._addMap.get(chunk);
if (next !== undefined) return next;
// must insert chunks in order to maintain order-independent identity of ChunkCombination
if (!this._parent || this._lastChunk.debugId < chunk.debugId) {
next = new ChunkCombination();
for (const chunk of this._chunks) {
next._chunks.add(chunk);
}
next._chunks.add(chunk);
next._removeCache.set(chunk, this);
next.size = this.size + 1;
next._parent = this;
next._lastChunk = chunk;
} else {
next = this._parent.with(chunk).with(this._lastChunk);
}
this._addMap.set(chunk, next);
return next;
}
/**
* @param {Chunk} chunk chunk to remove
* @returns {ChunkCombination} new chunk combination
*/
without(chunk) {
if (!this._chunks.has(chunk)) return this;
let next = this._removeCache.get(chunk);
if (next !== undefined) return next;
const stack = [this._lastChunk];
let current = this._parent;
while (current._lastChunk !== chunk) {
stack.push(current._lastChunk);
current = current._parent;
}
next = current._parent;
while (stack.length) next = next.with(stack.pop());
this._removeCache.set(chunk, next);
return next;
}
withAll(other) {
if (other.size === 0) return this;
if (this.size === 0) return other;
const stack = [];
/** @type {ChunkCombination} */
let current = this;
for (;;) {
if (current._lastChunk.debugId < other._lastChunk.debugId) {
stack.push(other._lastChunk);
other = other._parent;
if (other.size === 0) {
while (stack.length) current = current.with(stack.pop());
return current;
}
} else {
stack.push(current._lastChunk);
current = current._parent;
if (current.size === 0) {
while (stack.length) other = other.with(stack.pop());
return other;
}
}
}
}
hasSharedChunks(other) {
if (this.size > other.size) {
const chunks = this._chunks;
for (const chunk of other._chunks) {
if (chunks.has(chunk)) return true;
}
} else {
const chunks = other._chunks;
for (const chunk of this._chunks) {
if (chunks.has(chunk)) return true;
}
}
return false;
}
/**
* @param {ChunkCombination} other other combination
* @returns {boolean} true, when other is a subset of this combination
*/
isSubset(other) {
// TODO: This could be more efficient when using the debugId order of the combinations
/** @type {ChunkCombination} */
let current = this;
let otherSize = other.size;
let currentSize = current.size;
if (otherSize === 0) return true;
for (;;) {
if (currentSize === 0) return false;
if (otherSize === 1) {
if (currentSize === 1) {
return current._lastChunk === other._lastChunk;
} else {
return current._chunks.has(other._lastChunk);
}
}
if (otherSize * 8 < currentSize) {
// go for the Set access when current >> other
const chunks = current._chunks;
for (const item of other._chunks) {
if (!chunks.has(item)) return false;
}
return true;
}
const otherId = other._lastChunk.debugId;
// skip over nodes in current that have higher ids
while (otherId < current._lastChunk.debugId) {
current = current._parent;
currentSize--;
if (currentSize === 0) return false;
}
if (otherId > current._lastChunk.debugId) {
return false;
}
other = other._parent;
otherSize--;
if (otherSize === 0) return true;
current = current._parent;
currentSize--;
}
}
getChunks() {
return this._chunks.getFromUnorderedCache(getArray);
}
}
ChunkCombination.empty = new ChunkCombination();
module.exports = ChunkCombination;
/***/ }),
/***/ 97860:
......@@ -23336,7 +23141,6 @@ module.exports = ChunkCombination;
const util = __webpack_require__(31669);
const ChunkCombination = __webpack_require__(70359);
const Entrypoint = __webpack_require__(86695);
const ModuleGraphConnection = __webpack_require__(94144);
const { first } = __webpack_require__(34715);
......@@ -23371,8 +23175,6 @@ const {
/** @type {ReadonlySet<string>} */
const EMPTY_SET = new Set();
const EMPTY_RUNTIME_SPEC_SET = new RuntimeSpecSet();
const ZERO_BIG_INT = BigInt(0);
const compareModuleIterables = compareIterables(compareModulesByIdentifier);
......@@ -23510,7 +23312,8 @@ const isAvailableChunk = (a, b) => {
class ChunkGraphModule {
constructor() {
this.chunkCombination = ChunkCombination.empty;
/** @type {SortableSet<Chunk>} */
this.chunks = new SortableSet();
/** @type {Set<Chunk> | undefined} */
this.entryInChunks = undefined;
/** @type {Set<Chunk> | undefined} */
......@@ -23633,7 +23436,7 @@ class ChunkGraph {
connectChunkAndModule(chunk, module) {
const cgm = this._getChunkGraphModule(module);
const cgc = this._getChunkGraphChunk(chunk);
cgm.chunkCombination = cgm.chunkCombination.with(chunk);
cgm.chunks.add(chunk);
cgc.modules.add(module);
}
......@@ -23646,7 +23449,7 @@ class ChunkGraph {
const cgm = this._getChunkGraphModule(module);
const cgc = this._getChunkGraphChunk(chunk);
cgc.modules.delete(module);
cgm.chunkCombination = cgm.chunkCombination.without(chunk);
cgm.chunks.delete(chunk);
}
/**
......@@ -23657,7 +23460,7 @@ class ChunkGraph {
const cgc = this._getChunkGraphChunk(chunk);
for (const module of cgc.modules) {
const cgm = this._getChunkGraphModule(module);
cgm.chunkCombination = cgm.chunkCombination.without(chunk);
cgm.chunks.delete(chunk);
}
cgc.modules.clear();
chunk.disconnectFromGroups();
......@@ -23724,13 +23527,13 @@ class ChunkGraph {
const oldCgm = this._getChunkGraphModule(oldModule);
const newCgm = this._getChunkGraphModule(newModule);
for (const chunk of oldCgm.chunkCombination._chunks) {
for (const chunk of oldCgm.chunks) {
const cgc = this._getChunkGraphChunk(chunk);
cgc.modules.delete(oldModule);
cgc.modules.add(newModule);
newCgm.chunkCombination = newCgm.chunkCombination.with(chunk);
newCgm.chunks.add(chunk);
}
oldCgm.chunkCombination = ChunkCombination.empty;
oldCgm.chunks.clear();
if (oldCgm.entryInChunks !== undefined) {
if (newCgm.entryInChunks === undefined) {
......@@ -23817,22 +23620,13 @@ class ChunkGraph {
return cgm.entryInChunks !== undefined;
}
/**
* @param {Module} module the module
* @returns {ChunkCombination} chunk combination (do not modify)
*/
getModuleChunkCombination(module) {
const cgm = this._getChunkGraphModule(module);
return cgm.chunkCombination;
}
/**
* @param {Module} module the module
* @returns {Iterable<Chunk>} iterable of chunks (do not modify)
*/
getModuleChunksIterable(module) {
const cgm = this._getChunkGraphModule(module);
return cgm.chunkCombination._chunks;
return cgm.chunks;
}
/**
......@@ -23842,9 +23636,8 @@ class ChunkGraph {
*/
getOrderedModuleChunksIterable(module, sortFn) {
const cgm = this._getChunkGraphModule(module);
const chunks = cgm.chunkCombination._chunks;
chunks.sortWith(sortFn);
return chunks;
cgm.chunks.sortWith(sortFn);
return cgm.chunks;
}
/**
......@@ -23853,7 +23646,7 @@ class ChunkGraph {
*/
getModuleChunks(module) {
const cgm = this._getChunkGraphModule(module);
return cgm.chunkCombination.getChunks();
return cgm.chunks.getFromCache(getArray);
}
/**
......@@ -23862,7 +23655,7 @@ class ChunkGraph {
*/
getNumberOfModuleChunks(module) {
const cgm = this._getChunkGraphModule(module);
return cgm.chunkCombination.size;
return cgm.chunks.size;
}
/**
......@@ -23871,10 +23664,7 @@ class ChunkGraph {
*/
getModuleRuntimes(module) {
const cgm = this._getChunkGraphModule(module);
if (cgm.chunkCombination.size === 0) return EMPTY_RUNTIME_SPEC_SET;
return cgm.chunkCombination._chunks.getFromUnorderedCache(
getModuleRuntimes
);
return cgm.chunks.getFromUnorderedCache(getModuleRuntimes);
}
/**
......@@ -24238,7 +24028,8 @@ class ChunkGraph {
// Merge runtime
chunkA.runtime = mergeRuntime(chunkA.runtime, chunkB.runtime);
for (const module of this.getChunkModulesIterable(chunkB)) {
// getChunkModules is used here to create a clone, because disconnectChunkAndModule modifies
for (const module of this.getChunkModules(chunkB)) {
this.disconnectChunkAndModule(chunkB, module);
this.connectChunkAndModule(chunkA, module);
}
......@@ -30258,7 +30049,7 @@ Or do you want to use the entrypoints '${name}' and '${runtime}' independently o
this.moduleGraph.removeConnection(dep);
if (this.chunkGraph) {
for (const chunk of this.chunkGraph.getModuleChunksIterable(
for (const chunk of this.chunkGraph.getModuleChunks(
originalModule
)) {
this.patchChunksAfterReasonRemoval(originalModule, chunk);
......@@ -31469,7 +31260,7 @@ This prevents using hashes of each other and should be avoided.`);
strictModuleErrorHandling,
strictModuleExceptionHandling
} = this.outputOptions;
const __nested_webpack_require_147795__ = id => {
const __nested_webpack_require_147787__ = id => {
const cached = moduleCache[id];
if (cached !== undefined) {
if (cached.error) throw cached.error;
......@@ -31478,20 +31269,20 @@ This prevents using hashes of each other and should be avoided.`);
const moduleArgument = moduleArgumentsById.get(id);
return __webpack_require_module__(moduleArgument, id);
};
const interceptModuleExecution = (__nested_webpack_require_147795__[
const interceptModuleExecution = (__nested_webpack_require_147787__[
RuntimeGlobals.interceptModuleExecution.replace(
"__webpack_require__.",
""
)
] = []);
const moduleCache = (__nested_webpack_require_147795__[
const moduleCache = (__nested_webpack_require_147787__[
RuntimeGlobals.moduleCache.replace(
"__webpack_require__.",
""
)
] = {});
context.__webpack_require__ = __nested_webpack_require_147795__;
context.__webpack_require__ = __nested_webpack_require_147787__;
/**
* @param {ExecuteModuleArgument} moduleArgument the module argument
......@@ -31507,7 +31298,7 @@ This prevents using hashes of each other and should be avoided.`);
loaded: false,
error: undefined
},
require: __nested_webpack_require_147795__
require: __nested_webpack_require_147787__
};
interceptModuleExecution.forEach(handler =>
handler(execOptions)
......@@ -31547,7 +31338,7 @@ This prevents using hashes of each other and should be avoided.`);
moduleArgumentsMap.get(runtimeModule)
);
}
exports = __nested_webpack_require_147795__(module.identifier());
exports = __nested_webpack_require_147787__(module.identifier());
} catch (e) {
const err = new WebpackError(
`Execution of module code from module graph (${module.readableIdentifier(
......@@ -54212,49 +54003,68 @@ class NormalModuleFactory extends ModuleFactory {
: "") +
stringifyLoadersAndResource(loaders, resourceData.resource);
const resourceDataForRules = matchResourceData || resourceData;
const result = this.ruleSet.exec({
resource: resourceDataForRules.path,
realResource: resourceData.path,
resourceQuery: resourceDataForRules.query,
resourceFragment: resourceDataForRules.fragment,
scheme,
assertions,
mimetype: matchResourceData ? "" : resourceData.data.mimetype || "",
dependency: dependencyType,
descriptionData: matchResourceData
? undefined
: resourceData.data.descriptionFileData,
issuer: contextInfo.issuer,
compiler: contextInfo.compiler,
issuerLayer: contextInfo.issuerLayer || ""
});
const settings = {};
const useLoadersPost = [];
const useLoaders = [];
const useLoadersPre = [];
for (const r of result) {
if (r.type === "use") {
if (!noAutoLoaders && !noPrePostAutoLoaders) {
useLoaders.push(r.value);
}
} else if (r.type === "use-post") {
if (!noPrePostAutoLoaders) {
useLoadersPost.push(r.value);
}
} else if (r.type === "use-pre") {
if (!noPreAutoLoaders && !noPrePostAutoLoaders) {
useLoadersPre.push(r.value);
// handle .webpack[] suffix
let resource;
let match;
if (
matchResourceData &&
typeof (resource = matchResourceData.resource) === "string" &&
(match = /\.webpack\[([^\]]+)\]$/.exec(resource))
) {
settings.type = match[1];
matchResourceData.resource = matchResourceData.resource.slice(
0,
-settings.type.length - 10
);
} else {
settings.type = "javascript/auto";
const resourceDataForRules = matchResourceData || resourceData;
const result = this.ruleSet.exec({
resource: resourceDataForRules.path,
realResource: resourceData.path,
resourceQuery: resourceDataForRules.query,
resourceFragment: resourceDataForRules.fragment,
scheme,
assertions,
mimetype: matchResourceData
? ""
: resourceData.data.mimetype || "",
dependency: dependencyType,
descriptionData: matchResourceData
? undefined
: resourceData.data.descriptionFileData,
issuer: contextInfo.issuer,
compiler: contextInfo.compiler,
issuerLayer: contextInfo.issuerLayer || ""
});
for (const r of result) {
if (r.type === "use") {
if (!noAutoLoaders && !noPrePostAutoLoaders) {
useLoaders.push(r.value);
}
} else if (r.type === "use-post") {
if (!noPrePostAutoLoaders) {
useLoadersPost.push(r.value);
}
} else if (r.type === "use-pre") {
if (!noPreAutoLoaders && !noPrePostAutoLoaders) {
useLoadersPre.push(r.value);
}
} else if (
typeof r.value === "object" &&
r.value !== null &&
typeof settings[r.type] === "object" &&
settings[r.type] !== null
) {
settings[r.type] = cachedCleverMerge(settings[r.type], r.value);
} else {
settings[r.type] = r.value;
}
} else if (
typeof r.value === "object" &&
r.value !== null &&
typeof settings[r.type] === "object" &&
settings[r.type] !== null
) {
settings[r.type] = cachedCleverMerge(settings[r.type], r.value);
} else {
settings[r.type] = r.value;
}
}
......@@ -54274,23 +54084,6 @@ class NormalModuleFactory extends ModuleFactory {
}
for (const loader of preLoaders) allLoaders.push(loader);
let type = settings.type;
if (!type) {
let resource;
let match;
if (
matchResourceData &&
typeof (resource = matchResourceData.resource) === "string" &&
(match = /\.webpack\[([^\]]+)\]$/.exec(resource))
) {
type = match[1];
matchResourceData.resource = matchResourceData.resource.slice(
0,
-type.length - 10
);
} else {
type = "javascript/auto";
}
}
const resolveOptions = settings.resolve;
const layer = settings.layer;
if (layer !== undefined && !layers) {
......@@ -104945,10 +104738,11 @@ module.exports = SideEffectsFlagPlugin;
const ChunkCombination = __webpack_require__(70359);
const Chunk = __webpack_require__(65574);
const { STAGE_ADVANCED } = __webpack_require__(68145);
const WebpackError = __webpack_require__(68422);
const { requestToId } = __webpack_require__(72922);
const { isSubset } = __webpack_require__(34715);
const SortableSet = __webpack_require__(67563);
const {
compareModulesByIdentifier,
......@@ -104965,7 +104759,6 @@ const MinMaxSizeWarning = __webpack_require__(46681);
/** @typedef {import("../../declarations/WebpackOptions").OptimizationSplitChunksOptions} OptimizationSplitChunksOptions */
/** @typedef {import("../../declarations/WebpackOptions").OptimizationSplitChunksSizes} OptimizationSplitChunksSizes */
/** @typedef {import("../../declarations/WebpackOptions").Output} OutputOptions */
/** @typedef {import("../Chunk")} Chunk */
/** @typedef {import("../ChunkGraph")} ChunkGraph */
/** @typedef {import("../ChunkGroup")} ChunkGroup */
/** @typedef {import("../Compilation").AssetInfo} AssetInfo */
......@@ -105095,9 +104888,9 @@ const MinMaxSizeWarning = __webpack_require__(46681);
* @property {number} cacheGroupIndex
* @property {string} name
* @property {Record<string, number>} sizes
* @property {ChunkCombination} chunks
* @property {Set<Chunk>} chunks
* @property {Set<Chunk>} reuseableChunks
* @property {Set<ChunkCombination>} chunkCombinations
* @property {Set<bigint | Chunk>} chunksKeys
*/
const defaultGetName = /** @type {GetName} */ (() => {});
......@@ -105144,6 +104937,19 @@ const mapObject = (obj, fn) => {
return newObj;
};
/**
* @template T
* @param {Set<T>} a set
* @param {Set<T>} b other set
* @returns {boolean} true if at least one item of a is in b
*/
const isOverlap = (a, b) => {
for (const item of a) {
if (b.has(item)) return true;
}
return false;
};
const compareModuleIterables = compareIterables(compareModulesByIdentifier);
/**
......@@ -105696,132 +105502,207 @@ module.exports = class SplitChunksPlugin {
logger.time("prepare");
const chunkGraph = compilation.chunkGraph;
const moduleGraph = compilation.moduleGraph;
// Give each selected chunk an index (to create strings from chunks)
/** @type {Map<Chunk, bigint>} */
const chunkIndexMap = new Map();
const ZERO = BigInt("0");
const ONE = BigInt("1");
let index = ONE;
for (const chunk of chunks) {
chunkIndexMap.set(chunk, index);
index = index << ONE;
}
/**
* @param {Iterable<Chunk>} chunks list of chunks
* @returns {bigint | Chunk} key of the chunks
*/
const getKey = chunks => {
const iterator = chunks[Symbol.iterator]();
let result = iterator.next();
if (result.done) return ZERO;
const first = result.value;
result = iterator.next();
if (result.done) return first;
let key =
chunkIndexMap.get(first) | chunkIndexMap.get(result.value);
while (!(result = iterator.next()).done) {
key = key | chunkIndexMap.get(result.value);
}
return key;
};
const keyToString = key => {
if (typeof key === "bigint") return key.toString(16);
return chunkIndexMap.get(key).toString(16);
};
const getChunkCombinationsInGraph = memoize(() => {
/** @type {Set<ChunkCombination>} */
const chunkCombinationsInGraph = new Set();
const getChunkSetsInGraph = memoize(() => {
/** @type {Map<bigint, Set<Chunk>>} */
const chunkSetsInGraph = new Map();
/** @type {Set<Chunk>} */
const singleChunkSets = new Set();
for (const module of compilation.modules) {
const chunkCombination =
chunkGraph.getModuleChunkCombination(module);
chunkCombinationsInGraph.add(chunkCombination);
const chunks = chunkGraph.getModuleChunksIterable(module);
const chunksKey = getKey(chunks);
if (typeof chunksKey === "bigint") {
if (!chunkSetsInGraph.has(chunksKey)) {
chunkSetsInGraph.set(chunksKey, new Set(chunks));
}
} else {
singleChunkSets.add(chunksKey);
}
}
return chunkCombinationsInGraph;
return { chunkSetsInGraph, singleChunkSets };
});
/**
* @param {Module} module the module
* @returns {Iterable<ChunkCombination>} groups of chunks with equal exports
* @returns {Iterable<Chunk[]>} groups of chunks with equal exports
*/
const groupChunksByExports = module => {
const exportsInfo = moduleGraph.getExportsInfo(module);
const groupedByUsedExports = new Map();
for (const chunk of chunkGraph.getModuleChunksIterable(module)) {
const key = exportsInfo.getUsageKey(chunk.runtime);
const combination =
groupedByUsedExports.get(key) || ChunkCombination.empty;
groupedByUsedExports.set(key, combination.with(chunk));
const list = groupedByUsedExports.get(key);
if (list !== undefined) {
list.push(chunk);
} else {
groupedByUsedExports.set(key, [chunk]);
}
}
return groupedByUsedExports.values();
};
/** @type {Map<Module, Iterable<ChunkCombination>>} */
/** @type {Map<Module, Iterable<Chunk[]>>} */
const groupedByExportsMap = new Map();
const getExportsChunkCombinationsInGraph = memoize(() => {
/** @type {Set<ChunkCombination>} */
const chunkCombinationsInGraph = new Set();
const getExportsChunkSetsInGraph = memoize(() => {
/** @type {Map<bigint, Set<Chunk>>} */
const chunkSetsInGraph = new Map();
/** @type {Set<Chunk>} */
const singleChunkSets = new Set();
for (const module of compilation.modules) {
const groupedChunks = Array.from(groupChunksByExports(module));
groupedByExportsMap.set(module, groupedChunks);
for (const chunkCombination of groupedChunks) {
chunkCombinationsInGraph.add(chunkCombination);
for (const chunks of groupedChunks) {
if (chunks.length === 1) {
singleChunkSets.add(chunks[0]);
} else {
const chunksKey = /** @type {bigint} */ (getKey(chunks));
if (!chunkSetsInGraph.has(chunksKey)) {
chunkSetsInGraph.set(chunksKey, new Set(chunks));
}
}
}
}
return chunkCombinationsInGraph;
return { chunkSetsInGraph, singleChunkSets };
});
// group these set of chunks by count
// to allow to check less sets via isSubset
// (only smaller sets can be subset)
const groupChunkCombinationsByCount = chunkCombinations => {
/** @type {Map<number, ChunkCombination[]>} */
const chunkCombinationsByCount = new Map();
for (const chunksSet of chunkCombinations) {
const groupChunkSetsByCount = chunkSets => {
/** @type {Map<number, Array<Set<Chunk>>>} */
const chunkSetsByCount = new Map();
for (const chunksSet of chunkSets) {
const count = chunksSet.size;
let array = chunkCombinationsByCount.get(count);
let array = chunkSetsByCount.get(count);
if (array === undefined) {
array = [];
chunkCombinationsByCount.set(count, array);
chunkSetsByCount.set(count, array);
}
array.push(chunksSet);
}
return chunkCombinationsByCount;
return chunkSetsByCount;
};
const getChunkCombinationsByCount = memoize(() =>
groupChunkCombinationsByCount(getChunkCombinationsInGraph())
const getChunkSetsByCount = memoize(() =>
groupChunkSetsByCount(
getChunkSetsInGraph().chunkSetsInGraph.values()
)
);
const getExportsChunkCombinationsByCount = memoize(() =>
groupChunkCombinationsByCount(getExportsChunkCombinationsInGraph())
const getExportsChunkSetsByCount = memoize(() =>
groupChunkSetsByCount(
getExportsChunkSetsInGraph().chunkSetsInGraph.values()
)
);
/**
* Create a list of possible combinations
* @param {Map<number, ChunkCombination[]>} chunkCombinationsByCount by count
* @returns {function(ChunkCombination): ChunkCombination[]} get combinations function
*/
const createGetCombinations = chunkCombinationsByCount => {
/** @type {Map<ChunkCombination, ChunkCombination[]>} */
// Create a list of possible combinations
const createGetCombinations = (
chunkSets,
singleChunkSets,
chunkSetsByCount
) => {
/** @type {Map<bigint | Chunk, (Set<Chunk> | Chunk)[]>} */
const combinationsCache = new Map();
/**
* @param {ChunkCombination} chunkCombination chunkCombination
* @returns {ChunkCombination[]} combinations
*/
return chunkCombination => {
const cacheEntry = combinationsCache.get(chunkCombination);
return key => {
const cacheEntry = combinationsCache.get(key);
if (cacheEntry !== undefined) return cacheEntry;
if (chunkCombination.size === 1) {
const result = [chunkCombination];
combinationsCache.set(chunkCombination, result);
if (key instanceof Chunk) {
const result = [key];
combinationsCache.set(key, result);
return result;
}
/** @type {ChunkCombination[]} */
const array = [chunkCombination];
for (const [count, setArray] of chunkCombinationsByCount) {
const chunksSet = chunkSets.get(key);
/** @type {(Set<Chunk> | Chunk)[]} */
const array = [chunksSet];
for (const [count, setArray] of chunkSetsByCount) {
// "equal" is not needed because they would have been merge in the first step
if (count < chunkCombination.size) {
if (count < chunksSet.size) {
for (const set of setArray) {
if (chunkCombination.isSubset(set)) {
if (isSubset(chunksSet, set)) {
array.push(set);
}
}
}
}
combinationsCache.set(chunkCombination, array);
for (const chunk of singleChunkSets) {
if (chunksSet.has(chunk)) {
array.push(chunk);
}
}
combinationsCache.set(key, array);
return array;
};
};
const getCombinationsFactory = memoize(() => {
return createGetCombinations(getChunkCombinationsByCount());
const { chunkSetsInGraph, singleChunkSets } = getChunkSetsInGraph();
return createGetCombinations(
chunkSetsInGraph,
singleChunkSets,
getChunkSetsByCount()
);
});
const getCombinations = key => getCombinationsFactory()(key);
const getExportsCombinationsFactory = memoize(() => {
return createGetCombinations(getExportsChunkCombinationsByCount());
const { chunkSetsInGraph, singleChunkSets } =
getExportsChunkSetsInGraph();
return createGetCombinations(
chunkSetsInGraph,
singleChunkSets,
getExportsChunkSetsByCount()
);
});
const getExportsCombinations = key =>
getExportsCombinationsFactory()(key);
/** @type {WeakMap<ChunkCombination, WeakMap<ChunkFilterFunction, ChunkCombination>>} */
/**
* @typedef {Object} SelectedChunksResult
* @property {Chunk[]} chunks the list of chunks
* @property {bigint | Chunk} key a key of the list
*/
/** @type {WeakMap<Set<Chunk> | Chunk, WeakMap<ChunkFilterFunction, SelectedChunksResult>>} */
const selectedChunksCacheByChunksSet = new WeakMap();
/**
* get chunks by applying the filter function to the list
* get list and key by applying the filter function to the list
* It is cached for performance reasons
* @param {ChunkCombination} chunks list of chunks
* @param {Set<Chunk> | Chunk} chunks list of chunks
* @param {ChunkFilterFunction} chunkFilter filter function for chunks
* @returns {ChunkCombination} selected chunks
* @returns {SelectedChunksResult} list and key
*/
const getSelectedChunks = (chunks, chunkFilter) => {
let entry = selectedChunksCacheByChunksSet.get(chunks);
......@@ -105829,16 +105710,22 @@ module.exports = class SplitChunksPlugin {
entry = new WeakMap();
selectedChunksCacheByChunksSet.set(chunks, entry);
}
/** @type {ChunkCombination} */
/** @type {SelectedChunksResult} */
let entry2 = entry.get(chunkFilter);
if (entry2 === undefined) {
/** @type {ChunkCombination} */
let selectedChunks = ChunkCombination.empty;
for (const chunk of chunks.chunksIterable) {
if (chunkFilter(chunk))
selectedChunks = selectedChunks.with(chunk);
/** @type {Chunk[]} */
const selectedChunks = [];
if (chunks instanceof Chunk) {
if (chunkFilter(chunks)) selectedChunks.push(chunks);
} else {
for (const chunk of chunks) {
if (chunkFilter(chunk)) selectedChunks.push(chunk);
}
}
entry2 = selectedChunks;
entry2 = {
chunks: selectedChunks,
key: getKey(selectedChunks)
};
entry.set(chunkFilter, entry2);
}
return entry2;
......@@ -105857,7 +105744,8 @@ module.exports = class SplitChunksPlugin {
/**
* @param {CacheGroup} cacheGroup the current cache group
* @param {number} cacheGroupIndex the index of the cache group of ordering
* @param {ChunkCombination} selectedChunks chunks selected for this module
* @param {Chunk[]} selectedChunks chunks selected for this module
* @param {bigint | Chunk} selectedChunksKey a key of selectedChunks
* @param {Module} module the current module
* @returns {void}
*/
......@@ -105865,20 +105753,25 @@ module.exports = class SplitChunksPlugin {
cacheGroup,
cacheGroupIndex,
selectedChunks,
selectedChunksKey,
module
) => {
// Break if minimum number of chunks is not reached
if (selectedChunks.size < cacheGroup.minChunks) return;
if (selectedChunks.length < cacheGroup.minChunks) return;
// Determine name for split chunk
const name = cacheGroup.getName(
module,
selectedChunks.getChunks(),
selectedChunks,
cacheGroup.key
);
// Check if the name is ok
const existingChunk = compilation.namedChunks.get(name);
if (existingChunk) {
const parentValidationKey = `${name}|${selectedChunks.debugId}`;
const parentValidationKey = `${name}|${
typeof selectedChunksKey === "bigint"
? selectedChunksKey
: selectedChunksKey.debugId
}`;
const valid = alreadyValidatedParents.get(parentValidationKey);
if (valid === false) return;
if (valid === undefined) {
......@@ -105887,7 +105780,7 @@ module.exports = class SplitChunksPlugin {
let isInAllParents = true;
/** @type {Set<ChunkGroup>} */
const queue = new Set();
for (const chunk of selectedChunks.chunksIterable) {
for (const chunk of selectedChunks) {
for (const group of chunk.groupsIterable) {
queue.add(group);
}
......@@ -105933,7 +105826,9 @@ module.exports = class SplitChunksPlugin {
// This automatically merges equal names
const key =
cacheGroup.key +
(name ? ` name:${name}` : ` chunks:${selectedChunks.debugId}`);
(name
? ` name:${name}`
: ` chunks:${keyToString(selectedChunksKey)}`);
// Add module to maps
let info = chunksInfoMap.get(key);
if (info === undefined) {
......@@ -105948,9 +105843,9 @@ module.exports = class SplitChunksPlugin {
cacheGroupIndex,
name,
sizes: {},
chunks: ChunkCombination.empty,
chunks: new Set(),
reuseableChunks: new Set(),
chunkCombinations: new Set()
chunksKeys: new Set()
})
);
}
......@@ -105961,10 +105856,12 @@ module.exports = class SplitChunksPlugin {
info.sizes[type] = (info.sizes[type] || 0) + module.size(type);
}
}
const oldChunksKeysSize = info.chunkCombinations.size;
info.chunkCombinations.add(selectedChunks);
if (oldChunksKeysSize !== info.chunkCombinations.size) {
info.chunks = info.chunks.withAll(selectedChunks);
const oldChunksKeysSize = info.chunksKeys.size;
info.chunksKeys.add(selectedChunksKey);
if (oldChunksKeysSize !== info.chunksKeys.size) {
for (const chunk of selectedChunks) {
info.chunks.add(chunk);
}
}
};
......@@ -105985,56 +105882,50 @@ module.exports = class SplitChunksPlugin {
continue;
}
const chunkCombination =
chunkGraph.getModuleChunkCombination(module);
// Prepare some values (usedExports = false)
const getCombs = memoize(() => {
const chunks = chunkGraph.getModuleChunksIterable(module);
const chunksKey = getKey(chunks);
return getCombinations(chunksKey);
});
// Prepare some values (usedExports = true)
const getCombsByUsedExports = memoize(() => {
// fill the groupedByExportsMap
getExportsChunkSetsInGraph();
/** @type {Set<Set<Chunk> | Chunk>} */
const set = new Set();
const groupedByUsedExports = groupedByExportsMap.get(module);
for (const chunks of groupedByUsedExports) {
const chunksKey = getKey(chunks);
for (const comb of getExportsCombinations(chunksKey))
set.add(comb);
}
return set;
});
let cacheGroupIndex = 0;
for (const cacheGroupSource of cacheGroups) {
const cacheGroup = this._getCacheGroup(cacheGroupSource);
// Break if minimum number of chunks is not reached
if (chunkCombination.size < cacheGroup.minChunks) continue;
/** @type {Iterable<ChunkCombination>} */
let combs;
if (cacheGroup.usedExports) {
// fill the groupedByExportsMap
getExportsChunkCombinationsInGraph();
/** @type {Set<ChunkCombination>} */
const set = new Set();
const groupedByUsedExports = groupedByExportsMap.get(module);
for (const chunkCombination of groupedByUsedExports) {
const preSelectedChunks = getSelectedChunks(
chunkCombination,
cacheGroup.chunksFilter
);
// Break if minimum number of chunks is not reached
if (preSelectedChunks.size < cacheGroup.minChunks) continue;
for (const comb of getExportsCombinations(preSelectedChunks))
set.add(comb);
}
combs = set;
} else {
const preSelectedChunks = getSelectedChunks(
chunkCombination,
cacheGroup.chunksFilter
);
// Break if minimum number of chunks is not reached
if (preSelectedChunks.size < cacheGroup.minChunks) continue;
combs = getCombinations(preSelectedChunks);
}
const combs = cacheGroup.usedExports
? getCombsByUsedExports()
: getCombs();
// For all combination of chunk selection
for (const selectedChunks of combs) {
for (const chunkCombination of combs) {
// Break if minimum number of chunks is not reached
const count = chunkCombination.size;
const count =
chunkCombination instanceof Chunk ? 1 : chunkCombination.size;
if (count < cacheGroup.minChunks) continue;
// Select chunks by configuration
const { chunks: selectedChunks, key: selectedChunksKey } =
getSelectedChunks(chunkCombination, cacheGroup.chunksFilter);
addModuleToChunksInfoMap(
cacheGroup,
cacheGroupIndex,
selectedChunks,
selectedChunksKey,
module
);
}
......@@ -106126,12 +106017,12 @@ module.exports = class SplitChunksPlugin {
const chunkByName = compilation.namedChunks.get(chunkName);
if (chunkByName !== undefined) {
newChunk = chunkByName;
const newChunks = item.chunks.without(newChunk);
isExistingChunk = newChunks !== item.chunks;
if (isExistingChunk) item.chunks = newChunks;
const oldSize = item.chunks.size;
item.chunks.delete(newChunk);
isExistingChunk = item.chunks.size !== oldSize;
}
} else if (item.cacheGroup.reuseExistingChunk) {
outer: for (const chunk of item.chunks.chunksIterable) {
outer: for (const chunk of item.chunks) {
if (
chunkGraph.getNumberOfChunkModules(chunk) !==
item.modules.size
......@@ -106165,7 +106056,7 @@ module.exports = class SplitChunksPlugin {
}
}
if (newChunk) {
item.chunks = item.chunks.without(newChunk);
item.chunks.delete(newChunk);
chunkName = undefined;
isExistingChunk = true;
isReusedWithAllModules = true;
......@@ -106176,7 +106067,7 @@ module.exports = class SplitChunksPlugin {
item.cacheGroup._conditionalEnforce &&
checkMinSize(item.sizes, item.cacheGroup.enforceSizeThreshold);
let usedChunks = item.chunks;
const usedChunks = new Set(item.chunks);
// Check if maxRequests condition can be fulfilled
if (
......@@ -106184,7 +106075,7 @@ module.exports = class SplitChunksPlugin {
(Number.isFinite(item.cacheGroup.maxInitialRequests) ||
Number.isFinite(item.cacheGroup.maxAsyncRequests))
) {
for (const chunk of usedChunks.chunksIterable) {
for (const chunk of usedChunks) {
// respect max requests
const maxRequests = chunk.isOnlyInitial()
? item.cacheGroup.maxInitialRequests
......@@ -106198,28 +106089,30 @@ module.exports = class SplitChunksPlugin {
isFinite(maxRequests) &&
getRequests(chunk) >= maxRequests
) {
usedChunks = usedChunks.without(chunk);
usedChunks.delete(chunk);
}
}
}
outer: for (const chunk of usedChunks.chunksIterable) {
outer: for (const chunk of usedChunks) {
for (const module of item.modules) {
if (chunkGraph.isModuleInChunk(module, chunk)) continue outer;
}
usedChunks = usedChunks.without(chunk);
usedChunks.delete(chunk);
}
// Were some (invalid) chunks removed from usedChunks?
// => readd all modules to the queue, as things could have been changed
if (usedChunks !== item.chunks) {
if (isExistingChunk) usedChunks = usedChunks.with(newChunk);
if (usedChunks.size < item.chunks.size) {
if (isExistingChunk) usedChunks.add(newChunk);
if (usedChunks.size >= item.cacheGroup.minChunks) {
const chunksArr = Array.from(usedChunks);
for (const module of item.modules) {
addModuleToChunksInfoMap(
item.cacheGroup,
item.cacheGroupIndex,
usedChunks,
chunksArr,
getKey(usedChunks),
module
);
}
......@@ -106233,7 +106126,7 @@ module.exports = class SplitChunksPlugin {
item.cacheGroup._validateRemainingSize &&
usedChunks.size === 1
) {
const [chunk] = usedChunks.chunksIterable;
const [chunk] = usedChunks;
let chunkSizes = Object.create(null);
for (const module of chunkGraph.getChunkModulesIterable(chunk)) {
if (!item.modules.has(module)) {
......@@ -106267,7 +106160,7 @@ module.exports = class SplitChunksPlugin {
newChunk = compilation.addChunk(chunkName);
}
// Walk through all chunks
for (const chunk of usedChunks.chunksIterable) {
for (const chunk of usedChunks) {
// Add graph connections for splitted chunk
chunk.split(newChunk);
}
......@@ -106297,14 +106190,14 @@ module.exports = class SplitChunksPlugin {
// Add module to new chunk
chunkGraph.connectChunkAndModule(newChunk, module);
// Remove module from used chunks
for (const chunk of usedChunks.chunksIterable) {
for (const chunk of usedChunks) {
chunkGraph.disconnectChunkAndModule(chunk, module);
}
}
} else {
// Remove all modules from used chunks
for (const module of item.modules) {
for (const chunk of usedChunks.chunksIterable) {
for (const chunk of usedChunks) {
chunkGraph.disconnectChunkAndModule(chunk, module);
}
}
......@@ -106346,7 +106239,7 @@ module.exports = class SplitChunksPlugin {
// remove all modules from other entries and update size
for (const [key, info] of chunksInfoMap) {
if (info.chunks.hasSharedChunks(usedChunks)) {
if (isOverlap(info.chunks, usedChunks)) {
// update modules and total size
// may remove it from the map when < minSize
let updated = false;
......@@ -130349,7 +130242,6 @@ module.exports = WebAssemblyGenerator;
const WebpackError = __webpack_require__(68422);
const { someInIterable } = __webpack_require__(31065);
/** @typedef {import("../ChunkGraph")} ChunkGraph */
/** @typedef {import("../Module")} Module */
......@@ -130387,11 +130279,7 @@ const getInitialModuleChains = (
for (const connection of moduleGraph.getIncomingConnections(head)) {
const newHead = connection.originModule;
if (newHead) {
if (
!someInIterable(chunkGraph.getModuleChunksIterable(newHead), c =>
c.canBeInitial()
)
)
if (!chunkGraph.getModuleChunks(newHead).some(c => c.canBeInitial()))
continue;
final = false;
if (alreadyReferencedModules.has(newHead)) continue;
......@@ -249,7 +249,7 @@
"webpack-sources1": "npm:webpack-sources@1.4.3",
"webpack-sources3": "npm:webpack-sources@3.2.0",
"webpack4": "npm:webpack@4.44.1",
"webpack5": "npm:webpack@5.58.0"
"webpack5": "npm:webpack@5.58.1"
},
"resolutions": {
"browserslist": "4.16.6",
......
......@@ -19703,10 +19703,10 @@ webpack-sources@^3.2.0:
watchpack "^1.7.4"
webpack-sources "^1.4.1"
"webpack5@npm:webpack@5.58.0":
version "5.58.0"
resolved "https://registry.yarnpkg.com/webpack/-/webpack-5.58.0.tgz#9ec621cf8534f23c25e779e7c35dfde1211d5ccb"
integrity sha512-xc2k5MLbR1iah24Z5xUm1nBh1PZXEdUnrX6YkTSOScq/VWbl5JCLREXJzGYqEAUbIO8tZI+Dzv82lGtnuUnVCQ==
"webpack5@npm:webpack@5.58.1":
version "5.58.1"
resolved "https://registry.yarnpkg.com/webpack/-/webpack-5.58.1.tgz#df8aad72b617a9d0db8c89d4f410784ee93320d7"
integrity sha512-4Z/dmbTU+VmkCb2XNgW7wkE5TfEcSooclprn/UEuVeAkwHhn07OcgUsyaKHGtCY/VobjnsYBlyhKeMLiSoOqPg==
dependencies:
"@types/eslint-scope" "^3.7.0"
"@types/estree" "^0.0.50"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment