@umijs/plugins 4.0.0-beta.8 → 4.0.0-canary-20240513.3
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/LICENSE +21 -0
- package/README.md +4 -1
- package/dist/access.d.ts +1 -1
- package/dist/access.js +194 -4
- package/dist/{sass.d.ts → analytics.d.ts} +1 -1
- package/dist/analytics.js +118 -0
- package/dist/antd.d.ts +1 -1
- package/dist/antd.js +345 -157
- package/dist/{icons.d.ts → confetti.d.ts} +1 -1
- package/dist/confetti.js +64 -0
- package/dist/constants.d.ts +1 -0
- package/dist/constants.js +30 -0
- package/dist/dva.d.ts +4 -1
- package/dist/dva.js +302 -8
- package/dist/initial-state.d.ts +1 -1
- package/dist/initial-state.js +147 -4
- package/dist/layout.d.ts +1 -1
- package/dist/layout.js +754 -4
- package/dist/locale.d.ts +2 -1
- package/dist/locale.js +257 -4
- package/dist/mf.d.ts +2 -0
- package/dist/mf.js +358 -0
- package/dist/model.d.ts +1 -1
- package/dist/model.js +109 -4
- package/dist/moment2dayjs.d.ts +3 -0
- package/dist/moment2dayjs.js +125 -0
- package/dist/qiankun/constants.d.ts +5 -0
- package/dist/qiankun/constants.js +41 -0
- package/dist/qiankun/master.d.ts +6 -0
- package/dist/qiankun/master.js +236 -0
- package/dist/qiankun/slave.d.ts +3 -0
- package/dist/qiankun/slave.js +345 -0
- package/dist/qiankun.d.ts +1 -1
- package/dist/qiankun.js +51 -4
- package/dist/react-query.d.ts +3 -0
- package/dist/react-query.js +193 -0
- package/dist/request.d.ts +1 -1
- package/dist/request.js +384 -4
- package/dist/styled-components.d.ts +3 -0
- package/dist/styled-components.js +150 -0
- package/dist/tailwindcss.d.ts +3 -0
- package/dist/tailwindcss.js +106 -0
- package/dist/unocss.d.ts +3 -0
- package/dist/unocss.js +71 -0
- package/dist/utils/astUtils.d.ts +3 -0
- package/dist/utils/astUtils.js +49 -0
- package/dist/utils/localeUtils.d.ts +33 -0
- package/dist/utils/localeUtils.js +139 -0
- package/dist/utils/mfUtils.d.ts +14 -0
- package/dist/utils/mfUtils.js +56 -0
- package/dist/utils/modelUtils.d.ts +40 -0
- package/dist/utils/modelUtils.js +286 -0
- package/dist/utils/resolveProjectDep.d.ts +5 -0
- package/dist/utils/resolveProjectDep.js +40 -0
- package/dist/utils/withTmpPath.d.ts +6 -0
- package/dist/utils/withTmpPath.js +39 -0
- package/dist/valtio.d.ts +3 -0
- package/dist/valtio.js +81 -0
- package/libs/dva.tsx +45 -0
- package/libs/model.tsx +180 -0
- package/libs/qiankun/master/AntdErrorBoundary.tsx +34 -0
- package/libs/qiankun/master/AntdLoader.tsx +15 -0
- package/libs/qiankun/master/ErrorBoundary.tsx +7 -0
- package/libs/qiankun/master/MicroApp.tsx +327 -0
- package/libs/qiankun/master/MicroAppWithMemoHistory.tsx +43 -0
- package/libs/qiankun/master/common.ts +172 -0
- package/libs/qiankun/master/constants.ts +19 -0
- package/libs/qiankun/master/getMicroAppRouteComponent.tsx.tpl +45 -0
- package/libs/qiankun/master/masterRuntimePlugin.tsx +161 -0
- package/libs/qiankun/master/routeUtils.ts +26 -0
- package/libs/qiankun/master/types.ts +54 -0
- package/libs/qiankun/slave/MicroAppLink.tsx +122 -0
- package/libs/qiankun/slave/connectMaster.tsx +14 -0
- package/libs/qiankun/slave/constants.ts +5 -0
- package/libs/qiankun/slave/lifecycles.ts +164 -0
- package/libs/qiankun/slave/qiankunModel.ts +18 -0
- package/libs/qiankun/slave/slaveRuntimePlugin.ts +36 -0
- package/package.json +54 -24
- package/templates/antd/runtime.ts.tpl +170 -0
- package/templates/antd/types.d.ts.tpl +17 -0
- package/templates/locale/SelectLang.tpl +502 -0
- package/templates/locale/locale.tpl +82 -0
- package/templates/locale/localeExports.tpl +307 -0
- package/templates/locale/runtime.tpl +34 -0
- package/templates/mf/runtime.ts.tpl +149 -0
- package/dist/access.d.ts.map +0 -1
- package/dist/antd.d.ts.map +0 -1
- package/dist/dva.d.ts.map +0 -1
- package/dist/icons.d.ts.map +0 -1
- package/dist/icons.js +0 -5
- package/dist/initial-state.d.ts.map +0 -1
- package/dist/layout.d.ts.map +0 -1
- package/dist/locale.d.ts.map +0 -1
- package/dist/model.d.ts.map +0 -1
- package/dist/qiankun.d.ts.map +0 -1
- package/dist/request.d.ts.map +0 -1
- package/dist/sass.d.ts.map +0 -1
- package/dist/sass.js +0 -5
package/dist/unocss.js
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
|
|
19
|
+
// src/unocss.ts
|
|
20
|
+
var unocss_exports = {};
|
|
21
|
+
__export(unocss_exports, {
|
|
22
|
+
default: () => unocss_default
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(unocss_exports);
|
|
25
|
+
var import_utils = require("@umijs/utils");
|
|
26
|
+
var import_fs = require("fs");
|
|
27
|
+
var import_path = require("path");
|
|
28
|
+
var import_plugin_utils = require("umi/plugin-utils");
|
|
29
|
+
var unocss_default = (api) => {
|
|
30
|
+
api.describe({
|
|
31
|
+
key: "unocss",
|
|
32
|
+
config: {
|
|
33
|
+
schema({ zod }) {
|
|
34
|
+
return zod.object({
|
|
35
|
+
watch: zod.array(zod.any())
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
},
|
|
39
|
+
enableBy: api.EnableBy.config
|
|
40
|
+
});
|
|
41
|
+
const outputPath = "uno.css";
|
|
42
|
+
api.onBeforeCompiler(async () => {
|
|
43
|
+
if (process.env.IS_UMI_BUILD_WORKER)
|
|
44
|
+
return;
|
|
45
|
+
if (!(0, import_fs.existsSync)((0, import_path.join)(api.paths.cwd, "unocss.config.ts")))
|
|
46
|
+
api.logger.warn(
|
|
47
|
+
"请在项目目录中添加 unocss.config.ts 文件,并配置需要的 unocss presets,否则插件将没有效果!"
|
|
48
|
+
);
|
|
49
|
+
const generatedPath = (0, import_path.join)(api.paths.absTmpPath, outputPath);
|
|
50
|
+
const binPath = (0, import_path.join)(api.cwd, "node_modules/.bin/unocss");
|
|
51
|
+
const watchDirs = api.config.unocss.watch || [];
|
|
52
|
+
const isDev = api.env === "development";
|
|
53
|
+
const args = [
|
|
54
|
+
...watchDirs,
|
|
55
|
+
"--out-file",
|
|
56
|
+
generatedPath,
|
|
57
|
+
isDev ? "--watch" : ""
|
|
58
|
+
].filter(Boolean);
|
|
59
|
+
const execaRes = import_utils.execa.execa(binPath, args, {
|
|
60
|
+
cwd: api.cwd,
|
|
61
|
+
stdio: isDev ? "pipe" : "inherit"
|
|
62
|
+
});
|
|
63
|
+
if (!isDev) {
|
|
64
|
+
await execaRes;
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
api.addEntryImports(() => {
|
|
68
|
+
const generatedPath = (0, import_plugin_utils.winPath)((0, import_path.join)(api.paths.absTmpPath, outputPath));
|
|
69
|
+
return [{ source: generatedPath }];
|
|
70
|
+
});
|
|
71
|
+
};
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
24
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
25
|
+
mod
|
|
26
|
+
));
|
|
27
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
|
+
|
|
29
|
+
// src/utils/astUtils.ts
|
|
30
|
+
var astUtils_exports = {};
|
|
31
|
+
__export(astUtils_exports, {
|
|
32
|
+
getIdentifierDeclaration: () => getIdentifierDeclaration
|
|
33
|
+
});
|
|
34
|
+
module.exports = __toCommonJS(astUtils_exports);
|
|
35
|
+
var t = __toESM(require("@umijs/bundler-utils/compiled/babel/types"));
|
|
36
|
+
function getIdentifierDeclaration(node, path) {
|
|
37
|
+
if (t.isIdentifier(node) && path.scope.hasBinding(node.name)) {
|
|
38
|
+
let bindingNode = path.scope.getBinding(node.name).path.node;
|
|
39
|
+
if (t.isVariableDeclarator(bindingNode)) {
|
|
40
|
+
bindingNode = bindingNode.init;
|
|
41
|
+
}
|
|
42
|
+
return bindingNode;
|
|
43
|
+
}
|
|
44
|
+
return node;
|
|
45
|
+
}
|
|
46
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
47
|
+
0 && (module.exports = {
|
|
48
|
+
getIdentifierDeclaration
|
|
49
|
+
});
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
export declare type IAddAntdLocales = (args: {
|
|
2
|
+
lang: string;
|
|
3
|
+
country: string;
|
|
4
|
+
}) => Promise<string[]>;
|
|
5
|
+
export interface IGetLocaleFileListOpts {
|
|
6
|
+
localeFolder: string;
|
|
7
|
+
separator?: string;
|
|
8
|
+
absSrcPath?: string;
|
|
9
|
+
absPagesPath?: string;
|
|
10
|
+
addAntdLocales: IAddAntdLocales;
|
|
11
|
+
resolveKey: string;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* 获取 moment 包的 locale 名称
|
|
15
|
+
* @param lang 语言
|
|
16
|
+
* @param country 国家
|
|
17
|
+
* @param resolveKey 用来resolve的key,moment 或者 dayjs,为了使 dayjs 可以替换 moment
|
|
18
|
+
*/
|
|
19
|
+
export declare const getMomentLocale: (lang: string, country: string, resolveKey: string) => {
|
|
20
|
+
momentLocale: string;
|
|
21
|
+
};
|
|
22
|
+
export declare const getAntdLocale: (lang: string, country: string) => string;
|
|
23
|
+
export interface IGetLocaleFileListResult {
|
|
24
|
+
lang: string;
|
|
25
|
+
country: string;
|
|
26
|
+
name: string;
|
|
27
|
+
paths: string[];
|
|
28
|
+
antdLocale: string[];
|
|
29
|
+
momentLocale: string;
|
|
30
|
+
}
|
|
31
|
+
export declare const getLocaleList: (opts: IGetLocaleFileListOpts) => Promise<IGetLocaleFileListResult[]>;
|
|
32
|
+
export declare const exactLocalePaths: (data: IGetLocaleFileListResult[]) => string[];
|
|
33
|
+
export declare function isNeedPolyfill(targets?: {}): boolean;
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
|
|
19
|
+
// src/utils/localeUtils.ts
|
|
20
|
+
var localeUtils_exports = {};
|
|
21
|
+
__export(localeUtils_exports, {
|
|
22
|
+
exactLocalePaths: () => exactLocalePaths,
|
|
23
|
+
getAntdLocale: () => getAntdLocale,
|
|
24
|
+
getLocaleList: () => getLocaleList,
|
|
25
|
+
getMomentLocale: () => getMomentLocale,
|
|
26
|
+
isNeedPolyfill: () => isNeedPolyfill
|
|
27
|
+
});
|
|
28
|
+
module.exports = __toCommonJS(localeUtils_exports);
|
|
29
|
+
var import_fs = require("fs");
|
|
30
|
+
var import_path = require("path");
|
|
31
|
+
var import_plugin_utils = require("umi/plugin-utils");
|
|
32
|
+
var getMomentLocale = (lang, country, resolveKey) => {
|
|
33
|
+
var _a, _b;
|
|
34
|
+
const momentLocation = require.resolve(`${resolveKey}/locale/zh-cn`).replace(/zh\-cn\.js$/, "");
|
|
35
|
+
if ((0, import_fs.existsSync)(
|
|
36
|
+
(0, import_path.join)(momentLocation, `${lang}-${(_a = country == null ? void 0 : country.toLocaleLowerCase) == null ? void 0 : _a.call(country)}.js`)
|
|
37
|
+
)) {
|
|
38
|
+
const momentLocale = `${lang}-${(_b = country == null ? void 0 : country.toLocaleLowerCase) == null ? void 0 : _b.call(country)}`;
|
|
39
|
+
return {
|
|
40
|
+
momentLocale
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
if ((0, import_fs.existsSync)((0, import_path.join)(momentLocation, `${lang}.js`))) {
|
|
44
|
+
return {
|
|
45
|
+
momentLocale: lang
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
return { momentLocale: "" };
|
|
49
|
+
};
|
|
50
|
+
var getAntdLocale = (lang, country) => `${lang}_${(country || lang).toLocaleUpperCase()}`;
|
|
51
|
+
var modulesHasLocale = (localePath) => {
|
|
52
|
+
try {
|
|
53
|
+
require.resolve(localePath);
|
|
54
|
+
return true;
|
|
55
|
+
} catch (error) {
|
|
56
|
+
return false;
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
var getLocaleList = async (opts) => {
|
|
60
|
+
const {
|
|
61
|
+
localeFolder,
|
|
62
|
+
separator = "-",
|
|
63
|
+
absSrcPath = "",
|
|
64
|
+
absPagesPath = "",
|
|
65
|
+
addAntdLocales,
|
|
66
|
+
resolveKey = "moment"
|
|
67
|
+
} = opts;
|
|
68
|
+
const localeFileMath = new RegExp(
|
|
69
|
+
`^([a-z]{2})${separator}?([A-Z]{2})?.(js|json|ts)$`
|
|
70
|
+
);
|
|
71
|
+
const localeFiles = import_plugin_utils.glob.sync("*.{ts,js,json}", {
|
|
72
|
+
cwd: (0, import_plugin_utils.winPath)((0, import_path.join)(absSrcPath, localeFolder))
|
|
73
|
+
}).map((name) => (0, import_plugin_utils.winPath)((0, import_path.join)(absSrcPath, localeFolder, name))).concat(
|
|
74
|
+
import_plugin_utils.glob.sync(`**/${localeFolder}/*.{ts,js,json}`, {
|
|
75
|
+
cwd: absPagesPath
|
|
76
|
+
}).map((name) => (0, import_plugin_utils.winPath)((0, import_path.join)(absPagesPath, name)))
|
|
77
|
+
).filter((p) => localeFileMath.test((0, import_path.basename)(p)) && (0, import_fs.existsSync)(p)).map((fullName) => {
|
|
78
|
+
var _a, _b;
|
|
79
|
+
const fileName = (0, import_path.basename)(fullName);
|
|
80
|
+
const fileInfo = (_b = (_a = localeFileMath.exec(fileName)) == null ? void 0 : _a.slice(1, 3)) == null ? void 0 : _b.filter(Boolean);
|
|
81
|
+
return {
|
|
82
|
+
name: (fileInfo || []).join(separator),
|
|
83
|
+
path: fullName
|
|
84
|
+
};
|
|
85
|
+
});
|
|
86
|
+
const groups = import_plugin_utils.lodash.groupBy(localeFiles, "name");
|
|
87
|
+
const promises = Object.keys(groups).map(async (name) => {
|
|
88
|
+
const [lang, country = ""] = name.split(separator);
|
|
89
|
+
const { momentLocale } = getMomentLocale(lang, country, resolveKey);
|
|
90
|
+
const antdLocale = import_plugin_utils.lodash.uniq(await addAntdLocales({ lang, country })).filter((localePath) => modulesHasLocale(localePath));
|
|
91
|
+
return {
|
|
92
|
+
lang,
|
|
93
|
+
name,
|
|
94
|
+
// react-intl Function.supportedLocalesOf
|
|
95
|
+
// Uncaught RangeError: Incorrect locale information provided
|
|
96
|
+
locale: name.split(separator).join("-"),
|
|
97
|
+
country,
|
|
98
|
+
antdLocale,
|
|
99
|
+
paths: groups[name].map((item) => (0, import_plugin_utils.winPath)(item.path)),
|
|
100
|
+
momentLocale
|
|
101
|
+
};
|
|
102
|
+
});
|
|
103
|
+
return Promise.all(promises);
|
|
104
|
+
};
|
|
105
|
+
var exactLocalePaths = (data) => {
|
|
106
|
+
return import_plugin_utils.lodash.flatten(data.map((item) => item.paths));
|
|
107
|
+
};
|
|
108
|
+
function isNeedPolyfill(targets = {}) {
|
|
109
|
+
const polyfillTargets = {
|
|
110
|
+
ie: 10,
|
|
111
|
+
firefox: 28,
|
|
112
|
+
chrome: 23,
|
|
113
|
+
safari: 9.1,
|
|
114
|
+
opera: 12.1,
|
|
115
|
+
ios: 9.3,
|
|
116
|
+
ios_saf: 9.3,
|
|
117
|
+
operamini: Infinity,
|
|
118
|
+
op_mini: Infinity,
|
|
119
|
+
android: 4.3,
|
|
120
|
+
blackberry: Infinity,
|
|
121
|
+
operamobile: 12.1,
|
|
122
|
+
op_mob: 12.1,
|
|
123
|
+
explorermobil: 10,
|
|
124
|
+
ie_mob: 10,
|
|
125
|
+
ucandroid: Infinity
|
|
126
|
+
};
|
|
127
|
+
return Object.keys(targets).find((key) => {
|
|
128
|
+
const lowKey = key.toLocaleLowerCase();
|
|
129
|
+
return polyfillTargets[lowKey] && polyfillTargets[lowKey] >= targets[key];
|
|
130
|
+
}) !== void 0;
|
|
131
|
+
}
|
|
132
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
133
|
+
0 && (module.exports = {
|
|
134
|
+
exactLocalePaths,
|
|
135
|
+
getAntdLocale,
|
|
136
|
+
getLocaleList,
|
|
137
|
+
getMomentLocale,
|
|
138
|
+
isNeedPolyfill
|
|
139
|
+
});
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
declare type SimpleRemote = {
|
|
2
|
+
entry: string;
|
|
3
|
+
name: string;
|
|
4
|
+
aliasName?: string;
|
|
5
|
+
};
|
|
6
|
+
declare type RemoteEntries = {
|
|
7
|
+
name: string;
|
|
8
|
+
entries: object;
|
|
9
|
+
keyResolver: string;
|
|
10
|
+
aliasName?: string;
|
|
11
|
+
};
|
|
12
|
+
declare type Remote = SimpleRemote | RemoteEntries;
|
|
13
|
+
export declare function toRemotesCodeString(remotes: Remote[]): string;
|
|
14
|
+
export {};
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
|
|
19
|
+
// src/utils/mfUtils.ts
|
|
20
|
+
var mfUtils_exports = {};
|
|
21
|
+
__export(mfUtils_exports, {
|
|
22
|
+
toRemotesCodeString: () => toRemotesCodeString
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(mfUtils_exports);
|
|
25
|
+
function isSimpleRemote(r) {
|
|
26
|
+
return r.entry;
|
|
27
|
+
}
|
|
28
|
+
function isRemoteEntries(r) {
|
|
29
|
+
return r.entries && r.keyResolver;
|
|
30
|
+
}
|
|
31
|
+
function toRemotesCodeString(remotes) {
|
|
32
|
+
const res = [];
|
|
33
|
+
for (const r of remotes) {
|
|
34
|
+
const aliasName = r.aliasName || r.name;
|
|
35
|
+
const remoteName = r.name;
|
|
36
|
+
if (isSimpleRemote(r)) {
|
|
37
|
+
res.push(`${aliasName}: {
|
|
38
|
+
aliasName: "${aliasName}",
|
|
39
|
+
remoteName: "${remoteName}",
|
|
40
|
+
entry: "${r.entry}"
|
|
41
|
+
}`);
|
|
42
|
+
}
|
|
43
|
+
if (isRemoteEntries(r)) {
|
|
44
|
+
res.push(`${aliasName}: {
|
|
45
|
+
aliasName: "${aliasName}",
|
|
46
|
+
remoteName: "${remoteName}",
|
|
47
|
+
entry: (${JSON.stringify(r.entries)})[${r.keyResolver}]
|
|
48
|
+
}`);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
return res.join(",\n");
|
|
52
|
+
}
|
|
53
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
54
|
+
0 && (module.exports = {
|
|
55
|
+
toRemotesCodeString
|
|
56
|
+
});
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import * as t from '@umijs/bundler-utils/compiled/babel/types';
|
|
2
|
+
import { IApi } from 'umi';
|
|
3
|
+
interface IOpts {
|
|
4
|
+
contentTest?: (content: string) => Boolean;
|
|
5
|
+
astTest?: (opts: {
|
|
6
|
+
node: t.Node;
|
|
7
|
+
content: string;
|
|
8
|
+
}) => Boolean;
|
|
9
|
+
}
|
|
10
|
+
export declare function getNamespace(absFilePath: string, absSrcPath: string): string;
|
|
11
|
+
export declare class Model {
|
|
12
|
+
file: string;
|
|
13
|
+
namespace: string;
|
|
14
|
+
id: string;
|
|
15
|
+
exportName: string;
|
|
16
|
+
deps: string[];
|
|
17
|
+
constructor(file: string, absSrcPath: string, sort: {} | undefined, id: number);
|
|
18
|
+
findDeps(sort: object): string[];
|
|
19
|
+
}
|
|
20
|
+
export declare class ModelUtils {
|
|
21
|
+
api: IApi;
|
|
22
|
+
opts: IOpts;
|
|
23
|
+
count: number;
|
|
24
|
+
constructor(api: IApi | null, opts: IOpts);
|
|
25
|
+
getAllModels(opts: {
|
|
26
|
+
sort?: object;
|
|
27
|
+
extraModels: string[];
|
|
28
|
+
}): Model[];
|
|
29
|
+
getModels(opts: {
|
|
30
|
+
base: string;
|
|
31
|
+
pattern?: string;
|
|
32
|
+
}): string[];
|
|
33
|
+
isModelValid(opts: {
|
|
34
|
+
content: string;
|
|
35
|
+
file: string;
|
|
36
|
+
}): boolean;
|
|
37
|
+
static topologicalSort: (models: Model[]) => string[];
|
|
38
|
+
static getModelsContent(models: Model[]): string;
|
|
39
|
+
}
|
|
40
|
+
export {};
|
|
@@ -0,0 +1,286 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
24
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
25
|
+
mod
|
|
26
|
+
));
|
|
27
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
|
+
|
|
29
|
+
// src/utils/modelUtils.ts
|
|
30
|
+
var modelUtils_exports = {};
|
|
31
|
+
__export(modelUtils_exports, {
|
|
32
|
+
Model: () => Model,
|
|
33
|
+
ModelUtils: () => ModelUtils,
|
|
34
|
+
getNamespace: () => getNamespace
|
|
35
|
+
});
|
|
36
|
+
module.exports = __toCommonJS(modelUtils_exports);
|
|
37
|
+
var import_bundler_utils = require("@umijs/bundler-utils");
|
|
38
|
+
var parser = __toESM(require("@umijs/bundler-utils/compiled/babel/parser"));
|
|
39
|
+
var import_traverse = __toESM(require("@umijs/bundler-utils/compiled/babel/traverse"));
|
|
40
|
+
var t = __toESM(require("@umijs/bundler-utils/compiled/babel/types"));
|
|
41
|
+
var import_esbuild = require("@umijs/bundler-utils/compiled/esbuild");
|
|
42
|
+
var import_fs = require("fs");
|
|
43
|
+
var import_path = require("path");
|
|
44
|
+
var import_plugin_utils = require("umi/plugin-utils");
|
|
45
|
+
var import_astUtils = require("./astUtils");
|
|
46
|
+
function getNamespace(absFilePath, absSrcPath) {
|
|
47
|
+
const relPath = (0, import_plugin_utils.winPath)((0, import_path.relative)((0, import_plugin_utils.winPath)(absSrcPath), (0, import_plugin_utils.winPath)(absFilePath)));
|
|
48
|
+
const parts = relPath.split("/");
|
|
49
|
+
const dirs = parts.slice(0, -1);
|
|
50
|
+
const file = parts[parts.length - 1];
|
|
51
|
+
const validDirs = dirs.filter(
|
|
52
|
+
(dir) => !["src", "pages", "models"].includes(dir)
|
|
53
|
+
);
|
|
54
|
+
let normalizedFile = file;
|
|
55
|
+
normalizedFile = (0, import_path.basename)(file, (0, import_path.extname)(file));
|
|
56
|
+
if (normalizedFile.endsWith(".model")) {
|
|
57
|
+
normalizedFile = normalizedFile.split(".").slice(0, -1).join(".");
|
|
58
|
+
}
|
|
59
|
+
return [...validDirs, normalizedFile].join(".");
|
|
60
|
+
}
|
|
61
|
+
var Model = class {
|
|
62
|
+
constructor(file, absSrcPath, sort, id) {
|
|
63
|
+
let namespace;
|
|
64
|
+
let exportName;
|
|
65
|
+
const [_file, meta] = file.split("#");
|
|
66
|
+
if (meta) {
|
|
67
|
+
const metaObj = JSON.parse(meta);
|
|
68
|
+
namespace = metaObj.namespace;
|
|
69
|
+
exportName = metaObj.exportName;
|
|
70
|
+
}
|
|
71
|
+
this.file = _file;
|
|
72
|
+
this.id = `model_${id}`;
|
|
73
|
+
this.namespace = namespace || getNamespace(_file, absSrcPath);
|
|
74
|
+
this.exportName = exportName || "default";
|
|
75
|
+
this.deps = sort ? this.findDeps(sort) : [];
|
|
76
|
+
}
|
|
77
|
+
findDeps(sort) {
|
|
78
|
+
const content = (0, import_fs.readFileSync)(this.file, "utf-8");
|
|
79
|
+
const loader = (0, import_path.extname)(this.file).slice(1);
|
|
80
|
+
const result = (0, import_esbuild.transformSync)(content, {
|
|
81
|
+
loader,
|
|
82
|
+
sourcemap: false,
|
|
83
|
+
minify: false
|
|
84
|
+
});
|
|
85
|
+
const deps = /* @__PURE__ */ new Set();
|
|
86
|
+
const ast = parser.parse(result.code, {
|
|
87
|
+
sourceType: "module",
|
|
88
|
+
sourceFilename: this.file,
|
|
89
|
+
plugins: []
|
|
90
|
+
});
|
|
91
|
+
sort;
|
|
92
|
+
(0, import_traverse.default)(ast, {
|
|
93
|
+
CallExpression: (path) => {
|
|
94
|
+
if (t.isIdentifier(path.node.callee, { name: "useModel" }) && t.isStringLiteral(path.node.arguments[0])) {
|
|
95
|
+
deps.add(path.node.arguments[0].value);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
});
|
|
99
|
+
return [...deps];
|
|
100
|
+
}
|
|
101
|
+
};
|
|
102
|
+
var _ModelUtils = class {
|
|
103
|
+
constructor(api, opts) {
|
|
104
|
+
this.opts = {};
|
|
105
|
+
this.count = 1;
|
|
106
|
+
this.api = api;
|
|
107
|
+
this.opts = opts;
|
|
108
|
+
}
|
|
109
|
+
getAllModels(opts) {
|
|
110
|
+
this.count = 1;
|
|
111
|
+
const models = [
|
|
112
|
+
...this.getModels({
|
|
113
|
+
base: (0, import_path.join)(this.api.paths.absSrcPath, "models"),
|
|
114
|
+
pattern: "**/*.{ts,tsx,js,jsx}"
|
|
115
|
+
}),
|
|
116
|
+
...this.getModels({
|
|
117
|
+
base: (0, import_path.join)(this.api.paths.absPagesPath),
|
|
118
|
+
pattern: "**/models/**/*.{ts,tsx,js,jsx}"
|
|
119
|
+
}),
|
|
120
|
+
...this.getModels({
|
|
121
|
+
base: (0, import_path.join)(this.api.paths.absPagesPath),
|
|
122
|
+
pattern: "**/model.{ts,tsx,js,jsx}"
|
|
123
|
+
}),
|
|
124
|
+
...opts.extraModels
|
|
125
|
+
].map((file) => {
|
|
126
|
+
return new Model(
|
|
127
|
+
file,
|
|
128
|
+
this.api.paths.absSrcPath,
|
|
129
|
+
opts.sort,
|
|
130
|
+
this.count++
|
|
131
|
+
);
|
|
132
|
+
});
|
|
133
|
+
const namespaces = models.map((model) => model.namespace);
|
|
134
|
+
if (new Set(namespaces).size !== namespaces.length) {
|
|
135
|
+
throw new Error(
|
|
136
|
+
`Duplicate namespace in models: ${namespaces.sort().join(", ")}`
|
|
137
|
+
);
|
|
138
|
+
}
|
|
139
|
+
if (opts.sort) {
|
|
140
|
+
const namespaces2 = _ModelUtils.topologicalSort(models);
|
|
141
|
+
models.sort(
|
|
142
|
+
(a, b) => namespaces2.indexOf(a.namespace) - namespaces2.indexOf(b.namespace)
|
|
143
|
+
);
|
|
144
|
+
}
|
|
145
|
+
return models;
|
|
146
|
+
}
|
|
147
|
+
getModels(opts) {
|
|
148
|
+
return import_plugin_utils.glob.sync(opts.pattern || "**/*.{ts,js}", {
|
|
149
|
+
cwd: opts.base,
|
|
150
|
+
absolute: true
|
|
151
|
+
}).map(import_plugin_utils.winPath).filter((file) => {
|
|
152
|
+
if (/\.d.ts$/.test(file))
|
|
153
|
+
return false;
|
|
154
|
+
if (/\.(test|e2e|spec).([jt])sx?$/.test(file))
|
|
155
|
+
return false;
|
|
156
|
+
const content = (0, import_fs.readFileSync)(file, "utf-8");
|
|
157
|
+
return this.isModelValid({ content, file });
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
isModelValid(opts) {
|
|
161
|
+
var _a;
|
|
162
|
+
const { file, content } = opts;
|
|
163
|
+
if (this.opts.contentTest && this.opts.contentTest(content)) {
|
|
164
|
+
return true;
|
|
165
|
+
}
|
|
166
|
+
let result = null;
|
|
167
|
+
try {
|
|
168
|
+
const ext = (0, import_path.extname)(file).slice(1);
|
|
169
|
+
const loader = ext === "js" ? "jsx" : ext;
|
|
170
|
+
result = (0, import_esbuild.transformSync)(content, {
|
|
171
|
+
loader,
|
|
172
|
+
sourcemap: false,
|
|
173
|
+
minify: false,
|
|
174
|
+
sourcefile: file
|
|
175
|
+
});
|
|
176
|
+
} catch (e) {
|
|
177
|
+
if ((_a = e.errors) == null ? void 0 : _a.length) {
|
|
178
|
+
(0, import_bundler_utils.prettyPrintEsBuildErrors)(e.errors, { path: file, content });
|
|
179
|
+
delete e.errors;
|
|
180
|
+
}
|
|
181
|
+
throw e;
|
|
182
|
+
}
|
|
183
|
+
let ret = false;
|
|
184
|
+
const ast = parser.parse(result.code, {
|
|
185
|
+
sourceType: "module",
|
|
186
|
+
sourceFilename: file,
|
|
187
|
+
plugins: []
|
|
188
|
+
});
|
|
189
|
+
(0, import_traverse.default)(ast, {
|
|
190
|
+
ExportDefaultDeclaration: (path) => {
|
|
191
|
+
let node = path.node.declaration;
|
|
192
|
+
node = (0, import_astUtils.getIdentifierDeclaration)(node, path);
|
|
193
|
+
if (this.opts.astTest && this.opts.astTest({ node, content })) {
|
|
194
|
+
ret = true;
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
});
|
|
198
|
+
return ret;
|
|
199
|
+
}
|
|
200
|
+
static getModelsContent(models) {
|
|
201
|
+
const imports = [];
|
|
202
|
+
const modelProps = [];
|
|
203
|
+
models.forEach((model) => {
|
|
204
|
+
const fileWithoutExt = (0, import_plugin_utils.winPath)(
|
|
205
|
+
(0, import_path.format)({
|
|
206
|
+
dir: (0, import_path.dirname)(model.file),
|
|
207
|
+
base: (0, import_path.basename)(model.file, (0, import_path.extname)(model.file))
|
|
208
|
+
})
|
|
209
|
+
);
|
|
210
|
+
if (model.exportName !== "default") {
|
|
211
|
+
imports.push(
|
|
212
|
+
`import { ${model.exportName} as ${model.id} } from '${fileWithoutExt}';`
|
|
213
|
+
);
|
|
214
|
+
} else {
|
|
215
|
+
imports.push(`import ${model.id} from '${fileWithoutExt}';`);
|
|
216
|
+
}
|
|
217
|
+
modelProps.push(
|
|
218
|
+
`${model.id}: { namespace: '${model.namespace}', model: ${model.id} },`
|
|
219
|
+
);
|
|
220
|
+
});
|
|
221
|
+
return `
|
|
222
|
+
${imports.join("\n")}
|
|
223
|
+
|
|
224
|
+
export const models = {
|
|
225
|
+
${modelProps.join("\n")}
|
|
226
|
+
} as const`;
|
|
227
|
+
}
|
|
228
|
+
};
|
|
229
|
+
var ModelUtils = _ModelUtils;
|
|
230
|
+
// https://github.com/umijs/umi/issues/9837
|
|
231
|
+
ModelUtils.topologicalSort = (models) => {
|
|
232
|
+
const graph = [];
|
|
233
|
+
const namespaceToNode = {};
|
|
234
|
+
models.forEach((model, index) => {
|
|
235
|
+
const node = {
|
|
236
|
+
namespace: model.namespace,
|
|
237
|
+
deps: model.deps,
|
|
238
|
+
index,
|
|
239
|
+
in: 0,
|
|
240
|
+
childs: []
|
|
241
|
+
};
|
|
242
|
+
if (namespaceToNode[model.namespace]) {
|
|
243
|
+
throw new Error(`Duplicate namespace in models: ${model.namespace}`);
|
|
244
|
+
}
|
|
245
|
+
namespaceToNode[model.namespace] = node;
|
|
246
|
+
graph.push(node);
|
|
247
|
+
});
|
|
248
|
+
graph.forEach((node) => {
|
|
249
|
+
node.deps.forEach((dep) => {
|
|
250
|
+
const depNode = namespaceToNode[dep];
|
|
251
|
+
if (!depNode) {
|
|
252
|
+
throw new Error(`Model namespace not found: ${dep}`);
|
|
253
|
+
}
|
|
254
|
+
depNode.childs.push(node);
|
|
255
|
+
node.in++;
|
|
256
|
+
});
|
|
257
|
+
});
|
|
258
|
+
const queue = [];
|
|
259
|
+
while (true) {
|
|
260
|
+
const zeronode = graph.find((n) => {
|
|
261
|
+
return n && n.in === 0;
|
|
262
|
+
});
|
|
263
|
+
if (!zeronode) {
|
|
264
|
+
break;
|
|
265
|
+
}
|
|
266
|
+
queue.push(zeronode.namespace);
|
|
267
|
+
zeronode.childs.forEach((child) => {
|
|
268
|
+
child.in--;
|
|
269
|
+
});
|
|
270
|
+
zeronode.childs = [];
|
|
271
|
+
delete graph[zeronode.index];
|
|
272
|
+
}
|
|
273
|
+
const leftNodes = graph.filter(Boolean);
|
|
274
|
+
if (leftNodes.length > 0) {
|
|
275
|
+
throw new Error(
|
|
276
|
+
`Circle dependency detected in models: ${leftNodes.map((m) => import_plugin_utils.chalk.red(m.namespace)).join(", ")}`
|
|
277
|
+
);
|
|
278
|
+
}
|
|
279
|
+
return queue;
|
|
280
|
+
};
|
|
281
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
282
|
+
0 && (module.exports = {
|
|
283
|
+
Model,
|
|
284
|
+
ModelUtils,
|
|
285
|
+
getNamespace
|
|
286
|
+
});
|