summaryrefslogtreecommitdiff
path: root/node_modules/webpack/lib/library/ModernModuleLibraryPlugin.js
diff options
context:
space:
mode:
authorlittleblack111 <littleblack11111@gmail.com>2024-08-30 17:21:18 +0800
committerlittleblack111 <littleblack11111@gmail.com>2024-08-30 17:21:18 +0800
commitefbc2ffe6a1ee5ec38a4396305561d6515d0943e (patch)
tree2b4c94f18f2c792dfda813050755d5c0273fae22 /node_modules/webpack/lib/library/ModernModuleLibraryPlugin.js
parent43acceb75957c880a5ba5a31aae221394a36d5f6 (diff)
node fixes, updates
Diffstat (limited to 'node_modules/webpack/lib/library/ModernModuleLibraryPlugin.js')
-rw-r--r--node_modules/webpack/lib/library/ModernModuleLibraryPlugin.js144
1 files changed, 144 insertions, 0 deletions
diff --git a/node_modules/webpack/lib/library/ModernModuleLibraryPlugin.js b/node_modules/webpack/lib/library/ModernModuleLibraryPlugin.js
new file mode 100644
index 00000000..23a9510c
--- /dev/null
+++ b/node_modules/webpack/lib/library/ModernModuleLibraryPlugin.js
@@ -0,0 +1,144 @@
+/*
+ MIT License http://www.opensource.org/licenses/mit-license.php
+ Author Tobias Koppers @sokra
+*/
+
+"use strict";
+
+const { ConcatSource } = require("webpack-sources");
+const ConcatenatedModule = require("../optimize/ConcatenatedModule");
+const AbstractLibraryPlugin = require("./AbstractLibraryPlugin");
+
+/** @typedef {import("webpack-sources").Source} Source */
+/** @typedef {import("../../declarations/WebpackOptions").LibraryOptions} LibraryOptions */
+/** @typedef {import("../../declarations/WebpackOptions").LibraryType} LibraryType */
+/** @typedef {import("../Chunk")} Chunk */
+/** @typedef {import("../Compilation").ChunkHashContext} ChunkHashContext */
+/** @typedef {import("../Compiler")} Compiler */
+/** @typedef {import("../Module")} Module */
+/** @typedef {import("../Module").BuildMeta} BuildMeta */
+/** @typedef {import("../javascript/JavascriptModulesPlugin").StartupRenderContext} StartupRenderContext */
+/** @typedef {import("../util/Hash")} Hash */
+/** @template T @typedef {import("./AbstractLibraryPlugin").LibraryContext<T>} LibraryContext<T> */
+
+/**
+ * @typedef {object} ModernModuleLibraryPluginOptions
+ * @property {LibraryType} type
+ */
+
+/**
+ * @typedef {object} ModernModuleLibraryPluginParsed
+ * @property {string} name
+ */
+
+/**
+ * @typedef {ModernModuleLibraryPluginParsed} T
+ * @extends {AbstractLibraryPlugin<ModernModuleLibraryPluginParsed>}
+ */
+class ModernModuleLibraryPlugin extends AbstractLibraryPlugin {
+ /**
+ * Apply the plugin
+ * @param {Compiler} compiler the compiler instance
+ * @returns {void}
+ */
+ apply(compiler) {
+ super.apply(compiler);
+
+ compiler.hooks.compilation.tap("ModernModuleLibraryPlugin", compilation => {
+ const { exportsDefinitions } =
+ ConcatenatedModule.getCompilationHooks(compilation);
+ exportsDefinitions.tap("ModernModuleLibraryPlugin", () => true);
+ });
+ }
+
+ /**
+ * @param {ModernModuleLibraryPluginOptions} options the plugin options
+ */
+ constructor(options) {
+ super({
+ pluginName: "ModernModuleLibraryPlugin",
+ type: options.type
+ });
+ }
+
+ /**
+ * @param {LibraryOptions} library normalized library option
+ * @returns {T | false} preprocess as needed by overriding
+ */
+ parseOptions(library) {
+ const { name } = library;
+ if (name) {
+ throw new Error(
+ `Library name must be unset. ${AbstractLibraryPlugin.COMMON_LIBRARY_NAME_MESSAGE}`
+ );
+ }
+ const _name = /** @type {string} */ (name);
+ return {
+ name: _name
+ };
+ }
+
+ /**
+ * @param {Source} source source
+ * @param {Module} module module
+ * @param {StartupRenderContext} renderContext render context
+ * @param {LibraryContext<T>} libraryContext context
+ * @returns {Source} source with library export
+ */
+ renderStartup(
+ source,
+ module,
+ { moduleGraph, chunk },
+ { options, compilation }
+ ) {
+ const result = new ConcatSource(source);
+ const exportsInfo = moduleGraph.getExportsInfo(module);
+ const definitions =
+ /** @type {BuildMeta} */
+ (module.buildMeta).exportsFinalName;
+ const exports = [];
+
+ for (const exportInfo of exportsInfo.orderedExports) {
+ let shouldContinue = false;
+ const reexport = exportInfo.findTarget(moduleGraph, _m => true);
+
+ if (reexport) {
+ const exp = moduleGraph.getExportsInfo(reexport.module);
+
+ for (const reexportInfo of exp.orderedExports) {
+ if (
+ !reexportInfo.provided &&
+ reexportInfo.name === /** @type {string[]} */ (reexport.export)[0]
+ ) {
+ shouldContinue = true;
+ }
+ }
+ }
+
+ if (shouldContinue) continue;
+
+ const webpackExportsProperty = exportInfo.getUsedName(
+ exportInfo.name,
+ chunk.runtime
+ );
+ const finalName =
+ definitions[
+ /** @type {string} */
+ (webpackExportsProperty)
+ ];
+ exports.push(
+ finalName === exportInfo.name
+ ? finalName
+ : `${finalName} as ${exportInfo.name}`
+ );
+ }
+
+ if (exports.length > 0) {
+ result.add(`export { ${exports.join(", ")} };\n`);
+ }
+
+ return result;
+ }
+}
+
+module.exports = ModernModuleLibraryPlugin;