bugfixes and corrections
This commit is contained in:
parent
f0ed7b63e8
commit
3072378892
|
@ -3,15 +3,13 @@
|
|||
Author Tobias Koppers @sokra
|
||||
*/
|
||||
"use strict";
|
||||
|
||||
const DependenciesBlock = require("./DependenciesBlock");
|
||||
|
||||
/**
|
||||
* @typedef {import("./ChunkGroup")} ChunkGroup
|
||||
* @typedef {import("./Module")} Module
|
||||
* @typedef {import("crypto").Hash} Hash
|
||||
* @typedef {TODO} GroupOptions
|
||||
*
|
||||
*/
|
||||
/** @typedef {import("./ChunkGroup")} ChunkGroup */
|
||||
/** @typedef {import("./Module")} Module */
|
||||
/** @typedef {import("crypto").Hash} Hash */
|
||||
/** @typedef {TODO} GroupOptions */
|
||||
|
||||
module.exports = class AsyncDependenciesBlock extends DependenciesBlock {
|
||||
/**
|
||||
|
|
32
lib/Chunk.js
32
lib/Chunk.js
|
@ -29,6 +29,7 @@ const ERR_CHUNK_INITIAL =
|
|||
* @property {string} id the id of the object
|
||||
*/
|
||||
|
||||
// TODO use @callback
|
||||
/** @typedef {(a: Module, b: Module) => -1|0|1} ModuleSortPredicate */
|
||||
/** @typedef {(m: Module) => boolean} ModuleFilterPredicate */
|
||||
/** @typedef {(c: Chunk) => boolean} ChunkFilterPredicate */
|
||||
|
@ -115,7 +116,7 @@ class Chunk {
|
|||
this._modules = new SortableSet(undefined, sortByIdentifier);
|
||||
/** @private */
|
||||
this._groups = new SortableSet(undefined, sortById);
|
||||
/** @type {Source[]} */
|
||||
/** @type {string[]} */
|
||||
this.files = [];
|
||||
/** @type {boolean} */
|
||||
this.rendered = false;
|
||||
|
@ -532,12 +533,22 @@ class Chunk {
|
|||
}
|
||||
|
||||
/**
|
||||
* @param {Hash} realHash the hash for the chunk maps
|
||||
* @returns {{ hash: TODO, contentHash: TODO, name: TODO }} the chunk map information
|
||||
* @typedef {Object} ChunkMaps
|
||||
* @property {Record<string|number, string>} hash
|
||||
* @property {Record<string|number, Record<string, string>>} contentHash
|
||||
* @property {Record<string|number, string>} name
|
||||
*/
|
||||
|
||||
/**
|
||||
* @param {boolean} realHash should the full hash or the rendered hash be used
|
||||
* @returns {ChunkMaps} the chunk map information
|
||||
*/
|
||||
getChunkMaps(realHash) {
|
||||
/** @type {Record<string|number, string>} */
|
||||
const chunkHashMap = Object.create(null);
|
||||
/** @type {Record<string|number, Record<string, string>>} */
|
||||
const chunkContentHashMap = Object.create(null);
|
||||
/** @type {Record<string|number, string>} */
|
||||
const chunkNameMap = Object.create(null);
|
||||
|
||||
for (const chunk of this.getAllAsyncChunks()) {
|
||||
|
@ -558,7 +569,7 @@ class Chunk {
|
|||
}
|
||||
|
||||
/**
|
||||
* @returns {Record<string, Array<Set<TODO>>>} a record object of names to lists of child ids(?)
|
||||
* @returns {Record<string, Set<TODO>[]>} a record object of names to lists of child ids(?)
|
||||
*/
|
||||
getChildIdsByOrders() {
|
||||
const lists = new Map();
|
||||
|
@ -616,17 +627,24 @@ class Chunk {
|
|||
return chunkMaps;
|
||||
}
|
||||
|
||||
/** @typedef {(module: Module) => true} FilterFn */
|
||||
/**
|
||||
* @typedef {Object} ChunkModuleMaps
|
||||
* @property {Record<string|number, (string|number)[]>} id
|
||||
* @property {Record<string|number, string>} hash
|
||||
*/
|
||||
|
||||
/**
|
||||
* @param {FilterFn} filterFn function used to filter modules
|
||||
* @returns {TODO} module map information
|
||||
* @param {ModuleFilterPredicate} filterFn function used to filter modules
|
||||
* @returns {ChunkModuleMaps} module map information
|
||||
*/
|
||||
getChunkModuleMaps(filterFn) {
|
||||
/** @type {Record<string|number, (string|number)[]>} */
|
||||
const chunkModuleIdMap = Object.create(null);
|
||||
/** @type {Record<string|number, string>} */
|
||||
const chunkModuleHashMap = Object.create(null);
|
||||
|
||||
for (const chunk of this.getAllAsyncChunks()) {
|
||||
/** @type {(string|number)[]} */
|
||||
let array;
|
||||
for (const module of chunk.modulesIterable) {
|
||||
if (filterFn(module)) {
|
||||
|
|
|
@ -35,7 +35,7 @@ const createHash = require("./util/createHash");
|
|||
const Queue = require("./util/Queue");
|
||||
const SortableSet = require("./util/SortableSet");
|
||||
const GraphHelpers = require("./GraphHelpers");
|
||||
const SingleEntryDependency = require("./dependencies/SingleEntryDependency");
|
||||
const ModuleDependency = require("./dependencies/ModuleDependency");
|
||||
|
||||
/** @typedef {import("./Module")} Module */
|
||||
/** @typedef {import("./Compiler")} Compiler */
|
||||
|
@ -48,12 +48,12 @@ const SingleEntryDependency = require("./dependencies/SingleEntryDependency");
|
|||
/** @typedef {import("./DependenciesBlock")} DependenciesBlock */
|
||||
/** @typedef {import("./AsyncDependenciesBlock")} AsyncDependenciesBlock */
|
||||
|
||||
/** @typedef {SingleEntryDependency|MultiEntryDependency|DllEntryDependency} PossibleEntryDependencies */
|
||||
// TODO use @callback
|
||||
/** @typedef {{[assetName: string]: Source}} CompilationAssets */
|
||||
/** @typedef {(err: Error|null, result?: Module) => void } ModuleCallback */
|
||||
/** @typedef {(err?: Error|null, result?: Module) => void } ModuleChainCallback */
|
||||
/** @typedef {(module: Module) => void} OnModuleCallback */
|
||||
/** @typedef {(err?: Error|null) => void} CompilationSealCallback */
|
||||
/** @typedef {(err?: Error|null) => void} Callback */
|
||||
/** @typedef {{apply: (dep: Dependency, source: Source, runtime: RuntimeTemplate) => void}} DependencyTemplate */
|
||||
/** @typedef {(d: Dependency) => any} DepBlockVarDependenciesCallback */
|
||||
/** @typedef {new (...args: any[]) => Dependency} DepConstructor */
|
||||
|
@ -356,7 +356,7 @@ class Compilation extends Tapable {
|
|||
|
||||
// TODO the following hooks are weirdly located here
|
||||
// TODO move them for webpack 5
|
||||
/** @type {SyncHook<string, Module>} */
|
||||
/** @type {SyncHook<object, Module>} */
|
||||
normalModuleLoader: new SyncHook(["loaderContext", "module"]),
|
||||
|
||||
/** @type {SyncBailHook<Chunk[]>} */
|
||||
|
@ -448,7 +448,7 @@ class Compilation extends Tapable {
|
|||
this.dependencyTemplates = new Map();
|
||||
this.dependencyTemplates.set("hash", "");
|
||||
this.childrenCounters = {};
|
||||
/** @type {Set<number>} */
|
||||
/** @type {Set<number|string>} */
|
||||
this.usedChunkIds = null;
|
||||
/** @type {Set<number>} */
|
||||
this.usedModuleIds = null;
|
||||
|
@ -456,11 +456,11 @@ class Compilation extends Tapable {
|
|||
this.fileTimestamps = undefined;
|
||||
/** @type {Map<string, number>=} */
|
||||
this.contextTimestamps = undefined;
|
||||
/** @type {Set} */
|
||||
/** @type {Set<string>} */
|
||||
this.compilationDependencies = undefined;
|
||||
/** @private @type {Map<Module, any>} */
|
||||
/** @private @type {Map<Module, Callback[]>} */
|
||||
this._buildingModules = new Map();
|
||||
/** @private @type {Map<Module, any>} */
|
||||
/** @private @type {Map<Module, Callback[]>} */
|
||||
this._rebuildingModules = new Map();
|
||||
}
|
||||
|
||||
|
@ -468,10 +468,18 @@ class Compilation extends Tapable {
|
|||
return new Stats(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* @typedef {Object} AddModuleResult
|
||||
* @property {Module} module the added or existing module
|
||||
* @property {boolean} issuer was this the first request for this module
|
||||
* @property {boolean} build should the module be build
|
||||
* @property {boolean} dependencies should dependencies be walked
|
||||
*/
|
||||
|
||||
/**
|
||||
* @param {Module} module module to be added that was created
|
||||
* @param {any=} cacheGroup cacheGroup it is apart of
|
||||
* @returns {{module: Module, issuer: boolean, build: boolean, dependencies: boolean}} returns meta about whether or not the module had built
|
||||
* @returns {AddModuleResult} returns meta about whether or not the module had built
|
||||
* had an issuer, or any dependnecies
|
||||
*/
|
||||
addModule(module, cacheGroup) {
|
||||
|
@ -550,7 +558,7 @@ class Compilation extends Tapable {
|
|||
|
||||
/**
|
||||
* @param {Module} module module with its callback list
|
||||
* @param {any} callback the callback function
|
||||
* @param {Callback} callback the callback function
|
||||
* @returns {void}
|
||||
*/
|
||||
waitForBuildingFinished(module, callback) {
|
||||
|
@ -569,8 +577,8 @@ class Compilation extends Tapable {
|
|||
* @param {boolean} optional optional flag
|
||||
* @param {Module=} origin origin module this module build was requested from
|
||||
* @param {Dependency[]=} dependencies optional dependencies from the module to be built
|
||||
* @param {any} thisCallback the callback
|
||||
* @returns {any} returns the callback function with results
|
||||
* @param {TODO} thisCallback the callback
|
||||
* @returns {TODO} returns the callback function with results
|
||||
*/
|
||||
buildModule(module, optional, origin, dependencies, thisCallback) {
|
||||
let callbackList = this._buildingModules.get(module);
|
||||
|
@ -693,7 +701,7 @@ class Compilation extends Tapable {
|
|||
* @param {Module} module module to add deps to
|
||||
* @param {SortedDependency[]} dependencies set of sorted dependencies to iterate through
|
||||
* @param {(boolean|null)=} bail whether to bail or not
|
||||
* @param {any} cacheGroup optional cacheGroup
|
||||
* @param {TODO} cacheGroup optional cacheGroup
|
||||
* @param {boolean} recursive whether it is recursive traversal
|
||||
* @param {function} callback callback for when dependencies are finished being added
|
||||
* @returns {void}
|
||||
|
@ -870,7 +878,7 @@ class Compilation extends Tapable {
|
|||
* @param {Dependency} dependency dependency used to create Module chain
|
||||
* @param {OnModuleCallback} onModule function invoked on modules creation
|
||||
* @param {ModuleChainCallback} callback callback for when module chain is complete
|
||||
* @returns {void|never} will throw if dependency instance is not a valid Dependency
|
||||
* @returns {void} will throw if dependency instance is not a valid Dependency
|
||||
*/
|
||||
_addModuleChain(context, dependency, onModule, callback) {
|
||||
const start = this.profile && Date.now();
|
||||
|
@ -987,7 +995,7 @@ class Compilation extends Tapable {
|
|||
/**
|
||||
*
|
||||
* @param {string} context context path for entry
|
||||
* @param {PossibleEntryDependencies} entry entry dependency being created
|
||||
* @param {Dependency} entry entry dependency being created
|
||||
* @param {string} name name of entry
|
||||
* @param {ModuleCallback} callback callback function
|
||||
* @returns {void} returns
|
||||
|
@ -999,7 +1007,7 @@ class Compilation extends Tapable {
|
|||
module: null
|
||||
};
|
||||
|
||||
if (entry instanceof SingleEntryDependency) {
|
||||
if (entry instanceof ModuleDependency) {
|
||||
slot.request = entry.request;
|
||||
}
|
||||
|
||||
|
@ -1028,7 +1036,7 @@ class Compilation extends Tapable {
|
|||
|
||||
/**
|
||||
* @param {string} context context path string
|
||||
* @param {PossibleEntryDependencies} dependency dep used to create module
|
||||
* @param {Dependency} dependency dep used to create module
|
||||
* @param {ModuleCallback} callback module callback sending module up a level
|
||||
* @returns {void}
|
||||
*/
|
||||
|
@ -1110,7 +1118,7 @@ class Compilation extends Tapable {
|
|||
}
|
||||
|
||||
/**
|
||||
* @param {CompilationSealCallback} callback signals when the seal method is finishes
|
||||
* @param {Callback} callback signals when the seal method is finishes
|
||||
* @returns {void}
|
||||
*/
|
||||
seal(callback) {
|
||||
|
@ -1298,7 +1306,7 @@ class Compilation extends Tapable {
|
|||
}
|
||||
|
||||
/**
|
||||
* @param {any} groupOptions options provided for group
|
||||
* @param {TODO} groupOptions options provided for group
|
||||
* @param {Module} module module in question
|
||||
* @param {DependencyLocation} loc source location reference
|
||||
* @param {string} request request string
|
||||
|
@ -1877,13 +1885,14 @@ class Compilation extends Tapable {
|
|||
|
||||
const blocks = block.blocks;
|
||||
for (let indexBlock = 0; indexBlock < blocks.length; indexBlock++) {
|
||||
const asyncBlock = blocks[indexBlock];
|
||||
// Grab all chunks from the first Block's AsyncDepBlock
|
||||
const chunks = blocks[indexBlock].chunkGroup.chunks;
|
||||
const chunks = asyncBlock.chunkGroup.chunks;
|
||||
// For each chunk in chunkGroup
|
||||
for (let indexChunk = 0; indexChunk < chunks.length; indexChunk++) {
|
||||
const iteratedChunk = chunks[indexChunk];
|
||||
block.chunkGroup.removeChunk(iteratedChunk);
|
||||
block.chunkGroup.removeParent(iteratedChunk);
|
||||
asyncBlock.chunkGroup.removeChunk(iteratedChunk);
|
||||
asyncBlock.chunkGroup.removeParent(iteratedChunk);
|
||||
// Recurse
|
||||
this.removeChunkFromDependencies(block, iteratedChunk);
|
||||
}
|
||||
|
@ -1946,7 +1955,7 @@ class Compilation extends Tapable {
|
|||
}
|
||||
|
||||
applyChunkIds() {
|
||||
/** @type {Set<number|string>} */
|
||||
/** @type {Set<number>} */
|
||||
const usedIds = new Set();
|
||||
|
||||
// Get used ids from usedChunkIds property (i. e. from records)
|
||||
|
@ -2169,7 +2178,7 @@ class Compilation extends Tapable {
|
|||
}
|
||||
|
||||
/**
|
||||
* @param {TODO} update //TODO (update hash function?)
|
||||
* @param {string} update extra information
|
||||
* @returns {void}
|
||||
*/
|
||||
modifyHash(update) {
|
||||
|
@ -2268,7 +2277,7 @@ class Compilation extends Tapable {
|
|||
/**
|
||||
* @param {string} filename used to get asset path with hash
|
||||
* @param {TODO=} data // TODO: figure out this param type
|
||||
* @returns {TODO} figure out this return type
|
||||
* @returns {string} interpolated path
|
||||
*/
|
||||
getPath(filename, data) {
|
||||
data = data || {};
|
||||
|
|
|
@ -24,6 +24,9 @@ class DelegatedModule extends Module {
|
|||
this.userRequest = userRequest;
|
||||
this.originalRequest = originalRequest;
|
||||
this.delegateData = data;
|
||||
|
||||
// Build info
|
||||
this.delegatedSourceDependency = undefined;
|
||||
}
|
||||
|
||||
libIdent(options) {
|
||||
|
@ -50,9 +53,10 @@ class DelegatedModule extends Module {
|
|||
this.built = true;
|
||||
this.buildMeta = Object.assign({}, this.delegateData.buildMeta);
|
||||
this.buildInfo = {};
|
||||
/** @type {ModuleDependency[]=} */
|
||||
this.dependencies = [];
|
||||
this.addDependency(new DelegatedSourceDependency(this.sourceRequest));
|
||||
this.delegatedSourceDependency = new DelegatedSourceDependency(
|
||||
this.sourceRequest
|
||||
);
|
||||
this.addDependency(this.delegatedSourceDependency);
|
||||
this.addDependency(
|
||||
new DelegatedExportsDependency(this, this.delegateData.exports || true)
|
||||
);
|
||||
|
@ -60,7 +64,7 @@ class DelegatedModule extends Module {
|
|||
}
|
||||
|
||||
source(depTemplates, runtime) {
|
||||
const dep = this.dependencies[0];
|
||||
const dep = this.delegatedSourceDependency;
|
||||
const sourceModule = dep.module;
|
||||
let str;
|
||||
|
||||
|
|
|
@ -6,14 +6,12 @@
|
|||
|
||||
const DependenciesBlockVariable = require("./DependenciesBlockVariable");
|
||||
|
||||
/**
|
||||
* @typedef {import("./ChunkGroup")} ChunkGroup
|
||||
* @typedef {import("./Dependency")} Dependency
|
||||
* @typedef {import("./AsyncDependenciesBlock")} AsyncDependenciesBlock
|
||||
* @typedef {import("./DependenciesBlockVariable")} DependenciesBlockVariable
|
||||
* @typedef {(d: Dependency) => boolean} DependencyFilterFunction
|
||||
* @typedef {import("crypto").Hash} Hash
|
||||
*/
|
||||
/** @typedef {import("./ChunkGroup")} ChunkGroup */
|
||||
/** @typedef {import("./Dependency")} Dependency */
|
||||
/** @typedef {import("./AsyncDependenciesBlock")} AsyncDependenciesBlock */
|
||||
/** @typedef {import("./DependenciesBlockVariable")} DependenciesBlockVariable */
|
||||
/** @typedef {(d: Dependency) => boolean} DependencyFilterFunction */
|
||||
/** @typedef {import("crypto").Hash} Hash */
|
||||
|
||||
class DependenciesBlock {
|
||||
constructor() {
|
||||
|
@ -23,9 +21,6 @@ class DependenciesBlock {
|
|||
this.blocks = [];
|
||||
/** @type {DependenciesBlockVariable[]} */
|
||||
this.variables = [];
|
||||
// TODO remove this line, it's wrong
|
||||
/** @type {ChunkGroup=} */
|
||||
this.chunkGroup = undefined;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -7,10 +7,11 @@
|
|||
const { RawSource, ReplaceSource } = require("webpack-sources");
|
||||
|
||||
/** @typedef {import("./Dependency")} Dependency */
|
||||
/** @typedef {import("./Dependency").DependencyTemplate} DependencyTemplate */
|
||||
/** @typedef {import("./RuntimeTemplate")} RuntimeTemplate */
|
||||
/** @typedef {import("crypto").Hash} Hash */
|
||||
/** @typedef {(d: Dependency) => boolean} DependencyFilterFunction */
|
||||
/** @typedef {Map<Dependency["constructor"], any>} DependencyFactoryConstruction */
|
||||
/** @typedef {Map<Function, DependencyTemplate>} DependencyFactoryConstruction */
|
||||
|
||||
class DependenciesBlockVariable {
|
||||
/**
|
||||
|
|
|
@ -8,6 +8,13 @@ const compareLocations = require("./compareLocations");
|
|||
const DependencyReference = require("./dependencies/DependencyReference");
|
||||
|
||||
/** @typedef {import("./Module")} Module */
|
||||
/** @typedef {import("webpack-sources").Source} Source */
|
||||
/** @typedef {import("./RuntimeTemplate")} RuntimeTemplate */
|
||||
|
||||
/**
|
||||
* @typedef {Object} DependencyTemplate
|
||||
* @property {function(Dependency, Source, RuntimeTemplate, Map<Function, DependencyTemplate>): void} apply
|
||||
*/
|
||||
|
||||
class Dependency {
|
||||
constructor() {
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
/** @typedef {import("./ChunkGroup")} ChunkGroup */
|
||||
/** @typedef {import("./Module")} Module */
|
||||
/** @typedef {import("./DependenciesBlock")} DependenciesBlock */
|
||||
/** @typedef {import("./AsyncDependenciesBlock")} AsyncDependenciesBlock */
|
||||
|
||||
/**
|
||||
* @param {ChunkGroup} chunkGroup the ChunkGroup to connect
|
||||
|
@ -47,7 +48,7 @@ const disconnectChunkAndModule = (chunk, module) => {
|
|||
};
|
||||
|
||||
/**
|
||||
* @param {DependenciesBlock} depBlock DepBlock being tied to ChunkGroup
|
||||
* @param {AsyncDependenciesBlock} depBlock DepBlock being tied to ChunkGroup
|
||||
* @param {ChunkGroup} chunkGroup ChunkGroup being tied to DepBlock
|
||||
* @returns {void}
|
||||
*/
|
||||
|
|
|
@ -11,8 +11,8 @@ const ModuleReason = require("./ModuleReason");
|
|||
const SortableSet = require("./util/SortableSet");
|
||||
const Template = require("./Template");
|
||||
|
||||
/** @typedef {typeof import("./Chunk")} Chunk */
|
||||
/** @typedef {typeof import("./RequestShortener")} RequestShortener */
|
||||
/** @typedef {import("./Chunk")} Chunk */
|
||||
/** @typedef {import("./RequestShortener")} RequestShortener */
|
||||
/** @typedef {import("./WebpackError")} WebpackError */
|
||||
|
||||
const EMPTY_RESOLVE_OPTIONS = {};
|
||||
|
@ -48,7 +48,7 @@ class Module extends DependenciesBlock {
|
|||
this.renderedHash = undefined;
|
||||
|
||||
// Info from Factory
|
||||
/** @type {any} */
|
||||
/** @type {TODO} */
|
||||
this.resolveOptions = EMPTY_RESOLVE_OPTIONS;
|
||||
/** @type {object} */
|
||||
this.factoryMeta = {};
|
||||
|
|
|
@ -58,7 +58,7 @@ class MultiEntryPlugin {
|
|||
/**
|
||||
* @param {string[]} entries each entry path string
|
||||
* @param {string} name name of the entry
|
||||
* @return {MultiEntryDependency} returns a constructed Dependency
|
||||
* @returns {MultiEntryDependency} returns a constructed Dependency
|
||||
*/
|
||||
static createDependency(entries, name) {
|
||||
return new MultiEntryDependency(
|
||||
|
|
|
@ -13,7 +13,6 @@ class WebpackError extends Error {
|
|||
this.origin = undefined;
|
||||
this.dependencies = undefined;
|
||||
this.module = undefined;
|
||||
this.message = undefined;
|
||||
|
||||
Error.captureStackTrace(this, this.constructor);
|
||||
}
|
||||
|
|
|
@ -12,7 +12,6 @@ class DependencyReference {
|
|||
* @param {Module} module module there reference comes from
|
||||
* @param {string[]|boolean} importedNames imported names or boolean
|
||||
* @param {boolean} weak is weak reference or not
|
||||
* @memberof DependencyReference
|
||||
*/
|
||||
constructor(module, importedNames, weak) {
|
||||
this.module = module;
|
||||
|
|
|
@ -13,7 +13,7 @@ class Semaphore {
|
|||
*/
|
||||
constructor(available) {
|
||||
this.available = available;
|
||||
/** @type {(() => void)[]} */
|
||||
/** @type {(function(): void)[]} */
|
||||
this.waiters = [];
|
||||
/** @private */
|
||||
this._continue = this._continue.bind(this);
|
||||
|
|
Loading…
Reference in New Issue