@umijs/preset-umi 4.0.57 → 4.0.58
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/deadcode.js +64 -21
- package/dist/commands/generators/page.d.ts +5 -2
- package/dist/commands/generators/page.js +5 -0
- package/dist/commands/generators/utils.d.ts +1 -2
- package/dist/features/exportStatic/exportStatic.js +38 -10
- package/dist/types.d.ts +2 -0
- package/package.json +21 -21
- package/templates/generate/page/index.styled-components.tsx.tpl +1 -1
|
@@ -24,20 +24,45 @@ __export(deadcode_exports, {
|
|
|
24
24
|
module.exports = __toCommonJS(deadcode_exports);
|
|
25
25
|
var import_utils = require("@umijs/utils");
|
|
26
26
|
var import_path = require("path");
|
|
27
|
-
var
|
|
27
|
+
var { getFileCreateInfo, getFileLastModifyInfo, isGitRepo } = import_utils.git;
|
|
28
|
+
var response = (res) => res.status === "fulfilled";
|
|
29
|
+
var outputUnusedFiles = async (unusedFiles, fileName, option) => {
|
|
28
30
|
if (!(unusedFiles == null ? void 0 : unusedFiles.length)) {
|
|
29
31
|
return;
|
|
30
32
|
}
|
|
31
|
-
const
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
33
|
+
const { gitInfo, cwd } = option;
|
|
34
|
+
if (gitInfo) {
|
|
35
|
+
const isInGit = await isGitRepo();
|
|
36
|
+
if (!isInGit) {
|
|
37
|
+
throw new Error(`当前目录 ${cwd} 不是 git 仓库,请确认!`);
|
|
38
|
+
}
|
|
39
|
+
const records = {};
|
|
40
|
+
await Promise.allSettled(
|
|
41
|
+
unusedFiles.map(async ({ filePath }) => {
|
|
42
|
+
return Promise.allSettled([
|
|
43
|
+
getFileCreateInfo(filePath),
|
|
44
|
+
getFileLastModifyInfo(filePath)
|
|
45
|
+
]).then((infos) => {
|
|
46
|
+
const [createInfo, modifyInfo] = infos;
|
|
47
|
+
records[filePath] = {
|
|
48
|
+
...response(createInfo) ? createInfo.value : void 0,
|
|
49
|
+
...response(modifyInfo) ? modifyInfo.value : void 0
|
|
50
|
+
};
|
|
51
|
+
});
|
|
52
|
+
})
|
|
53
|
+
);
|
|
54
|
+
import_utils.fsExtra.writeFileSync(fileName, JSON.stringify(records), "utf8");
|
|
55
|
+
} else {
|
|
56
|
+
import_utils.fsExtra.writeFileSync(
|
|
57
|
+
fileName,
|
|
58
|
+
`[
|
|
59
|
+
${unusedFiles.reduce((res, { filePath }, index) => {
|
|
60
|
+
return `${res}"${filePath}" ${index !== unusedFiles.length - 1 ? "," : ""}`;
|
|
61
|
+
}, "")}
|
|
62
|
+
]`,
|
|
63
|
+
"utf8"
|
|
64
|
+
);
|
|
65
|
+
}
|
|
41
66
|
};
|
|
42
67
|
var deadcode_default = (api) => {
|
|
43
68
|
api.registerCommand({
|
|
@@ -81,6 +106,8 @@ var deadcode_default = (api) => {
|
|
|
81
106
|
import_utils.logger.info("begin check deadCode");
|
|
82
107
|
const cwd = api.cwd;
|
|
83
108
|
const tsconfig = await import_utils.tsconfigPaths.loadConfig(cwd);
|
|
109
|
+
const args = api.args;
|
|
110
|
+
const { out, gitInfo } = args;
|
|
84
111
|
const exclude = [/node_modules/, /\.d\.ts$/, /\.umi/];
|
|
85
112
|
const isExclude = (path) => {
|
|
86
113
|
return exclude.some((reg) => reg.test(path));
|
|
@@ -162,18 +189,34 @@ var deadcode_default = (api) => {
|
|
|
162
189
|
const unusedFiles = (0, import_utils.readDirFiles)({
|
|
163
190
|
dir: api.paths.absSrcPath,
|
|
164
191
|
exclude
|
|
165
|
-
}).filter(({ filePath
|
|
166
|
-
const relativePath = (0, import_path.relative)(cwd, file.filePath);
|
|
167
|
-
return relativePath;
|
|
168
|
-
});
|
|
192
|
+
}).filter(({ filePath }) => !dependenceMap[filePath]);
|
|
169
193
|
if (!unusedFiles.length) {
|
|
170
|
-
|
|
194
|
+
console.log(`🎉 ${import_utils.chalk.green("Good job, no unusedFiles.")}`);
|
|
195
|
+
return;
|
|
196
|
+
}
|
|
197
|
+
import_utils.logger.warn(`🚨 ${import_utils.chalk.red("Unused Files found:")}`);
|
|
198
|
+
unusedFiles.forEach((fileItem) => {
|
|
199
|
+
import_utils.logger.warn(
|
|
200
|
+
` · ${import_utils.chalk.yellow(fileItem.filePath, import_utils.chalk.gray(" -> "))}`
|
|
201
|
+
);
|
|
202
|
+
});
|
|
203
|
+
if (out) {
|
|
204
|
+
const recordJson = `DeadCodeList-${Date.now()}.json`;
|
|
205
|
+
const recordJsonPath = (0, import_utils.winPath)(
|
|
206
|
+
(0, import_path.join)(cwd, typeof out === "string" ? out : recordJson)
|
|
207
|
+
);
|
|
208
|
+
if (gitInfo)
|
|
209
|
+
import_utils.logger.wait("generating file...");
|
|
210
|
+
await outputUnusedFiles(unusedFiles, recordJsonPath, {
|
|
211
|
+
gitInfo,
|
|
212
|
+
cwd
|
|
213
|
+
});
|
|
214
|
+
import_utils.logger.warn(
|
|
215
|
+
`👀 ${unusedFiles.length} unused files, write content to file ${import_utils.chalk.cyan(recordJsonPath)}`
|
|
216
|
+
);
|
|
217
|
+
} else {
|
|
218
|
+
import_utils.logger.warn(`${unusedFiles.length} unused files`);
|
|
171
219
|
}
|
|
172
|
-
const filePath = (0, import_utils.winPath)((0, import_path.join)(cwd, `DeadCodeList-${Date.now()}.txt`));
|
|
173
|
-
import_utils.logger.info(
|
|
174
|
-
`${unusedFiles.length} unusedFiles, write content to file ${filePath}`
|
|
175
|
-
);
|
|
176
|
-
outputUnusedFiles(unusedFiles, filePath);
|
|
177
220
|
import_utils.logger.info(
|
|
178
221
|
`check dead code end, please be careful if you want to remove them (¬º-°)¬`
|
|
179
222
|
);
|
|
@@ -8,11 +8,13 @@ export declare class PageGenerator {
|
|
|
8
8
|
args: IArgsPage;
|
|
9
9
|
absPagesPath: string;
|
|
10
10
|
appCwd: string;
|
|
11
|
-
|
|
11
|
+
importSource?: string;
|
|
12
|
+
useStyledComponents?: boolean;
|
|
12
13
|
};
|
|
13
14
|
private isDirMode;
|
|
14
15
|
private dir;
|
|
15
16
|
private name;
|
|
17
|
+
private importSource;
|
|
16
18
|
private needEnsureDirMode;
|
|
17
19
|
private prompts;
|
|
18
20
|
private paths;
|
|
@@ -20,7 +22,8 @@ export declare class PageGenerator {
|
|
|
20
22
|
args: IArgsPage;
|
|
21
23
|
absPagesPath: string;
|
|
22
24
|
appCwd: string;
|
|
23
|
-
|
|
25
|
+
importSource?: string;
|
|
26
|
+
useStyledComponents?: boolean;
|
|
24
27
|
});
|
|
25
28
|
run(): Promise<void>;
|
|
26
29
|
runInteractiveMode(): Promise<void>;
|
|
@@ -47,6 +47,7 @@ var page_default = (api) => {
|
|
|
47
47
|
args,
|
|
48
48
|
absPagesPath: api.paths.absPagesPath,
|
|
49
49
|
appCwd: api.paths.cwd,
|
|
50
|
+
importSource: api.appData.umi.importSource,
|
|
50
51
|
useStyledComponents: !!api.userConfig.styledComponents
|
|
51
52
|
}).run();
|
|
52
53
|
}
|
|
@@ -61,10 +62,12 @@ var PageGenerator = class {
|
|
|
61
62
|
this.isDirMode = false;
|
|
62
63
|
this.dir = "";
|
|
63
64
|
this.name = "";
|
|
65
|
+
this.importSource = "";
|
|
64
66
|
this.needEnsureDirMode = false;
|
|
65
67
|
this.prompts = import_utils2.promptsExitWhenCancel;
|
|
66
68
|
this.paths = [];
|
|
67
69
|
this.isDirMode = !!options.args.dir;
|
|
70
|
+
this.importSource = options.importSource || "umi";
|
|
68
71
|
const [_, ...inputPaths] = options.args._;
|
|
69
72
|
if (inputPaths.length > 0) {
|
|
70
73
|
this.paths = inputPaths;
|
|
@@ -180,6 +183,7 @@ var PageGenerator = class {
|
|
|
180
183
|
color: (0, import_utils.randomColor)(),
|
|
181
184
|
name: this.name,
|
|
182
185
|
cssExt: ".less",
|
|
186
|
+
importSource: this.importSource,
|
|
183
187
|
...restVars
|
|
184
188
|
}
|
|
185
189
|
});
|
|
@@ -200,6 +204,7 @@ var PageGenerator = class {
|
|
|
200
204
|
fallback
|
|
201
205
|
},
|
|
202
206
|
templateVars: {
|
|
207
|
+
importSource: this.importSource,
|
|
203
208
|
color: (0, import_utils.randomColor)(),
|
|
204
209
|
name: "index",
|
|
205
210
|
cssExt: ".less",
|
|
@@ -36,7 +36,7 @@ export declare class GeneratorHelper {
|
|
|
36
36
|
export declare function getUmiJsPlugin(): any;
|
|
37
37
|
export declare function promptsExitWhenCancel<T extends string = string>(questions: prompts.PromptObject<T> | Array<prompts.PromptObject<T>>, options?: Pick<prompts.Options, 'onSubmit'>): Promise<prompts.Answers<T>>;
|
|
38
38
|
export declare function trim(s?: string): string;
|
|
39
|
-
interface IFile {
|
|
39
|
+
export interface IFile {
|
|
40
40
|
from: string;
|
|
41
41
|
fromFallback: string;
|
|
42
42
|
to: string;
|
|
@@ -55,4 +55,3 @@ export declare function processGenerateFiles({ filesMap, baseDir, presetArgs, te
|
|
|
55
55
|
templateVars: Record<string, any>;
|
|
56
56
|
}): Promise<void>;
|
|
57
57
|
export declare function tryEject(dir: ETempDir, baseDir: string): Promise<void>;
|
|
58
|
-
export {};
|
|
@@ -114,16 +114,8 @@ var exportStatic_default = (api) => {
|
|
|
114
114
|
(0, import_assert.default)(!api.config.mpa, "`exportStatic` is not supported in `mpa` mode.");
|
|
115
115
|
});
|
|
116
116
|
api.modifyExportHTMLFiles(async (_defaultFiles, opts) => {
|
|
117
|
-
const {
|
|
118
|
-
|
|
119
|
-
exportStatic: { extraRoutePaths = [] }
|
|
120
|
-
} = api.config;
|
|
121
|
-
const extraHtmlData = getExportHtmlData(
|
|
122
|
-
await getRoutesFromUserExtraPaths(extraRoutePaths)
|
|
123
|
-
);
|
|
124
|
-
const htmlData = getExportHtmlData(api.appData.routes).concat(
|
|
125
|
-
extraHtmlData
|
|
126
|
-
);
|
|
117
|
+
const { publicPath } = api.config;
|
|
118
|
+
const htmlData = api.appData.exportHtmlData;
|
|
127
119
|
const htmlFiles = [];
|
|
128
120
|
for (const { file, route, prerender } of htmlData) {
|
|
129
121
|
let { markupArgs } = opts;
|
|
@@ -177,6 +169,42 @@ var exportStatic_default = (api) => {
|
|
|
177
169
|
}
|
|
178
170
|
return htmlFiles;
|
|
179
171
|
});
|
|
172
|
+
api.onGenerateFiles(async () => {
|
|
173
|
+
const {
|
|
174
|
+
exportStatic: { extraRoutePaths = [] }
|
|
175
|
+
} = api.config;
|
|
176
|
+
const extraHtmlData = getExportHtmlData(
|
|
177
|
+
await getRoutesFromUserExtraPaths(extraRoutePaths)
|
|
178
|
+
);
|
|
179
|
+
const htmlData = getExportHtmlData(api.appData.routes).concat(
|
|
180
|
+
extraHtmlData
|
|
181
|
+
);
|
|
182
|
+
api.appData.exportHtmlData = htmlData;
|
|
183
|
+
api.writeTmpFile({
|
|
184
|
+
path: "core/exportStaticRuntimePlugin.ts",
|
|
185
|
+
content: import_utils.Mustache.render(
|
|
186
|
+
`
|
|
187
|
+
export function modifyClientRenderOpts(memo: any) {
|
|
188
|
+
const { history, hydrate } = memo;
|
|
189
|
+
|
|
190
|
+
return {
|
|
191
|
+
...memo,
|
|
192
|
+
hydrate: hydrate && !{{{ ignorePaths }}}.includes(history.location.pathname),
|
|
193
|
+
};
|
|
194
|
+
}
|
|
195
|
+
`.trim(),
|
|
196
|
+
{
|
|
197
|
+
ignorePaths: JSON.stringify(
|
|
198
|
+
htmlData.filter(({ prerender }) => prerender === false).map(({ route }) => route.path)
|
|
199
|
+
)
|
|
200
|
+
}
|
|
201
|
+
),
|
|
202
|
+
noPluginDir: true
|
|
203
|
+
});
|
|
204
|
+
});
|
|
205
|
+
api.addRuntimePlugin(() => {
|
|
206
|
+
return [`@@/core/exportStaticRuntimePlugin.ts`];
|
|
207
|
+
});
|
|
180
208
|
};
|
|
181
209
|
// Annotate the CommonJS export names for ESM import in node:
|
|
182
210
|
0 && (module.exports = {});
|
package/dist/types.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ import type { ImportDeclaration } from '@umijs/bundler-utils/compiled/@babel/typ
|
|
|
2
2
|
import type { BuildResult as ESBuildBuildResult, Plugin as ESBuildPlugin } from '@umijs/bundler-utils/compiled/esbuild';
|
|
3
3
|
import type { Express, RequestHandler, webpack } from '@umijs/bundler-webpack';
|
|
4
4
|
import type WebpackChain from '@umijs/bundler-webpack/compiled/webpack-5-chain';
|
|
5
|
+
import { createWebSocketServer } from '@umijs/bundler-webpack/dist/server/ws';
|
|
5
6
|
import type { IConfig } from '@umijs/bundler-webpack/dist/types';
|
|
6
7
|
import type { IAdd, IEvent, IModify, IRoute as ICoreRoute, IServicePluginAPI, PluginAPI } from '@umijs/core';
|
|
7
8
|
import { Env } from '@umijs/core';
|
|
@@ -176,6 +177,7 @@ export declare type IApi = PluginAPI & IServicePluginAPI & {
|
|
|
176
177
|
isFirstCompile: boolean;
|
|
177
178
|
stats: webpack.Stats;
|
|
178
179
|
time: number;
|
|
180
|
+
ws?: ReturnType<typeof createWebSocketServer>;
|
|
179
181
|
}>;
|
|
180
182
|
onGenerateFiles: IEvent<IOnGenerateFiles>;
|
|
181
183
|
onPatchRoute: IEvent<{
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@umijs/preset-umi",
|
|
3
|
-
"version": "4.0.
|
|
3
|
+
"version": "4.0.58",
|
|
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",
|
|
@@ -18,28 +18,10 @@
|
|
|
18
18
|
"compiled",
|
|
19
19
|
"devToolAppDist"
|
|
20
20
|
],
|
|
21
|
-
"scripts": {
|
|
22
|
-
"build": "umi-scripts father build",
|
|
23
|
-
"build:deps": "umi-scripts bundleDeps",
|
|
24
|
-
"dev": "umi-scripts father dev",
|
|
25
|
-
"test": "umi-scripts jest-turbo"
|
|
26
|
-
},
|
|
27
21
|
"dependencies": {
|
|
28
22
|
"@iconify/utils": "2.1.1",
|
|
29
23
|
"@svgr/core": "6.5.1",
|
|
30
|
-
"@umijs/ast": "4.0.57",
|
|
31
|
-
"@umijs/babel-preset-umi": "4.0.57",
|
|
32
|
-
"@umijs/bundler-utils": "4.0.57",
|
|
33
|
-
"@umijs/bundler-vite": "4.0.57",
|
|
34
|
-
"@umijs/bundler-webpack": "4.0.57",
|
|
35
|
-
"@umijs/core": "4.0.57",
|
|
36
|
-
"@umijs/did-you-know": "^1.0.0",
|
|
37
24
|
"@umijs/history": "5.3.1",
|
|
38
|
-
"@umijs/mfsu": "4.0.57",
|
|
39
|
-
"@umijs/plugin-run": "4.0.57",
|
|
40
|
-
"@umijs/renderer-react": "4.0.57",
|
|
41
|
-
"@umijs/server": "4.0.57",
|
|
42
|
-
"@umijs/utils": "4.0.57",
|
|
43
25
|
"babel-plugin-dynamic-import-node": "2.3.3",
|
|
44
26
|
"click-to-react-component": "^1.0.8",
|
|
45
27
|
"core-js": "3.28.0",
|
|
@@ -53,7 +35,19 @@
|
|
|
53
35
|
"react-dom": "18.1.0",
|
|
54
36
|
"react-router": "6.3.0",
|
|
55
37
|
"react-router-dom": "6.3.0",
|
|
56
|
-
"regenerator-runtime": "0.13.11"
|
|
38
|
+
"regenerator-runtime": "0.13.11",
|
|
39
|
+
"@umijs/ast": "4.0.58",
|
|
40
|
+
"@umijs/babel-preset-umi": "4.0.58",
|
|
41
|
+
"@umijs/bundler-vite": "4.0.58",
|
|
42
|
+
"@umijs/bundler-webpack": "4.0.58",
|
|
43
|
+
"@umijs/core": "4.0.58",
|
|
44
|
+
"@umijs/renderer-react": "4.0.58",
|
|
45
|
+
"@umijs/server": "4.0.58",
|
|
46
|
+
"@umijs/utils": "4.0.58",
|
|
47
|
+
"@umijs/plugin-run": "4.0.58",
|
|
48
|
+
"@umijs/bundler-utils": "4.0.58",
|
|
49
|
+
"@umijs/mfsu": "4.0.58",
|
|
50
|
+
"@umijs/did-you-know": "1.0.3"
|
|
57
51
|
},
|
|
58
52
|
"devDependencies": {
|
|
59
53
|
"@manypkg/get-packages": "1.1.3",
|
|
@@ -95,5 +89,11 @@
|
|
|
95
89
|
"joi2types",
|
|
96
90
|
"sirv"
|
|
97
91
|
]
|
|
92
|
+
},
|
|
93
|
+
"scripts": {
|
|
94
|
+
"build": "umi-scripts father build",
|
|
95
|
+
"build:deps": "umi-scripts bundleDeps",
|
|
96
|
+
"dev": "umi-scripts father dev",
|
|
97
|
+
"test": "umi-scripts jest-turbo"
|
|
98
98
|
}
|
|
99
|
-
}
|
|
99
|
+
}
|