@umijs/preset-umi 4.6.1 → 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.
Files changed (41) hide show
  1. package/dist/commands/config/remove.js +2 -1
  2. package/dist/commands/config/set.js +2 -1
  3. package/dist/commands/deadcode.js +2 -1
  4. package/dist/commands/dev/depBuildWorker/depBuildWorker.js +2 -1
  5. package/dist/commands/dev/depBuildWorker/depBuilder.js +6 -5
  6. package/dist/commands/generators/component.js +0 -2
  7. package/dist/commands/generators/page.js +9 -8
  8. package/dist/commands/generators/utils.js +0 -2
  9. package/dist/commands/mfsu/util.js +0 -2
  10. package/dist/features/apiRoute/apiRoute.js +2 -1
  11. package/dist/features/apiRoute/dev-server/esbuild.js +2 -1
  12. package/dist/features/apiRoute/request.js +6 -5
  13. package/dist/features/apiRoute/response.js +0 -1
  14. package/dist/features/apiRoute/utils.js +18 -9
  15. package/dist/features/appData/appData.js +2 -2
  16. package/dist/features/codeSplitting/codeSplitting.js +4 -2
  17. package/dist/features/esmi/Service.js +5 -5
  18. package/dist/features/favicons/favicons.js +4 -2
  19. package/dist/features/icons/svgr.js +4 -2
  20. package/dist/features/mock/createMockMiddleware.js +2 -1
  21. package/dist/features/monorepo/redirect.js +4 -2
  22. package/dist/features/mpa/mpa.js +10 -5
  23. package/dist/features/overrides/overrides.js +2 -1
  24. package/dist/features/overrides/transform.js +4 -2
  25. package/dist/features/phantomDependency/phantomDependency.js +30 -15
  26. package/dist/features/prepare/esbuildPlugins/esbuildAliasPlugin.js +8 -4
  27. package/dist/features/prepare/prepare.js +2 -1
  28. package/dist/features/ssr/builder/css-loader.js +2 -2
  29. package/dist/features/ssr/ssr.js +2 -1
  30. package/dist/features/tmpFiles/getModuleExports.js +2 -2
  31. package/dist/features/tmpFiles/routes.js +7 -6
  32. package/dist/features/transform/CodeFrameError.js +0 -1
  33. package/dist/features/ui/ui.js +2 -1
  34. package/dist/libs/folderCache/AutoUpdateFolderCache.js +3 -9
  35. package/dist/libs/folderCache/AutoUpdateSourceCodeCache.js +2 -5
  36. package/dist/libs/folderCache/FolderWatch.js +2 -5
  37. package/dist/libs/folderCache/LazySourceCodeCache.js +6 -10
  38. package/dist/libs/scan.js +4 -2
  39. package/dist/utils/routeExportExtractor.js +2 -1
  40. package/dist/utils/serializeAppData.js +2 -1
  41. package/package.json +16 -16
@@ -26,7 +26,8 @@ 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) return;
29
+ if (!ast)
30
+ return;
30
31
  const generateCode = (0, import_ast.generate)((0, import_ast.removeConfigByName)(ast, name));
31
32
  const prettier = require("@umijs/utils/compiled/prettier");
32
33
  const printStr = prettier.format(generateCode, {
@@ -35,7 +35,8 @@ 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) return;
38
+ if (!ast)
39
+ return;
39
40
  const generateCode = (0, import_ast.generate)((0, import_ast.setConfigByName)(ast, name, value));
40
41
  const prettier = require("@umijs/utils/compiled/prettier");
41
42
  const printStr = prettier.format(generateCode, {
@@ -205,7 +205,8 @@ 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) import_utils.logger.wait("generating file...");
208
+ if (gitInfo)
209
+ import_utils.logger.wait("generating file...");
209
210
  await outputUnusedFiles(unusedFiles, recordJsonPath, {
210
211
  gitInfo,
211
212
  cwd
@@ -114,7 +114,8 @@ 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)) return a;
117
+ if (Array.isArray(a))
118
+ return a;
118
119
  return [a];
119
120
  }
120
121
  function setupWorkerEnv() {
@@ -45,10 +45,9 @@ 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;
51
48
  constructor(opts) {
49
+ this.completeFns = [];
50
+ this.isBuilding = false;
52
51
  this.opts = opts;
53
52
  }
54
53
  async buildWithWebpack(opts) {
@@ -155,8 +154,10 @@ var DepBuilderInWorker = class {
155
154
  depConfig.output.path = this.opts.tmpBase;
156
155
  depConfig.output.publicPath = "auto";
157
156
  depConfig.devtool = false;
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;
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;
160
161
  depConfig.optimization || (depConfig.optimization = {});
161
162
  depConfig.optimization.splitChunks = {
162
163
  chunks: (chunk) => {
@@ -74,8 +74,6 @@ var ComponentGenerator = class {
74
74
  this.name = name;
75
75
  this.dir = dir;
76
76
  }
77
- name;
78
- dir;
79
77
  async run() {
80
78
  const { appRoot, args } = this.opts;
81
79
  const capitalizeName = import_utils.lodash.upperFirst(this.name);
@@ -59,6 +59,13 @@ 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 = [];
62
69
  this.isDirMode = !!options.args.dir;
63
70
  this.importSource = options.importSource || "umi";
64
71
  const [_, ...inputPaths] = options.args._;
@@ -68,13 +75,6 @@ var PageGenerator = class {
68
75
  this.needEnsureDirMode = true;
69
76
  }
70
77
  }
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,7 +129,8 @@ var PageGenerator = class {
129
129
  this.isDirMode = false;
130
130
  }
131
131
  async ensureDirMode() {
132
- if (!this.needEnsureDirMode) return;
132
+ if (!this.needEnsureDirMode)
133
+ return;
133
134
  const response = await this.prompts({
134
135
  type: "select",
135
136
  name: "mode",
@@ -60,8 +60,6 @@ var GeneratorHelper = class {
60
60
  this.needInstallUmiPlugin = needInstall;
61
61
  this.needConfigUmiPlugin = needConfigPlugins;
62
62
  }
63
- needConfigUmiPlugin;
64
- needInstallUmiPlugin;
65
63
  setUmirc(key, val) {
66
64
  (0, import_set.set)(this.api, key, val);
67
65
  }
@@ -49,8 +49,6 @@ 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;
54
52
  async prepare() {
55
53
  var _a, _b, _c, _d;
56
54
  const api = this.api;
@@ -66,7 +66,8 @@ 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) return false;
69
+ if (!hasApiRoutes)
70
+ return false;
70
71
  const config = api.userConfig.apiRoute;
71
72
  if (!config) {
72
73
  return false;
@@ -55,7 +55,8 @@ 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) import_utils.logger.error("Compile api routes failed: ", error);
58
+ if (error)
59
+ import_utils.logger.error("Compile api routes failed: ", error);
59
60
  Object.keys(require.cache).forEach((modulePath) => {
60
61
  if (modulePath.startsWith((0, import_path.join)(api.paths.cwd, import_constants.OUTPUT_PATH)))
61
62
  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 = {};
31
29
  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) this._params = m.params;
34
+ if (m)
35
+ this._params = m.params;
35
36
  }
36
37
  get params() {
37
38
  return this._params;
38
39
  }
39
- _body = null;
40
40
  get body() {
41
41
  return this._body;
42
42
  }
@@ -128,7 +128,8 @@ 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) return acc;
131
+ if (!name)
132
+ return acc;
132
133
  const fileName = (_b = meta.split('filename="')[1]) == null ? void 0 : _b.split('"')[0];
133
134
  if (fileName) {
134
135
  const fileBufferBeforeTrim = Buffer.from(hexValue, "hex");
@@ -23,7 +23,6 @@ __export(response_exports, {
23
23
  });
24
24
  module.exports = __toCommonJS(response_exports);
25
25
  var UmiApiResponse = class {
26
- _res;
27
26
  constructor(res) {
28
27
  this._res = res;
29
28
  }
@@ -34,30 +34,39 @@ function esbuildIgnorePathPrefixPlugin() {
34
34
  };
35
35
  }
36
36
  function matchApiRoute(apiRoutes, path) {
37
- if (path.startsWith("/")) path = path.substring(1);
38
- if (path.startsWith("api/")) path = path.substring(4);
37
+ if (path.startsWith("/"))
38
+ path = path.substring(1);
39
+ if (path.startsWith("api/"))
40
+ path = path.substring(4);
39
41
  const pathSegments = path.split("/").filter((p) => p !== "");
40
42
  if (pathSegments.length === 0 || pathSegments.length === 1 && pathSegments[0] === "api") {
41
43
  const route2 = apiRoutes.find((r) => r.path === "/");
42
- if (route2) return { route: route2, params: {} };
43
- else return void 0;
44
+ if (route2)
45
+ return { route: route2, params: {} };
46
+ else
47
+ return void 0;
44
48
  }
45
49
  const params = {};
46
50
  const route = apiRoutes.find((route2) => {
47
51
  const routePathSegments = route2.path.split("/").filter((p) => p !== "");
48
- if (routePathSegments.length !== pathSegments.length) return false;
52
+ if (routePathSegments.length !== pathSegments.length)
53
+ return false;
49
54
  for (let i = 0; i < routePathSegments.length; i++) {
50
55
  const routePathSegment = routePathSegments[i];
51
56
  if (routePathSegment.match(/^\[.*]$/)) {
52
57
  params[routePathSegment.substring(1, routePathSegment.length - 1)] = pathSegments[i];
53
- if (i == routePathSegments.length - 1) return true;
58
+ if (i == routePathSegments.length - 1)
59
+ return true;
54
60
  continue;
55
61
  }
56
- if (routePathSegment !== pathSegments[i]) return false;
57
- if (i == routePathSegments.length - 1) return true;
62
+ if (routePathSegment !== pathSegments[i])
63
+ return false;
64
+ if (i == routePathSegments.length - 1)
65
+ return true;
58
66
  }
59
67
  });
60
- if (route) return { route, params };
68
+ if (route)
69
+ return { route, params };
61
70
  }
62
71
  // Annotate the CommonJS export names for ESM import in node:
63
72
  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 [_, exports2] = await bundlerUtils.parseModule({
163
+ const [_, exports] = 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: exports2
169
+ exports
170
170
  };
171
171
  }
172
172
  }
@@ -49,7 +49,8 @@ var codeSplitting_default = (api) => {
49
49
  enableBy: api.EnableBy.config
50
50
  });
51
51
  api.chainWebpack((memo) => {
52
- if (api.env !== "production") return;
52
+ if (api.env !== "production")
53
+ return;
53
54
  const { jsStrategy, jsStrategyOptions, cssStrategy } = api.config.codeSplitting;
54
55
  if (jsStrategy === "bigVendors") {
55
56
  memo.optimization.splitChunks({
@@ -74,7 +75,8 @@ var codeSplitting_default = (api) => {
74
75
  name(module2) {
75
76
  const path = module2.context.replace(/.pnpm[\\/]/, "");
76
77
  const match = path.match(/[\\/]node_modules[\\/](.*?)([\\/]|$)/);
77
- if (!match) return "npm.unknown";
78
+ if (!match)
79
+ return "npm.unknown";
78
80
  const packageName = match[1];
79
81
  return `npm.${packageName.replace(/@/g, "_at_").replace(/\+/g, "_")}`;
80
82
  }
@@ -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 _ESMIService {
40
- cdnOrigin = "";
41
- cacheDir = "";
42
- cache = {};
39
+ var ESMIService = class {
43
40
  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 _ESMIService {
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,7 +44,8 @@ var favicons_default = (api) => {
44
44
  }
45
45
  });
46
46
  api.modifyAppData(async (memo) => {
47
- if (api.config.favicons) return memo;
47
+ if (api.config.favicons)
48
+ return memo;
48
49
  const faviconFiles = getFaviconFiles(api.paths.absSrcPath);
49
50
  if (faviconFiles) {
50
51
  memo.faviconFiles = faviconFiles;
@@ -64,7 +65,8 @@ var favicons_default = (api) => {
64
65
  }
65
66
  ]);
66
67
  api.onBuildComplete(({ err }) => {
67
- if (err) return;
68
+ if (err)
69
+ return;
68
70
  if (api.appData.faviconFiles) {
69
71
  api.appData.faviconFiles.forEach((e) => {
70
72
  (0, import_fs.copyFileSync)(
@@ -74,8 +74,10 @@ 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";')) return false;
78
- if (line.startsWith("export default ")) return false;
77
+ if (line.startsWith('import * as React from "react";'))
78
+ return false;
79
+ if (line.startsWith("export default "))
80
+ return false;
79
81
  return true;
80
82
  }).join("\n");
81
83
  }
@@ -40,7 +40,8 @@ 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) continue;
43
+ if (mock.method !== method)
44
+ continue;
44
45
  const { keys, re } = getPathReAndKeys(mock.path);
45
46
  const m = re.exec(req.path);
46
47
  if (m) {
@@ -68,7 +68,8 @@ 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) return memo;
71
+ if (!rootPkg)
72
+ return memo;
72
73
  const root = (0, import_path.dirname)(rootPkg);
73
74
  (0, import_assert.default)(
74
75
  (0, import_utils.isMonorepo)({ root }),
@@ -83,7 +84,8 @@ var redirect_default = (api) => {
83
84
  const usingDeps = collectPkgDeps(api.pkg).filter((name) => {
84
85
  return !exclude.some((reg) => reg.test(name));
85
86
  });
86
- if (!usingDeps.length) return memo;
87
+ if (!usingDeps.length)
88
+ return memo;
87
89
  const projects = await collectAllProjects({ root });
88
90
  const alias = usingDeps.reduce((obj, name) => {
89
91
  const pkgInfo = projects[name];
@@ -107,7 +107,8 @@ ${renderer}
107
107
  });
108
108
  });
109
109
  api.modifyEntry((memo) => {
110
- if ("umi" in memo) delete memo["umi"];
110
+ if ("umi" in memo)
111
+ delete memo["umi"];
111
112
  api.appData.mpa.entry.forEach((entry) => {
112
113
  memo[entry.name] = (0, import_path.join)(api.paths.absTmpPath, entry.tmpFilePath);
113
114
  });
@@ -176,10 +177,14 @@ async function collectEntry(root, opts, mountElementId) {
176
177
  );
177
178
  }
178
179
  function getIndexFile(dir) {
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");
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");
183
188
  return null;
184
189
  }
185
190
  async function getConfig(indexFile) {
@@ -38,7 +38,8 @@ 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) return;
41
+ if (content === cachedContent)
42
+ return;
42
43
  const subPath = "core/overrides.css";
43
44
  const targetPath = (0, import_path.join)(api.paths.absTmpPath, subPath);
44
45
  const isLess = filePath.endsWith(".less");
@@ -43,8 +43,10 @@ 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("~")) return;
47
- if (origin.startsWith("/")) return;
46
+ if (origin.startsWith("~"))
47
+ return;
48
+ if (origin.startsWith("/"))
49
+ return;
48
50
  function getResolvedPath(origin2) {
49
51
  return (0, import_utils.winPath)(import_path.default.resolve(import_path.default.dirname(filePath), origin2));
50
52
  }
@@ -57,10 +57,14 @@ 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/")) continue;
61
- if (winP.includes("/node_modules/")) continue;
62
- if (winP.startsWith("../")) continue;
63
- if (import_path.default.isAbsolute(file)) continue;
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;
64
68
  const { imports } = result.metafile.inputs[file];
65
69
  for (const imp of imports) {
66
70
  if (imp.kind === "import-statement" && imp.external) {
@@ -73,17 +77,27 @@ var phantomDependency_default = (api) => {
73
77
  }
74
78
  const phantomDeps = [];
75
79
  for (const [source, files2] of importsBySource) {
76
- if (source.startsWith("<")) continue;
77
- if (source.startsWith(".")) continue;
78
- if (source.startsWith("/")) continue;
79
- if (source.startsWith("@/") || source.startsWith("@@/")) continue;
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;
80
88
  const pkgName = getPkgName(source);
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;
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;
87
101
  phantomDeps.push(source);
88
102
  import_utils.logger.error(
89
103
  `[phantomDependency] ${import_utils.chalk.red(
@@ -104,7 +118,8 @@ var phantomDependency_default = (api) => {
104
118
  });
105
119
  function getPkgName(source) {
106
120
  const arr = source.split("/");
107
- if (source.startsWith("@")) return arr[0] + "/" + arr[1];
121
+ if (source.startsWith("@"))
122
+ return arr[0] + "/" + arr[1];
108
123
  return arr[0];
109
124
  }
110
125
  function matchAlias(source, alias) {
@@ -53,10 +53,14 @@ 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)) return 0;
57
- if (a.endsWith(opts.affix)) return -1;
58
- if (b.endsWith(opts.affix)) return 1;
59
- else return 0;
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;
60
64
  });
61
65
  }
62
66
  function addSlashAffix(key) {
@@ -84,7 +84,8 @@ var prepare_default = (api) => {
84
84
  if (api.appData.framework === "vue") {
85
85
  return;
86
86
  }
87
- if (!isFirstTime) return;
87
+ if (!isFirstTime)
88
+ return;
88
89
  import_utils.logger.info("Preparing...");
89
90
  const umiEntry = import_path.default.join(api.paths.absTmpPath, "umi.ts");
90
91
  const entryPoints = [umiEntry];
@@ -38,7 +38,7 @@ function hashString(str) {
38
38
  return hash;
39
39
  }
40
40
  function getClassNames(code, filename) {
41
- const { exports: exports2 } = import_parcelCSS.parcelCSS.transform({
41
+ const { exports } = 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(exports2 || {});
51
+ return Object.keys(exports || {});
52
52
  }
53
53
  function cssLoader(opts) {
54
54
  return {
@@ -203,7 +203,8 @@ export type {
203
203
  }
204
204
  });
205
205
  api.onBuildComplete(async ({ err }) => {
206
- if (err) return;
206
+ if (err)
207
+ return;
207
208
  if (api.config.ssr.platform === "vercel") {
208
209
  const jsonFile = (0, import_path.join)(api.cwd, "vercel.json");
209
210
  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 [_, exports2] = await (0, import_bundler_utils.parseModule)({ content, path: file });
33
- return exports2 || [];
32
+ const [_, exports] = await (0, import_bundler_utils.parseModule)({ content, path: file });
33
+ return exports || [];
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 exports2 = isJSFile && (0, import_fs.existsSync)(file) ? await (0, import_getModuleExports.getModuleExports)({
154
+ const exports = isJSFile && (0, import_fs.existsSync)(file) ? await (0, import_getModuleExports.getModuleExports)({
155
155
  file
156
156
  }) : [];
157
157
  if (enableSSR) {
158
- routes[id].hasServerLoader = exports2.includes("serverLoader");
159
- routes[id].hasMetadataLoader = exports2.includes("metadataLoader");
158
+ routes[id].hasServerLoader = exports.includes("serverLoader");
159
+ routes[id].hasMetadataLoader = exports.includes("metadataLoader");
160
160
  }
161
- if (enableClientLoader && exports2.includes("clientLoader")) {
161
+ if (enableClientLoader && exports.includes("clientLoader")) {
162
162
  routes[id].clientLoader = `clientLoaders['${id}']`;
163
163
  }
164
- if (enableRouteProps && exports2.includes("routeProps")) {
164
+ if (enableRouteProps && exports.includes("routeProps")) {
165
165
  routes[id].routeProps = `routeProps['${id}']`;
166
166
  }
167
167
  }
@@ -239,7 +239,8 @@ 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) break;
242
+ if (!rootCwd)
243
+ break;
243
244
  if ((0, import_utils.isMonorepo)({ root: rootCwd })) {
244
245
  return rootCwd;
245
246
  }
@@ -23,7 +23,6 @@ __export(CodeFrameError_exports, {
23
23
  });
24
24
  module.exports = __toCommonJS(CodeFrameError_exports);
25
25
  var CodeFrameError = class extends Error {
26
- location;
27
26
  constructor(msg, location) {
28
27
  super(msg);
29
28
  this.location = location;
@@ -124,7 +124,8 @@ var ui_default = (api) => {
124
124
  return memo;
125
125
  });
126
126
  api.onGenerateFiles(({ isFirstTime }) => {
127
- if (!isFirstTime) return;
127
+ if (!isFirstTime)
128
+ return;
128
129
  api.writeTmpFile({
129
130
  path: "core/ui.ts",
130
131
  noPluginDir: true,
@@ -27,15 +27,9 @@ 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;
38
30
  constructor(opts) {
31
+ this.fileContentCache = {};
32
+ this.pendingChanges = [];
39
33
  this.cwd = opts.cwd;
40
34
  this.onCacheUpdated = opts.onCacheUpdate;
41
35
  this.filesLoader = opts.filesLoader || this._defaultLoader;
@@ -65,7 +59,7 @@ var AutoUpdateFolderCache = class {
65
59
  modifiedFiles.push(c.path);
66
60
  break;
67
61
  default:
68
- /* @__PURE__ */ ((_n) => {
62
+ ((_n) => {
69
63
  })(c.event);
70
64
  }
71
65
  }
@@ -41,12 +41,9 @@ 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;
49
44
  constructor(opts) {
45
+ this.listeners = [];
46
+ this.ignores = import_constant.DEFAULT_SRC_IGNORES;
50
47
  this.srcPath = opts.cwd;
51
48
  this.cachePath = opts.cachePath;
52
49
  this.folderCache = new import_AutoUpdateFolderCache.AutoUpdateFolderCache({
@@ -26,12 +26,9 @@ 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 };
34
29
  constructor(opts) {
30
+ this.listeners = [];
31
+ this.eventMap = { add: 0, unlink: 0, change: 0 };
35
32
  this.cwd = opts.cwd;
36
33
  this.watcher = watch(`./**/*.{${opts.exts.join(",")}}`, {
37
34
  ignored: opts.ignored || [],
@@ -41,16 +41,12 @@ 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 = "{}";
53
44
  constructor(opts) {
45
+ this.listeners = [];
46
+ this.ignores = import_constant.DEFAULT_SRC_IGNORES;
47
+ this.fileContentCache = {};
48
+ this.pendingFilesEvents = [];
49
+ this.tsConfigRaw = "{}";
54
50
  this.root = opts.root;
55
51
  this.srcPath = opts.cwd;
56
52
  this.cachePath = opts.cachePath;
@@ -147,7 +143,7 @@ var LazySourceCodeCache = class {
147
143
  modifiedFiles.push(c.path);
148
144
  break;
149
145
  default:
150
- /* @__PURE__ */ ((_n) => {
146
+ ((_n) => {
151
147
  })(c.event);
152
148
  }
153
149
  }
package/dist/libs/scan.js CHANGED
@@ -62,7 +62,8 @@ async function scanContent(opts) {
62
62
  }
63
63
  ).map((imp) => {
64
64
  let importType = "import" /* import */;
65
- if (imp.d > -1) importType = "dynamicImport" /* dynamicImport */;
65
+ if (imp.d > -1)
66
+ importType = "dynamicImport" /* dynamicImport */;
66
67
  if (opts.content.slice(imp.ss, imp.se).startsWith("export ")) {
67
68
  importType = "export" /* export */;
68
69
  }
@@ -109,7 +110,8 @@ async function scan(opts) {
109
110
  const ret = {};
110
111
  while (queueDeps.length) {
111
112
  const depPath = queueDeps.shift();
112
- if (cache.has(depPath)) continue;
113
+ if (cache.has(depPath))
114
+ continue;
113
115
  const content = await getContent(depPath);
114
116
  const { deps } = await scanContent({ content });
115
117
  cache.set(depPath, deps);
@@ -96,7 +96,8 @@ async function setupExportExtractBuilder(opts) {
96
96
  setup(build) {
97
97
  let entry;
98
98
  build.onResolve({ filter: /.*/ }, (args) => {
99
- if (args.kind === "entry-point") entry = args.path;
99
+ if (args.kind === "entry-point")
100
+ entry = args.path;
100
101
  if (args.kind === "entry-point" || args.importer === entry) {
101
102
  return { path: (0, import_path.resolve)(args.resolveDir, args.path) };
102
103
  }
@@ -28,7 +28,8 @@ function serializeAppData(data) {
28
28
  data,
29
29
  (_, value) => {
30
30
  if (value && typeof value === "object") {
31
- if (cache.has(value)) return;
31
+ if (cache.has(value))
32
+ return;
32
33
  cache.add(value);
33
34
  }
34
35
  return value;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@umijs/preset-umi",
3
- "version": "4.6.1",
3
+ "version": "4.6.2",
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,21 +43,21 @@
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.6.1",
47
- "@umijs/bundler-esbuild": "4.6.1",
48
- "@umijs/bundler-utoopack": "4.6.1",
49
- "@umijs/bundler-vite": "4.6.1",
50
- "@umijs/babel-preset-umi": "4.6.1",
51
- "@umijs/bundler-utils": "4.6.1",
52
- "@umijs/bundler-webpack": "4.6.1",
53
- "@umijs/core": "4.6.1",
54
- "@umijs/plugin-run": "4.6.1",
55
- "@umijs/renderer-react": "4.6.1",
56
- "@umijs/server": "4.6.1",
57
- "@umijs/ui": "3.0.1",
58
- "@umijs/utils": "4.6.1",
59
- "@umijs/zod2ts": "4.6.1",
60
- "@umijs/mfsu": "4.6.1"
46
+ "@umijs/ast": "4.6.2",
47
+ "@umijs/babel-preset-umi": "4.6.2",
48
+ "@umijs/bundler-esbuild": "4.6.2",
49
+ "@umijs/bundler-utils": "4.6.2",
50
+ "@umijs/bundler-utoopack": "4.6.2",
51
+ "@umijs/bundler-vite": "4.6.2",
52
+ "@umijs/bundler-webpack": "4.6.2",
53
+ "@umijs/core": "4.6.2",
54
+ "@umijs/mfsu": "4.6.2",
55
+ "@umijs/plugin-run": "4.6.2",
56
+ "@umijs/renderer-react": "4.6.2",
57
+ "@umijs/server": "4.6.2",
58
+ "@umijs/utils": "4.6.2",
59
+ "@umijs/zod2ts": "4.6.2",
60
+ "@umijs/ui": "3.0.1"
61
61
  },
62
62
  "devDependencies": {
63
63
  "@manypkg/get-packages": "1.1.3",