@umijs/babel-preset-umi 4.0.0-beta.9 → 4.0.0-canary-20240513.3
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/LICENSE +21 -0
- package/dist/index.d.ts +6 -1
- package/dist/index.js +183 -91
- package/dist/plugins/autoCSSModules.js +59 -48
- package/dist/plugins/dynamicImportNode.js +73 -63
- package/dist/plugins/lockCoreJS.js +54 -37
- package/dist/plugins/stripExports.d.ts +3 -0
- package/dist/plugins/stripExports.js +113 -0
- package/package.json +16 -15
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2017-present ChenCheng (sorrycc@gmail.com)
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
|
13
|
+
all copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
+
THE SOFTWARE.
|
package/dist/index.d.ts
CHANGED
|
@@ -6,9 +6,14 @@ interface IOpts {
|
|
|
6
6
|
pluginLockCoreJS: any;
|
|
7
7
|
pluginDynamicImportNode: any;
|
|
8
8
|
pluginAutoCSSModules: any;
|
|
9
|
+
stripExports: {
|
|
10
|
+
exports: string[];
|
|
11
|
+
};
|
|
12
|
+
classPropertiesLoose: any;
|
|
13
|
+
pluginDecorators: any;
|
|
9
14
|
}
|
|
10
15
|
declare const _default: (_context: any, opts: IOpts) => {
|
|
11
|
-
presets: any[][];
|
|
16
|
+
presets: (false | any[])[];
|
|
12
17
|
plugins: any[];
|
|
13
18
|
};
|
|
14
19
|
export default _default;
|
package/dist/index.js
CHANGED
|
@@ -1,93 +1,185 @@
|
|
|
1
|
-
|
|
2
|
-
var
|
|
3
|
-
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
4
10
|
};
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
24
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
25
|
+
mod
|
|
26
|
+
));
|
|
27
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
|
+
|
|
29
|
+
// src/index.ts
|
|
30
|
+
var src_exports = {};
|
|
31
|
+
__export(src_exports, {
|
|
32
|
+
default: () => src_default
|
|
33
|
+
});
|
|
34
|
+
module.exports = __toCommonJS(src_exports);
|
|
35
|
+
var import_utils = require("@umijs/utils");
|
|
36
|
+
var import_path = require("path");
|
|
37
|
+
var import_autoCSSModules = __toESM(require("./plugins/autoCSSModules"));
|
|
38
|
+
var import_dynamicImportNode = __toESM(require("./plugins/dynamicImportNode"));
|
|
39
|
+
var import_lockCoreJS = __toESM(require("./plugins/lockCoreJS"));
|
|
40
|
+
var import_stripExports = __toESM(require("./plugins/stripExports"));
|
|
41
|
+
var src_default = (_context, opts) => {
|
|
42
|
+
return {
|
|
43
|
+
presets: [
|
|
44
|
+
[
|
|
45
|
+
require.resolve("@umijs/bundler-utils/compiled/babel/preset-env"),
|
|
46
|
+
{
|
|
47
|
+
bugfixes: true,
|
|
48
|
+
// 更兼容 spec,但会变慢,所以不开
|
|
49
|
+
spec: false,
|
|
50
|
+
// 推荐用 top level 的 assumptions 配置
|
|
51
|
+
loose: false,
|
|
52
|
+
// 保留 es modules 语法,交给 webpack 处理
|
|
53
|
+
modules: false,
|
|
54
|
+
debug: false,
|
|
55
|
+
useBuiltIns: "entry",
|
|
56
|
+
corejs: (0, import_utils.getCorejsVersion)((0, import_path.join)(__dirname, "../package.json")),
|
|
57
|
+
// 没必要,遇到了应该改 targets 配置
|
|
58
|
+
forceAllTransforms: false,
|
|
59
|
+
ignoreBrowserslistConfig: true,
|
|
60
|
+
...opts.presetEnv
|
|
61
|
+
}
|
|
62
|
+
],
|
|
63
|
+
// 允许禁用 preset-react 用于支持 vue 等其他框架
|
|
64
|
+
opts.presetReact !== false && [
|
|
65
|
+
require.resolve("@umijs/bundler-utils/compiled/babel/preset-react"),
|
|
66
|
+
{
|
|
67
|
+
runtime: "automatic",
|
|
68
|
+
development: process.env.NODE_ENV === "development",
|
|
69
|
+
...opts.presetReact
|
|
70
|
+
}
|
|
71
|
+
],
|
|
72
|
+
[
|
|
73
|
+
require.resolve("@umijs/bundler-utils/compiled/babel/preset-typescript"),
|
|
74
|
+
{
|
|
75
|
+
allowNamespaces: true,
|
|
76
|
+
allowDeclareFields: true,
|
|
77
|
+
// Why false?
|
|
78
|
+
// 如果为 true,babel 只删除 import type 语句,会保留其他通过 import 引入的 type
|
|
79
|
+
// 这些 type 引用走到 webpack 之后,就会报错
|
|
80
|
+
onlyRemoveTypeImports: false,
|
|
81
|
+
optimizeConstEnums: true,
|
|
82
|
+
...opts.presetTypeScript
|
|
83
|
+
}
|
|
84
|
+
]
|
|
85
|
+
].filter(Boolean),
|
|
86
|
+
plugins: [
|
|
87
|
+
// TC39 Proposals
|
|
88
|
+
// class-static-block
|
|
89
|
+
// decorators
|
|
90
|
+
opts.pluginDecorators !== false && [
|
|
91
|
+
require.resolve("@umijs/bundler-utils/compiled/babel/plugin-proposal-decorators"),
|
|
92
|
+
{
|
|
93
|
+
legacy: true,
|
|
94
|
+
...opts.pluginDecorators
|
|
95
|
+
}
|
|
96
|
+
],
|
|
97
|
+
// Enable loose mode to use assignment instead of defineProperty
|
|
98
|
+
// Note:
|
|
99
|
+
// 'loose' mode configuration must be the same for
|
|
100
|
+
// * @babel/plugin-proposal-class-properties
|
|
101
|
+
// * @babel/plugin-proposal-private-methods
|
|
102
|
+
// * @babel/plugin-proposal-private-property-in-object
|
|
103
|
+
// (when they are enabled)
|
|
104
|
+
// ref: https://github.com/facebook/create-react-app/issues/4263
|
|
105
|
+
// ref: https://github.com/mobxjs/mobx/issues/1471
|
|
106
|
+
// ref: https://github.com/umijs/umi/issues/9396
|
|
107
|
+
// 不移动到 feature 里的原因是因为 decorators 有顺序要求
|
|
108
|
+
opts.classPropertiesLoose && [
|
|
109
|
+
require.resolve("@umijs/bundler-utils/compiled/babel/plugin-proposal-class-properties"),
|
|
110
|
+
{ loose: true }
|
|
111
|
+
],
|
|
112
|
+
opts.classPropertiesLoose && [
|
|
113
|
+
require.resolve("@umijs/bundler-utils/compiled/babel/plugin-proposal-private-methods"),
|
|
114
|
+
{
|
|
115
|
+
loose: true
|
|
116
|
+
}
|
|
117
|
+
],
|
|
118
|
+
opts.classPropertiesLoose && [
|
|
119
|
+
require.resolve("@umijs/bundler-utils/compiled/babel/plugin-proposal-private-property-in-object"),
|
|
120
|
+
{
|
|
121
|
+
loose: true
|
|
122
|
+
}
|
|
123
|
+
],
|
|
124
|
+
// do-expressions
|
|
125
|
+
[
|
|
126
|
+
require.resolve("@umijs/bundler-utils/compiled/babel/plugin-proposal-do-expressions")
|
|
127
|
+
],
|
|
128
|
+
// export-default-from
|
|
129
|
+
[
|
|
130
|
+
require.resolve("@umijs/bundler-utils/compiled/babel/plugin-proposal-export-default-from")
|
|
131
|
+
],
|
|
132
|
+
// export-namespace-from
|
|
133
|
+
[
|
|
134
|
+
require.resolve("@umijs/bundler-utils/compiled/babel/plugin-proposal-export-namespace-from")
|
|
135
|
+
],
|
|
136
|
+
// function-bind
|
|
137
|
+
[
|
|
138
|
+
require.resolve("@umijs/bundler-utils/compiled/babel/plugin-proposal-function-bind")
|
|
139
|
+
],
|
|
140
|
+
// function-sent
|
|
141
|
+
// partial-application
|
|
142
|
+
[
|
|
143
|
+
require.resolve("@umijs/bundler-utils/compiled/babel/plugin-proposal-partial-application")
|
|
144
|
+
],
|
|
145
|
+
// pipeline-operator
|
|
146
|
+
[
|
|
147
|
+
require.resolve("@umijs/bundler-utils/compiled/babel/plugin-proposal-pipeline-operator"),
|
|
148
|
+
{ proposal: "minimal" }
|
|
149
|
+
],
|
|
150
|
+
// throw-expressions
|
|
151
|
+
// record-and-tuple
|
|
152
|
+
[
|
|
153
|
+
require.resolve("@umijs/bundler-utils/compiled/babel/plugin-proposal-record-and-tuple"),
|
|
154
|
+
{
|
|
155
|
+
syntaxType: "hash",
|
|
156
|
+
importPolyfill: true,
|
|
157
|
+
polyfillModuleName: (0, import_path.dirname)(
|
|
158
|
+
require.resolve("@bloomberg/record-tuple-polyfill/package")
|
|
159
|
+
)
|
|
160
|
+
}
|
|
161
|
+
],
|
|
162
|
+
opts.pluginTransformRuntime && [
|
|
163
|
+
require.resolve("@umijs/bundler-utils/compiled/babel/plugin-transform-runtime"),
|
|
164
|
+
{
|
|
165
|
+
helpers: true,
|
|
166
|
+
regenerator: true,
|
|
167
|
+
// 7.13 之后根据 exports 自动选择 esm 和 cjs,无需此配置
|
|
168
|
+
useESModules: false,
|
|
169
|
+
// lock the version of @babel/runtime
|
|
170
|
+
// make sure we are using the correct version
|
|
171
|
+
// ref: https://github.com/babel/babel/blob/v7.16.12/packages/babel-plugin-transform-runtime/src/get-runtime-path/index.ts#L19
|
|
172
|
+
// ref: https://github.com/umijs/umi/pull/7816
|
|
173
|
+
absoluteRuntime: (0, import_path.dirname)(require.resolve("../package.json")),
|
|
174
|
+
version: `^${require("@babel/runtime/package.json").version}`,
|
|
175
|
+
...opts.pluginTransformRuntime
|
|
176
|
+
}
|
|
177
|
+
],
|
|
178
|
+
// none official plugins
|
|
179
|
+
opts.pluginLockCoreJS && [import_lockCoreJS.default],
|
|
180
|
+
opts.pluginDynamicImportNode && [import_dynamicImportNode.default],
|
|
181
|
+
opts.pluginAutoCSSModules && [import_autoCSSModules.default],
|
|
182
|
+
opts.stripExports && [import_stripExports.default]
|
|
183
|
+
].filter(Boolean)
|
|
184
|
+
};
|
|
93
185
|
};
|
|
@@ -1,50 +1,61 @@
|
|
|
1
|
-
|
|
2
|
-
var
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
__setModuleDefault(result, mod);
|
|
19
|
-
return result;
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
20
18
|
};
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
24
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
25
|
+
mod
|
|
26
|
+
));
|
|
27
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
|
+
|
|
29
|
+
// src/plugins/autoCSSModules.ts
|
|
30
|
+
var autoCSSModules_exports = {};
|
|
31
|
+
__export(autoCSSModules_exports, {
|
|
32
|
+
default: () => autoCSSModules_default
|
|
33
|
+
});
|
|
34
|
+
module.exports = __toCommonJS(autoCSSModules_exports);
|
|
35
|
+
var t = __toESM(require("@umijs/bundler-utils/compiled/babel/types"));
|
|
36
|
+
var import_path = require("path");
|
|
37
|
+
var CSS_EXT_NAMES = [".css", ".less", ".sass", ".scss", ".stylus", ".styl"];
|
|
38
|
+
function autoCSSModules_default() {
|
|
39
|
+
return {
|
|
40
|
+
visitor: {
|
|
41
|
+
ImportDeclaration(path) {
|
|
42
|
+
const {
|
|
43
|
+
specifiers,
|
|
44
|
+
source,
|
|
45
|
+
source: { value }
|
|
46
|
+
} = path.node;
|
|
47
|
+
if (specifiers.length && CSS_EXT_NAMES.includes((0, import_path.extname)(value))) {
|
|
48
|
+
source.value = `${value}?modules`;
|
|
49
|
+
}
|
|
50
|
+
},
|
|
51
|
+
// e.g.
|
|
52
|
+
// const styles = await import('./index.less');
|
|
53
|
+
VariableDeclarator(path) {
|
|
54
|
+
const { node } = path;
|
|
55
|
+
if (t.isAwaitExpression(node.init) && t.isCallExpression(node.init.argument) && t.isImport(node.init.argument.callee) && node.init.argument.arguments.length === 1 && t.isStringLiteral(node.init.argument.arguments[0]) && CSS_EXT_NAMES.includes((0, import_path.extname)(node.init.argument.arguments[0].value))) {
|
|
56
|
+
node.init.argument.arguments[0].value = `${node.init.argument.arguments[0].value}?modules`;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
};
|
|
49
61
|
}
|
|
50
|
-
exports.default = default_1;
|
|
@@ -1,71 +1,81 @@
|
|
|
1
|
-
|
|
2
|
-
var
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
11
|
-
}) : function(o, v) {
|
|
12
|
-
o["default"] = v;
|
|
13
|
-
});
|
|
14
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
15
|
-
if (mod && mod.__esModule) return mod;
|
|
16
|
-
var result = {};
|
|
17
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
18
|
-
__setModuleDefault(result, mod);
|
|
19
|
-
return result;
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
20
10
|
};
|
|
21
|
-
var
|
|
22
|
-
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
23
18
|
};
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
24
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
25
|
+
mod
|
|
26
|
+
));
|
|
27
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
|
+
|
|
29
|
+
// src/plugins/dynamicImportNode.ts
|
|
30
|
+
var dynamicImportNode_exports = {};
|
|
31
|
+
__export(dynamicImportNode_exports, {
|
|
32
|
+
default: () => dynamicImportNode_default
|
|
33
|
+
});
|
|
34
|
+
module.exports = __toCommonJS(dynamicImportNode_exports);
|
|
35
|
+
var import_template = __toESM(require("@umijs/bundler-utils/compiled/babel/template"));
|
|
36
|
+
var t = __toESM(require("@umijs/bundler-utils/compiled/babel/types"));
|
|
27
37
|
function getImportSource(callNode) {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
],
|
|
38
|
+
const importArguments = callNode.arguments;
|
|
39
|
+
const [importPath] = importArguments;
|
|
40
|
+
const isString2 = t.isStringLiteral(importPath) || t.isTemplateLiteral(importPath);
|
|
41
|
+
if (isString2) {
|
|
42
|
+
t.removeComments(importPath);
|
|
43
|
+
return importPath;
|
|
44
|
+
}
|
|
45
|
+
return t.templateLiteral(
|
|
46
|
+
[
|
|
47
|
+
t.templateElement({ raw: "", cooked: "" }),
|
|
48
|
+
t.templateElement({ raw: "", cooked: "" }, true)
|
|
49
|
+
],
|
|
50
|
+
importArguments
|
|
51
|
+
);
|
|
40
52
|
}
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
53
|
+
var builders = {
|
|
54
|
+
static: (0, import_template.default)("Promise.resolve().then(() => INTEROP(require(SOURCE)))"),
|
|
55
|
+
dynamic: (0, import_template.default)("Promise.resolve(SOURCE).then(s => INTEROP(require(s)))")
|
|
44
56
|
};
|
|
45
57
|
function isString(node) {
|
|
46
|
-
|
|
47
|
-
(t.isTemplateLiteral(node) && node.expressions.length === 0));
|
|
58
|
+
return t.isStringLiteral(node) || t.isTemplateLiteral(node) && node.expressions.length === 0;
|
|
48
59
|
}
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
};
|
|
60
|
+
var dynamicImportNode_default = () => {
|
|
61
|
+
const visited = /* @__PURE__ */ new WeakSet();
|
|
62
|
+
return {
|
|
63
|
+
visitor: {
|
|
64
|
+
Import(path) {
|
|
65
|
+
if (visited) {
|
|
66
|
+
if (visited.has(path)) {
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
visited.add(path);
|
|
70
|
+
}
|
|
71
|
+
const SOURCE = getImportSource(path.parent);
|
|
72
|
+
const builder = isString(SOURCE) ? builders.static : builders.dynamic;
|
|
73
|
+
const newImport = builder({
|
|
74
|
+
SOURCE,
|
|
75
|
+
INTEROP: path.hub.addHelper("interopRequireWildcard")
|
|
76
|
+
});
|
|
77
|
+
path.parentPath.replaceWith(newImport);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
};
|
|
71
81
|
};
|
|
@@ -1,41 +1,58 @@
|
|
|
1
|
-
|
|
2
|
-
var
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
__setModuleDefault(result, mod);
|
|
19
|
-
return result;
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
20
18
|
};
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
24
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
25
|
+
mod
|
|
26
|
+
));
|
|
27
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
|
+
|
|
29
|
+
// src/plugins/lockCoreJS.ts
|
|
30
|
+
var lockCoreJS_exports = {};
|
|
31
|
+
__export(lockCoreJS_exports, {
|
|
32
|
+
default: () => lockCoreJS_default
|
|
33
|
+
});
|
|
34
|
+
module.exports = __toCommonJS(lockCoreJS_exports);
|
|
35
|
+
var t = __toESM(require("@umijs/bundler-utils/compiled/babel/types"));
|
|
36
|
+
var import_utils = require("@umijs/utils");
|
|
37
|
+
var import_path = require("path");
|
|
25
38
|
function addLastSlash(path) {
|
|
26
|
-
|
|
39
|
+
return path.endsWith("/") ? path : `${path}/`;
|
|
27
40
|
}
|
|
28
|
-
function
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
41
|
+
function lockCoreJS_default() {
|
|
42
|
+
return {
|
|
43
|
+
post({ path }) {
|
|
44
|
+
path.node.body.forEach((node) => {
|
|
45
|
+
if (t.isImportDeclaration(node)) {
|
|
46
|
+
if (node.source.value.startsWith("core-js/")) {
|
|
47
|
+
node.source.value = node.source.value.replace(
|
|
48
|
+
/^core-js\//,
|
|
49
|
+
addLastSlash(
|
|
50
|
+
(0, import_utils.winPath)((0, import_path.dirname)(require.resolve("core-js/package.json")))
|
|
51
|
+
)
|
|
52
|
+
);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
};
|
|
40
58
|
}
|
|
41
|
-
exports.default = default_1;
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
24
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
25
|
+
mod
|
|
26
|
+
));
|
|
27
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
|
+
|
|
29
|
+
// src/plugins/stripExports.ts
|
|
30
|
+
var stripExports_exports = {};
|
|
31
|
+
__export(stripExports_exports, {
|
|
32
|
+
default: () => stripExports_default
|
|
33
|
+
});
|
|
34
|
+
module.exports = __toCommonJS(stripExports_exports);
|
|
35
|
+
var t = __toESM(require("@umijs/bundler-utils/compiled/babel/types"));
|
|
36
|
+
var stripExports_default = () => {
|
|
37
|
+
return {
|
|
38
|
+
visitor: {
|
|
39
|
+
Program: {
|
|
40
|
+
enter(path, { opts }) {
|
|
41
|
+
const expressions = path.get("body");
|
|
42
|
+
const exports = (opts == null ? void 0 : opts.exports) || [];
|
|
43
|
+
expressions.forEach((exp) => {
|
|
44
|
+
if (!(t.isExportNamedDeclaration(exp) || t.isExportDefaultDeclaration(exp)))
|
|
45
|
+
return;
|
|
46
|
+
handleExportsIndividual(exp);
|
|
47
|
+
handleExportsList(exp);
|
|
48
|
+
handleExportsDefault(exp);
|
|
49
|
+
});
|
|
50
|
+
function handleExportsIndividual(path2) {
|
|
51
|
+
if (!path2.node)
|
|
52
|
+
return;
|
|
53
|
+
if (!t.isExportNamedDeclaration(path2))
|
|
54
|
+
return;
|
|
55
|
+
if (!path2.get("declaration").node)
|
|
56
|
+
return;
|
|
57
|
+
const declaration = path2.get("declaration");
|
|
58
|
+
if (t.isVariableDeclaration(declaration)) {
|
|
59
|
+
const variables = declaration.get("declarations");
|
|
60
|
+
variables.forEach((variable) => {
|
|
61
|
+
exports.includes(variable.get("id.name").node) && variable.remove();
|
|
62
|
+
});
|
|
63
|
+
} else {
|
|
64
|
+
exports.includes(declaration.get("id.name").node) && declaration.remove();
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
function handleExportsList(path2) {
|
|
68
|
+
if (!path2.node)
|
|
69
|
+
return;
|
|
70
|
+
if (!t.isExportNamedDeclaration(path2))
|
|
71
|
+
return;
|
|
72
|
+
const specifiers = path2.get("specifiers");
|
|
73
|
+
if (!specifiers || specifiers.length === 0)
|
|
74
|
+
return;
|
|
75
|
+
specifiers.forEach((specifier) => {
|
|
76
|
+
if (exports.includes(specifier.get("exported.name").node))
|
|
77
|
+
specifier.remove();
|
|
78
|
+
});
|
|
79
|
+
if (path2.get("specifiers").length === 0)
|
|
80
|
+
path2.remove();
|
|
81
|
+
}
|
|
82
|
+
function handleExportsDefault(path2) {
|
|
83
|
+
if (!path2.node)
|
|
84
|
+
return;
|
|
85
|
+
if (!t.isExportDefaultDeclaration(path2))
|
|
86
|
+
return;
|
|
87
|
+
const declaration = path2.get("declaration");
|
|
88
|
+
if (!declaration.node)
|
|
89
|
+
return;
|
|
90
|
+
if (exports.includes(declaration.get("name").node))
|
|
91
|
+
declaration.remove();
|
|
92
|
+
}
|
|
93
|
+
},
|
|
94
|
+
exit(path) {
|
|
95
|
+
path.scope.crawl();
|
|
96
|
+
const expressions = path.get("body");
|
|
97
|
+
expressions.forEach((exp) => {
|
|
98
|
+
if (!t.isImportDeclaration(exp))
|
|
99
|
+
return;
|
|
100
|
+
const specifiers = exp.get("specifiers");
|
|
101
|
+
specifiers.forEach((s) => {
|
|
102
|
+
const name = s.get("local.name").node;
|
|
103
|
+
if (!s.scope.getBinding(name).referenced)
|
|
104
|
+
s.remove();
|
|
105
|
+
});
|
|
106
|
+
if (exp.get("specifiers").length === 0)
|
|
107
|
+
exp.remove();
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
};
|
|
113
|
+
};
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@umijs/babel-preset-umi",
|
|
3
|
-
"version": "4.0.0-
|
|
3
|
+
"version": "4.0.0-canary-20240513.3",
|
|
4
4
|
"description": "Official babel preset for umi.",
|
|
5
|
-
"homepage": "https://github.com/umijs/umi
|
|
6
|
-
"bugs": "https://github.com/umijs/umi
|
|
5
|
+
"homepage": "https://github.com/umijs/umi/tree/master/packages/babel-preset-umi#readme",
|
|
6
|
+
"bugs": "https://github.com/umijs/umi/issues",
|
|
7
7
|
"repository": {
|
|
8
8
|
"type": "git",
|
|
9
|
-
"url": "https://github.com/umijs/umi
|
|
9
|
+
"url": "https://github.com/umijs/umi"
|
|
10
10
|
},
|
|
11
11
|
"license": "MIT",
|
|
12
12
|
"main": "dist/index.js",
|
|
@@ -14,22 +14,23 @@
|
|
|
14
14
|
"files": [
|
|
15
15
|
"dist"
|
|
16
16
|
],
|
|
17
|
-
"scripts": {
|
|
18
|
-
"build": "pnpm tsc",
|
|
19
|
-
"build:deps": "pnpm esno ../../scripts/bundleDeps.ts",
|
|
20
|
-
"dev": "pnpm build -- --watch"
|
|
21
|
-
},
|
|
22
17
|
"dependencies": {
|
|
23
|
-
"@babel/runtime": "7.
|
|
18
|
+
"@babel/runtime": "7.23.6",
|
|
24
19
|
"@bloomberg/record-tuple-polyfill": "0.0.4",
|
|
25
|
-
"
|
|
26
|
-
"@umijs/utils": "4.0.0-
|
|
27
|
-
"
|
|
20
|
+
"core-js": "3.34.0",
|
|
21
|
+
"@umijs/bundler-utils": "4.0.0-canary-20240513.3",
|
|
22
|
+
"@umijs/utils": "4.0.0-canary-20240513.3"
|
|
28
23
|
},
|
|
29
24
|
"publishConfig": {
|
|
30
25
|
"access": "public"
|
|
31
26
|
},
|
|
32
27
|
"authors": [
|
|
33
28
|
"chencheng <sorrycc@gmail.com> (https://github.com/sorrycc)"
|
|
34
|
-
]
|
|
35
|
-
|
|
29
|
+
],
|
|
30
|
+
"scripts": {
|
|
31
|
+
"build": "umi-scripts father build",
|
|
32
|
+
"build:deps": "umi-scripts bundleDeps",
|
|
33
|
+
"dev": "umi-scripts father dev",
|
|
34
|
+
"test": "umi-scripts jest-turbo"
|
|
35
|
+
}
|
|
36
|
+
}
|