1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | exports.PreserveExportsPlugin = exports.dependencyImports = void 0;
|
4 | const Webpack = require("webpack");
|
5 | exports.dependencyImports = Symbol();
|
6 | const moduleExports = Symbol();
|
7 | const nativeGetUsedName = Symbol();
|
8 | const useAllExports = Symbol();
|
9 | const TAP_NAME = "Aurelia:PreserveExports";
|
10 | function getModuleExports(module, moduleGraph) {
|
11 | let exportsInfo = moduleGraph.getExportsInfo(module);
|
12 | let set = exportsInfo[moduleExports];
|
13 | if (!set) {
|
14 | exportsInfo[moduleExports] = set = new Set();
|
15 | exportsInfo[nativeGetUsedName] = exportsInfo.getUsedName;
|
16 | exportsInfo.getUsedName = function (name, runtime) {
|
17 | return set.has(name)
|
18 | ? name
|
19 | : this[nativeGetUsedName](name, runtime);
|
20 | };
|
21 | }
|
22 | return set;
|
23 | }
|
24 | class PreserveExportsPlugin {
|
25 | apply(compiler) {
|
26 | compiler.hooks.compilation.tap(TAP_NAME, compilation => {
|
27 | compilation.hooks.finishModules.tap(TAP_NAME, modules => {
|
28 | for (let module of modules) {
|
29 | for (const connection of compilation.moduleGraph.getIncomingConnections(module)) {
|
30 | let dep = connection.dependency;
|
31 | let imports = dep === null || dep === void 0 ? void 0 : dep[exports.dependencyImports];
|
32 | if (!imports) {
|
33 | continue;
|
34 | }
|
35 | let exportsInfo = compilation.moduleGraph.getExportsInfo(module);
|
36 | if (exportsInfo[useAllExports]) {
|
37 | return;
|
38 | }
|
39 | if (imports === Webpack.Dependency.EXPORTS_OBJECT_REFERENCED) {
|
40 | exportsInfo[nativeGetUsedName] = exportsInfo.getUsedName;
|
41 | exportsInfo[useAllExports] = exportsInfo.getUsedName = function (name, runtime) {
|
42 | return name;
|
43 | };
|
44 | }
|
45 | else {
|
46 | let set = getModuleExports(module, compilation.moduleGraph);
|
47 | for (let e of imports)
|
48 | set.add(e);
|
49 | }
|
50 | }
|
51 | }
|
52 | });
|
53 | });
|
54 | }
|
55 | }
|
56 | exports.PreserveExportsPlugin = PreserveExportsPlugin;
|