@umijs/plugins 4.0.0-beta.11 → 4.0.0-beta.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/antd.js CHANGED
@@ -1,169 +1,138 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- const utils_1 = require("@umijs/utils");
4
- const fs_1 = require("fs");
5
3
  const path_1 = require("path");
6
- const presets = {
7
- antd: {
8
- plugins: [
9
- 'isSameOrBefore',
10
- 'isSameOrAfter',
11
- 'advancedFormat',
12
- 'customParseFormat',
13
- 'weekday',
14
- 'weekYear',
15
- 'weekOfYear',
16
- 'isMoment',
17
- 'localeData',
18
- 'localizedFormat',
19
- ],
20
- replaceMoment: true,
21
- },
22
- antdv3: {
23
- plugins: [
24
- 'isSameOrBefore',
25
- 'isSameOrAfter',
26
- 'advancedFormat',
27
- 'customParseFormat',
28
- 'weekday',
29
- 'weekYear',
30
- 'weekOfYear',
31
- 'isMoment',
32
- 'localeData',
33
- 'localizedFormat',
34
- 'badMutable',
35
- ],
36
- replaceMoment: true,
37
- },
38
- };
39
- const getConfig = (api) => {
40
- let { preset = 'antd', plugins, replaceMoment, } = api.userConfig.antdDayjs || {};
41
- if (preset && presets[preset]) {
42
- plugins = presets[preset].plugins;
43
- replaceMoment = presets[preset].replaceMoment;
44
- }
45
- if (plugins)
46
- plugins = plugins;
47
- if (replaceMoment !== undefined)
48
- replaceMoment = replaceMoment;
49
- return {
50
- plugins,
51
- replaceMoment,
52
- };
53
- };
54
- const DIR_NAME = 'plugin-antd';
4
+ const plugin_utils_1 = require("umi/plugin-utils");
5
+ const resolveProjectDep_1 = require("./utils/resolveProjectDep");
6
+ const withTmpPath_1 = require("./utils/withTmpPath");
55
7
  exports.default = (api) => {
56
- const opts = api.userConfig.antd;
57
- // dayjs (by default)
58
- const { dayjs = true } = opts;
8
+ const pkgPath = (0, resolveProjectDep_1.resolveProjectDep)({
9
+ pkg: api.pkg,
10
+ cwd: api.cwd,
11
+ dep: 'antd',
12
+ }) || (0, path_1.dirname)(require.resolve('antd/package.json'));
59
13
  api.describe({
60
14
  config: {
61
15
  schema(Joi) {
62
16
  return Joi.object({
17
+ configProvider: Joi.object(),
18
+ // themes
63
19
  dark: Joi.boolean(),
64
20
  compact: Joi.boolean(),
65
- config: Joi.object(),
66
- dayjs: Joi.alternatives(Joi.boolean(), Joi.object({
67
- preset: Joi.string(),
68
- plugins: Joi.array(),
69
- replaceMoment: Joi.boolean(),
70
- })),
21
+ // babel-plugin-import
22
+ import: Joi.boolean(),
23
+ // less or css, default less
24
+ style: Joi.string().allow('less', 'css'),
71
25
  });
72
26
  },
73
27
  },
28
+ enableBy: api.EnableBy.config,
29
+ });
30
+ api.modifyAppData((memo) => {
31
+ const version = require(`${pkgPath}/package.json`).version;
32
+ memo.antd = {
33
+ pkgPath,
34
+ version,
35
+ };
36
+ return memo;
74
37
  });
75
- // antd import
76
- // TODO: use api.modifyConfig for support with vite
77
- api.chainWebpack((memo) => {
78
- function getUserLibDir({ library }) {
79
- if (
80
- // @ts-ignore
81
- (api.pkg.dependencies && api.pkg.dependencies[library]) ||
82
- // @ts-ignore
83
- (api.pkg.devDependencies && api.pkg.devDependencies[library]) ||
84
- // egg project using `clientDependencies` in ali tnpm
85
- // @ts-ignore
86
- (api.pkg.clientDependencies && api.pkg.clientDependencies[library])) {
87
- return (0, utils_1.winPath)((0, path_1.dirname)(
88
- // 通过 resolve 往上找,可支持 lerna 仓库
89
- // lerna 仓库如果用 yarn workspace 的依赖不一定在 node_modules,可能被提到根目录,并且没有 link
90
- utils_1.resolve.sync(`${library}/package.json`, {
91
- basedir: api.paths.cwd,
92
- })));
93
- }
94
- return null;
38
+ api.modifyConfig((memo) => {
39
+ // antd import
40
+ memo.alias.antd = pkgPath;
41
+ // moment > dayjs
42
+ if (memo.antd.dayjs) {
43
+ memo.alias.moment = (0, path_1.dirname)(require.resolve('dayjs/package.json'));
95
44
  }
96
- memo.resolve.alias.set('antd', getUserLibDir({ library: 'antd' }) ||
97
- (0, path_1.dirname)(require.resolve('antd/package.json')));
98
- if (dayjs !== false) {
99
- const { replaceMoment } = getConfig(api);
100
- if (replaceMoment) {
101
- memo.resolve.alias.set('moment', getUserLibDir({ library: 'dayjs' }) ||
102
- (0, path_1.dirname)(require.resolve('dayjs/package.json')));
103
- }
45
+ // dark mode & compact mode
46
+ if (memo.antd.dark || memo.antd.compact) {
47
+ const { getThemeVariables } = require('antd/dist/theme');
48
+ memo.theme = Object.assign(Object.assign({}, getThemeVariables(memo.antd)), memo.theme);
104
49
  }
105
50
  return memo;
106
51
  });
107
- // dark mode
108
- // compat mode
109
- if ((opts === null || opts === void 0 ? void 0 : opts.dark) || (opts === null || opts === void 0 ? void 0 : opts.compact)) {
110
- // support dark mode, user use antd 4 by default
111
- const { getThemeVariables } = require('antd/dist/theme');
112
- api.modifyDefaultConfig((config) => {
113
- config.theme = Object.assign(Object.assign({}, getThemeVariables(opts)), config.theme);
114
- return config;
115
- });
116
- }
117
- if (dayjs !== false) {
118
- api.onGenerateFiles({
119
- fn: () => {
120
- const { plugins } = getConfig(api);
121
- const runtimeTpl = (0, fs_1.readFileSync)((0, path_1.join)(__dirname, '../templates/antd/dayjs.tpl'), 'utf-8');
122
- api.writeTmpFile({
123
- path: 'plugin-antd/dayjs.tsx',
124
- content: utils_1.Mustache.render(runtimeTpl, {
125
- plugins,
126
- dayjsPath: (0, path_1.dirname)(require.resolve('dayjs/package.json')),
127
- dayjsPluginPath: (0, path_1.dirname)(require.resolve('antd-dayjs-webpack-plugin/package.json')),
128
- }),
129
- });
130
- },
131
- });
132
- api.addEntryCodeAhead(() => {
133
- return [`import './${DIR_NAME}/dayjs.tsx'`];
134
- });
135
- }
136
52
  // babel-plugin-import
137
53
  api.addExtraBabelPlugins(() => {
138
- return [
139
- [
140
- require.resolve('babel-plugin-import'),
141
- {
142
- libraryName: 'antd',
143
- libraryDirectory: 'es',
144
- style: true,
145
- },
146
- ],
147
- ];
54
+ const style = api.config.antd.style || 'less';
55
+ return api.config.antd.import
56
+ ? [
57
+ [
58
+ require.resolve('babel-plugin-import'),
59
+ {
60
+ libraryName: 'antd',
61
+ libraryDirectory: 'es',
62
+ style: style === 'less' ? true : 'css',
63
+ },
64
+ ],
65
+ ]
66
+ : [];
148
67
  });
68
+ // if (dayjs !== false) {
69
+ // api.onGenerateFiles({
70
+ // fn: () => {
71
+ // const { plugins } = getConfig(api);
72
+ //
73
+ // const runtimeTpl = readFileSync(
74
+ // join(__dirname, '../templates/antd/dayjs.tpl'),
75
+ // 'utf-8',
76
+ // );
77
+ // api.writeTmpFile({
78
+ // path: 'plugin-antd/dayjs.tsx',
79
+ // content: Mustache.render(runtimeTpl, {
80
+ // plugins,
81
+ // dayjsPath: dirname(require.resolve('dayjs/package.json')),
82
+ // dayjsPluginPath: dirname(
83
+ // require.resolve('antd-dayjs-webpack-plugin/package.json'),
84
+ // ),
85
+ // }),
86
+ // });
87
+ // },
88
+ // });
89
+ // api.addEntryCodeAhead(() => {
90
+ // return [`import './${DIR_NAME}/dayjs.tsx'`];
91
+ // });
92
+ // }
149
93
  // antd config provider
150
- // TODO: use umi provider
151
- if (opts === null || opts === void 0 ? void 0 : opts.config) {
152
- api.onGenerateFiles({
153
- fn() {
154
- // runtime.tsx
155
- const runtimeTpl = (0, fs_1.readFileSync)((0, path_1.join)(__dirname, '../templates/antd/runtime.tpl'), 'utf-8');
156
- api.writeTmpFile({
157
- path: `${DIR_NAME}/runtime.tsx`,
158
- content: utils_1.Mustache.render(runtimeTpl, {
159
- config: JSON.stringify(opts === null || opts === void 0 ? void 0 : opts.config),
160
- }),
161
- });
162
- },
94
+ api.onGenerateFiles(() => {
95
+ if (!api.config.antd.config)
96
+ return;
97
+ api.writeTmpFile({
98
+ path: `runtime.tsx`,
99
+ content: plugin_utils_1.Mustache.render(`
100
+ import { ConfigProvider, Modal, message, notification } from 'antd';
101
+
102
+ export function rootContainer(container) {
103
+ const finalConfig = {...{{{ config }}}}
104
+ if (finalConfig.prefixCls) {
105
+ Modal.config({
106
+ rootPrefixCls: finalConfig.prefixCls
107
+ });
108
+ message.config({
109
+ prefixCls: \`\${finalConfig.prefixCls}-message\`
110
+ });
111
+ notification.config({
112
+ prefixCls: \`\${finalConfig.prefixCls}-notification\`
113
+ });
114
+ }
115
+ return <ConfigProvider {...finalConfig}>{container}</ConfigProvider>;
116
+ }
117
+ `.trim(), {
118
+ config: JSON.stringify(api.config.antd.config),
119
+ }),
163
120
  });
164
- //TODO:Runtime Plugin
165
- api.addRuntimePlugin(() => [
166
- (0, path_1.join)(api.paths.absTmpPath, DIR_NAME, 'runtime.tsx'),
167
- ]);
168
- }
121
+ });
122
+ api.addRuntimePlugin(() => {
123
+ return api.config.antd.config
124
+ ? [(0, withTmpPath_1.withTmpPath)({ api, path: 'runtime.tsx' })]
125
+ : [];
126
+ });
127
+ // import antd style if antd.import is not configured
128
+ api.addEntryImportsAhead(() => {
129
+ const style = api.config.antd.style || 'less';
130
+ return api.config.antd.import
131
+ ? []
132
+ : [
133
+ {
134
+ source: style === 'less' ? 'antd/dist/antd.less' : 'antd/dist/antd.css',
135
+ },
136
+ ];
137
+ });
169
138
  };
File without changes
File without changes
package/dist/dva.d.ts CHANGED
@@ -1,3 +1,12 @@
1
1
  import { IApi } from 'umi';
2
2
  declare const _default: (api: IApi) => void;
3
3
  export default _default;
4
+ export declare function getAllModels(api: IApi): string[][];
5
+ export declare function getModels(opts: {
6
+ base: string;
7
+ pattern?: string;
8
+ }): string[];
9
+ export declare function isModelValid(opts: {
10
+ content: string;
11
+ file: string;
12
+ }): boolean;
package/dist/dva.js CHANGED
@@ -1,9 +1,222 @@
1
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;
20
+ };
21
+ var __importDefault = (this && this.__importDefault) || function (mod) {
22
+ return (mod && mod.__esModule) ? mod : { "default": mod };
23
+ };
2
24
  Object.defineProperty(exports, "__esModule", { value: true });
25
+ exports.isModelValid = exports.getModels = exports.getAllModels = void 0;
26
+ const parser = __importStar(require("@umijs/bundler-utils/compiled/babel/parser"));
27
+ const traverse_1 = __importDefault(require("@umijs/bundler-utils/compiled/babel/traverse"));
28
+ const t = __importStar(require("@umijs/bundler-utils/compiled/babel/types"));
29
+ const esbuild_1 = require("@umijs/bundler-utils/compiled/esbuild");
30
+ const fs_1 = require("fs");
31
+ const path_1 = require("path");
32
+ const plugin_utils_1 = require("umi/plugin-utils");
33
+ const getIdentifierDeclaration_1 = require("./utils/getIdentifierDeclaration");
34
+ const resolveProjectDep_1 = require("./utils/resolveProjectDep");
35
+ const withTmpPath_1 = require("./utils/withTmpPath");
3
36
  exports.default = (api) => {
4
- api;
5
- // import from dva
6
- // model register
7
- // container
37
+ const pkgPath = (0, resolveProjectDep_1.resolveProjectDep)({
38
+ pkg: api.pkg,
39
+ cwd: api.cwd,
40
+ dep: 'dva',
41
+ }) || (0, path_1.dirname)(require.resolve('dva/package.json'));
42
+ api.describe({
43
+ config: {
44
+ schema(Joi) {
45
+ return Joi.object();
46
+ },
47
+ },
48
+ enableBy: api.EnableBy.config,
49
+ });
50
+ api.modifyAppData((memo) => {
51
+ const version = require(`${pkgPath}/package.json`).version;
52
+ memo.dva = {
53
+ pkgPath,
54
+ version,
55
+ };
56
+ return memo;
57
+ });
58
+ api.modifyConfig((memo) => {
59
+ // import from dva
60
+ memo.alias.dva = pkgPath;
61
+ return memo;
62
+ });
63
+ api.modifyAppData((memo) => {
64
+ const models = getAllModels(api);
65
+ memo.pluginDva = {
66
+ pkgPath,
67
+ models,
68
+ };
69
+ return memo;
70
+ });
71
+ api.onGenerateFiles((args) => {
72
+ const models = args.isFirstTime
73
+ ? api.appData.pluginDva.models
74
+ : getAllModels(api);
75
+ models;
76
+ // dva.tsx
77
+ api.writeTmpFile({
78
+ path: 'dva.tsx',
79
+ tpl: `
80
+ import dva from 'dva';
81
+ import { useRef } from 'react';
82
+ import { useAppContext } from 'umi';
83
+
84
+ export function RootContainer(props: any) {
85
+ const { navigator } = useAppContext();
86
+ const app = useRef();
87
+ if (!app.current) {
88
+ app.current = dva({
89
+ history: navigator,
90
+ initialState: props.initialState,
91
+ });
92
+ app.current.model({
93
+ namespace: 'count',
94
+ state: 0,
95
+ });
96
+ app.current.router(() => props.children);
97
+ }
98
+ return app.current.start()();
99
+ }
100
+ `,
101
+ context: {},
102
+ });
103
+ // runtime.tsx
104
+ api.writeTmpFile({
105
+ path: 'runtime.tsx',
106
+ content: `
107
+ import React from 'react';
108
+ import { RootContainer } from './dva';
109
+
110
+ export function dataflowProvider(container, opts) {
111
+ return React.createElement(RootContainer, opts, container);
112
+ }
113
+ `,
114
+ });
115
+ // index.ts for export
116
+ api.writeTmpFile({
117
+ path: 'index.ts',
118
+ content: `
119
+ export { connect, useDispatch, useStore, useSelector } from 'dva';`,
120
+ });
121
+ });
122
+ api.addTmpGenerateWatcherPaths(() => {
123
+ return [(0, path_1.join)(api.paths.absSrcPath, 'models')];
124
+ });
125
+ api.addRuntimePlugin(() => {
126
+ return [(0, withTmpPath_1.withTmpPath)({ api, path: 'runtime.tsx' })];
127
+ });
8
128
  // dva list model
129
+ api.registerCommand({
130
+ name: 'dva',
131
+ fn() {
132
+ api.logger.info(plugin_utils_1.chalk.green.bold('dva models'));
133
+ api.appData.pluginDva.models.forEach((model) => {
134
+ api.logger.info(` - ${model}`);
135
+ });
136
+ },
137
+ });
9
138
  };
139
+ function getAllModels(api) {
140
+ return [
141
+ getModels({
142
+ base: (0, path_1.join)(api.paths.absSrcPath, 'models'),
143
+ pattern: '**/*.{ts,tsx,js,jsx}',
144
+ }),
145
+ getModels({
146
+ base: (0, path_1.join)(api.paths.absPagesPath),
147
+ pattern: '**/models/**/*.{ts,tsx,js,jsx}',
148
+ }),
149
+ getModels({
150
+ base: (0, path_1.join)(api.paths.absPagesPath),
151
+ pattern: '**/model.{ts,tsx,js,jsx}',
152
+ }),
153
+ ];
154
+ }
155
+ exports.getAllModels = getAllModels;
156
+ function getModels(opts) {
157
+ return plugin_utils_1.glob
158
+ .sync(opts.pattern || '**/*.{ts,js}', {
159
+ cwd: opts.base,
160
+ absolute: true,
161
+ })
162
+ .map(plugin_utils_1.winPath)
163
+ .filter((file) => {
164
+ if (/\.d.ts$/.test(file))
165
+ return false;
166
+ if (/\.(test|e2e|spec).([jt])sx?$/.test(file))
167
+ return false;
168
+ const content = (0, fs_1.readFileSync)(file, 'utf-8');
169
+ return isModelValid({ content, file });
170
+ });
171
+ }
172
+ exports.getModels = getModels;
173
+ function isModelValid(opts) {
174
+ const { file, content } = opts;
175
+ // 标注式声明
176
+ if (content.startsWith('// @dva-model'))
177
+ return true;
178
+ // transform with esbuild first
179
+ // to reduce unexpected ast problem
180
+ const loader = (0, path_1.extname)(file).slice(1);
181
+ const result = (0, esbuild_1.transformSync)(content, {
182
+ loader,
183
+ sourcemap: false,
184
+ minify: false,
185
+ });
186
+ // transform with babel
187
+ let ret = false;
188
+ const ast = parser.parse(result.code, {
189
+ sourceType: 'module',
190
+ sourceFilename: file,
191
+ plugins: [],
192
+ });
193
+ (0, traverse_1.default)(ast, {
194
+ ExportDefaultDeclaration(path) {
195
+ let node = path.node.declaration;
196
+ node = (0, getIdentifierDeclaration_1.getIdentifierDeclaration)(node, path);
197
+ if (isModelObject(node)) {
198
+ ret = true;
199
+ }
200
+ else if (content.includes('dva-model-extend') &&
201
+ t.isCallExpression(node) &&
202
+ node.arguments.length === 2 &&
203
+ isModelObject(node.arguments[1])) {
204
+ ret = true;
205
+ }
206
+ },
207
+ });
208
+ return ret;
209
+ }
210
+ exports.isModelValid = isModelValid;
211
+ function isModelObject(node) {
212
+ return (t.isObjectExpression(node) &&
213
+ node.properties.some((property) => {
214
+ return [
215
+ 'state',
216
+ 'reducers',
217
+ 'subscriptions',
218
+ 'effects',
219
+ 'namespace',
220
+ ].includes(property.key.name);
221
+ }));
222
+ }
package/dist/model.d.ts CHANGED
@@ -1,3 +1,12 @@
1
1
  import { IApi } from 'umi';
2
2
  declare const _default: (api: IApi) => void;
3
3
  export default _default;
4
+ export declare function getAllModels(api: IApi): string[][];
5
+ export declare function getModels(opts: {
6
+ base: string;
7
+ pattern?: string;
8
+ }): string[];
9
+ export declare function isModelValid(opts: {
10
+ content: string;
11
+ file: string;
12
+ }): boolean;
package/dist/model.js CHANGED
@@ -1,5 +1,119 @@
1
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;
20
+ };
21
+ var __importDefault = (this && this.__importDefault) || function (mod) {
22
+ return (mod && mod.__esModule) ? mod : { "default": mod };
23
+ };
2
24
  Object.defineProperty(exports, "__esModule", { value: true });
25
+ exports.isModelValid = exports.getModels = exports.getAllModels = void 0;
26
+ const parser = __importStar(require("@umijs/bundler-utils/compiled/babel/parser"));
27
+ const traverse_1 = __importDefault(require("@umijs/bundler-utils/compiled/babel/traverse"));
28
+ const t = __importStar(require("@umijs/bundler-utils/compiled/babel/types"));
29
+ const esbuild_1 = require("@umijs/bundler-utils/compiled/esbuild");
30
+ const fs_1 = require("fs");
31
+ const path_1 = require("path");
32
+ const plugin_utils_1 = require("umi/plugin-utils");
33
+ const getIdentifierDeclaration_1 = require("./utils/getIdentifierDeclaration");
3
34
  exports.default = (api) => {
4
- api;
35
+ api.describe({
36
+ config: {
37
+ schema(Joi) {
38
+ return Joi.object();
39
+ },
40
+ },
41
+ enableBy: api.EnableBy.config,
42
+ });
43
+ api.modifyAppData((memo) => {
44
+ const models = getAllModels(api);
45
+ memo.pluginModel = {
46
+ models,
47
+ };
48
+ return memo;
49
+ });
50
+ api.onGenerateFiles((args) => {
51
+ const models = args.isFirstTime
52
+ ? api.appData.pluginDva.models
53
+ : getAllModels(api);
54
+ models;
55
+ });
5
56
  };
57
+ function getAllModels(api) {
58
+ return [
59
+ getModels({
60
+ base: (0, path_1.join)(api.paths.absSrcPath, 'models'),
61
+ pattern: '**/*.{ts,tsx,js,jsx}',
62
+ }),
63
+ getModels({
64
+ base: (0, path_1.join)(api.paths.absPagesPath),
65
+ pattern: '**/models/**/*.{ts,tsx,js,jsx}',
66
+ }),
67
+ getModels({
68
+ base: (0, path_1.join)(api.paths.absPagesPath),
69
+ pattern: '**/model.{ts,tsx,js,jsx}',
70
+ }),
71
+ ];
72
+ }
73
+ exports.getAllModels = getAllModels;
74
+ function getModels(opts) {
75
+ return plugin_utils_1.glob
76
+ .sync(opts.pattern || '**/*.{ts,js}', {
77
+ cwd: opts.base,
78
+ absolute: true,
79
+ })
80
+ .map(plugin_utils_1.winPath)
81
+ .filter((file) => {
82
+ if (/\.d.ts$/.test(file))
83
+ return false;
84
+ if (/\.(test|e2e|spec).([jt])sx?$/.test(file))
85
+ return false;
86
+ const content = (0, fs_1.readFileSync)(file, 'utf-8');
87
+ return isModelValid({ content, file });
88
+ });
89
+ }
90
+ exports.getModels = getModels;
91
+ function isModelValid(opts) {
92
+ const { file, content } = opts;
93
+ // transform with esbuild first
94
+ // to reduce unexpected ast problem
95
+ const loader = (0, path_1.extname)(file).slice(1);
96
+ const result = (0, esbuild_1.transformSync)(content, {
97
+ loader,
98
+ sourcemap: false,
99
+ minify: false,
100
+ });
101
+ // transform with babel
102
+ let ret = false;
103
+ const ast = parser.parse(result.code, {
104
+ sourceType: 'module',
105
+ sourceFilename: file,
106
+ plugins: [],
107
+ });
108
+ (0, traverse_1.default)(ast, {
109
+ ExportDefaultDeclaration(path) {
110
+ let node = path.node.declaration;
111
+ node = (0, getIdentifierDeclaration_1.getIdentifierDeclaration)(node, path);
112
+ if (t.isArrowFunctionExpression(node) || t.isFunctionDeclaration(node)) {
113
+ ret = true;
114
+ }
115
+ },
116
+ });
117
+ return ret;
118
+ }
119
+ exports.isModelValid = isModelValid;
@@ -0,0 +1,3 @@
1
+ import * as Babel from '@umijs/bundler-utils/compiled/babel/core';
2
+ import * as t from '@umijs/bundler-utils/compiled/babel/types';
3
+ export declare function getIdentifierDeclaration(node: t.Node, path: Babel.NodePath): Babel.types.Node;
@@ -0,0 +1,34 @@
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;
20
+ };
21
+ Object.defineProperty(exports, "__esModule", { value: true });
22
+ exports.getIdentifierDeclaration = void 0;
23
+ const t = __importStar(require("@umijs/bundler-utils/compiled/babel/types"));
24
+ function getIdentifierDeclaration(node, path) {
25
+ if (t.isIdentifier(node) && path.scope.hasBinding(node.name)) {
26
+ let bindingNode = path.scope.getBinding(node.name).path.node;
27
+ if (t.isVariableDeclarator(bindingNode)) {
28
+ bindingNode = bindingNode.init;
29
+ }
30
+ return bindingNode;
31
+ }
32
+ return node;
33
+ }
34
+ exports.getIdentifierDeclaration = getIdentifierDeclaration;
@@ -0,0 +1,5 @@
1
+ export declare function resolveProjectDep(opts: {
2
+ pkg: any;
3
+ cwd: string;
4
+ dep: string;
5
+ }): string | undefined;
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.resolveProjectDep = void 0;
4
+ const path_1 = require("path");
5
+ const plugin_utils_1 = require("umi/plugin-utils");
6
+ function resolveProjectDep(opts) {
7
+ var _a, _b;
8
+ if (((_a = opts.pkg.dependencies) === null || _a === void 0 ? void 0 : _a[opts.dep]) ||
9
+ ((_b = opts.pkg.devDependencies) === null || _b === void 0 ? void 0 : _b[opts.dep])) {
10
+ return (0, path_1.dirname)(plugin_utils_1.resolve.sync(`${opts.dep}/package.json`, {
11
+ basedir: opts.cwd,
12
+ }));
13
+ }
14
+ }
15
+ exports.resolveProjectDep = resolveProjectDep;
@@ -0,0 +1,6 @@
1
+ import { IApi } from 'umi';
2
+ export declare function withTmpPath(opts: {
3
+ api: IApi;
4
+ path: string;
5
+ noPluginDir?: boolean;
6
+ }): string;
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.withTmpPath = void 0;
4
+ const utils_1 = require("@umijs/utils");
5
+ const path_1 = require("path");
6
+ function withTmpPath(opts) {
7
+ return (0, utils_1.winPath)((0, path_1.join)(opts.api.paths.absTmpPath, opts.api.plugin.key && !opts.noPluginDir
8
+ ? `plugin-${opts.api.plugin.key}`
9
+ : '', opts.path));
10
+ }
11
+ exports.withTmpPath = withTmpPath;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@umijs/plugins",
3
- "version": "4.0.0-beta.11",
3
+ "version": "4.0.0-beta.12",
4
4
  "description": "@umijs/plugins",
5
5
  "homepage": "https://github.com/umijs/umi-next/tree/master/packages/plugins#readme",
6
6
  "bugs": "https://github.com/umijs/umi-next/issues",
@@ -20,13 +20,15 @@
20
20
  "dev": "pnpm build -- --watch"
21
21
  },
22
22
  "dependencies": {
23
- "antd": "^4.16.13",
23
+ "@umijs/bundler-utils": "4.0.0-beta.12",
24
+ "antd": "^4.17.2",
24
25
  "antd-dayjs-webpack-plugin": "^1.0.6",
25
26
  "babel-plugin-import": "^1.13.3",
26
- "dayjs": "^1.10.7"
27
+ "dayjs": "^1.10.7",
28
+ "dva": "^2.6.0-beta.22"
27
29
  },
28
30
  "devDependencies": {
29
- "umi": "4.0.0-beta.11"
31
+ "umi": "4.0.0-beta.12"
30
32
  },
31
33
  "publishConfig": {
32
34
  "access": "public"