@umijs/preset-umi 4.0.61 → 4.0.63
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/appData/appData.js +21 -0
- package/dist/features/clickToComponent/clickToComponent.js +1 -1
- package/dist/features/mpa/mpa.js +10 -0
- package/dist/features/prepare/prepare.js +42 -9
- package/dist/features/tmpFiles/tmpFiles.js +12 -6
- package/dist/types.d.ts +2 -0
- package/package.json +15 -14
|
@@ -100,6 +100,18 @@ var appData_default = (api) => {
|
|
|
100
100
|
memo.git = git;
|
|
101
101
|
}
|
|
102
102
|
memo.framework = "react";
|
|
103
|
+
const tsPkg = tryLoadDepPkg({
|
|
104
|
+
name: "typescript",
|
|
105
|
+
from: api.cwd
|
|
106
|
+
});
|
|
107
|
+
const tslibPkg = tryLoadDepPkg({
|
|
108
|
+
name: "tslib",
|
|
109
|
+
from: api.cwd
|
|
110
|
+
});
|
|
111
|
+
memo.typescript = {
|
|
112
|
+
tsVersion: tsPkg == null ? void 0 : tsPkg.version,
|
|
113
|
+
tslibVersion: tslibPkg == null ? void 0 : tslibPkg.version
|
|
114
|
+
};
|
|
103
115
|
return memo;
|
|
104
116
|
});
|
|
105
117
|
api.register({
|
|
@@ -194,5 +206,14 @@ function findGitDir(dir) {
|
|
|
194
206
|
}
|
|
195
207
|
return null;
|
|
196
208
|
}
|
|
209
|
+
function tryLoadDepPkg(opts) {
|
|
210
|
+
const { name, from } = opts;
|
|
211
|
+
try {
|
|
212
|
+
return require(require.resolve(`${name}/package.json`, {
|
|
213
|
+
paths: [from]
|
|
214
|
+
}));
|
|
215
|
+
} catch {
|
|
216
|
+
}
|
|
217
|
+
}
|
|
197
218
|
// Annotate the CommonJS export names for ESM import in node:
|
|
198
219
|
0 && (module.exports = {});
|
|
@@ -46,7 +46,7 @@ var clickToComponent_default = (api) => {
|
|
|
46
46
|
});
|
|
47
47
|
}
|
|
48
48
|
},
|
|
49
|
-
enableBy: api.EnableBy.config
|
|
49
|
+
enableBy: api.env === "development" ? api.EnableBy.config : () => false
|
|
50
50
|
});
|
|
51
51
|
const pkgPath = (0, import_path.dirname)(require.resolve("click-to-react-component"));
|
|
52
52
|
api.modifyConfig((memo) => {
|
package/dist/features/mpa/mpa.js
CHANGED
|
@@ -136,11 +136,21 @@ async function collectEntryWithTimeCount(root, opts) {
|
|
|
136
136
|
);
|
|
137
137
|
return entries;
|
|
138
138
|
}
|
|
139
|
+
function filterEntry(dir) {
|
|
140
|
+
if (!process.env.MPA_FILTER) {
|
|
141
|
+
return true;
|
|
142
|
+
}
|
|
143
|
+
const entries = process.env.MPA_FILTER.split(",");
|
|
144
|
+
return entries.includes(dir);
|
|
145
|
+
}
|
|
139
146
|
async function collectEntry(root, opts) {
|
|
140
147
|
return await (0, import_fs.readdirSync)(root).reduce(
|
|
141
148
|
async (memoP, dir) => {
|
|
142
149
|
var _a;
|
|
143
150
|
const memo = await memoP;
|
|
151
|
+
if (!filterEntry(dir)) {
|
|
152
|
+
return memo;
|
|
153
|
+
}
|
|
144
154
|
const absDir = (0, import_path.join)(root, dir);
|
|
145
155
|
if ((0, import_fs.existsSync)(absDir) && (0, import_fs.statSync)(absDir).isDirectory()) {
|
|
146
156
|
const indexFile = getIndexFile(absDir);
|
|
@@ -35,16 +35,45 @@ module.exports = __toCommonJS(prepare_exports);
|
|
|
35
35
|
var import_utils = require("@umijs/utils");
|
|
36
36
|
var import_path = __toESM(require("path"));
|
|
37
37
|
var import_watch = require("../../commands/dev/watch");
|
|
38
|
+
var parser = (0, import_utils.importLazy)(
|
|
39
|
+
require.resolve("@umijs/es-module-parser")
|
|
40
|
+
);
|
|
38
41
|
var prepare_default = (api) => {
|
|
39
|
-
function updateAppdata(
|
|
40
|
-
|
|
42
|
+
function updateAppdata(prepareData) {
|
|
43
|
+
var _a;
|
|
44
|
+
const buildResult = import_utils.lodash.cloneDeep(prepareData.buildResult);
|
|
41
45
|
(buildResult.outputFiles || []).forEach((file) => {
|
|
42
46
|
file == null ? true : delete file.contents;
|
|
43
47
|
});
|
|
48
|
+
const nextFileImports = prepareData.fileImports ?? ((_a = api.appData.prepare) == null ? void 0 : _a.fileImports);
|
|
44
49
|
api.appData.prepare = {
|
|
45
|
-
buildResult
|
|
50
|
+
buildResult,
|
|
51
|
+
fileImports: nextFileImports
|
|
46
52
|
};
|
|
47
53
|
}
|
|
54
|
+
async function parseProjectImportSpecifiers(br) {
|
|
55
|
+
const files = Object.keys(br.metafile.inputs) || [];
|
|
56
|
+
if (files.length === 0) {
|
|
57
|
+
return {};
|
|
58
|
+
}
|
|
59
|
+
try {
|
|
60
|
+
const start = Date.now();
|
|
61
|
+
const fileImports = await parser.parseFiles(
|
|
62
|
+
files.map((f) => import_path.default.join(api.paths.cwd, f))
|
|
63
|
+
);
|
|
64
|
+
api.telemetry.record({
|
|
65
|
+
name: "parse",
|
|
66
|
+
payload: { duration: Date.now() - start }
|
|
67
|
+
});
|
|
68
|
+
return fileImports;
|
|
69
|
+
} catch (e) {
|
|
70
|
+
api.telemetry.record({
|
|
71
|
+
name: "parse:error",
|
|
72
|
+
payload: {}
|
|
73
|
+
});
|
|
74
|
+
return void 0;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
48
77
|
api.register({
|
|
49
78
|
key: "onGenerateFiles",
|
|
50
79
|
async fn({ isFirstTime }) {
|
|
@@ -67,13 +96,15 @@ var prepare_default = (api) => {
|
|
|
67
96
|
const buildResult = await build({
|
|
68
97
|
entryPoints: [entryFile],
|
|
69
98
|
watch: watch && {
|
|
70
|
-
onRebuildSuccess({ result }) {
|
|
71
|
-
|
|
72
|
-
|
|
99
|
+
async onRebuildSuccess({ result }) {
|
|
100
|
+
const fileImports2 = await parseProjectImportSpecifiers(result);
|
|
101
|
+
updateAppdata({ buildResult: result, fileImports: fileImports2 });
|
|
102
|
+
await api.applyPlugins({
|
|
73
103
|
key: "onPrepareBuildSuccess",
|
|
74
104
|
args: {
|
|
75
105
|
isWatch: true,
|
|
76
|
-
result
|
|
106
|
+
result,
|
|
107
|
+
fileImports: fileImports2
|
|
77
108
|
}
|
|
78
109
|
});
|
|
79
110
|
}
|
|
@@ -90,11 +121,13 @@ var prepare_default = (api) => {
|
|
|
90
121
|
(_a = buildResult.stop) == null ? void 0 : _a.call(buildResult);
|
|
91
122
|
});
|
|
92
123
|
}
|
|
93
|
-
|
|
124
|
+
const fileImports = await parseProjectImportSpecifiers(buildResult);
|
|
125
|
+
updateAppdata({ buildResult, fileImports });
|
|
94
126
|
await api.applyPlugins({
|
|
95
127
|
key: "onPrepareBuildSuccess",
|
|
96
128
|
args: {
|
|
97
|
-
result: buildResult
|
|
129
|
+
result: buildResult,
|
|
130
|
+
fileImports
|
|
98
131
|
}
|
|
99
132
|
});
|
|
100
133
|
},
|
|
@@ -53,7 +53,7 @@ var tmpFiles_default = (api) => {
|
|
|
53
53
|
}
|
|
54
54
|
});
|
|
55
55
|
api.onGenerateFiles(async (opts) => {
|
|
56
|
-
var _a, _b;
|
|
56
|
+
var _a, _b, _c;
|
|
57
57
|
const rendererPath = (0, import_utils.winPath)(
|
|
58
58
|
await api.applyPlugins({
|
|
59
59
|
key: "modifyRendererPath",
|
|
@@ -71,6 +71,8 @@ var tmpFiles_default = (api) => {
|
|
|
71
71
|
const srcPrefix = api.appData.hasSrcDir ? "src/" : "";
|
|
72
72
|
const umiTempDir = `${srcPrefix}.umi`;
|
|
73
73
|
const baseUrl = api.appData.hasSrcDir ? "../../" : "../";
|
|
74
|
+
const isTs5 = (_a = api.appData.typescript.tsVersion) == null ? void 0 : _a.startsWith("5");
|
|
75
|
+
const isTslibInstalled = !!api.appData.typescript.tslibVersion;
|
|
74
76
|
api.writeTmpFile({
|
|
75
77
|
noPluginDir: true,
|
|
76
78
|
path: "tsconfig.json",
|
|
@@ -83,8 +85,12 @@ var tmpFiles_default = (api) => {
|
|
|
83
85
|
compilerOptions: {
|
|
84
86
|
target: "esnext",
|
|
85
87
|
module: "esnext",
|
|
86
|
-
|
|
87
|
-
|
|
88
|
+
lib: ["dom", "dom.iterable", "esnext"],
|
|
89
|
+
allowJs: true,
|
|
90
|
+
skipLibCheck: true,
|
|
91
|
+
moduleResolution: isTs5 ? "bundler" : "node",
|
|
92
|
+
importHelpers: isTslibInstalled,
|
|
93
|
+
noEmit: true,
|
|
88
94
|
jsx: api.appData.framework === "vue" ? "preserve" : "react-jsx",
|
|
89
95
|
esModuleInterop: true,
|
|
90
96
|
sourceMap: true,
|
|
@@ -344,7 +350,7 @@ export default function EmptyRoute() {
|
|
|
344
350
|
}
|
|
345
351
|
const hasSrc = api.appData.hasSrcDir;
|
|
346
352
|
const pages = (0, import_path.basename)(
|
|
347
|
-
((
|
|
353
|
+
((_b = api.config.conventionRoutes) == null ? void 0 : _b.base) || api.paths.absPagesPath
|
|
348
354
|
);
|
|
349
355
|
const prefix = hasSrc ? `../../../src/${pages}/` : `../../${pages}/`;
|
|
350
356
|
const clonedRoutes = import_utils.lodash.cloneDeep(routes);
|
|
@@ -362,7 +368,7 @@ export default function EmptyRoute() {
|
|
|
362
368
|
routesString = routesString.replace(/"(clientLoaders\[.*?)"/g, "$1");
|
|
363
369
|
headerImports.push(`import clientLoaders from './loaders.js';`);
|
|
364
370
|
}
|
|
365
|
-
if (!api.userConfig.routes) {
|
|
371
|
+
if (!api.userConfig.routes && api.isPluginEnable("routeProps")) {
|
|
366
372
|
routesString = routesString.replace(
|
|
367
373
|
/"routeProps":"(routeProps\[.*?)"/g,
|
|
368
374
|
"...$1"
|
|
@@ -406,7 +412,7 @@ if (process.env.NODE_ENV === 'development') {
|
|
|
406
412
|
});
|
|
407
413
|
const plugins = await api.applyPlugins({
|
|
408
414
|
key: "addRuntimePlugin",
|
|
409
|
-
initialValue: [(
|
|
415
|
+
initialValue: [(_c = api.appData.appJS) == null ? void 0 : _c.path].filter(Boolean)
|
|
410
416
|
});
|
|
411
417
|
const validKeys = await api.applyPlugins({
|
|
412
418
|
key: "addRuntimePluginKey",
|
package/dist/types.d.ts
CHANGED
|
@@ -6,6 +6,7 @@ import { createWebSocketServer } from '@umijs/bundler-webpack/dist/server/ws';
|
|
|
6
6
|
import type { IConfig } from '@umijs/bundler-webpack/dist/types';
|
|
7
7
|
import type { IAdd, IEvent, IModify, IRoute as ICoreRoute, IServicePluginAPI, PluginAPI } from '@umijs/core';
|
|
8
8
|
import { Env } from '@umijs/core';
|
|
9
|
+
import type { Declaration } from '@umijs/es-module-parser';
|
|
9
10
|
import type { getMarkup } from '@umijs/server';
|
|
10
11
|
import type { CheerioAPI } from '@umijs/utils/compiled/cheerio';
|
|
11
12
|
import type { InlineConfig as ViteInlineConfig } from 'vite';
|
|
@@ -188,6 +189,7 @@ export declare type IApi = PluginAPI & IServicePluginAPI & {
|
|
|
188
189
|
origin: Record<string, any>;
|
|
189
190
|
}>;
|
|
190
191
|
onPrepareBuildSuccess: IEvent<{
|
|
192
|
+
fileImports?: Record<string, Declaration[]>;
|
|
191
193
|
isWatch: boolean;
|
|
192
194
|
result: ESBuildBuildResult;
|
|
193
195
|
}>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@umijs/preset-umi",
|
|
3
|
-
"version": "4.0.
|
|
3
|
+
"version": "4.0.63",
|
|
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,6 +21,7 @@
|
|
|
21
21
|
"dependencies": {
|
|
22
22
|
"@iconify/utils": "2.1.1",
|
|
23
23
|
"@svgr/core": "6.5.1",
|
|
24
|
+
"@umijs/es-module-parser": "0.0.6",
|
|
24
25
|
"@umijs/history": "5.3.1",
|
|
25
26
|
"babel-plugin-dynamic-import-node": "2.3.3",
|
|
26
27
|
"click-to-react-component": "^1.0.8",
|
|
@@ -36,19 +37,19 @@
|
|
|
36
37
|
"react-router": "6.3.0",
|
|
37
38
|
"react-router-dom": "6.3.0",
|
|
38
39
|
"regenerator-runtime": "0.13.11",
|
|
39
|
-
"@umijs/
|
|
40
|
-
"@umijs/
|
|
41
|
-
"@umijs/
|
|
42
|
-
"@umijs/bundler-vite": "4.0.
|
|
43
|
-
"@umijs/
|
|
44
|
-
"@umijs/
|
|
40
|
+
"@umijs/ast": "4.0.63",
|
|
41
|
+
"@umijs/babel-preset-umi": "4.0.63",
|
|
42
|
+
"@umijs/bundler-utils": "4.0.63",
|
|
43
|
+
"@umijs/bundler-vite": "4.0.63",
|
|
44
|
+
"@umijs/bundler-webpack": "4.0.63",
|
|
45
|
+
"@umijs/core": "4.0.63",
|
|
45
46
|
"@umijs/did-you-know": "1.0.3",
|
|
46
|
-
"@umijs/
|
|
47
|
-
"@umijs/
|
|
48
|
-
"@umijs/renderer-react": "4.0.
|
|
49
|
-
"@umijs/server": "4.0.
|
|
50
|
-
"@umijs/utils": "4.0.
|
|
51
|
-
"@umijs/zod2ts": "4.0.
|
|
47
|
+
"@umijs/mfsu": "4.0.63",
|
|
48
|
+
"@umijs/plugin-run": "4.0.63",
|
|
49
|
+
"@umijs/renderer-react": "4.0.63",
|
|
50
|
+
"@umijs/server": "4.0.63",
|
|
51
|
+
"@umijs/utils": "4.0.63",
|
|
52
|
+
"@umijs/zod2ts": "4.0.63"
|
|
52
53
|
},
|
|
53
54
|
"devDependencies": {
|
|
54
55
|
"@manypkg/get-packages": "1.1.3",
|
|
@@ -62,7 +63,7 @@
|
|
|
62
63
|
"multer": "1.4.4",
|
|
63
64
|
"os-locale": "^6.0.2",
|
|
64
65
|
"sirv": "2.0.2",
|
|
65
|
-
"vite": "4.
|
|
66
|
+
"vite": "4.2.0"
|
|
66
67
|
},
|
|
67
68
|
"publishConfig": {
|
|
68
69
|
"access": "public"
|