@umijs/preset-umi 4.0.86 → 4.0.87

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 (79) hide show
  1. package/dist/commands/build.js +1 -2
  2. package/dist/commands/config/config.js +0 -2
  3. package/dist/commands/deadcode.js +0 -2
  4. package/dist/commands/dev/depBuildWorker/depBuilder.js +2 -2
  5. package/dist/commands/dev/depBuildWorker/dev-config.js +0 -2
  6. package/dist/commands/dev/depBuildWorker/workerPreset.js +0 -2
  7. package/dist/commands/dev/dev.js +1 -2
  8. package/dist/commands/dev/plugins/ViteHtmlPlugin.js +0 -2
  9. package/dist/commands/generators/cypress.js +0 -2
  10. package/dist/commands/generators/dva.js +0 -2
  11. package/dist/commands/generators/jest.js +0 -2
  12. package/dist/commands/generators/mock.js +0 -2
  13. package/dist/commands/generators/precommit.js +0 -2
  14. package/dist/commands/generators/prettier.js +0 -2
  15. package/dist/commands/generators/tailwindcss.js +0 -2
  16. package/dist/commands/generators/tsconfig.js +0 -2
  17. package/dist/commands/help.js +0 -2
  18. package/dist/commands/lint.js +0 -2
  19. package/dist/commands/mfsu/mfsu.js +0 -2
  20. package/dist/commands/plugin.js +0 -2
  21. package/dist/commands/preview.js +0 -2
  22. package/dist/commands/setup.js +0 -2
  23. package/dist/commands/verify-commit.js +0 -2
  24. package/dist/commands/version.js +0 -2
  25. package/dist/features/__sample.js +0 -2
  26. package/dist/features/apiRoute/apiRoute.js +0 -2
  27. package/dist/features/apiRoute/dev-server/esbuild.js +0 -2
  28. package/dist/features/apiRoute/response.js +0 -2
  29. package/dist/features/apiRoute/vercel/esbuild.js +0 -2
  30. package/dist/features/appData/appData.js +0 -2
  31. package/dist/features/appData/umiInfo.js +0 -2
  32. package/dist/features/check/babel722.js +0 -2
  33. package/dist/features/check/check.js +0 -2
  34. package/dist/features/classPropertiesLoose/classPropertiesLoose.js +0 -2
  35. package/dist/features/clickToComponent/clickToComponent.js +0 -2
  36. package/dist/features/clientLoader/clientLoader.js +0 -2
  37. package/dist/features/codeSplitting/codeSplitting.js +0 -2
  38. package/dist/features/crossorigin/crossorigin.js +0 -2
  39. package/dist/features/esmi/Service.js +2 -4
  40. package/dist/features/esmi/esbuildPlugins/requireToImport.js +0 -2
  41. package/dist/features/esmi/esbuildPlugins/topLevelExternal.js +0 -2
  42. package/dist/features/esmi/esmi.js +0 -2
  43. package/dist/features/favicons/favicons.js +0 -2
  44. package/dist/features/helmet/helmet.js +0 -2
  45. package/dist/features/hmrGuardian/hmrGuardian.js +0 -2
  46. package/dist/features/icons/icons.js +0 -2
  47. package/dist/features/legacy/legacy.js +0 -2
  48. package/dist/features/lowImport/babelPlugin.js +0 -2
  49. package/dist/features/lowImport/lowImport.js +0 -2
  50. package/dist/features/mock/mock.js +0 -2
  51. package/dist/features/mpa/mpa.js +2 -4
  52. package/dist/features/overrides/compileLess.d.ts +1 -0
  53. package/dist/features/overrides/compileLess.js +52 -0
  54. package/dist/features/overrides/compileLess.manullytest.d.ts +1 -0
  55. package/dist/features/overrides/compileLess.manullytest.js +62 -0
  56. package/dist/features/overrides/overrides.js +36 -25
  57. package/dist/features/overrides/transform.d.ts +1 -0
  58. package/dist/features/overrides/transform.js +86 -0
  59. package/dist/features/phantomDependency/phantomDependency.js +0 -2
  60. package/dist/features/polyfill/polyfill.js +0 -2
  61. package/dist/features/polyfill/publicPathPolyfill.js +0 -2
  62. package/dist/features/prepare/prepare.js +0 -2
  63. package/dist/features/routePrefetch/routePrefetch.js +0 -2
  64. package/dist/features/routeProps/routeProps.js +0 -2
  65. package/dist/features/ssr/builder/builder.js +2 -2
  66. package/dist/features/ssr/builder/svg-loader.js +0 -2
  67. package/dist/features/swc/swc.js +0 -2
  68. package/dist/features/terminal/terminal.js +0 -2
  69. package/dist/features/test/test.js +0 -2
  70. package/dist/features/tmpFiles/configTypes.js +0 -2
  71. package/dist/features/tmpFiles/tmpFiles.js +1 -6
  72. package/dist/features/transform/CodeFrameError.js +0 -2
  73. package/dist/features/transform/babelPlugin.js +0 -2
  74. package/dist/features/transform/transform.js +0 -2
  75. package/dist/features/ui/ui.js +0 -2
  76. package/dist/features/vite/vite.js +0 -2
  77. package/dist/features/webpack/webpack.js +0 -2
  78. package/dist/registerMethods.js +0 -2
  79. package/package.json +16 -14
@@ -131,6 +131,7 @@ umi build --clean
131
131
  if (api.config.vite) {
132
132
  stats = await bundlerVite.build(opts);
133
133
  } else if (process.env.OKAM) {
134
+ require("@umijs/bundler-webpack/dist/requireHook");
134
135
  const { build } = require(process.env.OKAM);
135
136
  stats = await build(opts);
136
137
  } else {
@@ -192,5 +193,3 @@ umi build --clean
192
193
  }
193
194
  });
194
195
  };
195
- // Annotate the CommonJS export names for ESM import in node:
196
- 0 && (module.exports = {});
@@ -71,5 +71,3 @@ $ umi config r history
71
71
  }
72
72
  });
73
73
  };
74
- // Annotate the CommonJS export names for ESM import in node:
75
- 0 && (module.exports = {});
@@ -223,5 +223,3 @@ var deadcode_default = (api) => {
223
223
  }
224
224
  });
225
225
  };
226
- // Annotate the CommonJS export names for ESM import in node:
227
- 0 && (module.exports = {});
@@ -85,7 +85,7 @@ var DepBuilderInWorker = class {
85
85
  const tmpDir = this.opts.tmpBase;
86
86
  const entryPath = (0, import_path.join)(tmpDir, ENTRY_FILE);
87
87
  (0, import_fs.writeFileSync)(entryPath, entryContent, "utf-8");
88
- const date = new Date().getTime();
88
+ const date = (/* @__PURE__ */ new Date()).getTime();
89
89
  await (0, import_bundler_esbuild.build)({
90
90
  cwd: this.opts.cwd,
91
91
  entry: {
@@ -100,7 +100,7 @@ var DepBuilderInWorker = class {
100
100
  inlineStyle: true
101
101
  });
102
102
  import_utils.logger.event(
103
- `[mfsu] compiled with esbuild successfully in ${+new Date() - date} ms`
103
+ `[mfsu] compiled with esbuild successfully in ${+/* @__PURE__ */ new Date() - date} ms`
104
104
  );
105
105
  opts.onBuildComplete();
106
106
  }
@@ -104,5 +104,3 @@ var dev_config_default = (api) => {
104
104
  }
105
105
  });
106
106
  };
107
- // Annotate the CommonJS export names for ESM import in node:
108
- 0 && (module.exports = {});
@@ -37,5 +37,3 @@ var workerPreset_default = () => {
37
37
  plugins: [require.resolve("./dev-config")]
38
38
  };
39
39
  };
40
- // Annotate the CommonJS export names for ESM import in node:
41
- 0 && (module.exports = {});
@@ -380,6 +380,7 @@ PORT=8888 umi dev
380
380
  if (enableVite) {
381
381
  await bundlerVite.dev(opts);
382
382
  } else if (process.env.OKAM) {
383
+ require("@umijs/bundler-webpack/dist/requireHook");
383
384
  const { dev } = require(process.env.OKAM);
384
385
  await dev(opts);
385
386
  } else {
@@ -415,5 +416,3 @@ PORT=8888 umi dev
415
416
  return viteConfig;
416
417
  });
417
418
  };
418
- // Annotate the CommonJS export names for ESM import in node:
419
- 0 && (module.exports = {});
@@ -59,5 +59,3 @@ function ViteHtmlPlugin(api) {
59
59
  }
60
60
  };
61
61
  }
62
- // Annotate the CommonJS export names for ESM import in node:
63
- 0 && (module.exports = {});
@@ -82,5 +82,3 @@ export default defineConfig({
82
82
  });
83
83
  };
84
84
  var CYPRESS_TPL_FOLDER = (0, import_path.join)(import_constants.TEMPLATES_DIR, "generate/cypress");
85
- // Annotate the CommonJS export names for ESM import in node:
86
- 0 && (module.exports = {});
@@ -77,5 +77,3 @@ export default {
77
77
  }
78
78
  });
79
79
  };
80
- // Annotate the CommonJS export names for ESM import in node:
81
- 0 && (module.exports = {});
@@ -148,5 +148,3 @@ function getJestVersion() {
148
148
  return 29;
149
149
  }
150
150
  }
151
- // Annotate the CommonJS export names for ESM import in node:
152
- 0 && (module.exports = {});
@@ -53,5 +53,3 @@ var mock_default = (api) => {
53
53
  }
54
54
  });
55
55
  };
56
- // Annotate the CommonJS export names for ESM import in node:
57
- 0 && (module.exports = {});
@@ -109,5 +109,3 @@ npx --no-install lint-staged --quiet
109
109
  }
110
110
  });
111
111
  };
112
- // Annotate the CommonJS export names for ESM import in node:
113
- 0 && (module.exports = {});
@@ -74,5 +74,3 @@ node_modules
74
74
  }
75
75
  });
76
76
  };
77
- // Annotate the CommonJS export names for ESM import in node:
78
- 0 && (module.exports = {});
@@ -76,5 +76,3 @@ module.exports = {
76
76
  }
77
77
  });
78
78
  };
79
- // Annotate the CommonJS export names for ESM import in node:
80
- 0 && (module.exports = {});
@@ -74,5 +74,3 @@ var tsconfig_default = (api) => {
74
74
  }
75
75
  });
76
76
  };
77
- // Annotate the CommonJS export names for ESM import in node:
78
- 0 && (module.exports = {});
@@ -84,5 +84,3 @@ ${getDeps(commands)}
84
84
  return str.trim().split("\n").map((line) => ` ${line}`).join("\n");
85
85
  }
86
86
  };
87
- // Annotate the CommonJS export names for ESM import in node:
88
- 0 && (module.exports = {});
@@ -73,5 +73,3 @@ umi lint --quiet
73
73
  }
74
74
  });
75
75
  };
76
- // Annotate the CommonJS export names for ESM import in node:
77
- 0 && (module.exports = {});
@@ -109,5 +109,3 @@ var mfsu_default = (api) => {
109
109
  function printHelpInfo(api) {
110
110
  console.log(HELP_TEXT.replace(/umi/g, api.appData.umi.cliName));
111
111
  }
112
- // Annotate the CommonJS export names for ESM import in node:
113
- 0 && (module.exports = {});
@@ -64,5 +64,3 @@ Did you mean:
64
64
  }
65
65
  });
66
66
  };
67
- // Annotate the CommonJS export names for ESM import in node:
68
- 0 && (module.exports = {});
@@ -125,5 +125,3 @@ umi preview --port [port]
125
125
  }
126
126
  });
127
127
  };
128
- // Annotate the CommonJS export names for ESM import in node:
129
- 0 && (module.exports = {});
@@ -40,5 +40,3 @@ var setup_default = (api) => {
40
40
  }
41
41
  });
42
42
  };
43
- // Annotate the CommonJS export names for ESM import in node:
44
- 0 && (module.exports = {});
@@ -109,5 +109,3 @@ var verify_commit_default = (api) => {
109
109
  function removeComment(msg) {
110
110
  return msg.replace(/^#.*[\n\r]*/gm, "");
111
111
  }
112
- // Annotate the CommonJS export names for ESM import in node:
113
- 0 && (module.exports = {});
@@ -37,5 +37,3 @@ var version_default = (api) => {
37
37
  }
38
38
  });
39
39
  };
40
- // Annotate the CommonJS export names for ESM import in node:
41
- 0 && (module.exports = {});
@@ -25,5 +25,3 @@ module.exports = __toCommonJS(sample_exports);
25
25
  var sample_default = (api) => {
26
26
  api;
27
27
  };
28
- // Annotate the CommonJS export names for ESM import in node:
29
- 0 && (module.exports = {});
@@ -220,5 +220,3 @@ var apiRoute_default = (api) => {
220
220
  }
221
221
  });
222
222
  };
223
- // Annotate the CommonJS export names for ESM import in node:
224
- 0 && (module.exports = {});
@@ -67,5 +67,3 @@ async function esbuild_default(api, apiRoutes) {
67
67
  });
68
68
  await ctx.watch();
69
69
  }
70
- // Annotate the CommonJS export names for ESM import in node:
71
- 0 && (module.exports = {});
@@ -59,5 +59,3 @@ var UmiApiResponse = class {
59
59
  }
60
60
  };
61
61
  var response_default = UmiApiResponse;
62
- // Annotate the CommonJS export names for ESM import in node:
63
- 0 && (module.exports = {});
@@ -54,5 +54,3 @@ async function esbuild_default(api, apiRoutes) {
54
54
  external: [...Object.keys(pkg.dependencies || {})]
55
55
  });
56
56
  }
57
- // Annotate the CommonJS export names for ESM import in node:
58
- 0 && (module.exports = {});
@@ -215,5 +215,3 @@ function tryLoadDepPkg(opts) {
215
215
  } catch {
216
216
  }
217
217
  }
218
- // Annotate the CommonJS export names for ESM import in node:
219
- 0 && (module.exports = {});
@@ -31,5 +31,3 @@ window.g_umi = {
31
31
  `
32
32
  ]);
33
33
  };
34
- // Annotate the CommonJS export names for ESM import in node:
35
- 0 && (module.exports = {});
@@ -81,5 +81,3 @@ var babel722_default = (api) => {
81
81
  }
82
82
  });
83
83
  };
84
- // Annotate the CommonJS export names for ESM import in node:
85
- 0 && (module.exports = {});
@@ -107,5 +107,3 @@ ${import_utils.chalk.red(
107
107
  return path.startsWith("/") || path.startsWith("@fs/");
108
108
  }
109
109
  };
110
- // Annotate the CommonJS export names for ESM import in node:
111
- 0 && (module.exports = {});
@@ -39,5 +39,3 @@ var classPropertiesLoose_default = (api) => {
39
39
  return memo;
40
40
  });
41
41
  };
42
- // Annotate the CommonJS export names for ESM import in node:
43
- 0 && (module.exports = {});
@@ -90,5 +90,3 @@ return React.createElement(
90
90
  (0, import_utils.winPath)((0, import_path.join)(api.paths.absTmpPath, "plugin-clickToComponent/runtime.tsx"))
91
91
  ]);
92
92
  };
93
- // Annotate the CommonJS export names for ESM import in node:
94
- 0 && (module.exports = {});
@@ -41,5 +41,3 @@ var clientLoader_default = (api) => {
41
41
  propertyName: "clientLoader"
42
42
  });
43
43
  };
44
- // Annotate the CommonJS export names for ESM import in node:
45
- 0 && (module.exports = {});
@@ -167,5 +167,3 @@ function isModuleCSS(module2) {
167
167
  module2.type === `css/extract-css-chunks`
168
168
  );
169
169
  }
170
- // Annotate the CommonJS export names for ESM import in node:
171
- 0 && (module.exports = {});
@@ -63,5 +63,3 @@ var crossorigin_default = (api) => {
63
63
  stage: Infinity
64
64
  });
65
65
  };
66
- // Annotate the CommonJS export names for ESM import in node:
67
- 0 && (module.exports = {});
@@ -104,7 +104,7 @@ var ESMIService = class {
104
104
  async getImportmap(data) {
105
105
  const cacheKey = ESMIService.getCacheKey(data);
106
106
  const cache = this.getCache(cacheKey);
107
- const stamp = +new Date();
107
+ const stamp = +/* @__PURE__ */ new Date();
108
108
  if (cache) {
109
109
  import_utils.logger.info("ESMi cache used");
110
110
  return cache;
@@ -125,7 +125,7 @@ var ESMIService = class {
125
125
  if (res.data.success) {
126
126
  this.setCache(cacheKey, res.data.data);
127
127
  import_utils.logger.info(
128
- `Done, took ${((+new Date() - stamp) / 1e3).toFixed(1)}s`
128
+ `Done, took ${((+/* @__PURE__ */ new Date() - stamp) / 1e3).toFixed(1)}s`
129
129
  );
130
130
  return res.data.data;
131
131
  }
@@ -135,5 +135,3 @@ var ESMIService = class {
135
135
  return deferrer();
136
136
  }
137
137
  };
138
- // Annotate the CommonJS export names for ESM import in node:
139
- 0 && (module.exports = {});
@@ -76,5 +76,3 @@ function requireToImportPlugin({
76
76
  }
77
77
  };
78
78
  }
79
- // Annotate the CommonJS export names for ESM import in node:
80
- 0 && (module.exports = {});
@@ -48,5 +48,3 @@ function topLevelExternal({
48
48
  }
49
49
  };
50
50
  }
51
- // Annotate the CommonJS export names for ESM import in node:
52
- 0 && (module.exports = {});
@@ -223,5 +223,3 @@ var esmi_default = (api) => {
223
223
  } else {
224
224
  }
225
225
  };
226
- // Annotate the CommonJS export names for ESM import in node:
227
- 0 && (module.exports = {});
@@ -85,5 +85,3 @@ var favicons_default = (api) => {
85
85
  return memo;
86
86
  });
87
87
  };
88
- // Annotate the CommonJS export names for ESM import in node:
89
- 0 && (module.exports = {});
@@ -66,5 +66,3 @@ export const innerProvider = (container) => {
66
66
  () => api.appData.framework === "react" ? ["@@/core/helmet.ts"] : []
67
67
  );
68
68
  };
69
- // Annotate the CommonJS export names for ESM import in node:
70
- 0 && (module.exports = {});
@@ -54,5 +54,3 @@ function hmrGuardian_default(api) {
54
54
  return [(0, import_babelPlugin.defaultRenameVisitor)()];
55
55
  });
56
56
  }
57
- // Annotate the CommonJS export names for ESM import in node:
58
- 0 && (module.exports = {});
@@ -450,5 +450,3 @@ function readIconsFromDir(dir) {
450
450
  collect(dir);
451
451
  return icons;
452
452
  }
453
- // Annotate the CommonJS export names for ESM import in node:
454
- 0 && (module.exports = {});
@@ -187,5 +187,3 @@ function useBabelTransformSvgr(memo, api) {
187
187
  ]
188
188
  }).before("svgr-loader").end();
189
189
  }
190
- // Annotate the CommonJS export names for ESM import in node:
191
- 0 && (module.exports = {});
@@ -173,5 +173,3 @@ function babelPlugin_default() {
173
173
  }
174
174
  };
175
175
  }
176
- // Annotate the CommonJS export names for ESM import in node:
177
- 0 && (module.exports = {});
@@ -171,5 +171,3 @@ function normalizeLibs(libs) {
171
171
  namespaceToLib
172
172
  };
173
173
  }
174
- // Annotate the CommonJS export names for ESM import in node:
175
- 0 && (module.exports = {});
@@ -93,5 +93,3 @@ function mock_default(api) {
93
93
  ];
94
94
  });
95
95
  }
96
- // Annotate the CommonJS export names for ESM import in node:
97
- 0 && (module.exports = {});
@@ -131,10 +131,10 @@ ${renderer}
131
131
  });
132
132
  };
133
133
  async function collectEntryWithTimeCount(root, opts, mountElementId) {
134
- const d = new Date();
134
+ const d = /* @__PURE__ */ new Date();
135
135
  const entries = await collectEntry(root, opts, mountElementId);
136
136
  import_utils.logger.info(
137
- `[MPA] Collect Entries in ${new Date().getTime() - d.getTime()}ms`
137
+ `[MPA] Collect Entries in ${(/* @__PURE__ */ new Date()).getTime() - d.getTime()}ms`
138
138
  );
139
139
  return entries;
140
140
  }
@@ -226,5 +226,3 @@ function checkConfig(config) {
226
226
  (0, import_assert.default)(Array.isArray(config.scripts), "scripts must be string");
227
227
  }
228
228
  }
229
- // Annotate the CommonJS export names for ESM import in node:
230
- 0 && (module.exports = {});
@@ -0,0 +1 @@
1
+ export declare function compileLess(lessContent: string, filePath: string, modifyVars?: Record<string, string>, alias?: Record<string, string>): Promise<string>;
@@ -0,0 +1,52 @@
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 });
10
+ };
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;
18
+ };
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/features/overrides/compileLess.ts
30
+ var compileLess_exports = {};
31
+ __export(compileLess_exports, {
32
+ compileLess: () => compileLess
33
+ });
34
+ module.exports = __toCommonJS(compileLess_exports);
35
+ var import_less = __toESM(require("@umijs/bundler-utils/compiled/less"));
36
+ async function compileLess(lessContent, filePath, modifyVars = {}, alias = {}) {
37
+ const result = await import_less.default.render(lessContent, {
38
+ filename: filePath,
39
+ plugins: [
40
+ new (require("less-plugin-resolve"))({
41
+ aliases: alias
42
+ })
43
+ ],
44
+ javascriptEnabled: true,
45
+ modifyVars
46
+ });
47
+ return result.css;
48
+ }
49
+ // Annotate the CommonJS export names for ESM import in node:
50
+ 0 && (module.exports = {
51
+ compileLess
52
+ });
@@ -0,0 +1,62 @@
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 __copyProps = (to, from, except, desc) => {
8
+ if (from && typeof from === "object" || typeof from === "function") {
9
+ for (let key of __getOwnPropNames(from))
10
+ if (!__hasOwnProp.call(to, key) && key !== except)
11
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
12
+ }
13
+ return to;
14
+ };
15
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
16
+ // If the importer is in node compatibility mode or this is not an ESM
17
+ // file that has been converted to a CommonJS file using a Babel-
18
+ // compatible transform (i.e. "__esModule" has not been set), then set
19
+ // "default" to the CommonJS "module.exports" for node compatibility.
20
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
21
+ mod
22
+ ));
23
+
24
+ // src/features/overrides/compileLess.manullytest.ts
25
+ var import_assert = __toESM(require("assert"));
26
+ var import_fs = __toESM(require("fs"));
27
+ var import_path = require("path");
28
+ var import_compileLess = require("./compileLess");
29
+ var fixturesDir = (0, import_path.join)(__dirname, "../../../fixtures");
30
+ (async () => {
31
+ const filePath = (0, import_path.join)(fixturesDir, "overrides/less/index.less");
32
+ const modifyVars = {
33
+ "primary-color": "#1DA57A"
34
+ };
35
+ const alias = {
36
+ barbar: (0, import_path.join)(filePath, "../node_modules/bar")
37
+ };
38
+ const result = await (0, import_compileLess.compileLess)(
39
+ import_fs.default.readFileSync(filePath, "utf-8"),
40
+ filePath,
41
+ modifyVars,
42
+ alias
43
+ );
44
+ (0, import_assert.default)(
45
+ result.includes(
46
+ `
47
+ .bar {
48
+ color: red;
49
+ }
50
+ .foo {
51
+ color: red;
52
+ }
53
+ .a {
54
+ aaa: green;
55
+ bbb: #1DA57A;
56
+ }
57
+ `.trim()
58
+ )
59
+ );
60
+ })().catch((e) => {
61
+ console.error(e);
62
+ });
@@ -23,39 +23,50 @@ __export(overrides_exports, {
23
23
  getOverridesCSS: () => getOverridesCSS
24
24
  });
25
25
  module.exports = __toCommonJS(overrides_exports);
26
- var import_utils = require("@umijs/utils");
27
26
  var import_fs = require("fs");
28
27
  var import_path = require("path");
29
28
  var import_watch = require("../../commands/dev/watch");
29
+ var import_compileLess = require("./compileLess");
30
+ var import_transform = require("./transform");
30
31
  function getOverridesCSS(absSrcPath) {
31
32
  return (0, import_watch.expandCSSPaths)((0, import_path.join)(absSrcPath, "overrides")).find(import_fs.existsSync);
32
33
  }
33
34
  var overrides_default = (api) => {
34
- api.modifyConfig((memo) => {
35
- if (getOverridesCSS(api.paths.absSrcPath)) {
36
- memo.extraPostCSSPlugins ?? (memo.extraPostCSSPlugins = []);
37
- memo.extraPostCSSPlugins.push(
38
- // prefix #root for overrides.{ext} style file, to make sure selector priority is higher than async chunk style
39
- require("postcss-prefix-selector")({
40
- // why not #root?
41
- // antd will insert dom into body, prefix #root will not works for that
42
- prefix: "body",
43
- transform(_p, selector, prefixedSelector, filePath) {
44
- const isOverridesFile = (0, import_utils.winPath)(api.appData.overridesCSS[0]) === (0, import_utils.winPath)(filePath);
45
- if (isOverridesFile) {
46
- if (selector === "html") {
47
- return `html:first-child`;
48
- } else if (/^body([\s+~>[:]|$)/.test(selector)) {
49
- return `html ${selector}`;
50
- }
51
- return prefixedSelector;
52
- }
53
- return selector;
54
- }
55
- })
56
- );
35
+ let cachedContent = null;
36
+ api.onGenerateFiles(async () => {
37
+ var _a;
38
+ if (api.appData.overridesCSS.length) {
39
+ const filePath = api.appData.overridesCSS[0];
40
+ let content = (0, import_fs.readFileSync)(filePath, "utf-8");
41
+ if (content === cachedContent)
42
+ return;
43
+ const isLess = filePath.endsWith(".less");
44
+ if (isLess) {
45
+ content = await (0, import_compileLess.compileLess)(
46
+ content,
47
+ filePath,
48
+ {
49
+ ...api.config.theme,
50
+ ...(_a = api.config.lessLoader) == null ? void 0 : _a.modifyVars
51
+ },
52
+ api.config.alias
53
+ );
54
+ }
55
+ content = await (0, import_transform.transform)(content, filePath);
56
+ api.writeTmpFile({
57
+ path: "core/overrides.css",
58
+ content,
59
+ noPluginDir: true
60
+ });
61
+ cachedContent = content;
57
62
  }
58
- return memo;
63
+ });
64
+ api.addEntryImports(() => {
65
+ return [
66
+ api.appData.overridesCSS.length && {
67
+ source: "@@/core/overrides.css"
68
+ }
69
+ ].filter(Boolean);
59
70
  });
60
71
  };
61
72
  // Annotate the CommonJS export names for ESM import in node:
@@ -0,0 +1 @@
1
+ export declare function transform(cssContent: string, filePath: string): Promise<any>;
@@ -0,0 +1,86 @@
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 });
10
+ };
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;
18
+ };
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/features/overrides/transform.ts
30
+ var transform_exports = {};
31
+ __export(transform_exports, {
32
+ transform: () => transform
33
+ });
34
+ module.exports = __toCommonJS(transform_exports);
35
+ var import_utils = require("@umijs/utils");
36
+ var import_fs = __toESM(require("fs"));
37
+ var import_path = __toESM(require("path"));
38
+ async function transform(cssContent, filePath) {
39
+ const importPlugin = {
40
+ postcssPlugin: "importPlugin",
41
+ AtRule: {
42
+ import(atRule) {
43
+ let origin = atRule.params;
44
+ origin = origin.replace(/^url\((.+)\)$/g, "$1");
45
+ origin = origin.replace(/^'(.+)'$/g, "$1").replace(/^"(.+)"$/g, "$1");
46
+ if (origin.startsWith("~"))
47
+ return;
48
+ if (origin.startsWith("/"))
49
+ return;
50
+ function getResolvedPath(origin2) {
51
+ return (0, import_utils.winPath)(import_path.default.resolve(import_path.default.dirname(filePath), origin2));
52
+ }
53
+ const resolvedPath = getResolvedPath(origin);
54
+ if (import_fs.default.existsSync(resolvedPath)) {
55
+ atRule.params = `"${resolvedPath}"`;
56
+ } else {
57
+ if (origin.startsWith("./") || origin.startsWith("../")) {
58
+ console.warn(`File does not exist: ${resolvedPath}`);
59
+ }
60
+ }
61
+ }
62
+ }
63
+ };
64
+ const selectorPlugin = require("postcss-prefix-selector")({
65
+ // why not #root?
66
+ // antd will insert dom into body, prefix #root will not work for that
67
+ prefix: "body",
68
+ transform(_p, selector, prefixedSelector) {
69
+ if (selector === "html") {
70
+ return `html:first-child`;
71
+ } else if (/^body([\s+~>[:]|$)/.test(selector)) {
72
+ return `html ${selector}`;
73
+ }
74
+ return prefixedSelector;
75
+ }
76
+ });
77
+ const result = await require("postcss")([
78
+ selectorPlugin,
79
+ importPlugin
80
+ ]).process(cssContent, {});
81
+ return result.css;
82
+ }
83
+ // Annotate the CommonJS export names for ESM import in node:
84
+ 0 && (module.exports = {
85
+ transform
86
+ });
@@ -146,5 +146,3 @@ var phantomDependency_default = (api) => {
146
146
  return false;
147
147
  }
148
148
  };
149
- // Annotate the CommonJS export names for ESM import in node:
150
- 0 && (module.exports = {});
@@ -112,5 +112,3 @@ export {};
112
112
  }).join("\n");
113
113
  }
114
114
  };
115
- // Annotate the CommonJS export names for ESM import in node:
116
- 0 && (module.exports = {});
@@ -42,5 +42,3 @@ var publicPathPolyfill_default = (api) => {
42
42
  ] : [];
43
43
  });
44
44
  };
45
- // Annotate the CommonJS export names for ESM import in node:
46
- 0 && (module.exports = {});
@@ -142,5 +142,3 @@ var prepare_default = (api) => {
142
142
  stage: Infinity
143
143
  });
144
144
  };
145
- // Annotate the CommonJS export names for ESM import in node:
146
- 0 && (module.exports = {});
@@ -68,5 +68,3 @@ var routePrefetch_default = (api) => {
68
68
  );
69
69
  });
70
70
  };
71
- // Annotate the CommonJS export names for ESM import in node:
72
- 0 && (module.exports = {});
@@ -43,5 +43,3 @@ var routeProps_default = (api) => {
43
43
  propertyName: "routeProps"
44
44
  });
45
45
  };
46
- // Annotate the CommonJS export names for ESM import in node:
47
- 0 && (module.exports = {});
@@ -45,7 +45,7 @@ var import_svg_loader = __toESM(require("./svg-loader"));
45
45
  async function build(opts) {
46
46
  const { api, watch } = opts;
47
47
  import_utils.logger.wait("[SSR] Compiling...");
48
- const now = new Date().getTime();
48
+ const now = (/* @__PURE__ */ new Date()).getTime();
49
49
  function getExternal() {
50
50
  if ((0, import_utils.isMonorepo)({ root: api.paths.cwd })) {
51
51
  return [];
@@ -92,7 +92,7 @@ async function build(opts) {
92
92
  } else {
93
93
  await import_esbuild.default.build(buildOptions);
94
94
  }
95
- const diff = new Date().getTime() - now;
95
+ const diff = (/* @__PURE__ */ new Date()).getTime() - now;
96
96
  import_utils.logger.info(`[SSR] Compiled in ${diff}ms`);
97
97
  }
98
98
  var loader = {
@@ -41,5 +41,3 @@ function svgLoader(opts) {
41
41
  };
42
42
  }
43
43
  var svg_loader_default = svgLoader;
44
- // Annotate the CommonJS export names for ESM import in node:
45
- 0 && (module.exports = {});
@@ -43,5 +43,3 @@ var swc_default = (api) => {
43
43
  ];
44
44
  });
45
45
  };
46
- // Annotate the CommonJS export names for ESM import in node:
47
- 0 && (module.exports = {});
@@ -95,5 +95,3 @@ export { terminal };
95
95
  };
96
96
  });
97
97
  };
98
- // Annotate the CommonJS export names for ESM import in node:
99
- 0 && (module.exports = {});
@@ -101,5 +101,3 @@ var test_default = (api) => {
101
101
  });
102
102
  });
103
103
  };
104
- // Annotate the CommonJS export names for ESM import in node:
105
- 0 && (module.exports = {});
@@ -101,5 +101,3 @@ export type IConfigFromPlugins = PrettifyWithCloseable<
101
101
  });
102
102
  });
103
103
  };
104
- // Annotate the CommonJS export names for ESM import in node:
105
- 0 && (module.exports = {});
@@ -307,12 +307,7 @@ declare module '*.txt' {
307
307
  imports: (0, import_importsToStr.importsToStr)(
308
308
  await api.applyPlugins({
309
309
  key: "addEntryImports",
310
- initialValue: [
311
- // append overrides.{ext} style file
312
- api.appData.overridesCSS.length && {
313
- source: api.appData.overridesCSS[0]
314
- }
315
- ].filter(Boolean)
310
+ initialValue: []
316
311
  })
317
312
  ).join("\n"),
318
313
  basename: api.config.base,
@@ -28,5 +28,3 @@ var CodeFrameError = class extends Error {
28
28
  this.location = location;
29
29
  }
30
30
  };
31
- // Annotate the CommonJS export names for ESM import in node:
32
- 0 && (module.exports = {});
@@ -111,5 +111,3 @@ function babelPlugin_default() {
111
111
  }
112
112
  };
113
113
  }
114
- // Annotate the CommonJS export names for ESM import in node:
115
- 0 && (module.exports = {});
@@ -85,5 +85,3 @@ ${babelCodeFrame.codeFrameColumns(
85
85
  ];
86
86
  });
87
87
  };
88
- // Annotate the CommonJS export names for ESM import in node:
89
- 0 && (module.exports = {});
@@ -151,5 +151,3 @@ uiBtn.addEventListener('click', () => {
151
151
  return [{ source: "@@/core/ui" }];
152
152
  });
153
153
  };
154
- // Annotate the CommonJS export names for ESM import in node:
155
- 0 && (module.exports = {});
@@ -78,5 +78,3 @@ var vite_default = (api) => {
78
78
  return $;
79
79
  });
80
80
  };
81
- // Annotate the CommonJS export names for ESM import in node:
82
- 0 && (module.exports = {});
@@ -89,5 +89,3 @@ var webpack_default = (api) => {
89
89
  });
90
90
  });
91
91
  };
92
- // Annotate the CommonJS export names for ESM import in node:
93
- 0 && (module.exports = {});
@@ -150,5 +150,3 @@ var registerMethods_default = (api) => {
150
150
  }
151
151
  });
152
152
  };
153
- // Annotate the CommonJS export names for ESM import in node:
154
- 0 && (module.exports = {});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@umijs/preset-umi",
3
- "version": "4.0.86",
3
+ "version": "4.0.87",
4
4
  "description": "@umijs/preset-umi",
5
5
  "homepage": "https://github.com/umijs/umi/tree/master/packages/preset-umi#readme",
6
6
  "bugs": "https://github.com/umijs/umi/issues",
@@ -30,28 +30,30 @@
30
30
  "enhanced-resolve": "5.9.3",
31
31
  "fast-glob": "3.2.12",
32
32
  "html-webpack-plugin": "5.5.0",
33
+ "less-plugin-resolve": "1.0.0",
33
34
  "path-to-regexp": "1.7.0",
35
+ "postcss": "^8.4.21",
34
36
  "postcss-prefix-selector": "1.16.0",
35
37
  "react": "18.1.0",
36
38
  "react-dom": "18.1.0",
37
39
  "react-router": "6.3.0",
38
40
  "react-router-dom": "6.3.0",
39
41
  "regenerator-runtime": "0.13.11",
40
- "@umijs/ast": "4.0.86",
41
- "@umijs/babel-preset-umi": "4.0.86",
42
- "@umijs/bundler-utils": "4.0.86",
43
- "@umijs/bundler-vite": "4.0.86",
44
- "@umijs/bundler-esbuild": "4.0.86",
45
- "@umijs/bundler-webpack": "4.0.86",
46
- "@umijs/core": "4.0.86",
42
+ "@umijs/ast": "4.0.87",
43
+ "@umijs/bundler-utils": "4.0.87",
44
+ "@umijs/bundler-vite": "4.0.87",
47
45
  "@umijs/did-you-know": "1.0.3",
48
- "@umijs/mfsu": "4.0.86",
49
- "@umijs/plugin-run": "4.0.86",
50
- "@umijs/renderer-react": "4.0.86",
51
- "@umijs/server": "4.0.86",
52
- "@umijs/zod2ts": "4.0.86",
46
+ "@umijs/core": "4.0.87",
47
+ "@umijs/bundler-esbuild": "4.0.87",
48
+ "@umijs/babel-preset-umi": "4.0.87",
49
+ "@umijs/mfsu": "4.0.87",
50
+ "@umijs/bundler-webpack": "4.0.87",
53
51
  "@umijs/ui": "3.0.1",
54
- "@umijs/utils": "4.0.86"
52
+ "@umijs/renderer-react": "4.0.87",
53
+ "@umijs/utils": "4.0.87",
54
+ "@umijs/server": "4.0.87",
55
+ "@umijs/zod2ts": "4.0.87",
56
+ "@umijs/plugin-run": "4.0.87"
55
57
  },
56
58
  "devDependencies": {
57
59
  "@manypkg/get-packages": "1.1.3",