refactor(types): more

This commit is contained in:
alexander.akait 2023-05-26 20:21:35 +03:00 committed by Sean Larkin
parent e0cd9288a1
commit 792ee7e516
35 changed files with 282 additions and 127 deletions

View File

@ -80,7 +80,7 @@ module.exports = class ContextModuleFactory extends ModuleFactory {
/**
* @param {ModuleFactoryCreateData} data data object
* @param {function(Error=, ModuleFactoryResult=): void} callback callback
* @param {function((Error | null)=, ModuleFactoryResult=): void} callback callback
* @returns {void}
*/
create(data, callback) {

View File

@ -19,7 +19,7 @@ class DllModuleFactory extends ModuleFactory {
}
/**
* @param {ModuleFactoryCreateData} data data object
* @param {function(Error=, ModuleFactoryResult=): void} callback callback
* @param {function((Error | null)=, ModuleFactoryResult=): void} callback callback
* @returns {void}
*/
create(data, callback) {

View File

@ -85,7 +85,7 @@ const tryRunOrWebpackError = (fn, hook) => {
if (err instanceof WebpackError) {
throw err;
}
throw new HookWebpackError(err, hook);
throw new HookWebpackError(/** @type {Error} */ (err), hook);
}
return r;
};

View File

@ -26,7 +26,7 @@ class IgnoreErrorModuleFactory extends ModuleFactory {
/**
* @param {ModuleFactoryCreateData} data data object
* @param {function(Error=, ModuleFactoryResult=): void} callback callback
* @param {function((Error | null)=, ModuleFactoryResult=): void} callback callback
* @returns {void}
*/
create(data, callback) {

View File

@ -130,9 +130,9 @@ const deprecatedNeedRebuild = util.deprecate(
class Module extends DependenciesBlock {
/**
* @param {ModuleTypes} type the module type, when deserializing the type is not known and is an empty string
* @param {string=} context an optional context
* @param {string=} layer an optional layer in which the module is
* @param {ModuleTypes | ""} type the module type, when deserializing the type is not known and is an empty string
* @param {(string | null)=} context an optional context
* @param {(string | null)=} layer an optional layer in which the module is
*/
constructor(type, context = null, layer = null) {
super();
@ -151,7 +151,7 @@ class Module extends DependenciesBlock {
this.debugId = debugId++;
// Info from Factory
/** @type {ResolveOptions} */
/** @type {ResolveOptions | undefined} */
this.resolveOptions = EMPTY_RESOLVE_OPTIONS;
/** @type {object | undefined} */
this.factoryMeta = undefined;
@ -167,9 +167,9 @@ class Module extends DependenciesBlock {
this._warnings = undefined;
/** @type {WebpackError[] | undefined} */
this._errors = undefined;
/** @type {BuildMeta} */
/** @type {BuildMeta | undefined} */
this.buildMeta = undefined;
/** @type {Record<string, any>} */
/** @type {Record<string, any> | undefined} */
this.buildInfo = undefined;
/** @type {Dependency[] | undefined} */
this.presentationalDependencies = undefined;
@ -331,6 +331,10 @@ class Module extends DependenciesBlock {
);
}
/**
* @param {Chunk} chunk the chunk
* @returns {boolean} true, when the module was added
*/
addChunk(chunk) {
const chunkGraph = ChunkGraph.getChunkGraphForModule(
this,
@ -342,6 +346,10 @@ class Module extends DependenciesBlock {
return true;
}
/**
* @param {Chunk} chunk the chunk
* @returns {void}
*/
removeChunk(chunk) {
return ChunkGraph.getChunkGraphForModule(
this,
@ -350,6 +358,10 @@ class Module extends DependenciesBlock {
).disconnectChunkAndModule(chunk, this);
}
/**
* @param {Chunk} chunk the chunk
* @returns {boolean} true, when the module is in the chunk
*/
isInChunk(chunk) {
return ChunkGraph.getChunkGraphForModule(
this,
@ -435,7 +447,7 @@ class Module extends DependenciesBlock {
case "namespace":
return "namespace";
case "default":
switch (this.buildMeta.defaultObject) {
switch (/** @type {BuildMeta} */ (this.buildMeta).defaultObject) {
case "redirect":
return "default-with-named";
case "redirect-warn":
@ -447,7 +459,7 @@ class Module extends DependenciesBlock {
if (strict) return "default-with-named";
// Try to figure out value of __esModule by following reexports
const handleDefault = () => {
switch (this.buildMeta.defaultObject) {
switch (/** @type {BuildMeta} */ (this.buildMeta).defaultObject) {
case "redirect":
case "redirect-warn":
return "default-with-named";
@ -664,7 +676,7 @@ class Module extends DependenciesBlock {
] of moduleGraph.getIncomingConnectionsByOriginModule(this)) {
if (!connections.some(c => c.isTargetActive(chunk.runtime))) continue;
for (const originChunk of chunkGraph.getModuleChunksIterable(
fromModule
/** @type {Module} */ (fromModule)
)) {
// return true if module this is not reachable from originChunk when ignoring chunk
if (!this.isAccessibleInChunk(chunkGraph, originChunk, chunk))

View File

@ -38,7 +38,7 @@ class ModuleFactory {
/**
* @abstract
* @param {ModuleFactoryCreateData} data data object
* @param {function(Error=, ModuleFactoryResult=): void} callback callback
* @param {function((Error | null)=, ModuleFactoryResult=): void} callback callback
* @returns {void}
*/
create(data, callback) {

View File

@ -753,7 +753,7 @@ class NormalModuleFactory extends ModuleFactory {
/**
* @param {ModuleFactoryCreateData} data data object
* @param {function(Error=, ModuleFactoryResult=): void} callback callback
* @param {function((Error | null)=, ModuleFactoryResult=): void} callback callback
* @returns {void}
*/
create(data, callback) {

View File

@ -13,7 +13,7 @@ const ModuleFactory = require("./ModuleFactory");
class NullFactory extends ModuleFactory {
/**
* @param {ModuleFactoryCreateData} data data object
* @param {function(Error=, ModuleFactoryResult=): void} callback callback
* @param {function((Error | null)=, ModuleFactoryResult=): void} callback callback
* @returns {void}
*/
create(data, callback) {

View File

@ -273,6 +273,10 @@ class ContainerEntryModule extends Module {
super.serialize(context);
}
/**
* @param {ObjectDeserializerContext} context context
* @returns {ContainerEntryModule} deserialized container entry module
*/
static deserialize(context) {
const { read } = context;
const obj = new ContainerEntryModule(read(), read(), read());

View File

@ -15,7 +15,7 @@ const ContainerEntryModule = require("./ContainerEntryModule");
module.exports = class ContainerEntryModuleFactory extends ModuleFactory {
/**
* @param {ModuleFactoryCreateData} data data object
* @param {function(Error=, ModuleFactoryResult=): void} callback callback
* @param {function((Error | null)=, ModuleFactoryResult=): void} callback callback
* @returns {void}
*/
create({ dependencies: [dependency] }, callback) {

View File

@ -12,6 +12,9 @@ const makeSerializable = require("../util/makeSerializable");
/** @typedef {import("../serialization/ObjectMiddleware").ObjectSerializerContext} ObjectSerializerContext */
class FallbackDependency extends Dependency {
/**
* @param {string[]} requests requests
*/
constructor(requests) {
super();
this.requests = requests;
@ -41,6 +44,10 @@ class FallbackDependency extends Dependency {
super.serialize(context);
}
/**
* @param {ObjectDeserializerContext} context context
* @returns {FallbackDependency} deserialize fallback dependency
*/
static deserialize(context) {
const { read } = context;
const obj = new FallbackDependency(read());

View File

@ -9,6 +9,9 @@ const ModuleDependency = require("../dependencies/ModuleDependency");
const makeSerializable = require("../util/makeSerializable");
class FallbackItemDependency extends ModuleDependency {
/**
* @param {string} request request
*/
constructor(request) {
super(request);
}

View File

@ -166,6 +166,10 @@ class FallbackModule extends Module {
super.serialize(context);
}
/**
* @param {ObjectDeserializerContext} context context
* @returns {FallbackModule} deserialized fallback module
*/
static deserialize(context) {
const { read } = context;
const obj = new FallbackModule(read());

View File

@ -15,7 +15,7 @@ const FallbackModule = require("./FallbackModule");
module.exports = class FallbackModuleFactory extends ModuleFactory {
/**
* @param {ModuleFactoryCreateData} data data object
* @param {function(Error=, ModuleFactoryResult=): void} callback callback
* @param {function((Error | null)=, ModuleFactoryResult=): void} callback callback
* @returns {void}
*/
create({ dependencies: [dependency] }, callback) {

View File

@ -164,6 +164,10 @@ class RemoteModule extends Module {
super.serialize(context);
}
/**
* @param {ObjectDeserializerContext} context context
* @returns {RemoteModule} deserialized module
*/
static deserialize(context) {
const { read } = context;
const obj = new RemoteModule(read(), read(), read(), read());

View File

@ -9,6 +9,7 @@ const RuntimeGlobals = require("../RuntimeGlobals");
const RuntimeModule = require("../RuntimeModule");
const Template = require("../Template");
/** @typedef {import("../Chunk")} Chunk */
/** @typedef {import("./RemoteModule")} RemoteModule */
class RemoteRuntimeModule extends RuntimeModule {

View File

@ -9,6 +9,9 @@ const ModuleDependency = require("../dependencies/ModuleDependency");
const makeSerializable = require("../util/makeSerializable");
class RemoteToExternalDependency extends ModuleDependency {
/**
* @param {string} request request
*/
constructor(request) {
super(request);
}

View File

@ -17,7 +17,9 @@ const {
} = require("../javascript/JavascriptModulesPlugin");
const { updateHashForEntryStartup } = require("../javascript/StartupHelpers");
/** @typedef {import("../Chunk")} Chunk */
/** @typedef {import("../Compiler")} Compiler */
/** @typedef {import("../Entrypoint")} Entrypoint */
class ModuleChunkFormatPlugin {
/**
@ -73,7 +75,9 @@ class ModuleChunkFormatPlugin {
chunkGraph.getChunkEntryModulesWithChunkGroupIterable(chunk)
);
if (entries.length > 0) {
const runtimeChunk = entries[0][1].getRuntimeChunk();
const runtimeChunk =
/** @type {Entrypoint[][]} */
(entries)[0][1].getRuntimeChunk();
const currentOutputName = compilation
.getPath(
getChunkFilenameTemplate(chunk, compilation.outputOptions),
@ -87,6 +91,10 @@ class ModuleChunkFormatPlugin {
// remove filename, we only need the directory
currentOutputName.pop();
/**
* @param {Chunk} chunk the chunk
* @returns {string} the relative path
*/
const getRelativePath = chunk => {
const baseOutputName = currentOutputName.slice();
const chunkOutputName = compilation
@ -124,7 +132,7 @@ class ModuleChunkFormatPlugin {
entrySource.add(";\n\n// load runtime\n");
entrySource.add(
`import ${RuntimeGlobals.require} from ${JSON.stringify(
getRelativePath(runtimeChunk)
getRelativePath(/** @type {Chunk} */ (runtimeChunk))
)};\n`
);
@ -143,8 +151,8 @@ class ModuleChunkFormatPlugin {
const final = i + 1 === entries.length;
const moduleId = chunkGraph.getModuleId(module);
const chunks = getAllChunks(
entrypoint,
runtimeChunk,
/** @type {Entrypoint} */ (entrypoint),
/** @type {Chunk} */ (runtimeChunk),
undefined
);
for (const chunk of chunks) {

View File

@ -9,6 +9,7 @@ const RuntimeGlobals = require("../RuntimeGlobals");
const ExportWebpackRequireRuntimeModule = require("./ExportWebpackRequireRuntimeModule");
const ModuleChunkLoadingRuntimeModule = require("./ModuleChunkLoadingRuntimeModule");
/** @typedef {import("../Chunk")} Chunk */
/** @typedef {import("../Compiler")} Compiler */
class ModuleChunkLoadingPlugin {
@ -22,6 +23,10 @@ class ModuleChunkLoadingPlugin {
"ModuleChunkLoadingPlugin",
compilation => {
const globalChunkLoading = compilation.outputOptions.chunkLoading;
/**
* @param {Chunk} chunk chunk to check
* @returns {boolean} true, when the plugin is enabled for the chunk
*/
const isEnabledForChunk = chunk => {
const options = chunk.getEntryOptions();
const chunkLoading =
@ -31,6 +36,10 @@ class ModuleChunkLoadingPlugin {
return chunkLoading === "import";
};
const onceForChunkSet = new WeakSet();
/**
* @param {Chunk} chunk chunk to check
* @param {Set<string>} set runtime requirements
*/
const handler = (chunk, set) => {
if (onceForChunkSet.has(chunk)) return;
onceForChunkSet.add(chunk);

View File

@ -18,6 +18,7 @@ const compileBooleanMatcher = require("../util/compileBooleanMatcher");
const { getUndoPath } = require("../util/identifier");
/** @typedef {import("../Chunk")} Chunk */
/** @typedef {import("../ChunkGraph")} ChunkGraph */
/**
* @typedef {Object} JsonpCompilationPluginHooks
@ -69,11 +70,10 @@ class ModuleChunkLoadingRuntimeModule extends RuntimeModule {
if (options && options.baseUri) {
return `${RuntimeGlobals.baseURI} = ${JSON.stringify(options.baseUri)};`;
}
const compilation = /** @type {Compilation} */ (this.compilation);
const {
compilation: {
outputOptions: { importMetaName }
}
} = this;
outputOptions: { importMetaName }
} = compilation;
return `${RuntimeGlobals.baseURI} = new URL(${JSON.stringify(
rootOutputDir
)}, ${importMetaName}.url);`;
@ -83,7 +83,9 @@ class ModuleChunkLoadingRuntimeModule extends RuntimeModule {
* @returns {string} runtime code
*/
generate() {
const { compilation, chunk, chunkGraph } = this;
const compilation = /** @type {Compilation} */ (this.compilation);
const chunkGraph = /** @type {ChunkGraph} */ (this.chunkGraph);
const chunk = /** @type {Chunk} */ (this.chunk);
const {
runtimeTemplate,
outputOptions: { importFunctionName }
@ -106,8 +108,8 @@ class ModuleChunkLoadingRuntimeModule extends RuntimeModule {
const hasJsMatcher = compileBooleanMatcher(conditionMap);
const initialChunkIds = getInitialChunkIds(chunk, chunkGraph, chunkHasJs);
const outputName = this.compilation.getPath(
getChunkFilenameTemplate(chunk, this.compilation.outputOptions),
const outputName = compilation.getPath(
getChunkFilenameTemplate(chunk, compilation.outputOptions),
{
chunk,
contentHashType: "javascript"
@ -115,7 +117,7 @@ class ModuleChunkLoadingRuntimeModule extends RuntimeModule {
);
const rootOutputDir = getUndoPath(
outputName,
/** @type {string} */ (this.compilation.outputOptions.path),
/** @type {string} */ (compilation.outputOptions.path),
true
);

View File

@ -303,7 +303,7 @@ class LazyCompilationDependencyFactory extends ModuleFactory {
/**
* @param {ModuleFactoryCreateData} data data object
* @param {function(Error=, ModuleFactoryResult=): void} callback callback
* @param {function((Error | null)=, ModuleFactoryResult=): void} callback callback
* @returns {void}
*/
create(data, callback) {

View File

@ -13,7 +13,18 @@ const {
/** @typedef {import("../Compiler")} Compiler */
/**
* @typedef {Object} ChunkModuleIdRangePluginOptions
* @property {string} name the chunk name
* @property {("index" | "index2" | "preOrderIndex" | "postOrderIndex")=} order order
* @property {number=} start start id
* @property {number=} end end id
*/
class ChunkModuleIdRangePlugin {
/**
* @param {ChunkModuleIdRangePluginOptions} options options object
*/
constructor(options) {
this.options = options;
}

View File

@ -15,9 +15,18 @@ const {
/** @typedef {import("../Compiler")} Compiler */
/** @typedef {import("../Module")} Module */
/**
* @typedef {Object} DeterministicChunkIdsPluginOptions
* @property {string=} context context for ids
* @property {number=} maxLength maximum length of ids
*/
class DeterministicChunkIdsPlugin {
constructor(options) {
this.options = options || {};
/**
* @param {DeterministicChunkIdsPluginOptions} [options] options
*/
constructor(options = {}) {
this.options = options;
}
/**

View File

@ -17,15 +17,19 @@ const {
/** @typedef {import("../Compiler")} Compiler */
/** @typedef {import("../Module")} Module */
/**
* @typedef {Object} DeterministicModuleIdsPluginOptions
* @property {string=} context context relative to which module identifiers are computed
* @property {function(Module): boolean=} test selector function for modules
* @property {number=} maxLength maximum id length in digits (used as starting point)
* @property {number=} salt hash salt for ids
* @property {boolean=} fixedLength do not increase the maxLength to find an optimal id space size
* @property {boolean=} failOnConflict throw an error when id conflicts occur (instead of rehashing)
*/
class DeterministicModuleIdsPlugin {
/**
* @param {Object} options options
* @param {string=} options.context context relative to which module identifiers are computed
* @param {function(Module): boolean=} options.test selector function for modules
* @param {number=} options.maxLength maximum id length in digits (used as starting point)
* @param {number=} options.salt hash salt for ids
* @param {boolean=} options.fixedLength do not increase the maxLength to find an optimal id space size
* @param {boolean=} options.failOnConflict throw an error when id conflicts occur (instead of rehashing)
* @param {DeterministicModuleIdsPluginOptions} [options] options
*/
constructor(options = {}) {
this.options = options;

View File

@ -16,6 +16,7 @@ const {
} = require("./IdHelpers");
/** @typedef {import("../../declarations/plugins/HashedModuleIdsPlugin").HashedModuleIdsPluginOptions} HashedModuleIdsPluginOptions */
/** @typedef {import("../Compiler")} Compiler */
const validate = createSchemaValidation(
require("../../schemas/plugins/HashedModuleIdsPlugin.check.js"),
@ -43,6 +44,11 @@ class HashedModuleIdsPlugin {
};
}
/**
* Apply the plugin
* @param {Compiler} compiler the compiler instance
* @returns {void}
*/
apply(compiler) {
const options = this.options;
compiler.hooks.compilation.tap("HashedModuleIdsPlugin", compilation => {
@ -64,7 +70,8 @@ class HashedModuleIdsPlugin {
hash.digest(options.hashDigest)
);
let len = options.hashDigestLength;
while (usedIds.has(hashId.slice(0, len))) len++;
while (usedIds.has(hashId.slice(0, len)))
/** @type {number} */ (len)++;
const moduleId = hashId.slice(0, len);
chunkGraph.setModuleId(module, moduleId);
usedIds.add(moduleId);

View File

@ -427,6 +427,9 @@ const assignAscendingModuleIds = (usedIds, modules, compilation) => {
let nextId = 0;
let assignId;
if (usedIds.size > 0) {
/**
* @param {Module} module the module
*/
assignId = module => {
if (chunkGraph.getModuleId(module) === null) {
while (usedIds.has(nextId + "")) nextId++;
@ -434,6 +437,9 @@ const assignAscendingModuleIds = (usedIds, modules, compilation) => {
}
};
} else {
/**
* @param {Module} module the module
*/
assignId = module => {
if (chunkGraph.getModuleId(module) === null) {
chunkGraph.setModuleId(module, nextId++);

View File

@ -14,11 +14,21 @@ const {
assignAscendingChunkIds
} = require("./IdHelpers");
/** @typedef {import("../../declarations/WebpackOptions").OutputNormalized} Output */
/** @typedef {import("../Chunk")} Chunk */
/** @typedef {import("../Compiler")} Compiler */
/** @typedef {import("../Module")} Module */
/**
* @typedef {Object} NamedChunkIdsPluginOptions
* @property {string} [context] context
* @property {string} [delimiter] delimiter
*/
class NamedChunkIdsPlugin {
/**
* @param {NamedChunkIdsPluginOptions=} options options
*/
constructor(options) {
this.delimiter = (options && options.delimiter) || "-";
this.context = options && options.context;
@ -31,7 +41,9 @@ class NamedChunkIdsPlugin {
*/
apply(compiler) {
compiler.hooks.compilation.tap("NamedChunkIdsPlugin", compilation => {
const { hashFunction } = compilation.outputOptions;
const hashFunction =
/** @type {NonNullable<Output["hashFunction"]>} */
(compilation.outputOptions.hashFunction);
compilation.hooks.chunkIds.tap("NamedChunkIdsPlugin", chunks => {
const chunkGraph = compilation.chunkGraph;
const context = this.context ? this.context : compiler.context;

View File

@ -14,12 +14,21 @@ const {
assignAscendingModuleIds
} = require("./IdHelpers");
/** @typedef {import("../../declarations/WebpackOptions").OutputNormalized} Output */
/** @typedef {import("../Compiler")} Compiler */
/** @typedef {import("../Module")} Module */
/**
* @typedef {Object} NamedModuleIdsPluginOptions
* @property {string} [context] context
*/
class NamedModuleIdsPlugin {
constructor(options) {
this.options = options || {};
/**
* @param {NamedModuleIdsPluginOptions} [options] options
*/
constructor(options = {}) {
this.options = options;
}
/**
@ -30,7 +39,9 @@ class NamedModuleIdsPlugin {
apply(compiler) {
const { root } = compiler;
compiler.hooks.compilation.tap("NamedModuleIdsPlugin", compilation => {
const { hashFunction } = compilation.outputOptions;
const hashFunction =
/** @type {NonNullable<Output["hashFunction"]>} */
(compilation.outputOptions.hashFunction);
compilation.hooks.moduleIds.tap("NamedModuleIdsPlugin", () => {
const chunkGraph = compilation.chunkGraph;
const context = this.options.context

View File

@ -60,8 +60,12 @@ class OccurrenceChunkIdsPlugin {
const chunksInOccurrenceOrder = Array.from(chunks).sort((a, b) => {
if (prioritiseInitial) {
const aEntryOccurs = occursInInitialChunksMap.get(a);
const bEntryOccurs = occursInInitialChunksMap.get(b);
const aEntryOccurs =
/** @type {number} */
(occursInInitialChunksMap.get(a));
const bEntryOccurs =
/** @type {number} */
(occursInInitialChunksMap.get(b));
if (aEntryOccurs > bEntryOccurs) return -1;
if (aEntryOccurs < bEntryOccurs) return 1;
}

View File

@ -50,7 +50,7 @@ class SyncModuleIdsPlugin {
}
return callback();
}
const json = JSON.parse(buffer.toString());
const json = JSON.parse(/** @type {Buffer} */ (buffer).toString());
data = new Map();
for (const key of Object.keys(json)) {
data.set(key, json[key]);
@ -98,7 +98,7 @@ class SyncModuleIdsPlugin {
err.module = module;
compilation.errors.push(err);
}
chunkGraph.setModuleId(module, id);
chunkGraph.setModuleId(module, /** @type {string | number} */ (id));
usedIds.add(idAsString);
}
});

View File

@ -11,8 +11,8 @@ const Entrypoint = require("../Entrypoint");
/**
* @param {Entrypoint} entrypoint a chunk group
* @param {Chunk} excludedChunk1 current chunk which is excluded
* @param {Chunk} excludedChunk2 runtime chunk which is excluded
* @param {Chunk=} excludedChunk1 current chunk which is excluded
* @param {Chunk=} excludedChunk2 runtime chunk which is excluded
* @returns {Set<Chunk>} chunks
*/
const getAllChunks = (entrypoint, excludedChunk1, excludedChunk2) => {

View File

@ -130,8 +130,8 @@ const printGeneratedCodeForStack = (module, code) => {
* @property {SyncWaterfallHook<[Source, Module, StartupRenderContext]>} renderStartup
* @property {SyncWaterfallHook<[string, RenderBootstrapContext]>} renderRequire
* @property {SyncBailHook<[Module, RenderBootstrapContext], string>} inlineInRuntimeBailout
* @property {SyncBailHook<[Module, RenderContext], string>} embedInRuntimeBailout
* @property {SyncBailHook<[RenderContext], string>} strictRuntimeBailout
* @property {SyncBailHook<[Module, RenderContext], string | void>} embedInRuntimeBailout
* @property {SyncBailHook<[RenderContext], string | void>} strictRuntimeBailout
* @property {SyncHook<[Chunk, Hash, ChunkHashContext]>} chunkHash
* @property {SyncBailHook<[Chunk, RenderContext], boolean>} useSourceMap
*/

View File

@ -15,7 +15,7 @@ const ProvideSharedModule = require("./ProvideSharedModule");
class ProvideSharedModuleFactory extends ModuleFactory {
/**
* @param {ModuleFactoryCreateData} data data object
* @param {function(Error=, ModuleFactoryResult=): void} callback callback
* @param {function((Error | null)=, ModuleFactoryResult=): void} callback callback
* @returns {void}
*/
create(data, callback) {

View File

@ -132,7 +132,7 @@ let BatchedHash = undefined;
/**
* Creates a hash by name or function
* @param {string | typeof Hash} algorithm the algorithm name or a constructor creating a hash
* @param {string | typeof Hash | undefined} algorithm the algorithm name or a constructor creating a hash
* @returns {Hash} the hash
*/
module.exports = algorithm => {

178
types.d.ts vendored
View File

@ -1187,14 +1187,35 @@ declare interface ChunkMaps {
name: Record<string | number, string>;
}
declare class ChunkModuleIdRangePlugin {
constructor(options?: any);
options: any;
constructor(options: ChunkModuleIdRangePluginOptions);
options: ChunkModuleIdRangePluginOptions;
/**
* Apply the plugin
*/
apply(compiler: Compiler): void;
}
declare interface ChunkModuleIdRangePluginOptions {
/**
* the chunk name
*/
name: string;
/**
* order
*/
order?: "index" | "index2" | "preOrderIndex" | "postOrderIndex";
/**
* start id
*/
start?: number;
/**
* end id
*/
end?: number;
}
declare interface ChunkModuleMaps {
id: Record<string | number, (string | number)[]>;
hash: Record<string | number, string>;
@ -2000,8 +2021,8 @@ declare interface CompilationHooksJavascriptModulesPlugin {
[Module, RenderBootstrapContext],
string
>;
embedInRuntimeBailout: SyncBailHook<[Module, RenderContext], string>;
strictRuntimeBailout: SyncBailHook<[RenderContext], string>;
embedInRuntimeBailout: SyncBailHook<[Module, RenderContext], string | void>;
strictRuntimeBailout: SyncBailHook<[RenderContext], string | void>;
chunkHash: SyncHook<[Chunk, Hash, ChunkHashContext]>;
useSourceMap: SyncBailHook<[Chunk, RenderContext], boolean>;
}
@ -2902,73 +2923,65 @@ declare abstract class DependencyTemplates {
clone(): DependencyTemplates;
}
declare class DeterministicChunkIdsPlugin {
constructor(options?: any);
options: any;
constructor(options?: DeterministicChunkIdsPluginOptions);
options: DeterministicChunkIdsPluginOptions;
/**
* Apply the plugin
*/
apply(compiler: Compiler): void;
}
declare interface DeterministicChunkIdsPluginOptions {
/**
* context for ids
*/
context?: string;
/**
* maximum length of ids
*/
maxLength?: number;
}
declare class DeterministicModuleIdsPlugin {
constructor(options?: {
/**
* context relative to which module identifiers are computed
*/
context?: string;
/**
* selector function for modules
*/
test?: (arg0: Module) => boolean;
/**
* maximum id length in digits (used as starting point)
*/
maxLength?: number;
/**
* hash salt for ids
*/
salt?: number;
/**
* do not increase the maxLength to find an optimal id space size
*/
fixedLength?: boolean;
/**
* throw an error when id conflicts occur (instead of rehashing)
*/
failOnConflict?: boolean;
});
options: {
/**
* context relative to which module identifiers are computed
*/
context?: string;
/**
* selector function for modules
*/
test?: (arg0: Module) => boolean;
/**
* maximum id length in digits (used as starting point)
*/
maxLength?: number;
/**
* hash salt for ids
*/
salt?: number;
/**
* do not increase the maxLength to find an optimal id space size
*/
fixedLength?: boolean;
/**
* throw an error when id conflicts occur (instead of rehashing)
*/
failOnConflict?: boolean;
};
constructor(options?: DeterministicModuleIdsPluginOptions);
options: DeterministicModuleIdsPluginOptions;
/**
* Apply the plugin
*/
apply(compiler: Compiler): void;
}
declare interface DeterministicModuleIdsPluginOptions {
/**
* context relative to which module identifiers are computed
*/
context?: string;
/**
* selector function for modules
*/
test?: (arg0: Module) => boolean;
/**
* maximum id length in digits (used as starting point)
*/
maxLength?: number;
/**
* hash salt for ids
*/
salt?: number;
/**
* do not increase the maxLength to find an optimal id space size
*/
fixedLength?: boolean;
/**
* throw an error when id conflicts occur (instead of rehashing)
*/
failOnConflict?: boolean;
}
/**
* Options for the webpack-dev-server.
@ -4700,7 +4713,11 @@ declare interface HashableObject {
declare class HashedModuleIdsPlugin {
constructor(options?: HashedModuleIdsPluginOptions);
options: HashedModuleIdsPluginOptions;
apply(compiler?: any): void;
/**
* Apply the plugin
*/
apply(compiler: Compiler): void;
}
declare interface HashedModuleIdsPluginOptions {
/**
@ -7218,12 +7235,12 @@ declare class Module extends DependenciesBlock {
layer: null | string;
needId: boolean;
debugId: number;
resolveOptions: ResolveOptionsWebpackOptions;
resolveOptions?: ResolveOptionsWebpackOptions;
factoryMeta?: object;
useSourceMap: boolean;
useSimpleSourceMap: boolean;
buildMeta: BuildMeta;
buildInfo: Record<string, any>;
buildMeta?: BuildMeta;
buildInfo?: Record<string, any>;
presentationalDependencies?: Dependency[];
codeGenerationDependencies?: Dependency[];
id: string | number;
@ -7240,9 +7257,9 @@ declare class Module extends DependenciesBlock {
| ((requestShortener: RequestShortener) => string)
)[];
get optional(): boolean;
addChunk(chunk?: any): boolean;
removeChunk(chunk?: any): void;
isInChunk(chunk?: any): boolean;
addChunk(chunk: Chunk): boolean;
removeChunk(chunk: Chunk): void;
isInChunk(chunk: Chunk): boolean;
isEntryModule(): boolean;
getChunks(): Chunk[];
getNumberOfChunks(): number;
@ -7372,7 +7389,7 @@ declare class ModuleDependency extends Dependency {
declare abstract class ModuleFactory {
create(
data: ModuleFactoryCreateData,
callback: (arg0?: Error, arg1?: ModuleFactoryResult) => void
callback: (arg0?: null | Error, arg1?: ModuleFactoryResult) => void
): void;
}
declare interface ModuleFactoryCreateData {
@ -7935,24 +7952,41 @@ declare abstract class MultiWatching {
close(callback: CallbackFunction<void>): void;
}
declare class NamedChunkIdsPlugin {
constructor(options?: any);
delimiter: any;
context: any;
constructor(options?: NamedChunkIdsPluginOptions);
delimiter: string;
context?: string;
/**
* Apply the plugin
*/
apply(compiler: Compiler): void;
}
declare interface NamedChunkIdsPluginOptions {
/**
* context
*/
context?: string;
/**
* delimiter
*/
delimiter?: string;
}
declare class NamedModuleIdsPlugin {
constructor(options?: any);
options: any;
constructor(options?: NamedModuleIdsPluginOptions);
options: NamedModuleIdsPluginOptions;
/**
* Apply the plugin
*/
apply(compiler: Compiler): void;
}
declare interface NamedModuleIdsPluginOptions {
/**
* context
*/
context?: string;
}
declare class NaturalModuleIdsPlugin {
constructor();
@ -13501,7 +13535,7 @@ declare namespace exports {
export { ProfilingPlugin };
}
export namespace util {
export const createHash: (algorithm: string | typeof Hash) => Hash;
export const createHash: (algorithm?: string | typeof Hash) => Hash;
export namespace comparators {
export let compareChunksById: (a: Chunk, b: Chunk) => 0 | 1 | -1;
export let compareModulesByIdentifier: (