@umijs/plugins 4.0.0-rc.9 → 4.0.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.
- package/dist/access.js +26 -21
- package/dist/analytics.js +1 -1
- package/dist/antd.js +25 -8
- package/dist/dva.js +27 -4
- package/dist/initial-state.js +25 -17
- package/dist/layout.js +69 -21
- package/dist/locale.js +32 -34
- package/dist/model.js +16 -35
- package/dist/qiankun/master.js +31 -11
- package/dist/qiankun/slave.js +66 -44
- package/dist/qiankun.js +1 -0
- package/dist/request.js +141 -127
- package/dist/tailwindcss.js +24 -12
- package/dist/utils/localeUtils.js +5 -14
- package/dist/utils/modelUtils.d.ts +6 -1
- package/dist/utils/modelUtils.js +110 -8
- package/libs/model.tsx +43 -5
- package/libs/qiankun/master/MicroApp.tsx +15 -6
- package/libs/qiankun/master/common.ts +15 -10
- package/libs/qiankun/master/getMicroAppRouteComponent.tsx.tpl +5 -16
- package/libs/qiankun/master/masterRuntimePlugin.tsx +6 -5
- package/libs/qiankun/master/types.ts +2 -0
- package/libs/qiankun/slave/connectMaster.tsx +0 -1
- package/libs/qiankun/slave/lifecycles.ts +14 -8
- package/libs/qiankun/slave/qiankunModel.ts +0 -1
- package/libs/qiankun/slave/slaveRuntimePlugin.ts +9 -15
- package/package.json +14 -14
package/dist/model.js
CHANGED
|
@@ -22,15 +22,6 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
22
22
|
__setModuleDefault(result, mod);
|
|
23
23
|
return result;
|
|
24
24
|
};
|
|
25
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
26
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
27
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
28
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
29
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
30
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
31
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
32
|
-
});
|
|
33
|
-
};
|
|
34
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
35
26
|
const t = __importStar(require("@umijs/bundler-utils/compiled/babel/types"));
|
|
36
27
|
const fs_1 = require("fs");
|
|
@@ -49,17 +40,8 @@ exports.default = (api) => {
|
|
|
49
40
|
},
|
|
50
41
|
enableBy: api.EnableBy.config,
|
|
51
42
|
});
|
|
52
|
-
api.
|
|
53
|
-
const models =
|
|
54
|
-
memo.pluginModel = {
|
|
55
|
-
models,
|
|
56
|
-
};
|
|
57
|
-
return memo;
|
|
58
|
-
}));
|
|
59
|
-
api.onGenerateFiles((args) => __awaiter(void 0, void 0, void 0, function* () {
|
|
60
|
-
const models = args.isFirstTime
|
|
61
|
-
? api.appData.pluginModel.models
|
|
62
|
-
: yield getAllModels(api);
|
|
43
|
+
api.onGenerateFiles(async () => {
|
|
44
|
+
const models = await getAllModels(api);
|
|
63
45
|
// model.ts
|
|
64
46
|
api.writeTmpFile({
|
|
65
47
|
path: 'model.ts',
|
|
@@ -94,7 +76,7 @@ export function dataflowProvider(container, opts) {
|
|
|
94
76
|
}
|
|
95
77
|
`,
|
|
96
78
|
});
|
|
97
|
-
})
|
|
79
|
+
});
|
|
98
80
|
api.addTmpGenerateWatcherPaths(() => {
|
|
99
81
|
return [(0, path_1.join)(api.paths.absSrcPath, 'models')];
|
|
100
82
|
});
|
|
@@ -102,19 +84,18 @@ export function dataflowProvider(container, opts) {
|
|
|
102
84
|
return [(0, withTmpPath_1.withTmpPath)({ api, path: 'runtime.tsx' })];
|
|
103
85
|
});
|
|
104
86
|
};
|
|
105
|
-
function getAllModels(api) {
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
});
|
|
87
|
+
async function getAllModels(api) {
|
|
88
|
+
const extraModels = await api.applyPlugins({
|
|
89
|
+
key: 'addExtraModels',
|
|
90
|
+
type: api.ApplyPluginsType.add,
|
|
91
|
+
initialValue: [],
|
|
92
|
+
});
|
|
93
|
+
return new modelUtils_1.ModelUtils(api, {
|
|
94
|
+
astTest({ node }) {
|
|
95
|
+
return t.isArrowFunctionExpression(node) || t.isFunctionDeclaration(node);
|
|
96
|
+
},
|
|
97
|
+
}).getAllModels({
|
|
98
|
+
sort: {},
|
|
99
|
+
extraModels: [...extraModels, ...(api.config.model.extraModels || [])],
|
|
119
100
|
});
|
|
120
101
|
}
|
package/dist/qiankun/master.js
CHANGED
|
@@ -23,22 +23,30 @@ exports.default = (api) => {
|
|
|
23
23
|
api.addRuntimePlugin(() => {
|
|
24
24
|
return [(0, withTmpPath_1.withTmpPath)({ api, path: 'masterRuntimePlugin.tsx' })];
|
|
25
25
|
});
|
|
26
|
-
api.modifyDefaultConfig((config) => (
|
|
27
|
-
|
|
26
|
+
api.modifyDefaultConfig((config) => ({
|
|
27
|
+
...config,
|
|
28
|
+
mountElementId: constants_1.defaultMasterRootId,
|
|
29
|
+
qiankun: {
|
|
30
|
+
...config.qiankun,
|
|
31
|
+
master: {
|
|
32
|
+
...JSON.parse(process.env.INITIAL_QIANKUN_MASTER_OPTIONS || '{}'),
|
|
33
|
+
...(config.qiankun || {}).master,
|
|
34
|
+
},
|
|
35
|
+
},
|
|
36
|
+
}));
|
|
28
37
|
api.modifyRoutes((memo) => {
|
|
29
38
|
Object.keys(memo).forEach((id) => {
|
|
39
|
+
var _a;
|
|
30
40
|
const route = memo[id];
|
|
31
41
|
if (route.microApp) {
|
|
32
42
|
const appName = route.microApp;
|
|
33
|
-
|
|
34
|
-
const
|
|
35
|
-
// TODO: config masterHistoryType
|
|
36
|
-
const masterHistoryType = 'browser';
|
|
43
|
+
const base = api.config.base || '/';
|
|
44
|
+
const masterHistoryType = ((_a = api.config.history) === null || _a === void 0 ? void 0 : _a.type) || 'browser';
|
|
37
45
|
const routeProps = route.microAppProps || {};
|
|
38
46
|
const normalizedRouteProps = JSON.stringify(routeProps).replace(/"/g, "'");
|
|
39
47
|
route.file = `(async () => {
|
|
40
48
|
const { getMicroAppRouteComponent } = await import('@@/plugin-qiankun-master/getMicroAppRouteComponent');
|
|
41
|
-
return getMicroAppRouteComponent({ appName: '${appName}', base: '${base}', masterHistoryType: '${masterHistoryType}', routeProps: ${normalizedRouteProps} })
|
|
49
|
+
return getMicroAppRouteComponent({ appName: '${appName}', base: '${base}', routePath: '${route.path}', masterHistoryType: '${masterHistoryType}', routeProps: ${normalizedRouteProps} })
|
|
42
50
|
})()`;
|
|
43
51
|
}
|
|
44
52
|
});
|
|
@@ -65,7 +73,11 @@ exports.default = (api) => {
|
|
|
65
73
|
api.writeTmpFile({
|
|
66
74
|
path: 'masterOptions.ts',
|
|
67
75
|
content: `
|
|
68
|
-
let options = ${JSON.stringify(
|
|
76
|
+
let options = ${JSON.stringify({
|
|
77
|
+
masterHistoryType: ((_a = api.config.history) === null || _a === void 0 ? void 0 : _a.type) || constants_1.defaultHistoryType,
|
|
78
|
+
base: api.config.base || '/',
|
|
79
|
+
...api.config.qiankun.master,
|
|
80
|
+
})};
|
|
69
81
|
export const getMasterOptions = () => options;
|
|
70
82
|
export const setMasterOptions = (newOpts) => options = ({ ...options, ...newOpts });
|
|
71
83
|
`,
|
|
@@ -91,7 +103,6 @@ export const setMasterOptions = (newOpts) => options = ({ ...options, ...newOpts
|
|
|
91
103
|
path: file.replace(/\.tpl$/, ''),
|
|
92
104
|
tpl: getFileContent(file),
|
|
93
105
|
context: {
|
|
94
|
-
runtimeHistory: api.config.runtimeHistory,
|
|
95
106
|
dynamicRoot: false,
|
|
96
107
|
hasModelPlugin: api.isPluginEnable('model'),
|
|
97
108
|
// dynamicRoot:
|
|
@@ -100,16 +111,25 @@ export const setMasterOptions = (newOpts) => options = ({ ...options, ...newOpts
|
|
|
100
111
|
});
|
|
101
112
|
}
|
|
102
113
|
else {
|
|
114
|
+
let content = getFileContent(file);
|
|
115
|
+
if (!api.config.qiankun.externalQiankun) {
|
|
116
|
+
content = content.replace(/from 'qiankun'/g, `from '${(0, plugin_utils_1.winPath)((0, path_1.dirname)(require.resolve('qiankun/package')))}'`);
|
|
117
|
+
}
|
|
103
118
|
api.writeTmpFile({
|
|
104
119
|
path: file.replace(/\.tpl$/, ''),
|
|
105
|
-
content:
|
|
120
|
+
content: content
|
|
106
121
|
.replace('__USE_MODEL__', api.isPluginEnable('model')
|
|
107
122
|
? `import { useModel } from '@@/plugin-model'`
|
|
108
123
|
: `const useModel = null;`)
|
|
109
|
-
.replace(/from 'qiankun'/g, `from '${(0, plugin_utils_1.winPath)((0, path_1.dirname)(require.resolve('qiankun/package')))}'`)
|
|
110
124
|
.replace(/from 'lodash\//g, `from '${(0, plugin_utils_1.winPath)((0, path_1.dirname)(require.resolve('lodash/package')))}/`),
|
|
111
125
|
});
|
|
112
126
|
}
|
|
113
127
|
});
|
|
128
|
+
api.writeTmpFile({
|
|
129
|
+
path: 'index.ts',
|
|
130
|
+
content: `
|
|
131
|
+
export { MicroApp } from './MicroApp';
|
|
132
|
+
`,
|
|
133
|
+
});
|
|
114
134
|
});
|
|
115
135
|
};
|
package/dist/qiankun/slave.js
CHANGED
|
@@ -30,20 +30,32 @@ exports.default = (api) => {
|
|
|
30
30
|
key: 'addExtraModels',
|
|
31
31
|
fn() {
|
|
32
32
|
return [
|
|
33
|
-
|
|
33
|
+
(0, withTmpPath_1.withTmpPath)({
|
|
34
|
+
api,
|
|
35
|
+
path: `qiankunModel.ts#{"namespace":"${constants_1.qiankunStateFromMasterModelNamespace}"}`,
|
|
36
|
+
}),
|
|
34
37
|
];
|
|
35
38
|
},
|
|
36
39
|
});
|
|
37
40
|
api.modifyDefaultConfig((memo) => {
|
|
38
|
-
var _a, _b, _c;
|
|
39
|
-
const initialSlaveOptions =
|
|
40
|
-
|
|
41
|
+
var _a, _b, _c, _d;
|
|
42
|
+
const initialSlaveOptions = {
|
|
43
|
+
devSourceMap: true,
|
|
44
|
+
...JSON.parse(process.env.INITIAL_QIANKUN_SLAVE_OPTIONS || '{}'),
|
|
45
|
+
...(memo.qiankun || {}).slave,
|
|
46
|
+
};
|
|
47
|
+
const modifiedDefaultConfig = {
|
|
48
|
+
...memo,
|
|
41
49
|
// 默认开启 runtimePublicPath,避免出现 dynamic import 场景子应用资源地址出问题
|
|
42
|
-
runtimePublicPath: true,
|
|
43
|
-
|
|
44
|
-
|
|
50
|
+
runtimePublicPath: true,
|
|
51
|
+
qiankun: {
|
|
52
|
+
...memo.qiankun,
|
|
53
|
+
slave: initialSlaveOptions,
|
|
54
|
+
},
|
|
55
|
+
};
|
|
45
56
|
const shouldNotModifyDefaultBase = (_c = (_b = (_a = api.userConfig.qiankun) === null || _a === void 0 ? void 0 : _a.slave) === null || _b === void 0 ? void 0 : _b.shouldNotModifyDefaultBase) !== null && _c !== void 0 ? _c : initialSlaveOptions.shouldNotModifyDefaultBase;
|
|
46
|
-
|
|
57
|
+
const historyType = ((_d = api.userConfig.history) === null || _d === void 0 ? void 0 : _d.type) || 'browser';
|
|
58
|
+
if (!shouldNotModifyDefaultBase && historyType !== 'hash') {
|
|
47
59
|
// @ts-ignore
|
|
48
60
|
modifiedDefaultConfig.base = `/${api.pkg.name}`;
|
|
49
61
|
}
|
|
@@ -53,22 +65,23 @@ exports.default = (api) => {
|
|
|
53
65
|
var _a, _b;
|
|
54
66
|
// mfsu 场景默认给子应用增加 mfName 配置,从而避免冲突
|
|
55
67
|
if (config.mfsu !== false) {
|
|
56
|
-
config.mfsu =
|
|
57
|
-
|
|
68
|
+
config.mfsu = {
|
|
69
|
+
...config.mfsu,
|
|
70
|
+
mfName: ((_a = config.mfsu) === null || _a === void 0 ? void 0 : _a.mfName) ||
|
|
71
|
+
`mf_${(_b = api.pkg.name) === null || _b === void 0 ? void 0 : _b.replace(/^@/, '').replace(/\W/g, '_')}`,
|
|
72
|
+
};
|
|
58
73
|
}
|
|
59
74
|
return config;
|
|
60
75
|
});
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
// return publicPathStr;
|
|
71
|
-
// });
|
|
76
|
+
api.addHTMLHeadScripts(() => {
|
|
77
|
+
var _a, _b;
|
|
78
|
+
const dontModify = (_b = (_a = api.config.qiankun) === null || _a === void 0 ? void 0 : _a.slave) === null || _b === void 0 ? void 0 : _b.shouldNotModifyRuntimePublicPath;
|
|
79
|
+
return dontModify
|
|
80
|
+
? []
|
|
81
|
+
: [
|
|
82
|
+
`window.publicPath = window.__INJECTED_PUBLIC_PATH_BY_QIANKUN__ || "${api.config.publicPath || '/'}";`,
|
|
83
|
+
];
|
|
84
|
+
});
|
|
72
85
|
api.chainWebpack((config) => {
|
|
73
86
|
(0, assert_1.default)(api.pkg.name, 'You should have name in package.json.');
|
|
74
87
|
const { shouldNotAddLibraryChunkName } = (api.config.qiankun || {}).slave;
|
|
@@ -113,30 +126,39 @@ if (!window.__POWERED_BY_QIANKUN__) {
|
|
|
113
126
|
function getFileContent(file) {
|
|
114
127
|
return (0, fs_1.readFileSync)((0, path_1.join)(__dirname, '../../libs/qiankun/slave', file), 'utf-8');
|
|
115
128
|
}
|
|
116
|
-
api.onGenerateFiles(
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
129
|
+
api.onGenerateFiles({
|
|
130
|
+
fn() {
|
|
131
|
+
// api.writeTmpFile({
|
|
132
|
+
// path: 'slaveOptions.ts',
|
|
133
|
+
// content: `
|
|
134
|
+
// let options = ${JSON.stringify((api.config.qiankun || {}).slave || {})};
|
|
135
|
+
// export const getSlaveOptions = () => options;
|
|
136
|
+
// export const setSlaveOptions = (newOpts) => options = ({ ...options, ...newOpts });
|
|
137
|
+
// `,
|
|
138
|
+
// });
|
|
139
|
+
[
|
|
140
|
+
'qiankunModel.ts',
|
|
141
|
+
'connectMaster.tsx',
|
|
142
|
+
'slaveRuntimePlugin.ts',
|
|
143
|
+
'lifecycles.ts',
|
|
144
|
+
].forEach((file) => {
|
|
145
|
+
api.writeTmpFile({
|
|
146
|
+
path: file.replace(/\.tpl$/, ''),
|
|
147
|
+
content: getFileContent(file)
|
|
148
|
+
.replace('__USE_MODEL__', api.isPluginEnable('model')
|
|
149
|
+
? `import { useModel } from '@@/plugin-model'`
|
|
150
|
+
: `const useModel = null;`)
|
|
151
|
+
.replace(/from 'qiankun'/g, `from '${(0, plugin_utils_1.winPath)((0, path_1.dirname)(require.resolve('qiankun/package')))}'`)
|
|
152
|
+
.replace(/from 'lodash\//g, `from '${(0, plugin_utils_1.winPath)((0, path_1.dirname)(require.resolve('lodash/package')))}/`),
|
|
153
|
+
});
|
|
154
|
+
});
|
|
131
155
|
api.writeTmpFile({
|
|
132
|
-
path:
|
|
133
|
-
content:
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
: `const useModel = null;`)
|
|
137
|
-
.replace(/from 'qiankun'/g, `from '${(0, plugin_utils_1.winPath)((0, path_1.dirname)(require.resolve('qiankun/package')))}'`)
|
|
138
|
-
.replace(/from 'lodash\//g, `from '${(0, plugin_utils_1.winPath)((0, path_1.dirname)(require.resolve('lodash/package')))}/`),
|
|
156
|
+
path: 'index.ts',
|
|
157
|
+
content: `
|
|
158
|
+
export { connectMaster } from './connectMaster';
|
|
159
|
+
`,
|
|
139
160
|
});
|
|
140
|
-
}
|
|
161
|
+
},
|
|
162
|
+
before: 'model',
|
|
141
163
|
});
|
|
142
164
|
};
|