[79a0317] | 1 | /*
|
---|
| 2 | MIT License http://www.opensource.org/licenses/mit-license.php
|
---|
| 3 | Author Tobias Koppers @sokra
|
---|
| 4 | */
|
---|
| 5 |
|
---|
| 6 | "use strict";
|
---|
| 7 |
|
---|
| 8 | const { getEntryRuntime } = require("./util/runtime");
|
---|
| 9 |
|
---|
| 10 | /** @typedef {import("./Compiler")} Compiler */
|
---|
| 11 |
|
---|
| 12 | const PLUGIN_NAME = "FlagEntryExportAsUsedPlugin";
|
---|
| 13 |
|
---|
| 14 | class FlagEntryExportAsUsedPlugin {
|
---|
| 15 | /**
|
---|
| 16 | * @param {boolean} nsObjectUsed true, if the ns object is used
|
---|
| 17 | * @param {string} explanation explanation for the reason
|
---|
| 18 | */
|
---|
| 19 | constructor(nsObjectUsed, explanation) {
|
---|
| 20 | this.nsObjectUsed = nsObjectUsed;
|
---|
| 21 | this.explanation = explanation;
|
---|
| 22 | }
|
---|
| 23 |
|
---|
| 24 | /**
|
---|
| 25 | * Apply the plugin
|
---|
| 26 | * @param {Compiler} compiler the compiler instance
|
---|
| 27 | * @returns {void}
|
---|
| 28 | */
|
---|
| 29 | apply(compiler) {
|
---|
| 30 | compiler.hooks.thisCompilation.tap(PLUGIN_NAME, compilation => {
|
---|
| 31 | const moduleGraph = compilation.moduleGraph;
|
---|
| 32 | compilation.hooks.seal.tap(PLUGIN_NAME, () => {
|
---|
| 33 | for (const [
|
---|
| 34 | entryName,
|
---|
| 35 | { dependencies: deps, options }
|
---|
| 36 | ] of compilation.entries) {
|
---|
| 37 | const runtime = getEntryRuntime(compilation, entryName, options);
|
---|
| 38 | for (const dep of deps) {
|
---|
| 39 | const module = moduleGraph.getModule(dep);
|
---|
| 40 | if (module) {
|
---|
| 41 | const exportsInfo = moduleGraph.getExportsInfo(module);
|
---|
| 42 | if (this.nsObjectUsed) {
|
---|
| 43 | exportsInfo.setUsedInUnknownWay(runtime);
|
---|
| 44 | } else {
|
---|
| 45 | exportsInfo.setAllKnownExportsUsed(runtime);
|
---|
| 46 | }
|
---|
| 47 | moduleGraph.addExtraReason(module, this.explanation);
|
---|
| 48 | }
|
---|
| 49 | }
|
---|
| 50 | }
|
---|
| 51 | });
|
---|
| 52 | });
|
---|
| 53 | }
|
---|
| 54 | }
|
---|
| 55 |
|
---|
| 56 | module.exports = FlagEntryExportAsUsedPlugin;
|
---|