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