@umijs/preset-umi 4.6.50 → 4.6.52

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.
@@ -65,6 +65,8 @@ var icons_default = (api) => {
65
65
  });
66
66
  const EMPTY_ICONS_FILE = `export const __no_icons = true;`;
67
67
  const icons = /* @__PURE__ */ new Set();
68
+ let noIconsLogged = false;
69
+ let lastGenerateIconsLog = null;
68
70
  api.addPrepareBuildPlugins(() => {
69
71
  return [
70
72
  iconPlugin.esbuildIconPlugin({
@@ -77,10 +79,18 @@ var icons_default = (api) => {
77
79
  const extraIcons = api.config.icons.include || [];
78
80
  const allIcons = /* @__PURE__ */ new Set([...icons, ...extraIcons]);
79
81
  if (!allIcons.size) {
80
- import_utils.logger.info(`[icons] no icons was found`);
82
+ if (!noIconsLogged) {
83
+ import_utils.logger.info(`[icons] no icons was found`);
84
+ noIconsLogged = true;
85
+ }
81
86
  return;
82
87
  }
83
- import_utils.logger.info(`[icons] generate icons ${Array.from(icons).join(", ")}`);
88
+ const iconNames = Array.from(allIcons);
89
+ const generateIconsLog = iconNames.join(", ");
90
+ if (generateIconsLog !== lastGenerateIconsLog) {
91
+ import_utils.logger.info(`[icons] generate icons ${generateIconsLog}`);
92
+ lastGenerateIconsLog = generateIconsLog;
93
+ }
84
94
  const code = [];
85
95
  const { generateIconName, generateSvgr } = svgr;
86
96
  for (const iconStr of allIcons) {
@@ -49,6 +49,9 @@ var ssr_default = (api) => {
49
49
  const makoBuiler = (0, import_utils.importLazy)(
50
50
  require.resolve("./mako/mako")
51
51
  );
52
+ const utoopackBuilder = (0, import_utils.importLazy)(
53
+ require.resolve("./utoopack/utoopack")
54
+ );
52
55
  let serverBuildTarget;
53
56
  api.describe({
54
57
  key: "ssr",
@@ -58,7 +61,7 @@ var ssr_default = (api) => {
58
61
  serverBuildPath: zod.string(),
59
62
  serverBuildTarget: zod.enum(["express", "worker"]),
60
63
  platform: zod.string(),
61
- builder: zod.enum(["esbuild", "webpack", "mako"]),
64
+ builder: zod.enum(["esbuild", "webpack", "mako", "utoopack"]),
62
65
  __INTERNAL_DO_NOT_USE_OR_YOU_WILL_BE_FIRED: zod.object({
63
66
  pureApp: zod.boolean(),
64
67
  pureHtml: zod.boolean()
@@ -107,6 +110,13 @@ var ssr_default = (api) => {
107
110
  memo.ssr.builder = "webpack";
108
111
  }
109
112
  }
113
+ if (memo.ssr.builder === "utoopack") {
114
+ (0, import_assert.default)(
115
+ memo.utoopack,
116
+ `The \`ssr.builder utoopack\` config is now allowed when \`utoopack\` is enable!`
117
+ );
118
+ memo.manifest ?? (memo.manifest = {});
119
+ }
110
120
  return memo;
111
121
  });
112
122
  api.addMiddlewares(() => [
@@ -190,16 +200,22 @@ export type {
190
200
  await webpackBuilder.build(api, opts);
191
201
  } else if (api.config.mako && builder === "mako") {
192
202
  await makoBuiler.build(api);
203
+ } else if (api.config.utoopack && builder === "utoopack") {
204
+ await utoopackBuilder.build(api, opts);
193
205
  }
194
206
  });
195
- api.onDevCompileDone(() => {
207
+ api.onDevCompileDone(({ stats }) => {
196
208
  if (api.config.mako) {
197
209
  (0, import_utils2.generateBuildManifest)(api);
210
+ } else if (api.config.utoopack) {
211
+ (0, import_utils2.generateBuildManifestFromStats)(api, stats);
198
212
  }
199
213
  });
200
- api.onBuildComplete(() => {
214
+ api.onBuildComplete(({ stats }) => {
201
215
  if (api.config.mako) {
202
216
  (0, import_utils2.generateBuildManifest)(api);
217
+ } else if (api.config.utoopack) {
218
+ (0, import_utils2.generateBuildManifestFromStats)(api, stats);
203
219
  }
204
220
  });
205
221
  api.onBuildComplete(async ({ err }) => {
@@ -6,3 +6,4 @@ export declare function esbuildUmiPlugin(api: IApi): {
6
6
  };
7
7
  export declare function absServerBuildPath(api: IApi): string;
8
8
  export declare const generateBuildManifest: (api: IApi) => void;
9
+ export declare const generateBuildManifestFromStats: (api: IApi, stats: any) => void;
@@ -21,7 +21,8 @@ var utils_exports = {};
21
21
  __export(utils_exports, {
22
22
  absServerBuildPath: () => absServerBuildPath,
23
23
  esbuildUmiPlugin: () => esbuildUmiPlugin,
24
- generateBuildManifest: () => generateBuildManifest
24
+ generateBuildManifest: () => generateBuildManifest,
25
+ generateBuildManifestFromStats: () => generateBuildManifestFromStats
25
26
  });
26
27
  module.exports = __toCommonJS(utils_exports);
27
28
  var import_utils = require("@umijs/utils");
@@ -72,9 +73,125 @@ var generateBuildManifest = (api) => {
72
73
  flag: "w"
73
74
  });
74
75
  };
76
+ function addPublicPath(publicPath, file) {
77
+ if (/^(?:https?:)?\/\//.test(file) || file.startsWith("/")) {
78
+ return file;
79
+ }
80
+ if (publicPath === "auto") {
81
+ return `/${file}`;
82
+ }
83
+ return `${publicPath.replace(/\/?$/, "/")}${file}`;
84
+ }
85
+ var assetExts = /* @__PURE__ */ new Set([
86
+ ".png",
87
+ ".jpg",
88
+ ".jpeg",
89
+ ".gif",
90
+ ".webp",
91
+ ".avif",
92
+ ".ico",
93
+ ".woff",
94
+ ".woff2",
95
+ ".ttf",
96
+ ".eot",
97
+ ".mp3",
98
+ ".mp4"
99
+ ]);
100
+ function getOriginalAssetName(file) {
101
+ const ext = (0, import_path.extname)(file);
102
+ return `${(0, import_path.basename)(file, ext).replace(/\.[a-f0-9]{8,}$/i, "")}${ext}`;
103
+ }
104
+ function walkSourceAssets(dir, cwd, ret = []) {
105
+ if (!(0, import_fs.existsSync)(dir)) return ret;
106
+ for (const entry of (0, import_fs.readdirSync)(dir, { withFileTypes: true })) {
107
+ const absPath = (0, import_path.join)(dir, entry.name);
108
+ if (entry.isDirectory()) {
109
+ if ([
110
+ "node_modules",
111
+ "dist",
112
+ "server",
113
+ ".umi",
114
+ ".umi-production",
115
+ ".turbopack"
116
+ ].includes(entry.name)) {
117
+ continue;
118
+ }
119
+ walkSourceAssets(absPath, cwd, ret);
120
+ } else if (assetExts.has((0, import_path.extname)(entry.name))) {
121
+ ret.push(absPath);
122
+ }
123
+ }
124
+ return ret;
125
+ }
126
+ function getSourceAssetMap(api, statsAssets, publicPath) {
127
+ const outputAssets = statsAssets.filter((file) => assetExts.has((0, import_path.extname)(file))).map((file) => {
128
+ const absPath = (0, import_path.join)(api.paths.absOutputPath, file);
129
+ if (!(0, import_fs.existsSync)(absPath)) return null;
130
+ return {
131
+ file,
132
+ name: getOriginalAssetName(file),
133
+ size: (0, import_fs.statSync)(absPath).size
134
+ };
135
+ }).filter(Boolean);
136
+ return walkSourceAssets(api.cwd, api.cwd).reduce((memo, absPath) => {
137
+ const stat = (0, import_fs.statSync)(absPath);
138
+ const matched = outputAssets.find((asset) => {
139
+ return asset.name === (0, import_path.basename)(absPath) && asset.size === stat.size;
140
+ });
141
+ if (matched) {
142
+ memo[(0, import_utils.winPath)((0, import_path.relative)(api.cwd, absPath))] = addPublicPath(
143
+ publicPath,
144
+ matched.file
145
+ );
146
+ }
147
+ return memo;
148
+ }, {});
149
+ }
150
+ var generateBuildManifestFromStats = (api, stats) => {
151
+ var _a;
152
+ const publicPath = api.userConfig.publicPath || "/";
153
+ const buildFilePath = (0, import_path.join)(api.paths.absOutputPath, "build-manifest.json");
154
+ const statsJson = (stats == null ? void 0 : stats.toJson) ? stats.toJson() : stats || {};
155
+ const entrypoint = (_a = statsJson.entrypoints) == null ? void 0 : _a.umi;
156
+ const entryFiles = /* @__PURE__ */ new Set();
157
+ for (const asset of (entrypoint == null ? void 0 : entrypoint.assets) || []) {
158
+ entryFiles.add(typeof asset === "string" ? asset : asset.name);
159
+ }
160
+ for (const chunkId of (entrypoint == null ? void 0 : entrypoint.chunks) || []) {
161
+ const chunk = (statsJson.chunks || []).find((item) => {
162
+ var _a2, _b;
163
+ return (item == null ? void 0 : item.id) === chunkId || ((_b = (_a2 = item == null ? void 0 : item.names) == null ? void 0 : _a2.includes) == null ? void 0 : _b.call(_a2, chunkId));
164
+ });
165
+ for (const file of (chunk == null ? void 0 : chunk.files) || []) {
166
+ entryFiles.add(file);
167
+ }
168
+ }
169
+ const statsAssets = (statsJson.assets || []).map((asset) => typeof asset === "string" ? asset : asset.name).filter(Boolean);
170
+ const files = Array.from(/* @__PURE__ */ new Set([...entryFiles, ...statsAssets])).filter(
171
+ Boolean
172
+ );
173
+ const jsFiles = files.filter((file) => /\.m?js$/.test(file));
174
+ const umiJs = jsFiles.find((file) => /^umi(?:\.[a-f0-9]+)?\.js$/i.test((0, import_path.basename)(file))) || jsFiles[0];
175
+ const finalJsonObj = {
176
+ assets: {
177
+ ...files.reduce((memo, file) => {
178
+ memo[file] = addPublicPath(publicPath, file);
179
+ return memo;
180
+ }, {}),
181
+ ...getSourceAssetMap(api, statsAssets, publicPath)
182
+ }
183
+ };
184
+ if (umiJs) {
185
+ finalJsonObj.assets["umi.js"] = addPublicPath(publicPath, umiJs);
186
+ }
187
+ (0, import_fs.writeFileSync)(buildFilePath, JSON.stringify(finalJsonObj, null, 2), {
188
+ flag: "w"
189
+ });
190
+ };
75
191
  // Annotate the CommonJS export names for ESM import in node:
76
192
  0 && (module.exports = {
77
193
  absServerBuildPath,
78
194
  esbuildUmiPlugin,
79
- generateBuildManifest
195
+ generateBuildManifest,
196
+ generateBuildManifestFromStats
80
197
  });
@@ -0,0 +1,2 @@
1
+ import { IApi } from '../../../types';
2
+ export declare const build: (api: IApi, opts: any) => Promise<void>;
@@ -0,0 +1,111 @@
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/ssr/utoopack/utoopack.ts
30
+ var utoopack_exports = {};
31
+ __export(utoopack_exports, {
32
+ build: () => build
33
+ });
34
+ module.exports = __toCommonJS(utoopack_exports);
35
+ var import_types = require("@umijs/bundler-webpack/dist/types");
36
+ var import_utils = require("@umijs/utils");
37
+ var import_fs = require("fs");
38
+ var import_path = __toESM(require("path"));
39
+ var import_utils2 = require("../utils");
40
+ function addPublicPath(publicPath, file) {
41
+ if (/^(?:https?:)?\/\//.test(file) || file.startsWith("/")) {
42
+ return file;
43
+ }
44
+ if (publicPath === "auto") {
45
+ return `/${file}`;
46
+ }
47
+ return `${publicPath.replace(/\/?$/, "/")}${file}`;
48
+ }
49
+ function getServerBuildFile(stats) {
50
+ var _a;
51
+ const statsJson = (stats == null ? void 0 : stats.toJson) ? stats.toJson() : stats || {};
52
+ const entrypoint = (_a = statsJson.entrypoints) == null ? void 0 : _a["umi.server"];
53
+ const files = /* @__PURE__ */ new Set();
54
+ for (const asset of (entrypoint == null ? void 0 : entrypoint.assets) || []) {
55
+ files.add(typeof asset === "string" ? asset : asset.name);
56
+ }
57
+ for (const chunkId of (entrypoint == null ? void 0 : entrypoint.chunks) || []) {
58
+ const chunk = (statsJson.chunks || []).find((item) => {
59
+ var _a2, _b;
60
+ return (item == null ? void 0 : item.id) === chunkId || ((_b = (_a2 = item == null ? void 0 : item.names) == null ? void 0 : _a2.includes) == null ? void 0 : _b.call(_a2, chunkId));
61
+ });
62
+ for (const file of (chunk == null ? void 0 : chunk.files) || []) {
63
+ files.add(file);
64
+ }
65
+ }
66
+ for (const asset of statsJson.assets || []) {
67
+ const name = typeof asset === "string" ? asset : asset.name;
68
+ if (/^umi\.server(?:\..*)?\.js$/.test((0, import_path.basename)(name))) {
69
+ files.add(name);
70
+ }
71
+ }
72
+ return Array.from(files).find((file) => /\.m?js$/.test(file));
73
+ }
74
+ var build = async (api, opts) => {
75
+ import_utils.logger.wait("[SSR] Compiling by utoopack...");
76
+ const now = (/* @__PURE__ */ new Date()).getTime();
77
+ const absOutputFile = (0, import_utils2.absServerBuildPath)(api);
78
+ require("@umijs/bundler-webpack/dist/requireHook");
79
+ const { buildSSR } = require(process.env.UTOOPACK);
80
+ const useHash = api.config.hash && api.env === import_types.Env.production;
81
+ const publicPath = api.userConfig.publicPath || "/";
82
+ const entry = import_path.default.resolve(api.paths.absTmpPath, "umi.server.ts");
83
+ const stats = await buildSSR({
84
+ ...opts,
85
+ cwd: api.cwd,
86
+ entry: {
87
+ "umi.server": entry
88
+ },
89
+ config: api.config,
90
+ serverBuildPath: absOutputFile,
91
+ useHash
92
+ });
93
+ const serverFile = getServerBuildFile(stats) || (0, import_path.basename)(absOutputFile);
94
+ const jsonFilePath = (0, import_path.join)((0, import_path.dirname)(absOutputFile), "build-manifest.json");
95
+ const assets = {
96
+ "umi.server.js": addPublicPath(publicPath, serverFile),
97
+ "umi.js": addPublicPath(publicPath, serverFile)
98
+ };
99
+ if (!(0, import_fs.existsSync)((0, import_path.dirname)(absOutputFile))) {
100
+ require("fs").mkdirSync((0, import_path.dirname)(absOutputFile), { recursive: true });
101
+ }
102
+ (0, import_fs.writeFileSync)(jsonFilePath, JSON.stringify({ assets }, null, 2), {
103
+ flag: "w"
104
+ });
105
+ const diff = (/* @__PURE__ */ new Date()).getTime() - now;
106
+ import_utils.logger.info(`[SSR] Compiled in ${diff}ms`);
107
+ };
108
+ // Annotate the CommonJS export names for ESM import in node:
109
+ 0 && (module.exports = {
110
+ build
111
+ });
@@ -36,8 +36,24 @@ module.exports = __toCommonJS(utoopack_exports);
36
36
  var import_utils = require("@umijs/utils");
37
37
  var import_path = require("path");
38
38
  var import_extractEntryAssets = require("../../utils/extractEntryAssets");
39
+ function cleanVersionRange(version) {
40
+ return version == null ? void 0 : version.replace(/^[^\d]*/, "");
41
+ }
39
42
  function getPackVersionFromBundler(bundlerEntry) {
40
- var _a, _b;
43
+ var _a;
44
+ const resolvePaths = [(0, import_path.dirname)(bundlerEntry), bundlerEntry];
45
+ for (const resolvePath of resolvePaths) {
46
+ try {
47
+ const pkgPath = require.resolve("@utoo/pack/package.json", {
48
+ paths: [resolvePath]
49
+ });
50
+ const pkg = require(pkgPath);
51
+ if (pkg.version) {
52
+ return pkg.version;
53
+ }
54
+ } catch {
55
+ }
56
+ }
41
57
  const packageJsonCandidates = [
42
58
  (0, import_path.join)((0, import_path.dirname)(bundlerEntry), "../package.json"),
43
59
  (0, import_path.join)(bundlerEntry, "../package.json"),
@@ -46,7 +62,7 @@ function getPackVersionFromBundler(bundlerEntry) {
46
62
  for (const packageJsonPath of packageJsonCandidates) {
47
63
  try {
48
64
  const pkg = require(packageJsonPath);
49
- return (_b = (_a = pkg.dependencies) == null ? void 0 : _a["@utoo/pack"]) == null ? void 0 : _b.replace(/^[^\d]*/, "");
65
+ return cleanVersionRange((_a = pkg.dependencies) == null ? void 0 : _a["@utoo/pack"]);
50
66
  } catch {
51
67
  }
52
68
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@umijs/preset-umi",
3
- "version": "4.6.50",
3
+ "version": "4.6.52",
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.50",
47
- "@umijs/bundler-vite": "4.6.50",
48
- "@umijs/babel-preset-umi": "4.6.50",
49
- "@umijs/bundler-utils": "4.6.50",
50
- "@umijs/bundler-webpack": "4.6.50",
51
- "@umijs/mfsu": "4.6.50",
52
- "@umijs/bundler-esbuild": "4.6.50",
53
- "@umijs/renderer-react": "4.6.50",
54
- "@umijs/core": "4.6.50",
55
- "@umijs/plugin-run": "4.6.50",
56
- "@umijs/bundler-utoopack": "4.6.50",
57
- "@umijs/zod2ts": "4.6.50",
58
- "@umijs/server": "4.6.50",
59
- "@umijs/utils": "4.6.50",
60
- "@umijs/ui": "3.0.1"
46
+ "@umijs/ast": "4.6.52",
47
+ "@umijs/babel-preset-umi": "4.6.52",
48
+ "@umijs/bundler-esbuild": "4.6.52",
49
+ "@umijs/bundler-vite": "4.6.52",
50
+ "@umijs/bundler-utils": "4.6.52",
51
+ "@umijs/bundler-webpack": "4.6.52",
52
+ "@umijs/bundler-utoopack": "4.6.52",
53
+ "@umijs/core": "4.6.52",
54
+ "@umijs/mfsu": "4.6.52",
55
+ "@umijs/plugin-run": "4.6.52",
56
+ "@umijs/utils": "4.6.52",
57
+ "@umijs/server": "4.6.52",
58
+ "@umijs/ui": "3.0.1",
59
+ "@umijs/zod2ts": "4.6.52",
60
+ "@umijs/renderer-react": "4.6.52"
61
61
  },
62
62
  "devDependencies": {
63
63
  "@manypkg/get-packages": "1.1.3",