Skip to content

Commit

Permalink
Merge branch 'feature/type-compiler-compilation-save' of https://gith…
Browse files Browse the repository at this point in the history
…ub.com/webpack/webpack into feature/type-compiler-compilation-save

Conflicts:
	lib/AsyncDependenciesBlock.js
	lib/Chunk.js
	lib/Compilation.js
	lib/DelegatedModule.js
	lib/DependenciesBlock.js
	lib/DependenciesBlockVariable.js
	lib/Dependency.js
	lib/Module.js
	lib/MultiEntryPlugin.js
	lib/WebpackError.js
	lib/dependencies/DependencyReference.js
	lib/util/Semaphore.js
  • Loading branch information
TheLarkInn committed May 18, 2018
2 parents 62cce4e + da823fc commit 156a6f7
Show file tree
Hide file tree
Showing 14 changed files with 96 additions and 63 deletions.
2 changes: 2 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,10 @@ module.exports = {
"valid-jsdoc": ["error", {
"prefer": {
"return": "returns",
"prop": "property",
"memberof": "DONTUSE",
"class": "DONTUSE",
"extends": "DONTUSE",
"inheritdoc": "DONTUSE",
"description": "DONTUSE",
"readonly": "DONTUSE"
Expand Down
12 changes: 5 additions & 7 deletions lib/AsyncDependenciesBlock.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
/**
Expand Down
32 changes: 25 additions & 7 deletions lib/Chunk.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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()) {
Expand All @@ -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();
Expand Down Expand Up @@ -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)) {
Expand Down
59 changes: 34 additions & 25 deletions lib/Compilation.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand All @@ -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 */
Expand Down Expand Up @@ -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[]>} */
Expand Down Expand Up @@ -448,30 +448,38 @@ 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;
/** @type {Map<string, number>=} */
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();
}

getStats() {
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) {
Expand Down Expand Up @@ -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) {
Expand All @@ -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);
Expand Down Expand Up @@ -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}
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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
Expand All @@ -999,7 +1007,7 @@ class Compilation extends Tapable {
module: null
};

if (entry instanceof SingleEntryDependency) {
if (entry instanceof ModuleDependency) {
slot.request = entry.request;
}

Expand Down Expand Up @@ -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}
*/
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -2169,7 +2178,7 @@ class Compilation extends Tapable {
}

/**
* @param {TODO} update //TODO (update hash function?)
* @param {string} update extra information
* @returns {void}
*/
modifyHash(update) {
Expand Down Expand Up @@ -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 || {};
Expand Down
12 changes: 8 additions & 4 deletions lib/DelegatedModule.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ class DelegatedModule extends Module {
this.userRequest = userRequest;
this.originalRequest = originalRequest;
this.delegateData = data;

// Build info
this.delegatedSourceDependency = undefined;
}

libIdent(options) {
Expand All @@ -50,17 +53,18 @@ 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)
);
callback();
}

source(depTemplates, runtime) {
const dep = this.dependencies[0];
const dep = this.delegatedSourceDependency;
const sourceModule = dep.module;
let str;

Expand Down
17 changes: 6 additions & 11 deletions lib/DependenciesBlock.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -23,9 +21,6 @@ class DependenciesBlock {
this.blocks = [];
/** @type {DependenciesBlockVariable[]} */
this.variables = [];
// TODO remove this line, it's wrong
/** @type {ChunkGroup=} */
this.chunkGroup = undefined;
}

/**
Expand Down
3 changes: 2 additions & 1 deletion lib/DependenciesBlockVariable.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
/**
Expand Down
Loading

0 comments on commit 156a6f7

Please sign in to comment.