@umijs/preset-umi 4.4.12 → 4.4.13-canary.20250911.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.
@@ -34,7 +34,7 @@ function createRouteMiddleware(opts) {
34
34
  onStats == null ? void 0 : onStats(stats);
35
35
  });
36
36
  async function getStats(api) {
37
- if (!compiler && api.config.mako) {
37
+ if (!compiler && (api.config.mako || api.config.utoopack)) {
38
38
  return {
39
39
  compilation: { assets: { "umi.js": "umi.js", "umi.css": "umi.css" } },
40
40
  hasErrors: () => false
@@ -58,8 +58,8 @@ var dev_default = (api) => {
58
58
  }
59
59
  });
60
60
  api.onStart(() => {
61
- var _a;
62
- if ((_a = api.config) == null ? void 0 : _a.mako)
61
+ var _a, _b;
62
+ if (((_a = api.config) == null ? void 0 : _a.mako) || ((_b = api.config) == null ? void 0 : _b.utoopack))
63
63
  return;
64
64
  if (process.env.BIGFISH_INFO)
65
65
  return;
@@ -51,7 +51,7 @@ var aiDev_default = (api) => {
51
51
  });
52
52
  api.onDevCompileDone((args) => {
53
53
  var _a, _b;
54
- if (api.config.mako) {
54
+ if (api.config.mako || api.config.utoopack) {
55
55
  return;
56
56
  }
57
57
  if (!process.env.UMI_AI_COMMAND || !process.env.UMI_AI_PACKAGE)
@@ -35,6 +35,10 @@ var bundler_default = (api) => {
35
35
  require("@umijs/bundler-webpack/dist/requireHook");
36
36
  return require(process.env.OKAM);
37
37
  }
38
+ if (bundler === "utoopack") {
39
+ require("@umijs/bundler-webpack/dist/requireHook");
40
+ return require(process.env.UTOOPACK);
41
+ }
38
42
  if (bundler === "vite") {
39
43
  return bundlerVite;
40
44
  }
@@ -109,7 +109,7 @@ var esbuildHelperChecker_default = (api) => {
109
109
  }
110
110
  });
111
111
  api.onBuildComplete(async ({ err }) => {
112
- if (api.config.vite || api.config.mako)
112
+ if (api.config.vite || api.config.mako || api.config.utoopack)
113
113
  return;
114
114
  if (err)
115
115
  return;
@@ -47,6 +47,11 @@ var forget_default = (api) => {
47
47
  `forget is not compatible with mako, please disable mako first.`
48
48
  );
49
49
  }
50
+ if (api.config.utoopack) {
51
+ throw new Error(
52
+ `forget is not compatible with utoopack, please disable utoopack first.`
53
+ );
54
+ }
50
55
  });
51
56
  api.onCheck(() => {
52
57
  let reactMajorVersion = api.appData.react.version.split(".")[0];
@@ -64,7 +64,7 @@ async function getRouteChunkFilesMap(chunks, opts) {
64
64
  if (chunk.entry)
65
65
  continue;
66
66
  const pickedFiles = pickPreloadFiles(chunk.files);
67
- const routeOrigins = chunk.origins.filter(
67
+ const routeOrigins = (chunk.origins || []).filter(
68
68
  (origin) => {
69
69
  var _a2;
70
70
  return (_a2 = origin.moduleName) == null ? void 0 : _a2.endsWith(routeModuleName);
@@ -110,7 +110,7 @@ var tmpFiles_default = (api) => {
110
110
  [`${api.appData.umi.importSource}/typings`]: [
111
111
  `${umiTempDir}/typings`
112
112
  ],
113
- ...api.config.vite ? {
113
+ ...api.config.vite || api.config.utoopack ? {
114
114
  "@fs/*": ["*"]
115
115
  } : {}
116
116
  }
@@ -674,8 +674,8 @@ if (process.env.NODE_ENV === 'development') {
674
674
  for (const plugin of allPlugins) {
675
675
  const file = (0, import_utils.winPath)((0, import_path.join)(api.paths.absTmpPath, plugin, "types.d.ts"));
676
676
  if ((0, import_fs.existsSync)(file)) {
677
- const noSuffixFile = file.replace(/\.ts$/, "");
678
- beforeExports.push(`export * from '${noSuffixFile}';`);
677
+ const noSuffixFile = file.replace(/\.d\.ts$/, "");
678
+ beforeExports.push(`export type * from '${noSuffixFile}';`);
679
679
  }
680
680
  }
681
681
  let pluginIndex = 0;
@@ -687,7 +687,7 @@ if (process.env.NODE_ENV === 'development') {
687
687
  );
688
688
  if ((0, import_fs.existsSync)(runtimeConfigFile)) {
689
689
  const noSuffixRuntimeConfigFile = runtimeConfigFile.replace(
690
- /\.ts$/,
690
+ /\.d\.ts$/,
691
691
  ""
692
692
  );
693
693
  beforeImport.push(
@@ -0,0 +1,3 @@
1
+ import { IApi } from '../../types';
2
+ declare const _default: (api: IApi) => void;
3
+ export default _default;
@@ -0,0 +1,143 @@
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/utoopack/utoopack.ts
30
+ var utoopack_exports = {};
31
+ __export(utoopack_exports, {
32
+ default: () => utoopack_default
33
+ });
34
+ module.exports = __toCommonJS(utoopack_exports);
35
+ var import_bundler_utoopack = require("@umijs/bundler-utoopack");
36
+ var import_path = require("path");
37
+ var import_extractEntryAssets = require("../../utils/extractEntryAssets");
38
+ var utoopack_default = (api) => {
39
+ api.describe({
40
+ key: "utoopack",
41
+ config: {
42
+ schema({ zod }) {
43
+ return zod.object({}).partial();
44
+ }
45
+ },
46
+ enableBy: api.EnableBy.config
47
+ });
48
+ const assets = {
49
+ // Will contain all js and mjs files
50
+ js: [],
51
+ // Will contain all css files
52
+ css: []
53
+ };
54
+ api.modifyAppData((memo) => {
55
+ memo.bundler = "utoopack";
56
+ return memo;
57
+ });
58
+ api.modifyConfig((memo, args) => {
59
+ const rootDir = memo.rootDir ? (0, import_path.join)(args.paths.cwd, memo.rootDir).replace(/\/$/, "") : (0, import_bundler_utoopack.findRootDir)(args.paths.cwd).replace(/\/$/, "");
60
+ memo.alias = {
61
+ ...memo.alias,
62
+ "@/*": `${args.paths.absSrcPath}/*`,
63
+ "@@/*": `${args.paths.absTmpPath}/*`,
64
+ [`${rootDir}/*`]: `${rootDir}/*`
65
+ };
66
+ return {
67
+ ...memo,
68
+ mfsu: false,
69
+ hmrGuardian: false,
70
+ utoopack: {
71
+ ...memo.utoopack
72
+ }
73
+ };
74
+ });
75
+ api.onStart(() => {
76
+ process.env.UTOOPACK = process.env.UTOOPACK || require.resolve("@umijs/bundler-utoopack");
77
+ try {
78
+ const pkg = require((0, import_path.join)(
79
+ require.resolve(process.env.UTOOPACK),
80
+ "../../package.json"
81
+ ));
82
+ api.logger.info(`Using @utoo/pack@${pkg.dependencies["@utoo/pack"]}`);
83
+ } catch (e) {
84
+ console.error(e);
85
+ }
86
+ });
87
+ api.onDevCompileDone(({ stats }) => {
88
+ var _a, _b, _c;
89
+ const entryPointFiles = /* @__PURE__ */ new Set();
90
+ for (const chunk of ((_b = (_a = stats.entrypoints) == null ? void 0 : _a["umi"]) == null ? void 0 : _b.chunks) || []) {
91
+ const files = ((_c = ((stats == null ? void 0 : stats.chunks) || []).find((c) => (c == null ? void 0 : c.id) === chunk)) == null ? void 0 : _c.files) || [];
92
+ for (const file of files) {
93
+ entryPointFiles.add(file);
94
+ }
95
+ }
96
+ const entryAssets = (0, import_extractEntryAssets.extractEntryAssets)(Array.from(entryPointFiles));
97
+ Object.entries(entryAssets).forEach(([ext, files]) => {
98
+ if (!Array.isArray(assets[ext])) {
99
+ assets[ext] = [];
100
+ }
101
+ assets[ext].push(...files);
102
+ });
103
+ const allAssets = (stats.assets || []).map((asset) => asset.name);
104
+ for (const asset of allAssets) {
105
+ if (asset.endsWith(".js") && !assets.js.includes(asset) && !asset.includes("umi.js")) {
106
+ assets.js.push(asset);
107
+ } else if (asset.endsWith(".css") && !assets.css.includes(asset)) {
108
+ assets.css.push(asset);
109
+ }
110
+ }
111
+ });
112
+ api.onBuildComplete(({ stats }) => {
113
+ var _a, _b, _c;
114
+ const entryPointFiles = /* @__PURE__ */ new Set();
115
+ for (const chunk of ((_b = (_a = stats.entrypoints) == null ? void 0 : _a["umi"]) == null ? void 0 : _b.chunks) || []) {
116
+ const files = ((_c = ((stats == null ? void 0 : stats.chunks) || []).find((c) => (c == null ? void 0 : c.id) === chunk)) == null ? void 0 : _c.files) || [];
117
+ for (const file of files) {
118
+ entryPointFiles.add(file);
119
+ }
120
+ }
121
+ const entryAssets = (0, import_extractEntryAssets.extractEntryAssets)(Array.from(entryPointFiles));
122
+ Object.entries(entryAssets).forEach(([ext, files]) => {
123
+ if (!Array.isArray(assets[ext])) {
124
+ assets[ext] = [];
125
+ }
126
+ assets[ext].push(...files);
127
+ });
128
+ });
129
+ api.addHTMLStyles(() => {
130
+ const { publicPath } = api.config;
131
+ const displayPublicPath = publicPath === "auto" ? "/" : publicPath;
132
+ return assets.css.map((css) => {
133
+ return `${displayPublicPath}${css}`;
134
+ });
135
+ });
136
+ api.addHTMLHeadScripts(() => {
137
+ const { publicPath } = api.config;
138
+ const displayPublicPath = publicPath === "auto" ? "/" : publicPath;
139
+ return assets.js.map((js) => {
140
+ return `${displayPublicPath}${js}`;
141
+ });
142
+ });
143
+ };
package/dist/index.js CHANGED
@@ -88,6 +88,7 @@ var src_default = () => {
88
88
  require.resolve("./features/swc/swc"),
89
89
  require.resolve("./features/ui/ui"),
90
90
  require.resolve("./features/mako/mako"),
91
+ require.resolve("./features/utoopack/utoopack"),
91
92
  require.resolve("./features/hmrGuardian/hmrGuardian"),
92
93
  require.resolve("./features/routePreloadOnLoad/routePreloadOnLoad"),
93
94
  require.resolve("./features/forget/forget"),
@@ -136,9 +136,10 @@ var registerMethods_default = (api) => {
136
136
  content.trim(),
137
137
  ""
138
138
  ].filter((text) => text !== false).join("\n");
139
- if (api.appData.vite && isJsFile) {
139
+ const isUtoopack = api.appData.bundler === "utoopack";
140
+ if ((api.appData.vite || isUtoopack) && isJsFile) {
140
141
  const transformIEAR = transformModule.default;
141
- content = transformIEAR({ content, path: absPath }, api);
142
+ content = transformIEAR({ content, path: absPath }, api, isUtoopack);
142
143
  }
143
144
  if (!(0, import_fs.existsSync)(absPath)) {
144
145
  (0, import_fs.writeFileSync)(absPath, content, "utf-8");
@@ -19,4 +19,4 @@ export declare const IEAR_REG_EXP: RegExp;
19
19
  export default function transformIEAR({ content, path }: {
20
20
  content: string;
21
21
  path: string;
22
- }, api: IApi): string;
22
+ }, api: IApi, isUtoopack?: boolean): string;
@@ -24,6 +24,7 @@ __export(transformIEAR_exports, {
24
24
  });
25
25
  module.exports = __toCommonJS(transformIEAR_exports);
26
26
  var import_bundler_utils = require("@umijs/bundler-utils");
27
+ var import_bundler_utoopack = require("@umijs/bundler-utoopack");
27
28
  var import_utils = require("@umijs/utils");
28
29
  var import_path = require("path");
29
30
  var IEAR_REG_EXP = new RegExp(
@@ -89,7 +90,11 @@ var IEAR_REG_EXP = new RegExp(
89
90
  // match full-content
90
91
  "g"
91
92
  );
92
- function transformIEAR({ content, path }, api) {
93
+ function transformIEAR({ content, path }, api, isUtoopack = false) {
94
+ let rootPath = api.cwd;
95
+ if (isUtoopack) {
96
+ rootPath = (0, import_bundler_utoopack.findRootDir)(api.cwd);
97
+ }
93
98
  return content.replace(IEAR_REG_EXP, (_, prefix, quote, absPath) => {
94
99
  if (absPath.startsWith(api.paths.absTmpPath)) {
95
100
  absPath = (0, import_utils.winPath)((0, import_path.relative)((0, import_path.dirname)(path), absPath)).replace(
@@ -99,6 +104,12 @@ function transformIEAR({ content, path }, api) {
99
104
  );
100
105
  } else if ((0, import_bundler_utils.isDepPath)(absPath)) {
101
106
  absPath = `@fs/${(0, import_utils.winPath)((0, import_path.relative)(api.cwd, absPath))}`;
107
+ } else if (absPath.startsWith(rootPath) && isUtoopack) {
108
+ absPath = (0, import_utils.winPath)((0, import_path.relative)((0, import_path.dirname)(path), absPath)).replace(
109
+ // prepend ./ for same or sub level imports
110
+ /^(?!\.\.\/)/,
111
+ "./"
112
+ );
102
113
  }
103
114
  return `${prefix}${quote}${absPath}${quote}`;
104
115
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@umijs/preset-umi",
3
- "version": "4.4.12",
3
+ "version": "4.4.13-canary.20250911.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,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.4.12",
47
- "@umijs/babel-preset-umi": "4.4.12",
48
- "@umijs/bundler-utils": "4.4.12",
49
- "@umijs/bundler-vite": "4.4.12",
50
- "@umijs/bundler-webpack": "4.4.12",
51
- "@umijs/bundler-esbuild": "4.4.12",
52
- "@umijs/plugin-run": "4.4.12",
53
- "@umijs/core": "4.4.12",
54
- "@umijs/renderer-react": "4.4.12",
55
- "@umijs/server": "4.4.12",
56
- "@umijs/ui": "3.0.1",
57
- "@umijs/utils": "4.4.12",
58
- "@umijs/zod2ts": "4.4.12",
59
- "@umijs/mfsu": "4.4.12"
46
+ "@umijs/ast": "4.4.13-canary.20250911.1",
47
+ "@umijs/bundler-utils": "4.4.13-canary.20250911.1",
48
+ "@umijs/bundler-utoopack": "4.4.13-canary.20250911.1",
49
+ "@umijs/bundler-vite": "4.4.13-canary.20250911.1",
50
+ "@umijs/bundler-webpack": "4.4.13-canary.20250911.1",
51
+ "@umijs/core": "4.4.13-canary.20250911.1",
52
+ "@umijs/mfsu": "4.4.13-canary.20250911.1",
53
+ "@umijs/babel-preset-umi": "4.4.13-canary.20250911.1",
54
+ "@umijs/plugin-run": "4.4.13-canary.20250911.1",
55
+ "@umijs/renderer-react": "4.4.13-canary.20250911.1",
56
+ "@umijs/server": "4.4.13-canary.20250911.1",
57
+ "@umijs/utils": "4.4.13-canary.20250911.1",
58
+ "@umijs/zod2ts": "4.4.13-canary.20250911.1",
59
+ "@umijs/bundler-esbuild": "4.4.13-canary.20250911.1",
60
+ "@umijs/ui": "3.0.1"
60
61
  },
61
62
  "devDependencies": {
62
63
  "@manypkg/get-packages": "1.1.3",