@umijs/preset-umi 4.4.11 → 4.4.13-canary.20250910.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,18 +58,11 @@ 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;
66
- if (process.env.MAKO_AD === "none")
67
- return;
68
- console.info(
69
- import_utils.chalk.yellow.bold(
70
- "Mako https://makojs.dev is a new fast Rust based bundler from us, which is heavily optimized for umi and much faster than webpack. Visit https://makojs.dev/docs/getting-started#bundle-with-umi for more details if you want to give it a try."
71
- )
72
- );
73
66
  });
74
67
  api.registerCommand({
75
68
  name: "dev",
@@ -0,0 +1,3 @@
1
+ import { IApi } from '../../types';
2
+ declare const _default: (api: IApi) => void;
3
+ export default _default;
@@ -0,0 +1,93 @@
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/aiDev/aiDev.ts
30
+ var aiDev_exports = {};
31
+ __export(aiDev_exports, {
32
+ default: () => aiDev_default
33
+ });
34
+ module.exports = __toCommonJS(aiDev_exports);
35
+ var import_utils = require("@umijs/utils");
36
+ var import_child_process = require("child_process");
37
+ var import_fs = __toESM(require("fs"));
38
+ var import_path = __toESM(require("path"));
39
+ function checkBinExists(binName) {
40
+ try {
41
+ const command = process.platform === "win32" ? `where ${binName}` : `which ${binName}`;
42
+ (0, import_child_process.execSync)(command, { stdio: "ignore" });
43
+ return true;
44
+ } catch {
45
+ return false;
46
+ }
47
+ }
48
+ var aiDev_default = (api) => {
49
+ api.describe({
50
+ key: "aiDev"
51
+ });
52
+ api.onDevCompileDone((args) => {
53
+ var _a, _b;
54
+ if (api.config.mako || api.config.utoopack) {
55
+ return;
56
+ }
57
+ if (!process.env.UMI_AI_COMMAND || !process.env.UMI_AI_PACKAGE)
58
+ return;
59
+ try {
60
+ const aiCommand = process.env.UMI_AI_COMMAND;
61
+ const aiPackage = process.env.UMI_AI_PACKAGE;
62
+ const aiCommandExists = checkBinExists(aiCommand);
63
+ const npmClient = api.appData.npmClient;
64
+ const hasErrors = ((_b = (_a = args.stats) == null ? void 0 : _a.hasErrors) == null ? void 0 : _b.call(_a)) || false;
65
+ if (hasErrors) {
66
+ const errorStats = args.stats.toString();
67
+ const errorFilePath = import_path.default.join(api.paths.absTmpPath, "devError.txt");
68
+ const relativeErrorFilePath = (0, import_utils.winPath)(
69
+ import_path.default.relative(api.paths.cwd, errorFilePath)
70
+ );
71
+ const prefix = aiCommandExists ? "" : `${npmClient} install -g ${aiPackage} && `;
72
+ try {
73
+ import_fs.default.writeFileSync(errorFilePath, errorStats);
74
+ console.log();
75
+ console.log(import_utils.chalk.red("🤖 AI Dev: Compilation errors detected!"));
76
+ console.log(`Error details saved to: ${errorFilePath}`);
77
+ } catch (err) {
78
+ console.log();
79
+ console.log(import_utils.chalk.red("🤖 AI Dev: Compilation errors detected!"));
80
+ console.log(import_utils.chalk.yellow("⚠️ Could not save error details"));
81
+ }
82
+ console.log(
83
+ import_utils.chalk.yellow(
84
+ `💡 Suggestion: Run \`${prefix}${aiCommand} "fix error in ${relativeErrorFilePath}"\` to get AI assistance`
85
+ )
86
+ );
87
+ console.log();
88
+ }
89
+ } catch (err) {
90
+ console.log(`[AI Dev] Error: ${err}`);
91
+ }
92
+ });
93
+ };
@@ -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);
@@ -0,0 +1,3 @@
1
+ import { IApi } from '../../types';
2
+ declare const _default: (api: IApi) => void;
3
+ export default _default;
@@ -0,0 +1,72 @@
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/stagewise/stagewise.ts
30
+ var stagewise_exports = {};
31
+ __export(stagewise_exports, {
32
+ default: () => stagewise_default
33
+ });
34
+ module.exports = __toCommonJS(stagewise_exports);
35
+ var import_path = __toESM(require("path"));
36
+ var stagewise_default = (api) => {
37
+ api.describe({
38
+ key: "stagewise",
39
+ config: {
40
+ schema(zod) {
41
+ return zod.any();
42
+ }
43
+ },
44
+ enableBy: api.EnableBy.config
45
+ });
46
+ api.onGenerateFiles(() => {
47
+ const stagewiseToolbarPath = import_path.default.join(
48
+ import_path.default.dirname(require.resolve("@stagewise/toolbar")),
49
+ ".."
50
+ );
51
+ api.writeTmpFile({
52
+ path: "stagewise.ts",
53
+ content: `
54
+ import { initToolbar } from '${stagewiseToolbarPath}';
55
+ const stagewiseConfig = ${JSON.stringify(api.config.stagewise, null, 2)};
56
+ function setupStagewise() {
57
+ // Only initialize once and only in development mode
58
+ if (process.env.NODE_ENV === 'development') {
59
+ initToolbar(stagewiseConfig);
60
+ }
61
+ }
62
+ setupStagewise();
63
+ `
64
+ });
65
+ });
66
+ api.addEntryImports(() => {
67
+ if (api.name !== "dev" && api.name !== "setup") {
68
+ return [];
69
+ }
70
+ return [{ source: "@@/plugin-stagewise/stagewise.ts" }];
71
+ });
72
+ };
@@ -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
@@ -40,6 +40,7 @@ var src_default = () => {
40
40
  // features
41
41
  process.env.DID_YOU_KNOW !== "none" && require.resolve("@umijs/did-you-know/dist/plugin"),
42
42
  require.resolve("./features/404/404"),
43
+ require.resolve("./features/aiDev/aiDev"),
43
44
  require.resolve("./features/appData/appData"),
44
45
  require.resolve("./features/appData/umiInfo"),
45
46
  require.resolve("./features/check/check"),
@@ -64,6 +65,7 @@ var src_default = () => {
64
65
  require.resolve("./features/polyfill/publicPathPolyfill"),
65
66
  require.resolve("./features/prepare/prepare"),
66
67
  require.resolve("./features/routePrefetch/routePrefetch"),
68
+ require.resolve("./features/stagewise/stagewise"),
67
69
  require.resolve("./features/terminal/terminal"),
68
70
  // 1. generate tmp files
69
71
  require.resolve("./features/tmpFiles/tmpFiles"),
@@ -86,6 +88,7 @@ var src_default = () => {
86
88
  require.resolve("./features/swc/swc"),
87
89
  require.resolve("./features/ui/ui"),
88
90
  require.resolve("./features/mako/mako"),
91
+ require.resolve("./features/utoopack/utoopack"),
89
92
  require.resolve("./features/hmrGuardian/hmrGuardian"),
90
93
  require.resolve("./features/routePreloadOnLoad/routePreloadOnLoad"),
91
94
  require.resolve("./features/forget/forget"),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@umijs/preset-umi",
3
- "version": "4.4.11",
3
+ "version": "4.4.13-canary.20250910.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",
@@ -20,8 +20,10 @@
20
20
  ],
21
21
  "dependencies": {
22
22
  "@iconify/utils": "2.1.1",
23
+ "@stagewise/toolbar": "0.6.2",
23
24
  "@svgr/core": "6.5.1",
24
25
  "@umijs/bundler-mako": "0.11.10",
26
+ "@umijs/did-you-know": "^1.0.4",
25
27
  "@umijs/es-module-parser": "0.0.7",
26
28
  "@umijs/history": "5.3.1",
27
29
  "babel-plugin-dynamic-import-node": "2.3.3",
@@ -41,21 +43,21 @@
41
43
  "react-router": "6.3.0",
42
44
  "react-router-dom": "6.3.0",
43
45
  "regenerator-runtime": "0.13.11",
44
- "@umijs/ast": "4.4.11",
45
- "@umijs/babel-preset-umi": "4.4.11",
46
- "@umijs/bundler-esbuild": "4.4.11",
47
- "@umijs/bundler-utils": "4.4.11",
48
- "@umijs/bundler-vite": "4.4.11",
49
- "@umijs/bundler-webpack": "4.4.11",
50
- "@umijs/core": "4.4.11",
51
- "@umijs/did-you-know": "1.0.3",
52
- "@umijs/mfsu": "4.4.11",
53
- "@umijs/server": "4.4.11",
54
- "@umijs/renderer-react": "4.4.11",
55
- "@umijs/plugin-run": "4.4.11",
56
- "@umijs/ui": "3.0.1",
57
- "@umijs/utils": "4.4.11",
58
- "@umijs/zod2ts": "4.4.11"
46
+ "@umijs/bundler-utils": "4.4.13-canary.20250910.1",
47
+ "@umijs/babel-preset-umi": "4.4.13-canary.20250910.1",
48
+ "@umijs/ast": "4.4.13-canary.20250910.1",
49
+ "@umijs/bundler-esbuild": "4.4.13-canary.20250910.1",
50
+ "@umijs/bundler-utoopack": "4.4.13-canary.20250910.1",
51
+ "@umijs/core": "4.4.13-canary.20250910.1",
52
+ "@umijs/bundler-webpack": "4.4.13-canary.20250910.1",
53
+ "@umijs/bundler-vite": "4.4.13-canary.20250910.1",
54
+ "@umijs/mfsu": "4.4.13-canary.20250910.1",
55
+ "@umijs/plugin-run": "4.4.13-canary.20250910.1",
56
+ "@umijs/server": "4.4.13-canary.20250910.1",
57
+ "@umijs/renderer-react": "4.4.13-canary.20250910.1",
58
+ "@umijs/utils": "4.4.13-canary.20250910.1",
59
+ "@umijs/zod2ts": "4.4.13-canary.20250910.1",
60
+ "@umijs/ui": "3.0.1"
59
61
  },
60
62
  "devDependencies": {
61
63
  "@manypkg/get-packages": "1.1.3",