@umijs/babel-preset-umi 4.0.0-canary.20220429.3 → 4.0.0-canary.20220506.2

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.
@@ -0,0 +1,14 @@
1
+ interface IOpts {
2
+ presetEnv: any;
3
+ presetReact: any;
4
+ presetTypeScript: any;
5
+ pluginTransformRuntime: any;
6
+ pluginLockCoreJS: any;
7
+ pluginDynamicImportNode: any;
8
+ pluginAutoCSSModules: any;
9
+ }
10
+ declare const _default: (_context: any, opts: IOpts) => {
11
+ presets: any[][];
12
+ plugins: any[];
13
+ };
14
+ export default _default;
package/dist/index.js ADDED
@@ -0,0 +1,123 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const utils_1 = require("@umijs/utils");
7
+ const path_1 = require("path");
8
+ const autoCSSModules_1 = __importDefault(require("./plugins/autoCSSModules"));
9
+ const dynamicImportNode_1 = __importDefault(require("./plugins/dynamicImportNode"));
10
+ const lockCoreJS_1 = __importDefault(require("./plugins/lockCoreJS"));
11
+ exports.default = (_context, opts) => {
12
+ return {
13
+ presets: [
14
+ [
15
+ require.resolve('@umijs/bundler-utils/compiled/babel/preset-env'),
16
+ {
17
+ bugfixes: true,
18
+ // 更兼容 spec,但会变慢,所以不开
19
+ spec: false,
20
+ // 推荐用 top level 的 assumptions 配置
21
+ loose: false,
22
+ // 保留 es modules 语法,交给 webpack 处理
23
+ modules: false,
24
+ debug: false,
25
+ useBuiltIns: 'entry',
26
+ corejs: (0, utils_1.getCorejsVersion)((0, path_1.join)(__dirname, '../package.json')),
27
+ // 没必要,遇到了应该改 targets 配置
28
+ forceAllTransforms: false,
29
+ ignoreBrowserslistConfig: true,
30
+ ...opts.presetEnv,
31
+ },
32
+ ],
33
+ [
34
+ require.resolve('@umijs/bundler-utils/compiled/babel/preset-react'),
35
+ {
36
+ runtime: 'automatic',
37
+ development: process.env.NODE_ENV === 'development',
38
+ importSource: 'react',
39
+ ...opts.presetReact,
40
+ },
41
+ ],
42
+ [
43
+ require.resolve('@umijs/bundler-utils/compiled/babel/preset-typescript'),
44
+ {
45
+ // 支持vue 后缀
46
+ allExtensions: true,
47
+ // 支持tsx
48
+ isTSX: true,
49
+ allowNamespaces: true,
50
+ allowDeclareFields: true,
51
+ onlyRemoveTypeImports: true,
52
+ optimizeConstEnums: true,
53
+ ...opts.presetTypeScript,
54
+ },
55
+ ],
56
+ ],
57
+ plugins: [
58
+ // TC39 Proposals
59
+ // class-static-block
60
+ // decorators
61
+ [
62
+ require.resolve('@umijs/bundler-utils/compiled/babel/plugin-proposal-decorators'),
63
+ { legacy: true },
64
+ ],
65
+ // do-expressions
66
+ [
67
+ require.resolve('@umijs/bundler-utils/compiled/babel/plugin-proposal-do-expressions'),
68
+ ],
69
+ // export-default-from
70
+ [
71
+ require.resolve('@umijs/bundler-utils/compiled/babel/plugin-proposal-export-default-from'),
72
+ ],
73
+ // export-namespace-from
74
+ [
75
+ require.resolve('@umijs/bundler-utils/compiled/babel/plugin-proposal-export-namespace-from'),
76
+ ],
77
+ // function-bind
78
+ [
79
+ require.resolve('@umijs/bundler-utils/compiled/babel/plugin-proposal-function-bind'),
80
+ ],
81
+ // function-sent
82
+ // partial-application
83
+ [
84
+ require.resolve('@umijs/bundler-utils/compiled/babel/plugin-proposal-partial-application'),
85
+ ],
86
+ // pipeline-operator
87
+ [
88
+ require.resolve('@umijs/bundler-utils/compiled/babel/plugin-proposal-pipeline-operator'),
89
+ { proposal: 'minimal' },
90
+ ],
91
+ // throw-expressions
92
+ // record-and-tuple
93
+ [
94
+ require.resolve('@umijs/bundler-utils/compiled/babel/plugin-proposal-record-and-tuple'),
95
+ {
96
+ syntaxType: 'hash',
97
+ importPolyfill: true,
98
+ polyfillModuleName: (0, path_1.dirname)(require.resolve('@bloomberg/record-tuple-polyfill/package')),
99
+ },
100
+ ],
101
+ opts.pluginTransformRuntime && [
102
+ require.resolve('@umijs/bundler-utils/compiled/babel/plugin-transform-runtime'),
103
+ {
104
+ helpers: true,
105
+ regenerator: true,
106
+ // 7.13 之后根据 exports 自动选择 esm 和 cjs,无需此配置
107
+ useESModules: false,
108
+ // lock the version of @babel/runtime
109
+ // make sure we are using the correct version
110
+ // ref: https://github.com/babel/babel/blob/v7.16.12/packages/babel-plugin-transform-runtime/src/get-runtime-path/index.ts#L19
111
+ // ref: https://github.com/umijs/umi/pull/7816
112
+ absoluteRuntime: (0, path_1.dirname)(require.resolve('../package.json')),
113
+ version: `^${require('@babel/runtime/package.json').version}`,
114
+ ...opts.pluginTransformRuntime,
115
+ },
116
+ ],
117
+ // none official plugins
118
+ opts.pluginLockCoreJS && [lockCoreJS_1.default],
119
+ opts.pluginDynamicImportNode && [dynamicImportNode_1.default],
120
+ opts.pluginAutoCSSModules && [autoCSSModules_1.default],
121
+ ].filter(Boolean),
122
+ };
123
+ };
@@ -0,0 +1,8 @@
1
+ import * as Babel from '@umijs/bundler-utils/compiled/babel/core';
2
+ import * as t from '@umijs/bundler-utils/compiled/babel/types';
3
+ export default function (): {
4
+ visitor: {
5
+ ImportDeclaration(path: Babel.NodePath<t.ImportDeclaration>): void;
6
+ VariableDeclarator(path: Babel.NodePath<t.VariableDeclarator>): void;
7
+ };
8
+ };
@@ -0,0 +1,54 @@
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
+ const path_1 = require("path");
28
+ const CSS_EXT_NAMES = ['.css', '.less', '.sass', '.scss', '.stylus', '.styl'];
29
+ function default_1() {
30
+ return {
31
+ visitor: {
32
+ ImportDeclaration(path) {
33
+ const { specifiers, source, source: { value }, } = path.node;
34
+ if (specifiers.length && CSS_EXT_NAMES.includes((0, path_1.extname)(value))) {
35
+ source.value = `${value}?modules`;
36
+ }
37
+ },
38
+ // e.g.
39
+ // const styles = await import('./index.less');
40
+ VariableDeclarator(path) {
41
+ const { node } = path;
42
+ if (t.isAwaitExpression(node.init) &&
43
+ t.isCallExpression(node.init.argument) &&
44
+ t.isImport(node.init.argument.callee) &&
45
+ node.init.argument.arguments.length === 1 &&
46
+ t.isStringLiteral(node.init.argument.arguments[0]) &&
47
+ CSS_EXT_NAMES.includes((0, path_1.extname)(node.init.argument.arguments[0].value))) {
48
+ node.init.argument.arguments[0].value = `${node.init.argument.arguments[0].value}?modules`;
49
+ }
50
+ },
51
+ },
52
+ };
53
+ }
54
+ 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,75 @@
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
+ var __importDefault = (this && this.__importDefault) || function (mod) {
26
+ return (mod && mod.__esModule) ? mod : { "default": mod };
27
+ };
28
+ Object.defineProperty(exports, "__esModule", { value: true });
29
+ const template_1 = __importDefault(require("@umijs/bundler-utils/compiled/babel/template"));
30
+ const t = __importStar(require("@umijs/bundler-utils/compiled/babel/types"));
31
+ function getImportSource(callNode) {
32
+ // @ts-ignore
33
+ const importArguments = callNode.arguments;
34
+ const [importPath] = importArguments;
35
+ const isString = t.isStringLiteral(importPath) || t.isTemplateLiteral(importPath);
36
+ if (isString) {
37
+ t.removeComments(importPath);
38
+ return importPath;
39
+ }
40
+ return t.templateLiteral([
41
+ t.templateElement({ raw: '', cooked: '' }),
42
+ t.templateElement({ raw: '', cooked: '' }, true),
43
+ ], importArguments);
44
+ }
45
+ const builders = {
46
+ static: (0, template_1.default)('Promise.resolve().then(() => INTEROP(require(SOURCE)))'),
47
+ dynamic: (0, template_1.default)('Promise.resolve(SOURCE).then(s => INTEROP(require(s)))'),
48
+ };
49
+ function isString(node) {
50
+ return (t.isStringLiteral(node) ||
51
+ (t.isTemplateLiteral(node) && node.expressions.length === 0));
52
+ }
53
+ exports.default = () => {
54
+ const visited = new WeakSet();
55
+ return {
56
+ visitor: {
57
+ Import(path) {
58
+ if (visited) {
59
+ if (visited.has(path)) {
60
+ return;
61
+ }
62
+ visited.add(path);
63
+ }
64
+ const SOURCE = getImportSource(path.parent);
65
+ const builder = isString(SOURCE) ? builders.static : builders.dynamic;
66
+ const newImport = builder({
67
+ SOURCE,
68
+ INTEROP: path.hub.addHelper('interopRequireWildcard'),
69
+ });
70
+ // @ts-ignore
71
+ path.parentPath.replaceWith(newImport);
72
+ },
73
+ },
74
+ };
75
+ };
@@ -0,0 +1,3 @@
1
+ export default function (): {
2
+ post({ path }: any): void;
3
+ };
@@ -0,0 +1,45 @@
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
+ const utils_1 = require("@umijs/utils");
28
+ const path_1 = require("path");
29
+ function addLastSlash(path) {
30
+ return path.endsWith('/') ? path : `${path}/`;
31
+ }
32
+ function default_1() {
33
+ return {
34
+ post({ path }) {
35
+ path.node.body.forEach((node) => {
36
+ if (t.isImportDeclaration(node)) {
37
+ if (node.source.value.startsWith('core-js/')) {
38
+ node.source.value = node.source.value.replace(/^core-js\//, addLastSlash((0, utils_1.winPath)((0, path_1.dirname)(require.resolve('core-js/package.json')))));
39
+ }
40
+ }
41
+ });
42
+ },
43
+ };
44
+ }
45
+ exports.default = default_1;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@umijs/babel-preset-umi",
3
- "version": "4.0.0-canary.20220429.3",
3
+ "version": "4.0.0-canary.20220506.2",
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.20220429.3",
27
- "@umijs/utils": "4.0.0-canary.20220429.3",
26
+ "@umijs/bundler-utils": "4.0.0-canary.20220506.2",
27
+ "@umijs/utils": "4.0.0-canary.20220506.2",
28
28
  "core-js": "3.21.1"
29
29
  },
30
30
  "publishConfig": {