@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
@@ -0,0 +1,126 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isNeedPolyfill = exports.exactLocalePaths = exports.getLocaleList = exports.getAntdLocale = exports.getMomentLocale = void 0;
4
+ const fs_1 = require("fs");
5
+ const path_1 = require("path");
6
+ const plugin_utils_1 = require("umi/plugin-utils");
7
+ /**
8
+ * 获取 moment 包的 locale 名称
9
+ * @param lang 语言
10
+ * @param country 国家
11
+ * @param resolveKey 用来resolve的key,moment 或者 dayjs,为了使 dayjs 可以替换 moment
12
+ */
13
+ const getMomentLocale = (lang, country, resolveKey) => {
14
+ var _a, _b;
15
+ const momentLocation = require
16
+ .resolve(`${resolveKey}/locale/zh-cn`)
17
+ .replace(/zh\-cn\.js$/, '');
18
+ if ((0, fs_1.existsSync)((0, path_1.join)(momentLocation, `${lang}-${(_a = country === null || country === void 0 ? void 0 : country.toLocaleLowerCase) === null || _a === void 0 ? void 0 : _a.call(country)}.js`))) {
19
+ const momentLocale = `${lang}-${(_b = country === null || country === void 0 ? void 0 : country.toLocaleLowerCase) === null || _b === void 0 ? void 0 : _b.call(country)}`;
20
+ return {
21
+ momentLocale,
22
+ };
23
+ }
24
+ if ((0, fs_1.existsSync)((0, path_1.join)(momentLocation, `${lang}.js`))) {
25
+ return {
26
+ momentLocale: lang,
27
+ };
28
+ }
29
+ return { momentLocale: '' };
30
+ };
31
+ exports.getMomentLocale = getMomentLocale;
32
+ const getAntdLocale = (lang, country) => `${lang}_${(country || lang).toLocaleUpperCase()}`;
33
+ exports.getAntdLocale = getAntdLocale;
34
+ /**
35
+ * 有些情况下可能项目包含的locale和antd的不匹配
36
+ * 这个方法用于检测
37
+ * @param localePath
38
+ * @returns
39
+ */
40
+ const modulesHasLocale = (localePath) => {
41
+ try {
42
+ require.resolve(localePath);
43
+ return true;
44
+ }
45
+ catch (error) {
46
+ return false;
47
+ }
48
+ };
49
+ const getLocaleList = async (opts) => {
50
+ const { localeFolder, separator = '-', absSrcPath = '', absPagesPath = '', addAntdLocales, resolveKey = 'moment', } = opts;
51
+ const localeFileMath = new RegExp(`^([a-z]{2})${separator}?([A-Z]{2})?\.(js|json|ts)$`);
52
+ const localeFiles = plugin_utils_1.glob
53
+ .sync('*.{ts,js,json}', {
54
+ cwd: (0, plugin_utils_1.winPath)((0, path_1.join)(absSrcPath, localeFolder)),
55
+ })
56
+ .map((name) => (0, plugin_utils_1.winPath)((0, path_1.join)(absSrcPath, localeFolder, name)))
57
+ .concat(plugin_utils_1.glob
58
+ .sync(`**/${localeFolder}/*.{ts,js,json}`, {
59
+ cwd: absPagesPath,
60
+ })
61
+ .map((name) => (0, plugin_utils_1.winPath)((0, path_1.join)(absPagesPath, name))))
62
+ .filter((p) => localeFileMath.test((0, path_1.basename)(p)) && (0, fs_1.existsSync)(p))
63
+ .map((fullName) => {
64
+ var _a, _b;
65
+ const fileName = (0, path_1.basename)(fullName);
66
+ const fileInfo = (_b = (_a = localeFileMath
67
+ .exec(fileName)) === null || _a === void 0 ? void 0 : _a.slice(1, 3)) === null || _b === void 0 ? void 0 : _b.filter(Boolean);
68
+ return {
69
+ name: (fileInfo || []).join(separator),
70
+ path: fullName,
71
+ };
72
+ });
73
+ const groups = plugin_utils_1.lodash.groupBy(localeFiles, 'name');
74
+ const promises = Object.keys(groups).map(async (name) => {
75
+ const [lang, country = ''] = name.split(separator);
76
+ const { momentLocale } = (0, exports.getMomentLocale)(lang, country, resolveKey);
77
+ const antdLocale = plugin_utils_1.lodash
78
+ .uniq(await addAntdLocales({ lang, country }))
79
+ .filter((localePath) => modulesHasLocale(localePath));
80
+ return {
81
+ lang,
82
+ name,
83
+ // react-intl Function.supportedLocalesOf
84
+ // Uncaught RangeError: Incorrect locale information provided
85
+ locale: name.split(separator).join('-'),
86
+ country,
87
+ antdLocale,
88
+ paths: groups[name].map((item) => (0, plugin_utils_1.winPath)(item.path)),
89
+ momentLocale,
90
+ };
91
+ });
92
+ return Promise.all(promises);
93
+ };
94
+ exports.getLocaleList = getLocaleList;
95
+ const exactLocalePaths = (data) => {
96
+ return plugin_utils_1.lodash.flatten(data.map((item) => item.paths));
97
+ };
98
+ exports.exactLocalePaths = exactLocalePaths;
99
+ function isNeedPolyfill(targets = {}) {
100
+ // data come from https://caniuse.com/#search=intl
101
+ // you can find all browsers in https://github.com/browserslist/browserslist#browsers
102
+ const polyfillTargets = {
103
+ ie: 10,
104
+ firefox: 28,
105
+ chrome: 23,
106
+ safari: 9.1,
107
+ opera: 12.1,
108
+ ios: 9.3,
109
+ ios_saf: 9.3,
110
+ operamini: Infinity,
111
+ op_mini: Infinity,
112
+ android: 4.3,
113
+ blackberry: Infinity,
114
+ operamobile: 12.1,
115
+ op_mob: 12.1,
116
+ explorermobil: 10,
117
+ ie_mob: 10,
118
+ ucandroid: Infinity,
119
+ };
120
+ return (Object.keys(targets).find((key) => {
121
+ const lowKey = key.toLocaleLowerCase();
122
+ // @ts-ignore
123
+ return polyfillTargets[lowKey] && polyfillTargets[lowKey] >= targets[key];
124
+ }) !== undefined);
125
+ }
126
+ exports.isNeedPolyfill = isNeedPolyfill;
@@ -0,0 +1,36 @@
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 class Model {
11
+ file: string;
12
+ namespace: string;
13
+ id: string;
14
+ exportName: string;
15
+ constructor(file: string, id: number);
16
+ }
17
+ export declare class ModelUtils {
18
+ api: IApi;
19
+ opts: IOpts;
20
+ count: number;
21
+ constructor(api: IApi | null, opts: IOpts);
22
+ getAllModels(opts: {
23
+ extraModelsPre: string[];
24
+ extraModels: string[];
25
+ }): Model[];
26
+ getModels(opts: {
27
+ base: string;
28
+ pattern?: string;
29
+ }): string[];
30
+ isModelValid(opts: {
31
+ content: string;
32
+ file: string;
33
+ }): boolean;
34
+ static getModelsContent(models: Model[]): string;
35
+ }
36
+ export {};
@@ -0,0 +1,150 @@
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
+ exports.ModelUtils = exports.Model = void 0;
30
+ const parser = __importStar(require("@umijs/bundler-utils/compiled/babel/parser"));
31
+ const traverse_1 = __importDefault(require("@umijs/bundler-utils/compiled/babel/traverse"));
32
+ const esbuild_1 = require("@umijs/bundler-utils/compiled/esbuild");
33
+ const fs_1 = require("fs");
34
+ const path_1 = require("path");
35
+ const plugin_utils_1 = require("umi/plugin-utils");
36
+ const astUtils_1 = require("./astUtils");
37
+ class Model {
38
+ constructor(file, id) {
39
+ let namespace;
40
+ let exportName;
41
+ const [_file, meta] = file.split('#');
42
+ if (meta) {
43
+ const metaObj = JSON.parse(meta);
44
+ namespace = metaObj.namespace;
45
+ exportName = metaObj.exportName;
46
+ }
47
+ this.file = _file;
48
+ this.id = `model_${id}`;
49
+ this.namespace = namespace || (0, path_1.basename)(file, (0, path_1.extname)(file));
50
+ this.exportName = exportName || 'default';
51
+ }
52
+ }
53
+ exports.Model = Model;
54
+ class ModelUtils {
55
+ constructor(api, opts) {
56
+ this.opts = {};
57
+ this.count = 1;
58
+ this.api = api;
59
+ this.opts = opts;
60
+ }
61
+ getAllModels(opts) {
62
+ // reset count
63
+ this.count = 1;
64
+ return [
65
+ ...opts.extraModelsPre,
66
+ ...this.getModels({
67
+ base: (0, path_1.join)(this.api.paths.absSrcPath, 'models'),
68
+ pattern: '**/*.{ts,tsx,js,jsx}',
69
+ }),
70
+ ...this.getModels({
71
+ base: (0, path_1.join)(this.api.paths.absPagesPath),
72
+ pattern: '**/models/**/*.{ts,tsx,js,jsx}',
73
+ }),
74
+ ...this.getModels({
75
+ base: (0, path_1.join)(this.api.paths.absPagesPath),
76
+ pattern: '**/model.{ts,tsx,js,jsx}',
77
+ }),
78
+ ...opts.extraModels,
79
+ ].map((file) => {
80
+ return new Model(file, this.count++);
81
+ });
82
+ }
83
+ getModels(opts) {
84
+ return plugin_utils_1.glob
85
+ .sync(opts.pattern || '**/*.{ts,js}', {
86
+ cwd: opts.base,
87
+ absolute: true,
88
+ })
89
+ .map(plugin_utils_1.winPath)
90
+ .filter((file) => {
91
+ if (/\.d.ts$/.test(file))
92
+ return false;
93
+ if (/\.(test|e2e|spec).([jt])sx?$/.test(file))
94
+ return false;
95
+ const content = (0, fs_1.readFileSync)(file, 'utf-8');
96
+ return this.isModelValid({ content, file });
97
+ });
98
+ }
99
+ isModelValid(opts) {
100
+ const { file, content } = opts;
101
+ if (this.opts.contentTest && this.opts.contentTest(content)) {
102
+ return true;
103
+ }
104
+ // transform with esbuild first
105
+ // to reduce unexpected ast problem
106
+ const loader = (0, path_1.extname)(file).slice(1);
107
+ const result = (0, esbuild_1.transformSync)(content, {
108
+ loader,
109
+ sourcemap: false,
110
+ minify: false,
111
+ });
112
+ // transform with babel
113
+ let ret = false;
114
+ const ast = parser.parse(result.code, {
115
+ sourceType: 'module',
116
+ sourceFilename: file,
117
+ plugins: [],
118
+ });
119
+ (0, traverse_1.default)(ast, {
120
+ ExportDefaultDeclaration: (path) => {
121
+ let node = path.node.declaration;
122
+ node = (0, astUtils_1.getIdentifierDeclaration)(node, path);
123
+ if (this.opts.astTest && this.opts.astTest({ node, content })) {
124
+ ret = true;
125
+ }
126
+ },
127
+ });
128
+ return ret;
129
+ }
130
+ static getModelsContent(models) {
131
+ const imports = [];
132
+ const modelProps = [];
133
+ models.forEach((model) => {
134
+ if (model.exportName !== 'default') {
135
+ imports.push(`import { ${model.exportName} as ${model.id} } from '${model.file}';`);
136
+ }
137
+ else {
138
+ imports.push(`import ${model.id} from '${model.file}';`);
139
+ }
140
+ modelProps.push(`${model.id}: { namespace: '${model.namespace}', model: ${model.id} },`);
141
+ });
142
+ return `
143
+ ${imports.join('\n')}
144
+
145
+ export const models = {
146
+ ${modelProps.join('\n')}
147
+ }`;
148
+ }
149
+ }
150
+ exports.ModelUtils = ModelUtils;
@@ -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 path_1 = require("path");
5
+ const plugin_utils_1 = require("umi/plugin-utils");
6
+ function withTmpPath(opts) {
7
+ return (0, plugin_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/libs/dva.ts ADDED
@@ -0,0 +1,10 @@
1
+ // @ts-ignore
2
+ export { create, saga, utils } from 'dva-core';
3
+ export {
4
+ connect,
5
+ Provider,
6
+ useDispatch,
7
+ useSelector,
8
+ useStore,
9
+ } from 'react-redux';
10
+ export { bindActionCreators } from 'redux';