@umijs/plugins 4.6.0 → 4.6.2

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
@@ -53,8 +53,13 @@ var antd_default = (api) => {
53
53
  antdVersion = require(`${pkgPath}/package.json`).version;
54
54
  } catch (e) {
55
55
  }
56
- const isV5 = antdVersion.startsWith("5");
57
- const isV4 = antdVersion.startsWith("4");
56
+ const isModern = import_plugin_utils.semver.satisfies(
57
+ antdVersion,
58
+ "^5.0.0 || ^6.0.0",
59
+ // 两者都还在维护周期中,允许使用预发布版本. eg. 6.1.0-alpha.0
60
+ { includePrerelease: true }
61
+ );
62
+ const isLegacy = import_plugin_utils.semver.satisfies(antdVersion, "^4.0.0");
58
63
  const appComponentAvailable = import_plugin_utils.semver.gte(antdVersion, "5.1.0");
59
64
  const appConfigAvailable = import_plugin_utils.semver.gte(antdVersion, "5.3.0");
60
65
  const day2MomentAvailable = import_plugin_utils.semver.gte(antdVersion, "5.0.0");
@@ -78,7 +83,7 @@ var antd_default = (api) => {
78
83
  })
79
84
  ]);
80
85
  };
81
- const createV5Schema = () => {
86
+ const createModernSchema = () => {
82
87
  const componentNameSchema = zod.string().refine(
83
88
  (value) => {
84
89
  const firstLetter = value.slice(0, 1);
@@ -103,17 +108,17 @@ var antd_default = (api) => {
103
108
  configProvider
104
109
  }).deepPartial();
105
110
  };
106
- const createV4Schema = () => {
111
+ const createLegacySchema = () => {
107
112
  return zod.object({
108
113
  ...commonSchema,
109
114
  configProvider: zod.record(zod.any())
110
115
  }).deepPartial();
111
116
  };
112
- if (isV5) {
113
- return createV5Schema();
117
+ if (isModern) {
118
+ return createModernSchema();
114
119
  }
115
- if (isV4) {
116
- return createV4Schema();
120
+ if (isLegacy) {
121
+ return createLegacySchema();
117
122
  }
118
123
  return zod.object({});
119
124
  }
@@ -128,6 +133,16 @@ var antd_default = (api) => {
128
133
  throw new Error(`Can't find antd package. Please install antd first.`);
129
134
  }
130
135
  }
136
+ api.onCheck(() => {
137
+ if (import_plugin_utils.semver.gte(antdVersion, "6.0.0")) {
138
+ const reactVersion = api.appData.react.version;
139
+ if (import_plugin_utils.semver.lt(reactVersion, "18.0.0")) {
140
+ throw new Error(
141
+ `antd@6 requires React version >= 18.0.0, but got ${reactVersion}.`
142
+ );
143
+ }
144
+ }
145
+ });
131
146
  api.modifyAppData((memo) => {
132
147
  checkPkgPath();
133
148
  const version = require(`${pkgPath}/package.json`).version;
@@ -146,21 +161,23 @@ var antd_default = (api) => {
146
161
  memo.antd = antd = Object.assign(defaultConfig, antd);
147
162
  }
148
163
  memo.alias.antd = pkgPath;
149
- if (isV5) {
164
+ if (isModern) {
150
165
  const theme = require("@ant-design/antd-theme-variable");
151
166
  memo.theme = {
152
167
  ...theme,
153
168
  ...memo.theme
154
169
  };
170
+ }
171
+ if (import_plugin_utils.semver.gte(antdVersion, "5.0.0")) {
155
172
  if ((_a = memo.antd) == null ? void 0 : _a.import) {
156
- const errorMessage = `Can't set antd.import while using antd5 (${antdVersion})`;
173
+ const errorMessage = `The antd.import option is not supported in antd version 5 and above (${antdVersion}).`;
157
174
  api.logger.fatal(
158
175
  "please change config antd.import to false, then start server again"
159
176
  );
160
177
  throw Error(errorMessage);
161
178
  }
162
179
  }
163
- if (isV4) {
180
+ if (isLegacy) {
164
181
  if (antd.dark || antd.compact) {
165
182
  const { getThemeVariables } = require("antd/dist/theme");
166
183
  memo.theme = {
@@ -174,7 +191,10 @@ var antd_default = (api) => {
174
191
  };
175
192
  }
176
193
  if (antd.theme) {
177
- (0, import_assert.default)(isV5, `antd.theme is only valid when antd is 5`);
194
+ (0, import_assert.default)(
195
+ isModern,
196
+ `The 'antd.theme' option is only available for antd version 5 and above.`
197
+ );
178
198
  antd.configProvider ?? (antd.configProvider = {});
179
199
  antd.configProvider.theme = (0, import_plugin_utils.deepmerge)(
180
200
  antd.configProvider.theme || {},
@@ -223,7 +243,7 @@ var antd_default = (api) => {
223
243
  {
224
244
  libraryName: "antd",
225
245
  libraryDirectory: "es",
226
- ...isV5 ? {} : { style: style === "less" || "css" }
246
+ style: style === "less" || "css"
227
247
  },
228
248
  "antd"
229
249
  ]
@@ -244,7 +264,7 @@ var antd_default = (api) => {
244
264
  const userInputDark = api.config.antd.dark;
245
265
  const ieTarget = !!((_a = api.config.targets) == null ? void 0 : _a.ie) || !!api.config.legacy;
246
266
  let styleProviderConfig = false;
247
- if (isV5 && (ieTarget || styleProvider)) {
267
+ if (isModern && (ieTarget || styleProvider)) {
248
268
  const cssinjs = (0, import_resolveProjectDep.resolveProjectDep)({
249
269
  pkg: api.pkg,
250
270
  cwd: api.cwd,
@@ -255,8 +275,14 @@ var antd_default = (api) => {
255
275
  cssinjs: (0, import_plugin_utils.winPath)(cssinjs)
256
276
  };
257
277
  if (ieTarget) {
258
- styleProviderConfig.hashPriority = "high";
259
- styleProviderConfig.legacyTransformer = true;
278
+ if (import_plugin_utils.semver.gte(antdVersion, "6.0.0")) {
279
+ api.logger.warn(
280
+ `You are using antd version ${antdVersion} which no longer supports IE, but your targets or legacy config indicates IE support. Please adjust your targets or legacy config accordingly.`
281
+ );
282
+ } else {
283
+ styleProviderConfig.hashPriority = "high";
284
+ styleProviderConfig.legacyTransformer = true;
285
+ }
260
286
  }
261
287
  styleProviderConfig = {
262
288
  ...styleProviderConfig,
@@ -266,9 +292,9 @@ var antd_default = (api) => {
266
292
  }
267
293
  const configProvider = withConfigProvider && JSON.stringify(api.config.antd.configProvider);
268
294
  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;
295
+ const enableModernThemeAlgorithm = isModern && (userInputCompact || userInputDark) ? { compact: userInputCompact, dark: userInputDark } : false;
296
+ const hasConfigProvider = configProvider || enableModernThemeAlgorithm;
297
+ const antdConfigSetter = isModern && hasConfigProvider;
272
298
  const isModelPluginEnabled = api.isPluginEnable("model");
273
299
  const modelPluginCompat = isModelPluginEnabled && antdConfigSetter;
274
300
  api.writeTmpFile({
@@ -277,8 +303,8 @@ var antd_default = (api) => {
277
303
  configProvider,
278
304
  appConfig,
279
305
  styleProvider: styleProviderConfig,
280
- // 是否启用了 v5 的 theme algorithm
281
- enableV5ThemeAlgorithm,
306
+ // 是否启用了 theme algorithm
307
+ enableModernThemeAlgorithm,
282
308
  antdConfigSetter,
283
309
  modelPluginCompat,
284
310
  lodashPath,
@@ -347,7 +373,7 @@ export const AntdConfigContextSetter = React.createContext<React.Dispatch<React.
347
373
  api.addEntryImportsAhead(() => {
348
374
  const style = api.config.antd.style || "less";
349
375
  const imports = [];
350
- if (isV5) {
376
+ if (isModern) {
351
377
  imports.push({ source: "antd/dist/reset.css" });
352
378
  } else if (!api.config.antd.import || api.appData.vite) {
353
379
  imports.push({
package/dist/dva.js CHANGED
@@ -266,7 +266,8 @@ export interface DvaModel<T, E = EffectsMapObject, R = ReducersMapObject<T>> {
266
266
  function getModelUtil(api) {
267
267
  return new import_modelUtils.ModelUtils(api, {
268
268
  contentTest(content) {
269
- if (api == null ? void 0 : api.config.dva.skipModelValidate) return true;
269
+ if (api == null ? void 0 : api.config.dva.skipModelValidate)
270
+ return true;
270
271
  return content.startsWith("// @dva-model");
271
272
  },
272
273
  astTest({ node, content }) {
package/dist/layout.js CHANGED
@@ -66,8 +66,13 @@ var layout_default = (api) => {
66
66
  } catch (e) {
67
67
  }
68
68
  const packageName = api.pkg.name || "plugin-layout";
69
- const isAntd5 = antdVersion.startsWith("5");
70
- const layoutFile = isAntd5 ? "Layout.css" : "Layout.less";
69
+ const isModern = import_plugin_utils.semver.satisfies(
70
+ antdVersion,
71
+ "^5.0.0 || ^6.0.0",
72
+ // 两者都还在维护周期中,允许使用预发布版本. eg. 6.1.0-alpha.0
73
+ { includePrerelease: true }
74
+ );
75
+ const layoutFile = isModern ? "Layout.css" : "Layout.less";
71
76
  api.describe({
72
77
  key: "layout",
73
78
  config: {
@@ -547,8 +552,8 @@ export function getRightRenderContent (opts: {
547
552
  api.writeTmpFile({
548
553
  path: layoutFile,
549
554
  content: `
550
- ${// antd@5里面没有这个样式了
551
- isAntd5 ? "" : "@import '~antd/es/style/themes/default.less';"}
555
+ ${// antd@5、@6 里面没有这个样式了
556
+ isModern ? "" : "@import '~antd/es/style/themes/default.less';"}
552
557
  @media screen and (max-width: 480px) {
553
558
  /* 在小屏幕的时候可以有更好的体验 */
554
559
  .umi-plugin-layout-container {
package/dist/mf.js CHANGED
@@ -141,14 +141,14 @@ function mf(api) {
141
141
  (0, import_path.join)(api.paths.absTmpPath, "umi.ts"),
142
142
  "utf-8"
143
143
  );
144
- const [_imports, exports2] = await (0, import_bundler_utils.parseModule)({ content, path: entry });
144
+ const [_imports, exports] = await (0, import_bundler_utils.parseModule)({ content, path: entry });
145
145
  const mfEntryContent = [];
146
146
  let hasDefaultExport = false;
147
- if (exports2.length) {
147
+ if (exports.length) {
148
148
  mfEntryContent.push(
149
149
  `const umiExports = await import('${(0, import_plugin_utils.winPath)(entry)}')`
150
150
  );
151
- for (const exportName of exports2) {
151
+ for (const exportName of exports) {
152
152
  if (exportName === "default") {
153
153
  hasDefaultExport = true;
154
154
  mfEntryContent.push(`export default umiExports.${exportName}`);
@@ -101,8 +101,8 @@ var master_default = (api) => {
101
101
  api.register({
102
102
  key: "addExtraModels",
103
103
  fn() {
104
- const { path, exports: exports2 } = api.appData.appJS || {};
105
- return path && exports2.includes(import_constants.MODEL_EXPORT_NAME) ? [
104
+ const { path, exports } = api.appData.appJS || {};
105
+ return path && exports.includes(import_constants.MODEL_EXPORT_NAME) ? [
106
106
  `${path}#{"namespace":"${import_constants.qiankunStateForSlaveModelNamespace}","exportName":"${import_constants.MODEL_EXPORT_NAME}"}`
107
107
  ] : [];
108
108
  }
package/dist/request.js CHANGED
@@ -326,7 +326,8 @@ export type {
326
326
  );
327
327
  const axiosPath = (0, import_plugin_utils.winPath)((0, import_path.dirname)(require.resolve("axios/package.json")));
328
328
  let dataField = (_a = api.config.request) == null ? void 0 : _a.dataField;
329
- if (dataField === void 0) dataField = "data";
329
+ if (dataField === void 0)
330
+ dataField = "data";
330
331
  const isEmpty = dataField === "";
331
332
  const formatResult = isEmpty ? `result => result` : `result => result?.${dataField}`;
332
333
  const resultDataType = isEmpty ? dataField : `${dataField}?: T;`;
package/dist/unocss.js CHANGED
@@ -40,7 +40,8 @@ var unocss_default = (api) => {
40
40
  });
41
41
  const outputPath = "uno.css";
42
42
  api.onBeforeCompiler(async () => {
43
- if (process.env.IS_UMI_BUILD_WORKER) return;
43
+ if (process.env.IS_UMI_BUILD_WORKER)
44
+ return;
44
45
  if (!(0, import_fs.existsSync)((0, import_path.join)(api.paths.cwd, "unocss.config.ts")))
45
46
  api.logger.warn(
46
47
  "请在项目目录中添加 unocss.config.ts 文件,并配置需要的 unocss presets,否则插件将没有效果!"
@@ -66,11 +66,6 @@ function getNamespace(absFilePath, absSrcPath) {
66
66
  return [...validDirs, normalizedFile].join(".");
67
67
  }
68
68
  var Model = class {
69
- file;
70
- namespace;
71
- id;
72
- exportName;
73
- deps;
74
69
  constructor(file, absSrcPath, sort, id) {
75
70
  let namespace;
76
71
  let exportName;
@@ -111,11 +106,10 @@ var Model = class {
111
106
  return [...deps];
112
107
  }
113
108
  };
114
- var ModelUtils = class _ModelUtils {
115
- api;
116
- opts = {};
117
- count = 1;
109
+ var _ModelUtils = class {
118
110
  constructor(api, opts) {
111
+ this.opts = {};
112
+ this.count = 1;
119
113
  this.api = api;
120
114
  this.opts = opts;
121
115
  }
@@ -162,8 +156,10 @@ var ModelUtils = class _ModelUtils {
162
156
  cwd: opts.base,
163
157
  absolute: true
164
158
  }).map(import_plugin_utils.winPath).filter((file) => {
165
- if (/\.d.ts$/.test(file)) return false;
166
- if (/\.(test|e2e|spec).([jt])sx?$/.test(file)) return false;
159
+ if (/\.d.ts$/.test(file))
160
+ return false;
161
+ if (/\.(test|e2e|spec).([jt])sx?$/.test(file))
162
+ return false;
167
163
  const content = (0, import_fs.readFileSync)(file, "utf-8");
168
164
  return this.isModelValid({ content, file });
169
165
  });
@@ -208,57 +204,6 @@ var ModelUtils = class _ModelUtils {
208
204
  });
209
205
  return ret;
210
206
  }
211
- // https://github.com/umijs/umi/issues/9837
212
- static topologicalSort = (models) => {
213
- const graph = [];
214
- const namespaceToNode = {};
215
- models.forEach((model, index) => {
216
- const node = {
217
- namespace: model.namespace,
218
- deps: model.deps,
219
- index,
220
- in: 0,
221
- childs: []
222
- };
223
- if (namespaceToNode[model.namespace]) {
224
- throw new Error(`Duplicate namespace in models: ${model.namespace}`);
225
- }
226
- namespaceToNode[model.namespace] = node;
227
- graph.push(node);
228
- });
229
- graph.forEach((node) => {
230
- node.deps.forEach((dep) => {
231
- const depNode = namespaceToNode[dep];
232
- if (!depNode) {
233
- throw new Error(`Model namespace not found: ${dep}`);
234
- }
235
- depNode.childs.push(node);
236
- node.in++;
237
- });
238
- });
239
- const queue = [];
240
- while (true) {
241
- const zeronode = graph.find((n) => {
242
- return n && n.in === 0;
243
- });
244
- if (!zeronode) {
245
- break;
246
- }
247
- queue.push(zeronode.namespace);
248
- zeronode.childs.forEach((child) => {
249
- child.in--;
250
- });
251
- zeronode.childs = [];
252
- delete graph[zeronode.index];
253
- }
254
- const leftNodes = graph.filter(Boolean);
255
- if (leftNodes.length > 0) {
256
- throw new Error(
257
- `Circle dependency detected in models: ${leftNodes.map((m) => import_plugin_utils.chalk.red(m.namespace)).join(", ")}`
258
- );
259
- }
260
- return queue;
261
- };
262
207
  static getModelsContent(models) {
263
208
  const imports = [];
264
209
  const modelProps = [];
@@ -288,6 +233,58 @@ ${modelProps.join("\n")}
288
233
  } as const`;
289
234
  }
290
235
  };
236
+ var ModelUtils = _ModelUtils;
237
+ // https://github.com/umijs/umi/issues/9837
238
+ ModelUtils.topologicalSort = (models) => {
239
+ const graph = [];
240
+ const namespaceToNode = {};
241
+ models.forEach((model, index) => {
242
+ const node = {
243
+ namespace: model.namespace,
244
+ deps: model.deps,
245
+ index,
246
+ in: 0,
247
+ childs: []
248
+ };
249
+ if (namespaceToNode[model.namespace]) {
250
+ throw new Error(`Duplicate namespace in models: ${model.namespace}`);
251
+ }
252
+ namespaceToNode[model.namespace] = node;
253
+ graph.push(node);
254
+ });
255
+ graph.forEach((node) => {
256
+ node.deps.forEach((dep) => {
257
+ const depNode = namespaceToNode[dep];
258
+ if (!depNode) {
259
+ throw new Error(`Model namespace not found: ${dep}`);
260
+ }
261
+ depNode.childs.push(node);
262
+ node.in++;
263
+ });
264
+ });
265
+ const queue = [];
266
+ while (true) {
267
+ const zeronode = graph.find((n) => {
268
+ return n && n.in === 0;
269
+ });
270
+ if (!zeronode) {
271
+ break;
272
+ }
273
+ queue.push(zeronode.namespace);
274
+ zeronode.childs.forEach((child) => {
275
+ child.in--;
276
+ });
277
+ zeronode.childs = [];
278
+ delete graph[zeronode.index];
279
+ }
280
+ const leftNodes = graph.filter(Boolean);
281
+ if (leftNodes.length > 0) {
282
+ throw new Error(
283
+ `Circle dependency detected in models: ${leftNodes.map((m) => import_plugin_utils.chalk.red(m.namespace)).join(", ")}`
284
+ );
285
+ }
286
+ return queue;
287
+ };
291
288
  // Annotate the CommonJS export names for ESM import in node:
292
289
  0 && (module.exports = {
293
290
  Model,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@umijs/plugins",
3
- "version": "4.6.0",
3
+ "version": "4.6.2",
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",
@@ -45,12 +45,12 @@
45
45
  "styled-components": "6.1.1",
46
46
  "tslib": "^2",
47
47
  "warning": "^4.0.3",
48
- "@umijs/bundler-utils": "4.6.0",
48
+ "@umijs/bundler-utils": "4.6.2",
49
49
  "@umijs/valtio": "1.0.4"
50
50
  },
51
51
  "devDependencies": {
52
52
  "antd": "^4.24.1",
53
- "umi": "4.6.0"
53
+ "umi": "4.6.2"
54
54
  },
55
55
  "publishConfig": {
56
56
  "access": "public"
@@ -9,9 +9,9 @@ import {
9
9
  message,
10
10
  notification,
11
11
  {{/disableInternalStatic}}
12
- {{#enableV5ThemeAlgorithm}}
12
+ {{#enableModernThemeAlgorithm}}
13
13
  theme,
14
- {{/enableV5ThemeAlgorithm}}
14
+ {{/enableModernThemeAlgorithm}}
15
15
  } from 'antd';
16
16
  import { ApplyPluginsType } from 'umi';
17
17
  {{#styleProvider}}
@@ -61,24 +61,24 @@ function AntdProvider({ children }) {
61
61
  appConfig: _,
62
62
  ...finalConfigProvider
63
63
  } = getAntdConfig();
64
- {{#enableV5ThemeAlgorithm}}
64
+ {{#enableModernThemeAlgorithm}}
65
65
  finalConfigProvider.theme ??= {};
66
66
  finalConfigProvider.theme.algorithm ??= [];
67
67
  if (!Array.isArray(finalConfigProvider.theme.algorithm)) {
68
68
  finalConfigProvider.theme.algorithm = [finalConfigProvider.theme.algorithm];
69
69
  }
70
70
  const algorithm = finalConfigProvider.theme.algorithm;
71
- {{#enableV5ThemeAlgorithm.compact}}
71
+ {{#enableModernThemeAlgorithm.compact}}
72
72
  if (!algorithm.includes(theme.compactAlgorithm)) {
73
73
  algorithm.push(theme.compactAlgorithm);
74
74
  }
75
- {{/enableV5ThemeAlgorithm.compact}}
76
- {{#enableV5ThemeAlgorithm.dark}}
75
+ {{/enableModernThemeAlgorithm.compact}}
76
+ {{#enableModernThemeAlgorithm.dark}}
77
77
  if (!algorithm.includes(theme.darkAlgorithm)) {
78
78
  algorithm.push(theme.darkAlgorithm);
79
79
  }
80
- {{/enableV5ThemeAlgorithm.dark}}
81
- {{/enableV5ThemeAlgorithm}}
80
+ {{/enableModernThemeAlgorithm.dark}}
81
+ {{/enableModernThemeAlgorithm}}
82
82
  return finalConfigProvider
83
83
  });
84
84
  const setAntdConfig: typeof _setAntdConfig = (newConfig) => {