@umijs/plugins 4.0.88 → 4.0.90

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/dist/antd.js CHANGED
@@ -61,22 +61,61 @@ var antd_default = (api) => {
61
61
  api.describe({
62
62
  config: {
63
63
  schema({ zod }) {
64
- return zod.object({
65
- configProvider: zod.record(zod.any()),
66
- // themes
64
+ const commonSchema = {
67
65
  dark: zod.boolean(),
68
66
  compact: zod.boolean(),
69
67
  // babel-plugin-import
70
68
  import: zod.boolean(),
71
69
  // less or css, default less
72
- style: zod.enum(["less", "css"]).describe("less or css, default less"),
73
- theme: zod.record(zod.any()),
74
- // Only antd@5.1.0 is supported
75
- appConfig: zod.record(zod.any()).describe("Only antd@5.1.0 is supported"),
76
- // DatePicker & Calendar use moment version
77
- momentPicker: zod.boolean().describe("Only antd@5.x is supported"),
78
- styleProvider: zod.record(zod.any())
79
- }).deepPartial();
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();
86
+ },
87
+ {
88
+ message: "theme.components.[componentName] needs to be in PascalCase, e.g. theme.components.Button"
89
+ }
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();
114
+ }
115
+ if (isV4) {
116
+ return createV4Schema();
117
+ }
118
+ return zod.object({});
80
119
  }
81
120
  },
82
121
  enableBy({ userConfig }) {
@@ -158,6 +197,9 @@ var antd_default = (api) => {
158
197
  );
159
198
  }
160
199
  }
200
+ if (antd.dark || antd.compact) {
201
+ antd.configProvider ?? (antd.configProvider = {});
202
+ }
161
203
  return memo;
162
204
  });
163
205
  api.chainWebpack((memo) => {
@@ -189,6 +231,10 @@ var antd_default = (api) => {
189
231
  }
190
232
  return [];
191
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
+ };
192
238
  api.onGenerateFiles(() => {
193
239
  var _a;
194
240
  const withConfigProvider = !!api.config.antd.configProvider;
@@ -218,14 +264,21 @@ var antd_default = (api) => {
218
264
  };
219
265
  }
220
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;
221
272
  api.writeTmpFile({
222
273
  path: `runtime.tsx`,
223
274
  context: {
224
- configProvider: withConfigProvider && JSON.stringify(api.config.antd.configProvider),
225
- appConfig: appComponentAvailable && JSON.stringify(api.config.antd.appConfig),
275
+ configProvider,
276
+ appConfig,
226
277
  styleProvider: styleProviderConfig,
227
278
  // 是否启用了 v5 的 theme algorithm
228
- enableV5ThemeAlgorithm: isV5 && (userInputCompact || userInputDark) ? { compact: userInputCompact, dark: userInputDark } : false,
279
+ enableV5ThemeAlgorithm,
280
+ antdConfigSetter,
281
+ lodashPath,
229
282
  /**
230
283
  * 是否重构了全局静态配置。 重构后需要在运行时将全局静态配置传入到 ConfigProvider 中。
231
284
  * 实际上 4.13.0 重构后有一个 bug,真正的 warn 出现在 4.13.1,并且 4.13.1 修复了这个 bug。
@@ -253,6 +306,34 @@ export type IRuntimeConfig = {
253
306
  };
254
307
  `
255
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
+ }
256
337
  });
257
338
  api.addRuntimePlugin(() => {
258
339
  if (api.config.antd.styleProvider || api.config.antd.configProvider || appComponentAvailable && api.config.antd.appConfig) {
@@ -87,6 +87,7 @@ var react_query_default = (api) => {
87
87
  api.writeTmpFile({
88
88
  path: "runtime.tsx",
89
89
  content: enableQueryClient ? `
90
+ import React from 'react';
90
91
  import { defaultContext, QueryClient, QueryClientProvider } from '${pkgPath}';
91
92
  import { ReactQueryDevtools } from '${devtoolPkgPath}';
92
93
  ${reactQueryRuntimeCode}
@@ -34,6 +34,7 @@ __export(styled_components_exports, {
34
34
  module.exports = __toCommonJS(styled_components_exports);
35
35
  var import_utils = require("@umijs/utils");
36
36
  var import_path = require("path");
37
+ var import_resolveProjectDep = require("./utils/resolveProjectDep");
37
38
  var import_withTmpPath = require("./utils/withTmpPath");
38
39
  var styled_components_default = (api) => {
39
40
  api.describe({
@@ -49,6 +50,9 @@ var styled_components_default = (api) => {
49
50
  });
50
51
  api.modifyConfig((memo) => {
51
52
  var _a, _b;
53
+ if (api.userConfig.mako || process.env.OKAM) {
54
+ return memo;
55
+ }
52
56
  const isProd = api.env === "production";
53
57
  const pluginConfig = {
54
58
  // https://github.com/styled-components/babel-plugin-styled-components/blob/f8e9fb480d1645be8be797d73e49686bdf98975b/src/utils/options.js#L11
@@ -77,7 +81,20 @@ var styled_components_default = (api) => {
77
81
  api.addRuntimePluginKey(() => {
78
82
  return ["styledComponents"];
79
83
  });
80
- const libPath = (0, import_path.dirname)(require.resolve("styled-components/package"));
84
+ const SC_NAME = `styled-components`;
85
+ let libPath;
86
+ try {
87
+ libPath = (0, import_resolveProjectDep.resolveProjectDep)({
88
+ pkg: api.pkg,
89
+ cwd: api.cwd,
90
+ dep: SC_NAME
91
+ }) || (0, import_path.dirname)(require.resolve(`${SC_NAME}/package.json`));
92
+ } catch (e) {
93
+ }
94
+ api.modifyConfig((memo) => {
95
+ memo.alias[SC_NAME] = libPath;
96
+ return memo;
97
+ });
81
98
  api.onGenerateFiles(() => {
82
99
  var _a, _b, _c;
83
100
  api.writeTmpFile({
@@ -103,6 +120,7 @@ export { styled, ThemeProvider, createGlobalStyle, css, keyframes, StyleSheetMan
103
120
  api.writeTmpFile({
104
121
  path: "runtime.tsx",
105
122
  content: `
123
+ import React from 'react';
106
124
  ${hasProvider ? `import { StyleSheetManager } from '${(0, import_utils.winPath)(libPath)}';` : ``}
107
125
 
108
126
  ${styledComponentsRuntimeCode}
@@ -109,7 +109,7 @@ export async function render(oldRender: typeof noop) {
109
109
  microAppRuntimeRoutes = routes;
110
110
 
111
111
  // 主应用相关的配置注册完毕后即可开启渲染
112
- oldRender();
112
+ const renderData = oldRender();
113
113
 
114
114
  // 未使用 base 配置的可以认为是路由关联或者使用标签装载的应用
115
115
  const loadableApps = apps.filter((app) => !app.base);
@@ -133,6 +133,8 @@ export async function render(oldRender: typeof noop) {
133
133
  '[plugins/qiankun] 检测到还在使用旧版配置,该配置已移除,请尽快升级到最新配置方式以获得更好的开发体验,详见 https://umijs.org/plugins/plugin-qiankun#%E5%8D%87%E7%BA%A7%E6%8C%87%E5%8D%97',
134
134
  );
135
135
  }
136
+
137
+ return renderData;
136
138
  }
137
139
 
138
140
  export function patchClientRoutes({ routes }: { routes: any[] }) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@umijs/plugins",
3
- "version": "4.0.88",
3
+ "version": "4.0.90",
4
4
  "description": "@umijs/plugins",
5
5
  "homepage": "https://github.com/umijs/umi/tree/master/packages/plugins#readme",
6
6
  "bugs": "https://github.com/umijs/umi/issues",
@@ -42,15 +42,15 @@
42
42
  "react-intl": "3.12.1",
43
43
  "react-redux": "^8.0.5",
44
44
  "redux": "^4.2.1",
45
- "styled-components": "6.1.0",
45
+ "styled-components": "6.1.1",
46
46
  "tslib": "^2",
47
47
  "warning": "^4.0.3",
48
- "@umijs/bundler-utils": "4.0.88",
48
+ "@umijs/bundler-utils": "4.0.90",
49
49
  "@umijs/valtio": "1.0.4"
50
50
  },
51
51
  "devDependencies": {
52
52
  "antd": "^4.24.1",
53
- "umi": "4.0.88"
53
+ "umi": "4.0.90"
54
54
  },
55
55
  "publishConfig": {
56
56
  "access": "public"
@@ -23,6 +23,10 @@ import {
23
23
  } from '{{{styleProvider.cssinjs}}}';
24
24
  {{/styleProvider}}
25
25
  import { getPluginManager } from '../core/plugin';
26
+ {{#antdConfigSetter}}
27
+ import { AntdConfigContext, AntdConfigContextSetter } from './context';
28
+ import merge from '{{{lodashPath.merge}}}'
29
+ {{/antdConfigSetter}}
26
30
 
27
31
  let cacheAntdConfig = null;
28
32
 
@@ -44,73 +48,80 @@ const getAntdConfig = () => {
44
48
  return cacheAntdConfig;
45
49
  }
46
50
 
47
- export function rootContainer(rawContainer) {
48
- const {
49
- appConfig,
50
- ...finalConfigProvider
51
- } = getAntdConfig();
52
- let container = rawContainer;
51
+ function AntdProvider({ children }) {
52
+ let container = children;
53
+
54
+ const [antdConfig, _setAntdConfig] = React.useState(() => {
55
+ const {
56
+ appConfig: _,
57
+ ...finalConfigProvider
58
+ } = getAntdConfig();
59
+ {{#enableV5ThemeAlgorithm}}
60
+ finalConfigProvider.theme ??= {};
61
+ finalConfigProvider.theme.algorithm ??= [];
62
+ if (!Array.isArray(finalConfigProvider.theme.algorithm)) {
63
+ finalConfigProvider.theme.algorithm = [finalConfigProvider.theme.algorithm];
64
+ }
65
+ const algorithm = finalConfigProvider.theme.algorithm;
66
+ {{#enableV5ThemeAlgorithm.compact}}
67
+ if (!algorithm.includes(theme.compactAlgorithm)) {
68
+ algorithm.push(theme.compactAlgorithm);
69
+ }
70
+ {{/enableV5ThemeAlgorithm.compact}}
71
+ {{#enableV5ThemeAlgorithm.dark}}
72
+ if (!algorithm.includes(theme.darkAlgorithm)) {
73
+ algorithm.push(theme.darkAlgorithm);
74
+ }
75
+ {{/enableV5ThemeAlgorithm.dark}}
76
+ {{/enableV5ThemeAlgorithm}}
77
+ return finalConfigProvider
78
+ });
79
+ const setAntdConfig: typeof _setAntdConfig = (newConfig) => {
80
+ _setAntdConfig(prev => {
81
+ return merge({}, prev, typeof newConfig === 'function' ? newConfig(prev) : newConfig)
82
+ })
83
+ }
53
84
 
54
85
  {{#configProvider}}
55
86
  {{^disableInternalStatic}}
56
- if (finalConfigProvider.prefixCls) {
87
+ if (antdConfig.prefixCls) {
57
88
  Modal.config({
58
- rootPrefixCls: finalConfigProvider.prefixCls
89
+ rootPrefixCls: antdConfig.prefixCls
59
90
  });
60
91
  message.config({
61
- prefixCls: `${finalConfigProvider.prefixCls}-message`
92
+ prefixCls: `${antdConfig.prefixCls}-message`
62
93
  });
63
94
  notification.config({
64
- prefixCls: `${finalConfigProvider.prefixCls}-notification`
95
+ prefixCls: `${antdConfig.prefixCls}-notification`
65
96
  });
66
97
  }
67
98
  {{/disableInternalStatic}}
68
99
 
69
100
  {{#disableInternalStatic}}
70
- if (finalConfigProvider.prefixCls) {
101
+ if (antdConfig.prefixCls) {
71
102
  ConfigProvider.config({
72
- prefixCls: finalConfigProvider.prefixCls,
103
+ prefixCls: antdConfig.prefixCls,
73
104
  });
74
105
  };
75
106
  {{/disableInternalStatic}}
76
107
 
77
- if (finalConfigProvider.iconPrefixCls) {
108
+ if (antdConfig.iconPrefixCls) {
78
109
  // Icons in message need to set iconPrefixCls via ConfigProvider.config()
79
110
  ConfigProvider.config({
80
- iconPrefixCls: finalConfigProvider.iconPrefixCls,
111
+ iconPrefixCls: antdConfig.iconPrefixCls,
81
112
  });
82
113
  };
83
114
 
84
- if (finalConfigProvider.theme) {
115
+ if (antdConfig.theme) {
85
116
  // Pass config theme to static method
86
117
  ConfigProvider.config({
87
- theme: finalConfigProvider.theme,
118
+ theme: antdConfig.theme,
88
119
  });
89
120
  }
90
121
 
91
- container = <ConfigProvider {...finalConfigProvider}>{container}</ConfigProvider>;
122
+ container = <ConfigProvider {...antdConfig}>{container}</ConfigProvider>;
92
123
  {{/configProvider}}
93
124
 
94
- {{#enableV5ThemeAlgorithm}}
95
- // Add token algorithm for antd5 only
96
- container = (
97
- <ConfigProvider
98
- theme={({
99
- algorithm: [
100
- {{#enableV5ThemeAlgorithm.compact}}
101
- theme.compactAlgorithm,
102
- {{/enableV5ThemeAlgorithm.compact}}
103
- {{#enableV5ThemeAlgorithm.dark}}
104
- theme.darkAlgorithm,
105
- {{/enableV5ThemeAlgorithm.dark}}
106
- ],
107
- })}
108
- >
109
- {container}
110
- </ConfigProvider>
111
- );
112
- {{/enableV5ThemeAlgorithm}}
113
-
114
125
  {{#styleProvider}}
115
126
  container = (
116
127
  <StyleProvider
@@ -126,9 +137,27 @@ export function rootContainer(rawContainer) {
126
137
  );
127
138
  {{/styleProvider}}
128
139
 
140
+ {{#antdConfigSetter}}
141
+ container = (
142
+ <AntdConfigContextSetter.Provider value={setAntdConfig}>
143
+ <AntdConfigContext.Provider value={antdConfig}>
144
+ {container}
145
+ </AntdConfigContext.Provider>
146
+ </AntdConfigContextSetter.Provider>
147
+ )
148
+ {{/antdConfigSetter}}
149
+
129
150
  return container;
130
151
  }
131
152
 
153
+ export function rootContainer(children) {
154
+ return (
155
+ <AntdProvider>
156
+ {children}
157
+ </AntdProvider>
158
+ );
159
+ }
160
+
132
161
  {{#appConfig}}
133
162
  // The App component should be under ConfigProvider
134
163
  // plugin-locale has other ConfigProvider