mirror of https://github.com/webpack/webpack.git
add more types to Module
This commit is contained in:
parent
0052861178
commit
22c4756c9e
|
|
@ -86,9 +86,11 @@ module.exports = class AsyncDependenciesBlock extends DependenciesBlock {
|
|||
}
|
||||
|
||||
/**
|
||||
* Sorts items in this module
|
||||
* @param {boolean=} sortChunks sort the chunks too
|
||||
* @returns {void}
|
||||
*/
|
||||
sortItems() {
|
||||
sortItems(sortChunks) {
|
||||
super.sortItems();
|
||||
}
|
||||
};
|
||||
|
|
|
|||
|
|
@ -205,6 +205,11 @@ class ContextModule extends Module {
|
|||
return identifier;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {TODO} fileTimestamps timestamps of files
|
||||
* @param {TODO} contextTimestamps timestamps of directories
|
||||
* @returns {boolean} true, if the module needs a rebuild
|
||||
*/
|
||||
needRebuild(fileTimestamps, contextTimestamps) {
|
||||
const ts = contextTimestamps.get(this.context);
|
||||
if (!ts) {
|
||||
|
|
|
|||
|
|
@ -58,7 +58,12 @@ class DelegatedModule extends Module {
|
|||
return `delegated ${this.userRequest} from ${this.sourceRequest}`;
|
||||
}
|
||||
|
||||
needRebuild() {
|
||||
/**
|
||||
* @param {TODO} fileTimestamps timestamps of files
|
||||
* @param {TODO} contextTimestamps timestamps of directories
|
||||
* @returns {boolean} true, if the module needs a rebuild
|
||||
*/
|
||||
needRebuild(fileTimestamps, contextTimestamps) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -116,7 +116,12 @@ class DependenciesBlock {
|
|||
return false;
|
||||
}
|
||||
|
||||
sortItems() {
|
||||
/**
|
||||
* Sorts items in this module
|
||||
* @param {boolean=} sortChunks sort the chunks too
|
||||
* @returns {void}
|
||||
*/
|
||||
sortItems(sortChunks) {
|
||||
for (const block of this.blocks) block.sortItems();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -64,7 +64,12 @@ class DllModule extends Module {
|
|||
return new RawSource("module.exports = __webpack_require__;");
|
||||
}
|
||||
|
||||
needRebuild() {
|
||||
/**
|
||||
* @param {TODO} fileTimestamps timestamps of files
|
||||
* @param {TODO} contextTimestamps timestamps of directories
|
||||
* @returns {boolean} true, if the module needs a rebuild
|
||||
*/
|
||||
needRebuild(fileTimestamps, contextTimestamps) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -55,7 +55,12 @@ class ExternalModule extends Module {
|
|||
return "external " + JSON.stringify(this.request);
|
||||
}
|
||||
|
||||
needRebuild() {
|
||||
/**
|
||||
* @param {TODO} fileTimestamps timestamps of files
|
||||
* @param {TODO} contextTimestamps timestamps of directories
|
||||
* @returns {boolean} true, if the module needs a rebuild
|
||||
*/
|
||||
needRebuild(fileTimestamps, contextTimestamps) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -10,7 +10,9 @@ const SortableSet = require("./util/SortableSet");
|
|||
const Template = require("./Template");
|
||||
|
||||
/** @typedef {import("./Chunk")} Chunk */
|
||||
/** @typedef {import("./ChunkGroup")} ChunkGroup */
|
||||
/** @typedef {import("./Compilation")} Compilation */
|
||||
/** @typedef {import("./Dependency")} Dependency */
|
||||
/** @typedef {import("./RequestShortener")} RequestShortener */
|
||||
/** @typedef {import("./DependencyTemplates")} DependencyTemplates */
|
||||
/** @typedef {import("./RuntimeTemplate")} RuntimeTemplate */
|
||||
|
|
@ -118,6 +120,10 @@ class Module extends DependenciesBlock {
|
|||
return (this.buildInfo && this.buildInfo.moduleArgument) || "module";
|
||||
}
|
||||
|
||||
/**
|
||||
* disconnect the module from the graph
|
||||
* @returns {void}
|
||||
*/
|
||||
disconnect() {
|
||||
this.hash = undefined;
|
||||
this.renderedHash = undefined;
|
||||
|
|
@ -140,6 +146,9 @@ class Module extends DependenciesBlock {
|
|||
super.disconnect();
|
||||
}
|
||||
|
||||
/**
|
||||
* @returns {void}
|
||||
*/
|
||||
unseal() {
|
||||
this.id = null;
|
||||
this.index = null;
|
||||
|
|
@ -149,16 +158,30 @@ class Module extends DependenciesBlock {
|
|||
super.unseal();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the chunks to a new value
|
||||
* @protected
|
||||
* @param {Iterable<Chunk>} chunks the new chunks
|
||||
* @returns {void}
|
||||
*/
|
||||
setChunks(chunks) {
|
||||
this._chunks = new SortableSet(chunks, sortById);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Chunk} chunk added chunk
|
||||
* @returns {boolean} true, if the chunk could be added
|
||||
*/
|
||||
addChunk(chunk) {
|
||||
if (this._chunks.has(chunk)) return false;
|
||||
this._chunks.add(chunk);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Chunk} chunk removed chunk
|
||||
* @returns {boolean} true, if the chunk could be removed
|
||||
*/
|
||||
removeChunk(chunk) {
|
||||
if (this._chunks.delete(chunk)) {
|
||||
chunk.removeModule(this);
|
||||
|
|
@ -167,10 +190,17 @@ class Module extends DependenciesBlock {
|
|||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Chunk} chunk chunk to be tested
|
||||
* @returns {boolean} true, if the module is in a chunk
|
||||
*/
|
||||
isInChunk(chunk) {
|
||||
return this._chunks.has(chunk);
|
||||
}
|
||||
|
||||
/**
|
||||
* @returns {boolean} true, if the module is entry of any chunk
|
||||
*/
|
||||
isEntryModule() {
|
||||
for (const chunk of this._chunks) {
|
||||
if (chunk.entryModule === this) return true;
|
||||
|
|
@ -178,6 +208,9 @@ class Module extends DependenciesBlock {
|
|||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @returns {boolean} true, if the module is optional
|
||||
*/
|
||||
get optional() {
|
||||
return (
|
||||
this.reasons.length > 0 &&
|
||||
|
|
@ -192,14 +225,24 @@ class Module extends DependenciesBlock {
|
|||
return Array.from(this._chunks);
|
||||
}
|
||||
|
||||
/**
|
||||
* @returns {number} the number of chunk which contain the module
|
||||
*/
|
||||
getNumberOfChunks() {
|
||||
return this._chunks.size;
|
||||
}
|
||||
|
||||
/**
|
||||
* @returns {Iterable<Chunk>} chunks that contain the module
|
||||
*/
|
||||
get chunksIterable() {
|
||||
return this._chunks;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Module} otherModule some other module
|
||||
* @returns {boolean} true, if modules are in the same chunks
|
||||
*/
|
||||
hasEqualsChunks(otherModule) {
|
||||
if (this._chunks.size !== otherModule._chunks.size) return false;
|
||||
this._chunks.sortWith(sortByDebugId);
|
||||
|
|
@ -215,10 +258,21 @@ class Module extends DependenciesBlock {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Module=} module referenced module
|
||||
* @param {Dependency=} dependency referencing dependency
|
||||
* @param {string=} explanation some explanation
|
||||
* @returns {void}
|
||||
*/
|
||||
addReason(module, dependency, explanation) {
|
||||
this.reasons.push(new ModuleReason(module, dependency, explanation));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Module=} module referenced module
|
||||
* @param {Dependency=} dependency referencing dependency
|
||||
* @returns {boolean} true, if the reason could be removed
|
||||
*/
|
||||
removeReason(module, dependency) {
|
||||
for (let i = 0; i < this.reasons.length; i++) {
|
||||
let r = this.reasons[i];
|
||||
|
|
@ -230,6 +284,11 @@ class Module extends DependenciesBlock {
|
|||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Chunk} chunk a chunk
|
||||
* @param {Chunk=} ignoreChunk chunk to be ignored
|
||||
* @returns {boolean} true, if the module is accessible from "chunk" when ignoring "ignoreChunk"
|
||||
*/
|
||||
isAccessibleInChunk(chunk, ignoreChunk) {
|
||||
// Check if module is accessible in ALL chunk groups
|
||||
for (const chunkGroup of chunk.groupsIterable) {
|
||||
|
|
@ -238,6 +297,11 @@ class Module extends DependenciesBlock {
|
|||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {ChunkGroup} chunkGroup a chunk group
|
||||
* @param {Chunk=} ignoreChunk chunk to be ignored
|
||||
* @returns {boolean} true, if the module is accessible from "chunkGroup" when ignoring "ignoreChunk"
|
||||
*/
|
||||
isAccessibleInChunkGroup(chunkGroup, ignoreChunk) {
|
||||
const queue = new Set([chunkGroup]);
|
||||
|
||||
|
|
@ -258,6 +322,10 @@ class Module extends DependenciesBlock {
|
|||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Chunk} chunk a chunk
|
||||
* @returns {boolean} true, if the module has any reason why "chunk" should be included
|
||||
*/
|
||||
hasReasonForChunk(chunk) {
|
||||
// check for each reason if we need the chunk
|
||||
for (const reason of this.reasons) {
|
||||
|
|
@ -270,10 +338,19 @@ class Module extends DependenciesBlock {
|
|||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @returns {boolean} true, if there are references to this module
|
||||
*/
|
||||
hasReasons() {
|
||||
return this.reasons.length > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string=} exportName a name of an export
|
||||
* @returns {string | boolean} true, when no "exportName" is provided and the module is used.
|
||||
* false, when module or referenced export is unused.
|
||||
* string, the mangled export name when used.
|
||||
*/
|
||||
isUsed(exportName) {
|
||||
if (!exportName) return this.used !== false;
|
||||
if (this.used === null || this.usedExports === null) return exportName;
|
||||
|
|
@ -298,15 +375,29 @@ class Module extends DependenciesBlock {
|
|||
return exportName;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} exportName a name of an export
|
||||
* @returns {boolean | null} true, if the export is provided why the module.
|
||||
* null, if it's unknown.
|
||||
* false, if it's not provided.
|
||||
*/
|
||||
isProvided(exportName) {
|
||||
if (!Array.isArray(this.buildMeta.providedExports)) return null;
|
||||
return this.buildMeta.providedExports.includes(exportName);
|
||||
}
|
||||
|
||||
/**
|
||||
* @returns {string} for debugging
|
||||
*/
|
||||
toString() {
|
||||
return `Module[${this.id || this.debugId}]`;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {TODO} fileTimestamps timestamps of files
|
||||
* @param {TODO} contextTimestamps timestamps of directories
|
||||
* @returns {boolean} true, if the module needs a rebuild
|
||||
*/
|
||||
needRebuild(fileTimestamps, contextTimestamps) {
|
||||
return true;
|
||||
}
|
||||
|
|
@ -321,6 +412,11 @@ class Module extends DependenciesBlock {
|
|||
super.updateHash(hash);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sorts items in this module
|
||||
* @param {boolean=} sortChunks sort the chunks too
|
||||
* @returns {void}
|
||||
*/
|
||||
sortItems(sortChunks) {
|
||||
super.sortItems();
|
||||
if (sortChunks) this._chunks.sort();
|
||||
|
|
@ -335,6 +431,9 @@ class Module extends DependenciesBlock {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @returns {void}
|
||||
*/
|
||||
unbuild() {
|
||||
this.dependencies.length = 0;
|
||||
this.blocks.length = 0;
|
||||
|
|
|
|||
|
|
@ -59,7 +59,12 @@ class MultiModule extends Module {
|
|||
return callback();
|
||||
}
|
||||
|
||||
needRebuild() {
|
||||
/**
|
||||
* @param {TODO} fileTimestamps timestamps of files
|
||||
* @param {TODO} contextTimestamps timestamps of directories
|
||||
* @returns {boolean} true, if the module needs a rebuild
|
||||
*/
|
||||
needRebuild(fileTimestamps, contextTimestamps) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -536,6 +536,11 @@ class NormalModule extends Module {
|
|||
return this._source;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {TODO} fileTimestamps timestamps of files
|
||||
* @param {TODO} contextTimestamps timestamps of directories
|
||||
* @returns {boolean} true, if the module needs a rebuild
|
||||
*/
|
||||
needRebuild(fileTimestamps, contextTimestamps) {
|
||||
// always try to rebuild in case of an error
|
||||
if (this.error) return true;
|
||||
|
|
|
|||
|
|
@ -45,7 +45,12 @@ module.exports = class RawModule extends Module {
|
|||
return requestShortener.shorten(this.readableIdentifierStr);
|
||||
}
|
||||
|
||||
needRebuild() {
|
||||
/**
|
||||
* @param {TODO} fileTimestamps timestamps of files
|
||||
* @param {TODO} contextTimestamps timestamps of directories
|
||||
* @returns {boolean} true, if the module needs a rebuild
|
||||
*/
|
||||
needRebuild(fileTimestamps, contextTimestamps) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue