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

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,100 @@
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
+ Object.assign({ bugfixes: true,
17
+ // 更兼容 spec,但会变慢,所以不开
18
+ spec: false,
19
+ // 推荐用 top level 的 assumptions 配置
20
+ loose: false,
21
+ // 保留 es modules 语法,交给 webpack 处理
22
+ modules: false, debug: false, useBuiltIns: 'entry', corejs: (0, utils_1.getCorejsVersion)((0, path_1.join)(__dirname, '../package.json')),
23
+ // 没必要,遇到了应该改 targets 配置
24
+ forceAllTransforms: false, ignoreBrowserslistConfig: true }, opts.presetEnv),
25
+ ],
26
+ [
27
+ require.resolve('@umijs/bundler-utils/compiled/babel/preset-react'),
28
+ Object.assign({ runtime: 'automatic', development: process.env.NODE_ENV === 'development', importSource: 'react' }, opts.presetReact),
29
+ ],
30
+ [
31
+ require.resolve('@umijs/bundler-utils/compiled/babel/preset-typescript'),
32
+ Object.assign({
33
+ // 支持vue 后缀
34
+ allExtensions: true,
35
+ // 支持tsx
36
+ isTSX: true, allowNamespaces: true, allowDeclareFields: true, onlyRemoveTypeImports: true, optimizeConstEnums: true }, opts.presetTypeScript),
37
+ ],
38
+ ],
39
+ plugins: [
40
+ // TC39 Proposals
41
+ // class-static-block
42
+ // decorators
43
+ [
44
+ require.resolve('@umijs/bundler-utils/compiled/babel/plugin-proposal-decorators'),
45
+ { legacy: true },
46
+ ],
47
+ // do-expressions
48
+ [
49
+ require.resolve('@umijs/bundler-utils/compiled/babel/plugin-proposal-do-expressions'),
50
+ ],
51
+ // export-default-from
52
+ [
53
+ require.resolve('@umijs/bundler-utils/compiled/babel/plugin-proposal-export-default-from'),
54
+ ],
55
+ // export-namespace-from
56
+ [
57
+ require.resolve('@umijs/bundler-utils/compiled/babel/plugin-proposal-export-namespace-from'),
58
+ ],
59
+ // function-bind
60
+ [
61
+ require.resolve('@umijs/bundler-utils/compiled/babel/plugin-proposal-function-bind'),
62
+ ],
63
+ // function-sent
64
+ // partial-application
65
+ [
66
+ require.resolve('@umijs/bundler-utils/compiled/babel/plugin-proposal-partial-application'),
67
+ ],
68
+ // pipeline-operator
69
+ [
70
+ require.resolve('@umijs/bundler-utils/compiled/babel/plugin-proposal-pipeline-operator'),
71
+ { proposal: 'minimal' },
72
+ ],
73
+ // throw-expressions
74
+ // record-and-tuple
75
+ [
76
+ require.resolve('@umijs/bundler-utils/compiled/babel/plugin-proposal-record-and-tuple'),
77
+ {
78
+ syntaxType: 'hash',
79
+ importPolyfill: true,
80
+ polyfillModuleName: (0, path_1.dirname)(require.resolve('@bloomberg/record-tuple-polyfill/package')),
81
+ },
82
+ ],
83
+ opts.pluginTransformRuntime && [
84
+ require.resolve('@umijs/bundler-utils/compiled/babel/plugin-transform-runtime'),
85
+ Object.assign({ helpers: true, regenerator: true,
86
+ // 7.13 之后根据 exports 自动选择 esm 和 cjs,无需此配置
87
+ useESModules: false,
88
+ // lock the version of @babel/runtime
89
+ // make sure we are using the correct version
90
+ // ref: https://github.com/babel/babel/blob/v7.16.12/packages/babel-plugin-transform-runtime/src/get-runtime-path/index.ts#L19
91
+ // ref: https://github.com/umijs/umi/pull/7816
92
+ absoluteRuntime: (0, path_1.dirname)(require.resolve('../package.json')), version: `^${require('@babel/runtime/package.json').version}` }, opts.pluginTransformRuntime),
93
+ ],
94
+ // none official plugins
95
+ opts.pluginLockCoreJS && [lockCoreJS_1.default],
96
+ opts.pluginDynamicImportNode && [dynamicImportNode_1.default],
97
+ opts.pluginAutoCSSModules && [autoCSSModules_1.default],
98
+ ].filter(Boolean),
99
+ };
100
+ };
@@ -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.20220429.4",
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.20220429.4",
27
+ "@umijs/utils": "4.0.0-canary.20220429.4",
28
28
  "core-js": "3.21.1"
29
29
  },
30
30
  "publishConfig": {