GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — webpack/lib/Compilation.js at da7954b60924ffbc0b6daefeee05f9867663af7f · webpack/webpack Expand file tree/ Copy pathCompilation.jsMore file actions 6858 lines (6433 loc) · 210 KB / Copy pathCompilation.jsFile metadata and controls6858 lines (6433 loc) · 210 KB 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 /* MIT License http://www.opensource.org/licenses/mit-license.php Author Tobias Koppers @sokra */ "use strict"; const util = require("util"); const { AsyncParallelHook, AsyncSeriesBailHook, AsyncSeriesHook, AsyncSeriesWaterfallHook, HookMap, SyncBailHook, SyncHook, SyncWaterfallHook } = require("tapable"); const { CachedSource } = require("webpack-sources"); const { MultiItemCache } = require("./cache/CacheFacade"); const ErrorHelpers = require("./errors/ErrorHelpers"); const { makeWebpackError, tryRunOrWebpackError } = require("./errors/HookWebpackError"); const WebpackError = require("./errors/WebpackError"); const FileSystemInfo = require("./fs/FileSystemInfo"); const Chunk = require("./graph/Chunk"); const ChunkGraph = require("./graph/ChunkGraph"); const ChunkGroup = require("./graph/ChunkGroup"); const Dependency = require("./graph/Dependency"); const Entrypoint = require("./graph/Entrypoint"); const ModuleGraph = require("./graph/ModuleGraph"); const buildChunkGraph = require("./graph/buildChunkGraph"); const { LogType, Logger } = require("./logging/Logger"); const CodeGenerationResults = require("./module/CodeGenerationResults"); const Module = require("./module/Module"); const ModuleProfile = require("./module/ModuleProfile"); const { WEBPACK_MODULE_TYPE_RUNTIME } = require("./module/ModuleTypeConstants"); const LazyBarrels = require("./optimize/LazyBarrels"); const RuntimeGlobals = require("./runtime/RuntimeGlobals"); const Stats = require("./stats/Stats"); const StatsFactory = require("./stats/StatsFactory"); const StatsPrinter = require("./stats/StatsPrinter"); const ChunkTemplate = require("./template/ChunkTemplate"); const DependencyTemplates = require("./template/DependencyTemplates"); const MainTemplate = require("./template/MainTemplate"); const ModuleTemplate = require("./template/ModuleTemplate"); const RuntimeTemplate = require("./template/RuntimeTemplate"); const { equals: arrayEquals } = require("./util/ArrayHelpers"); const AsyncQueue = require("./util/AsyncQueue"); const LazySet = require("./util/LazySet"); const { getOrInsert } = require("./util/MapHelpers"); const WeakTupleMap = require("./util/WeakTupleMap"); const asyncLib = require("./util/async"); const { replayOptimizationBailouts } = require("./util/buildDiagnostics"); const { cachedCleverMerge } = require("./util/cleverMerge"); const { compareErrors, compareIds, compareModulesByIdentifier, compareSelect, concatComparators } = require("./util/comparators"); const createHash = require("./util/createHash"); const { arrayToSetDeprecation, createFakeHook, soonFrozenObjectDeprecation } = require("./util/deprecation"); const memoize = require("./util/memoize"); const processAsyncTree = require("./util/processAsyncTree"); const { getRuntimeKey } = require("./util/runtime"); const { isSourceEqual } = require("./util/source"); const getModuleStoreError = memoize(() => require("./errors/ModuleStoreError")); const getModuleRestoreError = memoize(() => require("./errors/ModuleRestoreError") ); const getModuleNotFoundError = memoize(() => require("./errors/ModuleNotFoundError") ); const getModuleHashingError = memoize(() => require("./errors/ModuleHashingError") ); const getModuleDependencyWarning = memoize(() => require("./errors/ModuleDependencyWarning") ); const getModuleDependencyError = memoize(() => require("./errors/ModuleDependencyError") ); const getCodeGenerationError = memoize(() => require("./errors/CodeGenerationError") ); const getChunkRenderError = memoize(() => require("./errors/ChunkRenderError")); const getBuildCycleError = memoize(() => require("./errors/BuildCycleError")); const { toError } = ErrorHelpers; /** @import { Source } from "webpack-sources" */ /** * @import { * OutputNormalized as OutputOptions, * HashFunction, * HashDigest, * HashDigestLength, * StatsOptions, * Plugins, * ResolveOptions * } from "../declarations/WebpackOptions" */ /** * @import { * WebpackOptionsNormalizedWithDefaults as WebpackOptions, * OutputNormalizedWithDefaults as OutputOptionsWithDefaults * } from "./config/defaults" */ /** @import AsyncDependenciesBlock from "./graph/AsyncDependenciesBlock" */ /** @import Cache from "./cache/Cache" */ /** @import CacheFacade from "./cache/CacheFacade" */ /** @import { ChunkName, ChunkId } from "./graph/Chunk" */ /** @import { ChunkGroupOptions } from "./graph/ChunkGroup" */ /** * @import Compiler, { * CompilationParams, * MemCache, * WeakReferences, * ModuleMemCachesItem, * Records * } from "./Compiler" */ /** @import DependenciesBlock from "./graph/DependenciesBlock" */ /** @import { DependencyLocation, ReferencedExports } from "./graph/Dependency" */ /** @typedef {import("./graph/Entrypoint").EntryOptions} EntryOptions */ /** * @import { * NameForCondition, * BuildInfo, * ValueCacheVersions, * RuntimeRequirements, * SourceTypes, * SourceType, * FactoryMeta, * CodeGenerationResult * } from "./module/Module" */ /** * @import NormalModule, { * NormalModuleCompilationHooks, * AnyLoaderContext, * ParserOptions, * GeneratorOptions * } from "./module/NormalModule" */ /** * @import ModuleFactory, { * ModuleFactoryCreateDataContextInfo, * ModuleFactoryResult * } from "./module/ModuleFactory" */ /** @import { ModuleId } from "./graph/ChunkGraph" */ /** @import ModuleGraphConnection from "./graph/ModuleGraphConnection" */ /** @import RequestShortener from "./util/RequestShortener" */ /** @import RuntimeModule from "./runtime/RuntimeModule" */ /** * @import { * RenderManifestEntry, * RenderManifestEntryTemplated, * RenderManifestOptions * } from "./template/Template" */ /** * One language's source embedded in another's output. * @typedef {object} EmbeddedSourceInfo * @property {SourceType} type the embedded source's type, e.g. `"css"` / `"html"` * @property {SourceType} hostType the type of the source it is embedded in, e.g. `"javascript"` * @property {Module} module the module being generated * @property {string=} as which of that language's productions this is, where more than one can be embedded — a `style=""` holds `"block-contents"`, an inline `<style>` a whole `"stylesheet"`. Absent where the language has only one */ /** * @import { * StatsAsset, * StatsError, * StatsModule * } from "./stats/DefaultStatsFactoryPlugin" */ /** @import Hash from "./util/Hash" */ /** * Defines the shared type used by this module. * @template T * @typedef {import("tapable").AsArray<T>} AsArray<T> */ /** * Defines the shared type used by this module. * @template T * @typedef {import("./util/deprecation").FakeHook<T>} FakeHook<T> */ /** @import { RuntimeSpec } from "./util/runtime" */ /** @import { InputFileSystem } from "./fs/fs" */ /** * Defines the callback callback. * @callback Callback * @param {(WebpackError | null)=} err * @returns {void} */ /** * Defines the module callback callback. * @callback ModuleCallback * @param {WebpackError | null=} err * @param {Module | null=} result * @returns {void} */ /** * Defines the module factory result callback callback. * @callback ModuleFactoryResultCallback * @param {WebpackError | null=} err * @param {ModuleFactoryResult | null=} result * @returns {void} */ /** * Defines the module or module factory result callback callback. * @callback ModuleOrModuleFactoryResultCallback * @param {WebpackError | null=} err * @param {Module | ModuleFactoryResult | null=} result * @returns {void} */ /** * Defines the execute module callback callback. * @callback ExecuteModuleCallback * @param {WebpackError | null=} err * @param {ExecuteModuleResult | null=} result * @returns {void} */ /** @typedef {new (...args: EXPECTED_ANY[]) => Dependency} DependencyConstructor */ /** @typedef {Record<string, Source>} CompilationAssets */ /** * Defines the available modules chunk group mapping type used by this module. * @typedef {object} AvailableModulesChunkGroupMapping * @property {ChunkGroup} chunkGroup * @property {Set<Module>} availableModules * @property {boolean} needCopy */ /** * Defines the dependencies block like type used by this module. * @typedef {object} DependenciesBlockLike * @property {Dependency[]} dependencies * @property {AsyncDependenciesBlock[]} blocks */ /** @typedef {Set<Chunk>} Chunks */ /** * Defines the chunk path data type used by this module. * @typedef {object} ChunkPathData * @property {string | number} id * @property {string=} name * @property {string} hash * @property {HashWithLengthFunction=} hashWithLength * @property {HashWithDigestFunction=} hashWithDigest builds `[chunkhash:<digest>]` per chunk in the runtime chunk-filename map * @property {(Record<string, string>)=} contentHash * @property {(Record<string, HashWithLengthFunction>)=} contentHashWithLength * @property {(Record<string, HashWithDigestFunction>)=} contentHashWithDigest builds `[contenthash:<digest>]` per chunk in the runtime chunk-filename map */ /** * Defines the chunk hash context type used by this module. * @typedef {object} ChunkHashContext * @property {CodeGenerationResults} codeGenerationResults results of code generation * @property {RuntimeTemplate} runtimeTemplate the runtime template * @property {ModuleGraph} moduleGraph the module graph * @property {ChunkGraph} chunkGraph the chunk graph */ /** * Defines the runtime requirements context type used by this module. * @typedef {object} RuntimeRequirementsContext * @property {ChunkGraph} chunkGraph the chunk graph * @property {CodeGenerationResults} codeGenerationResults the code generation results */ /** * Defines the execute module options type used by this module. * @typedef {object} ExecuteModuleOptions * @property {EntryOptions=} entryOptions */ /** @typedef {LazySet<string>} FileSystemDependencies */ /** @typedef {EXPECTED_ANY} ExecuteModuleExports */ /** * Defines the execute module result type used by this module. * @typedef {object} ExecuteModuleResult * @property {ExecuteModuleExports} exports * @property {boolean} cacheable * @property {string[]} notCacheableReasons reasons why the executed modules are not cacheable * @property {ExecuteModuleAssets} assets * @property {FileSystemDependencies} fileDependencies * @property {FileSystemDependencies} contextDependencies * @property {FileSystemDependencies} missingDependencies * @property {FileSystemDependencies} buildDependencies */ /** * Defines the execute module object type used by this module. * @typedef {object} ExecuteModuleObject * @property {string=} id module id * @property {ExecuteModuleExports} exports exports * @property {boolean} loaded is loaded * @property {Error=} error error */ /** * Defines the execute module argument type used by this module. * @typedef {object} ExecuteModuleArgument * @property {Module} module * @property {ExecuteModuleObject=} moduleObject * @property {CodeGenerationResult} codeGenerationResult */ /** @typedef {((id: string) => ExecuteModuleExports) & { i?: ((options: ExecuteOptions) => void)[], c?: Record<string, ExecuteModuleObject>, p?: string }} WebpackRequire */ /** * Defines the execute options type used by this module. * @typedef {object} ExecuteOptions * @property {string=} id module id * @property {ExecuteModuleObject} module module * @property {WebpackRequire} require require function */ /** @typedef {Map<string, { source: Source, info: AssetInfo | undefined }>} ExecuteModuleAssets */ /** * Defines the execute module context type used by this module. * @typedef {object} ExecuteModuleContext * @property {ExecuteModuleAssets} assets * @property {Chunk} chunk * @property {ChunkGraph} chunkGraph * @property {WebpackRequire=} __webpack_require__ */ /** * Defines the entry data type used by this module. * @typedef {object} EntryData * @property {Dependency[]} dependencies dependencies of the entrypoint that should be evaluated at startup * @property {Dependency[]} includeDependencies dependencies of the entrypoint that should be included but not evaluated * @property {EntryOptions} options options of the entrypoint */ /** * Defines the log entry type used by this module. * @typedef {object} LogEntry * @property {keyof LogType} type * @property {EXPECTED_ANY[]=} args * @property {number} time * @property {string[]=} trace */ /** * Where an asset which is a symbolic link points, as the link itself spells it. * @typedef {object} AssetSymlink * @property {string} target what the link points at, left as it is written * @property {boolean} isDirectory whether it points at a directory, which is what Windows needs in order to create one */ /** * Access and modification times an asset carries onto the file it is written to. * @typedef {object} AssetTimestamps * @property {number} atime last access time, in milliseconds * @property {number} mtime last modification time, in milliseconds */ /** * Defines the known asset info type used by this module. * @typedef {object} KnownAssetInfo * @property {boolean=} immutable true, if the asset can be long term cached forever (contains a hash) * @property {boolean=} minimized whether the asset is minimized * @property {string | string[]=} fullhash the value(s) of the full hash used for this asset * @property {string | string[]=} chunkhash the value(s) of the chunk hash used for this asset * @property {string | string[]=} modulehash the value(s) of the module hash used for this asset * @property {string | string[]=} contenthash the value(s) of the content hash used for this asset * @property {Record<string, string>=} contenthashDigest maps a `[contenthash:<digest>]` value to its digest, so `RealContentHashPlugin` re-encodes the recomputed hash in it * @property {string=} sourceFilename when asset was created from a source file (potentially transformed), the original filename relative to compilation context * @property {boolean=} copied true, when the asset was copied from a file by `output.copy` * @property {AssetSymlink=} symlink when set, the asset is emitted as a symbolic link rather than as its content * @property {number=} mode when set, the file the asset is written to is given these permissions * @property {AssetTimestamps=} timestamps when set, the file the asset is written to is stamped with these times * @property {number=} size size in bytes, only set after asset has been emitted * @property {boolean=} development true, when asset is only used for development and doesn't count towards user-facing assets * @property {boolean=} hotModuleReplacement true, when asset ships data for updating an existing application (HMR) * @property {boolean=} javascriptModule true, when asset is javascript and an ESM * @property {boolean=} manifest true, when file is a manifest * @property {Record<string, null | string | string[]>=} related object of pointers to other assets, keyed by type of relation (only points from parent to child) */ /** @typedef {KnownAssetInfo & Record<string, EXPECTED_ANY>} AssetInfo */ /** @typedef {{ path: string, info: AssetInfo }} InterpolatedPathAndAssetInfo */ /** * Defines the asset type used by this module. * @typedef {object} Asset * @property {string} name the filename of the asset * @property {Source} source source of the asset * @property {AssetInfo} info info about the asset */ /** @typedef {(length: number) => string} HashWithLengthFunction */ /** @typedef {(digest: string, length?: number) => string} HashWithDigestFunction */ /** * Defines the module path data type used by this module. * @typedef {object} ModulePathData * @property {string | number} id * @property {string} hash * @property {HashWithLengthFunction=} hashWithLength */ /** @typedef {(id: string | number) => string | number} PrepareIdFunction */ /** * Defines the path data type used by this module. * @typedef {object} PathData * @property {ChunkGraph=} chunkGraph * @property {string=} hash * @property {string=} fullHash untruncated compilation hash, for re-encoding `[fullhash:<digest>]` * @property {string=} fullHashDigest digest `fullHash` is encoded in (defaults to `hashDigest`) * @property {HashWithLengthFunction=} hashWithLength * @property {HashWithDigestFunction=} hashWithDigest builds `[fullhash:<digest>]`/`[hash:<digest>]` in the runtime chunk-filename context, where it throws because a runtime `getFullHash()` expression cannot be re-encoded * @property {(Chunk | ChunkPathData)=} chunk * @property {(Module | ModulePathData)=} module * @property {RuntimeSpec=} runtime * @property {string=} filename * @property {string=} basename * @property {string=} query * @property {string=} contentHashType * @property {string=} contentHash * @property {string=} contentHashFull untruncated module/asset content hash, for re-encoding `[contenthash:<digest>]` from full entropy * @property {HashWithLengthFunction=} contentHashWithLength * @property {string=} hashDigest digest the stored hashes are encoded in (for `[hash:<digest>]`) * @property {boolean=} realContentHash whether `optimization.realContentHash` recomputes content hashes (records an inline `[contenthash:<digest>]` so it re-encodes in that digest) * @property {boolean=} hashAsFullHash treat `[hash]` as `[fullhash]` rather than the module hash (CSS local idents) * @property {boolean=} noChunkHash * @property {string=} url * @property {string=} local * @property {string=} uniqueName * @property {PrepareIdFunction=} prepareId */ /** * Path data narrowed for the chunk filename / chunk asset interpolation context, * where `chunk` is always provided. Use as the type parameter to `TemplatePathFn` * for callbacks that receive a chunk context (for example `output.filename`, * `output.chunkFilename`, `output.cssFilename`, `output.cssChunkFilename`, * `optimization.splitChunks.cacheGroups[*].filename`). * @typedef {PathData & { chunk: Chunk | ChunkPathData }} PathDataChunk */ /** * Path data narrowed for the module asset interpolation context, where `module` * and `chunkGraph` are always provided. Use as the type parameter to * `TemplatePathFn` for callbacks that receive a module context (for example * `output.assetModuleFilename`, the per-module `generator.filename` / * `generator.outputPath`, and `module.parser.css.localIdentName`). * @typedef {PathData & { module: Module | ModulePathData, chunkGraph: ChunkGraph }} PathDataModule */ /** @typedef {"module" | "chunk" | "root-of-chunk" | "nested"} ExcludeModulesType */ /** * Defines the known normalized stats options type used by this module. * @typedef {object} KnownNormalizedStatsOptions * @property {string} context * @property {RequestShortener} requestShortener * @property {string | false} chunksSort * @property {string | false} modulesSort * @property {string | false} chunkModulesSort * @property {string | false} nestedModulesSort * @property {string | false} assetsSort * @property {boolean} ids * @property {boolean} cachedAssets * @property {boolean} groupAssetsByEmitStatus * @property {boolean} groupAssetsByPath * @property {boolean} groupAssetsByExtension * @property {number} assetsSpace * @property {((value: string, asset: StatsAsset) => boolean)[]} excludeAssets * @property {((name: string, module: StatsModule, type: ExcludeModulesType) => boolean)[]} excludeModules * @property {((warning: StatsError, textValue: string) => boolean)[]} warningsFilter * @property {boolean} cachedModules * @property {boolean} orphanModules * @property {boolean} dependentModules * @property {boolean} runtimeModules * @property {boolean} groupModulesByCacheStatus * @property {boolean} groupModulesByLayer * @property {boolean} groupModulesByAttributes * @property {boolean} groupModulesByPath * @property {boolean} groupModulesByExtension * @property {boolean} groupModulesByType * @property {boolean | "auto"} entrypoints * @property {boolean} chunkGroups * @property {boolean} chunkGroupAuxiliary * @property {boolean} chunkGroupChildren * @property {number} chunkGroupMaxAssets * @property {number} modulesSpace * @property {number} chunkModulesSpace * @property {number} nestedModulesSpace * @property {false | "none" | "error" | "warn" | "info" | "log" | "verbose"} logging * @property {((value: string) => boolean)[]} loggingDebug * @property {boolean} loggingTrace * @property {EXPECTED_ANY} _env */ /** @typedef {KnownNormalizedStatsOptions & Omit<StatsOptions, keyof KnownNormalizedStatsOptions> & Record<string, EXPECTED_ANY>} NormalizedStatsOptions */ /** * Defines the known create stats options context type used by this module. * @typedef {object} KnownCreateStatsOptionsContext * @property {boolean=} forToString */ /** @typedef {KnownCreateStatsOptionsContext & Record<string, EXPECTED_ANY>} CreateStatsOptionsContext */ /** @typedef {{ module: Module, hash: string, runtime: RuntimeSpec, runtimes: RuntimeSpec[] }} CodeGenerationJob */ /** @typedef {CodeGenerationJob[]} CodeGenerationJobs */ /** @typedef {{ javascript: ModuleTemplate }} ModuleTemplates */ /** @typedef {Set<Module>} NotCodeGeneratedModules */ /** @type {AssetInfo} */ const EMPTY_ASSET_INFO = Object.freeze({}); // TODO in the next major release: remove const deprecatedNormalModuleLoaderHook = util.deprecate( /** * Handles the callback logic for this hook. * @param {Compilation} compilation compilation * @returns {NormalModuleCompilationHooks["loader"]} hooks */ (compilation) => require("./module/NormalModule").getCompilationHooks(compilation).loader, "Compilation.hooks.normalModuleLoader was moved to NormalModule.getCompilationHooks(compilation).loader", "DEP_WEBPACK_COMPILATION_NORMAL_MODULE_LOADER_HOOK" ); // TODO in the next major release: remove /** * Define removed module templates. * @param {ModuleTemplates | undefined} moduleTemplates module templates */ const defineRemovedModuleTemplates = (moduleTemplates) => { Object.defineProperties(moduleTemplates, { asset: { enumerable: false, configurable: false, get: () => { throw new WebpackError( "Compilation.moduleTemplates.asset has been removed" ); } }, webassembly: { enumerable: false, configurable: false, get: () => { throw new WebpackError( "Compilation.moduleTemplates.webassembly has been removed" ); } } }); moduleTemplates = undefined; }; const byId = compareSelect((c) => c.id, compareIds); const byNameOrHash = concatComparators( compareSelect((c) => c.name, compareIds), compareSelect((c) => c.fullHash, compareIds) ); /** * Defines the known unsafe cache data type used by this module. * @typedef {object} KnownUnsafeCacheData * @property {FactoryMeta=} factoryMeta factory meta * @property {ResolveOptions=} resolveOptions resolve options * @property {ParserOptions=} parserOptions * @property {GeneratorOptions=} generatorOptions */ /** @typedef {KnownUnsafeCacheData & Record<string, EXPECTED_ANY>} UnsafeCacheData */ /** * Defines the module with restore from unsafe cache type used by this module. * @typedef {Module & { restoreFromUnsafeCache?: (unsafeCacheData: UnsafeCacheData, moduleFactory: ModuleFactory, compilationParams: CompilationParams) => void }} ModuleWithRestoreFromUnsafeCache */ /** @typedef {(module: Module) => boolean} UnsafeCachePredicate */ /** @type {WeakMap<Dependency, ModuleWithRestoreFromUnsafeCache | null>} */ const unsafeCacheDependencies = new WeakMap(); /** @type {WeakMap<ModuleWithRestoreFromUnsafeCache, UnsafeCacheData>} */ const unsafeCacheData = new WeakMap(); /** @typedef {EXPECTED_OBJECT} DependencyReportCacheToken */ /** * Renewed when the module or a transitively referenced module is rebuilt. * @type {WeakMap<Module, DependencyReportCacheToken>} */ const dependencyReportCacheTokens = new WeakMap(); /** * Modules known to have no dependency errors/warnings, per cache token. * @type {WeakMap<DependencyReportCacheToken, WeakSet<Module>>} */ const modulesWithoutProblems = new WeakMap(); /** * Reduce affect type. * @param {Readonly<ModuleGraphConnection[]>} connections connections * @returns {symbol | boolean} result */ const reduceAffectType = (connections) => { let affected = false; for (const { dependency } of connections) { if (!dependency) continue; const type = dependency.couldAffectReferencingModule(); if (type === Dependency.TRANSITIVE) return Dependency.TRANSITIVE; if (type === false) continue; affected = true; } return affected; }; /** @typedef {{ id: ModuleId, modules?: Map<Module, string>, blocks?: (ChunkId | null)[], sourceTypes?: SourceTypes }} References */ /** @typedef {Map<Module, WeakTupleMap<EXPECTED_ANY[], EXPECTED_ANY>>} ModuleMemCaches */ /** @typedef {{ chunk: Chunk, load: () => Promise<EXPECTED_ANY>, create: (loaded: EXPECTED_ANY) => RuntimeModule, chunkGraph: ChunkGraph }} PendingRuntimeModule */ class Compilation { /** * Creates an instance of Compilation. * @param {Compiler} compiler the compiler which created the compilation * @param {CompilationParams} params the compilation parameters */ constructor(compiler, params) { /** @type {boolean} */ this._backCompat = compiler._backCompat; const getNormalModuleLoader = () => deprecatedNormalModuleLoaderHook(this); /** @typedef {{ additionalAssets?: boolean | ((assets: CompilationAssets) => void) }} ProcessAssetsAdditionalOptions */ /** @type {AsyncSeriesHook<[CompilationAssets], ProcessAssetsAdditionalOptions>} */ const processAssetsHook = new AsyncSeriesHook(["assets"]); /** @type {Set<string>} */ let savedAssets = new Set(); /** * Returns new assets. * @param {CompilationAssets} assets assets * @returns {CompilationAssets} new assets */ const popNewAssets = (assets) => { /** @type {undefined | CompilationAssets} */ let newAssets; for (const file of Object.keys(assets)) { if (savedAssets.has(file)) continue; if (newAssets === undefined) { newAssets = Object.create(null); } /** @type {CompilationAssets} */ (newAssets)[file] = assets[file]; savedAssets.add(file); } return /** @type {CompilationAssets} */ (newAssets); }; processAssetsHook.intercept({ name: "Compilation", call: () => { savedAssets = new Set(Object.keys(this.assets)); }, register: (tap) => { const { type, name } = tap; const { fn, additionalAssets, ...remainingTap } = tap; const additionalAssetsFn = additionalAssets === true ? fn : additionalAssets; /** @typedef {WeakSet<CompilationAssets>} ProcessedAssets */ /** @type {ProcessedAssets | undefined} */ const processedAssets = additionalAssetsFn ? new WeakSet() : undefined; /** * Gets available assets. * @param {CompilationAssets} assets to be processed by additionalAssetsFn * @returns {CompilationAssets} available assets */ const getAvailableAssets = (assets) => { /** @type {CompilationAssets} */ const availableAssets = {}; for (const file of Object.keys(assets)) { // https://github.com/webpack-contrib/compression-webpack-plugin/issues/390 if (this.assets[file]) { availableAssets[file] = assets[file]; } } return availableAssets; }; switch (type) { case "sync": if (additionalAssetsFn) { this.hooks.processAdditionalAssets.tap(name, (assets) => { if ( /** @type {ProcessedAssets} */ (processedAssets).has(this.assets) ) { additionalAssetsFn(getAvailableAssets(assets)); } }); } return { ...remainingTap, type: "async", /** * Processes the provided asset. * @param {CompilationAssets} assets assets * @param {(err?: Error | null, result?: void) => void} callback callback * @returns {void} */ fn: (assets, callback) => { try { fn(assets); } catch (err) { return callback(/** @type {Error} */ (err)); } if (processedAssets !== undefined) { processedAssets.add(this.assets); } const newAssets = popNewAssets(assets); if (newAssets !== undefined) { this.hooks.processAdditionalAssets.callAsync( newAssets, callback ); return; } callback(); } }; case "async": if (additionalAssetsFn) { this.hooks.processAdditionalAssets.tapAsync( name, (assets, callback) => { if ( /** @type {ProcessedAssets} */ (processedAssets).has(this.assets) ) { return additionalAssetsFn( getAvailableAssets(assets), callback ); } callback(); } ); } return { ...remainingTap, /** * Processes the provided asset. * @param {CompilationAssets} assets assets * @param {(err?: Error | null, result?: void) => void} callback callback * @returns {void} */ fn: (assets, callback) => { fn( assets, /** * Handles the callback logic for this hook. * @param {Error} err err * @returns {void} */ (err) => { if (err) return callback(err); if (processedAssets !== undefined) { processedAssets.add(this.assets); } const newAssets = popNewAssets(assets); if (newAssets !== undefined) { this.hooks.processAdditionalAssets.callAsync( newAssets, callback ); return; } callback(); } ); } }; case "promise": if (additionalAssetsFn) { this.hooks.processAdditionalAssets.tapPromise(name, (assets) => { if ( /** @type {ProcessedAssets} */ (processedAssets).has(this.assets) ) { return additionalAssetsFn(getAvailableAssets(assets)); } return Promise.resolve(); }); } return { ...remainingTap, /** * Returns result. * @param {CompilationAssets} assets assets * @returns {Promise<CompilationAssets>} result */ fn: (assets) => { const p = fn(assets); if (!p || !p.then) return p; return p.then(() => { if (processedAssets !== undefined) { processedAssets.add(this.assets); } const newAssets = popNewAssets(assets); if (newAssets !== undefined) { return this.hooks.processAdditionalAssets.promise( newAssets ); } }); } }; } } }); /** @type {SyncHook<[CompilationAssets]>} */ const afterProcessAssetsHook = new SyncHook(["assets"]); /** * Creates a process assets hook. * @template T * @param {string} name name of the hook * @param {number} stage new stage * @param {() => AsArray<T>} getArgs get old hook function args * @param {string=} code deprecation code (not deprecated when unset) * @returns {FakeHook<Pick<AsyncSeriesHook<T>, "tap" | "tapAsync" | "tapPromise" | "name">> | undefined} fake hook which redirects */ const createProcessAssetsHook = (name, stage, getArgs, code) => { if (!this._backCompat && code) return; /** * Returns error message. * @param {string} reason reason * @returns {string} error message */ const errorMessage = ( reason ) => `Can't automatically convert plugin using Compilation.hooks.${name} to Compilation.hooks.processAssets because ${reason}. BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a single Compilation.hooks.processAssets hook.`; /** * Normalizes tap options for migrated process-assets hooks. * @param {string | (import("tapable").TapOptions & { name: string } & ProcessAssetsAdditionalOptions)} options hook options * @returns {import("tapable").TapOptions & { name: string } & ProcessAssetsAdditionalOptions} modified options */ const getOptions = (options) => { if (typeof options === "string") options = { name: options }; if (options.stage) { throw new Error(errorMessage("it's using the 'stage' option")); } return { ...options, stage }; }; return createFakeHook( { name, /** @type {AsyncSeriesHook<T>["intercept"]} */ intercept(_interceptor) { throw new Error(errorMessage("it's using 'intercept'")); }, /** @type {AsyncSeriesHook<T>["tap"]} */ tap: (options, fn) => { processAssetsHook.tap(getOptions(options), () => fn(...getArgs())); }, /** @type {AsyncSeriesHook<T>["tapAsync"]} */ tapAsync: (options, fn) => { processAssetsHook.tapAsync( getOptions(options), (assets, callback) => /** @type {EXPECTED_ANY} */ (fn)(...getArgs(), callback) ); }, /** @type {AsyncSeriesHook<T>["tapPromise"]} */ tapPromise: (options, fn) => { processAssetsHook.tapPromise(getOptions(options), () => fn(...getArgs()) ); } }, `${name} is deprecated (use Compilation.hooks.processAssets instead and use one of Compilation.PROCESS_ASSETS_STAGE_* as stage option)`, code ); }; this.hooks = Object.freeze({ /** @type {SyncHook<[Module]>} */ buildModule: new SyncHook(["module"]), /** @type {SyncHook<[Module]>} */ rebuildModule: new SyncHook(["module"]), /** @type {SyncHook<[Module, WebpackError]>} */ failedModule: new SyncHook(["module", "error"]), /** @type {SyncHook<[Module]>} */ succeedModule: new SyncHook(["module"]), /** @type {SyncHook<[Module]>} */ stillValidModule: new SyncHook(["module"]), /** @type {SyncHook<[Dependency, EntryOptions]>} */ addEntry: new SyncHook(["entry", "options"]), /** @type {SyncHook<[Dependency, EntryOptions, Error]>} */ failedEntry: new SyncHook(["entry", "options", "error"]), /** @type {SyncHook<[Dependency, EntryOptions, Module]>} */ succeedEntry: new SyncHook(["entry", "options", "module"]), /** @type {SyncWaterfallHook<[ReferencedExports, Dependency, RuntimeSpec]>} */ dependencyReferencedExports: new SyncWaterfallHook([ "referencedExports", "dependency", "runtime" ]), /** * @type {SyncHook<[ExecuteModuleArgument, ExecuteModuleContext]>} * @since 5.32.0 */ executeModule: new SyncHook(["options", "context"]), /** * @type {AsyncParallelHook<[ExecuteModuleArgument, ExecuteModuleContext]>} * @since 5.33.0 */ prepareModuleExecution: new AsyncParallelHook(["options", "context"]), /** @type {AsyncSeriesHook<[Iterable<Module>]>} */ finishModules: new AsyncSeriesHook(["modules"]), /** @type {AsyncSeriesHook<[Module]>} */ finishRebuildingModule: new AsyncSeriesHook(["module"]), /** @type {SyncHook<[]>} */ unseal: new SyncHook([]), /** @type {SyncHook<[]>} */ seal: new SyncHook([]), /** @type {SyncHook<[]>} */ beforeChunks: new SyncHook([]), /** * The `afterChunks` hook is called directly after the chunks and module graph have * been created and before the chunks and modules have been optimized. This hook is useful to * inspect, analyze, and/or modify the chunk graph. * @type {SyncHook<[Iterable<Chunk>]>} */ afterChunks: new SyncHook(["chunks"]), /** @type {SyncBailHook<[Iterable<Module>], boolean | void>} */ optimizeDependencies: new SyncBailHook(["modules"]), /** @type {SyncHook<[Iterable<Module>]>} */ afterOptimizeDependencies: new SyncHook(["modules"]), /** @type {SyncHook<[]>} */ optimize: new SyncHook([]), /** @type {SyncBailHook<[Iterable<Module>], boolean | void>} */ optimizeModules: new SyncBailHook(["modules"]), /** @type {SyncHook<[Iterable<Module>]>} */ afterOptimizeModules: new SyncHook(["modules"]), /** @type {SyncBailHook<[Iterable<Chunk>, ChunkGroup[]], boolean | void>} */ optimizeChunks: new SyncBailHook(["chunks", "chunkGroups"]), /** @type {SyncHook<[Iterable<Chunk>, ChunkGroup[]]>} */ afterOptimizeChunks: new SyncHook(["chunks", "chunkGroups"]), /** @type {AsyncSeriesHook<[Iterable<Chunk>, Iterable<Module>]>} */ optimizeTree: new AsyncSeriesHook(["chunks", "modules"]), |
| You are visitor 01402792 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |