@umijs/preset-umi 4.0.32 → 4.0.34
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/commands/build.js +8 -3
- package/dist/commands/config/set.d.ts +1 -1
- package/dist/commands/dev/getAssetsMap.js +12 -12
- package/dist/commands/generators/precommit.js +6 -2
- package/dist/features/apiRoute/request.d.ts +1 -0
- package/dist/features/codeSplitting/codeSplitting.js +8 -4
- package/dist/features/configPlugins/schema.js +1 -1
- package/dist/features/favicons/favicons.js +1 -1
- package/dist/features/monorepo/redirect.d.ts +4 -0
- package/dist/features/monorepo/redirect.js +5 -2
- package/dist/features/polyfill/polyfill.js +3 -1
- package/dist/features/test/test.js +3 -0
- package/dist/features/tmpFiles/routes.js +16 -2
- package/dist/features/tmpFiles/tmpFiles.js +5 -2
- package/dist/libs/folderCache/LazySourceCodeCache.js +2 -1
- package/dist/libs/folderCache/empty.tsconfig.json +1 -0
- package/dist/types.d.ts +1 -1
- package/package.json +12 -12
- package/templates/TestBrowser.tpl +7 -1
- package/templates/history.tpl +8 -5
- package/templates/umi.tpl +7 -1
package/dist/commands/build.js
CHANGED
|
@@ -120,7 +120,8 @@ umi build --clean
|
|
|
120
120
|
args: opts2
|
|
121
121
|
});
|
|
122
122
|
},
|
|
123
|
-
clean: true
|
|
123
|
+
clean: true,
|
|
124
|
+
htmlFiles: []
|
|
124
125
|
};
|
|
125
126
|
await api.applyPlugins({
|
|
126
127
|
key: "onBeforeCompiler",
|
|
@@ -141,6 +142,7 @@ umi build --clean
|
|
|
141
142
|
buildFolder: absOutputPath
|
|
142
143
|
});
|
|
143
144
|
}
|
|
145
|
+
let htmlFiles = [];
|
|
144
146
|
if (!api.config.mpa) {
|
|
145
147
|
const assetsMap = api.config.vite ? {} : (0, import_getAssetsMap.getAssetsMap)({
|
|
146
148
|
stats,
|
|
@@ -161,7 +163,7 @@ umi build --clean
|
|
|
161
163
|
esmScript: !!opts.config.esm || vite,
|
|
162
164
|
path: "/"
|
|
163
165
|
};
|
|
164
|
-
|
|
166
|
+
htmlFiles = await api.applyPlugins({
|
|
165
167
|
key: "modifyExportHTMLFiles",
|
|
166
168
|
initialValue: [
|
|
167
169
|
{
|
|
@@ -180,7 +182,10 @@ umi build --clean
|
|
|
180
182
|
}
|
|
181
183
|
await api.applyPlugins({
|
|
182
184
|
key: "onBuildHtmlComplete",
|
|
183
|
-
args:
|
|
185
|
+
args: {
|
|
186
|
+
...opts,
|
|
187
|
+
htmlFiles
|
|
188
|
+
}
|
|
184
189
|
});
|
|
185
190
|
}
|
|
186
191
|
});
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { IApi } from '../../types';
|
|
2
|
-
export declare function set(api: IApi, name: string, value:
|
|
2
|
+
export declare function set(api: IApi, name: string, value: string): void;
|
|
@@ -35,22 +35,22 @@ function getAssetsMap(opts) {
|
|
|
35
35
|
const { stats, publicPath } = opts;
|
|
36
36
|
const displayPublicPath = publicPath === "auto" ? "/" : publicPath;
|
|
37
37
|
let ret = {};
|
|
38
|
-
|
|
39
|
-
const
|
|
40
|
-
for (const asset of
|
|
41
|
-
if (!asset.
|
|
42
|
-
if (UMI_ASSETS_REG.js.test(asset
|
|
43
|
-
ret["umi.js"] = [`${displayPublicPath}${asset
|
|
38
|
+
const realStats = stats.stats ? stats.stats[0] : stats;
|
|
39
|
+
const assets = Object.keys(realStats.compilation.assets);
|
|
40
|
+
for (const asset of assets) {
|
|
41
|
+
if (!asset.includes(HOT_UPDATE)) {
|
|
42
|
+
if (UMI_ASSETS_REG.js.test(asset)) {
|
|
43
|
+
ret["umi.js"] = [`${displayPublicPath}${asset}`];
|
|
44
44
|
}
|
|
45
|
-
if (FRAMEWORK_ASSETS_REG.js.test(asset
|
|
46
|
-
ret["framework.js"] = [`${displayPublicPath}${asset
|
|
45
|
+
if (FRAMEWORK_ASSETS_REG.js.test(asset)) {
|
|
46
|
+
ret["framework.js"] = [`${displayPublicPath}${asset}`];
|
|
47
47
|
}
|
|
48
48
|
}
|
|
49
|
-
if (UMI_ASSETS_REG.css.test(asset
|
|
50
|
-
ret["umi.css"] = [`${displayPublicPath}${asset
|
|
49
|
+
if (UMI_ASSETS_REG.css.test(asset)) {
|
|
50
|
+
ret["umi.css"] = [`${displayPublicPath}${asset}`];
|
|
51
51
|
}
|
|
52
|
-
if (FRAMEWORK_ASSETS_REG.css.test(asset
|
|
53
|
-
ret["framework.css"] = [`${displayPublicPath}${asset
|
|
52
|
+
if (FRAMEWORK_ASSETS_REG.css.test(asset)) {
|
|
53
|
+
ret["framework.css"] = [`${displayPublicPath}${asset}`];
|
|
54
54
|
}
|
|
55
55
|
}
|
|
56
56
|
return ret;
|
|
@@ -80,7 +80,9 @@ var precommit_default = (api) => {
|
|
|
80
80
|
npx --no-install ${cliName} verify-commit $1
|
|
81
81
|
`.trimStart());
|
|
82
82
|
import_utils.logger.info("Write commit-msg");
|
|
83
|
-
|
|
83
|
+
if (process.platform !== "win32") {
|
|
84
|
+
import_utils.execa.execaCommandSync("chmod +x .husky/commit-msg");
|
|
85
|
+
}
|
|
84
86
|
}
|
|
85
87
|
if (!(0, import_fs.existsSync)((0, import_path.join)(api.cwd, ".husky/pre-commit"))) {
|
|
86
88
|
(0, import_fs.writeFileSync)((0, import_path.join)(api.cwd, ".husky/pre-commit"), `
|
|
@@ -90,7 +92,9 @@ npx --no-install ${cliName} verify-commit $1
|
|
|
90
92
|
npx --no-install lint-staged --quiet
|
|
91
93
|
`.trimStart());
|
|
92
94
|
import_utils.logger.info("Write pre-commit");
|
|
93
|
-
|
|
95
|
+
if (process.platform !== "win32") {
|
|
96
|
+
import_utils.execa.execaCommandSync("chmod +x .husky/pre-commit");
|
|
97
|
+
}
|
|
94
98
|
}
|
|
95
99
|
h.installDeps();
|
|
96
100
|
}
|
|
@@ -99,12 +99,13 @@ var codeSplitting_default = (api) => {
|
|
|
99
99
|
},
|
|
100
100
|
lib: {
|
|
101
101
|
test(module2) {
|
|
102
|
-
return module2.size() > 16e4 && /node_modules[/\\]/.test(module2.identifier());
|
|
102
|
+
return !isModuleCSS(module2) && module2.size() > 16e4 && /node_modules[/\\]/.test(module2.identifier());
|
|
103
103
|
},
|
|
104
104
|
name(module2) {
|
|
105
105
|
const rawRequest = module2.rawRequest && module2.rawRequest.replace(/^@(\w+)[/\\]/, "$1-");
|
|
106
|
-
if (rawRequest)
|
|
107
|
-
return `${rawRequest}-lib`;
|
|
106
|
+
if (rawRequest) {
|
|
107
|
+
return `${rawRequest.replace(/\./g, "_").replace(/\//g, "-")}-lib`;
|
|
108
|
+
}
|
|
108
109
|
const identifier = module2.identifier();
|
|
109
110
|
const trimmedIdentifier = /(?:^|[/\\])node_modules[/\\](.*)/.exec(identifier);
|
|
110
111
|
const processedIdentifier = trimmedIdentifier && trimmedIdentifier[1].replace(/^@(\w+)[/\\]/, "$1-");
|
|
@@ -119,7 +120,7 @@ var codeSplitting_default = (api) => {
|
|
|
119
120
|
name(_module, chunks) {
|
|
120
121
|
const cryptoName = import_crypto.default.createHash("sha1").update(chunks.reduce((acc, chunk) => {
|
|
121
122
|
return acc + chunk.name;
|
|
122
|
-
}, "")).digest("base64").replace(/\//g, "");
|
|
123
|
+
}, "")).digest("base64").replace(/\//g, "").replace(/\+/g, "-").replace(/=/g, "_");
|
|
123
124
|
return `shared-${cryptoName}`;
|
|
124
125
|
},
|
|
125
126
|
chunks: "async",
|
|
@@ -136,5 +137,8 @@ var codeSplitting_default = (api) => {
|
|
|
136
137
|
return memo;
|
|
137
138
|
});
|
|
138
139
|
};
|
|
140
|
+
function isModuleCSS(module2) {
|
|
141
|
+
return module2.type === `css/mini-extract` || module2.type === `css/extract-chunks` || module2.type === `css/extract-css-chunks`;
|
|
142
|
+
}
|
|
139
143
|
// Annotate the CommonJS export names for ESM import in node:
|
|
140
144
|
0 && (module.exports = {});
|
|
@@ -25,7 +25,7 @@ module.exports = __toCommonJS(schema_exports);
|
|
|
25
25
|
var import_utils = require("@umijs/utils");
|
|
26
26
|
function getSchemas() {
|
|
27
27
|
return {
|
|
28
|
-
base: (Joi) => Joi.string()
|
|
28
|
+
base: (Joi) => Joi.string(),
|
|
29
29
|
conventionRoutes: (Joi) => Joi.object({
|
|
30
30
|
base: Joi.string(),
|
|
31
31
|
exclude: Joi.array().items(Joi.any())
|
|
@@ -54,7 +54,7 @@ var favicons_default = (api) => {
|
|
|
54
54
|
});
|
|
55
55
|
api.addBeforeMiddlewares(() => [
|
|
56
56
|
(req, res, next) => {
|
|
57
|
-
const iconFile = (api.appData.faviconFiles || []).find((file) => req.path ===
|
|
57
|
+
const iconFile = (api.appData.faviconFiles || []).find((file) => req.path === `${api.config.publicPath}${file}`);
|
|
58
58
|
if (!iconFile) {
|
|
59
59
|
next();
|
|
60
60
|
} else {
|
|
@@ -22,7 +22,8 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
22
22
|
// src/features/monorepo/redirect.ts
|
|
23
23
|
var redirect_exports = {};
|
|
24
24
|
__export(redirect_exports, {
|
|
25
|
-
default: () => redirect_default
|
|
25
|
+
default: () => redirect_default,
|
|
26
|
+
isMonorepo: () => isMonorepo
|
|
26
27
|
});
|
|
27
28
|
module.exports = __toCommonJS(redirect_exports);
|
|
28
29
|
var import_utils = require("@umijs/utils");
|
|
@@ -118,4 +119,6 @@ function isMonorepo(opts) {
|
|
|
118
119
|
}) || (pkg == null ? void 0 : pkg.workspaces));
|
|
119
120
|
}
|
|
120
121
|
// Annotate the CommonJS export names for ESM import in node:
|
|
121
|
-
0 && (module.exports = {
|
|
122
|
+
0 && (module.exports = {
|
|
123
|
+
isMonorepo
|
|
124
|
+
});
|
|
@@ -29,6 +29,7 @@ var import_core = require("@umijs/core");
|
|
|
29
29
|
var import_utils = require("@umijs/utils");
|
|
30
30
|
var import_fs = require("fs");
|
|
31
31
|
var import_path = require("path");
|
|
32
|
+
var import_redirect = require("../monorepo/redirect");
|
|
32
33
|
var import_getModuleExports = require("./getModuleExports");
|
|
33
34
|
async function getApiRoutes(opts) {
|
|
34
35
|
const routes = (0, import_core.getConventionRoutes)({
|
|
@@ -199,8 +200,21 @@ ${imports}
|
|
|
199
200
|
function lastSlash(str) {
|
|
200
201
|
return str[str.length - 1] === "/" ? str : `${str}/`;
|
|
201
202
|
}
|
|
202
|
-
function
|
|
203
|
-
|
|
203
|
+
function getProjectRootCwd(cwd) {
|
|
204
|
+
const splittedCwd = cwd.split("/");
|
|
205
|
+
for (let level = -1; level >= -3; level -= 1) {
|
|
206
|
+
const rootCwd = splittedCwd.slice(0, level).join("/");
|
|
207
|
+
if (!rootCwd)
|
|
208
|
+
break;
|
|
209
|
+
if ((0, import_redirect.isMonorepo)({ root: rootCwd })) {
|
|
210
|
+
return rootCwd;
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
return cwd;
|
|
214
|
+
}
|
|
215
|
+
function componentToChunkName(component, cwd = "/") {
|
|
216
|
+
cwd = (0, import_utils.winPath)(cwd);
|
|
217
|
+
return typeof component === "string" ? component.replace(new RegExp(`^(${import_utils.lodash.escapeRegExp(lastSlash(cwd))}|${import_utils.lodash.escapeRegExp(lastSlash(getProjectRootCwd(cwd)))})`), "").replace(/^.(\/|\\)/, "").replace(/(\/|\\)/g, "__").replace(/@/g, "_").replace(/\.jsx?$/, "").replace(/\.tsx?$/, "").replace(/\.vue?$/, "").replace(/^src__/, "").replace(/\.\.__/g, "").replace(/[\[\]]/g, "").replace(/^node_modules__/, "nm__").replace(/^.umi-production__/, "t__").replace(/^\./, "").replace(/^pages__/, "p__") : "";
|
|
204
218
|
}
|
|
205
219
|
// Annotate the CommonJS export names for ESM import in node:
|
|
206
220
|
0 && (module.exports = {
|
|
@@ -337,6 +337,7 @@ export default function EmptyRoute() {
|
|
|
337
337
|
"patchRoutes",
|
|
338
338
|
"patchClientRoutes",
|
|
339
339
|
"modifyContextOpts",
|
|
340
|
+
"modifyClientRenderOpts",
|
|
340
341
|
"rootContainer",
|
|
341
342
|
"innerProvider",
|
|
342
343
|
"i18nProvider",
|
|
@@ -452,8 +453,10 @@ export default function EmptyRoute() {
|
|
|
452
453
|
path: "@@/core/terminal.ts"
|
|
453
454
|
});
|
|
454
455
|
}
|
|
455
|
-
if (
|
|
456
|
-
|
|
456
|
+
if (api.appData.framework === "react") {
|
|
457
|
+
if (process.env.NODE_ENV === "test" || process.env.NODE_ENV === "development") {
|
|
458
|
+
exports.push(`export { TestBrowser } from './testBrowser';`);
|
|
459
|
+
}
|
|
457
460
|
}
|
|
458
461
|
exports.push("// plugins");
|
|
459
462
|
const allPlugins = (0, import_fs.readdirSync)(api.paths.absTmpPath).filter((file) => file.startsWith("plugin-"));
|
|
@@ -163,7 +163,8 @@ async function esbuildTransform(files, opts) {
|
|
|
163
163
|
".js": "tsx",
|
|
164
164
|
".jsx": "tsx"
|
|
165
165
|
},
|
|
166
|
-
logLevel: "error"
|
|
166
|
+
logLevel: "error",
|
|
167
|
+
tsconfig: (0, import_path.join)(__dirname, "empty.tsconfig.json")
|
|
167
168
|
});
|
|
168
169
|
} catch (e) {
|
|
169
170
|
if (((_a = e.errors) == null ? void 0 : _a.length) || ((_b = e.warnings) == null ? void 0 : _b.length)) {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{}
|
package/dist/types.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@umijs/preset-umi",
|
|
3
|
-
"version": "4.0.
|
|
3
|
+
"version": "4.0.34",
|
|
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",
|
|
@@ -25,19 +25,19 @@
|
|
|
25
25
|
"test": "umi-scripts jest-turbo"
|
|
26
26
|
},
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@umijs/ast": "4.0.
|
|
29
|
-
"@umijs/babel-preset-umi": "4.0.
|
|
30
|
-
"@umijs/bundler-utils": "4.0.
|
|
31
|
-
"@umijs/bundler-vite": "4.0.
|
|
32
|
-
"@umijs/bundler-webpack": "4.0.
|
|
33
|
-
"@umijs/core": "4.0.
|
|
28
|
+
"@umijs/ast": "4.0.34",
|
|
29
|
+
"@umijs/babel-preset-umi": "4.0.34",
|
|
30
|
+
"@umijs/bundler-utils": "4.0.34",
|
|
31
|
+
"@umijs/bundler-vite": "4.0.34",
|
|
32
|
+
"@umijs/bundler-webpack": "4.0.34",
|
|
33
|
+
"@umijs/core": "4.0.34",
|
|
34
34
|
"@umijs/did-you-know": "^1.0.0",
|
|
35
35
|
"@umijs/history": "5.3.1",
|
|
36
|
-
"@umijs/mfsu": "4.0.
|
|
37
|
-
"@umijs/plugin-run": "4.0.
|
|
38
|
-
"@umijs/renderer-react": "4.0.
|
|
39
|
-
"@umijs/server": "4.0.
|
|
40
|
-
"@umijs/utils": "4.0.
|
|
36
|
+
"@umijs/mfsu": "4.0.34",
|
|
37
|
+
"@umijs/plugin-run": "4.0.34",
|
|
38
|
+
"@umijs/renderer-react": "4.0.34",
|
|
39
|
+
"@umijs/server": "4.0.34",
|
|
40
|
+
"@umijs/utils": "4.0.34",
|
|
41
41
|
"babel-plugin-dynamic-import-node": "2.3.3",
|
|
42
42
|
"click-to-react-component": "^1.0.8",
|
|
43
43
|
"core-js": "3.22.4",
|
|
@@ -43,7 +43,7 @@ export function TestBrowser(props: TestBrowserProps) {
|
|
|
43
43
|
type: 'memory',
|
|
44
44
|
basename,
|
|
45
45
|
});
|
|
46
|
-
|
|
46
|
+
const context = {
|
|
47
47
|
routes,
|
|
48
48
|
{{#hydrate}}
|
|
49
49
|
hydrate: true,
|
|
@@ -63,6 +63,12 @@ export function TestBrowser(props: TestBrowserProps) {
|
|
|
63
63
|
basename,
|
|
64
64
|
components: true,
|
|
65
65
|
};
|
|
66
|
+
const modifiedContext = pluginManager.applyPlugins({
|
|
67
|
+
key: 'modifyClientRenderOpts',
|
|
68
|
+
type: ApplyPluginsType.modify,
|
|
69
|
+
initialValue: context,
|
|
70
|
+
});
|
|
71
|
+
return modifiedContext;
|
|
66
72
|
};
|
|
67
73
|
genContext().then((context) => {
|
|
68
74
|
setContext(context);
|
package/templates/history.tpl
CHANGED
|
@@ -18,10 +18,10 @@ export function createHistory(opts: any) {
|
|
|
18
18
|
history = {
|
|
19
19
|
...h,
|
|
20
20
|
push(to, state) {
|
|
21
|
-
h.push(patchTo(to), state);
|
|
21
|
+
h.push(patchTo(to, h), state);
|
|
22
22
|
},
|
|
23
23
|
replace(to, state) {
|
|
24
|
-
h.replace(patchTo(to), state);
|
|
24
|
+
h.replace(patchTo(to, h), state);
|
|
25
25
|
},
|
|
26
26
|
get location() {
|
|
27
27
|
return h.location;
|
|
@@ -38,13 +38,16 @@ export function createHistory(opts: any) {
|
|
|
38
38
|
// Refs:
|
|
39
39
|
// https://github.com/remix-run/history/blob/3e9dab4/packages/history/index.ts#L484
|
|
40
40
|
// https://github.com/remix-run/history/blob/dev/docs/api-reference.md#to
|
|
41
|
-
function patchTo(to: any) {
|
|
41
|
+
function patchTo(to: any, h: History) {
|
|
42
42
|
if (typeof to === 'string') {
|
|
43
43
|
return `${stripLastSlash(basename)}${to}`;
|
|
44
|
-
} else if (typeof to === 'object'
|
|
44
|
+
} else if (typeof to === 'object') {
|
|
45
|
+
|
|
46
|
+
const currentPathname = h.location.pathname;
|
|
47
|
+
|
|
45
48
|
return {
|
|
46
49
|
...to,
|
|
47
|
-
pathname: `${stripLastSlash(basename)}${to.pathname}
|
|
50
|
+
pathname: to.pathname? `${stripLastSlash(basename)}${to.pathname}` : currentPathname,
|
|
48
51
|
};
|
|
49
52
|
} else {
|
|
50
53
|
throw new Error(`Unexpected to: ${to}`);
|
package/templates/umi.tpl
CHANGED
|
@@ -59,8 +59,14 @@ async function render() {
|
|
|
59
59
|
...contextOpts.historyOpts,
|
|
60
60
|
}),
|
|
61
61
|
basename,
|
|
62
|
+
callback: contextOpts.callback,
|
|
62
63
|
};
|
|
63
|
-
|
|
64
|
+
const modifiedContext = pluginManager.applyPlugins({
|
|
65
|
+
key: 'modifyClientRenderOpts',
|
|
66
|
+
type: ApplyPluginsType.modify,
|
|
67
|
+
initialValue: context,
|
|
68
|
+
});
|
|
69
|
+
return renderClient(modifiedContext);
|
|
64
70
|
},
|
|
65
71
|
}))();
|
|
66
72
|
}
|