@umijs/babel-preset-umi 4.0.0-canary.20220614.2 → 4.0.0-canary.20220620.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +3 -0
- package/dist/index.js +2 -0
- package/dist/plugins/stripExports.d.ts +3 -0
- package/dist/plugins/stripExports.js +109 -0
- package/package.json +3 -3
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -8,6 +8,7 @@ const path_1 = require("path");
|
|
|
8
8
|
const autoCSSModules_1 = __importDefault(require("./plugins/autoCSSModules"));
|
|
9
9
|
const dynamicImportNode_1 = __importDefault(require("./plugins/dynamicImportNode"));
|
|
10
10
|
const lockCoreJS_1 = __importDefault(require("./plugins/lockCoreJS"));
|
|
11
|
+
const stripExports_1 = __importDefault(require("./plugins/stripExports"));
|
|
11
12
|
exports.default = (_context, opts) => {
|
|
12
13
|
return {
|
|
13
14
|
presets: [
|
|
@@ -118,6 +119,7 @@ exports.default = (_context, opts) => {
|
|
|
118
119
|
opts.pluginLockCoreJS && [lockCoreJS_1.default],
|
|
119
120
|
opts.pluginDynamicImportNode && [dynamicImportNode_1.default],
|
|
120
121
|
opts.pluginAutoCSSModules && [autoCSSModules_1.default],
|
|
122
|
+
opts.stripExports && [stripExports_1.default],
|
|
121
123
|
].filter(Boolean),
|
|
122
124
|
};
|
|
123
125
|
};
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
const t = __importStar(require("@umijs/bundler-utils/compiled/babel/types"));
|
|
27
|
+
exports.default = () => {
|
|
28
|
+
return {
|
|
29
|
+
visitor: {
|
|
30
|
+
Program: {
|
|
31
|
+
enter(path, { opts }) {
|
|
32
|
+
const expressions = path.get('body');
|
|
33
|
+
const exports = (opts === null || opts === void 0 ? void 0 : opts.exports) || [];
|
|
34
|
+
expressions.forEach((exp) => {
|
|
35
|
+
if (!(t.isExportNamedDeclaration(exp) ||
|
|
36
|
+
t.isExportDefaultDeclaration(exp)))
|
|
37
|
+
return;
|
|
38
|
+
handleExportsIndividual(exp);
|
|
39
|
+
handleExportsList(exp);
|
|
40
|
+
handleExportsDefault(exp);
|
|
41
|
+
});
|
|
42
|
+
function handleExportsIndividual(path) {
|
|
43
|
+
if (!path.node)
|
|
44
|
+
return;
|
|
45
|
+
if (!t.isExportNamedDeclaration(path))
|
|
46
|
+
return;
|
|
47
|
+
if (!path.get('declaration').node)
|
|
48
|
+
return;
|
|
49
|
+
const declaration = path.get('declaration');
|
|
50
|
+
if (t.isVariableDeclaration(declaration)) {
|
|
51
|
+
const variables = declaration.get('declarations');
|
|
52
|
+
variables.forEach((variable) => {
|
|
53
|
+
exports.includes(variable.get('id.name').node) &&
|
|
54
|
+
variable.remove();
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
else {
|
|
58
|
+
exports.includes(declaration.get('id.name').node) &&
|
|
59
|
+
declaration.remove();
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
function handleExportsList(path) {
|
|
63
|
+
if (!path.node)
|
|
64
|
+
return;
|
|
65
|
+
if (!t.isExportNamedDeclaration(path))
|
|
66
|
+
return;
|
|
67
|
+
const specifiers = path.get('specifiers');
|
|
68
|
+
if (!specifiers || specifiers.length === 0)
|
|
69
|
+
return;
|
|
70
|
+
specifiers.forEach((specifier) => {
|
|
71
|
+
if (exports.includes(specifier.get('exported.name').node))
|
|
72
|
+
specifier.remove();
|
|
73
|
+
});
|
|
74
|
+
if (path.get('specifiers').length === 0)
|
|
75
|
+
path.remove();
|
|
76
|
+
}
|
|
77
|
+
function handleExportsDefault(path) {
|
|
78
|
+
if (!path.node)
|
|
79
|
+
return;
|
|
80
|
+
if (!t.isExportDefaultDeclaration(path))
|
|
81
|
+
return;
|
|
82
|
+
const declaration = path.get('declaration');
|
|
83
|
+
if (!declaration.node)
|
|
84
|
+
return;
|
|
85
|
+
if (exports.includes(declaration.get('name').node))
|
|
86
|
+
declaration.remove();
|
|
87
|
+
}
|
|
88
|
+
},
|
|
89
|
+
exit(path) {
|
|
90
|
+
// Manually reprocess the scope to ensure that the removed declarations are updated.
|
|
91
|
+
path.scope.crawl();
|
|
92
|
+
const expressions = path.get('body');
|
|
93
|
+
expressions.forEach((exp) => {
|
|
94
|
+
if (!t.isImportDeclaration(exp))
|
|
95
|
+
return;
|
|
96
|
+
const specifiers = exp.get('specifiers');
|
|
97
|
+
specifiers.forEach((s) => {
|
|
98
|
+
const name = s.get('local.name').node;
|
|
99
|
+
if (!s.scope.getBinding(name).referenced)
|
|
100
|
+
s.remove();
|
|
101
|
+
});
|
|
102
|
+
if (exp.get('specifiers').length === 0)
|
|
103
|
+
exp.remove();
|
|
104
|
+
});
|
|
105
|
+
},
|
|
106
|
+
},
|
|
107
|
+
},
|
|
108
|
+
};
|
|
109
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@umijs/babel-preset-umi",
|
|
3
|
-
"version": "4.0.0-canary.
|
|
3
|
+
"version": "4.0.0-canary.20220620.1",
|
|
4
4
|
"description": "Official babel preset for umi.",
|
|
5
5
|
"homepage": "https://github.com/umijs/umi-next/tree/master/packages/babel-preset-umi#readme",
|
|
6
6
|
"bugs": "https://github.com/umijs/umi-next/issues",
|
|
@@ -23,8 +23,8 @@
|
|
|
23
23
|
"dependencies": {
|
|
24
24
|
"@babel/runtime": "7.17.9",
|
|
25
25
|
"@bloomberg/record-tuple-polyfill": "0.0.4",
|
|
26
|
-
"@umijs/bundler-utils": "4.0.0-canary.
|
|
27
|
-
"@umijs/utils": "4.0.0-canary.
|
|
26
|
+
"@umijs/bundler-utils": "4.0.0-canary.20220620.1",
|
|
27
|
+
"@umijs/utils": "4.0.0-canary.20220620.1",
|
|
28
28
|
"core-js": "3.22.4"
|
|
29
29
|
},
|
|
30
30
|
"publishConfig": {
|