@umijs/preset-umi 4.6.2 → 4.6.4
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/config/remove.js +1 -2
- package/dist/commands/config/set.js +1 -2
- package/dist/commands/deadcode.js +1 -2
- package/dist/commands/dev/depBuildWorker/depBuildWorker.js +1 -2
- package/dist/commands/dev/depBuildWorker/depBuilder.js +5 -6
- package/dist/commands/generators/component.js +2 -0
- package/dist/commands/generators/page.js +8 -9
- package/dist/commands/generators/utils.js +2 -0
- package/dist/commands/mfsu/util.js +2 -0
- package/dist/features/apiRoute/apiRoute.js +1 -2
- package/dist/features/apiRoute/dev-server/esbuild.js +1 -2
- package/dist/features/apiRoute/request.js +5 -6
- package/dist/features/apiRoute/response.js +1 -0
- package/dist/features/apiRoute/utils.js +9 -18
- package/dist/features/appData/appData.js +2 -2
- package/dist/features/codeSplitting/codeSplitting.js +2 -4
- package/dist/features/esmi/Service.js +5 -5
- package/dist/features/favicons/favicons.js +2 -4
- package/dist/features/icons/svgr.js +2 -4
- package/dist/features/mock/createMockMiddleware.js +1 -2
- package/dist/features/monorepo/redirect.js +2 -4
- package/dist/features/mpa/mpa.js +5 -10
- package/dist/features/overrides/overrides.js +1 -2
- package/dist/features/overrides/transform.js +2 -4
- package/dist/features/phantomDependency/phantomDependency.js +15 -30
- package/dist/features/prepare/esbuildPlugins/esbuildAliasPlugin.js +4 -8
- package/dist/features/prepare/prepare.js +1 -2
- package/dist/features/ssr/builder/css-loader.js +2 -2
- package/dist/features/ssr/ssr.js +1 -2
- package/dist/features/tmpFiles/getModuleExports.js +2 -2
- package/dist/features/tmpFiles/routes.js +6 -7
- package/dist/features/transform/CodeFrameError.js +1 -0
- package/dist/features/ui/ui.js +1 -2
- package/dist/libs/folderCache/AutoUpdateFolderCache.js +9 -3
- package/dist/libs/folderCache/AutoUpdateSourceCodeCache.js +5 -2
- package/dist/libs/folderCache/FolderWatch.js +5 -2
- package/dist/libs/folderCache/LazySourceCodeCache.js +10 -6
- package/dist/libs/scan.js +2 -4
- package/dist/utils/routeExportExtractor.js +1 -2
- package/dist/utils/serializeAppData.js +1 -2
- package/package.json +16 -16
|
@@ -26,8 +26,7 @@ var import_ast = require("@umijs/ast");
|
|
|
26
26
|
var import_fs = require("fs");
|
|
27
27
|
function remove(mainConfigFile, name) {
|
|
28
28
|
const ast = (0, import_ast.getASTByFilePath)(mainConfigFile);
|
|
29
|
-
if (!ast)
|
|
30
|
-
return;
|
|
29
|
+
if (!ast) return;
|
|
31
30
|
const generateCode = (0, import_ast.generate)((0, import_ast.removeConfigByName)(ast, name));
|
|
32
31
|
const prettier = require("@umijs/utils/compiled/prettier");
|
|
33
32
|
const printStr = prettier.format(generateCode, {
|
|
@@ -35,8 +35,7 @@ function set(api, name, value) {
|
|
|
35
35
|
api.appData.mainConfigFile = absPath;
|
|
36
36
|
}
|
|
37
37
|
const ast = (0, import_ast.getASTByFilePath)(mainConfigFile);
|
|
38
|
-
if (!ast)
|
|
39
|
-
return;
|
|
38
|
+
if (!ast) return;
|
|
40
39
|
const generateCode = (0, import_ast.generate)((0, import_ast.setConfigByName)(ast, name, value));
|
|
41
40
|
const prettier = require("@umijs/utils/compiled/prettier");
|
|
42
41
|
const printStr = prettier.format(generateCode, {
|
|
@@ -205,8 +205,7 @@ var deadcode_default = (api) => {
|
|
|
205
205
|
const recordJsonPath = (0, import_utils.winPath)(
|
|
206
206
|
(0, import_path.join)(cwd, typeof out === "string" ? out : recordJson)
|
|
207
207
|
);
|
|
208
|
-
if (gitInfo)
|
|
209
|
-
import_utils.logger.wait("generating file...");
|
|
208
|
+
if (gitInfo) import_utils.logger.wait("generating file...");
|
|
210
209
|
await outputUnusedFiles(unusedFiles, recordJsonPath, {
|
|
211
210
|
gitInfo,
|
|
212
211
|
cwd
|
|
@@ -114,8 +114,7 @@ start().catch((e) => {
|
|
|
114
114
|
import_utils.logger.error("[MFSU][eager] build worker start failed", e);
|
|
115
115
|
});
|
|
116
116
|
function makeArray(a) {
|
|
117
|
-
if (Array.isArray(a))
|
|
118
|
-
return a;
|
|
117
|
+
if (Array.isArray(a)) return a;
|
|
119
118
|
return [a];
|
|
120
119
|
}
|
|
121
120
|
function setupWorkerEnv() {
|
|
@@ -45,9 +45,10 @@ var import_path = require("path");
|
|
|
45
45
|
var import_worker_threads = require("worker_threads");
|
|
46
46
|
var MF_ENTRY = "mf_index.js";
|
|
47
47
|
var DepBuilderInWorker = class {
|
|
48
|
+
completeFns = [];
|
|
49
|
+
isBuilding = false;
|
|
50
|
+
opts;
|
|
48
51
|
constructor(opts) {
|
|
49
|
-
this.completeFns = [];
|
|
50
|
-
this.isBuilding = false;
|
|
51
52
|
this.opts = opts;
|
|
52
53
|
}
|
|
53
54
|
async buildWithWebpack(opts) {
|
|
@@ -154,10 +155,8 @@ var DepBuilderInWorker = class {
|
|
|
154
155
|
depConfig.output.path = this.opts.tmpBase;
|
|
155
156
|
depConfig.output.publicPath = "auto";
|
|
156
157
|
depConfig.devtool = false;
|
|
157
|
-
if ((_a = depConfig.output) == null ? void 0 : _a.library)
|
|
158
|
-
|
|
159
|
-
if ((_b = depConfig.output) == null ? void 0 : _b.libraryTarget)
|
|
160
|
-
delete depConfig.output.libraryTarget;
|
|
158
|
+
if ((_a = depConfig.output) == null ? void 0 : _a.library) delete depConfig.output.library;
|
|
159
|
+
if ((_b = depConfig.output) == null ? void 0 : _b.libraryTarget) delete depConfig.output.libraryTarget;
|
|
161
160
|
depConfig.optimization || (depConfig.optimization = {});
|
|
162
161
|
depConfig.optimization.splitChunks = {
|
|
163
162
|
chunks: (chunk) => {
|
|
@@ -59,13 +59,6 @@ var USER_TEMPLATE_PAGE_DIR = "templates/page";
|
|
|
59
59
|
var PageGenerator = class {
|
|
60
60
|
constructor(options) {
|
|
61
61
|
this.options = options;
|
|
62
|
-
this.isDirMode = false;
|
|
63
|
-
this.dir = "";
|
|
64
|
-
this.name = "";
|
|
65
|
-
this.importSource = "";
|
|
66
|
-
this.needEnsureDirMode = false;
|
|
67
|
-
this.prompts = import_utils2.promptsExitWhenCancel;
|
|
68
|
-
this.paths = [];
|
|
69
62
|
this.isDirMode = !!options.args.dir;
|
|
70
63
|
this.importSource = options.importSource || "umi";
|
|
71
64
|
const [_, ...inputPaths] = options.args._;
|
|
@@ -75,6 +68,13 @@ var PageGenerator = class {
|
|
|
75
68
|
this.needEnsureDirMode = true;
|
|
76
69
|
}
|
|
77
70
|
}
|
|
71
|
+
isDirMode = false;
|
|
72
|
+
dir = "";
|
|
73
|
+
name = "";
|
|
74
|
+
importSource = "";
|
|
75
|
+
needEnsureDirMode = false;
|
|
76
|
+
prompts = import_utils2.promptsExitWhenCancel;
|
|
77
|
+
paths = [];
|
|
78
78
|
async run() {
|
|
79
79
|
if (this.paths.length === 0) {
|
|
80
80
|
await this.runInteractiveMode();
|
|
@@ -129,8 +129,7 @@ var PageGenerator = class {
|
|
|
129
129
|
this.isDirMode = false;
|
|
130
130
|
}
|
|
131
131
|
async ensureDirMode() {
|
|
132
|
-
if (!this.needEnsureDirMode)
|
|
133
|
-
return;
|
|
132
|
+
if (!this.needEnsureDirMode) return;
|
|
134
133
|
const response = await this.prompts({
|
|
135
134
|
type: "select",
|
|
136
135
|
name: "mode",
|
|
@@ -49,6 +49,8 @@ var MFSUUtilBase = class {
|
|
|
49
49
|
this.mfsuCacheBase = ((_b = (_a = api.config) == null ? void 0 : _a.mfsu) == null ? void 0 : _b.cacheDirectoryPath) || (0, import_path.join)(cacheBase, "mfsu");
|
|
50
50
|
this.cliName = this.api.appData.umi.cliName;
|
|
51
51
|
}
|
|
52
|
+
mfsuCacheBase;
|
|
53
|
+
cliName;
|
|
52
54
|
async prepare() {
|
|
53
55
|
var _a, _b, _c, _d;
|
|
54
56
|
const api = this.api;
|
|
@@ -66,8 +66,7 @@ var apiRoute_default = (api) => {
|
|
|
66
66
|
},
|
|
67
67
|
enableBy: () => {
|
|
68
68
|
const hasApiRoutes = import_fs.default.existsSync((0, import_path.join)(api.paths.absSrcPath, "api"));
|
|
69
|
-
if (!hasApiRoutes)
|
|
70
|
-
return false;
|
|
69
|
+
if (!hasApiRoutes) return false;
|
|
71
70
|
const config = api.userConfig.apiRoute;
|
|
72
71
|
if (!config) {
|
|
73
72
|
return false;
|
|
@@ -55,8 +55,7 @@ async function esbuild_default(api, apiRoutes) {
|
|
|
55
55
|
(0, import_utils2.esbuildIgnorePathPrefixPlugin)(),
|
|
56
56
|
(0, import_watchRebuild.esbuildWatchRebuildPlugin)({
|
|
57
57
|
onRebuild(error) {
|
|
58
|
-
if (error)
|
|
59
|
-
import_utils.logger.error("Compile api routes failed: ", error);
|
|
58
|
+
if (error) import_utils.logger.error("Compile api routes failed: ", error);
|
|
60
59
|
Object.keys(require.cache).forEach((modulePath) => {
|
|
61
60
|
if (modulePath.startsWith((0, import_path.join)(api.paths.cwd, import_constants.OUTPUT_PATH)))
|
|
62
61
|
delete require.cache[modulePath];
|
|
@@ -26,17 +26,17 @@ __export(request_exports, {
|
|
|
26
26
|
module.exports = __toCommonJS(request_exports);
|
|
27
27
|
var import_utils = require("./utils");
|
|
28
28
|
var UmiApiRequest = class {
|
|
29
|
+
_req;
|
|
30
|
+
_params = {};
|
|
29
31
|
constructor(req, apiRoutes) {
|
|
30
|
-
this._params = {};
|
|
31
|
-
this._body = null;
|
|
32
32
|
this._req = req;
|
|
33
33
|
const m = (0, import_utils.matchApiRoute)(apiRoutes, this.pathName || "");
|
|
34
|
-
if (m)
|
|
35
|
-
this._params = m.params;
|
|
34
|
+
if (m) this._params = m.params;
|
|
36
35
|
}
|
|
37
36
|
get params() {
|
|
38
37
|
return this._params;
|
|
39
38
|
}
|
|
39
|
+
_body = null;
|
|
40
40
|
get body() {
|
|
41
41
|
return this._body;
|
|
42
42
|
}
|
|
@@ -128,8 +128,7 @@ function parseMultipart(body, boundary) {
|
|
|
128
128
|
);
|
|
129
129
|
const meta = Buffer.from(hexMeta, "hex").toString("utf-8");
|
|
130
130
|
const name = (_a = meta.split('name="')[1]) == null ? void 0 : _a.split('"')[0];
|
|
131
|
-
if (!name)
|
|
132
|
-
return acc;
|
|
131
|
+
if (!name) return acc;
|
|
133
132
|
const fileName = (_b = meta.split('filename="')[1]) == null ? void 0 : _b.split('"')[0];
|
|
134
133
|
if (fileName) {
|
|
135
134
|
const fileBufferBeforeTrim = Buffer.from(hexValue, "hex");
|
|
@@ -34,39 +34,30 @@ function esbuildIgnorePathPrefixPlugin() {
|
|
|
34
34
|
};
|
|
35
35
|
}
|
|
36
36
|
function matchApiRoute(apiRoutes, path) {
|
|
37
|
-
if (path.startsWith("/"))
|
|
38
|
-
|
|
39
|
-
if (path.startsWith("api/"))
|
|
40
|
-
path = path.substring(4);
|
|
37
|
+
if (path.startsWith("/")) path = path.substring(1);
|
|
38
|
+
if (path.startsWith("api/")) path = path.substring(4);
|
|
41
39
|
const pathSegments = path.split("/").filter((p) => p !== "");
|
|
42
40
|
if (pathSegments.length === 0 || pathSegments.length === 1 && pathSegments[0] === "api") {
|
|
43
41
|
const route2 = apiRoutes.find((r) => r.path === "/");
|
|
44
|
-
if (route2)
|
|
45
|
-
|
|
46
|
-
else
|
|
47
|
-
return void 0;
|
|
42
|
+
if (route2) return { route: route2, params: {} };
|
|
43
|
+
else return void 0;
|
|
48
44
|
}
|
|
49
45
|
const params = {};
|
|
50
46
|
const route = apiRoutes.find((route2) => {
|
|
51
47
|
const routePathSegments = route2.path.split("/").filter((p) => p !== "");
|
|
52
|
-
if (routePathSegments.length !== pathSegments.length)
|
|
53
|
-
return false;
|
|
48
|
+
if (routePathSegments.length !== pathSegments.length) return false;
|
|
54
49
|
for (let i = 0; i < routePathSegments.length; i++) {
|
|
55
50
|
const routePathSegment = routePathSegments[i];
|
|
56
51
|
if (routePathSegment.match(/^\[.*]$/)) {
|
|
57
52
|
params[routePathSegment.substring(1, routePathSegment.length - 1)] = pathSegments[i];
|
|
58
|
-
if (i == routePathSegments.length - 1)
|
|
59
|
-
return true;
|
|
53
|
+
if (i == routePathSegments.length - 1) return true;
|
|
60
54
|
continue;
|
|
61
55
|
}
|
|
62
|
-
if (routePathSegment !== pathSegments[i])
|
|
63
|
-
|
|
64
|
-
if (i == routePathSegments.length - 1)
|
|
65
|
-
return true;
|
|
56
|
+
if (routePathSegment !== pathSegments[i]) return false;
|
|
57
|
+
if (i == routePathSegments.length - 1) return true;
|
|
66
58
|
}
|
|
67
59
|
});
|
|
68
|
-
if (route)
|
|
69
|
-
return { route, params };
|
|
60
|
+
if (route) return { route, params };
|
|
70
61
|
}
|
|
71
62
|
// Annotate the CommonJS export names for ESM import in node:
|
|
72
63
|
0 && (module.exports = {
|
|
@@ -160,13 +160,13 @@ var appData_default = (api) => {
|
|
|
160
160
|
async function getAppJsInfo() {
|
|
161
161
|
for (const path of (0, import_watch.expandJSPaths)((0, import_path.join)(api.paths.absSrcPath, "app"))) {
|
|
162
162
|
if ((0, import_fs.existsSync)(path)) {
|
|
163
|
-
const [_,
|
|
163
|
+
const [_, exports2] = await bundlerUtils.parseModule({
|
|
164
164
|
path,
|
|
165
165
|
content: (0, import_fs.readFileSync)(path, "utf-8")
|
|
166
166
|
});
|
|
167
167
|
return {
|
|
168
168
|
path,
|
|
169
|
-
exports
|
|
169
|
+
exports: exports2
|
|
170
170
|
};
|
|
171
171
|
}
|
|
172
172
|
}
|
|
@@ -49,8 +49,7 @@ var codeSplitting_default = (api) => {
|
|
|
49
49
|
enableBy: api.EnableBy.config
|
|
50
50
|
});
|
|
51
51
|
api.chainWebpack((memo) => {
|
|
52
|
-
if (api.env !== "production")
|
|
53
|
-
return;
|
|
52
|
+
if (api.env !== "production") return;
|
|
54
53
|
const { jsStrategy, jsStrategyOptions, cssStrategy } = api.config.codeSplitting;
|
|
55
54
|
if (jsStrategy === "bigVendors") {
|
|
56
55
|
memo.optimization.splitChunks({
|
|
@@ -75,8 +74,7 @@ var codeSplitting_default = (api) => {
|
|
|
75
74
|
name(module2) {
|
|
76
75
|
const path = module2.context.replace(/.pnpm[\\/]/, "");
|
|
77
76
|
const match = path.match(/[\\/]node_modules[\\/](.*?)([\\/]|$)/);
|
|
78
|
-
if (!match)
|
|
79
|
-
return "npm.unknown";
|
|
77
|
+
if (!match) return "npm.unknown";
|
|
80
78
|
const packageName = match[1];
|
|
81
79
|
return `npm.${packageName.replace(/@/g, "_at_").replace(/\+/g, "_")}`;
|
|
82
80
|
}
|
|
@@ -36,11 +36,11 @@ var import_utils = require("@umijs/utils");
|
|
|
36
36
|
var import_crypto = require("crypto");
|
|
37
37
|
var import_fs = __toESM(require("fs"));
|
|
38
38
|
var import_path = __toESM(require("path"));
|
|
39
|
-
var ESMIService = class {
|
|
39
|
+
var ESMIService = class _ESMIService {
|
|
40
|
+
cdnOrigin = "";
|
|
41
|
+
cacheDir = "";
|
|
42
|
+
cache = {};
|
|
40
43
|
constructor(opts) {
|
|
41
|
-
this.cdnOrigin = "";
|
|
42
|
-
this.cacheDir = "";
|
|
43
|
-
this.cache = {};
|
|
44
44
|
this.cdnOrigin = opts.cdnOrigin;
|
|
45
45
|
this.cacheDir = opts.cacheDir;
|
|
46
46
|
const cacheFilePath = import_path.default.join(this.cacheDir, "importmap.json");
|
|
@@ -102,7 +102,7 @@ var ESMIService = class {
|
|
|
102
102
|
* @returns importmap
|
|
103
103
|
*/
|
|
104
104
|
async getImportmap(data) {
|
|
105
|
-
const cacheKey =
|
|
105
|
+
const cacheKey = _ESMIService.getCacheKey(data);
|
|
106
106
|
const cache = this.getCache(cacheKey);
|
|
107
107
|
const stamp = +/* @__PURE__ */ new Date();
|
|
108
108
|
if (cache) {
|
|
@@ -44,8 +44,7 @@ var favicons_default = (api) => {
|
|
|
44
44
|
}
|
|
45
45
|
});
|
|
46
46
|
api.modifyAppData(async (memo) => {
|
|
47
|
-
if (api.config.favicons)
|
|
48
|
-
return memo;
|
|
47
|
+
if (api.config.favicons) return memo;
|
|
49
48
|
const faviconFiles = getFaviconFiles(api.paths.absSrcPath);
|
|
50
49
|
if (faviconFiles) {
|
|
51
50
|
memo.faviconFiles = faviconFiles;
|
|
@@ -65,8 +64,7 @@ var favicons_default = (api) => {
|
|
|
65
64
|
}
|
|
66
65
|
]);
|
|
67
66
|
api.onBuildComplete(({ err }) => {
|
|
68
|
-
if (err)
|
|
69
|
-
return;
|
|
67
|
+
if (err) return;
|
|
70
68
|
if (api.appData.faviconFiles) {
|
|
71
69
|
api.appData.faviconFiles.forEach((e) => {
|
|
72
70
|
(0, import_fs.copyFileSync)(
|
|
@@ -74,10 +74,8 @@ function loadLocalIcon(icon, localIconDir) {
|
|
|
74
74
|
}
|
|
75
75
|
function normalizeSvgr(str) {
|
|
76
76
|
return str.split("\n").filter((line) => {
|
|
77
|
-
if (line.startsWith('import * as React from "react";'))
|
|
78
|
-
|
|
79
|
-
if (line.startsWith("export default "))
|
|
80
|
-
return false;
|
|
77
|
+
if (line.startsWith('import * as React from "react";')) return false;
|
|
78
|
+
if (line.startsWith("export default ")) return false;
|
|
81
79
|
return true;
|
|
82
80
|
}).join("\n");
|
|
83
81
|
}
|
|
@@ -40,8 +40,7 @@ function createMockMiddleware(opts) {
|
|
|
40
40
|
const method = req.method.toUpperCase();
|
|
41
41
|
for (const key of Object.keys(opts.context.mockData)) {
|
|
42
42
|
const mock = opts.context.mockData[key];
|
|
43
|
-
if (mock.method !== method)
|
|
44
|
-
continue;
|
|
43
|
+
if (mock.method !== method) continue;
|
|
45
44
|
const { keys, re } = getPathReAndKeys(mock.path);
|
|
46
45
|
const m = re.exec(req.path);
|
|
47
46
|
if (m) {
|
|
@@ -68,8 +68,7 @@ var redirect_default = (api) => {
|
|
|
68
68
|
// APP_ROOT: https://github.com/umijs/umi/issues/9461
|
|
69
69
|
cwd: useRootProject ? currentProjectRoot : (0, import_path.dirname)(currentProjectRoot)
|
|
70
70
|
});
|
|
71
|
-
if (!rootPkg)
|
|
72
|
-
return memo;
|
|
71
|
+
if (!rootPkg) return memo;
|
|
73
72
|
const root = (0, import_path.dirname)(rootPkg);
|
|
74
73
|
(0, import_assert.default)(
|
|
75
74
|
(0, import_utils.isMonorepo)({ root }),
|
|
@@ -84,8 +83,7 @@ var redirect_default = (api) => {
|
|
|
84
83
|
const usingDeps = collectPkgDeps(api.pkg).filter((name) => {
|
|
85
84
|
return !exclude.some((reg) => reg.test(name));
|
|
86
85
|
});
|
|
87
|
-
if (!usingDeps.length)
|
|
88
|
-
return memo;
|
|
86
|
+
if (!usingDeps.length) return memo;
|
|
89
87
|
const projects = await collectAllProjects({ root });
|
|
90
88
|
const alias = usingDeps.reduce((obj, name) => {
|
|
91
89
|
const pkgInfo = projects[name];
|
package/dist/features/mpa/mpa.js
CHANGED
|
@@ -107,8 +107,7 @@ ${renderer}
|
|
|
107
107
|
});
|
|
108
108
|
});
|
|
109
109
|
api.modifyEntry((memo) => {
|
|
110
|
-
if ("umi" in memo)
|
|
111
|
-
delete memo["umi"];
|
|
110
|
+
if ("umi" in memo) delete memo["umi"];
|
|
112
111
|
api.appData.mpa.entry.forEach((entry) => {
|
|
113
112
|
memo[entry.name] = (0, import_path.join)(api.paths.absTmpPath, entry.tmpFilePath);
|
|
114
113
|
});
|
|
@@ -177,14 +176,10 @@ async function collectEntry(root, opts, mountElementId) {
|
|
|
177
176
|
);
|
|
178
177
|
}
|
|
179
178
|
function getIndexFile(dir) {
|
|
180
|
-
if ((0, import_fs.existsSync)((0, import_path.join)(dir, "index.tsx")))
|
|
181
|
-
|
|
182
|
-
if ((0, import_fs.existsSync)((0, import_path.join)(dir, "index.
|
|
183
|
-
|
|
184
|
-
if ((0, import_fs.existsSync)((0, import_path.join)(dir, "index.jsx")))
|
|
185
|
-
return (0, import_path.join)(dir, "index.jsx");
|
|
186
|
-
if ((0, import_fs.existsSync)((0, import_path.join)(dir, "index.js")))
|
|
187
|
-
return (0, import_path.join)(dir, "index.js");
|
|
179
|
+
if ((0, import_fs.existsSync)((0, import_path.join)(dir, "index.tsx"))) return (0, import_path.join)(dir, "index.tsx");
|
|
180
|
+
if ((0, import_fs.existsSync)((0, import_path.join)(dir, "index.ts"))) return (0, import_path.join)(dir, "index.ts");
|
|
181
|
+
if ((0, import_fs.existsSync)((0, import_path.join)(dir, "index.jsx"))) return (0, import_path.join)(dir, "index.jsx");
|
|
182
|
+
if ((0, import_fs.existsSync)((0, import_path.join)(dir, "index.js"))) return (0, import_path.join)(dir, "index.js");
|
|
188
183
|
return null;
|
|
189
184
|
}
|
|
190
185
|
async function getConfig(indexFile) {
|
|
@@ -38,8 +38,7 @@ var overrides_default = (api) => {
|
|
|
38
38
|
if (api.appData.overridesCSS.length) {
|
|
39
39
|
const filePath = api.appData.overridesCSS[0];
|
|
40
40
|
let content = (0, import_fs.readFileSync)(filePath, "utf-8");
|
|
41
|
-
if (content === cachedContent)
|
|
42
|
-
return;
|
|
41
|
+
if (content === cachedContent) return;
|
|
43
42
|
const subPath = "core/overrides.css";
|
|
44
43
|
const targetPath = (0, import_path.join)(api.paths.absTmpPath, subPath);
|
|
45
44
|
const isLess = filePath.endsWith(".less");
|
|
@@ -43,10 +43,8 @@ async function transform(cssContent, filePath) {
|
|
|
43
43
|
let origin = atRule.params;
|
|
44
44
|
origin = origin.replace(/^url\((.+)\)$/g, "$1");
|
|
45
45
|
origin = origin.replace(/^'(.+)'$/g, "$1").replace(/^"(.+)"$/g, "$1");
|
|
46
|
-
if (origin.startsWith("~"))
|
|
47
|
-
|
|
48
|
-
if (origin.startsWith("/"))
|
|
49
|
-
return;
|
|
46
|
+
if (origin.startsWith("~")) return;
|
|
47
|
+
if (origin.startsWith("/")) return;
|
|
50
48
|
function getResolvedPath(origin2) {
|
|
51
49
|
return (0, import_utils.winPath)(import_path.default.resolve(import_path.default.dirname(filePath), origin2));
|
|
52
50
|
}
|
|
@@ -57,14 +57,10 @@ var phantomDependency_default = (api) => {
|
|
|
57
57
|
const importsBySource = /* @__PURE__ */ new Map();
|
|
58
58
|
for (const file of files) {
|
|
59
59
|
const winP = (0, import_utils.winPath)(file);
|
|
60
|
-
if (winP.includes(".umi/"))
|
|
61
|
-
|
|
62
|
-
if (winP.
|
|
63
|
-
|
|
64
|
-
if (winP.startsWith("../"))
|
|
65
|
-
continue;
|
|
66
|
-
if (import_path.default.isAbsolute(file))
|
|
67
|
-
continue;
|
|
60
|
+
if (winP.includes(".umi/")) continue;
|
|
61
|
+
if (winP.includes("/node_modules/")) continue;
|
|
62
|
+
if (winP.startsWith("../")) continue;
|
|
63
|
+
if (import_path.default.isAbsolute(file)) continue;
|
|
68
64
|
const { imports } = result.metafile.inputs[file];
|
|
69
65
|
for (const imp of imports) {
|
|
70
66
|
if (imp.kind === "import-statement" && imp.external) {
|
|
@@ -77,27 +73,17 @@ var phantomDependency_default = (api) => {
|
|
|
77
73
|
}
|
|
78
74
|
const phantomDeps = [];
|
|
79
75
|
for (const [source, files2] of importsBySource) {
|
|
80
|
-
if (source.startsWith("<"))
|
|
81
|
-
|
|
82
|
-
if (source.startsWith("
|
|
83
|
-
|
|
84
|
-
if (source.startsWith("/"))
|
|
85
|
-
continue;
|
|
86
|
-
if (source.startsWith("@/") || source.startsWith("@@/"))
|
|
87
|
-
continue;
|
|
76
|
+
if (source.startsWith("<")) continue;
|
|
77
|
+
if (source.startsWith(".")) continue;
|
|
78
|
+
if (source.startsWith("/")) continue;
|
|
79
|
+
if (source.startsWith("@/") || source.startsWith("@@/")) continue;
|
|
88
80
|
const pkgName = getPkgName(source);
|
|
89
|
-
if ((_a = api.config.phantomDependency.exclude) == null ? void 0 : _a.includes(pkgName))
|
|
90
|
-
|
|
91
|
-
if ((
|
|
92
|
-
|
|
93
|
-
if ((
|
|
94
|
-
|
|
95
|
-
if ((_d = api.pkg.clientDependencies) == null ? void 0 : _d[pkgName])
|
|
96
|
-
continue;
|
|
97
|
-
if (matchAlias(source, api.config.alias || {}))
|
|
98
|
-
continue;
|
|
99
|
-
if (matchExternals(source, api.config.externals || {}))
|
|
100
|
-
continue;
|
|
81
|
+
if ((_a = api.config.phantomDependency.exclude) == null ? void 0 : _a.includes(pkgName)) continue;
|
|
82
|
+
if ((_b = api.pkg.dependencies) == null ? void 0 : _b[pkgName]) continue;
|
|
83
|
+
if ((_c = api.pkg.devDependencies) == null ? void 0 : _c[pkgName]) continue;
|
|
84
|
+
if ((_d = api.pkg.clientDependencies) == null ? void 0 : _d[pkgName]) continue;
|
|
85
|
+
if (matchAlias(source, api.config.alias || {})) continue;
|
|
86
|
+
if (matchExternals(source, api.config.externals || {})) continue;
|
|
101
87
|
phantomDeps.push(source);
|
|
102
88
|
import_utils.logger.error(
|
|
103
89
|
`[phantomDependency] ${import_utils.chalk.red(
|
|
@@ -118,8 +104,7 @@ var phantomDependency_default = (api) => {
|
|
|
118
104
|
});
|
|
119
105
|
function getPkgName(source) {
|
|
120
106
|
const arr = source.split("/");
|
|
121
|
-
if (source.startsWith("@"))
|
|
122
|
-
return arr[0] + "/" + arr[1];
|
|
107
|
+
if (source.startsWith("@")) return arr[0] + "/" + arr[1];
|
|
123
108
|
return arr[0];
|
|
124
109
|
}
|
|
125
110
|
function matchAlias(source, alias) {
|
|
@@ -53,14 +53,10 @@ async function resolve(context, path2) {
|
|
|
53
53
|
}
|
|
54
54
|
function sortByAffix(opts) {
|
|
55
55
|
return opts.keys.sort((a, b) => {
|
|
56
|
-
if (a.endsWith(opts.affix) && b.endsWith(opts.affix))
|
|
57
|
-
|
|
58
|
-
if (
|
|
59
|
-
|
|
60
|
-
if (b.endsWith(opts.affix))
|
|
61
|
-
return 1;
|
|
62
|
-
else
|
|
63
|
-
return 0;
|
|
56
|
+
if (a.endsWith(opts.affix) && b.endsWith(opts.affix)) return 0;
|
|
57
|
+
if (a.endsWith(opts.affix)) return -1;
|
|
58
|
+
if (b.endsWith(opts.affix)) return 1;
|
|
59
|
+
else return 0;
|
|
64
60
|
});
|
|
65
61
|
}
|
|
66
62
|
function addSlashAffix(key) {
|
|
@@ -84,8 +84,7 @@ var prepare_default = (api) => {
|
|
|
84
84
|
if (api.appData.framework === "vue") {
|
|
85
85
|
return;
|
|
86
86
|
}
|
|
87
|
-
if (!isFirstTime)
|
|
88
|
-
return;
|
|
87
|
+
if (!isFirstTime) return;
|
|
89
88
|
import_utils.logger.info("Preparing...");
|
|
90
89
|
const umiEntry = import_path.default.join(api.paths.absTmpPath, "umi.ts");
|
|
91
90
|
const entryPoints = [umiEntry];
|
|
@@ -38,7 +38,7 @@ function hashString(str) {
|
|
|
38
38
|
return hash;
|
|
39
39
|
}
|
|
40
40
|
function getClassNames(code, filename) {
|
|
41
|
-
const { exports } = import_parcelCSS.parcelCSS.transform({
|
|
41
|
+
const { exports: exports2 } = import_parcelCSS.parcelCSS.transform({
|
|
42
42
|
filename,
|
|
43
43
|
code,
|
|
44
44
|
minify: false,
|
|
@@ -48,7 +48,7 @@ function getClassNames(code, filename) {
|
|
|
48
48
|
dashedIdents: false
|
|
49
49
|
}
|
|
50
50
|
});
|
|
51
|
-
return Object.keys(
|
|
51
|
+
return Object.keys(exports2 || {});
|
|
52
52
|
}
|
|
53
53
|
function cssLoader(opts) {
|
|
54
54
|
return {
|
package/dist/features/ssr/ssr.js
CHANGED
|
@@ -203,8 +203,7 @@ export type {
|
|
|
203
203
|
}
|
|
204
204
|
});
|
|
205
205
|
api.onBuildComplete(async ({ err }) => {
|
|
206
|
-
if (err)
|
|
207
|
-
return;
|
|
206
|
+
if (err) return;
|
|
208
207
|
if (api.config.ssr.platform === "vercel") {
|
|
209
208
|
const jsonFile = (0, import_path.join)(api.cwd, "vercel.json");
|
|
210
209
|
const json = (0, import_fs.existsSync)(jsonFile) ? import_utils.fsExtra.readJSONSync(jsonFile) : {};
|
|
@@ -29,8 +29,8 @@ async function getModuleExports(opts) {
|
|
|
29
29
|
const { file } = opts;
|
|
30
30
|
const content = (0, import_fs.readFileSync)(file, "utf-8");
|
|
31
31
|
try {
|
|
32
|
-
const [_,
|
|
33
|
-
return
|
|
32
|
+
const [_, exports2] = await (0, import_bundler_utils.parseModule)({ content, path: file });
|
|
33
|
+
return exports2 || [];
|
|
34
34
|
} catch (e) {
|
|
35
35
|
console.log(
|
|
36
36
|
`Parse file ${import_utils.chalk.red(
|
|
@@ -151,17 +151,17 @@ async function getRoutes(opts) {
|
|
|
151
151
|
const enableRouteProps = !opts.api.userConfig.routes;
|
|
152
152
|
const needCollectExports = enableSSR || enableClientLoader || enableRouteProps;
|
|
153
153
|
if (needCollectExports) {
|
|
154
|
-
const
|
|
154
|
+
const exports2 = isJSFile && (0, import_fs.existsSync)(file) ? await (0, import_getModuleExports.getModuleExports)({
|
|
155
155
|
file
|
|
156
156
|
}) : [];
|
|
157
157
|
if (enableSSR) {
|
|
158
|
-
routes[id].hasServerLoader =
|
|
159
|
-
routes[id].hasMetadataLoader =
|
|
158
|
+
routes[id].hasServerLoader = exports2.includes("serverLoader");
|
|
159
|
+
routes[id].hasMetadataLoader = exports2.includes("metadataLoader");
|
|
160
160
|
}
|
|
161
|
-
if (enableClientLoader &&
|
|
161
|
+
if (enableClientLoader && exports2.includes("clientLoader")) {
|
|
162
162
|
routes[id].clientLoader = `clientLoaders['${id}']`;
|
|
163
163
|
}
|
|
164
|
-
if (enableRouteProps &&
|
|
164
|
+
if (enableRouteProps && exports2.includes("routeProps")) {
|
|
165
165
|
routes[id].routeProps = `routeProps['${id}']`;
|
|
166
166
|
}
|
|
167
167
|
}
|
|
@@ -239,8 +239,7 @@ function getProjectRootCwd(cwd) {
|
|
|
239
239
|
const splittedCwd = cwd.split("/");
|
|
240
240
|
for (let level = -1; level >= -3; level -= 1) {
|
|
241
241
|
const rootCwd = splittedCwd.slice(0, level).join("/");
|
|
242
|
-
if (!rootCwd)
|
|
243
|
-
break;
|
|
242
|
+
if (!rootCwd) break;
|
|
244
243
|
if ((0, import_utils.isMonorepo)({ root: rootCwd })) {
|
|
245
244
|
return rootCwd;
|
|
246
245
|
}
|
package/dist/features/ui/ui.js
CHANGED
|
@@ -27,9 +27,15 @@ var import_fs = require("fs");
|
|
|
27
27
|
var import_path = require("path");
|
|
28
28
|
var { watch } = import_utils.chokidar;
|
|
29
29
|
var AutoUpdateFolderCache = class {
|
|
30
|
+
fileContentCache = {};
|
|
31
|
+
watcher;
|
|
32
|
+
readyPromise;
|
|
33
|
+
cwd;
|
|
34
|
+
pendingChanges = [];
|
|
35
|
+
debouchedHandleChanges;
|
|
36
|
+
onCacheUpdated;
|
|
37
|
+
filesLoader;
|
|
30
38
|
constructor(opts) {
|
|
31
|
-
this.fileContentCache = {};
|
|
32
|
-
this.pendingChanges = [];
|
|
33
39
|
this.cwd = opts.cwd;
|
|
34
40
|
this.onCacheUpdated = opts.onCacheUpdate;
|
|
35
41
|
this.filesLoader = opts.filesLoader || this._defaultLoader;
|
|
@@ -59,7 +65,7 @@ var AutoUpdateFolderCache = class {
|
|
|
59
65
|
modifiedFiles.push(c.path);
|
|
60
66
|
break;
|
|
61
67
|
default:
|
|
62
|
-
((_n) => {
|
|
68
|
+
/* @__PURE__ */ ((_n) => {
|
|
63
69
|
})(c.event);
|
|
64
70
|
}
|
|
65
71
|
}
|
|
@@ -41,9 +41,12 @@ var import_path = require("path");
|
|
|
41
41
|
var import_AutoUpdateFolderCache = require("./AutoUpdateFolderCache");
|
|
42
42
|
var import_constant = require("./constant");
|
|
43
43
|
var AutoUpdateSrcCodeCache = class {
|
|
44
|
+
srcPath;
|
|
45
|
+
cachePath;
|
|
46
|
+
folderCache;
|
|
47
|
+
listeners = [];
|
|
48
|
+
ignores = import_constant.DEFAULT_SRC_IGNORES;
|
|
44
49
|
constructor(opts) {
|
|
45
|
-
this.listeners = [];
|
|
46
|
-
this.ignores = import_constant.DEFAULT_SRC_IGNORES;
|
|
47
50
|
this.srcPath = opts.cwd;
|
|
48
51
|
this.cachePath = opts.cachePath;
|
|
49
52
|
this.folderCache = new import_AutoUpdateFolderCache.AutoUpdateFolderCache({
|
|
@@ -26,9 +26,12 @@ var import_utils = require("@umijs/utils");
|
|
|
26
26
|
var import_path = require("path");
|
|
27
27
|
var { watch } = import_utils.chokidar;
|
|
28
28
|
var FolderWatch = class {
|
|
29
|
+
cwd;
|
|
30
|
+
watcher;
|
|
31
|
+
readyPromise;
|
|
32
|
+
listeners = [];
|
|
33
|
+
eventMap = { add: 0, unlink: 0, change: 0 };
|
|
29
34
|
constructor(opts) {
|
|
30
|
-
this.listeners = [];
|
|
31
|
-
this.eventMap = { add: 0, unlink: 0, change: 0 };
|
|
32
35
|
this.cwd = opts.cwd;
|
|
33
36
|
this.watcher = watch(`./**/*.{${opts.exts.join(",")}}`, {
|
|
34
37
|
ignored: opts.ignored || [],
|
|
@@ -41,12 +41,16 @@ var import_path = require("path");
|
|
|
41
41
|
var import_constant = require("./constant");
|
|
42
42
|
var import_FolderWatch = require("./FolderWatch");
|
|
43
43
|
var LazySourceCodeCache = class {
|
|
44
|
+
srcPath;
|
|
45
|
+
cachePath;
|
|
46
|
+
folderWatch;
|
|
47
|
+
listeners = [];
|
|
48
|
+
ignores = import_constant.DEFAULT_SRC_IGNORES;
|
|
49
|
+
fileContentCache = {};
|
|
50
|
+
pendingFilesEvents = [];
|
|
51
|
+
root;
|
|
52
|
+
tsConfigRaw = "{}";
|
|
44
53
|
constructor(opts) {
|
|
45
|
-
this.listeners = [];
|
|
46
|
-
this.ignores = import_constant.DEFAULT_SRC_IGNORES;
|
|
47
|
-
this.fileContentCache = {};
|
|
48
|
-
this.pendingFilesEvents = [];
|
|
49
|
-
this.tsConfigRaw = "{}";
|
|
50
54
|
this.root = opts.root;
|
|
51
55
|
this.srcPath = opts.cwd;
|
|
52
56
|
this.cachePath = opts.cachePath;
|
|
@@ -143,7 +147,7 @@ var LazySourceCodeCache = class {
|
|
|
143
147
|
modifiedFiles.push(c.path);
|
|
144
148
|
break;
|
|
145
149
|
default:
|
|
146
|
-
((_n) => {
|
|
150
|
+
/* @__PURE__ */ ((_n) => {
|
|
147
151
|
})(c.event);
|
|
148
152
|
}
|
|
149
153
|
}
|
package/dist/libs/scan.js
CHANGED
|
@@ -62,8 +62,7 @@ async function scanContent(opts) {
|
|
|
62
62
|
}
|
|
63
63
|
).map((imp) => {
|
|
64
64
|
let importType = "import" /* import */;
|
|
65
|
-
if (imp.d > -1)
|
|
66
|
-
importType = "dynamicImport" /* dynamicImport */;
|
|
65
|
+
if (imp.d > -1) importType = "dynamicImport" /* dynamicImport */;
|
|
67
66
|
if (opts.content.slice(imp.ss, imp.se).startsWith("export ")) {
|
|
68
67
|
importType = "export" /* export */;
|
|
69
68
|
}
|
|
@@ -110,8 +109,7 @@ async function scan(opts) {
|
|
|
110
109
|
const ret = {};
|
|
111
110
|
while (queueDeps.length) {
|
|
112
111
|
const depPath = queueDeps.shift();
|
|
113
|
-
if (cache.has(depPath))
|
|
114
|
-
continue;
|
|
112
|
+
if (cache.has(depPath)) continue;
|
|
115
113
|
const content = await getContent(depPath);
|
|
116
114
|
const { deps } = await scanContent({ content });
|
|
117
115
|
cache.set(depPath, deps);
|
|
@@ -96,8 +96,7 @@ async function setupExportExtractBuilder(opts) {
|
|
|
96
96
|
setup(build) {
|
|
97
97
|
let entry;
|
|
98
98
|
build.onResolve({ filter: /.*/ }, (args) => {
|
|
99
|
-
if (args.kind === "entry-point")
|
|
100
|
-
entry = args.path;
|
|
99
|
+
if (args.kind === "entry-point") entry = args.path;
|
|
101
100
|
if (args.kind === "entry-point" || args.importer === entry) {
|
|
102
101
|
return { path: (0, import_path.resolve)(args.resolveDir, args.path) };
|
|
103
102
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@umijs/preset-umi",
|
|
3
|
-
"version": "4.6.
|
|
3
|
+
"version": "4.6.4",
|
|
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/
|
|
47
|
-
"@umijs/
|
|
48
|
-
"@umijs/bundler-
|
|
49
|
-
"@umijs/bundler-
|
|
50
|
-
"@umijs/bundler-utoopack": "4.6.
|
|
51
|
-
"@umijs/
|
|
52
|
-
"@umijs/
|
|
53
|
-
"@umijs/
|
|
54
|
-
"@umijs/
|
|
55
|
-
"@umijs/
|
|
56
|
-
"@umijs/
|
|
57
|
-
"@umijs/
|
|
58
|
-
"@umijs/
|
|
59
|
-
"@umijs/
|
|
60
|
-
"@umijs/
|
|
46
|
+
"@umijs/bundler-esbuild": "4.6.4",
|
|
47
|
+
"@umijs/bundler-vite": "4.6.4",
|
|
48
|
+
"@umijs/bundler-utils": "4.6.4",
|
|
49
|
+
"@umijs/bundler-webpack": "4.6.4",
|
|
50
|
+
"@umijs/bundler-utoopack": "4.6.4",
|
|
51
|
+
"@umijs/core": "4.6.4",
|
|
52
|
+
"@umijs/ast": "4.6.4",
|
|
53
|
+
"@umijs/mfsu": "4.6.4",
|
|
54
|
+
"@umijs/plugin-run": "4.6.4",
|
|
55
|
+
"@umijs/renderer-react": "4.6.4",
|
|
56
|
+
"@umijs/server": "4.6.4",
|
|
57
|
+
"@umijs/ui": "3.0.1",
|
|
58
|
+
"@umijs/zod2ts": "4.6.4",
|
|
59
|
+
"@umijs/babel-preset-umi": "4.6.4",
|
|
60
|
+
"@umijs/utils": "4.6.4"
|
|
61
61
|
},
|
|
62
62
|
"devDependencies": {
|
|
63
63
|
"@manypkg/get-packages": "1.1.3",
|