feat: refactoring project
This commit is contained in:
91
node_modules/webpack/lib/MainTemplate.js
generated
vendored
91
node_modules/webpack/lib/MainTemplate.js
generated
vendored
@@ -10,6 +10,7 @@ const util = require("util");
|
||||
const RuntimeGlobals = require("./RuntimeGlobals");
|
||||
const memoize = require("./util/memoize");
|
||||
|
||||
/** @typedef {import("tapable").Tap} Tap */
|
||||
/** @typedef {import("webpack-sources").ConcatSource} ConcatSource */
|
||||
/** @typedef {import("webpack-sources").Source} Source */
|
||||
/** @typedef {import("../declarations/WebpackOptions").Output} OutputOptions */
|
||||
@@ -17,15 +18,24 @@ const memoize = require("./util/memoize");
|
||||
/** @typedef {import("./Chunk")} Chunk */
|
||||
/** @typedef {import("./Compilation")} Compilation */
|
||||
/** @typedef {import("./Compilation").AssetInfo} AssetInfo */
|
||||
/** @typedef {import("./Compilation").InterpolatedPathAndAssetInfo} InterpolatedPathAndAssetInfo */
|
||||
/** @typedef {import("./Module")} Module} */
|
||||
/** @typedef {import("./util/Hash")} Hash} */
|
||||
/** @typedef {import("./DependencyTemplates")} DependencyTemplates} */
|
||||
/** @typedef {import("./javascript/JavascriptModulesPlugin").RenderContext} RenderContext} */
|
||||
/** @typedef {import("./javascript/JavascriptModulesPlugin").RenderBootstrapContext} RenderBootstrapContext} */
|
||||
/** @typedef {import("./javascript/JavascriptModulesPlugin").ChunkHashContext} ChunkHashContext} */
|
||||
/** @typedef {import("./RuntimeTemplate")} RuntimeTemplate} */
|
||||
/** @typedef {import("./ModuleGraph")} ModuleGraph} */
|
||||
/** @typedef {import("./ChunkGraph")} ChunkGraph} */
|
||||
/** @typedef {import("./Template").RenderManifestOptions} RenderManifestOptions} */
|
||||
/** @typedef {import("./Template").RenderManifestEntry} RenderManifestEntry} */
|
||||
/** @typedef {import("./TemplatedPathPlugin").TemplatePath} TemplatePath} */
|
||||
/** @typedef {import("./TemplatedPathPlugin").PathData} PathData} */
|
||||
/**
|
||||
* @template T
|
||||
* @typedef {import("tapable").IfSet<T>} IfSet
|
||||
*/
|
||||
|
||||
const getJavascriptModulesPlugin = memoize(() =>
|
||||
require("./javascript/JavascriptModulesPlugin")
|
||||
@@ -40,7 +50,6 @@ const getLoadScriptRuntimeModule = memoize(() =>
|
||||
// TODO webpack 6 remove this class
|
||||
class MainTemplate {
|
||||
/**
|
||||
*
|
||||
* @param {OutputOptions} outputOptions output options for the MainTemplate
|
||||
* @param {Compilation} compilation the compilation
|
||||
*/
|
||||
@@ -50,6 +59,11 @@ class MainTemplate {
|
||||
this.hooks = Object.freeze({
|
||||
renderManifest: {
|
||||
tap: util.deprecate(
|
||||
/**
|
||||
* @template AdditionalOptions
|
||||
* @param {string | Tap & IfSet<AdditionalOptions>} options options
|
||||
* @param {function(RenderManifestEntry[], RenderManifestOptions): RenderManifestEntry[]} fn fn
|
||||
*/
|
||||
(options, fn) => {
|
||||
compilation.hooks.renderManifest.tap(
|
||||
options,
|
||||
@@ -79,6 +93,11 @@ class MainTemplate {
|
||||
},
|
||||
require: {
|
||||
tap: util.deprecate(
|
||||
/**
|
||||
* @template AdditionalOptions
|
||||
* @param {string | Tap & IfSet<AdditionalOptions>} options options
|
||||
* @param {function(string, RenderBootstrapContext): string} fn fn
|
||||
*/
|
||||
(options, fn) => {
|
||||
getJavascriptModulesPlugin()
|
||||
.getCompilationHooks(compilation)
|
||||
@@ -111,6 +130,11 @@ class MainTemplate {
|
||||
},
|
||||
render: {
|
||||
tap: util.deprecate(
|
||||
/**
|
||||
* @template AdditionalOptions
|
||||
* @param {string | Tap & IfSet<AdditionalOptions>} options options
|
||||
* @param {function(Source, Chunk, string | undefined, ModuleTemplate, DependencyTemplates): Source} fn fn
|
||||
*/
|
||||
(options, fn) => {
|
||||
getJavascriptModulesPlugin()
|
||||
.getCompilationHooks(compilation)
|
||||
@@ -138,6 +162,11 @@ class MainTemplate {
|
||||
},
|
||||
renderWithEntry: {
|
||||
tap: util.deprecate(
|
||||
/**
|
||||
* @template AdditionalOptions
|
||||
* @param {string | Tap & IfSet<AdditionalOptions>} options options
|
||||
* @param {function(Source, Chunk, string | undefined): Source} fn fn
|
||||
*/
|
||||
(options, fn) => {
|
||||
getJavascriptModulesPlugin()
|
||||
.getCompilationHooks(compilation)
|
||||
@@ -159,6 +188,11 @@ class MainTemplate {
|
||||
},
|
||||
assetPath: {
|
||||
tap: util.deprecate(
|
||||
/**
|
||||
* @template AdditionalOptions
|
||||
* @param {string | Tap & IfSet<AdditionalOptions>} options options
|
||||
* @param {function(string, object, AssetInfo | undefined): string} fn fn
|
||||
*/
|
||||
(options, fn) => {
|
||||
compilation.hooks.assetPath.tap(options, fn);
|
||||
},
|
||||
@@ -166,15 +200,23 @@ class MainTemplate {
|
||||
"DEP_WEBPACK_MAIN_TEMPLATE_ASSET_PATH"
|
||||
),
|
||||
call: util.deprecate(
|
||||
(filename, options) => {
|
||||
return compilation.getAssetPath(filename, options);
|
||||
},
|
||||
/**
|
||||
* @param {TemplatePath} filename used to get asset path with hash
|
||||
* @param {PathData} options context data
|
||||
* @returns {string} interpolated path
|
||||
*/
|
||||
(filename, options) => compilation.getAssetPath(filename, options),
|
||||
"MainTemplate.hooks.assetPath is deprecated (use Compilation.hooks.assetPath instead)",
|
||||
"DEP_WEBPACK_MAIN_TEMPLATE_ASSET_PATH"
|
||||
)
|
||||
},
|
||||
hash: {
|
||||
tap: util.deprecate(
|
||||
/**
|
||||
* @template AdditionalOptions
|
||||
* @param {string | Tap & IfSet<AdditionalOptions>} options options
|
||||
* @param {function(Hash): void} fn fn
|
||||
*/
|
||||
(options, fn) => {
|
||||
compilation.hooks.fullHash.tap(options, fn);
|
||||
},
|
||||
@@ -184,6 +226,11 @@ class MainTemplate {
|
||||
},
|
||||
hashForChunk: {
|
||||
tap: util.deprecate(
|
||||
/**
|
||||
* @template AdditionalOptions
|
||||
* @param {string | Tap & IfSet<AdditionalOptions>} options options
|
||||
* @param {function(Hash, Chunk): void} fn fn
|
||||
*/
|
||||
(options, fn) => {
|
||||
getJavascriptModulesPlugin()
|
||||
.getCompilationHooks(compilation)
|
||||
@@ -259,7 +306,8 @@ class MainTemplate {
|
||||
* @param {string} hash the hash
|
||||
* @param {number=} length length of the hash
|
||||
* @returns {string} generated code
|
||||
*/ (hash, length) => {
|
||||
*/
|
||||
(hash, length) => {
|
||||
if (length) {
|
||||
return `${RuntimeGlobals.getFullHash} ? ${
|
||||
RuntimeGlobals.getFullHash
|
||||
@@ -273,31 +321,36 @@ class MainTemplate {
|
||||
|
||||
this.getPublicPath = util.deprecate(
|
||||
/**
|
||||
*
|
||||
* @param {object} options get public path options
|
||||
* @returns {string} hook call
|
||||
*/ options => {
|
||||
return compilation.getAssetPath(
|
||||
compilation.outputOptions.publicPath,
|
||||
* @param {PathData} options context data
|
||||
* @returns {string} interpolated path
|
||||
*/ options =>
|
||||
compilation.getAssetPath(
|
||||
/** @type {string} */
|
||||
(compilation.outputOptions.publicPath),
|
||||
options
|
||||
);
|
||||
},
|
||||
),
|
||||
"MainTemplate.getPublicPath is deprecated (use Compilation.getAssetPath(compilation.outputOptions.publicPath, options) instead)",
|
||||
"DEP_WEBPACK_MAIN_TEMPLATE_GET_PUBLIC_PATH"
|
||||
);
|
||||
|
||||
this.getAssetPath = util.deprecate(
|
||||
(path, options) => {
|
||||
return compilation.getAssetPath(path, options);
|
||||
},
|
||||
/**
|
||||
* @param {TemplatePath} path used to get asset path with hash
|
||||
* @param {PathData} options context data
|
||||
* @returns {string} interpolated path
|
||||
*/
|
||||
(path, options) => compilation.getAssetPath(path, options),
|
||||
"MainTemplate.getAssetPath is deprecated (use Compilation.getAssetPath instead)",
|
||||
"DEP_WEBPACK_MAIN_TEMPLATE_GET_ASSET_PATH"
|
||||
);
|
||||
|
||||
this.getAssetPathWithInfo = util.deprecate(
|
||||
(path, options) => {
|
||||
return compilation.getAssetPathWithInfo(path, options);
|
||||
},
|
||||
/**
|
||||
* @param {TemplatePath} path used to get asset path with hash
|
||||
* @param {PathData} options context data
|
||||
* @returns {InterpolatedPathAndAssetInfo} interpolated path and asset info
|
||||
*/
|
||||
(path, options) => compilation.getAssetPathWithInfo(path, options),
|
||||
"MainTemplate.getAssetPathWithInfo is deprecated (use Compilation.getAssetPath instead)",
|
||||
"DEP_WEBPACK_MAIN_TEMPLATE_GET_ASSET_PATH_WITH_INFO"
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user