@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.
Files changed (98) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +4 -1
  3. package/dist/access.d.ts +1 -1
  4. package/dist/access.js +194 -4
  5. package/dist/{sass.d.ts → analytics.d.ts} +1 -1
  6. package/dist/analytics.js +118 -0
  7. package/dist/antd.d.ts +1 -1
  8. package/dist/antd.js +345 -157
  9. package/dist/{icons.d.ts → confetti.d.ts} +1 -1
  10. package/dist/confetti.js +64 -0
  11. package/dist/constants.d.ts +1 -0
  12. package/dist/constants.js +30 -0
  13. package/dist/dva.d.ts +4 -1
  14. package/dist/dva.js +302 -8
  15. package/dist/initial-state.d.ts +1 -1
  16. package/dist/initial-state.js +147 -4
  17. package/dist/layout.d.ts +1 -1
  18. package/dist/layout.js +754 -4
  19. package/dist/locale.d.ts +2 -1
  20. package/dist/locale.js +257 -4
  21. package/dist/mf.d.ts +2 -0
  22. package/dist/mf.js +358 -0
  23. package/dist/model.d.ts +1 -1
  24. package/dist/model.js +109 -4
  25. package/dist/moment2dayjs.d.ts +3 -0
  26. package/dist/moment2dayjs.js +125 -0
  27. package/dist/qiankun/constants.d.ts +5 -0
  28. package/dist/qiankun/constants.js +41 -0
  29. package/dist/qiankun/master.d.ts +6 -0
  30. package/dist/qiankun/master.js +236 -0
  31. package/dist/qiankun/slave.d.ts +3 -0
  32. package/dist/qiankun/slave.js +345 -0
  33. package/dist/qiankun.d.ts +1 -1
  34. package/dist/qiankun.js +51 -4
  35. package/dist/react-query.d.ts +3 -0
  36. package/dist/react-query.js +193 -0
  37. package/dist/request.d.ts +1 -1
  38. package/dist/request.js +384 -4
  39. package/dist/styled-components.d.ts +3 -0
  40. package/dist/styled-components.js +150 -0
  41. package/dist/tailwindcss.d.ts +3 -0
  42. package/dist/tailwindcss.js +106 -0
  43. package/dist/unocss.d.ts +3 -0
  44. package/dist/unocss.js +71 -0
  45. package/dist/utils/astUtils.d.ts +3 -0
  46. package/dist/utils/astUtils.js +49 -0
  47. package/dist/utils/localeUtils.d.ts +33 -0
  48. package/dist/utils/localeUtils.js +139 -0
  49. package/dist/utils/mfUtils.d.ts +14 -0
  50. package/dist/utils/mfUtils.js +56 -0
  51. package/dist/utils/modelUtils.d.ts +40 -0
  52. package/dist/utils/modelUtils.js +286 -0
  53. package/dist/utils/resolveProjectDep.d.ts +5 -0
  54. package/dist/utils/resolveProjectDep.js +40 -0
  55. package/dist/utils/withTmpPath.d.ts +6 -0
  56. package/dist/utils/withTmpPath.js +39 -0
  57. package/dist/valtio.d.ts +3 -0
  58. package/dist/valtio.js +81 -0
  59. package/libs/dva.tsx +45 -0
  60. package/libs/model.tsx +180 -0
  61. package/libs/qiankun/master/AntdErrorBoundary.tsx +34 -0
  62. package/libs/qiankun/master/AntdLoader.tsx +15 -0
  63. package/libs/qiankun/master/ErrorBoundary.tsx +7 -0
  64. package/libs/qiankun/master/MicroApp.tsx +327 -0
  65. package/libs/qiankun/master/MicroAppWithMemoHistory.tsx +43 -0
  66. package/libs/qiankun/master/common.ts +172 -0
  67. package/libs/qiankun/master/constants.ts +19 -0
  68. package/libs/qiankun/master/getMicroAppRouteComponent.tsx.tpl +45 -0
  69. package/libs/qiankun/master/masterRuntimePlugin.tsx +161 -0
  70. package/libs/qiankun/master/routeUtils.ts +26 -0
  71. package/libs/qiankun/master/types.ts +54 -0
  72. package/libs/qiankun/slave/MicroAppLink.tsx +122 -0
  73. package/libs/qiankun/slave/connectMaster.tsx +14 -0
  74. package/libs/qiankun/slave/constants.ts +5 -0
  75. package/libs/qiankun/slave/lifecycles.ts +164 -0
  76. package/libs/qiankun/slave/qiankunModel.ts +18 -0
  77. package/libs/qiankun/slave/slaveRuntimePlugin.ts +36 -0
  78. package/package.json +54 -24
  79. package/templates/antd/runtime.ts.tpl +170 -0
  80. package/templates/antd/types.d.ts.tpl +17 -0
  81. package/templates/locale/SelectLang.tpl +502 -0
  82. package/templates/locale/locale.tpl +82 -0
  83. package/templates/locale/localeExports.tpl +307 -0
  84. package/templates/locale/runtime.tpl +34 -0
  85. package/templates/mf/runtime.ts.tpl +149 -0
  86. package/dist/access.d.ts.map +0 -1
  87. package/dist/antd.d.ts.map +0 -1
  88. package/dist/dva.d.ts.map +0 -1
  89. package/dist/icons.d.ts.map +0 -1
  90. package/dist/icons.js +0 -5
  91. package/dist/initial-state.d.ts.map +0 -1
  92. package/dist/layout.d.ts.map +0 -1
  93. package/dist/locale.d.ts.map +0 -1
  94. package/dist/model.d.ts.map +0 -1
  95. package/dist/qiankun.d.ts.map +0 -1
  96. package/dist/request.d.ts.map +0 -1
  97. package/dist/sass.d.ts.map +0 -1
  98. package/dist/sass.js +0 -5
package/dist/antd.js CHANGED
@@ -1,168 +1,356 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const utils_1 = require("@umijs/utils");
4
- const fs_1 = require("fs");
5
- const path_1 = require("path");
6
- const presets = {
7
- antd: {
8
- plugins: [
9
- 'isSameOrBefore',
10
- 'isSameOrAfter',
11
- 'advancedFormat',
12
- 'customParseFormat',
13
- 'weekday',
14
- 'weekYear',
15
- 'weekOfYear',
16
- 'isMoment',
17
- 'localeData',
18
- 'localizedFormat',
19
- ],
20
- replaceMoment: true,
21
- },
22
- antdv3: {
23
- plugins: [
24
- 'isSameOrBefore',
25
- 'isSameOrAfter',
26
- 'advancedFormat',
27
- 'customParseFormat',
28
- 'weekday',
29
- 'weekYear',
30
- 'weekOfYear',
31
- 'isMoment',
32
- 'localeData',
33
- 'localizedFormat',
34
- 'badMutable',
35
- ],
36
- replaceMoment: true,
37
- },
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 });
38
10
  };
39
- const getConfig = (api) => {
40
- let { preset = 'antd', plugins, replaceMoment, } = api.userConfig.antdDayjs || {};
41
- if (preset && presets[preset]) {
42
- plugins = presets[preset].plugins;
43
- replaceMoment = presets[preset].replaceMoment;
44
- }
45
- if (plugins)
46
- plugins = plugins;
47
- if (replaceMoment !== undefined)
48
- replaceMoment = replaceMoment;
49
- return {
50
- plugins,
51
- replaceMoment,
52
- };
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;
53
18
  };
54
- const DIR_NAME = 'plugin-antd';
55
- exports.default = (api) => {
56
- const opts = api.userConfig.antd;
57
- // dayjs (by default)
58
- const { dayjs = true } = opts;
59
- api.describe({
60
- config: {
61
- schema(Joi) {
62
- return Joi.object({
63
- dark: Joi.boolean(),
64
- compact: Joi.boolean(),
65
- config: Joi.object(),
66
- dayjs: Joi.alternatives(Joi.boolean(), Joi.object({
67
- preset: Joi.string(),
68
- plugins: Joi.array(),
69
- replaceMoment: Joi.boolean(),
70
- })),
71
- });
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/antd.ts
30
+ var antd_exports = {};
31
+ __export(antd_exports, {
32
+ default: () => antd_default
33
+ });
34
+ module.exports = __toCommonJS(antd_exports);
35
+ var import_moment_webpack_plugin = __toESM(require("@ant-design/moment-webpack-plugin"));
36
+ var import_assert = __toESM(require("assert"));
37
+ var import_path = require("path");
38
+ var import_umi = require("umi");
39
+ var import_plugin_utils = require("umi/plugin-utils");
40
+ var import_constants = require("./constants");
41
+ var import_resolveProjectDep = require("./utils/resolveProjectDep");
42
+ var import_withTmpPath = require("./utils/withTmpPath");
43
+ var ANTD_TEMPLATES_DIR = (0, import_path.join)(import_constants.TEMPLATES_DIR, "antd");
44
+ var antd_default = (api) => {
45
+ let pkgPath;
46
+ let antdVersion = "4.0.0";
47
+ try {
48
+ pkgPath = (0, import_resolveProjectDep.resolveProjectDep)({
49
+ pkg: api.pkg,
50
+ cwd: api.cwd,
51
+ dep: "antd"
52
+ }) || (0, import_path.dirname)(require.resolve("antd/package.json"));
53
+ antdVersion = require(`${pkgPath}/package.json`).version;
54
+ } catch (e) {
55
+ }
56
+ const isV5 = antdVersion.startsWith("5");
57
+ const isV4 = antdVersion.startsWith("4");
58
+ const appComponentAvailable = import_plugin_utils.semver.gte(antdVersion, "5.1.0");
59
+ const appConfigAvailable = import_plugin_utils.semver.gte(antdVersion, "5.3.0");
60
+ const day2MomentAvailable = import_plugin_utils.semver.gte(antdVersion, "5.0.0");
61
+ api.describe({
62
+ config: {
63
+ schema({ zod }) {
64
+ const commonSchema = {
65
+ dark: zod.boolean(),
66
+ compact: zod.boolean(),
67
+ // babel-plugin-import
68
+ import: zod.boolean(),
69
+ // less or css, default less
70
+ style: zod.enum(["less", "css"]).describe("less or css, default less")
71
+ };
72
+ const createZodRecordWithSpecifiedPartial = (partial) => {
73
+ const keys = Object.keys(partial);
74
+ return zod.union([
75
+ zod.object(partial),
76
+ zod.record(zod.any()).refine((obj) => {
77
+ return !keys.some((key) => key in obj);
78
+ })
79
+ ]);
80
+ };
81
+ const createV5Schema = () => {
82
+ const componentNameSchema = zod.string().refine(
83
+ (value) => {
84
+ const firstLetter = value.slice(0, 1);
85
+ return firstLetter === firstLetter.toUpperCase();
72
86
  },
73
- },
74
- });
75
- // antd import
76
- api.chainWebpack((memo) => {
77
- function getUserLibDir({ library }) {
78
- if (
79
- // @ts-ignore
80
- (api.pkg.dependencies && api.pkg.dependencies[library]) ||
81
- // @ts-ignore
82
- (api.pkg.devDependencies && api.pkg.devDependencies[library]) ||
83
- // egg project using `clientDependencies` in ali tnpm
84
- // @ts-ignore
85
- (api.pkg.clientDependencies && api.pkg.clientDependencies[library])) {
86
- return (0, utils_1.winPath)((0, path_1.dirname)(
87
- // 通过 resolve 往上找,可支持 lerna 仓库
88
- // lerna 仓库如果用 yarn workspace 的依赖不一定在 node_modules,可能被提到根目录,并且没有 link
89
- utils_1.resolve.sync(`${library}/package.json`, {
90
- basedir: api.paths.cwd,
91
- })));
87
+ {
88
+ message: "theme.components.[componentName] needs to be in PascalCase, e.g. theme.components.Button"
92
89
  }
93
- return null;
90
+ );
91
+ const themeSchema = createZodRecordWithSpecifiedPartial({
92
+ components: zod.record(componentNameSchema, zod.record(zod.any()))
93
+ });
94
+ const configProvider = createZodRecordWithSpecifiedPartial({
95
+ theme: themeSchema
96
+ });
97
+ return zod.object({
98
+ ...commonSchema,
99
+ theme: themeSchema.describe("Shortcut of `configProvider.theme`"),
100
+ appConfig: zod.record(zod.any()).describe("Only >= antd@5.1.0 is supported"),
101
+ momentPicker: zod.boolean().describe("DatePicker & Calendar use moment version"),
102
+ styleProvider: zod.record(zod.any()),
103
+ configProvider
104
+ }).deepPartial();
105
+ };
106
+ const createV4Schema = () => {
107
+ return zod.object({
108
+ ...commonSchema,
109
+ configProvider: zod.record(zod.any())
110
+ }).deepPartial();
111
+ };
112
+ if (isV5) {
113
+ return createV5Schema();
94
114
  }
95
- memo.resolve.alias.set('antd', getUserLibDir({ library: 'antd' }) ||
96
- (0, path_1.dirname)(require.resolve('antd/package.json')));
97
- if (dayjs !== false) {
98
- const { replaceMoment } = getConfig(api);
99
- if (replaceMoment) {
100
- memo.resolve.alias.set('moment', getUserLibDir({ library: 'dayjs' }) ||
101
- (0, path_1.dirname)(require.resolve('dayjs/package.json')));
102
- }
115
+ if (isV4) {
116
+ return createV4Schema();
103
117
  }
104
- return memo;
105
- });
106
- // dark mode
107
- // compat mode
108
- if ((opts === null || opts === void 0 ? void 0 : opts.dark) || (opts === null || opts === void 0 ? void 0 : opts.compact)) {
109
- // support dark mode, user use antd 4 by default
110
- const { getThemeVariables } = require('antd/dist/theme');
111
- api.modifyDefaultConfig((config) => {
112
- config.theme = Object.assign(Object.assign({}, getThemeVariables(opts)), config.theme);
113
- return config;
114
- });
118
+ return zod.object({});
119
+ }
120
+ },
121
+ enableBy({ userConfig }) {
122
+ return process.env.UMI_PLUGIN_ANTD_ENABLE || userConfig.antd;
115
123
  }
116
- if (dayjs !== false) {
117
- api.onGenerateFiles({
118
- fn: () => {
119
- const { plugins } = getConfig(api);
120
- const runtimeTpl = (0, fs_1.readFileSync)((0, path_1.join)(__dirname, '../templates/antd/dayjs.tpl'), 'utf-8');
121
- api.writeTmpFile({
122
- path: 'plugin-antd/dayjs.tsx',
123
- content: utils_1.Mustache.render(runtimeTpl, {
124
- plugins,
125
- dayjsPath: (0, path_1.dirname)(require.resolve('dayjs/package.json')),
126
- dayjsPluginPath: (0, path_1.dirname)(require.resolve('antd-dayjs-webpack-plugin/package.json')),
127
- }),
128
- });
129
- },
130
- });
131
- api.addEntryCodeAhead(() => {
132
- return [`import './${DIR_NAME}/dayjs.tsx'`];
133
- });
124
+ });
125
+ api.addRuntimePluginKey(() => ["antd"]);
126
+ function checkPkgPath() {
127
+ if (!pkgPath) {
128
+ throw new Error(`Can't find antd package. Please install antd first.`);
129
+ }
130
+ }
131
+ api.modifyAppData((memo) => {
132
+ checkPkgPath();
133
+ const version = require(`${pkgPath}/package.json`).version;
134
+ memo.antd = {
135
+ pkgPath,
136
+ version
137
+ };
138
+ return memo;
139
+ });
140
+ api.modifyConfig((memo) => {
141
+ var _a;
142
+ checkPkgPath();
143
+ let antd = memo.antd || {};
144
+ if (process.env.UMI_PLUGIN_ANTD_ENABLE) {
145
+ const { defaultConfig } = JSON.parse(process.env.UMI_PLUGIN_ANTD_ENABLE);
146
+ memo.antd = antd = Object.assign(defaultConfig, antd);
147
+ }
148
+ memo.alias.antd = pkgPath;
149
+ if (isV5) {
150
+ const theme = require("@ant-design/antd-theme-variable");
151
+ memo.theme = {
152
+ ...theme,
153
+ ...memo.theme
154
+ };
155
+ if ((_a = memo.antd) == null ? void 0 : _a.import) {
156
+ const errorMessage = `Can't set antd.import while using antd5 (${antdVersion})`;
157
+ api.logger.fatal(
158
+ "please change config antd.import to false, then start server again"
159
+ );
160
+ throw Error(errorMessage);
161
+ }
162
+ }
163
+ if (isV4) {
164
+ if (antd.dark || antd.compact) {
165
+ const { getThemeVariables } = require("antd/dist/theme");
166
+ memo.theme = {
167
+ ...getThemeVariables(antd),
168
+ ...memo.theme
169
+ };
170
+ }
171
+ memo.theme = {
172
+ "root-entry-name": "default",
173
+ ...memo.theme
174
+ };
134
175
  }
135
- // babel-plugin-import
136
- api.addExtraBabelPlugins(() => {
137
- return [
138
- [
139
- require.resolve('babel-plugin-import'),
140
- {
141
- libraryName: 'antd',
142
- libraryDirectory: 'es',
143
- style: true,
144
- },
145
- ],
146
- ];
176
+ if (antd.theme) {
177
+ (0, import_assert.default)(isV5, `antd.theme is only valid when antd is 5`);
178
+ antd.configProvider ?? (antd.configProvider = {});
179
+ antd.configProvider.theme = (0, import_plugin_utils.deepmerge)(
180
+ antd.configProvider.theme || {},
181
+ antd.theme
182
+ );
183
+ (0, import_assert.default)(
184
+ !antd.configProvider.theme.algorithm,
185
+ `The 'algorithm' option only available for runtime config, please move it to the runtime plugin, see: https://umijs.org/docs/max/antd#运行时配置`
186
+ );
187
+ }
188
+ if (antd.appConfig) {
189
+ if (!appComponentAvailable) {
190
+ delete antd.appConfig;
191
+ api.logger.warn(
192
+ `antd.appConfig is only available in version 5.1.0 and above, but you are using version ${antdVersion}`
193
+ );
194
+ } else if (!appConfigAvailable && Object.keys(antd.appConfig).length > 0) {
195
+ api.logger.warn(
196
+ `versions [5.1.0 ~ 5.3.0) only allows antd.appConfig to be set to \`{}\``
197
+ );
198
+ }
199
+ }
200
+ if (antd.dark || antd.compact) {
201
+ antd.configProvider ?? (antd.configProvider = {});
202
+ }
203
+ return memo;
204
+ });
205
+ api.chainWebpack((memo) => {
206
+ if (api.config.antd.momentPicker) {
207
+ if (day2MomentAvailable) {
208
+ memo.plugin("antd-moment-webpack-plugin").use(import_moment_webpack_plugin.default);
209
+ } else {
210
+ api.logger.warn(
211
+ `MomentPicker is only available in version 5.0.0 and above, but you are using version ${antdVersion}`
212
+ );
213
+ }
214
+ }
215
+ return memo;
216
+ });
217
+ api.addExtraBabelPlugins(() => {
218
+ const style = api.config.antd.style || "less";
219
+ if (api.config.antd.import && !api.appData.vite) {
220
+ return [
221
+ [
222
+ require.resolve("babel-plugin-import"),
223
+ {
224
+ libraryName: "antd",
225
+ libraryDirectory: "es",
226
+ ...isV5 ? {} : { style: style === "less" || "css" }
227
+ },
228
+ "antd"
229
+ ]
230
+ ];
231
+ }
232
+ return [];
233
+ });
234
+ const lodashPkg = (0, import_path.dirname)(require.resolve("lodash/package.json"));
235
+ const lodashPath = {
236
+ merge: (0, import_plugin_utils.winPath)((0, import_path.join)(lodashPkg, "merge"))
237
+ };
238
+ api.onGenerateFiles(() => {
239
+ var _a;
240
+ const withConfigProvider = !!api.config.antd.configProvider;
241
+ const withAppConfig = appConfigAvailable && !!api.config.antd.appConfig;
242
+ const styleProvider = api.config.antd.styleProvider;
243
+ const userInputCompact = api.config.antd.compact;
244
+ const userInputDark = api.config.antd.dark;
245
+ const ieTarget = !!((_a = api.config.targets) == null ? void 0 : _a.ie) || !!api.config.legacy;
246
+ let styleProviderConfig = false;
247
+ if (isV5 && (ieTarget || styleProvider)) {
248
+ const cssinjs = (0, import_resolveProjectDep.resolveProjectDep)({
249
+ pkg: api.pkg,
250
+ cwd: api.cwd,
251
+ dep: "@ant-design/cssinjs"
252
+ }) || (0, import_path.dirname)(require.resolve("@ant-design/cssinjs/package.json"));
253
+ if (cssinjs) {
254
+ styleProviderConfig = {
255
+ cssinjs: (0, import_plugin_utils.winPath)(cssinjs)
256
+ };
257
+ if (ieTarget) {
258
+ styleProviderConfig.hashPriority = "high";
259
+ styleProviderConfig.legacyTransformer = true;
260
+ }
261
+ styleProviderConfig = {
262
+ ...styleProviderConfig,
263
+ ...styleProvider
264
+ };
265
+ }
266
+ }
267
+ const configProvider = withConfigProvider && JSON.stringify(api.config.antd.configProvider);
268
+ const appConfig = appComponentAvailable && JSON.stringify(api.config.antd.appConfig);
269
+ const enableV5ThemeAlgorithm = isV5 && (userInputCompact || userInputDark) ? { compact: userInputCompact, dark: userInputDark } : false;
270
+ const hasConfigProvider = configProvider || enableV5ThemeAlgorithm;
271
+ const antdConfigSetter = isV5 && hasConfigProvider;
272
+ api.writeTmpFile({
273
+ path: `runtime.tsx`,
274
+ context: {
275
+ configProvider,
276
+ appConfig,
277
+ styleProvider: styleProviderConfig,
278
+ // 是否启用了 v5 的 theme algorithm
279
+ enableV5ThemeAlgorithm,
280
+ antdConfigSetter,
281
+ lodashPath,
282
+ /**
283
+ * 是否重构了全局静态配置。 重构后需要在运行时将全局静态配置传入到 ConfigProvider 中。
284
+ * 实际上 4.13.0 重构后有一个 bug,真正的 warn 出现在 4.13.1,并且 4.13.1 修复了这个 bug。
285
+ * Resolve issue: https://github.com/umijs/umi/issues/10231
286
+ * `InternalStatic` 指 `Modal.config` 等静态方法,详见:https://github.com/ant-design/ant-design/pull/29285
287
+ */
288
+ disableInternalStatic: import_plugin_utils.semver.gt(antdVersion, "4.13.0")
289
+ },
290
+ tplPath: (0, import_plugin_utils.winPath)((0, import_path.join)(ANTD_TEMPLATES_DIR, "runtime.ts.tpl"))
147
291
  });
148
- // antd config provider
149
- // TODO: use umi provider
150
- if (opts === null || opts === void 0 ? void 0 : opts.config) {
151
- api.onGenerateFiles({
152
- fn() {
153
- // runtime.tsx
154
- const runtimeTpl = (0, fs_1.readFileSync)((0, path_1.join)(__dirname, '../templates/antd/runtime.tpl'), 'utf-8');
155
- api.writeTmpFile({
156
- path: `${DIR_NAME}/runtime.tsx`,
157
- content: utils_1.Mustache.render(runtimeTpl, {
158
- config: JSON.stringify(opts === null || opts === void 0 ? void 0 : opts.config),
159
- }),
160
- });
161
- },
162
- });
163
- //TODO:Runtime Plugin
164
- api.addRuntimePlugin(() => [
165
- (0, path_1.join)(api.paths.absTmpPath, DIR_NAME, 'runtime.tsx'),
166
- ]);
292
+ api.writeTmpFile({
293
+ path: "types.d.ts",
294
+ context: {
295
+ withConfigProvider,
296
+ withAppConfig
297
+ },
298
+ tplPath: (0, import_plugin_utils.winPath)((0, import_path.join)(ANTD_TEMPLATES_DIR, "types.d.ts.tpl"))
299
+ });
300
+ api.writeTmpFile({
301
+ path: import_umi.RUNTIME_TYPE_FILE_NAME,
302
+ content: `
303
+ import type { RuntimeAntdConfig } from './types.d';
304
+ export type IRuntimeConfig = {
305
+ antd?: RuntimeAntdConfig
306
+ };
307
+ `
308
+ });
309
+ if (antdConfigSetter) {
310
+ api.writeTmpFile({
311
+ path: "index.tsx",
312
+ content: `import React from 'react';
313
+ import { AntdConfigContext, AntdConfigContextSetter } from './context';
314
+
315
+ export function useAntdConfig() {
316
+ return React.useContext(AntdConfigContext);
317
+ }
318
+
319
+ export function useAntdConfigSetter() {
320
+ return React.useContext(AntdConfigContextSetter);
321
+ }`
322
+ });
323
+ api.writeTmpFile({
324
+ path: "context.tsx",
325
+ content: `import React from 'react';
326
+ import type { ConfigProviderProps } from 'antd/es/config-provider';
327
+
328
+ export const AntdConfigContext = React.createContext<ConfigProviderProps>(null!);
329
+ export const AntdConfigContextSetter = React.createContext<React.Dispatch<React.SetStateAction<ConfigProviderProps>>>(
330
+ () => {
331
+ console.error(\`The 'useAntdConfigSetter()' method depends on the antd 'ConfigProvider', requires one of 'antd.configProvider' / 'antd.dark' / 'antd.compact' to be enabled.\`);
332
+ }
333
+ );
334
+ `
335
+ });
336
+ }
337
+ });
338
+ api.addRuntimePlugin(() => {
339
+ if (api.config.antd.styleProvider || api.config.antd.configProvider || appComponentAvailable && api.config.antd.appConfig) {
340
+ return [(0, import_withTmpPath.withTmpPath)({ api, path: "runtime.tsx" })];
341
+ }
342
+ return [];
343
+ });
344
+ api.addEntryImportsAhead(() => {
345
+ const style = api.config.antd.style || "less";
346
+ const imports = [];
347
+ if (isV5) {
348
+ imports.push({ source: "antd/dist/reset.css" });
349
+ } else if (!api.config.antd.import || api.appData.vite) {
350
+ imports.push({
351
+ source: style === "less" ? "antd/dist/antd.less" : "antd/dist/antd.css"
352
+ });
167
353
  }
354
+ return imports;
355
+ });
168
356
  };
@@ -1,3 +1,3 @@
1
+ import { IApi } from 'umi';
1
2
  declare const _default: (api: IApi) => void;
2
3
  export default _default;
3
- //# sourceMappingURL=icons.d.ts.map
@@ -0,0 +1,64 @@
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/confetti.ts
20
+ var confetti_exports = {};
21
+ __export(confetti_exports, {
22
+ default: () => confetti_default
23
+ });
24
+ module.exports = __toCommonJS(confetti_exports);
25
+ var import_plugin_utils = require("umi/plugin-utils");
26
+ var handleConfetti = () => {
27
+ const confettiShell = `
28
+ open raycast://confetti;
29
+ exit;
30
+ `;
31
+ const confetti = (0, import_plugin_utils.crossSpawn)(confettiShell, [], {
32
+ stdio: "pipe",
33
+ shell: true
34
+ });
35
+ confetti.on("error", (err) => {
36
+ const errStr = "[confetti] " + err;
37
+ import_plugin_utils.logger.error(errStr);
38
+ });
39
+ confetti.stderr && confetti.stderr.on("data", () => {
40
+ const err = `[confetti] 未安装 Raycast , 请安装后尝试 https://www.raycast.com`;
41
+ import_plugin_utils.logger.error(err);
42
+ });
43
+ };
44
+ var confetti_default = (api) => {
45
+ api.describe({
46
+ key: "confetti",
47
+ config: {
48
+ schema({ zod }) {
49
+ return zod.object({});
50
+ }
51
+ },
52
+ enableBy: api.EnableBy.config
53
+ });
54
+ api.onBuildComplete(({ err }) => {
55
+ if (!err) {
56
+ handleConfetti();
57
+ }
58
+ });
59
+ api.onDevCompileDone(({ isFirstCompile }) => {
60
+ if (isFirstCompile) {
61
+ handleConfetti();
62
+ }
63
+ });
64
+ };
@@ -0,0 +1 @@
1
+ export declare const TEMPLATES_DIR: string;
@@ -0,0 +1,30 @@
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/constants.ts
20
+ var constants_exports = {};
21
+ __export(constants_exports, {
22
+ TEMPLATES_DIR: () => TEMPLATES_DIR
23
+ });
24
+ module.exports = __toCommonJS(constants_exports);
25
+ var import_path = require("path");
26
+ var TEMPLATES_DIR = (0, import_path.join)(__dirname, "../templates");
27
+ // Annotate the CommonJS export names for ESM import in node:
28
+ 0 && (module.exports = {
29
+ TEMPLATES_DIR
30
+ });
package/dist/dva.d.ts CHANGED
@@ -1,3 +1,6 @@
1
+ import { IApi } from 'umi';
2
+ import { Model, ModelUtils } from './utils/modelUtils';
1
3
  declare const _default: (api: IApi) => void;
2
4
  export default _default;
3
- //# sourceMappingURL=dva.d.ts.map
5
+ export declare function getModelUtil(api: IApi | null): ModelUtils;
6
+ export declare function getAllModels(api: IApi): Model[];