| | |
| | | const ModuleGraph = require("./ModuleGraph"); |
| | | const { JAVASCRIPT_MODULE_TYPE_AUTO } = require("./ModuleTypeConstants"); |
| | | const NormalModule = require("./NormalModule"); |
| | | const { ImportPhaseUtils } = require("./dependencies/ImportPhase"); |
| | | const BasicEffectRulePlugin = require("./rules/BasicEffectRulePlugin"); |
| | | const BasicMatcherRulePlugin = require("./rules/BasicMatcherRulePlugin"); |
| | | const ObjectMatcherRulePlugin = require("./rules/ObjectMatcherRulePlugin"); |
| | |
| | | /** @typedef {import("enhanced-resolve").ResolveRequest} ResolveRequest */ |
| | | /** @typedef {import("../declarations/WebpackOptions").ModuleOptionsNormalized} ModuleOptions */ |
| | | /** @typedef {import("../declarations/WebpackOptions").RuleSetRule} RuleSetRule */ |
| | | /** @typedef {import("./Compilation").FileSystemDependencies} FileSystemDependencies */ |
| | | /** @typedef {import("./Generator")} Generator */ |
| | | /** @typedef {import("./ModuleFactory").ModuleFactoryCallback} ModuleFactoryCallback */ |
| | | /** @typedef {import("./ModuleFactory").ModuleFactoryCreateData} ModuleFactoryCreateData */ |
| | |
| | | /** @typedef {import("./ResolverFactory")} ResolverFactory */ |
| | | /** @typedef {import("./ResolverFactory").ResolverWithOptions} ResolverWithOptions */ |
| | | /** @typedef {import("./dependencies/ModuleDependency")} ModuleDependency */ |
| | | /** @typedef {import("./dependencies/ImportPhase").ImportPhaseType} ImportPhaseType */ |
| | | /** @typedef {import("./dependencies/ImportPhase").ImportPhaseName} ImportPhaseName */ |
| | | /** @typedef {import("./javascript/JavascriptParser").ImportAttributes} ImportAttributes */ |
| | | /** @typedef {import("./rules/RuleSetCompiler").RuleSetRules} RuleSetRules */ |
| | | /** @typedef {import("./rules/RuleSetCompiler").RuleSet} RuleSet */ |
| | | /** @typedef {import("./util/fs").InputFileSystem} InputFileSystem */ |
| | | /** @typedef {import("./util/identifier").AssociatedObjectForCache} AssociatedObjectForCache */ |
| | | |
| | | /** |
| | | * Defines the callback type used by this module. |
| | | * @template T |
| | | * @typedef {import("./Compiler").Callback<T>} Callback |
| | | */ |
| | | |
| | | /** @typedef {Pick<RuleSetRule, 'type' | 'sideEffects' | 'parser' | 'generator' | 'resolve' | 'layer' | 'extractSourceMap'>} ModuleSettings */ |
| | | /** @typedef {Pick<RuleSetRule, "type" | "sideEffects" | "parser" | "generator" | "resolve" | "layer" | "extractSourceMap">} ModuleSettings */ |
| | | /** @typedef {Partial<NormalModuleCreateData & { settings: ModuleSettings }>} CreateData */ |
| | | |
| | | /** |
| | | * Defines the resolve data type used by this module. |
| | | * @typedef {object} ResolveData |
| | | * @property {ModuleFactoryCreateData["contextInfo"]} contextInfo |
| | | * @property {ModuleFactoryCreateData["resolveOptions"]} resolveOptions |
| | | * @property {string} context |
| | | * @property {string} request |
| | | * @property {ImportAttributes | undefined} attributes |
| | | * @property {ImportPhaseName=} phase |
| | | * @property {ImportAttributes=} attributes |
| | | * @property {ModuleDependency[]} dependencies |
| | | * @property {string} dependencyType |
| | | * @property {CreateData} createData |
| | | * @property {LazySet<string>} fileDependencies |
| | | * @property {LazySet<string>} missingDependencies |
| | | * @property {LazySet<string>} contextDependencies |
| | | * @property {FileSystemDependencies} fileDependencies |
| | | * @property {FileSystemDependencies} missingDependencies |
| | | * @property {FileSystemDependencies} contextDependencies |
| | | * @property {Module=} ignoredModule |
| | | * @property {boolean} cacheable allow to use the unsafe cache |
| | | */ |
| | | |
| | | /** |
| | | * Defines the resource data type used by this module. |
| | | * @typedef {object} ResourceData |
| | | * @property {string} resource |
| | | * @property {string=} path |
| | |
| | | */ |
| | | |
| | | /** |
| | | * Defines the resource scheme data type used by this module. |
| | | * @typedef {object} ResourceSchemeData |
| | | * @property {string=} mimetype mime type of the resource |
| | | * @property {string=} parameters additional parameters for the resource |
| | |
| | | /** @typedef {ResourceData & { data: ResourceSchemeData & Partial<ResolveRequest> }} ResourceDataWithData */ |
| | | |
| | | /** |
| | | * Defines the parsed loader request type used by this module. |
| | | * @typedef {object} ParsedLoaderRequest |
| | | * @property {string} loader loader |
| | | * @property {string|undefined} options options |
| | |
| | | const LEADING_DOT_EXTENSION_REGEX = /^[^.]/; |
| | | |
| | | /** |
| | | * Returns ident. |
| | | * @param {LoaderItem} data data |
| | | * @returns {string} ident |
| | | */ |
| | |
| | | }; |
| | | |
| | | /** |
| | | * Stringify loaders and resource. |
| | | * @param {LoaderItem[]} loaders loaders |
| | | * @param {string} resource resource |
| | | * @returns {string} stringified loaders and resource |
| | |
| | | }; |
| | | |
| | | /** |
| | | * Checks whether it needs calls. |
| | | * @param {number} times times |
| | | * @param {(err?: null | Error) => void} callback callback |
| | | * @returns {(err?: null | Error) => void} callback |
| | |
| | | }; |
| | | |
| | | /** |
| | | * Merges global options. |
| | | * @template T |
| | | * @template O |
| | | * @param {T} globalOptions global options |
| | |
| | | */ |
| | | const mergeGlobalOptions = (globalOptions, type, localOptions) => { |
| | | const parts = type.split("/"); |
| | | /** @type {undefined | T} */ |
| | | let result; |
| | | let current = ""; |
| | | for (const part of parts) { |
| | |
| | | |
| | | // TODO webpack 6 remove |
| | | /** |
| | | * Deprecation changed hook message. |
| | | * @template {import("tapable").Hook<EXPECTED_ANY, EXPECTED_ANY>} T |
| | | * @param {string} name name |
| | | * @param {T} hook hook |
| | |
| | | new BasicMatcherRulePlugin("issuer"), |
| | | new BasicMatcherRulePlugin("compiler"), |
| | | new BasicMatcherRulePlugin("issuerLayer"), |
| | | new BasicMatcherRulePlugin("phase"), |
| | | new ObjectMatcherRulePlugin("assert", "attributes", (value) => { |
| | | if (value) { |
| | | return ( |
| | |
| | | |
| | | /** @typedef {import("./css/CssParser")} CssParser */ |
| | | /** @typedef {import("../declarations/WebpackOptions").CssParserOptions} CssParserOptions */ |
| | | /** @typedef {import("../declarations/WebpackOptions").CssAutoParserOptions} CssAutoParserOptions */ |
| | | /** @typedef {import("../declarations/WebpackOptions").CssGlobalParserOptions} CssGlobalParserOptions */ |
| | | /** @typedef {import("../declarations/WebpackOptions").CssModuleParserOptions} CssModuleParserOptions */ |
| | | /** @typedef {import("./css/CssGenerator")} CssGenerator */ |
| | | /** @typedef {import("../declarations/WebpackOptions").CssGeneratorOptions} CssGeneratorOptions */ |
| | | /** @typedef {import("../declarations/WebpackOptions").CssGlobalGeneratorOptions} CssGlobalGeneratorOptions */ |
| | | /** @typedef {import("../declarations/WebpackOptions").CssModuleGeneratorOptions} CssModuleGeneratorOptions */ |
| | | /** @typedef {import("../declarations/WebpackOptions").CssAutoGeneratorOptions} CssAutoGeneratorOptions */ |
| | | |
| | | /* eslint-disable jsdoc/type-formatting */ |
| | | /** |
| | | * Defines the shared type used by this module. |
| | | * @typedef {[ |
| | | * [JAVASCRIPT_MODULE_TYPE_AUTO, JavascriptParser, JavascriptParserOptions, JavascriptGenerator, EmptyGeneratorOptions], |
| | | * [JAVASCRIPT_MODULE_TYPE_DYNAMIC, JavascriptParser, JavascriptParserOptions, JavascriptGenerator, EmptyGeneratorOptions], |
| | |
| | | * [WEBASSEMBLY_MODULE_TYPE_ASYNC, AsyncWebAssemblyParser, EmptyParserOptions, Generator, EmptyParserOptions], |
| | | * [WEBASSEMBLY_MODULE_TYPE_SYNC, WebAssemblyParser, EmptyParserOptions, Generator, EmptyParserOptions], |
| | | * [CSS_MODULE_TYPE, CssParser, CssParserOptions, CssGenerator, CssGeneratorOptions], |
| | | * [CSS_MODULE_TYPE_AUTO, CssParser, CssAutoParserOptions, CssGenerator, CssAutoGeneratorOptions], |
| | | * [CSS_MODULE_TYPE_AUTO, CssParser, CssModuleParserOptions, CssGenerator, CssModuleGeneratorOptions], |
| | | * [CSS_MODULE_TYPE_MODULE, CssParser, CssModuleParserOptions, CssGenerator, CssModuleGeneratorOptions], |
| | | * [CSS_MODULE_TYPE_GLOBAL, CssParser, CssGlobalParserOptions, CssGenerator, CssGlobalGeneratorOptions], |
| | | * [CSS_MODULE_TYPE_GLOBAL, CssParser, CssModuleParserOptions, CssGenerator, CssModuleGeneratorOptions], |
| | | * [string, Parser, ParserOptions, Generator, GeneratorOptions], |
| | | * ]} ParsersAndGeneratorsByTypes |
| | | */ |
| | | /* eslint-enable jsdoc/type-formatting */ |
| | | |
| | | /** |
| | | * Defines the extract tuple elements type used by this module. |
| | | * @template {unknown[]} T |
| | | * @template {number[]} I |
| | | * @typedef {{ [K in keyof I]: K extends keyof I ? I[K] extends keyof T ? T[I[K]] : never : never }} ExtractTupleElements |
| | | */ |
| | | |
| | | /** |
| | | * Represents the normal module factory runtime component. |
| | | * @template {unknown[]} T |
| | | * @template {number[]} A |
| | | * @template [R=void] |
| | |
| | | |
| | | class NormalModuleFactory extends ModuleFactory { |
| | | /** |
| | | * Creates an instance of NormalModuleFactory. |
| | | * @param {object} param params |
| | | * @param {string=} param.context context |
| | | * @param {InputFileSystem} param.fs file system |
| | |
| | | () => new SyncBailHook(["createData", "resolveData"]) |
| | | ) |
| | | }); |
| | | /** @type {ResolverFactory} */ |
| | | this.resolverFactory = resolverFactory; |
| | | /** @type {RuleSet} */ |
| | | this.ruleSet = ruleSetCompiler.compile([ |
| | | { |
| | | rules: /** @type {RuleSetRules} */ (options.defaultRules) |
| | |
| | | rules: /** @type {RuleSetRules} */ (options.rules) |
| | | } |
| | | ]); |
| | | /** @type {string} */ |
| | | this.context = context || ""; |
| | | /** @type {InputFileSystem} */ |
| | | this.fs = fs; |
| | | this._globalParserOptions = options.parser; |
| | | this._globalGeneratorOptions = options.generator; |
| | |
| | | dependencies, |
| | | dependencyType, |
| | | request, |
| | | phase, |
| | | attributes, |
| | | resolveOptions, |
| | | fileDependencies, |
| | |
| | | const useLoadersPre = []; |
| | | |
| | | // handle .webpack[] suffix |
| | | /** @type {string} */ |
| | | let resource; |
| | | /** @type {RegExpExecArray | null} */ |
| | | let match; |
| | | if ( |
| | | matchResourceData && |
| | |
| | | } else { |
| | | settings.type = JAVASCRIPT_MODULE_TYPE_AUTO; |
| | | const resourceDataForRules = matchResourceData || resourceData; |
| | | |
| | | const result = this.ruleSet.exec({ |
| | | resource: resourceDataForRules.path, |
| | | realResource: resourceData.path, |
| | | resourceQuery: resourceDataForRules.query, |
| | | resourceFragment: resourceDataForRules.fragment, |
| | | scheme, |
| | | phase, |
| | | attributes, |
| | | mimetype: matchResourceData |
| | | ? "" |
| | |
| | | ); |
| | | |
| | | /** |
| | | * Processes the provided string. |
| | | * @param {string} context context |
| | | */ |
| | | const defaultResolve = (context) => { |
| | | if (/^($|\?)/.test(unresolvedResource)) { |
| | | if (/^(?:$|\?)/.test(unresolvedResource)) { |
| | | resourceData = { |
| | | ...cacheParseResource(unresolvedResource), |
| | | resource: unresolvedResource, |
| | |
| | | } |
| | | |
| | | /** |
| | | * Processes the provided data. |
| | | * @param {ModuleFactoryCreateData} data data object |
| | | * @param {ModuleFactoryCallback} callback callback |
| | | * @returns {void} |
| | |
| | | const attributes = |
| | | /** @type {ModuleDependency & { attributes: ImportAttributes }} */ |
| | | (dependency).attributes; |
| | | const phase = |
| | | typeof ( |
| | | /** @type {ModuleDependency & { phase?: ImportPhaseType }} */ |
| | | (dependency).phase |
| | | ) === "number" |
| | | ? ImportPhaseUtils.stringify( |
| | | /** @type {ModuleDependency & { phase?: ImportPhaseType }} */ |
| | | (dependency).phase |
| | | ) |
| | | : "evaluation"; |
| | | const dependencyType = dependency.category || ""; |
| | | const contextInfo = data.contextInfo; |
| | | /** @type {FileSystemDependencies} */ |
| | | const fileDependencies = new LazySet(); |
| | | /** @type {FileSystemDependencies} */ |
| | | const missingDependencies = new LazySet(); |
| | | /** @type {FileSystemDependencies} */ |
| | | const contextDependencies = new LazySet(); |
| | | /** @type {ResolveData} */ |
| | | const resolveData = { |
| | |
| | | resolveOptions, |
| | | context, |
| | | request, |
| | | phase, |
| | | attributes, |
| | | dependencies, |
| | | dependencyType, |
| | |
| | | } |
| | | |
| | | /** |
| | | * Processes the provided context info. |
| | | * @param {ModuleFactoryCreateDataContextInfo} contextInfo context info |
| | | * @param {string} context context |
| | | * @param {string} unresolvedResource unresolved resource |
| | |
| | | } |
| | | |
| | | /** |
| | | * Resolve resource error hints. |
| | | * @param {Error} error error |
| | | * @param {ModuleFactoryCreateDataContextInfo} contextInfo context info |
| | | * @param {string} context context |
| | |
| | | (err, resolvedResource) => { |
| | | if (!err && resolvedResource) { |
| | | let hint = ""; |
| | | const match = /(\.[^.]+)(\?|$)/.exec(unresolvedResource); |
| | | const match = /\.[^.]+(?:\?|$)/.exec(unresolvedResource); |
| | | if (match) { |
| | | const fixedRequest = unresolvedResource.replace( |
| | | /(\.[^.]+)(\?|$)/, |
| | |
| | | } |
| | | |
| | | /** |
| | | * Resolves request array. |
| | | * @param {ModuleFactoryCreateDataContextInfo} contextInfo context info |
| | | * @param {string} context context |
| | | * @param {LoaderItem[]} array array |
| | |
| | | asyncLib.map( |
| | | array, |
| | | /** |
| | | * Handles the callback logic for this hook. |
| | | * @param {LoaderItem} item item |
| | | * @param {Callback<LoaderItem>} callback callback |
| | | */ |
| | |
| | | ); |
| | | }, |
| | | (err, value) => { |
| | | callback(err, /** @type {(LoaderItem)[]} */ (value)); |
| | | callback( |
| | | /** @type {Error | null} */ (err), |
| | | /** @type {(LoaderItem)[]} */ (value) |
| | | ); |
| | | } |
| | | ); |
| | | } |
| | | |
| | | /** |
| | | * Returns parser. |
| | | * @param {string} type type |
| | | * @param {ParserOptions} parserOptions parser options |
| | | * @returns {Parser} parser |
| | |
| | | } |
| | | |
| | | /** |
| | | * Creates a parser from the provided type. |
| | | * @param {string} type type |
| | | * @param {ParserOptions} parserOptions parser options |
| | | * @returns {Parser} parser |
| | |
| | | } |
| | | |
| | | /** |
| | | * Returns generator. |
| | | * @param {string} type type of generator |
| | | * @param {GeneratorOptions} generatorOptions generator options |
| | | * @returns {Generator} generator |
| | |
| | | } |
| | | |
| | | /** |
| | | * Creates a generator. |
| | | * @param {string} type type of generator |
| | | * @param {GeneratorOptions} generatorOptions generator options |
| | | * @returns {Generator} generator |
| | |
| | | } |
| | | |
| | | /** |
| | | * Returns the resolver. |
| | | * @param {Parameters<ResolverFactory["get"]>[0]} type type of resolver |
| | | * @param {Parameters<ResolverFactory["get"]>[1]=} resolveOptions options |
| | | * @returns {ReturnType<ResolverFactory["get"]>} the resolver |