@umijs/plugins 4.0.0-beta.9 → 4.0.0-canary.202200505.1

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.
Files changed (58) hide show
  1. package/README.md +4 -1
  2. package/dist/access.js +135 -1
  3. package/dist/{sass.d.ts → analytics.d.ts} +0 -0
  4. package/dist/analytics.js +67 -0
  5. package/dist/antd.js +113 -145
  6. package/dist/dva.d.ts +3 -0
  7. package/dist/dva.js +194 -4
  8. package/dist/initial-state.js +112 -1
  9. package/dist/layout.js +534 -1
  10. package/dist/locale.d.ts +1 -0
  11. package/dist/locale.js +195 -1
  12. package/dist/model.js +114 -1
  13. package/dist/moment2dayjs.d.ts +3 -0
  14. package/dist/moment2dayjs.js +96 -0
  15. package/dist/qiankun/constants.d.ts +5 -0
  16. package/dist/qiankun/constants.js +8 -0
  17. package/dist/qiankun/master.d.ts +6 -0
  18. package/dist/qiankun/master.js +134 -0
  19. package/dist/qiankun/slave.d.ts +3 -0
  20. package/dist/qiankun/slave.js +158 -0
  21. package/dist/qiankun.js +15 -1
  22. package/dist/request.js +307 -1
  23. package/dist/tailwindcss.d.ts +3 -0
  24. package/dist/tailwindcss.js +40 -0
  25. package/dist/unocss.d.ts +3 -0
  26. package/dist/unocss.js +39 -0
  27. package/dist/utils/astUtils.d.ts +3 -0
  28. package/dist/utils/astUtils.js +38 -0
  29. package/dist/utils/localeUtils.d.ts +33 -0
  30. package/dist/utils/localeUtils.js +126 -0
  31. package/dist/utils/modelUtils.d.ts +36 -0
  32. package/dist/utils/modelUtils.js +150 -0
  33. package/dist/utils/resolveProjectDep.d.ts +5 -0
  34. package/dist/utils/resolveProjectDep.js +15 -0
  35. package/dist/utils/withTmpPath.d.ts +6 -0
  36. package/dist/utils/withTmpPath.js +11 -0
  37. package/libs/dva.ts +10 -0
  38. package/libs/locale/SelectLang.tpl +478 -0
  39. package/libs/locale/locale.tpl +82 -0
  40. package/libs/locale/localeExports.tpl +271 -0
  41. package/libs/locale/runtime.tpl +33 -0
  42. package/libs/model.tsx +140 -0
  43. package/libs/qiankun/master/AntdErrorBoundary.tsx +34 -0
  44. package/libs/qiankun/master/AntdLoader.tsx +15 -0
  45. package/libs/qiankun/master/ErrorBoundary.tsx +7 -0
  46. package/libs/qiankun/master/MicroApp.tsx +269 -0
  47. package/libs/qiankun/master/MicroAppWithMemoHistory.tsx +43 -0
  48. package/libs/qiankun/master/common.ts +133 -0
  49. package/libs/qiankun/master/constants.ts +7 -0
  50. package/libs/qiankun/master/getMicroAppRouteComponent.tsx.tpl +36 -0
  51. package/libs/qiankun/master/masterRuntimePlugin.tsx +130 -0
  52. package/libs/qiankun/master/types.ts +44 -0
  53. package/libs/qiankun/slave/connectMaster.tsx +14 -0
  54. package/libs/qiankun/slave/lifecycles.ts +147 -0
  55. package/libs/qiankun/slave/qiankunModel.ts +18 -0
  56. package/libs/qiankun/slave/slaveRuntimePlugin.ts +15 -0
  57. package/package.json +25 -7
  58. package/dist/sass.js +0 -5
package/dist/dva.js CHANGED
@@ -1,9 +1,199 @@
1
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
+ };
2
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.getAllModels = exports.getModelUtil = void 0;
27
+ const t = __importStar(require("@umijs/bundler-utils/compiled/babel/types"));
28
+ const utils_1 = require("@umijs/utils");
29
+ const path_1 = require("path");
30
+ const plugin_utils_1 = require("umi/plugin-utils");
31
+ const modelUtils_1 = require("./utils/modelUtils");
32
+ const withTmpPath_1 = require("./utils/withTmpPath");
3
33
  exports.default = (api) => {
4
- api;
5
- // import from dva
6
- // model register
7
- // container
34
+ const pkgPath = (0, path_1.join)(__dirname, '../libs/dva.ts');
35
+ api.describe({
36
+ config: {
37
+ schema(Joi) {
38
+ return Joi.object({
39
+ extraModels: Joi.array().items(Joi.string()),
40
+ immer: Joi.object(),
41
+ });
42
+ },
43
+ },
44
+ enableBy: api.EnableBy.config,
45
+ });
46
+ api.modifyAppData((memo) => {
47
+ const models = getAllModels(api);
48
+ memo.pluginDva = {
49
+ pkgPath,
50
+ models,
51
+ };
52
+ return memo;
53
+ });
54
+ api.modifyConfig((memo) => {
55
+ // import from dva
56
+ memo.alias['dva$'] = pkgPath;
57
+ return memo;
58
+ });
59
+ api.onGenerateFiles((args) => {
60
+ var _a, _b, _c, _d, _e, _f;
61
+ const models = args.isFirstTime
62
+ ? api.appData.pluginDva.models
63
+ : getAllModels(api);
64
+ // models.ts
65
+ api.writeTmpFile({
66
+ path: 'models.ts',
67
+ content: modelUtils_1.ModelUtils.getModelsContent(models),
68
+ });
69
+ // dva.tsx
70
+ api.writeTmpFile({
71
+ path: 'dva.tsx',
72
+ tpl: `
73
+ // It's faked dva
74
+ // aliased to @umijs/plugins/templates/dva
75
+ import { create, Provider } from 'dva';
76
+ import createLoading from '${(0, utils_1.winPath)(require.resolve('dva-loading'))}';
77
+ ${((_a = api.config.dva) === null || _a === void 0 ? void 0 : _a.immer)
78
+ ? `
79
+ import dvaImmer, { enableES5, enableAllPlugins } from '${(0, utils_1.winPath)(require.resolve('dva-immer'))}';
80
+ `
81
+ : ''}
82
+ import React, { useRef } from 'react';
83
+ import { history, ApplyPluginsType, useAppData } from 'umi';
84
+ import { models } from './models';
85
+
86
+ export function RootContainer(props: any) {
87
+ const { pluginManager } = useAppData();
88
+ const app = useRef<any>();
89
+ const runtimeDva = pluginManager.applyPlugins({
90
+ key: 'dva',
91
+ type: ApplyPluginsType.modify,
92
+ initialValue: {},
93
+ });
94
+ if (!app.current) {
95
+ app.current = create(
96
+ {
97
+ history,
98
+ ...(runtimeDva.config || {}),
99
+ },
100
+ {
101
+ initialReducer: {},
102
+ setupMiddlewares(middlewares: Function[]) {
103
+ return [...middlewares];
104
+ },
105
+ setupApp(app: IDvaApp) {
106
+ app._history = history;
107
+ },
108
+ },
109
+ );
110
+ app.current.use(createLoading());
111
+ ${((_b = api.config.dva) === null || _b === void 0 ? void 0 : _b.immer) ? `app.current.use(dvaImmer());` : ''}
112
+ ${((_d = (_c = api.config.dva) === null || _c === void 0 ? void 0 : _c.immer) === null || _d === void 0 ? void 0 : _d.enableES5) ? `enableES5();` : ''}
113
+ ${((_f = (_e = api.config.dva) === null || _e === void 0 ? void 0 : _e.immer) === null || _f === void 0 ? void 0 : _f.enableAllPlugins) ? `enableAllPlugins();` : ''}
114
+ for (const id of Object.keys(models)) {
115
+ app.current.model(models[id].model);
116
+ }
117
+ app.current.start();
118
+ }
119
+ return <Provider store={app.current!._store}>{props.children}</Provider>;
120
+ }
121
+ `,
122
+ context: {},
123
+ });
124
+ // runtime.tsx
125
+ api.writeTmpFile({
126
+ path: 'runtime.tsx',
127
+ content: `
128
+ import React from 'react';
129
+ import { RootContainer } from './dva';
130
+
131
+ export function dataflowProvider(container, opts) {
132
+ return React.createElement(RootContainer, opts, container);
133
+ }
134
+ `,
135
+ });
136
+ // index.ts for export
137
+ api.writeTmpFile({
138
+ path: 'index.ts',
139
+ content: `
140
+ export { connect, useDispatch, useStore, useSelector } from 'dva';`,
141
+ });
142
+ });
143
+ api.addTmpGenerateWatcherPaths(() => {
144
+ return [(0, path_1.join)(api.paths.absSrcPath, 'models')];
145
+ });
146
+ api.addRuntimePlugin(() => {
147
+ return [(0, withTmpPath_1.withTmpPath)({ api, path: 'runtime.tsx' })];
148
+ });
149
+ api.addRuntimePluginKey(() => ['dva']);
8
150
  // dva list model
151
+ api.registerCommand({
152
+ name: 'dva',
153
+ fn() {
154
+ api.logger.info(plugin_utils_1.chalk.green.bold('dva models'));
155
+ api.appData.pluginDva.models.forEach((model) => {
156
+ api.logger.info(` - ${(0, path_1.relative)(api.cwd, model.file)}`);
157
+ });
158
+ },
159
+ });
9
160
  };
161
+ function getModelUtil(api) {
162
+ return new modelUtils_1.ModelUtils(api, {
163
+ contentTest(content) {
164
+ return content.startsWith('// @dva-model');
165
+ },
166
+ astTest({ node, content }) {
167
+ if (isModelObject(node)) {
168
+ return true;
169
+ }
170
+ else if (content.includes('dva-model-extend') &&
171
+ t.isCallExpression(node) &&
172
+ node.arguments.length === 2 &&
173
+ isModelObject(node.arguments[1])) {
174
+ return true;
175
+ }
176
+ return false;
177
+ },
178
+ });
179
+ }
180
+ exports.getModelUtil = getModelUtil;
181
+ function getAllModels(api) {
182
+ return getModelUtil(api).getAllModels({
183
+ extraModelsPre: [],
184
+ extraModels: [...(api.config.dva.extraModels || [])],
185
+ });
186
+ }
187
+ exports.getAllModels = getAllModels;
188
+ function isModelObject(node) {
189
+ return (t.isObjectExpression(node) &&
190
+ node.properties.some((property) => {
191
+ return [
192
+ 'state',
193
+ 'reducers',
194
+ 'subscriptions',
195
+ 'effects',
196
+ 'namespace',
197
+ ].includes(property.key.name);
198
+ }));
199
+ }
@@ -1,5 +1,116 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ const withTmpPath_1 = require("./utils/withTmpPath");
3
4
  exports.default = (api) => {
4
- api;
5
+ api.describe({
6
+ config: {
7
+ schema(Joi) {
8
+ return Joi.object({
9
+ loading: Joi.string(),
10
+ });
11
+ },
12
+ },
13
+ enableBy: api.EnableBy.config,
14
+ });
15
+ api.register({
16
+ key: 'addExtraModelsPre',
17
+ fn: () => [(0, withTmpPath_1.withTmpPath)({ api, path: '@@initialState.ts' })],
18
+ });
19
+ api.addRuntimePluginKey(() => ['getInitialState']);
20
+ api.addRuntimePlugin(() => {
21
+ return [(0, withTmpPath_1.withTmpPath)({ api, path: 'runtime.tsx' })];
22
+ });
23
+ api.onGenerateFiles(() => {
24
+ var _a;
25
+ const { loading } = api.config.initialState;
26
+ // Provider.tsx
27
+ api.writeTmpFile({
28
+ path: 'Provider.tsx',
29
+ content: `
30
+ import React from 'react';
31
+ import { useModel } from '@@/plugin-model';
32
+ ${loading
33
+ ? `import Loading from '${loading}'`
34
+ : `function Loading() { return <div />; }`}
35
+ export default function InitialStateProvider(props: any) {
36
+ const appLoaded = React.useRef(false);
37
+ const { loading = false } = useModel("@@initialState") || {};
38
+ React.useEffect(() => {
39
+ if (!loading) {
40
+ appLoaded.current = true;
41
+ }
42
+ }, [loading]);
43
+ if (loading && !appLoaded.current) {
44
+ return <Loading />;
45
+ }
46
+ return props.children;
47
+ }
48
+ `,
49
+ });
50
+ // @@initialState.ts
51
+ api.writeTmpFile({
52
+ path: '@@initialState.ts',
53
+ content: ((_a = api.appData.appJS) === null || _a === void 0 ? void 0 : _a.exports.includes('getInitialState'))
54
+ ? `
55
+ import { useState, useEffect, useCallback } from 'react';
56
+ import { getInitialState } from '@/app';
57
+
58
+ const initState = {
59
+ initialState: undefined,
60
+ loading: true,
61
+ error: undefined,
62
+ };
63
+
64
+ export default () => {
65
+ const [state, setState] = useState(initState);
66
+ const refresh = useCallback(async () => {
67
+ setState((s) => ({ ...s, loading: true, error: undefined }));
68
+ try {
69
+ const ret = await getInitialState();
70
+ setState((s) => ({ ...s, initialState: ret, loading: false }));
71
+ } catch (e) {
72
+ setState((s) => ({ ...s, error: e, loading: false }));
73
+ }
74
+ // [?]
75
+ // await sleep(10);
76
+ }, []);
77
+
78
+ const setInitialState = useCallback(async (initialState) => {
79
+ setState((s) => {
80
+ if (typeof initialState === 'function') {
81
+ return { ...s, initialState: initialState(s.initialState), loading: false };
82
+ }
83
+ return { ...s, initialState, loading: false };
84
+ });
85
+ // [?]
86
+ // await sleep(10)
87
+ }, []);
88
+
89
+ useEffect(() => {
90
+ refresh();
91
+ }, []);
92
+
93
+ return {
94
+ ...state,
95
+ refresh,
96
+ setInitialState,
97
+ };
98
+ }
99
+ `
100
+ : `
101
+ export default () => ({ loading: false, refresh: () => {} })
102
+ `,
103
+ });
104
+ // runtime.tsx
105
+ api.writeTmpFile({
106
+ path: 'runtime.tsx',
107
+ content: `
108
+ import React from 'react';
109
+ import Provider from './Provider';
110
+ export function dataflowProvider(container) {
111
+ return <Provider>{ container }</Provider>;
112
+ }
113
+ `,
114
+ });
115
+ });
5
116
  };