From e99f950f5018cfe737c0d1150e50d97c6e6a4823 Mon Sep 17 00:00:00 2001 From: littleblack111 Date: Wed, 1 Nov 2023 20:49:36 +0800 Subject: update --- node_modules/webpack/lib/BannerPlugin.js | 130 ------------------------------- 1 file changed, 130 deletions(-) delete mode 100644 node_modules/webpack/lib/BannerPlugin.js (limited to 'node_modules/webpack/lib/BannerPlugin.js') diff --git a/node_modules/webpack/lib/BannerPlugin.js b/node_modules/webpack/lib/BannerPlugin.js deleted file mode 100644 index cf7c0530..00000000 --- a/node_modules/webpack/lib/BannerPlugin.js +++ /dev/null @@ -1,130 +0,0 @@ -/* - MIT License http://www.opensource.org/licenses/mit-license.php - Author Tobias Koppers @sokra -*/ - -"use strict"; - -const { ConcatSource } = require("webpack-sources"); -const Compilation = require("./Compilation"); -const ModuleFilenameHelpers = require("./ModuleFilenameHelpers"); -const Template = require("./Template"); -const createSchemaValidation = require("./util/create-schema-validation"); - -/** @typedef {import("../declarations/plugins/BannerPlugin").BannerFunction} BannerFunction */ -/** @typedef {import("../declarations/plugins/BannerPlugin").BannerPluginArgument} BannerPluginArgument */ -/** @typedef {import("../declarations/plugins/BannerPlugin").BannerPluginOptions} BannerPluginOptions */ -/** @typedef {import("./Compiler")} Compiler */ - -const validate = createSchemaValidation( - require("../schemas/plugins/BannerPlugin.check.js"), - () => require("../schemas/plugins/BannerPlugin.json"), - { - name: "Banner Plugin", - baseDataPath: "options" - } -); - -/** - * @param {string} str string to wrap - * @returns {string} wrapped string - */ -const wrapComment = str => { - if (!str.includes("\n")) { - return Template.toComment(str); - } - return `/*!\n * ${str - .replace(/\*\//g, "* /") - .split("\n") - .join("\n * ") - .replace(/\s+\n/g, "\n") - .trimEnd()}\n */`; -}; - -class BannerPlugin { - /** - * @param {BannerPluginArgument} options options object - */ - constructor(options) { - if (typeof options === "string" || typeof options === "function") { - options = { - banner: options - }; - } - - validate(options); - - this.options = options; - - const bannerOption = options.banner; - if (typeof bannerOption === "function") { - const getBanner = bannerOption; - this.banner = this.options.raw - ? getBanner - : /** @type {BannerFunction} */ data => wrapComment(getBanner(data)); - } else { - const banner = this.options.raw - ? bannerOption - : wrapComment(bannerOption); - this.banner = () => banner; - } - } - - /** - * Apply the plugin - * @param {Compiler} compiler the compiler instance - * @returns {void} - */ - apply(compiler) { - const options = this.options; - const banner = this.banner; - const matchObject = ModuleFilenameHelpers.matchObject.bind( - undefined, - options - ); - const cache = new WeakMap(); - - compiler.hooks.compilation.tap("BannerPlugin", compilation => { - compilation.hooks.processAssets.tap( - { - name: "BannerPlugin", - stage: Compilation.PROCESS_ASSETS_STAGE_ADDITIONS - }, - () => { - for (const chunk of compilation.chunks) { - if (options.entryOnly && !chunk.canBeInitial()) { - continue; - } - - for (const file of chunk.files) { - if (!matchObject(file)) { - continue; - } - - const data = { - chunk, - filename: file - }; - - const comment = compilation.getPath(banner, data); - - compilation.updateAsset(file, old => { - let cached = cache.get(old); - if (!cached || cached.comment !== comment) { - const source = options.footer - ? new ConcatSource(old, "\n", comment) - : new ConcatSource(comment, "\n", old); - cache.set(old, { source, comment }); - return source; - } - return cached.source; - }); - } - } - } - ); - }); - } -} - -module.exports = BannerPlugin; -- cgit v1.2.3