@umijs/babel-preset-umi 4.0.0-beta.8 → 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 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
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
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
- Object.defineProperty(exports, "__esModule", { value: true });
6
- const path_1 = require("path");
7
- const autoCSSModules_1 = __importDefault(require("./plugins/autoCSSModules"));
8
- const dynamicImportNode_1 = __importDefault(require("./plugins/dynamicImportNode"));
9
- const lockCoreJS_1 = __importDefault(require("./plugins/lockCoreJS"));
10
- exports.default = (_context, opts) => {
11
- return {
12
- presets: [
13
- [
14
- require.resolve('@umijs/bundler-utils/compiled/babel/preset-env'),
15
- Object.assign({ bugfixes: true,
16
- // 更兼容 spec,但会变慢,所以不开
17
- spec: false,
18
- // 推荐用 top level assumptions 配置
19
- loose: false,
20
- // 保留 es modules 语法,交给 webpack 处理
21
- modules: false, debug: false, useBuiltIns: 'entry', corejs: '3',
22
- // 没必要,遇到了应该改 targets 配置
23
- forceAllTransforms: false, ignoreBrowserslistConfig: true }, opts.presetEnv),
24
- ],
25
- [
26
- require.resolve('@umijs/bundler-utils/compiled/babel/preset-react'),
27
- Object.assign({ runtime: 'automatic', development: process.env.NODE_ENV === 'development', importSource: 'react' }, opts.presetReact),
28
- ],
29
- [
30
- require.resolve('@umijs/bundler-utils/compiled/babel/preset-typescript'),
31
- Object.assign({ allowNamespaces: true, allowDeclareFields: true, onlyRemoveTypeImports: true, optimizeConstEnums: true }, opts.presetTypeScript),
32
- ],
33
- ],
34
- plugins: [
35
- // TC39 Proposals
36
- // class-static-block
37
- // decorators
38
- [
39
- require.resolve('@umijs/bundler-utils/compiled/babel/plugin-proposal-decorators'),
40
- { legacy: true },
41
- ],
42
- // do-expressions
43
- [
44
- require.resolve('@umijs/bundler-utils/compiled/babel/plugin-proposal-do-expressions'),
45
- ],
46
- // export-default-from
47
- [
48
- require.resolve('@umijs/bundler-utils/compiled/babel/plugin-proposal-export-default-from'),
49
- ],
50
- // export-namespace-from
51
- [
52
- require.resolve('@umijs/bundler-utils/compiled/babel/plugin-proposal-export-namespace-from'),
53
- ],
54
- // function-bind
55
- [
56
- require.resolve('@umijs/bundler-utils/compiled/babel/plugin-proposal-function-bind'),
57
- ],
58
- // function-sent
59
- // partial-application
60
- [
61
- require.resolve('@umijs/bundler-utils/compiled/babel/plugin-proposal-partial-application'),
62
- ],
63
- // pipeline-operator
64
- [
65
- require.resolve('@umijs/bundler-utils/compiled/babel/plugin-proposal-pipeline-operator'),
66
- { proposal: 'minimal' },
67
- ],
68
- // throw-expressions
69
- // record-and-tuple
70
- [
71
- require.resolve('@umijs/bundler-utils/compiled/babel/plugin-proposal-record-and-tuple'),
72
- {
73
- syntaxType: 'hash',
74
- importPolyfill: true,
75
- polyfillModuleName: (0, path_1.dirname)(require.resolve('@bloomberg/record-tuple-polyfill/package')),
76
- },
77
- ],
78
- opts.pluginTransformRuntime && [
79
- require.resolve('@umijs/bundler-utils/compiled/babel/plugin-transform-runtime'),
80
- Object.assign({ helpers: true, regenerator: true,
81
- // 7.13 之后根据 exports 自动选择 esm 和 cjs,无需此配置
82
- useESModules: false,
83
- // lock the version of @babel/runtime
84
- // make sure we are using the correct version
85
- absoluteRuntime: (0, path_1.dirname)(require.resolve('@babel/runtime/package.json')), version: `^${require('@babel/runtime/package.json').version}` }, opts.pluginTransformRuntime),
86
- ],
87
- // none official plugins
88
- opts.pluginLockCoreJS && [lockCoreJS_1.default],
89
- opts.pluginDynamicImportNode && [dynamicImportNode_1.default],
90
- opts.pluginAutoCSSModules && [autoCSSModules_1.default],
91
- ].filter(Boolean),
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
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
- }) : (function(o, m, k, k2) {
6
- if (k2 === undefined) k2 = k;
7
- o[k2] = m[k];
8
- }));
9
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
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 });
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
- Object.defineProperty(exports, "__esModule", { value: true });
22
- const t = __importStar(require("@umijs/bundler-utils/compiled/babel/types"));
23
- const path_1 = require("path");
24
- const CSS_EXT_NAMES = ['.css', '.less', '.sass', '.scss', '.stylus', '.styl'];
25
- function default_1() {
26
- return {
27
- visitor: {
28
- ImportDeclaration(path) {
29
- const { specifiers, source, source: { value }, } = path.node;
30
- if (specifiers.length && CSS_EXT_NAMES.includes((0, path_1.extname)(value))) {
31
- source.value = `${value}?modules`;
32
- }
33
- },
34
- // e.g.
35
- // const styles = await import('./index.less');
36
- VariableDeclarator(path) {
37
- const { node } = path;
38
- if (t.isAwaitExpression(node.init) &&
39
- t.isCallExpression(node.init.argument) &&
40
- t.isImport(node.init.argument.callee) &&
41
- node.init.argument.arguments.length === 1 &&
42
- t.isStringLiteral(node.init.argument.arguments[0]) &&
43
- CSS_EXT_NAMES.includes((0, path_1.extname)(node.init.argument.arguments[0].value))) {
44
- node.init.argument.arguments[0].value = `${node.init.argument.arguments[0].value}?modules`;
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
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
- }) : (function(o, m, k, k2) {
6
- if (k2 === undefined) k2 = k;
7
- o[k2] = m[k];
8
- }));
9
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
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 __importDefault = (this && this.__importDefault) || function (mod) {
22
- return (mod && mod.__esModule) ? mod : { "default": mod };
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
- Object.defineProperty(exports, "__esModule", { value: true });
25
- const template_1 = __importDefault(require("@umijs/bundler-utils/compiled/babel/template"));
26
- const t = __importStar(require("@umijs/bundler-utils/compiled/babel/types"));
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
- // @ts-ignore
29
- const importArguments = callNode.arguments;
30
- const [importPath] = importArguments;
31
- const isString = t.isStringLiteral(importPath) || t.isTemplateLiteral(importPath);
32
- if (isString) {
33
- t.removeComments(importPath);
34
- return importPath;
35
- }
36
- return t.templateLiteral([
37
- t.templateElement({ raw: '', cooked: '' }),
38
- t.templateElement({ raw: '', cooked: '' }, true),
39
- ], importArguments);
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
- const builders = {
42
- static: (0, template_1.default)('Promise.resolve().then(() => INTEROP(require(SOURCE)))'),
43
- dynamic: (0, template_1.default)('Promise.resolve(SOURCE).then(s => INTEROP(require(s)))'),
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
- return (t.isStringLiteral(node) ||
47
- (t.isTemplateLiteral(node) && node.expressions.length === 0));
58
+ return t.isStringLiteral(node) || t.isTemplateLiteral(node) && node.expressions.length === 0;
48
59
  }
49
- exports.default = () => {
50
- const visited = new WeakSet();
51
- return {
52
- visitor: {
53
- Import(path) {
54
- if (visited) {
55
- if (visited.has(path)) {
56
- return;
57
- }
58
- visited.add(path);
59
- }
60
- const SOURCE = getImportSource(path.parent);
61
- const builder = isString(SOURCE) ? builders.static : builders.dynamic;
62
- const newImport = builder({
63
- SOURCE,
64
- INTEROP: path.hub.addHelper('interopRequireWildcard'),
65
- });
66
- // @ts-ignore
67
- path.parentPath.replaceWith(newImport);
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
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
- }) : (function(o, m, k, k2) {
6
- if (k2 === undefined) k2 = k;
7
- o[k2] = m[k];
8
- }));
9
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
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 });
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
- Object.defineProperty(exports, "__esModule", { value: true });
22
- const t = __importStar(require("@umijs/bundler-utils/compiled/babel/types"));
23
- const utils_1 = require("@umijs/utils");
24
- const path_1 = require("path");
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
- return path.endsWith('/') ? path : `${path}/`;
39
+ return path.endsWith("/") ? path : `${path}/`;
27
40
  }
28
- function default_1() {
29
- return {
30
- post({ path }) {
31
- path.node.body.forEach((node) => {
32
- if (t.isImportDeclaration(node)) {
33
- if (node.source.value.startsWith('core-js/')) {
34
- node.source.value = node.source.value.replace(/^core-js\//, addLastSlash((0, utils_1.winPath)((0, path_1.dirname)(require.resolve('core-js/package.json')))));
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,3 @@
1
+ import * as Babel from '@umijs/bundler-utils/compiled/babel/core';
2
+ declare const _default: () => Babel.PluginObj;
3
+ export default _default;
@@ -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,35 +1,36 @@
1
1
  {
2
2
  "name": "@umijs/babel-preset-umi",
3
- "version": "4.0.0-beta.8",
3
+ "version": "4.0.0-canary-20240513.3",
4
4
  "description": "Official babel preset for umi.",
5
+ "homepage": "https://github.com/umijs/umi/tree/master/packages/babel-preset-umi#readme",
6
+ "bugs": "https://github.com/umijs/umi/issues",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "https://github.com/umijs/umi"
10
+ },
11
+ "license": "MIT",
5
12
  "main": "dist/index.js",
6
13
  "types": "dist/index.d.ts",
7
14
  "files": [
8
15
  "dist"
9
16
  ],
10
- "scripts": {
11
- "build": "pnpm tsc",
12
- "build:deps": "pnpm esno ../../scripts/bundleDeps.ts",
13
- "dev": "pnpm build -- --watch"
17
+ "dependencies": {
18
+ "@babel/runtime": "7.23.6",
19
+ "@bloomberg/record-tuple-polyfill": "0.0.4",
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"
14
23
  },
15
- "repository": {
16
- "type": "git",
17
- "url": "https://github.com/umijs/umi-next"
24
+ "publishConfig": {
25
+ "access": "public"
18
26
  },
19
27
  "authors": [
20
28
  "chencheng <sorrycc@gmail.com> (https://github.com/sorrycc)"
21
29
  ],
22
- "license": "MIT",
23
- "bugs": "https://github.com/umijs/umi-next/issues",
24
- "homepage": "https://github.com/umijs/umi-next/tree/master/packages/babel-preset-umi#readme",
25
- "publishConfig": {
26
- "access": "public"
27
- },
28
- "dependencies": {
29
- "@babel/runtime": "7.16.0",
30
- "@bloomberg/record-tuple-polyfill": "0.0.4",
31
- "@umijs/bundler-utils": "4.0.0-beta.8",
32
- "@umijs/utils": "4.0.0-beta.8",
33
- "core-js": "3.19.0"
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"
34
35
  }
35
- }
36
+ }
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAKA,UAAU,KAAK;IACb,SAAS,EAAE,GAAG,CAAC;IACf,WAAW,EAAE,GAAG,CAAC;IACjB,gBAAgB,EAAE,GAAG,CAAC;IACtB,sBAAsB,EAAE,GAAG,CAAC;IAC5B,gBAAgB,EAAE,GAAG,CAAC;IACtB,uBAAuB,EAAE,GAAG,CAAC;IAC7B,oBAAoB,EAAE,GAAG,CAAC;CAC3B;mCAEyB,GAAG,QAAQ,KAAK;;;;AAA1C,wBAkIE"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"autoCSSModules.d.ts","sourceRoot":"","sources":["../../src/plugins/autoCSSModules.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,0CAA0C,CAAC;AAClE,OAAO,KAAK,CAAC,MAAM,2CAA2C,CAAC;AAK/D,MAAM,CAAC,OAAO;;gCAGgB,MAAM,QAAQ,CAAC,EAAE,iBAAiB,CAAC;iCAalC,MAAM,QAAQ,CAAC,EAAE,kBAAkB,CAAC;;EAelE"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"dynamicImportNode.d.ts","sourceRoot":"","sources":["../../src/plugins/dynamicImportNode.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,0CAA0C,CAAC;8BAqC/C,MAAM,SAAS;AAAlC,wBAuBE"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"lockCoreJS.d.ts","sourceRoot":"","sources":["../../src/plugins/lockCoreJS.ts"],"names":[],"mappings":"AAQA,MAAM,CAAC,OAAO;mBAEK,GAAG;EAerB"}