@umijs/preset-umi 4.1.4 → 4.1.6

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.
@@ -105,10 +105,10 @@ umi build --clean
105
105
  umi: (0, import_path.join)(api.paths.absTmpPath, "umi.ts")
106
106
  }
107
107
  });
108
- const isGTEReact17 = ((_a = api.appData.react) == null ? void 0 : _a.version) && import_utils.semver.gte(api.appData.react.version, "17.0.0");
108
+ const shouldUseAutomaticRuntime = ((_a = api.appData.react) == null ? void 0 : _a.version) && import_utils.semver.gte(api.appData.react.version, "16.14.0");
109
109
  const opts = {
110
110
  react: {
111
- runtime: isGTEReact17 ? "automatic" : "classic"
111
+ runtime: shouldUseAutomaticRuntime ? "automatic" : "classic"
112
112
  },
113
113
  config: api.config,
114
114
  cwd: api.cwd,
@@ -309,10 +309,10 @@ PORT=8888 umi dev
309
309
  umi: (0, import_path.join)(api.paths.absTmpPath, "umi.ts")
310
310
  }
311
311
  });
312
- const isGTEReact17 = ((_c = api.appData.react) == null ? void 0 : _c.version) && import_utils.semver.gte(api.appData.react.version, "17.0.0");
312
+ const shouldUseAutomaticRuntime = ((_c = api.appData.react) == null ? void 0 : _c.version) && import_utils.semver.gte(api.appData.react.version, "16.14.0");
313
313
  const opts = {
314
314
  react: {
315
- runtime: isGTEReact17 ? "automatic" : "classic"
315
+ runtime: shouldUseAutomaticRuntime ? "automatic" : "classic"
316
316
  },
317
317
  config: api.config,
318
318
  pkg: api.pkg,
@@ -34,15 +34,15 @@ __export(getBabelOpts_exports, {
34
34
  module.exports = __toCommonJS(getBabelOpts_exports);
35
35
  var import_utils = require("@umijs/utils");
36
36
  async function getBabelOpts(opts) {
37
- const isGTEReact17 = import_utils.semver.gte(opts.api.appData.react.version, "17.0.0");
37
+ const shouldUseAutomaticRuntime = import_utils.semver.gte(opts.api.appData.react.version, "16.14.0");
38
38
  const babelPresetOpts = await opts.api.applyPlugins({
39
39
  key: "modifyBabelPresetOpts",
40
40
  initialValue: {
41
41
  presetEnv: {},
42
42
  presetReact: {
43
- runtime: isGTEReact17 ? "automatic" : "classic",
43
+ runtime: shouldUseAutomaticRuntime ? "automatic" : "classic",
44
44
  // importSource cannot be set when runtime is classic
45
- ...isGTEReact17 ? {} : { importSource: void 0 }
45
+ ...shouldUseAutomaticRuntime ? {} : { importSource: void 0 }
46
46
  },
47
47
  presetTypeScript: {},
48
48
  pluginTransformRuntime: {},
@@ -73,7 +73,9 @@ async function getMarkupArgs(opts) {
73
73
  async modifyHTML(memo, args) {
74
74
  let $ = import_cheerio.default.load(memo, {
75
75
  // @ts-ignore
76
- decodeEntities: false
76
+ decodeEntities: false,
77
+ // reduce memory overhead, to avoid oom in antd site with `exportStatic: {}`
78
+ _useHtmlParser2: true
77
79
  });
78
80
  $ = await opts.api.applyPlugins({
79
81
  key: "modifyHTML",
@@ -55,7 +55,7 @@ var jest_default = (api) => {
55
55
  jest: jestMajorVersion,
56
56
  "@types/jest": jestMajorVersion,
57
57
  // we use `jest.config.ts` so jest needs ts and ts-node
58
- typescript: "^4",
58
+ typescript: "^5",
59
59
  "ts-node": "^10",
60
60
  "cross-env": "^7"
61
61
  };
@@ -40,12 +40,12 @@ var precommit_default = (api) => {
40
40
  const h = new import_utils2.GeneratorHelper(api);
41
41
  const cliName = api.appData.umi.cliName;
42
42
  h.addDevDeps({
43
- husky: "^8",
43
+ husky: "^9",
44
44
  prettier: "^2",
45
- typescript: "^4",
45
+ typescript: "^5",
46
46
  "lint-staged": "^13"
47
47
  });
48
- h.addScript("prepare", "husky install");
48
+ h.addScript("prepare", "husky");
49
49
  if (!(0, import_fs.existsSync)((0, import_path.join)(api.cwd, ".lintstagedrc")) && !api.pkg["lint-staged"]) {
50
50
  (0, import_fs.writeFileSync)(
51
51
  (0, import_path.join)(api.cwd, ".lintstagedrc"),
@@ -79,9 +79,6 @@ var precommit_default = (api) => {
79
79
  (0, import_fs.writeFileSync)(
80
80
  (0, import_path.join)(api.cwd, ".husky/commit-msg"),
81
81
  `
82
- #!/usr/bin/env sh
83
- . "$(dirname -- "$0")/_/husky.sh"
84
-
85
82
  npx --no-install ${cliName} verify-commit $1
86
83
  `.trimStart()
87
84
  );
@@ -94,9 +91,6 @@ npx --no-install ${cliName} verify-commit $1
94
91
  (0, import_fs.writeFileSync)(
95
92
  (0, import_path.join)(api.cwd, ".husky/pre-commit"),
96
93
  `
97
- #!/usr/bin/env sh
98
- . "$(dirname -- "$0")/_/husky.sh"
99
-
100
94
  npx --no-install lint-staged --quiet
101
95
  `.trimStart()
102
96
  );
@@ -51,7 +51,7 @@ var tsconfig_default = (api) => {
51
51
  }
52
52
  const reactMajorVersion = parseInt(reactVersion.split(".")[0], 10) || 18;
53
53
  h.addDevDeps({
54
- typescript: "^4",
54
+ typescript: "^5",
55
55
  "@types/react": `^${reactMajorVersion}`,
56
56
  "@types/react-dom": `^${reactMajorVersion}`
57
57
  });
@@ -41,7 +41,7 @@ var devTool_default = (api) => {
41
41
  const loadingHtml = $.html();
42
42
  return [
43
43
  (req, res, next) => {
44
- var _a, _b;
44
+ var _a, _b, _c;
45
45
  const { path } = req;
46
46
  const enableVite = api.appData.vite;
47
47
  if (path.startsWith("/__umi/api/")) {
@@ -82,11 +82,13 @@ var devTool_default = (api) => {
82
82
  return res.sendFile((0, import_path.join)(devToolAppDist, "index.html"));
83
83
  }
84
84
  }
85
- const isDone = api.appData.bundleStatus.done && (enableVite || api.config.mfsu === false || api.appData.mfsuBundleStatus.done);
86
- if (!isDone) {
87
- res.setHeader("Content-Type", "text/html");
88
- res.send(loadingHtml);
89
- return;
85
+ if (((_c = req.headers.accept) == null ? void 0 : _c.includes("text/html")) || req.headers.accept === "*/*") {
86
+ const isDone = api.appData.bundleStatus.done && (enableVite || api.config.mfsu === false || api.appData.mfsuBundleStatus.done);
87
+ if (!isDone) {
88
+ res.setHeader("Content-Type", "text/html");
89
+ res.send(loadingHtml);
90
+ return;
91
+ }
90
92
  }
91
93
  return next();
92
94
  }
@@ -56,11 +56,15 @@ async function checkDir(opts) {
56
56
  }
57
57
  const conflicts = Object.keys(varMap).filter((v) => varMap[v].length > 1).map((v) => `${v} (${varMap[v].join(", ")})`);
58
58
  if (conflicts.length) {
59
- throw new Error(
60
- `Found conflicts in esbuild helpers: ${conflicts.join(
61
- ", "
62
- )}, please set esbuildMinifyIIFE: true in your config file.`
59
+ import_utils.logger.fatal(
60
+ import_utils.chalk.yellow(
61
+ `Found conflicts in esbuild helpers: ${conflicts.join(", ")}`
62
+ )
63
63
  );
64
+ import_utils.logger.info(
65
+ `please set ${import_utils.chalk.blue("esbuildMinifyIIFE: true")} in your config file`
66
+ );
67
+ throw new Error(`Found conflicts in esbuild helpers.`);
64
68
  }
65
69
  import_utils.logger.info(`[esbuildHelperChecker] No conflicts found.`);
66
70
  }
@@ -98,6 +102,8 @@ var esbuildHelperChecker_default = (api) => {
98
102
  }
99
103
  });
100
104
  api.onBuildComplete(async ({ err }) => {
105
+ if (api.config.vite)
106
+ return;
101
107
  if (process.env.OKAM)
102
108
  return;
103
109
  if (err)
@@ -124,13 +124,16 @@ var exportStatic_default = (api) => {
124
124
  const { publicPath } = api.config;
125
125
  const htmlData = api.appData.exportHtmlData;
126
126
  const htmlFiles = [];
127
+ const { markupArgs: defaultMarkupArgs } = opts;
128
+ let asyncMarkupArgs;
127
129
  for (const { file, route, prerender } of htmlData) {
128
- let { markupArgs } = opts;
130
+ let markupArgs = defaultMarkupArgs;
129
131
  if (api.config.ssr && prerender) {
130
- markupArgs.scripts.forEach((script) => {
131
- if (script.src) {
132
- script.async = true;
133
- }
132
+ markupArgs = asyncMarkupArgs ?? (asyncMarkupArgs = {
133
+ ...markupArgs,
134
+ scripts: markupArgs.scripts.map(
135
+ (script) => script.src ? { ...script, async: true } : script
136
+ )
134
137
  });
135
138
  }
136
139
  if (publicPath.startsWith(".")) {
@@ -155,39 +155,42 @@ var routePreloadOnLoad_default = (api) => {
155
155
  );
156
156
  }
157
157
  });
158
- api.addHTMLHeadScripts(() => {
159
- if (api.name === "build" && routeChunkFilesMap) {
160
- return api.config.tern ? (
161
- // map mode
162
- [
163
- {
164
- type: import_utils2.PRELOAD_ROUTE_MAP_SCP_TYPE,
165
- content: JSON.stringify(routeChunkFilesMap)
166
- }
167
- ]
168
- ) : (
169
- // script mode
170
- [
171
- {
172
- content: (0, import_fs.readFileSync)(
173
- (0, import_path.join)(
174
- import_constants.TEMPLATES_DIR,
175
- "routePreloadOnLoad/preloadRouteFilesScp.js"
176
- ),
177
- "utf-8"
178
- ).replace(
179
- '"{{routeChunkFilesMap}}"',
180
- JSON.stringify(routeChunkFilesMap)
181
- ).replace("{{basename}}", api.config.base).replace(
182
- '"{{publicPath}}"',
183
- `${// handle runtimePublicPath
184
- api.config.runtimePublicPath ? "window.publicPath||" : ""}"${api.config.publicPath}"`
185
- )
186
- }
187
- ]
188
- );
189
- }
190
- return [];
158
+ api.addHTMLHeadScripts({
159
+ fn: () => {
160
+ if (api.name === "build" && routeChunkFilesMap) {
161
+ return api.config.tern ? (
162
+ // map mode
163
+ [
164
+ {
165
+ type: import_utils2.PRELOAD_ROUTE_MAP_SCP_TYPE,
166
+ content: JSON.stringify(routeChunkFilesMap)
167
+ }
168
+ ]
169
+ ) : (
170
+ // script mode
171
+ [
172
+ {
173
+ content: (0, import_fs.readFileSync)(
174
+ (0, import_path.join)(
175
+ import_constants.TEMPLATES_DIR,
176
+ "routePreloadOnLoad/preloadRouteFilesScp.js"
177
+ ),
178
+ "utf-8"
179
+ ).replace(
180
+ '"{{routeChunkFilesMap}}"',
181
+ JSON.stringify(routeChunkFilesMap)
182
+ ).replace("{{basename}}", api.config.base).replace(
183
+ '"{{publicPath}}"',
184
+ `${// handle runtimePublicPath
185
+ api.config.runtimePublicPath ? "window.publicPath||" : ""}"${api.config.publicPath}"`
186
+ )
187
+ }
188
+ ]
189
+ );
190
+ }
191
+ return [];
192
+ },
193
+ stage: Infinity
191
194
  });
192
195
  api.onBuildComplete(async ({ err, stats }) => {
193
196
  if (!err && !stats.hasErrors()) {
@@ -51,9 +51,9 @@ var build2 = async (api, opts) => {
51
51
  ]);
52
52
  delete bundlerOpts.onBuildComplete;
53
53
  bundlerOpts.watch = api.env === "development";
54
- bundlerOpts.chainWebpack = async (memo) => {
54
+ bundlerOpts.chainWebpack = async (memo, opts2) => {
55
55
  const absOutputFile = (0, import_utils2.absServerBuildPath)(api);
56
- await oChainWebpack(memo);
56
+ await oChainWebpack(memo, { ...opts2, ssr: true });
57
57
  memo.entryPoints.clear();
58
58
  memo.entry("umi").add((0, import_path.resolve)(api.paths.absTmpPath, "umi.server.ts"));
59
59
  memo.target("node");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@umijs/preset-umi",
3
- "version": "4.1.4",
3
+ "version": "4.1.6",
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",
@@ -39,21 +39,21 @@
39
39
  "react-router": "6.3.0",
40
40
  "react-router-dom": "6.3.0",
41
41
  "regenerator-runtime": "0.13.11",
42
- "@umijs/babel-preset-umi": "4.1.4",
43
- "@umijs/ast": "4.1.4",
44
- "@umijs/bundler-utils": "4.1.4",
45
- "@umijs/bundler-vite": "4.1.4",
46
- "@umijs/bundler-esbuild": "4.1.4",
47
- "@umijs/core": "4.1.4",
48
- "@umijs/bundler-webpack": "4.1.4",
42
+ "@umijs/bundler-utils": "4.1.6",
43
+ "@umijs/bundler-esbuild": "4.1.6",
44
+ "@umijs/babel-preset-umi": "4.1.6",
45
+ "@umijs/bundler-vite": "4.1.6",
46
+ "@umijs/ast": "4.1.6",
47
+ "@umijs/bundler-webpack": "4.1.6",
48
+ "@umijs/core": "4.1.6",
49
+ "@umijs/plugin-run": "4.1.6",
50
+ "@umijs/server": "4.1.6",
51
+ "@umijs/renderer-react": "4.1.6",
52
+ "@umijs/utils": "4.1.6",
53
+ "@umijs/mfsu": "4.1.6",
49
54
  "@umijs/did-you-know": "1.0.3",
50
- "@umijs/mfsu": "4.1.4",
51
- "@umijs/renderer-react": "4.1.4",
52
- "@umijs/server": "4.1.4",
53
- "@umijs/plugin-run": "4.1.4",
54
55
  "@umijs/ui": "3.0.1",
55
- "@umijs/utils": "4.1.4",
56
- "@umijs/zod2ts": "4.1.4"
56
+ "@umijs/zod2ts": "4.1.6"
57
57
  },
58
58
  "devDependencies": {
59
59
  "@manypkg/get-packages": "1.1.3",
@@ -67,7 +67,7 @@
67
67
  "multer": "1.4.4",
68
68
  "os-locale": "^6.0.2",
69
69
  "sirv": "2.0.2",
70
- "vite": "4.3.1"
70
+ "vite": "4.5.2"
71
71
  },
72
72
  "publishConfig": {
73
73
  "access": "public"