WXL
3 天以前 9bce51f651aad297ef9eb6df832bfdaf1de05d84
node_modules/webpack/lib/hmr/LazyCompilationPlugin.js
@@ -10,7 +10,8 @@
const Dependency = require("../Dependency");
const Module = require("../Module");
const ModuleFactory = require("../ModuleFactory");
const { JS_TYPES } = require("../ModuleSourceTypesConstants");
const { JAVASCRIPT_TYPES } = require("../ModuleSourceTypeConstants");
const { JAVASCRIPT_TYPE } = require("../ModuleSourceTypeConstants");
const {
   WEBPACK_MODULE_TYPE_LAZY_COMPILATION_PROXY
} = require("../ModuleTypeConstants");
@@ -32,6 +33,8 @@
/** @typedef {import("../Module").NeedBuildCallback} NeedBuildCallback */
/** @typedef {import("../Module").NeedBuildContext} NeedBuildContext */
/** @typedef {import("../Module").SourceTypes} SourceTypes */
/** @typedef {import("../Module").Sources} Sources */
/** @typedef {import("../Module").RuntimeRequirements} RuntimeRequirements */
/** @typedef {import("../ModuleFactory").ModuleFactoryCallback} ModuleFactoryCallback */
/** @typedef {import("../ModuleFactory").ModuleFactoryCreateData} ModuleFactoryCreateData */
/** @typedef {import("../RequestShortener")} RequestShortener */
@@ -43,6 +46,7 @@
/** @typedef {{ client: string, data: string, active: boolean }} ModuleResult */
/**
 * Defines the backend api type used by this module.
 * @typedef {object} BackendApi
 * @property {(callback: (err?: (Error | null)) => void) => void} dispose
 * @property {(module: Module) => ModuleResult} module
@@ -56,6 +60,7 @@
]);
/**
 * Checks true, if the module should be selected.
 * @param {Options["test"]} test test option
 * @param {Module} module the module
 * @returns {boolean | null | string} true, if the module should be selected
@@ -78,6 +83,7 @@
class LazyCompilationDependency extends Dependency {
   /**
    * Creates an instance of LazyCompilationDependency.
    * @param {LazyCompilationProxyModule} proxyModule proxy module
    */
   constructor(proxyModule) {
@@ -94,6 +100,7 @@
   }
   /**
    * Returns an identifier to merge equal requests.
    * @returns {string | null} an identifier to merge equal requests
    */
   getResourceIdentifier() {
@@ -105,6 +112,7 @@
class LazyCompilationProxyModule extends Module {
   /**
    * Creates an instance of LazyCompilationProxyModule.
    * @param {string} context context
    * @param {Module} originalModule an original module
    * @param {string} request request
@@ -126,6 +134,7 @@
   }
   /**
    * Returns the unique identifier used to reference this module.
    * @returns {string} a unique identifier of the module
    */
   identifier() {
@@ -133,6 +142,7 @@
   }
   /**
    * Returns a human-readable identifier for this module.
    * @param {RequestShortener} requestShortener the request shortener
    * @returns {string} a user readable identifier of the module
    */
@@ -160,6 +170,7 @@
   }
   /**
    * Gets the library identifier.
    * @param {LibIdentOptions} options options
    * @returns {LibIdent | null} an identifier for library inclusion
    */
@@ -170,6 +181,7 @@
   }
   /**
    * Checks whether the module needs to be rebuilt for the current build state.
    * @param {NeedBuildContext} context context info
    * @param {NeedBuildCallback} callback callback function, returns true, if the module needs a rebuild
    * @returns {void}
@@ -179,6 +191,7 @@
   }
   /**
    * Builds the module using the provided compilation context.
    * @param {WebpackOptions} options webpack options
    * @param {Compilation} compilation the compilation
    * @param {ResolverWithOptions} resolver the resolver
@@ -205,13 +218,15 @@
   }
   /**
    * Returns the source types this module can generate.
    * @returns {SourceTypes} types available (do not mutate)
    */
   getSourceTypes() {
      return JS_TYPES;
      return JAVASCRIPT_TYPES;
   }
   /**
    * Returns the estimated size for the requested source type.
    * @param {string=} type the source type for which the size should be estimated
    * @returns {number} the estimated size of the module (must be non-zero)
    */
@@ -220,11 +235,14 @@
   }
   /**
    * Generates code and runtime requirements for this module.
    * @param {CodeGenerationContext} context context for code generation
    * @returns {CodeGenerationResult} result
    */
   codeGeneration({ runtimeTemplate, chunkGraph, moduleGraph }) {
      /** @type {Sources} */
      const sources = new Map();
      /** @type {RuntimeRequirements} */
      const runtimeRequirements = new Set();
      runtimeRequirements.add(RuntimeGlobals.module);
      const clientDep = /** @type {CommonJsRequireDependency} */ (
@@ -246,6 +264,7 @@
            Boolean(block)
         )}, module: module, onError: onError });`
      ]);
      /** @type {string} */
      let source;
      if (block) {
         const dep = block.dependencies[0];
@@ -290,7 +309,7 @@
            keepActive
         ]);
      }
      sources.set("javascript", new RawSource(source));
      sources.set(JAVASCRIPT_TYPE, new RawSource(source));
      return {
         sources,
         runtimeRequirements
@@ -298,6 +317,7 @@
   }
   /**
    * Updates the hash with the data contributed by this instance.
    * @param {Hash} hash the hash used to track dependencies
    * @param {UpdateHashContext} context context
    * @returns {void}
@@ -317,6 +337,7 @@
   }
   /**
    * Processes the provided data.
    * @param {ModuleFactoryCreateData} data data object
    * @param {ModuleFactoryCallback} callback callback
    * @returns {void}
@@ -332,6 +353,7 @@
}
/**
 * Defines the backend handler callback.
 * @callback BackendHandler
 * @param {Compiler} compiler compiler
 * @param {(err: Error | null, backendApi?: BackendApi) => void} callback callback
@@ -339,6 +361,7 @@
 */
/**
 * Defines the promise backend handler callback.
 * @callback PromiseBackendHandler
 * @param {Compiler} compiler compiler
 * @returns {Promise<BackendApi>} backend
@@ -349,6 +372,7 @@
/** @typedef {(module: Module) => boolean} TestFn */
/**
 * Defines the options type used by this module.
 * @typedef {object} Options options
 * @property {BackEnd} backend the backend
 * @property {boolean=} entries
@@ -360,6 +384,7 @@
class LazyCompilationPlugin {
   /**
    * Creates an instance of LazyCompilationPlugin.
    * @param {Options} options options
    */
   constructor({ backend, entries, imports, test }) {
@@ -370,7 +395,7 @@
   }
   /**
    * Apply the plugin
    * Applies the plugin by registering its hooks on the compiler.
    * @param {Compiler} compiler the compiler instance
    * @returns {void}
    */