@umijs/preset-umi 4.2.3 → 4.2.5
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.
- package/dist/features/configPlugins/configPlugins.js +5 -2
- package/dist/features/forget/forget.d.ts +3 -0
- package/dist/features/forget/forget.js +77 -0
- package/dist/features/mpa/mpa.js +3 -3
- package/dist/features/routePreloadOnLoad/routePreloadOnLoad.js +25 -14
- package/dist/features/routePreloadOnLoad/utils.d.ts +1 -0
- package/dist/features/routePreloadOnLoad/utils.js +3 -0
- package/dist/index.js +1 -0
- package/package.json +17 -16
- package/templates/history.tpl +6 -0
|
@@ -55,8 +55,11 @@ var configPlugins_default = (api) => {
|
|
|
55
55
|
cwd: api.cwd,
|
|
56
56
|
dep: "react-dom"
|
|
57
57
|
}) || (0, import_path.dirname)(require.resolve("react-dom/package.json"));
|
|
58
|
-
const
|
|
59
|
-
|
|
58
|
+
const isLT18 = (() => {
|
|
59
|
+
const reactDOMVersion = require((0, import_path.join)(reactDOMPath, "package.json")).version;
|
|
60
|
+
const majorVersion = parseInt(reactDOMVersion.split(".")[0], 10);
|
|
61
|
+
return majorVersion < 18;
|
|
62
|
+
})();
|
|
60
63
|
const configDefaults = {
|
|
61
64
|
alias: {
|
|
62
65
|
umi: "@@/exports",
|
|
@@ -0,0 +1,77 @@
|
|
|
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/forget/forget.ts
|
|
30
|
+
var forget_exports = {};
|
|
31
|
+
__export(forget_exports, {
|
|
32
|
+
default: () => forget_default
|
|
33
|
+
});
|
|
34
|
+
module.exports = __toCommonJS(forget_exports);
|
|
35
|
+
var forget_default = (api) => {
|
|
36
|
+
api.describe({
|
|
37
|
+
key: "forget",
|
|
38
|
+
config: {
|
|
39
|
+
schema({ zod }) {
|
|
40
|
+
return zod.object({
|
|
41
|
+
ReactCompilerConfig: zod.object({}).optional()
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
},
|
|
45
|
+
enableBy: api.EnableBy.config
|
|
46
|
+
});
|
|
47
|
+
api.onCheckConfig(() => {
|
|
48
|
+
if (api.config.mfsu) {
|
|
49
|
+
throw new Error(
|
|
50
|
+
`forget is not compatible with mfsu, please disable mfsu first.`
|
|
51
|
+
);
|
|
52
|
+
}
|
|
53
|
+
if (api.config.mako) {
|
|
54
|
+
throw new Error(
|
|
55
|
+
`forget is not compatible with mako, please disable mako first.`
|
|
56
|
+
);
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
api.onCheck(() => {
|
|
60
|
+
let reactMajorVersion = api.appData.react.version.split(".")[0];
|
|
61
|
+
if (reactMajorVersion < 19) {
|
|
62
|
+
throw new Error(
|
|
63
|
+
`forget is only compatible with React 19 and above, please upgrade your React version.`
|
|
64
|
+
);
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
api.modifyConfig((memo) => {
|
|
68
|
+
let ReactCompilerConfig = api.userConfig.forget.ReactCompilerConfig || {};
|
|
69
|
+
return {
|
|
70
|
+
...memo,
|
|
71
|
+
extraBabelPlugins: [
|
|
72
|
+
...memo.extraBabelPlugins || [],
|
|
73
|
+
[require.resolve("babel-plugin-react-compiler"), ReactCompilerConfig]
|
|
74
|
+
]
|
|
75
|
+
};
|
|
76
|
+
});
|
|
77
|
+
};
|
package/dist/features/mpa/mpa.js
CHANGED
|
@@ -72,14 +72,14 @@ var mpa_default = (api) => {
|
|
|
72
72
|
api.userConfig.mountElementId
|
|
73
73
|
);
|
|
74
74
|
}
|
|
75
|
-
const
|
|
75
|
+
const isGTEReact18 = api.appData.react.version.split(".")[0] >= 18;
|
|
76
76
|
api.appData.mpa.entry.forEach((entry) => {
|
|
77
77
|
const layout = entry.layout || api.config.mpa.layout;
|
|
78
78
|
const layoutImport = layout ? `import Layout from '${layout}';` : "";
|
|
79
79
|
const layoutJSX = layout ? `<Layout><App /></Layout>` : `<App />`;
|
|
80
80
|
const rootElement = `document.getElementById('${entry.mountElementId}')`;
|
|
81
|
-
const renderer =
|
|
82
|
-
const reactDOMSource =
|
|
81
|
+
const renderer = isGTEReact18 ? `ReactDOM.createRoot(${rootElement}).render(${layoutJSX});` : `ReactDOM.render(${layoutJSX}, ${rootElement});`;
|
|
82
|
+
const reactDOMSource = isGTEReact18 ? "react-dom/client" : "react-dom";
|
|
83
83
|
api.writeTmpFile({
|
|
84
84
|
path: entry.tmpFilePath,
|
|
85
85
|
noPluginDir: true,
|
|
@@ -23,6 +23,7 @@ __export(routePreloadOnLoad_exports, {
|
|
|
23
23
|
});
|
|
24
24
|
module.exports = __toCommonJS(routePreloadOnLoad_exports);
|
|
25
25
|
var import_utils = require("@umijs/utils");
|
|
26
|
+
var import_crypto = require("crypto");
|
|
26
27
|
var import_fs = require("fs");
|
|
27
28
|
var import_path = require("path");
|
|
28
29
|
var import_constants = require("../../constants");
|
|
@@ -142,6 +143,7 @@ async function getRoutePathFilesMap(routes, fileChunksMap, opts) {
|
|
|
142
143
|
}
|
|
143
144
|
var routePreloadOnLoad_default = (api) => {
|
|
144
145
|
let routeChunkFilesMap;
|
|
146
|
+
let hashedPart = ".js";
|
|
145
147
|
api.describe({
|
|
146
148
|
enableBy: () => {
|
|
147
149
|
var _a;
|
|
@@ -158,6 +160,8 @@ var routePreloadOnLoad_default = (api) => {
|
|
|
158
160
|
api.addHTMLHeadScripts({
|
|
159
161
|
fn: () => {
|
|
160
162
|
if (api.name === "build" && routeChunkFilesMap) {
|
|
163
|
+
const { publicPath } = api.config;
|
|
164
|
+
const displayPublicPath = publicPath === "auto" ? "/" : publicPath;
|
|
161
165
|
return api.config.tern ? (
|
|
162
166
|
// map mode
|
|
163
167
|
[
|
|
@@ -170,20 +174,7 @@ var routePreloadOnLoad_default = (api) => {
|
|
|
170
174
|
// script mode
|
|
171
175
|
[
|
|
172
176
|
{
|
|
173
|
-
|
|
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
|
-
)
|
|
177
|
+
src: `${displayPublicPath}${import_utils2.PRELOAD_ROUTE_HELPER}${hashedPart}`
|
|
187
178
|
}
|
|
188
179
|
]
|
|
189
180
|
);
|
|
@@ -224,6 +215,26 @@ var routePreloadOnLoad_default = (api) => {
|
|
|
224
215
|
).fromPairs().value()
|
|
225
216
|
};
|
|
226
217
|
}
|
|
218
|
+
if (api.name === "build" && routeChunkFilesMap && !api.config.tern) {
|
|
219
|
+
const content = (0, import_fs.readFileSync)(
|
|
220
|
+
(0, import_path.join)(import_constants.TEMPLATES_DIR, "routePreloadOnLoad/preloadRouteFilesScp.js"),
|
|
221
|
+
"utf-8"
|
|
222
|
+
).replace(
|
|
223
|
+
'"{{routeChunkFilesMap}}"',
|
|
224
|
+
JSON.stringify(routeChunkFilesMap)
|
|
225
|
+
).replace("{{basename}}", api.config.base).replace(
|
|
226
|
+
'"{{publicPath}}"',
|
|
227
|
+
`${// handle runtimePublicPath
|
|
228
|
+
api.config.runtimePublicPath ? "window.publicPath||" : ""}"${api.config.publicPath}"`
|
|
229
|
+
);
|
|
230
|
+
if (api.config.hash) {
|
|
231
|
+
hashedPart = `.${(0, import_crypto.createHash)("md5").update(content).digest("hex").substring(0, 8)}.js`;
|
|
232
|
+
}
|
|
233
|
+
(0, import_fs.writeFileSync)(
|
|
234
|
+
(0, import_path.join)(api.paths.absOutputPath, `${import_utils2.PRELOAD_ROUTE_HELPER}${hashedPart}`),
|
|
235
|
+
content
|
|
236
|
+
), "utf-8";
|
|
237
|
+
}
|
|
227
238
|
}
|
|
228
239
|
});
|
|
229
240
|
};
|
|
@@ -9,6 +9,7 @@ export interface IPreloadRouteFile {
|
|
|
9
9
|
attrs: ([string, string] | [string])[];
|
|
10
10
|
}
|
|
11
11
|
export declare const PRELOAD_ROUTE_MAP_SCP_TYPE = "umi-route-chunk-files-map";
|
|
12
|
+
export declare const PRELOAD_ROUTE_HELPER = "_umi_route_preload_helper";
|
|
12
13
|
export declare function getPreloadRouteFiles(path: string, map: IRouteChunkFilesMap, opts: {
|
|
13
14
|
publicPath: string;
|
|
14
15
|
}): IPreloadRouteFile[] | undefined;
|
|
@@ -19,11 +19,13 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
19
19
|
// src/features/routePreloadOnLoad/utils.ts
|
|
20
20
|
var utils_exports = {};
|
|
21
21
|
__export(utils_exports, {
|
|
22
|
+
PRELOAD_ROUTE_HELPER: () => PRELOAD_ROUTE_HELPER,
|
|
22
23
|
PRELOAD_ROUTE_MAP_SCP_TYPE: () => PRELOAD_ROUTE_MAP_SCP_TYPE,
|
|
23
24
|
getPreloadRouteFiles: () => getPreloadRouteFiles
|
|
24
25
|
});
|
|
25
26
|
module.exports = __toCommonJS(utils_exports);
|
|
26
27
|
var PRELOAD_ROUTE_MAP_SCP_TYPE = "umi-route-chunk-files-map";
|
|
28
|
+
var PRELOAD_ROUTE_HELPER = "_umi_route_preload_helper";
|
|
27
29
|
function getPreloadRouteFiles(path, map, opts) {
|
|
28
30
|
var _a;
|
|
29
31
|
const matched = (
|
|
@@ -52,6 +54,7 @@ function getPreloadRouteFiles(path, map, opts) {
|
|
|
52
54
|
}
|
|
53
55
|
// Annotate the CommonJS export names for ESM import in node:
|
|
54
56
|
0 && (module.exports = {
|
|
57
|
+
PRELOAD_ROUTE_HELPER,
|
|
55
58
|
PRELOAD_ROUTE_MAP_SCP_TYPE,
|
|
56
59
|
getPreloadRouteFiles
|
|
57
60
|
});
|
package/dist/index.js
CHANGED
|
@@ -88,6 +88,7 @@ var src_default = () => {
|
|
|
88
88
|
require.resolve("./features/mako/mako"),
|
|
89
89
|
require.resolve("./features/hmrGuardian/hmrGuardian"),
|
|
90
90
|
require.resolve("./features/routePreloadOnLoad/routePreloadOnLoad"),
|
|
91
|
+
require.resolve("./features/forget/forget"),
|
|
91
92
|
// commands
|
|
92
93
|
require.resolve("./commands/build"),
|
|
93
94
|
require.resolve("./commands/config/config"),
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@umijs/preset-umi",
|
|
3
|
-
"version": "4.2.
|
|
3
|
+
"version": "4.2.5",
|
|
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",
|
|
@@ -21,10 +21,11 @@
|
|
|
21
21
|
"dependencies": {
|
|
22
22
|
"@iconify/utils": "2.1.1",
|
|
23
23
|
"@svgr/core": "6.5.1",
|
|
24
|
-
"@umijs/bundler-mako": "0.4.
|
|
24
|
+
"@umijs/bundler-mako": "0.4.17",
|
|
25
25
|
"@umijs/es-module-parser": "0.0.7",
|
|
26
26
|
"@umijs/history": "5.3.1",
|
|
27
27
|
"babel-plugin-dynamic-import-node": "2.3.3",
|
|
28
|
+
"babel-plugin-react-compiler": "0.0.0-experimental-c23de8d-20240515",
|
|
28
29
|
"click-to-react-component": "^1.0.8",
|
|
29
30
|
"core-js": "3.34.0",
|
|
30
31
|
"current-script-polyfill": "1.0.0",
|
|
@@ -40,21 +41,21 @@
|
|
|
40
41
|
"react-router": "6.3.0",
|
|
41
42
|
"react-router-dom": "6.3.0",
|
|
42
43
|
"regenerator-runtime": "0.13.11",
|
|
43
|
-
"@umijs/ast": "4.2.
|
|
44
|
-
"@umijs/
|
|
45
|
-
"@umijs/bundler-
|
|
46
|
-
"@umijs/bundler-
|
|
47
|
-
"@umijs/
|
|
48
|
-
"@umijs/
|
|
49
|
-
"@umijs/mfsu": "4.2.
|
|
50
|
-
"@umijs/bundler-vite": "4.2.3",
|
|
51
|
-
"@umijs/plugin-run": "4.2.3",
|
|
52
|
-
"@umijs/renderer-react": "4.2.3",
|
|
53
|
-
"@umijs/server": "4.2.3",
|
|
44
|
+
"@umijs/ast": "4.2.5",
|
|
45
|
+
"@umijs/babel-preset-umi": "4.2.5",
|
|
46
|
+
"@umijs/bundler-esbuild": "4.2.5",
|
|
47
|
+
"@umijs/bundler-utils": "4.2.5",
|
|
48
|
+
"@umijs/bundler-vite": "4.2.5",
|
|
49
|
+
"@umijs/bundler-webpack": "4.2.5",
|
|
50
|
+
"@umijs/mfsu": "4.2.5",
|
|
54
51
|
"@umijs/did-you-know": "1.0.3",
|
|
55
|
-
"@umijs/
|
|
56
|
-
"@umijs/
|
|
57
|
-
"@umijs/zod2ts": "4.2.
|
|
52
|
+
"@umijs/core": "4.2.5",
|
|
53
|
+
"@umijs/server": "4.2.5",
|
|
54
|
+
"@umijs/zod2ts": "4.2.5",
|
|
55
|
+
"@umijs/utils": "4.2.5",
|
|
56
|
+
"@umijs/renderer-react": "4.2.5",
|
|
57
|
+
"@umijs/plugin-run": "4.2.5",
|
|
58
|
+
"@umijs/ui": "3.0.1"
|
|
58
59
|
},
|
|
59
60
|
"devDependencies": {
|
|
60
61
|
"@manypkg/get-packages": "1.1.3",
|
package/templates/history.tpl
CHANGED
|
@@ -41,6 +41,12 @@ export function createHistory(opts: any) {
|
|
|
41
41
|
return h;
|
|
42
42
|
}
|
|
43
43
|
|
|
44
|
+
export function setHistory(h: UmiHistory) {
|
|
45
|
+
if (h) {
|
|
46
|
+
history = h;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
44
50
|
// Patch `to` to support basename
|
|
45
51
|
// Refs:
|
|
46
52
|
// https://github.com/remix-run/history/blob/3e9dab4/packages/history/index.ts#L484
|