| 1 | /*
|
|---|
| 2 | MIT License http://www.opensource.org/licenses/mit-license.php
|
|---|
| 3 | Author Tobias Koppers @sokra
|
|---|
| 4 | */
|
|---|
| 5 |
|
|---|
| 6 | "use strict";
|
|---|
| 7 |
|
|---|
| 8 | const util = require("util");
|
|---|
| 9 | const ChunkGraph = require("./ChunkGraph");
|
|---|
| 10 | const DependenciesBlock = require("./DependenciesBlock");
|
|---|
| 11 | const ModuleGraph = require("./ModuleGraph");
|
|---|
| 12 | const {
|
|---|
| 13 | JAVASCRIPT_TYPE,
|
|---|
| 14 | UNKNOWN_TYPE
|
|---|
| 15 | } = require("./ModuleSourceTypeConstants");
|
|---|
| 16 | const { JAVASCRIPT_TYPES } = require("./ModuleSourceTypeConstants");
|
|---|
| 17 | const RuntimeGlobals = require("./RuntimeGlobals");
|
|---|
| 18 | const { first } = require("./util/SetHelpers");
|
|---|
| 19 | const { compareChunksById } = require("./util/comparators");
|
|---|
| 20 | const makeSerializable = require("./util/makeSerializable");
|
|---|
| 21 |
|
|---|
| 22 | /** @typedef {import("webpack-sources").Source} Source */
|
|---|
| 23 | /** @typedef {import("../declarations/WebpackOptions").ResolveOptions} ResolveOptions */
|
|---|
| 24 | /** @typedef {import("./config/defaults").WebpackOptionsNormalizedWithDefaults} WebpackOptions */
|
|---|
| 25 | /** @typedef {import("./Chunk")} Chunk */
|
|---|
| 26 | /** @typedef {import("./ChunkGraph").ModuleId} ModuleId */
|
|---|
| 27 | /** @typedef {import("./ChunkGroup")} ChunkGroup */
|
|---|
| 28 | /** @typedef {import("./CodeGenerationResults")} CodeGenerationResults */
|
|---|
| 29 | /** @typedef {import("./Compilation")} Compilation */
|
|---|
| 30 | /** @typedef {import("./Compilation").AssetInfo} AssetInfo */
|
|---|
| 31 | /** @typedef {import("./Compilation").FileSystemDependencies} FileSystemDependencies */
|
|---|
| 32 | /** @typedef {import("./Compilation").UnsafeCacheData} UnsafeCacheData */
|
|---|
| 33 | /** @typedef {import("./ConcatenationScope")} ConcatenationScope */
|
|---|
| 34 | /** @typedef {import("./Dependency")} Dependency */
|
|---|
| 35 | /** @typedef {import("./Dependency").UpdateHashContext} UpdateHashContext */
|
|---|
| 36 | /** @typedef {import("./DependencyTemplate").CssData} CssData */
|
|---|
| 37 | /** @typedef {import("./DependencyTemplates")} DependencyTemplates */
|
|---|
| 38 | /** @typedef {import("./ModuleSourceTypeConstants").AllTypes} AllTypes */
|
|---|
| 39 | /** @typedef {import("./FileSystemInfo")} FileSystemInfo */
|
|---|
| 40 | /** @typedef {import("./FileSystemInfo").Snapshot} Snapshot */
|
|---|
| 41 | /** @typedef {import("./ModuleGraphConnection").ConnectionState} ConnectionState */
|
|---|
| 42 | /** @typedef {import("./ModuleTypeConstants").ModuleTypes} ModuleTypes */
|
|---|
| 43 | /** @typedef {import("./ModuleGraph").OptimizationBailouts} OptimizationBailouts */
|
|---|
| 44 | /** @typedef {import("./ModuleProfile")} ModuleProfile */
|
|---|
| 45 | /** @typedef {import("./NormalModuleFactory")} NormalModuleFactory */
|
|---|
| 46 | /** @typedef {import("./RequestShortener")} RequestShortener */
|
|---|
| 47 | /** @typedef {import("./ResolverFactory").ResolverWithOptions} ResolverWithOptions */
|
|---|
| 48 | /** @typedef {import("./RuntimeTemplate")} RuntimeTemplate */
|
|---|
| 49 | /**
|
|---|
| 50 | * Defines the init fragment type used by this module.
|
|---|
| 51 | * @template T
|
|---|
| 52 | * @typedef {import("./InitFragment")<T>} InitFragment
|
|---|
| 53 | */
|
|---|
| 54 | /** @typedef {import("./errors/WebpackError")} WebpackError */
|
|---|
| 55 | /** @typedef {import("./json/JsonData")} JsonData */
|
|---|
| 56 | /** @typedef {import("./serialization/ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */
|
|---|
| 57 | /** @typedef {import("./serialization/ObjectMiddleware").ObjectSerializerContext} ObjectSerializerContext */
|
|---|
| 58 | /** @typedef {import("./util/Hash")} Hash */
|
|---|
| 59 | /** @typedef {import("./util/fs").InputFileSystem} InputFileSystem */
|
|---|
| 60 | /** @typedef {import("./util/identifier").AssociatedObjectForCache} AssociatedObjectForCache */
|
|---|
| 61 | /** @typedef {import("./util/runtime").RuntimeSpec} RuntimeSpec */
|
|---|
| 62 | /**
|
|---|
| 63 | * @template T
|
|---|
| 64 | * @typedef {import("./util/SortableSet")<T>} SortableSet
|
|---|
| 65 | */
|
|---|
| 66 | /** @typedef {"namespace" | "default-only" | "default-with-named" | "dynamic"} ExportsType */
|
|---|
| 67 |
|
|---|
| 68 | /**
|
|---|
| 69 | * Defines the shared type used by this module.
|
|---|
| 70 | * @template T
|
|---|
| 71 | * @typedef {import("./util/LazySet")<T>} LazySet<T>
|
|---|
| 72 | */
|
|---|
| 73 |
|
|---|
| 74 | /**
|
|---|
| 75 | * Defines the source context type used by this module.
|
|---|
| 76 | * @typedef {object} SourceContext
|
|---|
| 77 | * @property {DependencyTemplates} dependencyTemplates the dependency templates
|
|---|
| 78 | * @property {RuntimeTemplate} runtimeTemplate the runtime template
|
|---|
| 79 | * @property {ModuleGraph} moduleGraph the module graph
|
|---|
| 80 | * @property {ChunkGraph} chunkGraph the chunk graph
|
|---|
| 81 | * @property {RuntimeSpec} runtime the runtimes code should be generated for
|
|---|
| 82 | * @property {string=} type the type of source that should be generated
|
|---|
| 83 | */
|
|---|
| 84 |
|
|---|
| 85 | /** @typedef {AllTypes} KnownSourceType */
|
|---|
| 86 | /** @typedef {KnownSourceType | string} SourceType */
|
|---|
| 87 | /** @typedef {ReadonlySet<SourceType>} SourceTypes */
|
|---|
| 88 |
|
|---|
| 89 | /** @typedef {ReadonlySet<typeof JAVASCRIPT_TYPE | string>} BasicSourceTypes */
|
|---|
| 90 |
|
|---|
| 91 | // TODO webpack 6: compilation will be required in CodeGenerationContext
|
|---|
| 92 | /**
|
|---|
| 93 | * Defines the code generation context type used by this module.
|
|---|
| 94 | * @typedef {object} CodeGenerationContext
|
|---|
| 95 | * @property {DependencyTemplates} dependencyTemplates the dependency templates
|
|---|
| 96 | * @property {RuntimeTemplate} runtimeTemplate the runtime template
|
|---|
| 97 | * @property {ModuleGraph} moduleGraph the module graph
|
|---|
| 98 | * @property {ChunkGraph} chunkGraph the chunk graph
|
|---|
| 99 | * @property {RuntimeSpec} runtime the runtimes code should be generated for
|
|---|
| 100 | * @property {RuntimeSpec[]} runtimes all runtimes code should be generated for
|
|---|
| 101 | * @property {ConcatenationScope=} concatenationScope when in concatenated module, information about other concatenated modules
|
|---|
| 102 | * @property {CodeGenerationResults | undefined} codeGenerationResults code generation results of other modules (need to have a codeGenerationDependency to use that)
|
|---|
| 103 | * @property {Compilation=} compilation the compilation
|
|---|
| 104 | * @property {SourceTypes=} sourceTypes source types
|
|---|
| 105 | */
|
|---|
| 106 |
|
|---|
| 107 | /**
|
|---|
| 108 | * Defines the concatenation bailout reason context type used by this module.
|
|---|
| 109 | * @typedef {object} ConcatenationBailoutReasonContext
|
|---|
| 110 | * @property {ModuleGraph} moduleGraph the module graph
|
|---|
| 111 | * @property {ChunkGraph} chunkGraph the chunk graph
|
|---|
| 112 | */
|
|---|
| 113 |
|
|---|
| 114 | /** @typedef {Set<string>} RuntimeRequirements */
|
|---|
| 115 | /** @typedef {ReadonlySet<string>} ReadOnlyRuntimeRequirements */
|
|---|
| 116 |
|
|---|
| 117 | /**
|
|---|
| 118 | * Defines the all code generation schemas type used by this module.
|
|---|
| 119 | * @typedef {object} AllCodeGenerationSchemas
|
|---|
| 120 | * @property {Set<string>} topLevelDeclarations top level declarations for javascript modules
|
|---|
| 121 | * @property {InitFragment<EXPECTED_ANY>[]} chunkInitFragments chunk init fragments for javascript modules
|
|---|
| 122 | * @property {{ javascript?: string, ["asset-url"]?: string }} url url for asset modules
|
|---|
| 123 | * @property {string} filename a filename for asset modules
|
|---|
| 124 | * @property {AssetInfo} assetInfo an asset info for asset modules
|
|---|
| 125 | * @property {string} fullContentHash a full content hash for asset modules
|
|---|
| 126 | * @property {[{ shareScope: string, initStage: number, init: string }]} share-init share-init for modules federation
|
|---|
| 127 | */
|
|---|
| 128 |
|
|---|
| 129 | /**
|
|---|
| 130 | * Defines the code gen value type used by this module.
|
|---|
| 131 | * @template {string} K
|
|---|
| 132 | * @typedef {K extends (keyof AllCodeGenerationSchemas) ? AllCodeGenerationSchemas[K] : EXPECTED_ANY} CodeGenValue
|
|---|
| 133 | */
|
|---|
| 134 |
|
|---|
| 135 | /**
|
|---|
| 136 | * Defines the code gen map overloads type used by this module.
|
|---|
| 137 | * @typedef {object} CodeGenMapOverloads
|
|---|
| 138 | * @property {<K extends string>(key: K) => CodeGenValue<K> | undefined} get
|
|---|
| 139 | * @property {<K extends string>(key: K, value: CodeGenValue<K>) => CodeGenerationResultData} set
|
|---|
| 140 | * @property {<K extends string>(key: K) => boolean} has
|
|---|
| 141 | * @property {<K extends string>(key: K) => boolean} delete
|
|---|
| 142 | */
|
|---|
| 143 |
|
|---|
| 144 | /**
|
|---|
| 145 | * Defines the code generation result data type used by this module.
|
|---|
| 146 | * @typedef {Omit<Map<string, EXPECTED_ANY>, "get" | "set" | "has" | "delete"> & CodeGenMapOverloads} CodeGenerationResultData
|
|---|
| 147 | */
|
|---|
| 148 |
|
|---|
| 149 | /** @typedef {Map<SourceType, Source>} Sources */
|
|---|
| 150 |
|
|---|
| 151 | /**
|
|---|
| 152 | * Defines the code generation result type used by this module.
|
|---|
| 153 | * @typedef {object} CodeGenerationResult
|
|---|
| 154 | * @property {Sources} sources the resulting sources for all source types
|
|---|
| 155 | * @property {CodeGenerationResultData=} data the resulting data for all source types
|
|---|
| 156 | * @property {ReadOnlyRuntimeRequirements | null} runtimeRequirements the runtime requirements
|
|---|
| 157 | * @property {string=} hash a hash of the code generation result (will be automatically calculated from sources and runtimeRequirements if not provided)
|
|---|
| 158 | */
|
|---|
| 159 |
|
|---|
| 160 | /**
|
|---|
| 161 | * Defines the lib ident options type used by this module.
|
|---|
| 162 | * @typedef {object} LibIdentOptions
|
|---|
| 163 | * @property {string} context absolute context path to which lib ident is relative to
|
|---|
| 164 | * @property {AssociatedObjectForCache=} associatedObjectForCache object for caching
|
|---|
| 165 | */
|
|---|
| 166 |
|
|---|
| 167 | /**
|
|---|
| 168 | * Defines the known build meta type used by this module.
|
|---|
| 169 | * @typedef {object} KnownBuildMeta
|
|---|
| 170 | * @property {("default" | "namespace" | "flagged" | "dynamic")=} exportsType
|
|---|
| 171 | * @property {(false | "redirect" | "redirect-warn")=} defaultObject
|
|---|
| 172 | * @property {boolean=} strictHarmonyModule
|
|---|
| 173 | * @property {boolean=} treatAsCommonJs
|
|---|
| 174 | * @property {boolean=} async
|
|---|
| 175 | * @property {boolean=} sideEffectFree
|
|---|
| 176 | * @property {boolean=} isCssModule
|
|---|
| 177 | * @property {boolean=} needIdInConcatenation
|
|---|
| 178 | * @property {Record<string, string>=} jsIncompatibleExports
|
|---|
| 179 | * @property {Map<string, Record<string, string>>=} exportsFinalNameByRuntime
|
|---|
| 180 | * @property {Map<string, string>=} exportsSourceByRuntime
|
|---|
| 181 | */
|
|---|
| 182 |
|
|---|
| 183 | /**
|
|---|
| 184 | * Defines the known build info type used by this module.
|
|---|
| 185 | * @typedef {object} KnownBuildInfo
|
|---|
| 186 | * @property {boolean=} cacheable
|
|---|
| 187 | * @property {boolean=} parsed
|
|---|
| 188 | * @property {boolean=} strict
|
|---|
| 189 | * @property {string=} moduleArgument using in AMD
|
|---|
| 190 | * @property {string=} exportsArgument using in AMD
|
|---|
| 191 | * @property {string=} moduleConcatenationBailout using in CommonJs
|
|---|
| 192 | * @property {boolean=} needCreateRequire using in APIPlugin
|
|---|
| 193 | * @property {string=} resourceIntegrity using in HttpUriPlugin
|
|---|
| 194 | * @property {FileSystemDependencies=} fileDependencies using in NormalModule
|
|---|
| 195 | * @property {FileSystemDependencies=} contextDependencies using in NormalModule
|
|---|
| 196 | * @property {FileSystemDependencies=} missingDependencies using in NormalModule
|
|---|
| 197 | * @property {FileSystemDependencies=} buildDependencies using in NormalModule
|
|---|
| 198 | * @property {ValueCacheVersions=} valueDependencies using in NormalModule
|
|---|
| 199 | * @property {Record<string, Source>=} assets using in NormalModule
|
|---|
| 200 | * @property {Map<string, AssetInfo | undefined>=} assetsInfo using in NormalModule
|
|---|
| 201 | * @property {string=} hash using in NormalModule
|
|---|
| 202 | * @property {(Snapshot | null)=} snapshot using in ContextModule
|
|---|
| 203 | * @property {string=} fullContentHash for assets modules
|
|---|
| 204 | * @property {string=} filename for assets modules
|
|---|
| 205 | * @property {boolean=} dataUrl for assets modules
|
|---|
| 206 | * @property {AssetInfo=} assetInfo for assets modules
|
|---|
| 207 | * @property {boolean=} javascriptModule for external modules
|
|---|
| 208 | * @property {boolean=} active for lazy compilation modules
|
|---|
| 209 | * @property {CssData=} cssData for css modules
|
|---|
| 210 | * @property {string=} charset for css modules (charset at-rule)
|
|---|
| 211 | * @property {JsonData=} jsonData for json modules
|
|---|
| 212 | * @property {Set<string>=} topLevelDeclarations top level declaration names
|
|---|
| 213 | */
|
|---|
| 214 |
|
|---|
| 215 | /** @typedef {string | Set<string>} ValueCacheVersion */
|
|---|
| 216 | /** @typedef {Map<string, ValueCacheVersion>} ValueCacheVersions */
|
|---|
| 217 |
|
|---|
| 218 | /**
|
|---|
| 219 | * Defines the need build context type used by this module.
|
|---|
| 220 | * @typedef {object} NeedBuildContext
|
|---|
| 221 | * @property {Compilation} compilation
|
|---|
| 222 | * @property {FileSystemInfo} fileSystemInfo
|
|---|
| 223 | * @property {ValueCacheVersions} valueCacheVersions
|
|---|
| 224 | */
|
|---|
| 225 |
|
|---|
| 226 | /** @typedef {(err?: WebpackError | null, needBuild?: boolean) => void} NeedBuildCallback */
|
|---|
| 227 |
|
|---|
| 228 | /** @typedef {(err?: WebpackError) => void} BuildCallback */
|
|---|
| 229 |
|
|---|
| 230 | /** @typedef {KnownBuildMeta & Record<string, EXPECTED_ANY>} BuildMeta */
|
|---|
| 231 | /** @typedef {KnownBuildInfo & Record<string, EXPECTED_ANY>} BuildInfo */
|
|---|
| 232 |
|
|---|
| 233 | /**
|
|---|
| 234 | * Defines the factory meta type used by this module.
|
|---|
| 235 | * @typedef {object} FactoryMeta
|
|---|
| 236 | * @property {boolean=} sideEffectFree
|
|---|
| 237 | */
|
|---|
| 238 |
|
|---|
| 239 | const EMPTY_RESOLVE_OPTIONS = {};
|
|---|
| 240 |
|
|---|
| 241 | let debugId = 1000;
|
|---|
| 242 |
|
|---|
| 243 | /** @type {SourceTypes} */
|
|---|
| 244 | const DEFAULT_TYPES_UNKNOWN = new Set([UNKNOWN_TYPE]);
|
|---|
| 245 |
|
|---|
| 246 | const deprecatedNeedRebuild = util.deprecate(
|
|---|
| 247 | /**
|
|---|
| 248 | * Handles the callback logic for this hook.
|
|---|
| 249 | * @param {Module} module the module
|
|---|
| 250 | * @param {NeedBuildContext} context context info
|
|---|
| 251 | * @returns {boolean} true, when rebuild is needed
|
|---|
| 252 | */
|
|---|
| 253 | (module, context) =>
|
|---|
| 254 | module.needRebuild(
|
|---|
| 255 | context.fileSystemInfo.getDeprecatedFileTimestamps(),
|
|---|
| 256 | context.fileSystemInfo.getDeprecatedContextTimestamps()
|
|---|
| 257 | ),
|
|---|
| 258 | "Module.needRebuild is deprecated in favor of Module.needBuild",
|
|---|
| 259 | "DEP_WEBPACK_MODULE_NEED_REBUILD"
|
|---|
| 260 | );
|
|---|
| 261 |
|
|---|
| 262 | /** @typedef {string} LibIdent */
|
|---|
| 263 | /** @typedef {string} NameForCondition */
|
|---|
| 264 |
|
|---|
| 265 | /** @typedef {(requestShortener: RequestShortener) => string} OptimizationBailoutFunction */
|
|---|
| 266 |
|
|---|
| 267 | class Module extends DependenciesBlock {
|
|---|
| 268 | /**
|
|---|
| 269 | * Creates an instance of Module.
|
|---|
| 270 | * @param {ModuleTypes | ""} type the module type, when deserializing the type is not known and is an empty string
|
|---|
| 271 | * @param {(string | null)=} context an optional context
|
|---|
| 272 | * @param {(string | null)=} layer an optional layer in which the module is
|
|---|
| 273 | */
|
|---|
| 274 | constructor(type, context = null, layer = null) {
|
|---|
| 275 | super();
|
|---|
| 276 |
|
|---|
| 277 | /** @type {ModuleTypes} */
|
|---|
| 278 | this.type = type;
|
|---|
| 279 | /** @type {string | null} */
|
|---|
| 280 | this.context = context;
|
|---|
| 281 | /** @type {string | null} */
|
|---|
| 282 | this.layer = layer;
|
|---|
| 283 | /** @type {boolean} */
|
|---|
| 284 | this.needId = true;
|
|---|
| 285 |
|
|---|
| 286 | // Unique Id
|
|---|
| 287 | /** @type {number} */
|
|---|
| 288 | this.debugId = debugId++;
|
|---|
| 289 |
|
|---|
| 290 | // Info from Factory
|
|---|
| 291 | /** @type {ResolveOptions | undefined} */
|
|---|
| 292 | this.resolveOptions = EMPTY_RESOLVE_OPTIONS;
|
|---|
| 293 | /** @type {FactoryMeta | undefined} */
|
|---|
| 294 | this.factoryMeta = undefined;
|
|---|
| 295 | // TODO refactor this -> options object filled from Factory
|
|---|
| 296 | // TODO webpack 6: use an enum
|
|---|
| 297 | /** @type {boolean} */
|
|---|
| 298 | this.useSourceMap = false;
|
|---|
| 299 | /** @type {boolean} */
|
|---|
| 300 | this.useSimpleSourceMap = false;
|
|---|
| 301 |
|
|---|
| 302 | // Is in hot context, i.e. HotModuleReplacementPlugin.js enabled
|
|---|
| 303 | // TODO do we need hot here?
|
|---|
| 304 | /** @type {boolean} */
|
|---|
| 305 | this.hot = false;
|
|---|
| 306 | // Info from Build
|
|---|
| 307 | /** @type {Error[] | undefined} */
|
|---|
| 308 | this._warnings = undefined;
|
|---|
| 309 | /** @type {Error[] | undefined} */
|
|---|
| 310 | this._errors = undefined;
|
|---|
| 311 | /** @type {BuildMeta | undefined} */
|
|---|
| 312 | this.buildMeta = undefined;
|
|---|
| 313 | /** @type {BuildInfo | undefined} */
|
|---|
| 314 | this.buildInfo = undefined;
|
|---|
| 315 | /** @type {Dependency[] | undefined} */
|
|---|
| 316 | this.presentationalDependencies = undefined;
|
|---|
| 317 | /** @type {Dependency[] | undefined} */
|
|---|
| 318 | this.codeGenerationDependencies = undefined;
|
|---|
| 319 | }
|
|---|
| 320 |
|
|---|
| 321 | // TODO remove in webpack 6
|
|---|
| 322 | // BACKWARD-COMPAT START
|
|---|
| 323 | /**
|
|---|
| 324 | * Returns the module id assigned by the chunk graph.
|
|---|
| 325 | * @deprecated
|
|---|
| 326 | * @returns {ModuleId | null} module id
|
|---|
| 327 | */
|
|---|
| 328 | get id() {
|
|---|
| 329 | return ChunkGraph.getChunkGraphForModule(
|
|---|
| 330 | this,
|
|---|
| 331 | "Module.id",
|
|---|
| 332 | "DEP_WEBPACK_MODULE_ID"
|
|---|
| 333 | ).getModuleId(this);
|
|---|
| 334 | }
|
|---|
| 335 |
|
|---|
| 336 | /**
|
|---|
| 337 | * Updates the module id using the provided value.
|
|---|
| 338 | * @deprecated
|
|---|
| 339 | * @param {ModuleId} value value
|
|---|
| 340 | */
|
|---|
| 341 | set id(value) {
|
|---|
| 342 | if (value === "") {
|
|---|
| 343 | this.needId = false;
|
|---|
| 344 | return;
|
|---|
| 345 | }
|
|---|
| 346 | ChunkGraph.getChunkGraphForModule(
|
|---|
| 347 | this,
|
|---|
| 348 | "Module.id",
|
|---|
| 349 | "DEP_WEBPACK_MODULE_ID"
|
|---|
| 350 | ).setModuleId(this, value);
|
|---|
| 351 | }
|
|---|
| 352 |
|
|---|
| 353 | /**
|
|---|
| 354 | * Returns the hash of the module.
|
|---|
| 355 | * @deprecated
|
|---|
| 356 | * @returns {string} the hash of the module
|
|---|
| 357 | */
|
|---|
| 358 | get hash() {
|
|---|
| 359 | return ChunkGraph.getChunkGraphForModule(
|
|---|
| 360 | this,
|
|---|
| 361 | "Module.hash",
|
|---|
| 362 | "DEP_WEBPACK_MODULE_HASH"
|
|---|
| 363 | ).getModuleHash(this, undefined);
|
|---|
| 364 | }
|
|---|
| 365 |
|
|---|
| 366 | /**
|
|---|
| 367 | * Returns the rendered hash of the module.
|
|---|
| 368 | * @deprecated
|
|---|
| 369 | * @returns {string} the shortened hash of the module
|
|---|
| 370 | */
|
|---|
| 371 | get renderedHash() {
|
|---|
| 372 | return ChunkGraph.getChunkGraphForModule(
|
|---|
| 373 | this,
|
|---|
| 374 | "Module.renderedHash",
|
|---|
| 375 | "DEP_WEBPACK_MODULE_RENDERED_HASH"
|
|---|
| 376 | ).getRenderedModuleHash(this, undefined);
|
|---|
| 377 | }
|
|---|
| 378 |
|
|---|
| 379 | /**
|
|---|
| 380 | * @deprecated
|
|---|
| 381 | * @returns {ModuleProfile | undefined} module profile
|
|---|
| 382 | */
|
|---|
| 383 | get profile() {
|
|---|
| 384 | return ModuleGraph.getModuleGraphForModule(
|
|---|
| 385 | this,
|
|---|
| 386 | "Module.profile",
|
|---|
| 387 | "DEP_WEBPACK_MODULE_PROFILE"
|
|---|
| 388 | ).getProfile(this);
|
|---|
| 389 | }
|
|---|
| 390 |
|
|---|
| 391 | /**
|
|---|
| 392 | * @deprecated
|
|---|
| 393 | * @param {ModuleProfile | undefined} value module profile
|
|---|
| 394 | */
|
|---|
| 395 | set profile(value) {
|
|---|
| 396 | ModuleGraph.getModuleGraphForModule(
|
|---|
| 397 | this,
|
|---|
| 398 | "Module.profile",
|
|---|
| 399 | "DEP_WEBPACK_MODULE_PROFILE"
|
|---|
| 400 | ).setProfile(this, value);
|
|---|
| 401 | }
|
|---|
| 402 |
|
|---|
| 403 | /**
|
|---|
| 404 | * Returns the pre-order index.
|
|---|
| 405 | * @deprecated
|
|---|
| 406 | * @returns {number | null} the pre order index
|
|---|
| 407 | */
|
|---|
| 408 | get index() {
|
|---|
| 409 | return ModuleGraph.getModuleGraphForModule(
|
|---|
| 410 | this,
|
|---|
| 411 | "Module.index",
|
|---|
| 412 | "DEP_WEBPACK_MODULE_INDEX"
|
|---|
| 413 | ).getPreOrderIndex(this);
|
|---|
| 414 | }
|
|---|
| 415 |
|
|---|
| 416 | /**
|
|---|
| 417 | * Updates the pre-order index using the provided value.
|
|---|
| 418 | * @deprecated
|
|---|
| 419 | * @param {number} value the pre order index
|
|---|
| 420 | */
|
|---|
| 421 | set index(value) {
|
|---|
| 422 | ModuleGraph.getModuleGraphForModule(
|
|---|
| 423 | this,
|
|---|
| 424 | "Module.index",
|
|---|
| 425 | "DEP_WEBPACK_MODULE_INDEX"
|
|---|
| 426 | ).setPreOrderIndex(this, value);
|
|---|
| 427 | }
|
|---|
| 428 |
|
|---|
| 429 | /**
|
|---|
| 430 | * Returns the post-order index.
|
|---|
| 431 | * @deprecated
|
|---|
| 432 | * @returns {number | null} the post order index
|
|---|
| 433 | */
|
|---|
| 434 | get index2() {
|
|---|
| 435 | return ModuleGraph.getModuleGraphForModule(
|
|---|
| 436 | this,
|
|---|
| 437 | "Module.index2",
|
|---|
| 438 | "DEP_WEBPACK_MODULE_INDEX2"
|
|---|
| 439 | ).getPostOrderIndex(this);
|
|---|
| 440 | }
|
|---|
| 441 |
|
|---|
| 442 | /**
|
|---|
| 443 | * Updates the post-order index using the provided value.
|
|---|
| 444 | * @deprecated
|
|---|
| 445 | * @param {number} value the post order index
|
|---|
| 446 | */
|
|---|
| 447 | set index2(value) {
|
|---|
| 448 | ModuleGraph.getModuleGraphForModule(
|
|---|
| 449 | this,
|
|---|
| 450 | "Module.index2",
|
|---|
| 451 | "DEP_WEBPACK_MODULE_INDEX2"
|
|---|
| 452 | ).setPostOrderIndex(this, value);
|
|---|
| 453 | }
|
|---|
| 454 |
|
|---|
| 455 | /**
|
|---|
| 456 | * Returns the depth.
|
|---|
| 457 | * @deprecated
|
|---|
| 458 | * @returns {number | null} the depth
|
|---|
| 459 | */
|
|---|
| 460 | get depth() {
|
|---|
| 461 | return ModuleGraph.getModuleGraphForModule(
|
|---|
| 462 | this,
|
|---|
| 463 | "Module.depth",
|
|---|
| 464 | "DEP_WEBPACK_MODULE_DEPTH"
|
|---|
| 465 | ).getDepth(this);
|
|---|
| 466 | }
|
|---|
| 467 |
|
|---|
| 468 | /**
|
|---|
| 469 | * Updates the depth using the provided value.
|
|---|
| 470 | * @deprecated
|
|---|
| 471 | * @param {number} value the depth
|
|---|
| 472 | */
|
|---|
| 473 | set depth(value) {
|
|---|
| 474 | ModuleGraph.getModuleGraphForModule(
|
|---|
| 475 | this,
|
|---|
| 476 | "Module.depth",
|
|---|
| 477 | "DEP_WEBPACK_MODULE_DEPTH"
|
|---|
| 478 | ).setDepth(this, value);
|
|---|
| 479 | }
|
|---|
| 480 |
|
|---|
| 481 | /**
|
|---|
| 482 | * Returns the issuer.
|
|---|
| 483 | * @deprecated
|
|---|
| 484 | * @returns {Module | null | undefined} issuer
|
|---|
| 485 | */
|
|---|
| 486 | get issuer() {
|
|---|
| 487 | return ModuleGraph.getModuleGraphForModule(
|
|---|
| 488 | this,
|
|---|
| 489 | "Module.issuer",
|
|---|
| 490 | "DEP_WEBPACK_MODULE_ISSUER"
|
|---|
| 491 | ).getIssuer(this);
|
|---|
| 492 | }
|
|---|
| 493 |
|
|---|
| 494 | /**
|
|---|
| 495 | * Updates the issuer using the provided value.
|
|---|
| 496 | * @deprecated
|
|---|
| 497 | * @param {Module | null} value issuer
|
|---|
| 498 | */
|
|---|
| 499 | set issuer(value) {
|
|---|
| 500 | ModuleGraph.getModuleGraphForModule(
|
|---|
| 501 | this,
|
|---|
| 502 | "Module.issuer",
|
|---|
| 503 | "DEP_WEBPACK_MODULE_ISSUER"
|
|---|
| 504 | ).setIssuer(this, value);
|
|---|
| 505 | }
|
|---|
| 506 |
|
|---|
| 507 | /**
|
|---|
| 508 | * @deprecated
|
|---|
| 509 | * @returns {boolean | SortableSet<string> | null} used exports
|
|---|
| 510 | */
|
|---|
| 511 | get usedExports() {
|
|---|
| 512 | return ModuleGraph.getModuleGraphForModule(
|
|---|
| 513 | this,
|
|---|
| 514 | "Module.usedExports",
|
|---|
| 515 | "DEP_WEBPACK_MODULE_USED_EXPORTS"
|
|---|
| 516 | ).getUsedExports(this, undefined);
|
|---|
| 517 | }
|
|---|
| 518 |
|
|---|
| 519 | /**
|
|---|
| 520 | * Gets optimization bailout.
|
|---|
| 521 | * @deprecated
|
|---|
| 522 | * @returns {OptimizationBailouts} list
|
|---|
| 523 | */
|
|---|
| 524 | get optimizationBailout() {
|
|---|
| 525 | return ModuleGraph.getModuleGraphForModule(
|
|---|
| 526 | this,
|
|---|
| 527 | "Module.optimizationBailout",
|
|---|
| 528 | "DEP_WEBPACK_MODULE_OPTIMIZATION_BAILOUT"
|
|---|
| 529 | ).getOptimizationBailout(this);
|
|---|
| 530 | }
|
|---|
| 531 |
|
|---|
| 532 | /**
|
|---|
| 533 | * @deprecated
|
|---|
| 534 | * @returns {boolean} true when optional, otherwise false
|
|---|
| 535 | */
|
|---|
| 536 | get optional() {
|
|---|
| 537 | return this.isOptional(
|
|---|
| 538 | ModuleGraph.getModuleGraphForModule(
|
|---|
| 539 | this,
|
|---|
| 540 | "Module.optional",
|
|---|
| 541 | "DEP_WEBPACK_MODULE_OPTIONAL"
|
|---|
| 542 | )
|
|---|
| 543 | );
|
|---|
| 544 | }
|
|---|
| 545 |
|
|---|
| 546 | /**
|
|---|
| 547 | * Adds the provided chunk to the module.
|
|---|
| 548 | * @deprecated
|
|---|
| 549 | * @param {Chunk} chunk the chunk
|
|---|
| 550 | * @returns {boolean} true, when the module was added
|
|---|
| 551 | */
|
|---|
| 552 | addChunk(chunk) {
|
|---|
| 553 | const chunkGraph = ChunkGraph.getChunkGraphForModule(
|
|---|
| 554 | this,
|
|---|
| 555 | "Module.addChunk",
|
|---|
| 556 | "DEP_WEBPACK_MODULE_ADD_CHUNK"
|
|---|
| 557 | );
|
|---|
| 558 | if (chunkGraph.isModuleInChunk(this, chunk)) return false;
|
|---|
| 559 | chunkGraph.connectChunkAndModule(chunk, this);
|
|---|
| 560 | return true;
|
|---|
| 561 | }
|
|---|
| 562 |
|
|---|
| 563 | /**
|
|---|
| 564 | * Removes the provided chunk from the module.
|
|---|
| 565 | * @deprecated
|
|---|
| 566 | * @param {Chunk} chunk the chunk
|
|---|
| 567 | * @returns {void}
|
|---|
| 568 | */
|
|---|
| 569 | removeChunk(chunk) {
|
|---|
| 570 | return ChunkGraph.getChunkGraphForModule(
|
|---|
| 571 | this,
|
|---|
| 572 | "Module.removeChunk",
|
|---|
| 573 | "DEP_WEBPACK_MODULE_REMOVE_CHUNK"
|
|---|
| 574 | ).disconnectChunkAndModule(chunk, this);
|
|---|
| 575 | }
|
|---|
| 576 |
|
|---|
| 577 | /**
|
|---|
| 578 | * Checks whether this module is in the provided chunk.
|
|---|
| 579 | * @deprecated
|
|---|
| 580 | * @param {Chunk} chunk the chunk
|
|---|
| 581 | * @returns {boolean} true, when the module is in the chunk
|
|---|
| 582 | */
|
|---|
| 583 | isInChunk(chunk) {
|
|---|
| 584 | return ChunkGraph.getChunkGraphForModule(
|
|---|
| 585 | this,
|
|---|
| 586 | "Module.isInChunk",
|
|---|
| 587 | "DEP_WEBPACK_MODULE_IS_IN_CHUNK"
|
|---|
| 588 | ).isModuleInChunk(this, chunk);
|
|---|
| 589 | }
|
|---|
| 590 |
|
|---|
| 591 | /**
|
|---|
| 592 | * @deprecated
|
|---|
| 593 | * @returns {boolean} true when is entry module, otherwise false
|
|---|
| 594 | */
|
|---|
| 595 | isEntryModule() {
|
|---|
| 596 | return ChunkGraph.getChunkGraphForModule(
|
|---|
| 597 | this,
|
|---|
| 598 | "Module.isEntryModule",
|
|---|
| 599 | "DEP_WEBPACK_MODULE_IS_ENTRY_MODULE"
|
|---|
| 600 | ).isEntryModule(this);
|
|---|
| 601 | }
|
|---|
| 602 |
|
|---|
| 603 | /**
|
|---|
| 604 | * @deprecated
|
|---|
| 605 | * @returns {Chunk[]} chunks
|
|---|
| 606 | */
|
|---|
| 607 | getChunks() {
|
|---|
| 608 | return ChunkGraph.getChunkGraphForModule(
|
|---|
| 609 | this,
|
|---|
| 610 | "Module.getChunks",
|
|---|
| 611 | "DEP_WEBPACK_MODULE_GET_CHUNKS"
|
|---|
| 612 | ).getModuleChunks(this);
|
|---|
| 613 | }
|
|---|
| 614 |
|
|---|
| 615 | /**
|
|---|
| 616 | * @deprecated
|
|---|
| 617 | * @returns {number} number of chunks
|
|---|
| 618 | */
|
|---|
| 619 | getNumberOfChunks() {
|
|---|
| 620 | return ChunkGraph.getChunkGraphForModule(
|
|---|
| 621 | this,
|
|---|
| 622 | "Module.getNumberOfChunks",
|
|---|
| 623 | "DEP_WEBPACK_MODULE_GET_NUMBER_OF_CHUNKS"
|
|---|
| 624 | ).getNumberOfModuleChunks(this);
|
|---|
| 625 | }
|
|---|
| 626 |
|
|---|
| 627 | /**
|
|---|
| 628 | * @deprecated
|
|---|
| 629 | * @returns {Iterable<Chunk>} chunks
|
|---|
| 630 | */
|
|---|
| 631 | get chunksIterable() {
|
|---|
| 632 | return ChunkGraph.getChunkGraphForModule(
|
|---|
| 633 | this,
|
|---|
| 634 | "Module.chunksIterable",
|
|---|
| 635 | "DEP_WEBPACK_MODULE_CHUNKS_ITERABLE"
|
|---|
| 636 | ).getOrderedModuleChunksIterable(this, compareChunksById);
|
|---|
| 637 | }
|
|---|
| 638 |
|
|---|
| 639 | /**
|
|---|
| 640 | * Checks whether this module provides the specified export.
|
|---|
| 641 | * @deprecated
|
|---|
| 642 | * @param {string} exportName a name of an export
|
|---|
| 643 | * @returns {boolean | null} true, if the export is provided why the module.
|
|---|
| 644 | * null, if it's unknown.
|
|---|
| 645 | * false, if it's not provided.
|
|---|
| 646 | */
|
|---|
| 647 | isProvided(exportName) {
|
|---|
| 648 | return ModuleGraph.getModuleGraphForModule(
|
|---|
| 649 | this,
|
|---|
| 650 | "Module.usedExports",
|
|---|
| 651 | "DEP_WEBPACK_MODULE_USED_EXPORTS"
|
|---|
| 652 | ).isExportProvided(this, exportName);
|
|---|
| 653 | }
|
|---|
| 654 | // BACKWARD-COMPAT END
|
|---|
| 655 |
|
|---|
| 656 | /**
|
|---|
| 657 | * Gets exports argument.
|
|---|
| 658 | * @returns {string} name of the exports argument
|
|---|
| 659 | */
|
|---|
| 660 | get exportsArgument() {
|
|---|
| 661 | return (this.buildInfo && this.buildInfo.exportsArgument) || "exports";
|
|---|
| 662 | }
|
|---|
| 663 |
|
|---|
| 664 | /**
|
|---|
| 665 | * Gets module argument.
|
|---|
| 666 | * @returns {string} name of the module argument
|
|---|
| 667 | */
|
|---|
| 668 | get moduleArgument() {
|
|---|
| 669 | return (this.buildInfo && this.buildInfo.moduleArgument) || "module";
|
|---|
| 670 | }
|
|---|
| 671 |
|
|---|
| 672 | /**
|
|---|
| 673 | * Returns export type.
|
|---|
| 674 | * @param {ModuleGraph} moduleGraph the module graph
|
|---|
| 675 | * @param {boolean | undefined} strict the importing module is strict
|
|---|
| 676 | * @returns {ExportsType} export type
|
|---|
| 677 | * "namespace": Exports is already a namespace object. namespace = exports.
|
|---|
| 678 | * "dynamic": Check at runtime if __esModule is set. When set: namespace = { ...exports, default: exports }. When not set: namespace = { default: exports }.
|
|---|
| 679 | * "default-only": Provide a namespace object with only default export. namespace = { default: exports }
|
|---|
| 680 | * "default-with-named": Provide a namespace object with named and default export. namespace = { ...exports, default: exports }
|
|---|
| 681 | */
|
|---|
| 682 | getExportsType(moduleGraph, strict) {
|
|---|
| 683 | switch (this.buildMeta && this.buildMeta.exportsType) {
|
|---|
| 684 | case "flagged":
|
|---|
| 685 | return strict ? "default-with-named" : "namespace";
|
|---|
| 686 | case "namespace":
|
|---|
| 687 | return "namespace";
|
|---|
| 688 | case "default":
|
|---|
| 689 | switch (/** @type {BuildMeta} */ (this.buildMeta).defaultObject) {
|
|---|
| 690 | case "redirect":
|
|---|
| 691 | return "default-with-named";
|
|---|
| 692 | case "redirect-warn":
|
|---|
| 693 | return strict ? "default-only" : "default-with-named";
|
|---|
| 694 | default:
|
|---|
| 695 | return "default-only";
|
|---|
| 696 | }
|
|---|
| 697 | case "dynamic": {
|
|---|
| 698 | if (strict) return "default-with-named";
|
|---|
| 699 | // Try to figure out value of __esModule by following reexports
|
|---|
| 700 | const handleDefault = () => {
|
|---|
| 701 | switch (/** @type {BuildMeta} */ (this.buildMeta).defaultObject) {
|
|---|
| 702 | case "redirect":
|
|---|
| 703 | case "redirect-warn":
|
|---|
| 704 | return "default-with-named";
|
|---|
| 705 | default:
|
|---|
| 706 | return "default-only";
|
|---|
| 707 | }
|
|---|
| 708 | };
|
|---|
| 709 | const exportInfo = moduleGraph.getReadOnlyExportInfo(
|
|---|
| 710 | this,
|
|---|
| 711 | "__esModule"
|
|---|
| 712 | );
|
|---|
| 713 | if (exportInfo.provided === false) {
|
|---|
| 714 | return handleDefault();
|
|---|
| 715 | }
|
|---|
| 716 | const target = exportInfo.getTarget(moduleGraph);
|
|---|
| 717 | if (
|
|---|
| 718 | !target ||
|
|---|
| 719 | !target.export ||
|
|---|
| 720 | target.export.length !== 1 ||
|
|---|
| 721 | target.export[0] !== "__esModule"
|
|---|
| 722 | ) {
|
|---|
| 723 | return "dynamic";
|
|---|
| 724 | }
|
|---|
| 725 | switch (
|
|---|
| 726 | target.module.buildMeta &&
|
|---|
| 727 | target.module.buildMeta.exportsType
|
|---|
| 728 | ) {
|
|---|
| 729 | case "flagged":
|
|---|
| 730 | case "namespace":
|
|---|
| 731 | return "namespace";
|
|---|
| 732 | case "default":
|
|---|
| 733 | return handleDefault();
|
|---|
| 734 | default:
|
|---|
| 735 | return "dynamic";
|
|---|
| 736 | }
|
|---|
| 737 | }
|
|---|
| 738 | default:
|
|---|
| 739 | return strict ? "default-with-named" : "dynamic";
|
|---|
| 740 | }
|
|---|
| 741 | }
|
|---|
| 742 |
|
|---|
| 743 | /**
|
|---|
| 744 | * Adds presentational dependency.
|
|---|
| 745 | * @param {Dependency} presentationalDependency dependency being tied to module.
|
|---|
| 746 | * This is a Dependency without edge in the module graph. It's only for presentation.
|
|---|
| 747 | * @returns {void}
|
|---|
| 748 | */
|
|---|
| 749 | addPresentationalDependency(presentationalDependency) {
|
|---|
| 750 | if (this.presentationalDependencies === undefined) {
|
|---|
| 751 | this.presentationalDependencies = [];
|
|---|
| 752 | }
|
|---|
| 753 | this.presentationalDependencies.push(presentationalDependency);
|
|---|
| 754 | }
|
|---|
| 755 |
|
|---|
| 756 | /**
|
|---|
| 757 | * Adds code generation dependency.
|
|---|
| 758 | * @param {Dependency} codeGenerationDependency dependency being tied to module.
|
|---|
| 759 | * This is a Dependency where the code generation result of the referenced module is needed during code generation.
|
|---|
| 760 | * The Dependency should also be added to normal dependencies via addDependency.
|
|---|
| 761 | * @returns {void}
|
|---|
| 762 | */
|
|---|
| 763 | addCodeGenerationDependency(codeGenerationDependency) {
|
|---|
| 764 | if (this.codeGenerationDependencies === undefined) {
|
|---|
| 765 | this.codeGenerationDependencies = [];
|
|---|
| 766 | }
|
|---|
| 767 | this.codeGenerationDependencies.push(codeGenerationDependency);
|
|---|
| 768 | }
|
|---|
| 769 |
|
|---|
| 770 | /**
|
|---|
| 771 | * Clear dependencies and blocks.
|
|---|
| 772 | * @returns {void}
|
|---|
| 773 | */
|
|---|
| 774 | clearDependenciesAndBlocks() {
|
|---|
| 775 | if (this.presentationalDependencies !== undefined) {
|
|---|
| 776 | this.presentationalDependencies.length = 0;
|
|---|
| 777 | }
|
|---|
| 778 | if (this.codeGenerationDependencies !== undefined) {
|
|---|
| 779 | this.codeGenerationDependencies.length = 0;
|
|---|
| 780 | }
|
|---|
| 781 | super.clearDependenciesAndBlocks();
|
|---|
| 782 | }
|
|---|
| 783 |
|
|---|
| 784 | /**
|
|---|
| 785 | * Adds the provided warning to the module.
|
|---|
| 786 | * @param {Error} warning the warning
|
|---|
| 787 | * @returns {void}
|
|---|
| 788 | */
|
|---|
| 789 | addWarning(warning) {
|
|---|
| 790 | if (this._warnings === undefined) {
|
|---|
| 791 | this._warnings = [];
|
|---|
| 792 | }
|
|---|
| 793 | this._warnings.push(warning);
|
|---|
| 794 | }
|
|---|
| 795 |
|
|---|
| 796 | /**
|
|---|
| 797 | * Returns list of warnings if any.
|
|---|
| 798 | * @returns {Error[] | undefined} list of warnings if any
|
|---|
| 799 | */
|
|---|
| 800 | getWarnings() {
|
|---|
| 801 | return this._warnings;
|
|---|
| 802 | }
|
|---|
| 803 |
|
|---|
| 804 | /**
|
|---|
| 805 | * Gets number of warnings.
|
|---|
| 806 | * @returns {number} number of warnings
|
|---|
| 807 | */
|
|---|
| 808 | getNumberOfWarnings() {
|
|---|
| 809 | return this._warnings !== undefined ? this._warnings.length : 0;
|
|---|
| 810 | }
|
|---|
| 811 |
|
|---|
| 812 | /**
|
|---|
| 813 | * Adds the provided error to the module.
|
|---|
| 814 | * @param {Error} error the error
|
|---|
| 815 | * @returns {void}
|
|---|
| 816 | */
|
|---|
| 817 | addError(error) {
|
|---|
| 818 | if (this._errors === undefined) {
|
|---|
| 819 | this._errors = [];
|
|---|
| 820 | }
|
|---|
| 821 | this._errors.push(error);
|
|---|
| 822 | }
|
|---|
| 823 |
|
|---|
| 824 | /**
|
|---|
| 825 | * Returns list of errors if any.
|
|---|
| 826 | * @returns {Error[] | undefined} list of errors if any
|
|---|
| 827 | */
|
|---|
| 828 | getErrors() {
|
|---|
| 829 | return this._errors;
|
|---|
| 830 | }
|
|---|
| 831 |
|
|---|
| 832 | /**
|
|---|
| 833 | * Gets number of errors.
|
|---|
| 834 | * @returns {number} number of errors
|
|---|
| 835 | */
|
|---|
| 836 | getNumberOfErrors() {
|
|---|
| 837 | return this._errors !== undefined ? this._errors.length : 0;
|
|---|
| 838 | }
|
|---|
| 839 |
|
|---|
| 840 | /**
|
|---|
| 841 | * removes all warnings and errors
|
|---|
| 842 | * @returns {void}
|
|---|
| 843 | */
|
|---|
| 844 | clearWarningsAndErrors() {
|
|---|
| 845 | if (this._warnings !== undefined) {
|
|---|
| 846 | this._warnings.length = 0;
|
|---|
| 847 | }
|
|---|
| 848 | if (this._errors !== undefined) {
|
|---|
| 849 | this._errors.length = 0;
|
|---|
| 850 | }
|
|---|
| 851 | }
|
|---|
| 852 |
|
|---|
| 853 | /**
|
|---|
| 854 | * Checks whether this module is optional.
|
|---|
| 855 | * @param {ModuleGraph} moduleGraph the module graph
|
|---|
| 856 | * @returns {boolean} true, if the module is optional
|
|---|
| 857 | */
|
|---|
| 858 | isOptional(moduleGraph) {
|
|---|
| 859 | let hasConnections = false;
|
|---|
| 860 | for (const r of moduleGraph.getIncomingConnections(this)) {
|
|---|
| 861 | if (
|
|---|
| 862 | !r.dependency ||
|
|---|
| 863 | !r.dependency.optional ||
|
|---|
| 864 | !r.isTargetActive(undefined)
|
|---|
| 865 | ) {
|
|---|
| 866 | return false;
|
|---|
| 867 | }
|
|---|
| 868 | hasConnections = true;
|
|---|
| 869 | }
|
|---|
| 870 | return hasConnections;
|
|---|
| 871 | }
|
|---|
| 872 |
|
|---|
| 873 | /**
|
|---|
| 874 | * Checks whether this module is accessible in chunk.
|
|---|
| 875 | * @param {ChunkGraph} chunkGraph the chunk graph
|
|---|
| 876 | * @param {Chunk} chunk a chunk
|
|---|
| 877 | * @param {Chunk=} ignoreChunk chunk to be ignored
|
|---|
| 878 | * @returns {boolean} true, if the module is accessible from "chunk" when ignoring "ignoreChunk"
|
|---|
| 879 | */
|
|---|
| 880 | isAccessibleInChunk(chunkGraph, chunk, ignoreChunk) {
|
|---|
| 881 | // Check if module is accessible in ALL chunk groups
|
|---|
| 882 | for (const chunkGroup of chunk.groupsIterable) {
|
|---|
| 883 | if (!this.isAccessibleInChunkGroup(chunkGraph, chunkGroup)) return false;
|
|---|
| 884 | }
|
|---|
| 885 | return true;
|
|---|
| 886 | }
|
|---|
| 887 |
|
|---|
| 888 | /**
|
|---|
| 889 | * Checks whether this module is accessible in chunk group.
|
|---|
| 890 | * @param {ChunkGraph} chunkGraph the chunk graph
|
|---|
| 891 | * @param {ChunkGroup} chunkGroup a chunk group
|
|---|
| 892 | * @param {Chunk=} ignoreChunk chunk to be ignored
|
|---|
| 893 | * @returns {boolean} true, if the module is accessible from "chunkGroup" when ignoring "ignoreChunk"
|
|---|
| 894 | */
|
|---|
| 895 | isAccessibleInChunkGroup(chunkGraph, chunkGroup, ignoreChunk) {
|
|---|
| 896 | const queue = new Set([chunkGroup]);
|
|---|
| 897 |
|
|---|
| 898 | // Check if module is accessible from all items of the queue
|
|---|
| 899 | queueFor: for (const cg of queue) {
|
|---|
| 900 | // 1. If module is in one of the chunks of the group we can continue checking the next items
|
|---|
| 901 | // because it's accessible.
|
|---|
| 902 | for (const chunk of cg.chunks) {
|
|---|
| 903 | if (chunk !== ignoreChunk && chunkGraph.isModuleInChunk(this, chunk)) {
|
|---|
| 904 | continue queueFor;
|
|---|
| 905 | }
|
|---|
| 906 | }
|
|---|
| 907 | // 2. If the chunk group is initial, we can break here because it's not accessible.
|
|---|
| 908 | if (chunkGroup.isInitial()) return false;
|
|---|
| 909 | // 3. Enqueue all parents because it must be accessible from ALL parents
|
|---|
| 910 | for (const parent of chunkGroup.parentsIterable) queue.add(parent);
|
|---|
| 911 | }
|
|---|
| 912 | // When we processed through the whole list and we didn't bailout, the module is accessible
|
|---|
| 913 | return true;
|
|---|
| 914 | }
|
|---|
| 915 |
|
|---|
| 916 | /**
|
|---|
| 917 | * Checks whether this module contains the chunk.
|
|---|
| 918 | * @param {Chunk} chunk a chunk
|
|---|
| 919 | * @param {ModuleGraph} moduleGraph the module graph
|
|---|
| 920 | * @param {ChunkGraph} chunkGraph the chunk graph
|
|---|
| 921 | * @returns {boolean} true, if the module has any reason why "chunk" should be included
|
|---|
| 922 | */
|
|---|
| 923 | hasReasonForChunk(chunk, moduleGraph, chunkGraph) {
|
|---|
| 924 | // check for each reason if we need the chunk
|
|---|
| 925 | for (const [
|
|---|
| 926 | fromModule,
|
|---|
| 927 | connections
|
|---|
| 928 | ] of moduleGraph.getIncomingConnectionsByOriginModule(this)) {
|
|---|
| 929 | if (!connections.some((c) => c.isTargetActive(chunk.runtime))) continue;
|
|---|
| 930 | for (const originChunk of chunkGraph.getModuleChunksIterable(
|
|---|
| 931 | /** @type {Module} */ (fromModule)
|
|---|
| 932 | )) {
|
|---|
| 933 | // return true if module this is not reachable from originChunk when ignoring chunk
|
|---|
| 934 | if (!this.isAccessibleInChunk(chunkGraph, originChunk, chunk)) {
|
|---|
| 935 | return true;
|
|---|
| 936 | }
|
|---|
| 937 | }
|
|---|
| 938 | }
|
|---|
| 939 | return false;
|
|---|
| 940 | }
|
|---|
| 941 |
|
|---|
| 942 | /**
|
|---|
| 943 | * Checks whether this module contains the module graph.
|
|---|
| 944 | * @param {ModuleGraph} moduleGraph the module graph
|
|---|
| 945 | * @param {RuntimeSpec} runtime the runtime
|
|---|
| 946 | * @returns {boolean} true if at least one other module depends on this module
|
|---|
| 947 | */
|
|---|
| 948 | hasReasons(moduleGraph, runtime) {
|
|---|
| 949 | for (const c of moduleGraph.getIncomingConnections(this)) {
|
|---|
| 950 | if (c.isTargetActive(runtime)) return true;
|
|---|
| 951 | }
|
|---|
| 952 | return false;
|
|---|
| 953 | }
|
|---|
| 954 |
|
|---|
| 955 | /**
|
|---|
| 956 | * Returns a string representation.
|
|---|
| 957 | * @returns {string} for debugging
|
|---|
| 958 | */
|
|---|
| 959 | toString() {
|
|---|
| 960 | return `Module[${this.debugId}: ${this.identifier()}]`;
|
|---|
| 961 | }
|
|---|
| 962 |
|
|---|
| 963 | /**
|
|---|
| 964 | * Checks whether the module needs to be rebuilt for the current build state.
|
|---|
| 965 | * @param {NeedBuildContext} context context info
|
|---|
| 966 | * @param {NeedBuildCallback} callback callback function, returns true, if the module needs a rebuild
|
|---|
| 967 | * @returns {void}
|
|---|
| 968 | */
|
|---|
| 969 | needBuild(context, callback) {
|
|---|
| 970 | callback(
|
|---|
| 971 | null,
|
|---|
| 972 | !this.buildMeta ||
|
|---|
| 973 | this.needRebuild === Module.prototype.needRebuild ||
|
|---|
| 974 | deprecatedNeedRebuild(this, context)
|
|---|
| 975 | );
|
|---|
| 976 | }
|
|---|
| 977 |
|
|---|
| 978 | /**
|
|---|
| 979 | * Checks whether it needs rebuild.
|
|---|
| 980 | * @deprecated Use needBuild instead
|
|---|
| 981 | * @param {Map<string, number | null>} fileTimestamps timestamps of files
|
|---|
| 982 | * @param {Map<string, number | null>} contextTimestamps timestamps of directories
|
|---|
| 983 | * @returns {boolean} true, if the module needs a rebuild
|
|---|
| 984 | */
|
|---|
| 985 | needRebuild(fileTimestamps, contextTimestamps) {
|
|---|
| 986 | return true;
|
|---|
| 987 | }
|
|---|
| 988 |
|
|---|
| 989 | /**
|
|---|
| 990 | * Updates the hash with the data contributed by this instance.
|
|---|
| 991 | * @param {Hash} hash the hash used to track dependencies
|
|---|
| 992 | * @param {UpdateHashContext} context context
|
|---|
| 993 | * @returns {void}
|
|---|
| 994 | */
|
|---|
| 995 | updateHash(
|
|---|
| 996 | hash,
|
|---|
| 997 | context = {
|
|---|
| 998 | chunkGraph: ChunkGraph.getChunkGraphForModule(
|
|---|
| 999 | this,
|
|---|
| 1000 | "Module.updateHash",
|
|---|
| 1001 | "DEP_WEBPACK_MODULE_UPDATE_HASH"
|
|---|
| 1002 | ),
|
|---|
| 1003 | runtime: undefined
|
|---|
| 1004 | }
|
|---|
| 1005 | ) {
|
|---|
| 1006 | const { chunkGraph, runtime } = context;
|
|---|
| 1007 | hash.update(chunkGraph.getModuleGraphHash(this, runtime));
|
|---|
| 1008 | if (this.presentationalDependencies !== undefined) {
|
|---|
| 1009 | for (const dep of this.presentationalDependencies) {
|
|---|
| 1010 | dep.updateHash(hash, context);
|
|---|
| 1011 | }
|
|---|
| 1012 | }
|
|---|
| 1013 | super.updateHash(hash, context);
|
|---|
| 1014 | }
|
|---|
| 1015 |
|
|---|
| 1016 | /**
|
|---|
| 1017 | * Invalidates the cached state associated with this value.
|
|---|
| 1018 | * @returns {void}
|
|---|
| 1019 | */
|
|---|
| 1020 | invalidateBuild() {
|
|---|
| 1021 | // should be overridden to support this feature
|
|---|
| 1022 | }
|
|---|
| 1023 |
|
|---|
| 1024 | /* istanbul ignore next */
|
|---|
| 1025 | /**
|
|---|
| 1026 | * Returns the unique identifier used to reference this module.
|
|---|
| 1027 | * @abstract
|
|---|
| 1028 | * @returns {string} a unique identifier of the module
|
|---|
| 1029 | */
|
|---|
| 1030 | identifier() {
|
|---|
| 1031 | const AbstractMethodError = require("./errors/AbstractMethodError");
|
|---|
| 1032 |
|
|---|
| 1033 | throw new AbstractMethodError();
|
|---|
| 1034 | }
|
|---|
| 1035 |
|
|---|
| 1036 | /* istanbul ignore next */
|
|---|
| 1037 | /**
|
|---|
| 1038 | * Returns a human-readable identifier for this module.
|
|---|
| 1039 | * @abstract
|
|---|
| 1040 | * @param {RequestShortener} requestShortener the request shortener
|
|---|
| 1041 | * @returns {string} a user readable identifier of the module
|
|---|
| 1042 | */
|
|---|
| 1043 | readableIdentifier(requestShortener) {
|
|---|
| 1044 | const AbstractMethodError = require("./errors/AbstractMethodError");
|
|---|
| 1045 |
|
|---|
| 1046 | throw new AbstractMethodError();
|
|---|
| 1047 | }
|
|---|
| 1048 |
|
|---|
| 1049 | /* istanbul ignore next */
|
|---|
| 1050 | /**
|
|---|
| 1051 | * Builds the module using the provided compilation context.
|
|---|
| 1052 | * @abstract
|
|---|
| 1053 | * @param {WebpackOptions} options webpack options
|
|---|
| 1054 | * @param {Compilation} compilation the compilation
|
|---|
| 1055 | * @param {ResolverWithOptions} resolver the resolver
|
|---|
| 1056 | * @param {InputFileSystem} fs the file system
|
|---|
| 1057 | * @param {BuildCallback} callback callback function
|
|---|
| 1058 | * @returns {void}
|
|---|
| 1059 | */
|
|---|
| 1060 | build(options, compilation, resolver, fs, callback) {
|
|---|
| 1061 | const AbstractMethodError = require("./errors/AbstractMethodError");
|
|---|
| 1062 |
|
|---|
| 1063 | throw new AbstractMethodError();
|
|---|
| 1064 | }
|
|---|
| 1065 |
|
|---|
| 1066 | /**
|
|---|
| 1067 | * Returns the source types this module can generate.
|
|---|
| 1068 | * @abstract
|
|---|
| 1069 | * @returns {SourceTypes} types available (do not mutate)
|
|---|
| 1070 | */
|
|---|
| 1071 | getSourceTypes() {
|
|---|
| 1072 | // Better override this method to return the correct types
|
|---|
| 1073 | if (this.source === Module.prototype.source) {
|
|---|
| 1074 | return DEFAULT_TYPES_UNKNOWN;
|
|---|
| 1075 | }
|
|---|
| 1076 | return JAVASCRIPT_TYPES;
|
|---|
| 1077 | }
|
|---|
| 1078 |
|
|---|
| 1079 | /**
|
|---|
| 1080 | * Basic source types are high-level categories like javascript, css, webassembly, etc.
|
|---|
| 1081 | * We only have built-in knowledge about the javascript basic type here; other basic types may be
|
|---|
| 1082 | * added or changed over time by generators and do not need to be handled or detected here.
|
|---|
| 1083 | *
|
|---|
| 1084 | * Some modules, e.g. RemoteModule, may return non-basic source types like "remote" and "share-init"
|
|---|
| 1085 | * from getSourceTypes(), but their generated output is still JavaScript, i.e. their basic type is JS.
|
|---|
| 1086 | * @returns {BasicSourceTypes} types available (do not mutate)
|
|---|
| 1087 | */
|
|---|
| 1088 | getSourceBasicTypes() {
|
|---|
| 1089 | return this.getSourceTypes();
|
|---|
| 1090 | }
|
|---|
| 1091 |
|
|---|
| 1092 | /**
|
|---|
| 1093 | * Returns generated source.
|
|---|
| 1094 | * @abstract
|
|---|
| 1095 | * @deprecated Use codeGeneration() instead
|
|---|
| 1096 | * @param {DependencyTemplates} dependencyTemplates the dependency templates
|
|---|
| 1097 | * @param {RuntimeTemplate} runtimeTemplate the runtime template
|
|---|
| 1098 | * @param {SourceType=} type the type of source that should be generated
|
|---|
| 1099 | * @returns {Source} generated source
|
|---|
| 1100 | */
|
|---|
| 1101 | source(dependencyTemplates, runtimeTemplate, type = JAVASCRIPT_TYPE) {
|
|---|
| 1102 | if (this.codeGeneration === Module.prototype.codeGeneration) {
|
|---|
| 1103 | const AbstractMethodError = require("./errors/AbstractMethodError");
|
|---|
| 1104 |
|
|---|
| 1105 | throw new AbstractMethodError();
|
|---|
| 1106 | }
|
|---|
| 1107 | const chunkGraph = ChunkGraph.getChunkGraphForModule(
|
|---|
| 1108 | this,
|
|---|
| 1109 | "Module.source() is deprecated. Use Compilation.codeGenerationResults.getSource(module, runtime, type) instead",
|
|---|
| 1110 | "DEP_WEBPACK_MODULE_SOURCE"
|
|---|
| 1111 | );
|
|---|
| 1112 | /** @type {CodeGenerationContext} */
|
|---|
| 1113 | const codeGenContext = {
|
|---|
| 1114 | dependencyTemplates,
|
|---|
| 1115 | runtimeTemplate,
|
|---|
| 1116 | moduleGraph: chunkGraph.moduleGraph,
|
|---|
| 1117 | chunkGraph,
|
|---|
| 1118 | runtime: undefined,
|
|---|
| 1119 | runtimes: [],
|
|---|
| 1120 | codeGenerationResults: undefined
|
|---|
| 1121 | };
|
|---|
| 1122 | const sources = this.codeGeneration(codeGenContext).sources;
|
|---|
| 1123 |
|
|---|
| 1124 | return /** @type {Source} */ (
|
|---|
| 1125 | type
|
|---|
| 1126 | ? sources.get(type)
|
|---|
| 1127 | : sources.get(/** @type {SourceType} */ (first(this.getSourceTypes())))
|
|---|
| 1128 | );
|
|---|
| 1129 | }
|
|---|
| 1130 |
|
|---|
| 1131 | /* istanbul ignore next */
|
|---|
| 1132 | /**
|
|---|
| 1133 | * Returns the estimated size for the requested source type.
|
|---|
| 1134 | * @abstract
|
|---|
| 1135 | * @param {string=} type the source type for which the size should be estimated
|
|---|
| 1136 | * @returns {number} the estimated size of the module (must be non-zero)
|
|---|
| 1137 | */
|
|---|
| 1138 | size(type) {
|
|---|
| 1139 | const AbstractMethodError = require("./errors/AbstractMethodError");
|
|---|
| 1140 |
|
|---|
| 1141 | throw new AbstractMethodError();
|
|---|
| 1142 | }
|
|---|
| 1143 |
|
|---|
| 1144 | /**
|
|---|
| 1145 | * Gets the library identifier.
|
|---|
| 1146 | * @param {LibIdentOptions} options options
|
|---|
| 1147 | * @returns {LibIdent | null} an identifier for library inclusion
|
|---|
| 1148 | */
|
|---|
| 1149 | libIdent(options) {
|
|---|
| 1150 | return null;
|
|---|
| 1151 | }
|
|---|
| 1152 |
|
|---|
| 1153 | /**
|
|---|
| 1154 | * Returns the path used when matching this module against rule conditions.
|
|---|
| 1155 | * @returns {NameForCondition | null} absolute path which should be used for condition matching (usually the resource path)
|
|---|
| 1156 | */
|
|---|
| 1157 | nameForCondition() {
|
|---|
| 1158 | return null;
|
|---|
| 1159 | }
|
|---|
| 1160 |
|
|---|
| 1161 | /**
|
|---|
| 1162 | * Returns the reason this module cannot be concatenated, when one exists.
|
|---|
| 1163 | * @param {ConcatenationBailoutReasonContext} context context
|
|---|
| 1164 | * @returns {string | undefined} reason why this module can't be concatenated, undefined when it can be concatenated
|
|---|
| 1165 | */
|
|---|
| 1166 | getConcatenationBailoutReason(context) {
|
|---|
| 1167 | return `Module Concatenation is not implemented for ${this.constructor.name}`;
|
|---|
| 1168 | }
|
|---|
| 1169 |
|
|---|
| 1170 | /**
|
|---|
| 1171 | * Gets side effects connection state.
|
|---|
| 1172 | * @param {ModuleGraph} moduleGraph the module graph
|
|---|
| 1173 | * @returns {ConnectionState} how this module should be connected to referencing modules when consumed for side-effects only
|
|---|
| 1174 | */
|
|---|
| 1175 | getSideEffectsConnectionState(moduleGraph) {
|
|---|
| 1176 | return true;
|
|---|
| 1177 | }
|
|---|
| 1178 |
|
|---|
| 1179 | /**
|
|---|
| 1180 | * Generates code and runtime requirements for this module.
|
|---|
| 1181 | * @param {CodeGenerationContext} context context for code generation
|
|---|
| 1182 | * @returns {CodeGenerationResult} result
|
|---|
| 1183 | */
|
|---|
| 1184 | codeGeneration(context) {
|
|---|
| 1185 | // Best override this method
|
|---|
| 1186 | /** @type {Sources} */
|
|---|
| 1187 | const sources = new Map();
|
|---|
| 1188 | for (const type of this.getSourceTypes()) {
|
|---|
| 1189 | if (type !== UNKNOWN_TYPE) {
|
|---|
| 1190 | sources.set(
|
|---|
| 1191 | type,
|
|---|
| 1192 | this.source(
|
|---|
| 1193 | context.dependencyTemplates,
|
|---|
| 1194 | context.runtimeTemplate,
|
|---|
| 1195 | type
|
|---|
| 1196 | )
|
|---|
| 1197 | );
|
|---|
| 1198 | }
|
|---|
| 1199 | }
|
|---|
| 1200 | return {
|
|---|
| 1201 | sources,
|
|---|
| 1202 | runtimeRequirements: new Set([
|
|---|
| 1203 | RuntimeGlobals.module,
|
|---|
| 1204 | RuntimeGlobals.exports,
|
|---|
| 1205 | RuntimeGlobals.require
|
|---|
| 1206 | ])
|
|---|
| 1207 | };
|
|---|
| 1208 | }
|
|---|
| 1209 |
|
|---|
| 1210 | /**
|
|---|
| 1211 | * Returns true if the module can be placed in the chunk.
|
|---|
| 1212 | * @param {Chunk} chunk the chunk which condition should be checked
|
|---|
| 1213 | * @param {Compilation} compilation the compilation
|
|---|
| 1214 | * @returns {boolean} true if the module can be placed in the chunk
|
|---|
| 1215 | */
|
|---|
| 1216 | chunkCondition(chunk, compilation) {
|
|---|
| 1217 | return true;
|
|---|
| 1218 | }
|
|---|
| 1219 |
|
|---|
| 1220 | hasChunkCondition() {
|
|---|
| 1221 | return this.chunkCondition !== Module.prototype.chunkCondition;
|
|---|
| 1222 | }
|
|---|
| 1223 |
|
|---|
| 1224 | /**
|
|---|
| 1225 | * Assuming this module is in the cache. Update the (cached) module with
|
|---|
| 1226 | * the fresh module from the factory. Usually updates internal references
|
|---|
| 1227 | * and properties.
|
|---|
| 1228 | * @param {Module} module fresh module
|
|---|
| 1229 | * @returns {void}
|
|---|
| 1230 | */
|
|---|
| 1231 | updateCacheModule(module) {
|
|---|
| 1232 | this.type = module.type;
|
|---|
| 1233 | this.layer = module.layer;
|
|---|
| 1234 | this.context = module.context;
|
|---|
| 1235 | this.factoryMeta = module.factoryMeta;
|
|---|
| 1236 | this.resolveOptions = module.resolveOptions;
|
|---|
| 1237 | }
|
|---|
| 1238 |
|
|---|
| 1239 | /**
|
|---|
| 1240 | * Module should be unsafe cached. Get data that's needed for that.
|
|---|
| 1241 | * This data will be passed to restoreFromUnsafeCache later.
|
|---|
| 1242 | * @returns {UnsafeCacheData} cached data
|
|---|
| 1243 | */
|
|---|
| 1244 | getUnsafeCacheData() {
|
|---|
| 1245 | return {
|
|---|
| 1246 | factoryMeta: this.factoryMeta,
|
|---|
| 1247 | resolveOptions: this.resolveOptions
|
|---|
| 1248 | };
|
|---|
| 1249 | }
|
|---|
| 1250 |
|
|---|
| 1251 | /**
|
|---|
| 1252 | * restore unsafe cache data
|
|---|
| 1253 | * @param {UnsafeCacheData} unsafeCacheData data from getUnsafeCacheData
|
|---|
| 1254 | * @param {NormalModuleFactory} normalModuleFactory the normal module factory handling the unsafe caching
|
|---|
| 1255 | */
|
|---|
| 1256 | _restoreFromUnsafeCache(unsafeCacheData, normalModuleFactory) {
|
|---|
| 1257 | this.factoryMeta = unsafeCacheData.factoryMeta;
|
|---|
| 1258 | this.resolveOptions = unsafeCacheData.resolveOptions;
|
|---|
| 1259 | }
|
|---|
| 1260 |
|
|---|
| 1261 | /**
|
|---|
| 1262 | * Assuming this module is in the cache. Remove internal references to allow freeing some memory.
|
|---|
| 1263 | */
|
|---|
| 1264 | cleanupForCache() {
|
|---|
| 1265 | this.factoryMeta = undefined;
|
|---|
| 1266 | this.resolveOptions = undefined;
|
|---|
| 1267 | }
|
|---|
| 1268 |
|
|---|
| 1269 | /**
|
|---|
| 1270 | * Gets the original source.
|
|---|
| 1271 | * @returns {Source | null} the original source for the module before webpack transformation
|
|---|
| 1272 | */
|
|---|
| 1273 | originalSource() {
|
|---|
| 1274 | return null;
|
|---|
| 1275 | }
|
|---|
| 1276 |
|
|---|
| 1277 | /**
|
|---|
| 1278 | * Adds the provided file dependencies to the module.
|
|---|
| 1279 | * @param {FileSystemDependencies} fileDependencies set where file dependencies are added to
|
|---|
| 1280 | * @param {FileSystemDependencies} contextDependencies set where context dependencies are added to
|
|---|
| 1281 | * @param {FileSystemDependencies} missingDependencies set where missing dependencies are added to
|
|---|
| 1282 | * @param {FileSystemDependencies} buildDependencies set where build dependencies are added to
|
|---|
| 1283 | */
|
|---|
| 1284 | addCacheDependencies(
|
|---|
| 1285 | fileDependencies,
|
|---|
| 1286 | contextDependencies,
|
|---|
| 1287 | missingDependencies,
|
|---|
| 1288 | buildDependencies
|
|---|
| 1289 | ) {}
|
|---|
| 1290 |
|
|---|
| 1291 | /**
|
|---|
| 1292 | * Serializes this instance into the provided serializer context.
|
|---|
| 1293 | * @param {ObjectSerializerContext} context context
|
|---|
| 1294 | */
|
|---|
| 1295 | serialize(context) {
|
|---|
| 1296 | const { write } = context;
|
|---|
| 1297 | write(this.type);
|
|---|
| 1298 | write(this.layer);
|
|---|
| 1299 | write(this.context);
|
|---|
| 1300 | write(this.resolveOptions);
|
|---|
| 1301 | write(this.factoryMeta);
|
|---|
| 1302 | write(this.useSourceMap);
|
|---|
| 1303 | write(this.useSimpleSourceMap);
|
|---|
| 1304 | write(this.hot);
|
|---|
| 1305 | write(
|
|---|
| 1306 | this._warnings !== undefined && this._warnings.length === 0
|
|---|
| 1307 | ? undefined
|
|---|
| 1308 | : this._warnings
|
|---|
| 1309 | );
|
|---|
| 1310 | write(
|
|---|
| 1311 | this._errors !== undefined && this._errors.length === 0
|
|---|
| 1312 | ? undefined
|
|---|
| 1313 | : this._errors
|
|---|
| 1314 | );
|
|---|
| 1315 | write(this.buildMeta);
|
|---|
| 1316 | write(this.buildInfo);
|
|---|
| 1317 | write(this.presentationalDependencies);
|
|---|
| 1318 | write(this.codeGenerationDependencies);
|
|---|
| 1319 | super.serialize(context);
|
|---|
| 1320 | }
|
|---|
| 1321 |
|
|---|
| 1322 | /**
|
|---|
| 1323 | * Restores this instance from the provided deserializer context.
|
|---|
| 1324 | * @param {ObjectDeserializerContext} context context
|
|---|
| 1325 | */
|
|---|
| 1326 | deserialize(context) {
|
|---|
| 1327 | const { read } = context;
|
|---|
| 1328 | this.type = read();
|
|---|
| 1329 | this.layer = read();
|
|---|
| 1330 | this.context = read();
|
|---|
| 1331 | this.resolveOptions = read();
|
|---|
| 1332 | this.factoryMeta = read();
|
|---|
| 1333 | this.useSourceMap = read();
|
|---|
| 1334 | this.useSimpleSourceMap = read();
|
|---|
| 1335 | this.hot = read();
|
|---|
| 1336 | this._warnings = read();
|
|---|
| 1337 | this._errors = read();
|
|---|
| 1338 | this.buildMeta = read();
|
|---|
| 1339 | this.buildInfo = read();
|
|---|
| 1340 | this.presentationalDependencies = read();
|
|---|
| 1341 | this.codeGenerationDependencies = read();
|
|---|
| 1342 | super.deserialize(context);
|
|---|
| 1343 | }
|
|---|
| 1344 |
|
|---|
| 1345 | // TODO remove in webpack 6
|
|---|
| 1346 | /**
|
|---|
| 1347 | * Gets source basic types.
|
|---|
| 1348 | * @deprecated In webpack 6, call getSourceBasicTypes() directly on the module instance instead of using this static method.
|
|---|
| 1349 | * @param {Module} module the module
|
|---|
| 1350 | * @returns {ReturnType<Module["getSourceBasicTypes"]>} the source types of the module
|
|---|
| 1351 | */
|
|---|
| 1352 | static getSourceBasicTypes(module) {
|
|---|
| 1353 | if (!(module instanceof Module)) {
|
|---|
| 1354 | // https://github.com/webpack/webpack/issues/20597
|
|---|
| 1355 | // fallback to javascript
|
|---|
| 1356 | return JAVASCRIPT_TYPES;
|
|---|
| 1357 | }
|
|---|
| 1358 | return module.getSourceBasicTypes();
|
|---|
| 1359 | }
|
|---|
| 1360 | }
|
|---|
| 1361 |
|
|---|
| 1362 | makeSerializable(Module, "webpack/lib/Module");
|
|---|
| 1363 |
|
|---|
| 1364 | // TODO remove in webpack 6
|
|---|
| 1365 | Object.defineProperty(Module.prototype, "hasEqualsChunks", {
|
|---|
| 1366 | /**
|
|---|
| 1367 | * Gets has equals chunks.
|
|---|
| 1368 | * @deprecated
|
|---|
| 1369 | * @returns {EXPECTED_ANY} throw an error
|
|---|
| 1370 | */
|
|---|
| 1371 | get() {
|
|---|
| 1372 | throw new Error(
|
|---|
| 1373 | "Module.hasEqualsChunks was renamed (use hasEqualChunks instead)"
|
|---|
| 1374 | );
|
|---|
| 1375 | }
|
|---|
| 1376 | });
|
|---|
| 1377 |
|
|---|
| 1378 | // TODO remove in webpack 6
|
|---|
| 1379 | Object.defineProperty(Module.prototype, "isUsed", {
|
|---|
| 1380 | /**
|
|---|
| 1381 | * Returns throw an error.
|
|---|
| 1382 | * @deprecated
|
|---|
| 1383 | * @returns {EXPECTED_ANY} throw an error
|
|---|
| 1384 | */
|
|---|
| 1385 | get() {
|
|---|
| 1386 | throw new Error(
|
|---|
| 1387 | "Module.isUsed was renamed (use getUsedName, isExportUsed or isModuleUsed instead)"
|
|---|
| 1388 | );
|
|---|
| 1389 | }
|
|---|
| 1390 | });
|
|---|
| 1391 |
|
|---|
| 1392 | // TODO remove in webpack 6
|
|---|
| 1393 | Object.defineProperty(Module.prototype, "errors", {
|
|---|
| 1394 | /**
|
|---|
| 1395 | * Returns errors.
|
|---|
| 1396 | * @deprecated
|
|---|
| 1397 | * @returns {Error[]} errors
|
|---|
| 1398 | */
|
|---|
| 1399 | get: util.deprecate(
|
|---|
| 1400 | /**
|
|---|
| 1401 | * Returns errors.
|
|---|
| 1402 | * @this {Module}
|
|---|
| 1403 | * @returns {Error[]} errors
|
|---|
| 1404 | */
|
|---|
| 1405 | function errors() {
|
|---|
| 1406 | if (this._errors === undefined) {
|
|---|
| 1407 | this._errors = [];
|
|---|
| 1408 | }
|
|---|
| 1409 | return this._errors;
|
|---|
| 1410 | },
|
|---|
| 1411 | "Module.errors was removed (use getErrors instead)",
|
|---|
| 1412 | "DEP_WEBPACK_MODULE_ERRORS"
|
|---|
| 1413 | )
|
|---|
| 1414 | });
|
|---|
| 1415 |
|
|---|
| 1416 | // TODO remove in webpack 6
|
|---|
| 1417 | Object.defineProperty(Module.prototype, "warnings", {
|
|---|
| 1418 | /**
|
|---|
| 1419 | * Returns warnings.
|
|---|
| 1420 | * @deprecated
|
|---|
| 1421 | * @returns {Error[]} warnings
|
|---|
| 1422 | */
|
|---|
| 1423 | get: util.deprecate(
|
|---|
| 1424 | /**
|
|---|
| 1425 | * Returns warnings.
|
|---|
| 1426 | * @this {Module}
|
|---|
| 1427 | * @returns {Error[]} warnings
|
|---|
| 1428 | */
|
|---|
| 1429 | function warnings() {
|
|---|
| 1430 | if (this._warnings === undefined) {
|
|---|
| 1431 | this._warnings = [];
|
|---|
| 1432 | }
|
|---|
| 1433 | return this._warnings;
|
|---|
| 1434 | },
|
|---|
| 1435 | "Module.warnings was removed (use getWarnings instead)",
|
|---|
| 1436 | "DEP_WEBPACK_MODULE_WARNINGS"
|
|---|
| 1437 | )
|
|---|
| 1438 | });
|
|---|
| 1439 |
|
|---|
| 1440 | // TODO remove in webpack 6
|
|---|
| 1441 | Object.defineProperty(Module.prototype, "used", {
|
|---|
| 1442 | /**
|
|---|
| 1443 | * Returns throw an error.
|
|---|
| 1444 | * @deprecated
|
|---|
| 1445 | * @returns {EXPECTED_ANY} throw an error
|
|---|
| 1446 | */
|
|---|
| 1447 | get() {
|
|---|
| 1448 | throw new Error(
|
|---|
| 1449 | "Module.used was refactored (use ModuleGraph.getUsedExports instead)"
|
|---|
| 1450 | );
|
|---|
| 1451 | },
|
|---|
| 1452 | /**
|
|---|
| 1453 | * Updates used using the provided value.
|
|---|
| 1454 | * @param {EXPECTED_ANY} value value
|
|---|
| 1455 | */
|
|---|
| 1456 | set(value) {
|
|---|
| 1457 | throw new Error(
|
|---|
| 1458 | "Module.used was refactored (use ModuleGraph.setUsedExports instead)"
|
|---|
| 1459 | );
|
|---|
| 1460 | }
|
|---|
| 1461 | });
|
|---|
| 1462 |
|
|---|
| 1463 | module.exports = Module;
|
|---|