@umijs/plugins 4.0.7 → 4.0.10

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.
@@ -1,126 +1,131 @@
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: '' };
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 });
30
8
  };
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
- }
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;
48
16
  };
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);
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)((0, import_path.join)(momentLocation, `${lang}-${(_a = country == null ? void 0 : country.toLocaleLowerCase) == null ? void 0 : _a.call(country)}.js`))) {
36
+ const momentLocale = `${lang}-${(_b = country == null ? void 0 : country.toLocaleLowerCase) == null ? void 0 : _b.call(country)}`;
37
+ return {
38
+ momentLocale
39
+ };
40
+ }
41
+ if ((0, import_fs.existsSync)((0, import_path.join)(momentLocation, `${lang}.js`))) {
42
+ return {
43
+ momentLocale: lang
44
+ };
45
+ }
46
+ return { momentLocale: "" };
93
47
  };
94
- exports.getLocaleList = getLocaleList;
95
- const exactLocalePaths = (data) => {
96
- return plugin_utils_1.lodash.flatten(data.map((item) => item.paths));
48
+ var getAntdLocale = (lang, country) => `${lang}_${(country || lang).toLocaleUpperCase()}`;
49
+ var modulesHasLocale = (localePath) => {
50
+ try {
51
+ require.resolve(localePath);
52
+ return true;
53
+ } catch (error) {
54
+ return false;
55
+ }
97
56
  };
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,
57
+ var getLocaleList = async (opts) => {
58
+ const {
59
+ localeFolder,
60
+ separator = "-",
61
+ absSrcPath = "",
62
+ absPagesPath = "",
63
+ addAntdLocales,
64
+ resolveKey = "moment"
65
+ } = opts;
66
+ const localeFileMath = new RegExp(`^([a-z]{2})${separator}?([A-Z]{2})?.(js|json|ts)$`);
67
+ const localeFiles = import_plugin_utils.glob.sync("*.{ts,js,json}", {
68
+ cwd: (0, import_plugin_utils.winPath)((0, import_path.join)(absSrcPath, localeFolder))
69
+ }).map((name) => (0, import_plugin_utils.winPath)((0, import_path.join)(absSrcPath, localeFolder, name))).concat(import_plugin_utils.glob.sync(`**/${localeFolder}/*.{ts,js,json}`, {
70
+ cwd: absPagesPath
71
+ }).map((name) => (0, import_plugin_utils.winPath)((0, import_path.join)(absPagesPath, name)))).filter((p) => localeFileMath.test((0, import_path.basename)(p)) && (0, import_fs.existsSync)(p)).map((fullName) => {
72
+ var _a, _b;
73
+ const fileName = (0, import_path.basename)(fullName);
74
+ const fileInfo = (_b = (_a = localeFileMath.exec(fileName)) == null ? void 0 : _a.slice(1, 3)) == null ? void 0 : _b.filter(Boolean);
75
+ return {
76
+ name: (fileInfo || []).join(separator),
77
+ path: fullName
119
78
  };
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);
79
+ });
80
+ const groups = import_plugin_utils.lodash.groupBy(localeFiles, "name");
81
+ const promises = Object.keys(groups).map(async (name) => {
82
+ const [lang, country = ""] = name.split(separator);
83
+ const { momentLocale } = getMomentLocale(lang, country, resolveKey);
84
+ const antdLocale = import_plugin_utils.lodash.uniq(await addAntdLocales({ lang, country })).filter((localePath) => modulesHasLocale(localePath));
85
+ return {
86
+ lang,
87
+ name,
88
+ locale: name.split(separator).join("-"),
89
+ country,
90
+ antdLocale,
91
+ paths: groups[name].map((item) => (0, import_plugin_utils.winPath)(item.path)),
92
+ momentLocale
93
+ };
94
+ });
95
+ return Promise.all(promises);
96
+ };
97
+ var exactLocalePaths = (data) => {
98
+ return import_plugin_utils.lodash.flatten(data.map((item) => item.paths));
99
+ };
100
+ function isNeedPolyfill(targets = {}) {
101
+ const polyfillTargets = {
102
+ ie: 10,
103
+ firefox: 28,
104
+ chrome: 23,
105
+ safari: 9.1,
106
+ opera: 12.1,
107
+ ios: 9.3,
108
+ ios_saf: 9.3,
109
+ operamini: Infinity,
110
+ op_mini: Infinity,
111
+ android: 4.3,
112
+ blackberry: Infinity,
113
+ operamobile: 12.1,
114
+ op_mob: 12.1,
115
+ explorermobil: 10,
116
+ ie_mob: 10,
117
+ ucandroid: Infinity
118
+ };
119
+ return Object.keys(targets).find((key) => {
120
+ const lowKey = key.toLocaleLowerCase();
121
+ return polyfillTargets[lowKey] && polyfillTargets[lowKey] >= targets[key];
122
+ }) !== void 0;
125
123
  }
126
- exports.isNeedPolyfill = isNeedPolyfill;
124
+ // Annotate the CommonJS export names for ESM import in node:
125
+ 0 && (module.exports = {
126
+ exactLocalePaths,
127
+ getAntdLocale,
128
+ getLocaleList,
129
+ getMomentLocale,
130
+ isNeedPolyfill
131
+ });