@umijs/preset-umi 4.4.13-canary.20250917.1 → 4.5.1

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 (46) hide show
  1. package/dist/commands/config/remove.js +1 -2
  2. package/dist/commands/config/set.js +1 -2
  3. package/dist/commands/deadcode.js +1 -2
  4. package/dist/commands/dev/createRouteMiddleware.js +1 -2
  5. package/dist/commands/dev/depBuildWorker/depBuildWorker.js +1 -2
  6. package/dist/commands/dev/depBuildWorker/depBuilder.js +5 -6
  7. package/dist/commands/generators/component.js +2 -0
  8. package/dist/commands/generators/page.js +8 -9
  9. package/dist/commands/generators/utils.js +2 -0
  10. package/dist/commands/mfsu/util.js +2 -0
  11. package/dist/features/aiDev/aiDev.js +1 -2
  12. package/dist/features/apiRoute/apiRoute.js +1 -2
  13. package/dist/features/apiRoute/dev-server/esbuild.js +1 -2
  14. package/dist/features/apiRoute/request.js +5 -6
  15. package/dist/features/apiRoute/response.js +1 -0
  16. package/dist/features/apiRoute/utils.js +9 -18
  17. package/dist/features/appData/appData.js +2 -2
  18. package/dist/features/codeSplitting/codeSplitting.js +2 -4
  19. package/dist/features/esbuildHelperChecker/esbuildHelperChecker.js +5 -10
  20. package/dist/features/esmi/Service.js +5 -5
  21. package/dist/features/favicons/favicons.js +2 -4
  22. package/dist/features/icons/svgr.js +2 -4
  23. package/dist/features/mock/createMockMiddleware.js +1 -2
  24. package/dist/features/monorepo/redirect.js +2 -4
  25. package/dist/features/mpa/mpa.js +5 -10
  26. package/dist/features/overrides/overrides.js +1 -2
  27. package/dist/features/overrides/transform.js +2 -4
  28. package/dist/features/phantomDependency/phantomDependency.js +15 -30
  29. package/dist/features/prepare/esbuildPlugins/esbuildAliasPlugin.js +4 -8
  30. package/dist/features/prepare/prepare.js +1 -2
  31. package/dist/features/routePreloadOnLoad/routePreloadOnLoad.js +26 -5
  32. package/dist/features/ssr/builder/css-loader.js +2 -2
  33. package/dist/features/ssr/ssr.js +1 -2
  34. package/dist/features/tmpFiles/getModuleExports.js +2 -2
  35. package/dist/features/tmpFiles/routes.js +6 -7
  36. package/dist/features/transform/CodeFrameError.js +1 -0
  37. package/dist/features/ui/ui.js +1 -2
  38. package/dist/features/utoopack/utoopack.js +2 -2
  39. package/dist/libs/folderCache/AutoUpdateFolderCache.js +9 -3
  40. package/dist/libs/folderCache/AutoUpdateSourceCodeCache.js +5 -2
  41. package/dist/libs/folderCache/FolderWatch.js +5 -2
  42. package/dist/libs/folderCache/LazySourceCodeCache.js +10 -6
  43. package/dist/libs/scan.js +2 -4
  44. package/dist/utils/routeExportExtractor.js +1 -2
  45. package/dist/utils/serializeAppData.js +1 -2
  46. package/package.json +15 -15
@@ -26,8 +26,7 @@ var import_ast = require("@umijs/ast");
26
26
  var import_fs = require("fs");
27
27
  function remove(mainConfigFile, name) {
28
28
  const ast = (0, import_ast.getASTByFilePath)(mainConfigFile);
29
- if (!ast)
30
- return;
29
+ if (!ast) return;
31
30
  const generateCode = (0, import_ast.generate)((0, import_ast.removeConfigByName)(ast, name));
32
31
  const prettier = require("@umijs/utils/compiled/prettier");
33
32
  const printStr = prettier.format(generateCode, {
@@ -35,8 +35,7 @@ function set(api, name, value) {
35
35
  api.appData.mainConfigFile = absPath;
36
36
  }
37
37
  const ast = (0, import_ast.getASTByFilePath)(mainConfigFile);
38
- if (!ast)
39
- return;
38
+ if (!ast) return;
40
39
  const generateCode = (0, import_ast.generate)((0, import_ast.setConfigByName)(ast, name, value));
41
40
  const prettier = require("@umijs/utils/compiled/prettier");
42
41
  const printStr = prettier.format(generateCode, {
@@ -205,8 +205,7 @@ var deadcode_default = (api) => {
205
205
  const recordJsonPath = (0, import_utils.winPath)(
206
206
  (0, import_path.join)(cwd, typeof out === "string" ? out : recordJson)
207
207
  );
208
- if (gitInfo)
209
- import_utils.logger.wait("generating file...");
208
+ if (gitInfo) import_utils.logger.wait("generating file...");
210
209
  await outputUnusedFiles(unusedFiles, recordJsonPath, {
211
210
  gitInfo,
212
211
  cwd
@@ -40,8 +40,7 @@ function createRouteMiddleware(opts) {
40
40
  hasErrors: () => false
41
41
  };
42
42
  }
43
- if (webpackStats)
44
- return Promise.resolve(webpackStats);
43
+ if (webpackStats) return Promise.resolve(webpackStats);
45
44
  return new Promise((resolve) => {
46
45
  onStats = (stats) => {
47
46
  resolve(stats);
@@ -114,8 +114,7 @@ start().catch((e) => {
114
114
  import_utils.logger.error("[MFSU][eager] build worker start failed", e);
115
115
  });
116
116
  function makeArray(a) {
117
- if (Array.isArray(a))
118
- return a;
117
+ if (Array.isArray(a)) return a;
119
118
  return [a];
120
119
  }
121
120
  function setupWorkerEnv() {
@@ -45,9 +45,10 @@ var import_path = require("path");
45
45
  var import_worker_threads = require("worker_threads");
46
46
  var MF_ENTRY = "mf_index.js";
47
47
  var DepBuilderInWorker = class {
48
+ completeFns = [];
49
+ isBuilding = false;
50
+ opts;
48
51
  constructor(opts) {
49
- this.completeFns = [];
50
- this.isBuilding = false;
51
52
  this.opts = opts;
52
53
  }
53
54
  async buildWithWebpack(opts) {
@@ -154,10 +155,8 @@ var DepBuilderInWorker = class {
154
155
  depConfig.output.path = this.opts.tmpBase;
155
156
  depConfig.output.publicPath = "auto";
156
157
  depConfig.devtool = false;
157
- if ((_a = depConfig.output) == null ? void 0 : _a.library)
158
- delete depConfig.output.library;
159
- if ((_b = depConfig.output) == null ? void 0 : _b.libraryTarget)
160
- delete depConfig.output.libraryTarget;
158
+ if ((_a = depConfig.output) == null ? void 0 : _a.library) delete depConfig.output.library;
159
+ if ((_b = depConfig.output) == null ? void 0 : _b.libraryTarget) delete depConfig.output.libraryTarget;
161
160
  depConfig.optimization || (depConfig.optimization = {});
162
161
  depConfig.optimization.splitChunks = {
163
162
  chunks: (chunk) => {
@@ -74,6 +74,8 @@ var ComponentGenerator = class {
74
74
  this.name = name;
75
75
  this.dir = dir;
76
76
  }
77
+ name;
78
+ dir;
77
79
  async run() {
78
80
  const { appRoot, args } = this.opts;
79
81
  const capitalizeName = import_utils.lodash.upperFirst(this.name);
@@ -59,13 +59,6 @@ var USER_TEMPLATE_PAGE_DIR = "templates/page";
59
59
  var PageGenerator = class {
60
60
  constructor(options) {
61
61
  this.options = options;
62
- this.isDirMode = false;
63
- this.dir = "";
64
- this.name = "";
65
- this.importSource = "";
66
- this.needEnsureDirMode = false;
67
- this.prompts = import_utils2.promptsExitWhenCancel;
68
- this.paths = [];
69
62
  this.isDirMode = !!options.args.dir;
70
63
  this.importSource = options.importSource || "umi";
71
64
  const [_, ...inputPaths] = options.args._;
@@ -75,6 +68,13 @@ var PageGenerator = class {
75
68
  this.needEnsureDirMode = true;
76
69
  }
77
70
  }
71
+ isDirMode = false;
72
+ dir = "";
73
+ name = "";
74
+ importSource = "";
75
+ needEnsureDirMode = false;
76
+ prompts = import_utils2.promptsExitWhenCancel;
77
+ paths = [];
78
78
  async run() {
79
79
  if (this.paths.length === 0) {
80
80
  await this.runInteractiveMode();
@@ -129,8 +129,7 @@ var PageGenerator = class {
129
129
  this.isDirMode = false;
130
130
  }
131
131
  async ensureDirMode() {
132
- if (!this.needEnsureDirMode)
133
- return;
132
+ if (!this.needEnsureDirMode) return;
134
133
  const response = await this.prompts({
135
134
  type: "select",
136
135
  name: "mode",
@@ -60,6 +60,8 @@ var GeneratorHelper = class {
60
60
  this.needInstallUmiPlugin = needInstall;
61
61
  this.needConfigUmiPlugin = needConfigPlugins;
62
62
  }
63
+ needConfigUmiPlugin;
64
+ needInstallUmiPlugin;
63
65
  setUmirc(key, val) {
64
66
  (0, import_set.set)(this.api, key, val);
65
67
  }
@@ -49,6 +49,8 @@ var MFSUUtilBase = class {
49
49
  this.mfsuCacheBase = ((_b = (_a = api.config) == null ? void 0 : _a.mfsu) == null ? void 0 : _b.cacheDirectoryPath) || (0, import_path.join)(cacheBase, "mfsu");
50
50
  this.cliName = this.api.appData.umi.cliName;
51
51
  }
52
+ mfsuCacheBase;
53
+ cliName;
52
54
  async prepare() {
53
55
  var _a, _b, _c, _d;
54
56
  const api = this.api;
@@ -54,8 +54,7 @@ var aiDev_default = (api) => {
54
54
  if (api.config.mako || api.config.utoopack) {
55
55
  return;
56
56
  }
57
- if (!process.env.UMI_AI_COMMAND || !process.env.UMI_AI_PACKAGE)
58
- return;
57
+ if (!process.env.UMI_AI_COMMAND || !process.env.UMI_AI_PACKAGE) return;
59
58
  try {
60
59
  const aiCommand = process.env.UMI_AI_COMMAND;
61
60
  const aiPackage = process.env.UMI_AI_PACKAGE;
@@ -66,8 +66,7 @@ var apiRoute_default = (api) => {
66
66
  },
67
67
  enableBy: () => {
68
68
  const hasApiRoutes = import_fs.default.existsSync((0, import_path.join)(api.paths.absSrcPath, "api"));
69
- if (!hasApiRoutes)
70
- return false;
69
+ if (!hasApiRoutes) return false;
71
70
  const config = api.userConfig.apiRoute;
72
71
  if (!config) {
73
72
  return false;
@@ -55,8 +55,7 @@ async function esbuild_default(api, apiRoutes) {
55
55
  (0, import_utils2.esbuildIgnorePathPrefixPlugin)(),
56
56
  (0, import_watchRebuild.esbuildWatchRebuildPlugin)({
57
57
  onRebuild(error) {
58
- if (error)
59
- import_utils.logger.error("Compile api routes failed: ", error);
58
+ if (error) import_utils.logger.error("Compile api routes failed: ", error);
60
59
  Object.keys(require.cache).forEach((modulePath) => {
61
60
  if (modulePath.startsWith((0, import_path.join)(api.paths.cwd, import_constants.OUTPUT_PATH)))
62
61
  delete require.cache[modulePath];
@@ -26,17 +26,17 @@ __export(request_exports, {
26
26
  module.exports = __toCommonJS(request_exports);
27
27
  var import_utils = require("./utils");
28
28
  var UmiApiRequest = class {
29
+ _req;
30
+ _params = {};
29
31
  constructor(req, apiRoutes) {
30
- this._params = {};
31
- this._body = null;
32
32
  this._req = req;
33
33
  const m = (0, import_utils.matchApiRoute)(apiRoutes, this.pathName || "");
34
- if (m)
35
- this._params = m.params;
34
+ if (m) this._params = m.params;
36
35
  }
37
36
  get params() {
38
37
  return this._params;
39
38
  }
39
+ _body = null;
40
40
  get body() {
41
41
  return this._body;
42
42
  }
@@ -128,8 +128,7 @@ function parseMultipart(body, boundary) {
128
128
  );
129
129
  const meta = Buffer.from(hexMeta, "hex").toString("utf-8");
130
130
  const name = (_a = meta.split('name="')[1]) == null ? void 0 : _a.split('"')[0];
131
- if (!name)
132
- return acc;
131
+ if (!name) return acc;
133
132
  const fileName = (_b = meta.split('filename="')[1]) == null ? void 0 : _b.split('"')[0];
134
133
  if (fileName) {
135
134
  const fileBufferBeforeTrim = Buffer.from(hexValue, "hex");
@@ -23,6 +23,7 @@ __export(response_exports, {
23
23
  });
24
24
  module.exports = __toCommonJS(response_exports);
25
25
  var UmiApiResponse = class {
26
+ _res;
26
27
  constructor(res) {
27
28
  this._res = res;
28
29
  }
@@ -34,39 +34,30 @@ function esbuildIgnorePathPrefixPlugin() {
34
34
  };
35
35
  }
36
36
  function matchApiRoute(apiRoutes, path) {
37
- if (path.startsWith("/"))
38
- path = path.substring(1);
39
- if (path.startsWith("api/"))
40
- path = path.substring(4);
37
+ if (path.startsWith("/")) path = path.substring(1);
38
+ if (path.startsWith("api/")) path = path.substring(4);
41
39
  const pathSegments = path.split("/").filter((p) => p !== "");
42
40
  if (pathSegments.length === 0 || pathSegments.length === 1 && pathSegments[0] === "api") {
43
41
  const route2 = apiRoutes.find((r) => r.path === "/");
44
- if (route2)
45
- return { route: route2, params: {} };
46
- else
47
- return void 0;
42
+ if (route2) return { route: route2, params: {} };
43
+ else return void 0;
48
44
  }
49
45
  const params = {};
50
46
  const route = apiRoutes.find((route2) => {
51
47
  const routePathSegments = route2.path.split("/").filter((p) => p !== "");
52
- if (routePathSegments.length !== pathSegments.length)
53
- return false;
48
+ if (routePathSegments.length !== pathSegments.length) return false;
54
49
  for (let i = 0; i < routePathSegments.length; i++) {
55
50
  const routePathSegment = routePathSegments[i];
56
51
  if (routePathSegment.match(/^\[.*]$/)) {
57
52
  params[routePathSegment.substring(1, routePathSegment.length - 1)] = pathSegments[i];
58
- if (i == routePathSegments.length - 1)
59
- return true;
53
+ if (i == routePathSegments.length - 1) return true;
60
54
  continue;
61
55
  }
62
- if (routePathSegment !== pathSegments[i])
63
- return false;
64
- if (i == routePathSegments.length - 1)
65
- return true;
56
+ if (routePathSegment !== pathSegments[i]) return false;
57
+ if (i == routePathSegments.length - 1) return true;
66
58
  }
67
59
  });
68
- if (route)
69
- return { route, params };
60
+ if (route) return { route, params };
70
61
  }
71
62
  // Annotate the CommonJS export names for ESM import in node:
72
63
  0 && (module.exports = {
@@ -160,13 +160,13 @@ var appData_default = (api) => {
160
160
  async function getAppJsInfo() {
161
161
  for (const path of (0, import_watch.expandJSPaths)((0, import_path.join)(api.paths.absSrcPath, "app"))) {
162
162
  if ((0, import_fs.existsSync)(path)) {
163
- const [_, exports] = await bundlerUtils.parseModule({
163
+ const [_, exports2] = await bundlerUtils.parseModule({
164
164
  path,
165
165
  content: (0, import_fs.readFileSync)(path, "utf-8")
166
166
  });
167
167
  return {
168
168
  path,
169
- exports
169
+ exports: exports2
170
170
  };
171
171
  }
172
172
  }
@@ -49,8 +49,7 @@ var codeSplitting_default = (api) => {
49
49
  enableBy: api.EnableBy.config
50
50
  });
51
51
  api.chainWebpack((memo) => {
52
- if (api.env !== "production")
53
- return;
52
+ if (api.env !== "production") return;
54
53
  const { jsStrategy, jsStrategyOptions, cssStrategy } = api.config.codeSplitting;
55
54
  if (jsStrategy === "bigVendors") {
56
55
  memo.optimization.splitChunks({
@@ -75,8 +74,7 @@ var codeSplitting_default = (api) => {
75
74
  name(module2) {
76
75
  const path = module2.context.replace(/.pnpm[\\/]/, "");
77
76
  const match = path.match(/[\\/]node_modules[\\/](.*?)([\\/]|$)/);
78
- if (!match)
79
- return "npm.unknown";
77
+ if (!match) return "npm.unknown";
80
78
  const packageName = match[1];
81
79
  return `npm.${packageName.replace(/@/g, "_at_").replace(/\+/g, "_")}`;
82
80
  }
@@ -109,17 +109,12 @@ var esbuildHelperChecker_default = (api) => {
109
109
  }
110
110
  });
111
111
  api.onBuildComplete(async ({ err }) => {
112
- if (api.config.vite || api.config.mako || api.config.utoopack)
113
- return;
114
- if (err)
115
- return;
112
+ if (api.config.vite || api.config.mako || api.config.utoopack) return;
113
+ if (err) return;
116
114
  const jsMinifier = api.config.jsMinifier || "esbuild";
117
- if (jsMinifier !== "esbuild")
118
- return;
119
- if (api.config.esbuildMinifyIIFE)
120
- return;
121
- if (process.env.COMPRESS === "none")
122
- return;
115
+ if (jsMinifier !== "esbuild") return;
116
+ if (api.config.esbuildMinifyIIFE) return;
117
+ if (process.env.COMPRESS === "none") return;
123
118
  try {
124
119
  await checkDir({
125
120
  dir: api.paths.absOutputPath
@@ -36,11 +36,11 @@ var import_utils = require("@umijs/utils");
36
36
  var import_crypto = require("crypto");
37
37
  var import_fs = __toESM(require("fs"));
38
38
  var import_path = __toESM(require("path"));
39
- var ESMIService = class {
39
+ var ESMIService = class _ESMIService {
40
+ cdnOrigin = "";
41
+ cacheDir = "";
42
+ cache = {};
40
43
  constructor(opts) {
41
- this.cdnOrigin = "";
42
- this.cacheDir = "";
43
- this.cache = {};
44
44
  this.cdnOrigin = opts.cdnOrigin;
45
45
  this.cacheDir = opts.cacheDir;
46
46
  const cacheFilePath = import_path.default.join(this.cacheDir, "importmap.json");
@@ -102,7 +102,7 @@ var ESMIService = class {
102
102
  * @returns importmap
103
103
  */
104
104
  async getImportmap(data) {
105
- const cacheKey = ESMIService.getCacheKey(data);
105
+ const cacheKey = _ESMIService.getCacheKey(data);
106
106
  const cache = this.getCache(cacheKey);
107
107
  const stamp = +/* @__PURE__ */ new Date();
108
108
  if (cache) {
@@ -44,8 +44,7 @@ var favicons_default = (api) => {
44
44
  }
45
45
  });
46
46
  api.modifyAppData(async (memo) => {
47
- if (api.config.favicons)
48
- return memo;
47
+ if (api.config.favicons) return memo;
49
48
  const faviconFiles = getFaviconFiles(api.paths.absSrcPath);
50
49
  if (faviconFiles) {
51
50
  memo.faviconFiles = faviconFiles;
@@ -65,8 +64,7 @@ var favicons_default = (api) => {
65
64
  }
66
65
  ]);
67
66
  api.onBuildComplete(({ err }) => {
68
- if (err)
69
- return;
67
+ if (err) return;
70
68
  if (api.appData.faviconFiles) {
71
69
  api.appData.faviconFiles.forEach((e) => {
72
70
  (0, import_fs.copyFileSync)(
@@ -74,10 +74,8 @@ function loadLocalIcon(icon, localIconDir) {
74
74
  }
75
75
  function normalizeSvgr(str) {
76
76
  return str.split("\n").filter((line) => {
77
- if (line.startsWith('import * as React from "react";'))
78
- return false;
79
- if (line.startsWith("export default "))
80
- return false;
77
+ if (line.startsWith('import * as React from "react";')) return false;
78
+ if (line.startsWith("export default ")) return false;
81
79
  return true;
82
80
  }).join("\n");
83
81
  }
@@ -40,8 +40,7 @@ function createMockMiddleware(opts) {
40
40
  const method = req.method.toUpperCase();
41
41
  for (const key of Object.keys(opts.context.mockData)) {
42
42
  const mock = opts.context.mockData[key];
43
- if (mock.method !== method)
44
- continue;
43
+ if (mock.method !== method) continue;
45
44
  const { keys, re } = getPathReAndKeys(mock.path);
46
45
  const m = re.exec(req.path);
47
46
  if (m) {
@@ -68,8 +68,7 @@ var redirect_default = (api) => {
68
68
  // APP_ROOT: https://github.com/umijs/umi/issues/9461
69
69
  cwd: useRootProject ? currentProjectRoot : (0, import_path.dirname)(currentProjectRoot)
70
70
  });
71
- if (!rootPkg)
72
- return memo;
71
+ if (!rootPkg) return memo;
73
72
  const root = (0, import_path.dirname)(rootPkg);
74
73
  (0, import_assert.default)(
75
74
  (0, import_utils.isMonorepo)({ root }),
@@ -84,8 +83,7 @@ var redirect_default = (api) => {
84
83
  const usingDeps = collectPkgDeps(api.pkg).filter((name) => {
85
84
  return !exclude.some((reg) => reg.test(name));
86
85
  });
87
- if (!usingDeps.length)
88
- return memo;
86
+ if (!usingDeps.length) return memo;
89
87
  const projects = await collectAllProjects({ root });
90
88
  const alias = usingDeps.reduce((obj, name) => {
91
89
  const pkgInfo = projects[name];
@@ -107,8 +107,7 @@ ${renderer}
107
107
  });
108
108
  });
109
109
  api.modifyEntry((memo) => {
110
- if ("umi" in memo)
111
- delete memo["umi"];
110
+ if ("umi" in memo) delete memo["umi"];
112
111
  api.appData.mpa.entry.forEach((entry) => {
113
112
  memo[entry.name] = (0, import_path.join)(api.paths.absTmpPath, entry.tmpFilePath);
114
113
  });
@@ -177,14 +176,10 @@ async function collectEntry(root, opts, mountElementId) {
177
176
  );
178
177
  }
179
178
  function getIndexFile(dir) {
180
- if ((0, import_fs.existsSync)((0, import_path.join)(dir, "index.tsx")))
181
- return (0, import_path.join)(dir, "index.tsx");
182
- if ((0, import_fs.existsSync)((0, import_path.join)(dir, "index.ts")))
183
- return (0, import_path.join)(dir, "index.ts");
184
- if ((0, import_fs.existsSync)((0, import_path.join)(dir, "index.jsx")))
185
- return (0, import_path.join)(dir, "index.jsx");
186
- if ((0, import_fs.existsSync)((0, import_path.join)(dir, "index.js")))
187
- return (0, import_path.join)(dir, "index.js");
179
+ if ((0, import_fs.existsSync)((0, import_path.join)(dir, "index.tsx"))) return (0, import_path.join)(dir, "index.tsx");
180
+ if ((0, import_fs.existsSync)((0, import_path.join)(dir, "index.ts"))) return (0, import_path.join)(dir, "index.ts");
181
+ if ((0, import_fs.existsSync)((0, import_path.join)(dir, "index.jsx"))) return (0, import_path.join)(dir, "index.jsx");
182
+ if ((0, import_fs.existsSync)((0, import_path.join)(dir, "index.js"))) return (0, import_path.join)(dir, "index.js");
188
183
  return null;
189
184
  }
190
185
  async function getConfig(indexFile) {
@@ -38,8 +38,7 @@ var overrides_default = (api) => {
38
38
  if (api.appData.overridesCSS.length) {
39
39
  const filePath = api.appData.overridesCSS[0];
40
40
  let content = (0, import_fs.readFileSync)(filePath, "utf-8");
41
- if (content === cachedContent)
42
- return;
41
+ if (content === cachedContent) return;
43
42
  const subPath = "core/overrides.css";
44
43
  const targetPath = (0, import_path.join)(api.paths.absTmpPath, subPath);
45
44
  const isLess = filePath.endsWith(".less");
@@ -43,10 +43,8 @@ async function transform(cssContent, filePath) {
43
43
  let origin = atRule.params;
44
44
  origin = origin.replace(/^url\((.+)\)$/g, "$1");
45
45
  origin = origin.replace(/^'(.+)'$/g, "$1").replace(/^"(.+)"$/g, "$1");
46
- if (origin.startsWith("~"))
47
- return;
48
- if (origin.startsWith("/"))
49
- return;
46
+ if (origin.startsWith("~")) return;
47
+ if (origin.startsWith("/")) return;
50
48
  function getResolvedPath(origin2) {
51
49
  return (0, import_utils.winPath)(import_path.default.resolve(import_path.default.dirname(filePath), origin2));
52
50
  }
@@ -57,14 +57,10 @@ var phantomDependency_default = (api) => {
57
57
  const importsBySource = /* @__PURE__ */ new Map();
58
58
  for (const file of files) {
59
59
  const winP = (0, import_utils.winPath)(file);
60
- if (winP.includes(".umi/"))
61
- continue;
62
- if (winP.includes("/node_modules/"))
63
- continue;
64
- if (winP.startsWith("../"))
65
- continue;
66
- if (import_path.default.isAbsolute(file))
67
- continue;
60
+ if (winP.includes(".umi/")) continue;
61
+ if (winP.includes("/node_modules/")) continue;
62
+ if (winP.startsWith("../")) continue;
63
+ if (import_path.default.isAbsolute(file)) continue;
68
64
  const { imports } = result.metafile.inputs[file];
69
65
  for (const imp of imports) {
70
66
  if (imp.kind === "import-statement" && imp.external) {
@@ -77,27 +73,17 @@ var phantomDependency_default = (api) => {
77
73
  }
78
74
  const phantomDeps = [];
79
75
  for (const [source, files2] of importsBySource) {
80
- if (source.startsWith("<"))
81
- continue;
82
- if (source.startsWith("."))
83
- continue;
84
- if (source.startsWith("/"))
85
- continue;
86
- if (source.startsWith("@/") || source.startsWith("@@/"))
87
- continue;
76
+ if (source.startsWith("<")) continue;
77
+ if (source.startsWith(".")) continue;
78
+ if (source.startsWith("/")) continue;
79
+ if (source.startsWith("@/") || source.startsWith("@@/")) continue;
88
80
  const pkgName = getPkgName(source);
89
- if ((_a = api.config.phantomDependency.exclude) == null ? void 0 : _a.includes(pkgName))
90
- continue;
91
- if ((_b = api.pkg.dependencies) == null ? void 0 : _b[pkgName])
92
- continue;
93
- if ((_c = api.pkg.devDependencies) == null ? void 0 : _c[pkgName])
94
- continue;
95
- if ((_d = api.pkg.clientDependencies) == null ? void 0 : _d[pkgName])
96
- continue;
97
- if (matchAlias(source, api.config.alias || {}))
98
- continue;
99
- if (matchExternals(source, api.config.externals || {}))
100
- continue;
81
+ if ((_a = api.config.phantomDependency.exclude) == null ? void 0 : _a.includes(pkgName)) continue;
82
+ if ((_b = api.pkg.dependencies) == null ? void 0 : _b[pkgName]) continue;
83
+ if ((_c = api.pkg.devDependencies) == null ? void 0 : _c[pkgName]) continue;
84
+ if ((_d = api.pkg.clientDependencies) == null ? void 0 : _d[pkgName]) continue;
85
+ if (matchAlias(source, api.config.alias || {})) continue;
86
+ if (matchExternals(source, api.config.externals || {})) continue;
101
87
  phantomDeps.push(source);
102
88
  import_utils.logger.error(
103
89
  `[phantomDependency] ${import_utils.chalk.red(
@@ -118,8 +104,7 @@ var phantomDependency_default = (api) => {
118
104
  });
119
105
  function getPkgName(source) {
120
106
  const arr = source.split("/");
121
- if (source.startsWith("@"))
122
- return arr[0] + "/" + arr[1];
107
+ if (source.startsWith("@")) return arr[0] + "/" + arr[1];
123
108
  return arr[0];
124
109
  }
125
110
  function matchAlias(source, alias) {
@@ -53,14 +53,10 @@ async function resolve(context, path2) {
53
53
  }
54
54
  function sortByAffix(opts) {
55
55
  return opts.keys.sort((a, b) => {
56
- if (a.endsWith(opts.affix) && b.endsWith(opts.affix))
57
- return 0;
58
- if (a.endsWith(opts.affix))
59
- return -1;
60
- if (b.endsWith(opts.affix))
61
- return 1;
62
- else
63
- return 0;
56
+ if (a.endsWith(opts.affix) && b.endsWith(opts.affix)) return 0;
57
+ if (a.endsWith(opts.affix)) return -1;
58
+ if (b.endsWith(opts.affix)) return 1;
59
+ else return 0;
64
60
  });
65
61
  }
66
62
  function addSlashAffix(key) {
@@ -84,8 +84,7 @@ var prepare_default = (api) => {
84
84
  if (api.appData.framework === "vue") {
85
85
  return;
86
86
  }
87
- if (!isFirstTime)
88
- return;
87
+ if (!isFirstTime) return;
89
88
  import_utils.logger.info("Preparing...");
90
89
  const umiEntry = import_path.default.join(api.paths.absTmpPath, "umi.ts");
91
90
  const entryPoints = [umiEntry];
@@ -29,6 +29,7 @@ var import_path = require("path");
29
29
  var import_constants = require("../../constants");
30
30
  var import_scan = require("../../libs/scan");
31
31
  var import_utils2 = require("./utils");
32
+ var import_terser = require("@umijs/bundler-webpack/compiled/terser");
32
33
  var routeScoreCache = /* @__PURE__ */ new Map();
33
34
  function computeRouteScore(path) {
34
35
  if (!routeScoreCache.get(path)) {
@@ -61,8 +62,7 @@ async function getRouteChunkFilesMap(chunks, opts) {
61
62
  const pickPreloadFiles = (files) => files.filter((f) => f.endsWith(".js") || f.endsWith(".css"));
62
63
  const routeFileResolveCache = {};
63
64
  for (const chunk of chunks) {
64
- if (chunk.entry)
65
- continue;
65
+ if (chunk.entry) continue;
66
66
  const pickedFiles = pickPreloadFiles(chunk.files);
67
67
  const routeOrigins = (chunk.origins || []).filter(
68
68
  (origin) => {
@@ -104,8 +104,7 @@ async function getRoutePathFilesMap(routes, fileChunksMap, opts) {
104
104
  const { resolver, absPagesPath } = opts;
105
105
  const routeFilesMap = {};
106
106
  for (const route of Object.values(routes)) {
107
- if (!route.file)
108
- continue;
107
+ if (!route.file) continue;
109
108
  if (!((_a = route.absPath) == null ? void 0 : _a.startsWith("/"))) {
110
109
  import_utils.logger.error(
111
110
  `[routePreloadOnLoad]: route absPath error, cannot preload for ${route.absPath}`
@@ -223,7 +222,7 @@ var routePreloadOnLoad_default = (api) => {
223
222
  };
224
223
  }
225
224
  if (api.name === "build" && routeChunkFilesMap && !api.config.tern) {
226
- const content = (0, import_fs.readFileSync)(
225
+ let content = (0, import_fs.readFileSync)(
227
226
  (0, import_path.join)(import_constants.TEMPLATES_DIR, "routePreloadOnLoad/preloadRouteFilesScp.js"),
228
227
  "utf-8"
229
228
  ).replace(
@@ -234,6 +233,28 @@ var routePreloadOnLoad_default = (api) => {
234
233
  `${// handle runtimePublicPath
235
234
  api.config.runtimePublicPath ? "window.publicPath||" : ""}"${api.config.publicPath}"`
236
235
  );
236
+ if (api.env === "production") {
237
+ try {
238
+ const minified = await (0, import_terser.minify)(content, {
239
+ compress: {
240
+ drop_console: false,
241
+ // Keep console logs if any
242
+ drop_debugger: true
243
+ },
244
+ mangle: true,
245
+ format: {
246
+ comments: false
247
+ // Remove comments
248
+ }
249
+ });
250
+ content = minified.code || content;
251
+ } catch (err2) {
252
+ import_utils.logger.warn(
253
+ `Failed to minify ${import_utils2.PRELOAD_ROUTE_HELPER}.js, using unminified version.`
254
+ );
255
+ import_utils.logger.warn(err2);
256
+ }
257
+ }
237
258
  if (api.config.hash) {
238
259
  preloadJSFileExt = `.${(0, import_crypto.createHash)("md5").update(content).digest("hex").substring(0, 8)}.js`;
239
260
  }
@@ -38,7 +38,7 @@ function hashString(str) {
38
38
  return hash;
39
39
  }
40
40
  function getClassNames(code, filename) {
41
- const { exports } = import_parcelCSS.parcelCSS.transform({
41
+ const { exports: exports2 } = import_parcelCSS.parcelCSS.transform({
42
42
  filename,
43
43
  code,
44
44
  minify: false,
@@ -48,7 +48,7 @@ function getClassNames(code, filename) {
48
48
  dashedIdents: false
49
49
  }
50
50
  });
51
- return Object.keys(exports || {});
51
+ return Object.keys(exports2 || {});
52
52
  }
53
53
  function cssLoader(opts) {
54
54
  return {
@@ -203,8 +203,7 @@ export type {
203
203
  }
204
204
  });
205
205
  api.onBuildComplete(async ({ err }) => {
206
- if (err)
207
- return;
206
+ if (err) return;
208
207
  if (api.config.ssr.platform === "vercel") {
209
208
  const jsonFile = (0, import_path.join)(api.cwd, "vercel.json");
210
209
  const json = (0, import_fs.existsSync)(jsonFile) ? import_utils.fsExtra.readJSONSync(jsonFile) : {};
@@ -29,8 +29,8 @@ async function getModuleExports(opts) {
29
29
  const { file } = opts;
30
30
  const content = (0, import_fs.readFileSync)(file, "utf-8");
31
31
  try {
32
- const [_, exports] = await (0, import_bundler_utils.parseModule)({ content, path: file });
33
- return exports || [];
32
+ const [_, exports2] = await (0, import_bundler_utils.parseModule)({ content, path: file });
33
+ return exports2 || [];
34
34
  } catch (e) {
35
35
  console.log(
36
36
  `Parse file ${import_utils.chalk.red(
@@ -151,17 +151,17 @@ async function getRoutes(opts) {
151
151
  const enableRouteProps = !opts.api.userConfig.routes;
152
152
  const needCollectExports = enableSSR || enableClientLoader || enableRouteProps;
153
153
  if (needCollectExports) {
154
- const exports = isJSFile && (0, import_fs.existsSync)(file) ? await (0, import_getModuleExports.getModuleExports)({
154
+ const exports2 = isJSFile && (0, import_fs.existsSync)(file) ? await (0, import_getModuleExports.getModuleExports)({
155
155
  file
156
156
  }) : [];
157
157
  if (enableSSR) {
158
- routes[id].hasServerLoader = exports.includes("serverLoader");
159
- routes[id].hasMetadataLoader = exports.includes("metadataLoader");
158
+ routes[id].hasServerLoader = exports2.includes("serverLoader");
159
+ routes[id].hasMetadataLoader = exports2.includes("metadataLoader");
160
160
  }
161
- if (enableClientLoader && exports.includes("clientLoader")) {
161
+ if (enableClientLoader && exports2.includes("clientLoader")) {
162
162
  routes[id].clientLoader = `clientLoaders['${id}']`;
163
163
  }
164
- if (enableRouteProps && exports.includes("routeProps")) {
164
+ if (enableRouteProps && exports2.includes("routeProps")) {
165
165
  routes[id].routeProps = `routeProps['${id}']`;
166
166
  }
167
167
  }
@@ -239,8 +239,7 @@ function getProjectRootCwd(cwd) {
239
239
  const splittedCwd = cwd.split("/");
240
240
  for (let level = -1; level >= -3; level -= 1) {
241
241
  const rootCwd = splittedCwd.slice(0, level).join("/");
242
- if (!rootCwd)
243
- break;
242
+ if (!rootCwd) break;
244
243
  if ((0, import_utils.isMonorepo)({ root: rootCwd })) {
245
244
  return rootCwd;
246
245
  }
@@ -23,6 +23,7 @@ __export(CodeFrameError_exports, {
23
23
  });
24
24
  module.exports = __toCommonJS(CodeFrameError_exports);
25
25
  var CodeFrameError = class extends Error {
26
+ location;
26
27
  constructor(msg, location) {
27
28
  super(msg);
28
29
  this.location = location;
@@ -124,8 +124,7 @@ var ui_default = (api) => {
124
124
  return memo;
125
125
  });
126
126
  api.onGenerateFiles(({ isFirstTime }) => {
127
- if (!isFirstTime)
128
- return;
127
+ if (!isFirstTime) return;
129
128
  api.writeTmpFile({
130
129
  path: "core/ui.ts",
131
130
  noPluginDir: true,
@@ -75,10 +75,10 @@ var utoopack_default = (api) => {
75
75
  process.env.UTOOPACK = process.env.UTOOPACK || require.resolve("@umijs/bundler-utoopack");
76
76
  try {
77
77
  const pkg = require((0, import_path.join)(
78
- require.resolve(process.env.UTOOPACK),
78
+ require.resolve("@utoo/pack"),
79
79
  "../../package.json"
80
80
  ));
81
- api.logger.info(`Using @utoo/pack@${pkg.dependencies["@utoo/pack"]}`);
81
+ api.logger.info(`Using @utoo/pack@${pkg.version}`);
82
82
  } catch (e) {
83
83
  console.error(e);
84
84
  }
@@ -27,9 +27,15 @@ var import_fs = require("fs");
27
27
  var import_path = require("path");
28
28
  var { watch } = import_utils.chokidar;
29
29
  var AutoUpdateFolderCache = class {
30
+ fileContentCache = {};
31
+ watcher;
32
+ readyPromise;
33
+ cwd;
34
+ pendingChanges = [];
35
+ debouchedHandleChanges;
36
+ onCacheUpdated;
37
+ filesLoader;
30
38
  constructor(opts) {
31
- this.fileContentCache = {};
32
- this.pendingChanges = [];
33
39
  this.cwd = opts.cwd;
34
40
  this.onCacheUpdated = opts.onCacheUpdate;
35
41
  this.filesLoader = opts.filesLoader || this._defaultLoader;
@@ -59,7 +65,7 @@ var AutoUpdateFolderCache = class {
59
65
  modifiedFiles.push(c.path);
60
66
  break;
61
67
  default:
62
- ((_n) => {
68
+ /* @__PURE__ */ ((_n) => {
63
69
  })(c.event);
64
70
  }
65
71
  }
@@ -41,9 +41,12 @@ var import_path = require("path");
41
41
  var import_AutoUpdateFolderCache = require("./AutoUpdateFolderCache");
42
42
  var import_constant = require("./constant");
43
43
  var AutoUpdateSrcCodeCache = class {
44
+ srcPath;
45
+ cachePath;
46
+ folderCache;
47
+ listeners = [];
48
+ ignores = import_constant.DEFAULT_SRC_IGNORES;
44
49
  constructor(opts) {
45
- this.listeners = [];
46
- this.ignores = import_constant.DEFAULT_SRC_IGNORES;
47
50
  this.srcPath = opts.cwd;
48
51
  this.cachePath = opts.cachePath;
49
52
  this.folderCache = new import_AutoUpdateFolderCache.AutoUpdateFolderCache({
@@ -26,9 +26,12 @@ var import_utils = require("@umijs/utils");
26
26
  var import_path = require("path");
27
27
  var { watch } = import_utils.chokidar;
28
28
  var FolderWatch = class {
29
+ cwd;
30
+ watcher;
31
+ readyPromise;
32
+ listeners = [];
33
+ eventMap = { add: 0, unlink: 0, change: 0 };
29
34
  constructor(opts) {
30
- this.listeners = [];
31
- this.eventMap = { add: 0, unlink: 0, change: 0 };
32
35
  this.cwd = opts.cwd;
33
36
  this.watcher = watch(`./**/*.{${opts.exts.join(",")}}`, {
34
37
  ignored: opts.ignored || [],
@@ -41,12 +41,16 @@ var import_path = require("path");
41
41
  var import_constant = require("./constant");
42
42
  var import_FolderWatch = require("./FolderWatch");
43
43
  var LazySourceCodeCache = class {
44
+ srcPath;
45
+ cachePath;
46
+ folderWatch;
47
+ listeners = [];
48
+ ignores = import_constant.DEFAULT_SRC_IGNORES;
49
+ fileContentCache = {};
50
+ pendingFilesEvents = [];
51
+ root;
52
+ tsConfigRaw = "{}";
44
53
  constructor(opts) {
45
- this.listeners = [];
46
- this.ignores = import_constant.DEFAULT_SRC_IGNORES;
47
- this.fileContentCache = {};
48
- this.pendingFilesEvents = [];
49
- this.tsConfigRaw = "{}";
50
54
  this.root = opts.root;
51
55
  this.srcPath = opts.cwd;
52
56
  this.cachePath = opts.cachePath;
@@ -143,7 +147,7 @@ var LazySourceCodeCache = class {
143
147
  modifiedFiles.push(c.path);
144
148
  break;
145
149
  default:
146
- ((_n) => {
150
+ /* @__PURE__ */ ((_n) => {
147
151
  })(c.event);
148
152
  }
149
153
  }
package/dist/libs/scan.js CHANGED
@@ -62,8 +62,7 @@ async function scanContent(opts) {
62
62
  }
63
63
  ).map((imp) => {
64
64
  let importType = "import" /* import */;
65
- if (imp.d > -1)
66
- importType = "dynamicImport" /* dynamicImport */;
65
+ if (imp.d > -1) importType = "dynamicImport" /* dynamicImport */;
67
66
  if (opts.content.slice(imp.ss, imp.se).startsWith("export ")) {
68
67
  importType = "export" /* export */;
69
68
  }
@@ -110,8 +109,7 @@ async function scan(opts) {
110
109
  const ret = {};
111
110
  while (queueDeps.length) {
112
111
  const depPath = queueDeps.shift();
113
- if (cache.has(depPath))
114
- continue;
112
+ if (cache.has(depPath)) continue;
115
113
  const content = await getContent(depPath);
116
114
  const { deps } = await scanContent({ content });
117
115
  cache.set(depPath, deps);
@@ -96,8 +96,7 @@ async function setupExportExtractBuilder(opts) {
96
96
  setup(build) {
97
97
  let entry;
98
98
  build.onResolve({ filter: /.*/ }, (args) => {
99
- if (args.kind === "entry-point")
100
- entry = args.path;
99
+ if (args.kind === "entry-point") entry = args.path;
101
100
  if (args.kind === "entry-point" || args.importer === entry) {
102
101
  return { path: (0, import_path.resolve)(args.resolveDir, args.path) };
103
102
  }
@@ -28,8 +28,7 @@ function serializeAppData(data) {
28
28
  data,
29
29
  (_, value) => {
30
30
  if (value && typeof value === "object") {
31
- if (cache.has(value))
32
- return;
31
+ if (cache.has(value)) return;
33
32
  cache.add(value);
34
33
  }
35
34
  return value;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@umijs/preset-umi",
3
- "version": "4.4.13-canary.20250917.1",
3
+ "version": "4.5.1",
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",
@@ -43,20 +43,20 @@
43
43
  "react-router": "6.3.0",
44
44
  "react-router-dom": "6.3.0",
45
45
  "regenerator-runtime": "0.13.11",
46
- "@umijs/ast": "4.4.13-canary.20250917.1",
47
- "@umijs/bundler-esbuild": "4.4.13-canary.20250917.1",
48
- "@umijs/babel-preset-umi": "4.4.13-canary.20250917.1",
49
- "@umijs/bundler-utils": "4.4.13-canary.20250917.1",
50
- "@umijs/bundler-webpack": "4.4.13-canary.20250917.1",
51
- "@umijs/bundler-utoopack": "4.4.13-canary.20250917.1",
52
- "@umijs/bundler-vite": "4.4.13-canary.20250917.1",
53
- "@umijs/core": "4.4.13-canary.20250917.1",
54
- "@umijs/plugin-run": "4.4.13-canary.20250917.1",
55
- "@umijs/renderer-react": "4.4.13-canary.20250917.1",
56
- "@umijs/server": "4.4.13-canary.20250917.1",
57
- "@umijs/mfsu": "4.4.13-canary.20250917.1",
58
- "@umijs/utils": "4.4.13-canary.20250917.1",
59
- "@umijs/zod2ts": "4.4.13-canary.20250917.1",
46
+ "@umijs/ast": "4.5.1",
47
+ "@umijs/bundler-vite": "4.5.1",
48
+ "@umijs/bundler-utils": "4.5.1",
49
+ "@umijs/bundler-esbuild": "4.5.1",
50
+ "@umijs/core": "4.5.1",
51
+ "@umijs/plugin-run": "4.5.1",
52
+ "@umijs/utils": "4.5.1",
53
+ "@umijs/bundler-webpack": "4.5.1",
54
+ "@umijs/bundler-utoopack": "4.5.1",
55
+ "@umijs/babel-preset-umi": "4.5.1",
56
+ "@umijs/mfsu": "4.5.1",
57
+ "@umijs/zod2ts": "4.5.1",
58
+ "@umijs/server": "4.5.1",
59
+ "@umijs/renderer-react": "4.5.1",
60
60
  "@umijs/ui": "3.0.1"
61
61
  },
62
62
  "devDependencies": {