@umijs/preset-umi 4.0.49 → 4.0.51
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/generators/tailwindcss.js +2 -2
- package/dist/commands/verify-commit.js +1 -0
- package/dist/features/apiRoute/apiRoute.js +3 -0
- package/dist/features/check/check.js +14 -1
- package/dist/features/clientLoader/clientLoader.js +3 -0
- package/dist/features/depsOnDemand/depsOnDemand.d.ts +10 -0
- package/dist/features/depsOnDemand/depsOnDemand.js +50 -26
- package/dist/features/legacy/legacy.js +1 -0
- package/dist/features/monorepo/redirect.js +63 -17
- package/dist/features/mpa/extractExports.js +6 -1
- package/dist/features/polyfill/polyfill.js +4 -2
- package/dist/features/prepare/build.d.ts +2 -1
- package/dist/features/prepare/build.js +3 -2
- package/dist/features/prepare/esbuildPlugins/esbuildExternalPlugin.js +19 -37
- package/dist/features/prepare/prepare.js +4 -1
- package/dist/features/ssr/builder/builder.js +3 -0
- package/dist/features/{polyfill/swcPolyfill.d.ts → swc/swc.d.ts} +0 -0
- package/dist/features/swc/swc.js +47 -0
- package/dist/features/tmpFiles/tmpFiles.js +14 -3
- package/dist/index.js +1 -0
- package/dist/registerMethods.js +1 -0
- package/dist/types.d.ts +2 -0
- package/package.json +12 -12
- package/templates/history.tpl +3 -2
- package/templates/historyIntelli.tpl +127 -0
- package/templates/plugin.tpl +7 -5
- package/templates/route.tpl +2 -1
- package/dist/features/polyfill/swcPolyfill.js +0 -49
|
@@ -56,8 +56,8 @@ var tailwindcss_default = (api) => {
|
|
|
56
56
|
module.exports = {
|
|
57
57
|
content: [
|
|
58
58
|
'./${srcPrefix}pages/**/*.tsx',
|
|
59
|
-
'./${srcPrefix}components
|
|
60
|
-
'./${srcPrefix}layouts
|
|
59
|
+
'./${srcPrefix}components/**/*.tsx',
|
|
60
|
+
'./${srcPrefix}layouts/**/*.tsx',
|
|
61
61
|
],
|
|
62
62
|
}
|
|
63
63
|
`.trimStart()
|
|
@@ -128,6 +128,9 @@ var apiRoute_default = (api) => {
|
|
|
128
128
|
const middlewares = await api.applyPlugins({
|
|
129
129
|
key: "addApiMiddlewares"
|
|
130
130
|
});
|
|
131
|
+
middlewares.forEach((middleware) => {
|
|
132
|
+
middleware.path = (0, import_utils.winPath)(middleware.path);
|
|
133
|
+
});
|
|
131
134
|
api.writeTmpFile({
|
|
132
135
|
noPluginDir: true,
|
|
133
136
|
path: "api/_middlewares.ts",
|
|
@@ -28,8 +28,8 @@ __export(check_exports, {
|
|
|
28
28
|
default: () => check_default
|
|
29
29
|
});
|
|
30
30
|
module.exports = __toCommonJS(check_exports);
|
|
31
|
-
var import_assert = __toESM(require("assert"));
|
|
32
31
|
var import_utils = require("@umijs/utils");
|
|
32
|
+
var import_assert = __toESM(require("assert"));
|
|
33
33
|
var check_default = (api) => {
|
|
34
34
|
api.onCheck(async () => {
|
|
35
35
|
(0, import_assert.default)(
|
|
@@ -86,6 +86,19 @@ ${import_utils.chalk.red(
|
|
|
86
86
|
);
|
|
87
87
|
}
|
|
88
88
|
});
|
|
89
|
+
api.onPrepareBuildSuccess(({ result }) => {
|
|
90
|
+
var _a;
|
|
91
|
+
const imps = Object.keys(((_a = result.metafile) == null ? void 0 : _a.inputs) || {}).filter(
|
|
92
|
+
(f) => f.startsWith("mock/")
|
|
93
|
+
);
|
|
94
|
+
if (imps.length) {
|
|
95
|
+
throw new Error(
|
|
96
|
+
`Detected mock imports from src: ${imps.join(
|
|
97
|
+
", "
|
|
98
|
+
)}. \`mock/**\` is not allowed to import.`
|
|
99
|
+
);
|
|
100
|
+
}
|
|
101
|
+
});
|
|
89
102
|
function isAbsolutePath(path) {
|
|
90
103
|
return path.startsWith("/") || path.startsWith("@fs/");
|
|
91
104
|
}
|
|
@@ -1,3 +1,13 @@
|
|
|
1
1
|
import { IApi } from '../../types';
|
|
2
|
+
export interface IOnDemandInstallDep {
|
|
3
|
+
name: string;
|
|
4
|
+
version: string;
|
|
5
|
+
reason?: string;
|
|
6
|
+
/**
|
|
7
|
+
* install dev dep by default
|
|
8
|
+
* @default true
|
|
9
|
+
*/
|
|
10
|
+
dev?: boolean;
|
|
11
|
+
}
|
|
2
12
|
declare const _default: (api: IApi) => void;
|
|
3
13
|
export default _default;
|
|
@@ -26,26 +26,29 @@ var import_utils = require("@umijs/utils");
|
|
|
26
26
|
var import_fs = require("fs");
|
|
27
27
|
var import_path = require("path");
|
|
28
28
|
var depsOnDemand_default = (api) => {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
{
|
|
38
|
-
name: "swc-plugin-auto-css-modules",
|
|
39
|
-
version: `^${bundlerWebpackPkg.devDependencies["swc-plugin-auto-css-modules"]}`
|
|
29
|
+
api.onStart(async () => {
|
|
30
|
+
const deps = import_utils.lodash.uniqBy(
|
|
31
|
+
await api.applyPlugins({
|
|
32
|
+
key: "addOnDemandDeps",
|
|
33
|
+
initialValue: []
|
|
34
|
+
}),
|
|
35
|
+
(dep) => {
|
|
36
|
+
return dep.name;
|
|
40
37
|
}
|
|
41
|
-
|
|
42
|
-
const { missingDeps } = checkDeps({
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
38
|
+
);
|
|
39
|
+
const { missingDeps } = checkDeps({ deps });
|
|
40
|
+
if (missingDeps.length) {
|
|
41
|
+
const hasReason = missingDeps.some((dep) => dep.reason);
|
|
42
|
+
const loggerText = [
|
|
43
|
+
`Install dependencies ${missingDeps.map(({ name }) => import_utils.chalk.green(name)).join(", ")} on demand.`,
|
|
44
|
+
...hasReason ? [
|
|
45
|
+
` ${import_utils.chalk.bold.bgBlue(" REASONS ")}`,
|
|
46
|
+
...missingDeps.filter((dep) => dep.reason).map(
|
|
47
|
+
(dep) => ` · ${import_utils.chalk.cyan(dep.name)}${dep.outdated ? import_utils.chalk.gray("(outdated)") : ""}: ${dep.reason}`
|
|
48
|
+
)
|
|
49
|
+
] : []
|
|
50
|
+
].join("\n");
|
|
51
|
+
import_utils.logger.info(loggerText);
|
|
49
52
|
addDeps({
|
|
50
53
|
pkgPath: api.pkgPath || (0, import_path.join)(api.cwd, "package.json"),
|
|
51
54
|
deps: missingDeps
|
|
@@ -69,7 +72,10 @@ var depsOnDemand_default = (api) => {
|
|
|
69
72
|
const userVersion = import_utils.semver.minVersion(installed);
|
|
70
73
|
const isOutdated = !userVersion || import_utils.semver.ltr(userVersion, dep.version);
|
|
71
74
|
if (isOutdated) {
|
|
72
|
-
missingDeps.push(
|
|
75
|
+
missingDeps.push({
|
|
76
|
+
...dep,
|
|
77
|
+
outdated: true
|
|
78
|
+
});
|
|
73
79
|
}
|
|
74
80
|
}
|
|
75
81
|
});
|
|
@@ -79,12 +85,30 @@ var depsOnDemand_default = (api) => {
|
|
|
79
85
|
}
|
|
80
86
|
};
|
|
81
87
|
function addDeps(opts) {
|
|
82
|
-
const
|
|
83
|
-
pkg
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
+
const { pkgPath, deps } = opts;
|
|
89
|
+
const pkg = (0, import_fs.existsSync)(pkgPath) ? import_utils.fsExtra.readJSONSync(pkgPath) : {};
|
|
90
|
+
const [devDependencies, dependencies] = [
|
|
91
|
+
deps.filter((dep) => dep.dev !== false),
|
|
92
|
+
deps.filter((dep) => dep.dev === false)
|
|
93
|
+
];
|
|
94
|
+
if (devDependencies.length) {
|
|
95
|
+
pkg.devDependencies || (pkg.devDependencies = {});
|
|
96
|
+
devDependencies.forEach((dep) => {
|
|
97
|
+
pkg.devDependencies[dep.name] = dep.version;
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
if (dependencies.length) {
|
|
101
|
+
pkg.dependencies || (pkg.dependencies = {});
|
|
102
|
+
dependencies.forEach((dep) => {
|
|
103
|
+
pkg.dependencies[dep.name] = dep.version;
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
import_utils.fsExtra.writeFileSync(
|
|
107
|
+
opts.pkgPath,
|
|
108
|
+
`${JSON.stringify(pkg, null, 2)}
|
|
109
|
+
`,
|
|
110
|
+
"utf-8"
|
|
111
|
+
);
|
|
88
112
|
}
|
|
89
113
|
// Annotate the CommonJS export names for ESM import in node:
|
|
90
114
|
0 && (module.exports = {});
|
|
@@ -43,7 +43,8 @@ var redirect_default = (api) => {
|
|
|
43
43
|
Joi.boolean(),
|
|
44
44
|
Joi.object({
|
|
45
45
|
srcDir: Joi.array().items(Joi.string()),
|
|
46
|
-
exclude: Joi.array().items(Joi.object().instance(RegExp))
|
|
46
|
+
exclude: Joi.array().items(Joi.object().instance(RegExp)),
|
|
47
|
+
peerDeps: Joi.boolean()
|
|
47
48
|
})
|
|
48
49
|
);
|
|
49
50
|
}
|
|
@@ -51,8 +52,9 @@ var redirect_default = (api) => {
|
|
|
51
52
|
enableBy: api.EnableBy.config
|
|
52
53
|
});
|
|
53
54
|
api.modifyConfig(async (memo) => {
|
|
55
|
+
const currentProjectRoot = process.env.APP_ROOT ? process.cwd() : api.cwd;
|
|
54
56
|
const rootPkg = await (0, import_pkg_up.pkgUp)({
|
|
55
|
-
cwd: (0, import_path.dirname)(
|
|
57
|
+
cwd: (0, import_path.dirname)(currentProjectRoot)
|
|
56
58
|
});
|
|
57
59
|
if (!rootPkg)
|
|
58
60
|
return memo;
|
|
@@ -62,7 +64,7 @@ var redirect_default = (api) => {
|
|
|
62
64
|
`The 'monorepoRedirect' option can only be used in monorepo, you don't need configure.`
|
|
63
65
|
);
|
|
64
66
|
const config = memo.monorepoRedirect || {};
|
|
65
|
-
const { exclude = [], srcDir = ["src"] } = config;
|
|
67
|
+
const { exclude = [], srcDir = ["src"], peerDeps = false } = config;
|
|
66
68
|
if ((0, import_utils.isLocalDev)()) {
|
|
67
69
|
import_utils.logger.info(
|
|
68
70
|
`[monorepoRedirect]: Auto excluded 'umi' package in local dev scene`
|
|
@@ -76,12 +78,12 @@ var redirect_default = (api) => {
|
|
|
76
78
|
return memo;
|
|
77
79
|
const projects = await collectAllProjects({ root });
|
|
78
80
|
const alias = usingDeps.reduce((obj, name) => {
|
|
79
|
-
const
|
|
80
|
-
if (!
|
|
81
|
+
const pkgInfo = projects[name];
|
|
82
|
+
if (!pkgInfo) {
|
|
81
83
|
return obj;
|
|
82
84
|
}
|
|
83
85
|
srcDir.some((dirName) => {
|
|
84
|
-
const dirPath = (0, import_path.join)(
|
|
86
|
+
const dirPath = (0, import_path.join)(pkgInfo.dir, dirName);
|
|
85
87
|
if ((0, import_fs.existsSync)(dirPath) && (0, import_fs.statSync)(dirPath).isDirectory()) {
|
|
86
88
|
obj[name] = dirPath;
|
|
87
89
|
return true;
|
|
@@ -89,8 +91,44 @@ var redirect_default = (api) => {
|
|
|
89
91
|
});
|
|
90
92
|
return obj;
|
|
91
93
|
}, {});
|
|
94
|
+
const peerDepsAliasMap = {};
|
|
95
|
+
if (peerDeps) {
|
|
96
|
+
Object.entries(projects).forEach(([_name, pkgInfo]) => {
|
|
97
|
+
var _a;
|
|
98
|
+
const willResolveDeps = ((_a = pkgInfo.packageJson) == null ? void 0 : _a.peerDependencies) || {};
|
|
99
|
+
Object.keys(willResolveDeps).forEach((depName) => {
|
|
100
|
+
if (peerDepsAliasMap[depName]) {
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
if (projects[depName]) {
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
const resolved = tryResolveDep({
|
|
107
|
+
name: depName,
|
|
108
|
+
from: currentProjectRoot
|
|
109
|
+
});
|
|
110
|
+
if (resolved) {
|
|
111
|
+
peerDepsAliasMap[depName] = resolved;
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
114
|
+
const resolvedFromOtherProject = tryResolveDep({
|
|
115
|
+
name: depName,
|
|
116
|
+
from: pkgInfo.dir
|
|
117
|
+
});
|
|
118
|
+
if (resolvedFromOtherProject) {
|
|
119
|
+
peerDepsAliasMap[depName] = resolvedFromOtherProject;
|
|
120
|
+
}
|
|
121
|
+
});
|
|
122
|
+
import_utils.logger.debug(
|
|
123
|
+
`[monorepoRedirect]: resolved peer deps ${Object.keys(
|
|
124
|
+
peerDepsAliasMap
|
|
125
|
+
).map((i) => import_utils.chalk.green(i)).join(", ")} from ${(0, import_path.basename)(pkgInfo.dir)}`
|
|
126
|
+
);
|
|
127
|
+
});
|
|
128
|
+
}
|
|
92
129
|
memo.alias = {
|
|
93
130
|
...memo.alias,
|
|
131
|
+
...peerDepsAliasMap,
|
|
94
132
|
...alias
|
|
95
133
|
};
|
|
96
134
|
return memo;
|
|
@@ -106,17 +144,25 @@ function collectPkgDeps(pkg) {
|
|
|
106
144
|
}
|
|
107
145
|
async function collectAllProjects(opts) {
|
|
108
146
|
const workspaces = await (0, import_get_packages.getPackages)(opts.root);
|
|
109
|
-
return workspaces.packages.reduce(
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
147
|
+
return workspaces.packages.reduce((obj, pkg) => {
|
|
148
|
+
var _a;
|
|
149
|
+
const name = (_a = pkg.packageJson) == null ? void 0 : _a.name;
|
|
150
|
+
if (name) {
|
|
151
|
+
obj[name] = pkg;
|
|
152
|
+
}
|
|
153
|
+
return obj;
|
|
154
|
+
}, {});
|
|
155
|
+
}
|
|
156
|
+
function tryResolveDep(opts) {
|
|
157
|
+
const { name, from } = opts;
|
|
158
|
+
try {
|
|
159
|
+
return (0, import_path.dirname)(
|
|
160
|
+
import_utils.resolve.sync(`${name}/package.json`, {
|
|
161
|
+
basedir: from
|
|
162
|
+
})
|
|
163
|
+
);
|
|
164
|
+
} catch {
|
|
165
|
+
}
|
|
120
166
|
}
|
|
121
167
|
// Annotate the CommonJS export names for ESM import in node:
|
|
122
168
|
0 && (module.exports = {});
|
|
@@ -30,6 +30,7 @@ __export(extractExports_exports, {
|
|
|
30
30
|
module.exports = __toCommonJS(extractExports_exports);
|
|
31
31
|
var import_esbuild = __toESM(require("@umijs/bundler-utils/compiled/esbuild"));
|
|
32
32
|
var import_utils = require("@umijs/utils");
|
|
33
|
+
var import_path = require("path");
|
|
33
34
|
async function extractExports(opts) {
|
|
34
35
|
const res = await import_esbuild.default.build({
|
|
35
36
|
format: "cjs",
|
|
@@ -44,7 +45,10 @@ async function extractExports(opts) {
|
|
|
44
45
|
".eot": "text",
|
|
45
46
|
".flac": "text",
|
|
46
47
|
".gif": "text",
|
|
48
|
+
".htm": "text",
|
|
49
|
+
".html": "text",
|
|
47
50
|
".ico": "text",
|
|
51
|
+
".icon": "text",
|
|
48
52
|
".jpeg": "text",
|
|
49
53
|
".jpg": "text",
|
|
50
54
|
".js": "jsx",
|
|
@@ -98,7 +102,8 @@ async function extractExports(opts) {
|
|
|
98
102
|
import * as x from "${(0, import_utils.winPath)(args.path)}";
|
|
99
103
|
ret = x.${opts.exportName} || {};
|
|
100
104
|
`,
|
|
101
|
-
loader: "ts"
|
|
105
|
+
loader: "ts",
|
|
106
|
+
resolveDir: (0, import_path.dirname)(args.path)
|
|
102
107
|
};
|
|
103
108
|
});
|
|
104
109
|
}
|
|
@@ -70,7 +70,8 @@ export {};
|
|
|
70
70
|
(0, import_path.join)(__dirname, "../../../package.json")
|
|
71
71
|
),
|
|
72
72
|
modules: false,
|
|
73
|
-
targets: api.config.targets
|
|
73
|
+
targets: api.config.targets,
|
|
74
|
+
ignoreBrowserslistConfig: true
|
|
74
75
|
}
|
|
75
76
|
]
|
|
76
77
|
],
|
|
@@ -78,7 +79,8 @@ export {};
|
|
|
78
79
|
require.resolve("@umijs/babel-preset-umi/dist/plugins/lockCoreJS")
|
|
79
80
|
],
|
|
80
81
|
babelrc: false,
|
|
81
|
-
configFile: false
|
|
82
|
+
configFile: false,
|
|
83
|
+
browserslistConfigFile: false
|
|
82
84
|
}
|
|
83
85
|
);
|
|
84
86
|
api.writeTmpFile({
|
|
@@ -35,6 +35,7 @@ var import_esbuildAliasPlugin = require("./esbuildPlugins/esbuildAliasPlugin");
|
|
|
35
35
|
var import_esbuildExternalPlugin = require("./esbuildPlugins/esbuildExternalPlugin");
|
|
36
36
|
async function build(opts) {
|
|
37
37
|
var _a;
|
|
38
|
+
const outdir = import_path.default.join(import_path.default.dirname(opts.entryPoints[0]), "out");
|
|
38
39
|
return await import_esbuild.default.build({
|
|
39
40
|
format: "esm",
|
|
40
41
|
platform: "browser",
|
|
@@ -59,8 +60,8 @@ async function build(opts) {
|
|
|
59
60
|
bundle: true,
|
|
60
61
|
logLevel: "error",
|
|
61
62
|
entryPoints: opts.entryPoints,
|
|
62
|
-
write: false,
|
|
63
|
-
outdir
|
|
63
|
+
write: opts.write || false,
|
|
64
|
+
outdir,
|
|
64
65
|
metafile: true,
|
|
65
66
|
plugins: [
|
|
66
67
|
(0, import_esbuildExternalPlugin.esbuildExternalPlugin)(),
|
|
@@ -34,15 +34,12 @@ function esbuildExternalPlugin() {
|
|
|
34
34
|
return {
|
|
35
35
|
name: "esbuildExternalPlugin",
|
|
36
36
|
setup(build) {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
build.onResolve({ filter }, () => {
|
|
37
|
+
build.onResolve({ filter: /.*/ }, (args) => {
|
|
38
|
+
if (!isSource(args.path)) {
|
|
40
39
|
return {
|
|
41
40
|
external: true
|
|
42
41
|
};
|
|
43
|
-
}
|
|
44
|
-
});
|
|
45
|
-
build.onResolve({ filter: /.*/ }, (args) => {
|
|
42
|
+
}
|
|
46
43
|
if (args.path.startsWith(".")) {
|
|
47
44
|
return null;
|
|
48
45
|
}
|
|
@@ -65,37 +62,22 @@ function esbuildExternalPlugin() {
|
|
|
65
62
|
}
|
|
66
63
|
};
|
|
67
64
|
}
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
"
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
"md",
|
|
85
|
-
"mdx",
|
|
86
|
-
"mp3",
|
|
87
|
-
"mp4",
|
|
88
|
-
"ogg",
|
|
89
|
-
"otf",
|
|
90
|
-
"png",
|
|
91
|
-
"svg",
|
|
92
|
-
"ttf",
|
|
93
|
-
"wav",
|
|
94
|
-
"webm",
|
|
95
|
-
"webp",
|
|
96
|
-
"woff",
|
|
97
|
-
"woff2"
|
|
98
|
-
];
|
|
65
|
+
function parseExt(file) {
|
|
66
|
+
const ext = import_path.default.extname(file);
|
|
67
|
+
const idx = ext.indexOf("?");
|
|
68
|
+
if (idx > 0) {
|
|
69
|
+
return ext.slice(0, idx);
|
|
70
|
+
}
|
|
71
|
+
return ext;
|
|
72
|
+
}
|
|
73
|
+
var SOURCE_REG = /\.(t|j)sx?$/;
|
|
74
|
+
function isSource(file) {
|
|
75
|
+
if (SOURCE_REG.test(file)) {
|
|
76
|
+
return true;
|
|
77
|
+
}
|
|
78
|
+
const ext = parseExt(file);
|
|
79
|
+
return !ext;
|
|
80
|
+
}
|
|
99
81
|
// Annotate the CommonJS export names for ESM import in node:
|
|
100
82
|
0 && (module.exports = {
|
|
101
83
|
esbuildExternalPlugin
|
|
@@ -48,6 +48,9 @@ var prepare_default = (api) => {
|
|
|
48
48
|
key: "addPrepareBuildPlugins",
|
|
49
49
|
initialValue: []
|
|
50
50
|
});
|
|
51
|
+
const unwrappedAlias = import_utils.aliasUtils.parseCircleAlias({
|
|
52
|
+
alias: api.config.alias
|
|
53
|
+
});
|
|
51
54
|
const buildResult = await build({
|
|
52
55
|
entryPoints: [entryFile],
|
|
53
56
|
watch: watch && {
|
|
@@ -62,7 +65,7 @@ var prepare_default = (api) => {
|
|
|
62
65
|
}
|
|
63
66
|
},
|
|
64
67
|
config: {
|
|
65
|
-
alias:
|
|
68
|
+
alias: unwrappedAlias
|
|
66
69
|
},
|
|
67
70
|
plugins
|
|
68
71
|
});
|
|
File without changes
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
|
|
19
|
+
// src/features/swc/swc.ts
|
|
20
|
+
var swc_exports = {};
|
|
21
|
+
__export(swc_exports, {
|
|
22
|
+
default: () => swc_default
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(swc_exports);
|
|
25
|
+
var swc_default = (api) => {
|
|
26
|
+
api.addOnDemandDeps(() => {
|
|
27
|
+
const enabled = api.config.srcTranspiler === "swc" || api.userConfig.srcTranspiler === "swc";
|
|
28
|
+
if (!enabled) {
|
|
29
|
+
return [];
|
|
30
|
+
}
|
|
31
|
+
const bundlerWebpackPkg = require("@umijs/bundler-webpack/package.json");
|
|
32
|
+
return [
|
|
33
|
+
{
|
|
34
|
+
name: "@swc/core",
|
|
35
|
+
version: `^${bundlerWebpackPkg.devDependencies["@swc/core"]}`,
|
|
36
|
+
reason: `swc is used, install swc dependencies`
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
name: "swc-plugin-auto-css-modules",
|
|
40
|
+
version: `^${bundlerWebpackPkg.devDependencies["swc-plugin-auto-css-modules"]}`,
|
|
41
|
+
reason: `swc plugins`
|
|
42
|
+
}
|
|
43
|
+
];
|
|
44
|
+
});
|
|
45
|
+
};
|
|
46
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
47
|
+
0 && (module.exports = {});
|
|
@@ -380,7 +380,8 @@ export default function EmptyRoute() {
|
|
|
380
380
|
hasDefaultExport: appPluginRegExp.test(plugin),
|
|
381
381
|
path: (0, import_utils.winPath)(plugin)
|
|
382
382
|
})),
|
|
383
|
-
validKeys
|
|
383
|
+
validKeys,
|
|
384
|
+
isViteMode: !!api.config.vite
|
|
384
385
|
}
|
|
385
386
|
});
|
|
386
387
|
if (api.config.ssr) {
|
|
@@ -426,6 +427,14 @@ export default function EmptyRoute() {
|
|
|
426
427
|
historyPath
|
|
427
428
|
}
|
|
428
429
|
});
|
|
430
|
+
api.writeTmpFile({
|
|
431
|
+
noPluginDir: true,
|
|
432
|
+
path: "core/historyIntelli.ts",
|
|
433
|
+
tplPath: (0, import_path.join)(import_constants.TEMPLATES_DIR, "historyIntelli.tpl"),
|
|
434
|
+
context: {
|
|
435
|
+
historyPath
|
|
436
|
+
}
|
|
437
|
+
});
|
|
429
438
|
}
|
|
430
439
|
});
|
|
431
440
|
function checkMembers(opts) {
|
|
@@ -559,8 +568,10 @@ export default function EmptyRoute() {
|
|
|
559
568
|
runtimeConfigType
|
|
560
569
|
}
|
|
561
570
|
});
|
|
562
|
-
exports.
|
|
563
|
-
|
|
571
|
+
exports.unshift(
|
|
572
|
+
`export { defineApp } from './core/defineApp'`,
|
|
573
|
+
`export type { RuntimeConfig } from './core/defineApp'`
|
|
574
|
+
);
|
|
564
575
|
api.writeTmpFile({
|
|
565
576
|
noPluginDir: true,
|
|
566
577
|
path: "exports.ts",
|
package/dist/index.js
CHANGED
|
@@ -69,6 +69,7 @@ var src_default = () => {
|
|
|
69
69
|
require.resolve("./features/legacy/legacy"),
|
|
70
70
|
require.resolve("./features/classPropertiesLoose/classPropertiesLoose"),
|
|
71
71
|
require.resolve("./features/webpack/webpack"),
|
|
72
|
+
require.resolve("./features/swc/swc"),
|
|
72
73
|
require.resolve("./commands/build"),
|
|
73
74
|
require.resolve("./commands/config/config"),
|
|
74
75
|
require.resolve("./commands/dev/dev"),
|
package/dist/registerMethods.js
CHANGED
package/dist/types.d.ts
CHANGED
|
@@ -9,6 +9,7 @@ import type { getMarkup } from '@umijs/server';
|
|
|
9
9
|
import type { CheerioAPI } from '@umijs/utils/compiled/cheerio';
|
|
10
10
|
import type { InlineConfig as ViteInlineConfig } from 'vite';
|
|
11
11
|
import type { getMarkupArgs } from './commands/dev/getMarkupArgs';
|
|
12
|
+
import type { IOnDemandInstallDep } from './features/depsOnDemand/depsOnDemand';
|
|
12
13
|
import type CodeFrameError from './features/transform/CodeFrameError';
|
|
13
14
|
export { UmiApiRequest, UmiApiResponse } from './features/apiRoute';
|
|
14
15
|
export { webpack, IConfig };
|
|
@@ -89,6 +90,7 @@ export declare type IApi = PluginAPI & IServicePluginAPI & {
|
|
|
89
90
|
id: string;
|
|
90
91
|
}>;
|
|
91
92
|
addMiddlewares: IAdd<null, RequestHandler>;
|
|
93
|
+
addOnDemandDeps: IAdd<null, IOnDemandInstallDep>;
|
|
92
94
|
addPolyfillImports: IAdd<null, {
|
|
93
95
|
source: string;
|
|
94
96
|
specifier?: string;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@umijs/preset-umi",
|
|
3
|
-
"version": "4.0.
|
|
3
|
+
"version": "4.0.51",
|
|
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",
|
|
@@ -27,19 +27,19 @@
|
|
|
27
27
|
"dependencies": {
|
|
28
28
|
"@iconify/utils": "2.0.9",
|
|
29
29
|
"@svgr/core": "6.2.1",
|
|
30
|
-
"@umijs/ast": "4.0.
|
|
31
|
-
"@umijs/babel-preset-umi": "4.0.
|
|
32
|
-
"@umijs/bundler-utils": "4.0.
|
|
33
|
-
"@umijs/bundler-vite": "4.0.
|
|
34
|
-
"@umijs/bundler-webpack": "4.0.
|
|
35
|
-
"@umijs/core": "4.0.
|
|
30
|
+
"@umijs/ast": "4.0.51",
|
|
31
|
+
"@umijs/babel-preset-umi": "4.0.51",
|
|
32
|
+
"@umijs/bundler-utils": "4.0.51",
|
|
33
|
+
"@umijs/bundler-vite": "4.0.51",
|
|
34
|
+
"@umijs/bundler-webpack": "4.0.51",
|
|
35
|
+
"@umijs/core": "4.0.51",
|
|
36
36
|
"@umijs/did-you-know": "^1.0.0",
|
|
37
37
|
"@umijs/history": "5.3.1",
|
|
38
|
-
"@umijs/mfsu": "4.0.
|
|
39
|
-
"@umijs/plugin-run": "4.0.
|
|
40
|
-
"@umijs/renderer-react": "4.0.
|
|
41
|
-
"@umijs/server": "4.0.
|
|
42
|
-
"@umijs/utils": "4.0.
|
|
38
|
+
"@umijs/mfsu": "4.0.51",
|
|
39
|
+
"@umijs/plugin-run": "4.0.51",
|
|
40
|
+
"@umijs/renderer-react": "4.0.51",
|
|
41
|
+
"@umijs/server": "4.0.51",
|
|
42
|
+
"@umijs/utils": "4.0.51",
|
|
43
43
|
"babel-plugin-dynamic-import-node": "2.3.3",
|
|
44
44
|
"click-to-react-component": "^1.0.8",
|
|
45
45
|
"core-js": "3.27.1",
|
package/templates/history.tpl
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { createHashHistory, createMemoryHistory, createBrowserHistory
|
|
1
|
+
import { createHashHistory, createMemoryHistory, createBrowserHistory } from '{{{ historyPath }}}';
|
|
2
|
+
import type { UmiHistory } from './historyIntelli';
|
|
2
3
|
|
|
3
|
-
let history:
|
|
4
|
+
let history: UmiHistory;
|
|
4
5
|
let basename: string = '/';
|
|
5
6
|
export function createHistory(opts: any) {
|
|
6
7
|
let h;
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import { getRoutes } from './route'
|
|
2
|
+
import type { History } from '{{{ historyPath }}}'
|
|
3
|
+
|
|
4
|
+
type Routes = Awaited<ReturnType<typeof getRoutes>>['routes']
|
|
5
|
+
type AllRoute = Routes[keyof Routes]
|
|
6
|
+
type IsRoot<T extends any> = 'parentId' extends keyof T ? false : true
|
|
7
|
+
|
|
8
|
+
// show `/` in not `layout / wrapper` only
|
|
9
|
+
type GetAllRouteWithoutLayout<Item extends AllRoute> = Item extends any
|
|
10
|
+
? 'isWrapper' extends keyof Item
|
|
11
|
+
? never
|
|
12
|
+
: 'isLayout' extends keyof Item
|
|
13
|
+
? never
|
|
14
|
+
: Item
|
|
15
|
+
: never
|
|
16
|
+
type AllRouteWithoutLayout = GetAllRouteWithoutLayout<AllRoute>
|
|
17
|
+
type IndexRoutePathname = '/' extends AllRouteWithoutLayout['path']
|
|
18
|
+
? '/'
|
|
19
|
+
: never
|
|
20
|
+
|
|
21
|
+
type GetChildrens<T extends any> = T extends any
|
|
22
|
+
? IsRoot<T> extends true
|
|
23
|
+
? never
|
|
24
|
+
: T
|
|
25
|
+
: never
|
|
26
|
+
type Childrens = GetChildrens<AllRoute>
|
|
27
|
+
type Root = Exclude<AllRoute, Childrens>
|
|
28
|
+
type AllIds = AllRoute['id']
|
|
29
|
+
|
|
30
|
+
type GetChildrensByParentId<
|
|
31
|
+
Id extends AllIds,
|
|
32
|
+
Item = AllRoute
|
|
33
|
+
> = Item extends any
|
|
34
|
+
? 'parentId' extends keyof Item
|
|
35
|
+
? Item['parentId'] extends Id
|
|
36
|
+
? Item
|
|
37
|
+
: never
|
|
38
|
+
: never
|
|
39
|
+
: never
|
|
40
|
+
|
|
41
|
+
type RouteObject<
|
|
42
|
+
Id extends AllIds,
|
|
43
|
+
Item = GetChildrensByParentId<Id>
|
|
44
|
+
> = IsNever<Item> extends true
|
|
45
|
+
? ''
|
|
46
|
+
: Item extends AllRoute
|
|
47
|
+
? {
|
|
48
|
+
[Key in Item['path'] as TrimSlash<Key>]: UnionMerge<
|
|
49
|
+
RouteObject<Item['id']>
|
|
50
|
+
>
|
|
51
|
+
}
|
|
52
|
+
: never
|
|
53
|
+
|
|
54
|
+
type GetRootRouteObject<Item extends Root> = Item extends Root
|
|
55
|
+
? {
|
|
56
|
+
[K in Item['path'] as TrimSlash<K>]: UnionMerge<RouteObject<Item['id']>>
|
|
57
|
+
}
|
|
58
|
+
: never
|
|
59
|
+
type MergedResult = UnionMerge<GetRootRouteObject<Root>>
|
|
60
|
+
|
|
61
|
+
// --- patch history types ---
|
|
62
|
+
|
|
63
|
+
type HistoryTo = Parameters<History['push']>['0']
|
|
64
|
+
type HistoryPath = Exclude<HistoryTo, string>
|
|
65
|
+
|
|
66
|
+
type UmiPathname = Path<MergedResult> | (string & {})
|
|
67
|
+
interface UmiPath extends HistoryPath {
|
|
68
|
+
pathname: UmiPathname
|
|
69
|
+
}
|
|
70
|
+
type UmiTo = UmiPathname | UmiPath
|
|
71
|
+
|
|
72
|
+
type UmiPush = (to: UmiTo, state?: any) => void
|
|
73
|
+
type UmiReplace = (to: UmiTo, state?: any) => void
|
|
74
|
+
export interface UmiHistory extends History {
|
|
75
|
+
push: UmiPush
|
|
76
|
+
replace: UmiReplace
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
// --- type utils ---
|
|
80
|
+
type TrimLeftSlash<T extends string> = T extends `/${infer R}`
|
|
81
|
+
? TrimLeftSlash<R>
|
|
82
|
+
: T
|
|
83
|
+
type TrimRightSlash<T extends string> = T extends `${infer R}/`
|
|
84
|
+
? TrimRightSlash<R>
|
|
85
|
+
: T
|
|
86
|
+
type TrimSlash<T extends string> = TrimLeftSlash<TrimRightSlash<T>>
|
|
87
|
+
|
|
88
|
+
type IsNever<T> = [T] extends [never] ? true : false
|
|
89
|
+
type IsEqual<A, B> = (<G>() => G extends A ? 1 : 2) extends <G>() => G extends B
|
|
90
|
+
? 1
|
|
91
|
+
: 2
|
|
92
|
+
? true
|
|
93
|
+
: false
|
|
94
|
+
|
|
95
|
+
type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends (
|
|
96
|
+
k: infer I
|
|
97
|
+
) => void
|
|
98
|
+
? I
|
|
99
|
+
: never
|
|
100
|
+
type UnionMerge<U> = UnionToIntersection<U> extends infer O
|
|
101
|
+
? { [K in keyof O]: O[K] }
|
|
102
|
+
: never
|
|
103
|
+
|
|
104
|
+
type ExcludeEmptyKey<T> = IsEqual<T, ''> extends true ? never : T
|
|
105
|
+
|
|
106
|
+
type PathConcat<
|
|
107
|
+
TKey extends string,
|
|
108
|
+
TValue,
|
|
109
|
+
N = TrimSlash<TKey>
|
|
110
|
+
> = TValue extends string
|
|
111
|
+
? ExcludeEmptyKey<N>
|
|
112
|
+
:
|
|
113
|
+
| ExcludeEmptyKey<N>
|
|
114
|
+
| `${N & string}${IsNever<ExcludeEmptyKey<N>> extends true
|
|
115
|
+
? ''
|
|
116
|
+
: '/'}${UnionPath<TValue>}`
|
|
117
|
+
|
|
118
|
+
type UnionPath<T> = {
|
|
119
|
+
[K in keyof T]-?: PathConcat<K & string, T[K]>
|
|
120
|
+
}[keyof T]
|
|
121
|
+
|
|
122
|
+
type MakeSureLeftSlash<T> = T extends any
|
|
123
|
+
? `/${TrimRightSlash<T & string>}`
|
|
124
|
+
: never
|
|
125
|
+
|
|
126
|
+
// exclude `/*`, because it always at the top of the IDE tip list
|
|
127
|
+
type Path<T, K = UnionPath<T>> = Exclude<MakeSureLeftSlash<K>, '/*'> | IndexRoutePathname
|
package/templates/plugin.tpl
CHANGED
|
@@ -26,27 +26,29 @@ export function getValidKeys() {
|
|
|
26
26
|
|
|
27
27
|
let pluginManager = null;
|
|
28
28
|
|
|
29
|
-
// 确保 webpack 模式 import.meta.hot 代码被 tree shaking 掉
|
|
30
|
-
const isDev = process.env.NODE_ENV === 'development';
|
|
31
|
-
|
|
32
29
|
export function createPluginManager() {
|
|
33
30
|
pluginManager = PluginManager.create({
|
|
34
31
|
plugins: getPlugins(),
|
|
35
32
|
validKeys: getValidKeys(),
|
|
36
33
|
});
|
|
37
34
|
|
|
35
|
+
{{#isViteMode}}
|
|
38
36
|
// fix https://github.com/umijs/umi/issues/10047
|
|
39
37
|
// https://vitejs.dev/guide/api-hmr.html#hot-data 通过 hot data 持久化 pluginManager 解决 vite 热更时 getPluginManager 获取到 null 的情况
|
|
40
|
-
if (
|
|
38
|
+
if (process.env.NODE_ENV === 'development' && import.meta.hot) {
|
|
41
39
|
import.meta.hot.data.pluginManager = pluginManager
|
|
42
40
|
}
|
|
41
|
+
{{/isViteMode}}
|
|
42
|
+
|
|
43
43
|
return pluginManager;
|
|
44
44
|
}
|
|
45
45
|
|
|
46
46
|
export function getPluginManager() {
|
|
47
|
+
{{#isViteMode}}
|
|
47
48
|
// vite 热更模式优先从 hot data 中获取 pluginManager
|
|
48
|
-
if (
|
|
49
|
+
if (process.env.NODE_ENV === 'development' && import.meta.hot) {
|
|
49
50
|
return import.meta.hot.data.pluginManager || pluginManager
|
|
50
51
|
}
|
|
52
|
+
{{/isViteMode}}
|
|
51
53
|
return pluginManager;
|
|
52
54
|
}
|
package/templates/route.tpl
CHANGED
|
@@ -1,49 +0,0 @@
|
|
|
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
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
21
|
-
mod
|
|
22
|
-
));
|
|
23
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
24
|
-
|
|
25
|
-
// src/features/polyfill/swcPolyfill.ts
|
|
26
|
-
var swcPolyfill_exports = {};
|
|
27
|
-
__export(swcPolyfill_exports, {
|
|
28
|
-
default: () => swcPolyfill_default
|
|
29
|
-
});
|
|
30
|
-
module.exports = __toCommonJS(swcPolyfill_exports);
|
|
31
|
-
var import_types = require("@umijs/bundler-webpack/dist/types");
|
|
32
|
-
var import_path = require("path");
|
|
33
|
-
var swcPolyfill_default = (api) => {
|
|
34
|
-
api.describe({
|
|
35
|
-
enableBy: ({ userConfig }) => {
|
|
36
|
-
const isSwcTranspiler = userConfig.srcTranspiler === import_types.Transpiler.swc;
|
|
37
|
-
return isSwcTranspiler;
|
|
38
|
-
}
|
|
39
|
-
});
|
|
40
|
-
api.modifyConfig((memo) => {
|
|
41
|
-
memo.alias["regenerator-runtime"] = (0, import_path.dirname)(
|
|
42
|
-
require.resolve("regenerator-runtime/package")
|
|
43
|
-
);
|
|
44
|
-
memo.alias["core-js"] = (0, import_path.dirname)(require.resolve("core-js/package"));
|
|
45
|
-
return memo;
|
|
46
|
-
});
|
|
47
|
-
};
|
|
48
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
49
|
-
0 && (module.exports = {});
|