| | |
| | | const NormalModule = require("./NormalModule"); |
| | | const RuntimeGlobals = require("./RuntimeGlobals"); |
| | | const WebpackError = require("./WebpackError"); |
| | | const { chunkHasCss } = require("./css/CssModulesPlugin"); |
| | | const ConstDependency = require("./dependencies/ConstDependency"); |
| | | const ImportMetaHotAcceptDependency = require("./dependencies/ImportMetaHotAcceptDependency"); |
| | | const ImportMetaHotDeclineDependency = require("./dependencies/ImportMetaHotDeclineDependency"); |
| | |
| | | /** @typedef {string[]} Requests */ |
| | | |
| | | /** |
| | | * Defines the hmr javascript parser hooks type used by this module. |
| | | * @typedef {object} HMRJavascriptParserHooks |
| | | * @property {SyncBailHook<[Expression | SpreadElement, Requests], void>} hotAcceptCallback |
| | | * @property {SyncBailHook<[CallExpression, Requests], void>} hotAcceptWithoutCallback |
| | |
| | | /** @typedef {Record<ChunkId, string>} ChunkRuntime */ |
| | | /** @typedef {Record<ChunkId, ModuleId[]>} ChunkModuleIds */ |
| | | |
| | | /** @typedef {{ updatedChunkIds: Set<ChunkId>, removedChunkIds: Set<ChunkId>, removedModules: Set<Module>, filename: string, assetInfo: AssetInfo }} HotUpdateMainContentByRuntimeItem */ |
| | | /** @typedef {Set<ChunkId>} ChunkIds */ |
| | | /** @typedef {Set<Module>} ModuleSet */ |
| | | |
| | | /** @typedef {{ updatedChunkIds: ChunkIds, removedChunkIds: ChunkIds, removedModules: ModuleSet, filename: string, assetInfo: AssetInfo }} HotUpdateMainContentByRuntimeItem */ |
| | | /** @typedef {Map<string, HotUpdateMainContentByRuntimeItem>} HotUpdateMainContentByRuntime */ |
| | | |
| | | /** @type {WeakMap<JavascriptParser, HMRJavascriptParserHooks>} */ |
| | |
| | | |
| | | class HotModuleReplacementPlugin { |
| | | /** |
| | | * Returns the attached hooks. |
| | | * @param {JavascriptParser} parser the parser |
| | | * @returns {HMRJavascriptParserHooks} the attached hooks |
| | | */ |
| | |
| | | } |
| | | |
| | | /** |
| | | * Apply the plugin |
| | | * Applies the plugin by registering its hooks on the compiler. |
| | | * @param {Compiler} compiler the compiler instance |
| | | * @returns {void} |
| | | */ |
| | |
| | | const runtimeRequirements = [RuntimeGlobals.module]; |
| | | |
| | | /** |
| | | * Creates an accept handler. |
| | | * @param {JavascriptParser} parser the parser |
| | | * @param {typeof ModuleHotAcceptDependency} ParamDependency dependency |
| | | * @returns {(expr: CallExpression) => boolean | undefined} callback |
| | |
| | | }; |
| | | |
| | | /** |
| | | * Creates a decline handler. |
| | | * @param {JavascriptParser} parser the parser |
| | | * @param {typeof ModuleHotDeclineDependency} ParamDependency dependency |
| | | * @returns {(expr: CallExpression) => boolean | undefined} callback |
| | |
| | | }; |
| | | |
| | | /** |
| | | * Creates a hmr expression handler. |
| | | * @param {JavascriptParser} parser the parser |
| | | * @returns {(expr: Expression) => boolean | undefined} callback |
| | | */ |
| | |
| | | }; |
| | | |
| | | /** |
| | | * Processes the provided parser. |
| | | * @param {JavascriptParser} parser the parser |
| | | * @returns {void} |
| | | */ |
| | |
| | | }; |
| | | |
| | | /** |
| | | * Apply import meta hot. |
| | | * @param {JavascriptParser} parser the parser |
| | | * @returns {void} |
| | | */ |
| | |
| | | const records = /** @type {Records} */ (compilation.records); |
| | | for (const chunk of compilation.chunks) { |
| | | /** |
| | | * Returns module hash. |
| | | * @param {Module} module module |
| | | * @returns {string} module hash |
| | | */ |
| | |
| | | |
| | | /** @type {HotUpdateMainContentByRuntime} */ |
| | | const hotUpdateMainContentByRuntime = new Map(); |
| | | /** @type {RuntimeSpec} */ |
| | | let allOldRuntime; |
| | | const chunkRuntime = |
| | | /** @type {ChunkRuntime} */ |
| | |
| | | hotUpdateMainContentByRuntime.set( |
| | | /** @type {string} */ (runtime), |
| | | { |
| | | /** @type {ChunkIds} */ |
| | | updatedChunkIds: new Set(), |
| | | /** @type {ChunkIds} */ |
| | | removedChunkIds: new Set(), |
| | | /** @type {ModuleSet} */ |
| | | removedModules: new Set(), |
| | | filename, |
| | | assetInfo |
| | |
| | | |
| | | /** @type {ChunkId | null} */ |
| | | let chunkId; |
| | | /** @type {undefined | Module[]} */ |
| | | let newModules; |
| | | /** @type {undefined | RuntimeModule[]} */ |
| | | let newRuntimeModules; |
| | | /** @type {undefined | RuntimeModule[]} */ |
| | | let newFullHashModules; |
| | | /** @type {undefined | RuntimeModule[]} */ |
| | | let newDependentHashModules; |
| | | /** @type {RuntimeSpec} */ |
| | | let newRuntime; |
| | | /** @type {RuntimeSpec} */ |
| | | let removedFromRuntime; |
| | | const currentChunk = find( |
| | | compilation.chunks, |
| | |
| | | } |
| | | } |
| | | const completelyRemovedModulesArray = [...completelyRemovedModules]; |
| | | /** @type {Map<string, Omit<HotUpdateMainContentByRuntimeItem, "filename">>} */ |
| | | const hotUpdateMainContentByFilename = new Map(); |
| | | for (const { |
| | | removedChunkIds, |
| | |
| | | filename, |
| | | { removedChunkIds, removedModules, updatedChunkIds, assetInfo } |
| | | ] of hotUpdateMainContentByFilename) { |
| | | /** @type {{ c: ChunkId[], r: ChunkId[], m: ModuleId[], css?: { r: ChunkId[] } }} */ |
| | | const hotUpdateMainJson = { |
| | | c: [...updatedChunkIds], |
| | | r: [...removedChunkIds], |
| | |
| | | ] |
| | | }; |
| | | |
| | | // Build CSS removed chunks list (chunks in updatedChunkIds that no longer have CSS) |
| | | /** @type {ChunkId[]} */ |
| | | const cssRemovedChunkIds = []; |
| | | if (compilation.options.experiments.css) { |
| | | for (const chunkId of updatedChunkIds) { |
| | | for (const /** @type {Chunk} */ chunk of compilation.chunks) { |
| | | if (chunk.id === chunkId) { |
| | | if (!chunkHasCss(chunk, chunkGraph)) { |
| | | cssRemovedChunkIds.push(chunkId); |
| | | } |
| | | break; |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | if (cssRemovedChunkIds.length > 0) { |
| | | hotUpdateMainJson.css = { r: cssRemovedChunkIds }; |
| | | } |
| | | |
| | | const source = new RawSource( |
| | | (filename.endsWith(".json") ? "" : "export default ") + |
| | | JSON.stringify(hotUpdateMainJson) |