1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126 |
- "use strict";
- const util = require("util");
- const ChunkGraph = require("./ChunkGraph");
- const DependenciesBlock = require("./DependenciesBlock");
- const ModuleGraph = require("./ModuleGraph");
- const RuntimeGlobals = require("./RuntimeGlobals");
- const { first } = require("./util/SetHelpers");
- const { compareChunksById } = require("./util/comparators");
- const makeSerializable = require("./util/makeSerializable");
- const EMPTY_RESOLVE_OPTIONS = {};
- let debugId = 1000;
- const DEFAULT_TYPES_UNKNOWN = new Set(["unknown"]);
- const DEFAULT_TYPES_JS = new Set(["javascript"]);
- const deprecatedNeedRebuild = util.deprecate(
-
- (module, context) => {
- return module.needRebuild(
- context.fileSystemInfo.getDeprecatedFileTimestamps(),
- context.fileSystemInfo.getDeprecatedContextTimestamps()
- );
- },
- "Module.needRebuild is deprecated in favor of Module.needBuild",
- "DEP_WEBPACK_MODULE_NEED_REBUILD"
- );
- class Module extends DependenciesBlock {
-
- constructor(type, context = null, layer = null) {
- super();
-
- this.type = type;
-
- this.context = context;
-
- this.layer = layer;
-
- this.needId = true;
-
-
- this.debugId = debugId++;
-
-
- this.resolveOptions = EMPTY_RESOLVE_OPTIONS;
-
- this.factoryMeta = undefined;
-
-
-
- this.useSourceMap = false;
-
- this.useSimpleSourceMap = false;
-
-
- this._warnings = undefined;
-
- this._errors = undefined;
-
- this.buildMeta = undefined;
-
- this.buildInfo = undefined;
-
- this.presentationalDependencies = undefined;
-
- this.codeGenerationDependencies = undefined;
- }
-
-
- get id() {
- return ChunkGraph.getChunkGraphForModule(
- this,
- "Module.id",
- "DEP_WEBPACK_MODULE_ID"
- ).getModuleId(this);
- }
- set id(value) {
- if (value === "") {
- this.needId = false;
- return;
- }
- ChunkGraph.getChunkGraphForModule(
- this,
- "Module.id",
- "DEP_WEBPACK_MODULE_ID"
- ).setModuleId(this, value);
- }
-
- get hash() {
- return ChunkGraph.getChunkGraphForModule(
- this,
- "Module.hash",
- "DEP_WEBPACK_MODULE_HASH"
- ).getModuleHash(this, undefined);
- }
-
- get renderedHash() {
- return ChunkGraph.getChunkGraphForModule(
- this,
- "Module.renderedHash",
- "DEP_WEBPACK_MODULE_RENDERED_HASH"
- ).getRenderedModuleHash(this, undefined);
- }
- get profile() {
- return ModuleGraph.getModuleGraphForModule(
- this,
- "Module.profile",
- "DEP_WEBPACK_MODULE_PROFILE"
- ).getProfile(this);
- }
- set profile(value) {
- ModuleGraph.getModuleGraphForModule(
- this,
- "Module.profile",
- "DEP_WEBPACK_MODULE_PROFILE"
- ).setProfile(this, value);
- }
- get index() {
- return ModuleGraph.getModuleGraphForModule(
- this,
- "Module.index",
- "DEP_WEBPACK_MODULE_INDEX"
- ).getPreOrderIndex(this);
- }
- set index(value) {
- ModuleGraph.getModuleGraphForModule(
- this,
- "Module.index",
- "DEP_WEBPACK_MODULE_INDEX"
- ).setPreOrderIndex(this, value);
- }
- get index2() {
- return ModuleGraph.getModuleGraphForModule(
- this,
- "Module.index2",
- "DEP_WEBPACK_MODULE_INDEX2"
- ).getPostOrderIndex(this);
- }
- set index2(value) {
- ModuleGraph.getModuleGraphForModule(
- this,
- "Module.index2",
- "DEP_WEBPACK_MODULE_INDEX2"
- ).setPostOrderIndex(this, value);
- }
- get depth() {
- return ModuleGraph.getModuleGraphForModule(
- this,
- "Module.depth",
- "DEP_WEBPACK_MODULE_DEPTH"
- ).getDepth(this);
- }
- set depth(value) {
- ModuleGraph.getModuleGraphForModule(
- this,
- "Module.depth",
- "DEP_WEBPACK_MODULE_DEPTH"
- ).setDepth(this, value);
- }
- get issuer() {
- return ModuleGraph.getModuleGraphForModule(
- this,
- "Module.issuer",
- "DEP_WEBPACK_MODULE_ISSUER"
- ).getIssuer(this);
- }
- set issuer(value) {
- ModuleGraph.getModuleGraphForModule(
- this,
- "Module.issuer",
- "DEP_WEBPACK_MODULE_ISSUER"
- ).setIssuer(this, value);
- }
- get usedExports() {
- return ModuleGraph.getModuleGraphForModule(
- this,
- "Module.usedExports",
- "DEP_WEBPACK_MODULE_USED_EXPORTS"
- ).getUsedExports(this, undefined);
- }
-
- get optimizationBailout() {
- return ModuleGraph.getModuleGraphForModule(
- this,
- "Module.optimizationBailout",
- "DEP_WEBPACK_MODULE_OPTIMIZATION_BAILOUT"
- ).getOptimizationBailout(this);
- }
- get optional() {
- return this.isOptional(
- ModuleGraph.getModuleGraphForModule(
- this,
- "Module.optional",
- "DEP_WEBPACK_MODULE_OPTIONAL"
- )
- );
- }
-
- addChunk(chunk) {
- const chunkGraph = ChunkGraph.getChunkGraphForModule(
- this,
- "Module.addChunk",
- "DEP_WEBPACK_MODULE_ADD_CHUNK"
- );
- if (chunkGraph.isModuleInChunk(this, chunk)) return false;
- chunkGraph.connectChunkAndModule(chunk, this);
- return true;
- }
-
- removeChunk(chunk) {
- return ChunkGraph.getChunkGraphForModule(
- this,
- "Module.removeChunk",
- "DEP_WEBPACK_MODULE_REMOVE_CHUNK"
- ).disconnectChunkAndModule(chunk, this);
- }
-
- isInChunk(chunk) {
- return ChunkGraph.getChunkGraphForModule(
- this,
- "Module.isInChunk",
- "DEP_WEBPACK_MODULE_IS_IN_CHUNK"
- ).isModuleInChunk(this, chunk);
- }
- isEntryModule() {
- return ChunkGraph.getChunkGraphForModule(
- this,
- "Module.isEntryModule",
- "DEP_WEBPACK_MODULE_IS_ENTRY_MODULE"
- ).isEntryModule(this);
- }
- getChunks() {
- return ChunkGraph.getChunkGraphForModule(
- this,
- "Module.getChunks",
- "DEP_WEBPACK_MODULE_GET_CHUNKS"
- ).getModuleChunks(this);
- }
- getNumberOfChunks() {
- return ChunkGraph.getChunkGraphForModule(
- this,
- "Module.getNumberOfChunks",
- "DEP_WEBPACK_MODULE_GET_NUMBER_OF_CHUNKS"
- ).getNumberOfModuleChunks(this);
- }
- get chunksIterable() {
- return ChunkGraph.getChunkGraphForModule(
- this,
- "Module.chunksIterable",
- "DEP_WEBPACK_MODULE_CHUNKS_ITERABLE"
- ).getOrderedModuleChunksIterable(this, compareChunksById);
- }
-
- isProvided(exportName) {
- return ModuleGraph.getModuleGraphForModule(
- this,
- "Module.usedExports",
- "DEP_WEBPACK_MODULE_USED_EXPORTS"
- ).isExportProvided(this, exportName);
- }
-
-
- get exportsArgument() {
- return (this.buildInfo && this.buildInfo.exportsArgument) || "exports";
- }
-
- get moduleArgument() {
- return (this.buildInfo && this.buildInfo.moduleArgument) || "module";
- }
-
- getExportsType(moduleGraph, strict) {
- switch (this.buildMeta && this.buildMeta.exportsType) {
- case "flagged":
- return strict ? "default-with-named" : "namespace";
- case "namespace":
- return "namespace";
- case "default":
- switch ( (this.buildMeta).defaultObject) {
- case "redirect":
- return "default-with-named";
- case "redirect-warn":
- return strict ? "default-only" : "default-with-named";
- default:
- return "default-only";
- }
- case "dynamic": {
- if (strict) return "default-with-named";
-
- const handleDefault = () => {
- switch ( (this.buildMeta).defaultObject) {
- case "redirect":
- case "redirect-warn":
- return "default-with-named";
- default:
- return "default-only";
- }
- };
- const exportInfo = moduleGraph.getReadOnlyExportInfo(
- this,
- "__esModule"
- );
- if (exportInfo.provided === false) {
- return handleDefault();
- }
- const target = exportInfo.getTarget(moduleGraph);
- if (
- !target ||
- !target.export ||
- target.export.length !== 1 ||
- target.export[0] !== "__esModule"
- ) {
- return "dynamic";
- }
- switch (
- target.module.buildMeta &&
- target.module.buildMeta.exportsType
- ) {
- case "flagged":
- case "namespace":
- return "namespace";
- case "default":
- return handleDefault();
- default:
- return "dynamic";
- }
- }
- default:
- return strict ? "default-with-named" : "dynamic";
- }
- }
-
- addPresentationalDependency(presentationalDependency) {
- if (this.presentationalDependencies === undefined) {
- this.presentationalDependencies = [];
- }
- this.presentationalDependencies.push(presentationalDependency);
- }
-
- addCodeGenerationDependency(codeGenerationDependency) {
- if (this.codeGenerationDependencies === undefined) {
- this.codeGenerationDependencies = [];
- }
- this.codeGenerationDependencies.push(codeGenerationDependency);
- }
-
- clearDependenciesAndBlocks() {
- if (this.presentationalDependencies !== undefined) {
- this.presentationalDependencies.length = 0;
- }
- if (this.codeGenerationDependencies !== undefined) {
- this.codeGenerationDependencies.length = 0;
- }
- super.clearDependenciesAndBlocks();
- }
-
- addWarning(warning) {
- if (this._warnings === undefined) {
- this._warnings = [];
- }
- this._warnings.push(warning);
- }
-
- getWarnings() {
- return this._warnings;
- }
-
- getNumberOfWarnings() {
- return this._warnings !== undefined ? this._warnings.length : 0;
- }
-
- addError(error) {
- if (this._errors === undefined) {
- this._errors = [];
- }
- this._errors.push(error);
- }
-
- getErrors() {
- return this._errors;
- }
-
- getNumberOfErrors() {
- return this._errors !== undefined ? this._errors.length : 0;
- }
-
- clearWarningsAndErrors() {
- if (this._warnings !== undefined) {
- this._warnings.length = 0;
- }
- if (this._errors !== undefined) {
- this._errors.length = 0;
- }
- }
-
- isOptional(moduleGraph) {
- let hasConnections = false;
- for (const r of moduleGraph.getIncomingConnections(this)) {
- if (
- !r.dependency ||
- !r.dependency.optional ||
- !r.isTargetActive(undefined)
- ) {
- return false;
- }
- hasConnections = true;
- }
- return hasConnections;
- }
-
- isAccessibleInChunk(chunkGraph, chunk, ignoreChunk) {
-
- for (const chunkGroup of chunk.groupsIterable) {
- if (!this.isAccessibleInChunkGroup(chunkGraph, chunkGroup)) return false;
- }
- return true;
- }
-
- isAccessibleInChunkGroup(chunkGraph, chunkGroup, ignoreChunk) {
- const queue = new Set([chunkGroup]);
-
- queueFor: for (const cg of queue) {
-
-
- for (const chunk of cg.chunks) {
- if (chunk !== ignoreChunk && chunkGraph.isModuleInChunk(this, chunk))
- continue queueFor;
- }
-
- if (chunkGroup.isInitial()) return false;
-
- for (const parent of chunkGroup.parentsIterable) queue.add(parent);
- }
-
- return true;
- }
-
- hasReasonForChunk(chunk, moduleGraph, chunkGraph) {
-
- for (const [
- fromModule,
- connections
- ] of moduleGraph.getIncomingConnectionsByOriginModule(this)) {
- if (!connections.some(c => c.isTargetActive(chunk.runtime))) continue;
- for (const originChunk of chunkGraph.getModuleChunksIterable(
- (fromModule)
- )) {
-
- if (!this.isAccessibleInChunk(chunkGraph, originChunk, chunk))
- return true;
- }
- }
- return false;
- }
-
- hasReasons(moduleGraph, runtime) {
- for (const c of moduleGraph.getIncomingConnections(this)) {
- if (c.isTargetActive(runtime)) return true;
- }
- return false;
- }
-
- toString() {
- return `Module[${this.debugId}: ${this.identifier()}]`;
- }
-
- needBuild(context, callback) {
- callback(
- null,
- !this.buildMeta ||
- this.needRebuild === Module.prototype.needRebuild ||
- deprecatedNeedRebuild(this, context)
- );
- }
-
- needRebuild(fileTimestamps, contextTimestamps) {
- return true;
- }
-
- updateHash(
- hash,
- context = {
- chunkGraph: ChunkGraph.getChunkGraphForModule(
- this,
- "Module.updateHash",
- "DEP_WEBPACK_MODULE_UPDATE_HASH"
- ),
- runtime: undefined
- }
- ) {
- const { chunkGraph, runtime } = context;
- hash.update(chunkGraph.getModuleGraphHash(this, runtime));
- if (this.presentationalDependencies !== undefined) {
- for (const dep of this.presentationalDependencies) {
- dep.updateHash(hash, context);
- }
- }
- super.updateHash(hash, context);
- }
-
- invalidateBuild() {
-
- }
-
-
- identifier() {
- const AbstractMethodError = require("./AbstractMethodError");
- throw new AbstractMethodError();
- }
-
-
- readableIdentifier(requestShortener) {
- const AbstractMethodError = require("./AbstractMethodError");
- throw new AbstractMethodError();
- }
-
-
- build(options, compilation, resolver, fs, callback) {
- const AbstractMethodError = require("./AbstractMethodError");
- throw new AbstractMethodError();
- }
-
- getSourceTypes() {
-
- if (this.source === Module.prototype.source) {
- return DEFAULT_TYPES_UNKNOWN;
- } else {
- return DEFAULT_TYPES_JS;
- }
- }
-
- source(dependencyTemplates, runtimeTemplate, type = "javascript") {
- if (this.codeGeneration === Module.prototype.codeGeneration) {
- const AbstractMethodError = require("./AbstractMethodError");
- throw new AbstractMethodError();
- }
- const chunkGraph = ChunkGraph.getChunkGraphForModule(
- this,
- "Module.source() is deprecated. Use Compilation.codeGenerationResults.getSource(module, runtime, type) instead",
- "DEP_WEBPACK_MODULE_SOURCE"
- );
-
- const codeGenContext = {
- dependencyTemplates,
- runtimeTemplate,
- moduleGraph: chunkGraph.moduleGraph,
- chunkGraph,
- runtime: undefined,
- codeGenerationResults: undefined
- };
- const sources = this.codeGeneration(codeGenContext).sources;
- return type ? sources.get(type) : sources.get(first(this.getSourceTypes()));
- }
-
-
- size(type) {
- const AbstractMethodError = require("./AbstractMethodError");
- throw new AbstractMethodError();
- }
-
- libIdent(options) {
- return null;
- }
-
- nameForCondition() {
- return null;
- }
-
- getConcatenationBailoutReason(context) {
- return `Module Concatenation is not implemented for ${this.constructor.name}`;
- }
-
- getSideEffectsConnectionState(moduleGraph) {
- return true;
- }
-
- codeGeneration(context) {
-
- const sources = new Map();
- for (const type of this.getSourceTypes()) {
- if (type !== "unknown") {
- sources.set(
- type,
- this.source(
- context.dependencyTemplates,
- context.runtimeTemplate,
- type
- )
- );
- }
- }
- return {
- sources,
- runtimeRequirements: new Set([
- RuntimeGlobals.module,
- RuntimeGlobals.exports,
- RuntimeGlobals.require
- ])
- };
- }
-
- chunkCondition(chunk, compilation) {
- return true;
- }
- hasChunkCondition() {
- return this.chunkCondition !== Module.prototype.chunkCondition;
- }
-
- updateCacheModule(module) {
- this.type = module.type;
- this.layer = module.layer;
- this.context = module.context;
- this.factoryMeta = module.factoryMeta;
- this.resolveOptions = module.resolveOptions;
- }
-
- getUnsafeCacheData() {
- return {
- factoryMeta: this.factoryMeta,
- resolveOptions: this.resolveOptions
- };
- }
-
- _restoreFromUnsafeCache(unsafeCacheData, normalModuleFactory) {
- this.factoryMeta = unsafeCacheData.factoryMeta;
- this.resolveOptions = unsafeCacheData.resolveOptions;
- }
-
- cleanupForCache() {
- this.factoryMeta = undefined;
- this.resolveOptions = undefined;
- }
-
- originalSource() {
- return null;
- }
-
- addCacheDependencies(
- fileDependencies,
- contextDependencies,
- missingDependencies,
- buildDependencies
- ) {}
-
- serialize(context) {
- const { write } = context;
- write(this.type);
- write(this.layer);
- write(this.context);
- write(this.resolveOptions);
- write(this.factoryMeta);
- write(this.useSourceMap);
- write(this.useSimpleSourceMap);
- write(
- this._warnings !== undefined && this._warnings.length === 0
- ? undefined
- : this._warnings
- );
- write(
- this._errors !== undefined && this._errors.length === 0
- ? undefined
- : this._errors
- );
- write(this.buildMeta);
- write(this.buildInfo);
- write(this.presentationalDependencies);
- write(this.codeGenerationDependencies);
- super.serialize(context);
- }
-
- deserialize(context) {
- const { read } = context;
- this.type = read();
- this.layer = read();
- this.context = read();
- this.resolveOptions = read();
- this.factoryMeta = read();
- this.useSourceMap = read();
- this.useSimpleSourceMap = read();
- this._warnings = read();
- this._errors = read();
- this.buildMeta = read();
- this.buildInfo = read();
- this.presentationalDependencies = read();
- this.codeGenerationDependencies = read();
- super.deserialize(context);
- }
- }
- makeSerializable(Module, "webpack/lib/Module");
- Object.defineProperty(Module.prototype, "hasEqualsChunks", {
- get() {
- throw new Error(
- "Module.hasEqualsChunks was renamed (use hasEqualChunks instead)"
- );
- }
- });
- Object.defineProperty(Module.prototype, "isUsed", {
- get() {
- throw new Error(
- "Module.isUsed was renamed (use getUsedName, isExportUsed or isModuleUsed instead)"
- );
- }
- });
- Object.defineProperty(Module.prototype, "errors", {
- get: util.deprecate(
-
- function () {
- if (this._errors === undefined) {
- this._errors = [];
- }
- return this._errors;
- },
- "Module.errors was removed (use getErrors instead)",
- "DEP_WEBPACK_MODULE_ERRORS"
- )
- });
- Object.defineProperty(Module.prototype, "warnings", {
- get: util.deprecate(
-
- function () {
- if (this._warnings === undefined) {
- this._warnings = [];
- }
- return this._warnings;
- },
- "Module.warnings was removed (use getWarnings instead)",
- "DEP_WEBPACK_MODULE_WARNINGS"
- )
- });
- Object.defineProperty(Module.prototype, "used", {
- get() {
- throw new Error(
- "Module.used was refactored (use ModuleGraph.getUsedExports instead)"
- );
- },
- set(value) {
- throw new Error(
- "Module.used was refactored (use ModuleGraph.setUsedExports instead)"
- );
- }
- });
- module.exports = Module;
|