js-code-detector 0.0.27 → 0.0.29
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/cjs/index.d.ts +26 -2
- package/dist/cjs/index.js +17 -130
- package/dist/cjs/util/ast_util/AstUtil.js +7 -0
- package/dist/cjs/util/report_util/generateGitDiffReport.d.ts +4 -0
- package/dist/cjs/util/report_util/generateGitDiffReport.js +6 -51
- package/dist/cjs/util/report_util/getMadgeInstance.d.ts +3 -3
- package/dist/cjs/util/report_util.d.ts +1 -1
- package/dist/cjs/util/shared/getRepoSupportFlag.d.ts +1 -0
- package/dist/cjs/util/shared/getRepoSupportFlag.js +21 -2
- package/dist/cjs/util/shared/gitDiffTool.d.ts +36 -0
- package/dist/cjs/util/shared/gitDiffTool.js +170 -0
- package/dist/cjs/util/shared/umi4ProjectUtil.d.ts +8 -0
- package/dist/cjs/util/shared/umi4ProjectUtil.js +86 -0
- package/dist/cjs/util/shared/vueProjectUtil.d.ts +8 -0
- package/dist/cjs/util/shared/vueProjectUtil.js +65 -0
- package/package.json +1 -1
package/dist/cjs/index.d.ts
CHANGED
|
@@ -4,11 +4,32 @@ export declare function getGitRepositoryAndBranch(): Promise<{
|
|
|
4
4
|
branchName: string;
|
|
5
5
|
}>;
|
|
6
6
|
export declare function sameCodeDetect(dirOfCwd?: string): Promise<void>;
|
|
7
|
-
export declare function gitDiffDetect(): Promise<
|
|
8
|
-
|
|
7
|
+
export declare function gitDiffDetect(): Promise<{
|
|
8
|
+
mdContent: string;
|
|
9
|
+
dependenceJson: Record<string, any>;
|
|
10
|
+
upstreamDependenceJson: Record<string, any>;
|
|
11
|
+
partialDependenceJson: Record<string, any>;
|
|
12
|
+
reports: {
|
|
13
|
+
dangerIdentifiers: string[];
|
|
14
|
+
blockReports: {
|
|
15
|
+
diff_txt: string[];
|
|
16
|
+
infos: {
|
|
17
|
+
causeBy: string;
|
|
18
|
+
effectsUpstream: string[];
|
|
19
|
+
occupations: string[];
|
|
20
|
+
effectsDownstream: string[];
|
|
21
|
+
}[];
|
|
22
|
+
}[];
|
|
23
|
+
type: "modify" | "add" | "delete";
|
|
24
|
+
filesDependsOnMe: string[];
|
|
25
|
+
undefinedIdentifiers: string[];
|
|
26
|
+
filePath: string;
|
|
27
|
+
}[];
|
|
28
|
+
} | undefined>;
|
|
9
29
|
export declare function gitDiffDetectByUrl(inputUrl: string): Promise<{
|
|
10
30
|
mdContent: string;
|
|
11
31
|
dependenceJson: Record<string, any>;
|
|
32
|
+
upstreamDependenceJson: Record<string, any>;
|
|
12
33
|
partialDependenceJson: Record<string, any>;
|
|
13
34
|
reports: {
|
|
14
35
|
dangerIdentifiers: string[];
|
|
@@ -27,3 +48,6 @@ export declare function gitDiffDetectByUrl(inputUrl: string): Promise<{
|
|
|
27
48
|
filePath: string;
|
|
28
49
|
}[];
|
|
29
50
|
} | undefined>;
|
|
51
|
+
export declare function getUpstreamDependenceJson(inputUrl: string): Promise<{
|
|
52
|
+
[k: string]: string[];
|
|
53
|
+
} | undefined>;
|
package/dist/cjs/index.js
CHANGED
|
@@ -8,13 +8,13 @@ var __export = (target, all) => {
|
|
|
8
8
|
for (var name in all)
|
|
9
9
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
10
|
};
|
|
11
|
-
var __copyProps = (
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
12
|
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
13
|
for (let key of __getOwnPropNames(from))
|
|
14
|
-
if (!__hasOwnProp.call(
|
|
15
|
-
__defProp(
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
16
|
}
|
|
17
|
-
return
|
|
17
|
+
return to;
|
|
18
18
|
};
|
|
19
19
|
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
20
|
// If the importer is in node compatibility mode or this is not an ESM
|
|
@@ -29,30 +29,23 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
29
29
|
// src/index.ts
|
|
30
30
|
var src_exports = {};
|
|
31
31
|
__export(src_exports, {
|
|
32
|
-
getEslintCheckResult: () => getEslintCheckResult,
|
|
33
32
|
getGitRepositoryAndBranch: () => getGitRepositoryAndBranch,
|
|
33
|
+
getUpstreamDependenceJson: () => getUpstreamDependenceJson,
|
|
34
34
|
gitDiffDetect: () => gitDiffDetect,
|
|
35
35
|
gitDiffDetectByUrl: () => gitDiffDetectByUrl,
|
|
36
36
|
gitDiffFileName: () => gitDiffFileName,
|
|
37
37
|
sameCodeDetect: () => sameCodeDetect
|
|
38
38
|
});
|
|
39
39
|
module.exports = __toCommonJS(src_exports);
|
|
40
|
-
var import_fs = require("fs");
|
|
41
40
|
var import_path = require("path");
|
|
42
|
-
var
|
|
41
|
+
var import_fs = require("fs");
|
|
43
42
|
var import_utils = require("@umijs/utils");
|
|
44
43
|
var import_dayjs = __toESM(require("dayjs"));
|
|
45
44
|
var import_readDirFiles = require("./util/shared/readDirFiles");
|
|
46
45
|
var import_Core = __toESM(require("./util/ast_util/Core"));
|
|
47
|
-
var import_constants = require("./util/constants");
|
|
48
|
-
var import_await_to_js = __toESM(require("await-to-js"));
|
|
49
|
-
var import_generateGitDiffReport = require("./util/report_util/generateGitDiffReport");
|
|
50
46
|
var import_parseGitLabDiffUril = require("./util/parseGitLabDiffUril");
|
|
51
|
-
var
|
|
52
|
-
var import_handleExecaError = require("./util/shared/handleExecaError");
|
|
47
|
+
var import_gitDiffTool = require("./util/shared/gitDiffTool");
|
|
53
48
|
var gitDiffFileName = "git_diff.txt";
|
|
54
|
-
var eslintJsonName = "eslint-report.json";
|
|
55
|
-
var eslintFinalJsonName = "eslint-final-report.json";
|
|
56
49
|
async function getGitRepositoryAndBranch() {
|
|
57
50
|
const res = await import_utils.execa.execa("git remote get-url origin", { shell: "/bin/bash" });
|
|
58
51
|
import_utils.chalk.green(["仓库地址:", res.stdout]);
|
|
@@ -70,132 +63,26 @@ async function sameCodeDetect(dirOfCwd) {
|
|
|
70
63
|
const validDepthList = depthList.filter((e) => top3DepthsSet.includes(e));
|
|
71
64
|
const validContentList = nodeContentGroupList.filter((e) => validDepthList.includes(e.depth)).sort((a, b) => b.depth - a.depth);
|
|
72
65
|
const md = import_Core.default.createMarkdownFile(validContentList);
|
|
73
|
-
(0,
|
|
66
|
+
(0, import_fs.writeFileSync)((0, import_path.join)(process.cwd(), `${(0, import_dayjs.default)().format("YYYYMDD_HHmm")}_same_code.md`), md, { encoding: "utf-8", flag: "w" });
|
|
74
67
|
}
|
|
75
68
|
async function gitDiffDetect() {
|
|
76
|
-
const today = (0, import_dayjs.default)().format("YYYYMDD");
|
|
77
69
|
const { gitUrl, branchName } = await getGitRepositoryAndBranch();
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
if (err) {
|
|
81
|
-
import_utils.logger.error("临时目录删除失败");
|
|
82
|
-
}
|
|
83
|
-
await import_utils.execa.execa(`mkdir -p ${today}`, { shell: "/bin/bash" });
|
|
84
|
-
import_utils.logger.info("临时目录建立完成");
|
|
85
|
-
import_utils.logger.ready(`准备clone源代码到临时目录下的 ${import_constants.TARGET} 文件夹`);
|
|
86
|
-
await import_utils.execa.execa(`git clone ${gitUrl} ${today}/${import_constants.TARGET}`, { shell: "/bin/bash" });
|
|
87
|
-
import_utils.logger.info("源代码clone完成");
|
|
88
|
-
const supportFlag = (0, import_getRepoSupportFlag.getRepoSupportFlag)((0, import_path.join)(process.cwd(), today, import_constants.TARGET, "package.json"));
|
|
89
|
-
if (!supportFlag) {
|
|
90
|
-
import_utils.logger.error("该项目不支持检测");
|
|
91
|
-
(0, import_utils.rimraf)((0, import_path.join)(process.cwd(), today), () => {
|
|
92
|
-
import_utils.logger.info("临时目录已删除");
|
|
93
|
-
});
|
|
94
|
-
return;
|
|
95
|
-
}
|
|
96
|
-
import_utils.logger.ready(`准备clone源代码到临时目录下的 ${import_constants.SOURCE} 文件夹`);
|
|
97
|
-
await import_utils.execa.execa(`git clone ${gitUrl} ${today}/${import_constants.SOURCE}`, { shell: "/bin/bash" });
|
|
98
|
-
import_utils.logger.info("源代码clone完成");
|
|
99
|
-
import_utils.logger.ready("准备切换到目标分支");
|
|
100
|
-
await import_utils.execa.execa(`cd ${today}/${import_constants.TARGET} && git fetch origin ${branchName}:${branchName} && git checkout ${branchName}`, { shell: "/bin/bash" });
|
|
101
|
-
import_utils.logger.info("分支切换完成");
|
|
102
|
-
import_utils.logger.ready("准备生成git_diff.txt文件");
|
|
103
|
-
await import_utils.execa.execa(`cd ${today}/${import_constants.TARGET} && git diff master..${branchName} --unified=0 --output=${gitDiffFileName}`, { shell: "/bin/bash" });
|
|
104
|
-
import_utils.logger.info("git_diff.txt文件生成完成");
|
|
105
|
-
import_utils.logger.wait("准备生成 入口文件");
|
|
106
|
-
await import_utils.execa.execa(`cd ${today}/${import_constants.TARGET} && npx max setup`, { shell: "/bin/bash" });
|
|
107
|
-
import_utils.logger.info("入口文件 生成完成!");
|
|
108
|
-
import_utils.logger.ready("准备生成报告");
|
|
109
|
-
await (0, import_generateGitDiffReport.generateGitDiffReport)({ targetDirPath: (0, import_path.join)(process.cwd(), today, import_constants.TARGET) });
|
|
110
|
-
import_utils.logger.info("报告完成");
|
|
111
|
-
(0, import_utils.rimraf)((0, import_path.join)(process.cwd(), today), () => {
|
|
112
|
-
import_utils.logger.info("临时目录已删除");
|
|
113
|
-
});
|
|
114
|
-
}
|
|
115
|
-
async function getEslintCheckResult(today) {
|
|
116
|
-
today = today || (0, import_dayjs.default)().format("YYYYMDD");
|
|
117
|
-
import_utils.logger.ready("准备生成 eslint 类型检查 json");
|
|
118
|
-
await (0, import_await_to_js.default)(import_utils.execa.execa(`cd ${today}/target && npx eslint src --ext .js,.jsx,.ts,.tsx --format json -o ${eslintJsonName}`, { shell: "/bin/bash" }));
|
|
119
|
-
import_utils.logger.info("eslint 类型检查 json 生成完成");
|
|
120
|
-
import_utils.logger.ready(`读取 ${eslintJsonName} 文件内容,并解析`);
|
|
121
|
-
let eslintJson = [];
|
|
122
|
-
{
|
|
123
|
-
const content = (0, import_fs.readFileSync)((0, import_path.join)(process.cwd(), today, "target", eslintJsonName), "utf-8");
|
|
124
|
-
try {
|
|
125
|
-
eslintJson = JSON.parse(content);
|
|
126
|
-
} catch (error) {
|
|
127
|
-
import_utils.logger.error("解析json文件失败");
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
const validEslintJson = eslintJson.filter((e) => {
|
|
131
|
-
const { filePath, ...rest } = e;
|
|
132
|
-
return Object.values(rest).some((v) => Array.isArray(v) && v.length > 0 || !Array.isArray(v) && v);
|
|
133
|
-
});
|
|
134
|
-
(0, import_fs2.writeFileSync)((0, import_path.join)(process.cwd(), eslintFinalJsonName), JSON.stringify(validEslintJson, null, 2), { encoding: "utf-8", flag: "w" });
|
|
135
|
-
import_utils.logger.info(`${eslintFinalJsonName} 文件生成`);
|
|
70
|
+
const today = (0, import_dayjs.default)().format("YYYYMDD_HHmmss");
|
|
71
|
+
return (0, import_gitDiffTool.gitDiffTool)({ gitRepoUrl: gitUrl, targetBranch: branchName, baseBranch: "master", tempDirPath: today, generateFile: void 0 });
|
|
136
72
|
}
|
|
137
73
|
async function gitDiffDetectByUrl(inputUrl) {
|
|
138
74
|
const today = (0, import_dayjs.default)().format("YYYYMDD_HHmmss") + Math.random().toString(36).slice(-5);
|
|
139
|
-
const
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
await import_utils.execa.execa(`mkdir -p ${today}`, { shell: "/bin/bash" });
|
|
146
|
-
import_utils.logger.info("临时目录建立完成");
|
|
147
|
-
try {
|
|
148
|
-
import_utils.logger.ready(`准备clone ${projectPathPart} 源代码到临时目录下的 ${import_constants.TARGET} 文件夹`);
|
|
149
|
-
let stderr, failed;
|
|
150
|
-
({ stderr, failed } = await import_utils.execa.execa(`git clone ${gitUrl} ${today}/${import_constants.TARGET}`, { shell: "/bin/bash" }));
|
|
151
|
-
(0, import_handleExecaError.handleExecaError)({ failed, stderr });
|
|
152
|
-
import_utils.logger.info("源代码clone完成");
|
|
153
|
-
const supportFlag = (0, import_getRepoSupportFlag.getRepoSupportFlag)((0, import_path.join)(process.cwd(), today, import_constants.TARGET, "package.json"));
|
|
154
|
-
if (!supportFlag) {
|
|
155
|
-
import_utils.logger.error("该项目不支持检测");
|
|
156
|
-
(0, import_utils.rimraf)((0, import_path.join)(process.cwd(), today), () => {
|
|
157
|
-
import_utils.logger.info("临时目录已删除");
|
|
158
|
-
});
|
|
159
|
-
return;
|
|
160
|
-
}
|
|
161
|
-
import_utils.logger.ready(`准备clone ${projectPathPart} 源代码到临时目录下的 ${import_constants.SOURCE} 文件夹`);
|
|
162
|
-
({ stderr, failed } = await import_utils.execa.execa(`git clone ${gitUrl} ${today}/${import_constants.SOURCE}`, { shell: "/bin/bash" }));
|
|
163
|
-
(0, import_handleExecaError.handleExecaError)({ failed, stderr });
|
|
164
|
-
import_utils.logger.info("源代码clone完成");
|
|
165
|
-
if (baseBranch !== "master") {
|
|
166
|
-
import_utils.logger.ready("准备切换到基准分支");
|
|
167
|
-
({ stderr, failed } = await import_utils.execa.execa(`cd ${today}/${import_constants.SOURCE} && git fetch origin ${baseBranch}:${baseBranch} && git checkout ${baseBranch}`, { shell: "/bin/bash" }));
|
|
168
|
-
(0, import_handleExecaError.handleExecaError)({ failed, stderr });
|
|
169
|
-
import_utils.logger.info("源代码切换到基准分支完成");
|
|
170
|
-
}
|
|
171
|
-
import_utils.logger.ready("准备切换到目标分支");
|
|
172
|
-
({ stderr, failed } = await import_utils.execa.execa(`cd ${today}/${import_constants.TARGET} && git fetch origin ${branchName}:${branchName} && git checkout ${branchName}`, { shell: "/bin/bash" }));
|
|
173
|
-
(0, import_handleExecaError.handleExecaError)({ failed, stderr });
|
|
174
|
-
import_utils.logger.info("分支切换完成");
|
|
175
|
-
import_utils.logger.ready("准备生成git_diff.txt文件");
|
|
176
|
-
({ stderr, failed } = await import_utils.execa.execa(`cd ${today}/${import_constants.TARGET} && git diff ${baseBranch}..${branchName} --unified=0 --output=${gitDiffFileName}`, { shell: "/bin/bash" }));
|
|
177
|
-
(0, import_handleExecaError.handleExecaError)({ failed, stderr });
|
|
178
|
-
import_utils.logger.info("git_diff.txt文件生成完成");
|
|
179
|
-
import_utils.logger.wait("准备生成 入口文件");
|
|
180
|
-
({ stderr, failed } = await import_utils.execa.execa(`cd ${today}/${import_constants.TARGET} && npx max setup`, { shell: "/bin/bash" }));
|
|
181
|
-
(0, import_handleExecaError.handleExecaError)({ failed, stderr });
|
|
182
|
-
import_utils.logger.info("入口文件 生成完成!");
|
|
183
|
-
import_utils.logger.ready("准备生成报告");
|
|
184
|
-
const res = await (0, import_generateGitDiffReport.generateGitDiffReport)({ targetDirPath: (0, import_path.join)(process.cwd(), today, import_constants.TARGET), generateFile: [] });
|
|
185
|
-
import_utils.logger.info("报告完成");
|
|
186
|
-
return res;
|
|
187
|
-
} catch (error) {
|
|
188
|
-
import_utils.logger.error(error.message);
|
|
189
|
-
} finally {
|
|
190
|
-
(0, import_utils.rimraf)((0, import_path.join)(process.cwd(), today), () => {
|
|
191
|
-
import_utils.logger.info("临时目录已删除");
|
|
192
|
-
});
|
|
193
|
-
}
|
|
75
|
+
const gitInfo = (0, import_parseGitLabDiffUril.parseGitLabCompareUrl)(inputUrl);
|
|
76
|
+
return (0, import_gitDiffTool.gitDiffTool)({ ...gitInfo, tempDirPath: today, generateFile: [] });
|
|
77
|
+
}
|
|
78
|
+
async function getUpstreamDependenceJson(inputUrl) {
|
|
79
|
+
const gitInfo = (0, import_parseGitLabDiffUril.parseGitLabCompareUrl)(inputUrl);
|
|
80
|
+
return (0, import_gitDiffTool.cloneGitRepoAndGetDiff)(gitInfo.gitRepoUrl, gitInfo.targetBranch);
|
|
194
81
|
}
|
|
195
82
|
// Annotate the CommonJS export names for ESM import in node:
|
|
196
83
|
0 && (module.exports = {
|
|
197
|
-
getEslintCheckResult,
|
|
198
84
|
getGitRepositoryAndBranch,
|
|
85
|
+
getUpstreamDependenceJson,
|
|
199
86
|
gitDiffDetect,
|
|
200
87
|
gitDiffDetectByUrl,
|
|
201
88
|
gitDiffFileName,
|
|
@@ -203,6 +203,13 @@ var _AstUtil = class {
|
|
|
203
203
|
target = { sourcePath: sourceValue, members: [] };
|
|
204
204
|
importedMember.push(target);
|
|
205
205
|
}
|
|
206
|
+
if (specifier.type === "ImportNamespaceSpecifier") {
|
|
207
|
+
target.members.push({
|
|
208
|
+
localName: local.name,
|
|
209
|
+
importedName: "*"
|
|
210
|
+
});
|
|
211
|
+
return;
|
|
212
|
+
}
|
|
206
213
|
target.members.push({
|
|
207
214
|
localName: local.name,
|
|
208
215
|
importedName: (imported == null ? void 0 : imported.name) || "default"
|
|
@@ -1,10 +1,14 @@
|
|
|
1
|
+
import { IMadgeInstance } from "./getMadgeInstance";
|
|
1
2
|
declare const reportFileName = "git_diff_report.md";
|
|
2
3
|
export declare function generateGitDiffReport(arg: {
|
|
4
|
+
madgeResult: IMadgeInstance;
|
|
5
|
+
parsedAlias: Record<string, any>;
|
|
3
6
|
targetDirPath: string;
|
|
4
7
|
generateFile?: ('dependence_map.json' | 'partial_dependence_map.json' | 'report.json' | typeof reportFileName)[];
|
|
5
8
|
}): Promise<{
|
|
6
9
|
mdContent: string;
|
|
7
10
|
dependenceJson: Record<string, any>;
|
|
11
|
+
upstreamDependenceJson: Record<string, any>;
|
|
8
12
|
partialDependenceJson: Record<string, any>;
|
|
9
13
|
reports: {
|
|
10
14
|
dangerIdentifiers: string[];
|
|
@@ -39,63 +39,14 @@ var import_format_git_diff_content = require("../format_git_diff_content");
|
|
|
39
39
|
var import_utils = require("@umijs/utils");
|
|
40
40
|
var import_report_util = require("../report_util");
|
|
41
41
|
var import_createMdByJson = require("./createMdByJson");
|
|
42
|
-
var import_getMadgeInstance = require("./getMadgeInstance");
|
|
43
42
|
var import_createDependenceMap = require("./createDependenceMap");
|
|
44
43
|
var import_dayjs = __toESM(require("dayjs"));
|
|
45
|
-
var userAliasGetter = (cwd, appData) => {
|
|
46
|
-
var _a;
|
|
47
|
-
return ((_a = appData.config) == null ? void 0 : _a.alias) || {
|
|
48
|
-
umi: "@@/exports",
|
|
49
|
-
"@": cwd + "/src",
|
|
50
|
-
"@@": cwd + "/src/.umi",
|
|
51
|
-
"@umijs/max": "@@/exports"
|
|
52
|
-
};
|
|
53
|
-
};
|
|
54
44
|
var reportFileName = "git_diff_report.md";
|
|
55
45
|
async function generateGitDiffReport(arg) {
|
|
56
|
-
const { targetDirPath, generateFile = ["dependence_map.json", "partial_dependence_map.json", "report.json", reportFileName] } = arg;
|
|
57
|
-
const
|
|
46
|
+
const { madgeResult, parsedAlias, targetDirPath, generateFile = ["upstream_dependence_map.json", "dependence_map.json", "partial_dependence_map.json", "report.json", reportFileName] } = arg;
|
|
47
|
+
const { tree } = madgeResult;
|
|
58
48
|
const diff_txt = (0, import_fs.readFileSync)((0, import_path.join)(targetDirPath, import__.gitDiffFileName), "utf-8");
|
|
59
49
|
const gitDiffDetail = (0, import_format_git_diff_content.formatGitDiffContent)(diff_txt);
|
|
60
|
-
const tsconfig = await import_utils.tsconfigPaths.loadConfig(targetDirPath);
|
|
61
|
-
const appDataContent = (0, import_fs.readFileSync)((0, import_path.join)(targetDirPath, "src", ".umi", "appData.json"), "utf-8");
|
|
62
|
-
let appData = { config: null };
|
|
63
|
-
try {
|
|
64
|
-
appData = JSON.parse(appDataContent);
|
|
65
|
-
} catch (e) {
|
|
66
|
-
console.warn("appData.json 解析失败,将使用默认别名");
|
|
67
|
-
}
|
|
68
|
-
const userAlias = userAliasGetter(targetDirPath, appData);
|
|
69
|
-
const exclude = [/node_modules/, /\.d\.ts$/, /\.umi/];
|
|
70
|
-
const isExclude = (path) => {
|
|
71
|
-
return exclude.some((reg) => reg.test(path));
|
|
72
|
-
};
|
|
73
|
-
const parsedAlias = import_utils.aliasUtils.parseCircleAlias({
|
|
74
|
-
alias: userAlias
|
|
75
|
-
});
|
|
76
|
-
const filteredAlias = Object.keys(parsedAlias).reduce(
|
|
77
|
-
(acc, key) => {
|
|
78
|
-
var _a, _b;
|
|
79
|
-
const value = parsedAlias[key];
|
|
80
|
-
if (isExclude(value)) {
|
|
81
|
-
return acc;
|
|
82
|
-
}
|
|
83
|
-
if ((_a = tsconfig.paths) == null ? void 0 : _a[key]) {
|
|
84
|
-
return acc;
|
|
85
|
-
}
|
|
86
|
-
const tsconfigValue = [(0, import_path.join)((0, import_path.relative)(targetDirPath, value), "/*")];
|
|
87
|
-
const tsconfigKey = `${key}/*`;
|
|
88
|
-
if ((_b = tsconfig.paths) == null ? void 0 : _b[tsconfigKey]) {
|
|
89
|
-
return acc;
|
|
90
|
-
}
|
|
91
|
-
acc[tsconfigKey] = tsconfigValue;
|
|
92
|
-
return acc;
|
|
93
|
-
},
|
|
94
|
-
{}
|
|
95
|
-
);
|
|
96
|
-
const devTmpDir = (0, import_path.join)(absSrcPath, ".umi");
|
|
97
|
-
const res = await (0, import_getMadgeInstance.getMadgeInstance)(devTmpDir, targetDirPath, exclude, filteredAlias, tsconfig);
|
|
98
|
-
const tree = res.tree;
|
|
99
50
|
const absPathPrefix = targetDirPath + "/";
|
|
100
51
|
const usingFileNoPrefix = Object.keys(tree);
|
|
101
52
|
const usingFilePaths = usingFileNoPrefix.map((item) => (0, import_utils.winPath)((0, import_path.join)(absPathPrefix, item)));
|
|
@@ -104,14 +55,17 @@ async function generateGitDiffReport(arg) {
|
|
|
104
55
|
const time = (0, import_dayjs.default)().format("YYYYMDD_HHmm");
|
|
105
56
|
let dependenceJson = {};
|
|
106
57
|
let partialDependenceJson = {};
|
|
58
|
+
let upstreamDependenceJson = {};
|
|
107
59
|
try {
|
|
108
60
|
dependenceJson = (0, import_createDependenceMap.createDependenceMap)(usingFilePaths, parsedAlias, absPathPrefix);
|
|
109
61
|
partialDependenceJson = Object.fromEntries(changedFilePaths.map((p) => [p, dependenceJson[p]]));
|
|
62
|
+
upstreamDependenceJson = Object.fromEntries(changedFilePaths.map((p) => [p, madgeResult.depends(p)]));
|
|
110
63
|
} catch (e) {
|
|
111
64
|
console.warn("dependenceJson 生成失败", e);
|
|
112
65
|
}
|
|
113
66
|
const reports = (0, import_report_util.createDetectReport)({ groupGitDiffLines, tree, absPathPrefix });
|
|
114
67
|
const mdContent = (0, import_createMdByJson.createMdByJson)(reports);
|
|
68
|
+
generateFile.includes("upstream_dependence_map.json") && (0, import_fs.writeFileSync)((0, import_path.join)(targetDirPath, "..", "..", `${time}_upstream_dependence_map.json`), JSON.stringify(dependenceJson, null, 2), { encoding: "utf-8", flag: "w" });
|
|
115
69
|
generateFile.includes("dependence_map.json") && (0, import_fs.writeFileSync)((0, import_path.join)(targetDirPath, "..", "..", `${time}_dependence_map.json`), JSON.stringify(dependenceJson, null, 2), { encoding: "utf-8", flag: "w" });
|
|
116
70
|
generateFile.includes("partial_dependence_map.json") && (0, import_fs.writeFileSync)((0, import_path.join)(targetDirPath, "..", "..", `${time}_partial_dependence_map.json`), JSON.stringify(partialDependenceJson, null, 2), { encoding: "utf-8", flag: "w" });
|
|
117
71
|
generateFile.includes("report.json") && (0, import_fs.writeFileSync)((0, import_path.join)(targetDirPath, "..", "..", `${time}_report.json`), JSON.stringify(reports, null, 2), { encoding: "utf-8", flag: "w" });
|
|
@@ -119,6 +73,7 @@ async function generateGitDiffReport(arg) {
|
|
|
119
73
|
return {
|
|
120
74
|
mdContent,
|
|
121
75
|
dependenceJson,
|
|
76
|
+
upstreamDependenceJson,
|
|
122
77
|
partialDependenceJson,
|
|
123
78
|
reports
|
|
124
79
|
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { MadgeInstance } from "madge";
|
|
2
|
-
interface IMadgeInstance extends MadgeInstance {
|
|
1
|
+
import { MadgeConfig, MadgeInstance, MadgePath } from "madge";
|
|
2
|
+
export interface IMadgeInstance extends MadgeInstance {
|
|
3
3
|
tree: Record<string, string[]>;
|
|
4
4
|
}
|
|
5
|
+
export type MadgeFunc = (path: MadgePath, config: MadgeConfig) => Promise<IMadgeInstance>;
|
|
5
6
|
export declare function getMadgeInstance(devTmpDir: string, targetDirPath: string, exclude: RegExp[], filteredAlias: Record<string, string[]>, tsconfig?: any): Promise<IMadgeInstance>;
|
|
6
|
-
export {};
|
|
@@ -35,7 +35,7 @@ export declare function createDetectReport(arg: Arg): {
|
|
|
35
35
|
effectsDownstream: string[];
|
|
36
36
|
}[];
|
|
37
37
|
}[];
|
|
38
|
-
type: "
|
|
38
|
+
type: "modify" | "add" | "delete";
|
|
39
39
|
filesDependsOnMe: string[];
|
|
40
40
|
undefinedIdentifiers: string[];
|
|
41
41
|
filePath: string;
|
|
@@ -19,10 +19,28 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
19
19
|
// src/util/shared/getRepoSupportFlag.ts
|
|
20
20
|
var getRepoSupportFlag_exports = {};
|
|
21
21
|
__export(getRepoSupportFlag_exports, {
|
|
22
|
-
getRepoSupportFlag: () => getRepoSupportFlag
|
|
22
|
+
getRepoSupportFlag: () => getRepoSupportFlag,
|
|
23
|
+
getRepoType: () => getRepoType
|
|
23
24
|
});
|
|
24
25
|
module.exports = __toCommonJS(getRepoSupportFlag_exports);
|
|
25
26
|
var import_fs = require("fs");
|
|
27
|
+
function getRepoType(jsonPath) {
|
|
28
|
+
var _a;
|
|
29
|
+
const isExist = (0, import_fs.existsSync)(jsonPath);
|
|
30
|
+
if (!isExist)
|
|
31
|
+
return null;
|
|
32
|
+
const packageJson = (0, import_fs.readFileSync)(jsonPath, "utf-8");
|
|
33
|
+
if (!packageJson)
|
|
34
|
+
return null;
|
|
35
|
+
try {
|
|
36
|
+
const packageJsonObj = JSON.parse(packageJson);
|
|
37
|
+
if ((_a = packageJsonObj == null ? void 0 : packageJsonObj.dependencies) == null ? void 0 : _a["@umijs/max"]) {
|
|
38
|
+
return "umi";
|
|
39
|
+
}
|
|
40
|
+
} catch (e) {
|
|
41
|
+
return null;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
26
44
|
function getRepoSupportFlag(jsonPath) {
|
|
27
45
|
var _a;
|
|
28
46
|
const isExist = (0, import_fs.existsSync)(jsonPath);
|
|
@@ -41,5 +59,6 @@ function getRepoSupportFlag(jsonPath) {
|
|
|
41
59
|
}
|
|
42
60
|
// Annotate the CommonJS export names for ESM import in node:
|
|
43
61
|
0 && (module.exports = {
|
|
44
|
-
getRepoSupportFlag
|
|
62
|
+
getRepoSupportFlag,
|
|
63
|
+
getRepoType
|
|
45
64
|
});
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { generateGitDiffReport } from "../report_util/generateGitDiffReport";
|
|
2
|
+
export declare function cloneGitRepo(gitUrl: string, branchName: string, tempDirPath: string, folder: string): Promise<{
|
|
3
|
+
failed: boolean;
|
|
4
|
+
stderr: string;
|
|
5
|
+
}>;
|
|
6
|
+
export declare function cloneGitRepoAndGetDiff(gitRepoUrl: string, branchName: string): Promise<{
|
|
7
|
+
[k: string]: string[];
|
|
8
|
+
} | undefined>;
|
|
9
|
+
export declare function gitDiffTool(arg: {
|
|
10
|
+
gitRepoUrl: string;
|
|
11
|
+
baseBranch: string;
|
|
12
|
+
targetBranch: string;
|
|
13
|
+
tempDirPath: string;
|
|
14
|
+
generateFile: Parameters<typeof generateGitDiffReport>[0]['generateFile'];
|
|
15
|
+
}): Promise<{
|
|
16
|
+
mdContent: string;
|
|
17
|
+
dependenceJson: Record<string, any>;
|
|
18
|
+
upstreamDependenceJson: Record<string, any>;
|
|
19
|
+
partialDependenceJson: Record<string, any>;
|
|
20
|
+
reports: {
|
|
21
|
+
dangerIdentifiers: string[];
|
|
22
|
+
blockReports: {
|
|
23
|
+
diff_txt: string[];
|
|
24
|
+
infos: {
|
|
25
|
+
causeBy: string;
|
|
26
|
+
effectsUpstream: string[];
|
|
27
|
+
occupations: string[];
|
|
28
|
+
effectsDownstream: string[];
|
|
29
|
+
}[];
|
|
30
|
+
}[];
|
|
31
|
+
type: "modify" | "add" | "delete";
|
|
32
|
+
filesDependsOnMe: string[];
|
|
33
|
+
undefinedIdentifiers: string[];
|
|
34
|
+
filePath: string;
|
|
35
|
+
}[];
|
|
36
|
+
} | undefined>;
|
|
@@ -0,0 +1,170 @@
|
|
|
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 = (to2, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to2, key) && key !== except)
|
|
15
|
+
__defProp(to2, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to2;
|
|
18
|
+
};
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
24
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
25
|
+
mod
|
|
26
|
+
));
|
|
27
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
|
+
|
|
29
|
+
// src/util/shared/gitDiffTool.ts
|
|
30
|
+
var gitDiffTool_exports = {};
|
|
31
|
+
__export(gitDiffTool_exports, {
|
|
32
|
+
cloneGitRepo: () => cloneGitRepo,
|
|
33
|
+
cloneGitRepoAndGetDiff: () => cloneGitRepoAndGetDiff,
|
|
34
|
+
gitDiffTool: () => gitDiffTool
|
|
35
|
+
});
|
|
36
|
+
module.exports = __toCommonJS(gitDiffTool_exports);
|
|
37
|
+
var import_utils = require("@umijs/utils");
|
|
38
|
+
var import_await_to_js = __toESM(require("await-to-js"));
|
|
39
|
+
var import_constants = require("../constants");
|
|
40
|
+
var import_handleExecaError = require("./handleExecaError");
|
|
41
|
+
var import_getRepoSupportFlag = require("./getRepoSupportFlag");
|
|
42
|
+
var import_path = require("path");
|
|
43
|
+
var import_umi4ProjectUtil = require("./umi4ProjectUtil");
|
|
44
|
+
var import_generateGitDiffReport = require("../report_util/generateGitDiffReport");
|
|
45
|
+
var import_vueProjectUtil = require("./vueProjectUtil");
|
|
46
|
+
var import__ = require("../../index");
|
|
47
|
+
var import_dayjs = __toESM(require("dayjs"));
|
|
48
|
+
var import_fs = require("fs");
|
|
49
|
+
var import_format_git_diff_content = require("../format_git_diff_content");
|
|
50
|
+
async function cloneGitRepo(gitUrl, branchName, tempDirPath, folder) {
|
|
51
|
+
import_utils.logger.ready(`准备clone 源代码到临时目录下的 ${tempDirPath}/${folder} 文件夹`);
|
|
52
|
+
let stderr, failed;
|
|
53
|
+
({ stderr, failed } = await import_utils.execa.execa(`git clone ${gitUrl} ${tempDirPath}/${folder}`, { shell: "/bin/bash" }));
|
|
54
|
+
(0, import_handleExecaError.handleExecaError)({ failed, stderr });
|
|
55
|
+
import_utils.logger.info("源代码clone完成");
|
|
56
|
+
if (branchName !== "master") {
|
|
57
|
+
import_utils.logger.ready("准备切换到分支");
|
|
58
|
+
({ stderr, failed } = await import_utils.execa.execa(`cd ${tempDirPath}/${folder} && git fetch origin ${branchName}:${branchName} && git checkout ${branchName}`, { shell: "/bin/bash" }));
|
|
59
|
+
(0, import_handleExecaError.handleExecaError)({ failed, stderr });
|
|
60
|
+
import_utils.logger.info("源代码切换分支完成");
|
|
61
|
+
}
|
|
62
|
+
return { failed, stderr };
|
|
63
|
+
}
|
|
64
|
+
async function cloneGitRepoAndGetDiff(gitRepoUrl, branchName) {
|
|
65
|
+
const today = (0, import_dayjs.default)().format("YYYYMDD_HHmmss") + Math.random().toString(36).slice(-5);
|
|
66
|
+
import_utils.logger.ready("准备生成临时工作目录...");
|
|
67
|
+
const [err] = await (0, import_await_to_js.default)(import_utils.execa.execa(`rm -rf ${today}`, { shell: "/bin/bash" }));
|
|
68
|
+
if (err) {
|
|
69
|
+
import_utils.logger.error("临时目录删除失败");
|
|
70
|
+
}
|
|
71
|
+
await import_utils.execa.execa(`mkdir -p ${today}`, { shell: "/bin/bash" });
|
|
72
|
+
import_utils.logger.info("临时目录建立完成");
|
|
73
|
+
try {
|
|
74
|
+
let stderr, failed;
|
|
75
|
+
({ stderr, failed } = await cloneGitRepo(gitRepoUrl, branchName, today, import_constants.TARGET));
|
|
76
|
+
(0, import_handleExecaError.handleExecaError)({ failed, stderr });
|
|
77
|
+
import_utils.logger.ready("准备生成git_diff.txt文件");
|
|
78
|
+
({ stderr, failed } = await import_utils.execa.execa(`cd ${today}/${import_constants.TARGET} && git diff master..${branchName} --unified=0 --output=${import__.gitDiffFileName}`, { shell: "/bin/bash" }));
|
|
79
|
+
(0, import_handleExecaError.handleExecaError)({ failed, stderr });
|
|
80
|
+
const repoType = await (0, import_getRepoSupportFlag.getRepoType)((0, import_path.join)(process.cwd(), today, import_constants.TARGET, "package.json"));
|
|
81
|
+
import_utils.logger.info(`项目类型为: ${repoType}`);
|
|
82
|
+
if (repoType === "umi") {
|
|
83
|
+
const { madgeResult, shellExeResult } = await (0, import_umi4ProjectUtil.umi4SetUp)({ targetDirPath: (0, import_path.join)(process.cwd(), today, import_constants.TARGET) });
|
|
84
|
+
({ stderr, failed } = shellExeResult);
|
|
85
|
+
(0, import_handleExecaError.handleExecaError)({ failed, stderr });
|
|
86
|
+
const targetDirPath = (0, import_path.join)(process.cwd(), today, import_constants.TARGET);
|
|
87
|
+
const diff_txt = (0, import_fs.readFileSync)((0, import_path.join)(targetDirPath, import__.gitDiffFileName), "utf-8");
|
|
88
|
+
const gitDiffDetail = (0, import_format_git_diff_content.formatGitDiffContent)(diff_txt);
|
|
89
|
+
const usingFileNoPrefix = Object.keys(madgeResult.tree);
|
|
90
|
+
const groupGitDiffLines = gitDiffDetail.filter((item) => usingFileNoPrefix.includes(item.filePath));
|
|
91
|
+
const changedFilePaths = groupGitDiffLines.map((item) => item.filePath);
|
|
92
|
+
const upstreamDependenceJson = Object.fromEntries(changedFilePaths.map((p) => [p, madgeResult.depends(p)]));
|
|
93
|
+
return upstreamDependenceJson;
|
|
94
|
+
}
|
|
95
|
+
} catch (error) {
|
|
96
|
+
import_utils.logger.error(error);
|
|
97
|
+
} finally {
|
|
98
|
+
(0, import_utils.rimraf)((0, import_path.join)(process.cwd(), today), () => {
|
|
99
|
+
import_utils.logger.info("临时目录已删除");
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
async function gitDiffTool(arg) {
|
|
104
|
+
const { gitRepoUrl: gitUrl, baseBranch, targetBranch: branchName, tempDirPath: today, generateFile } = arg;
|
|
105
|
+
import_utils.logger.ready("准备生成临时工作目录...");
|
|
106
|
+
const [err] = await (0, import_await_to_js.default)(import_utils.execa.execa(`rm -rf ${today}`, { shell: "/bin/bash" }));
|
|
107
|
+
if (err) {
|
|
108
|
+
import_utils.logger.error("临时目录删除失败");
|
|
109
|
+
}
|
|
110
|
+
await import_utils.execa.execa(`mkdir -p ${today}`, { shell: "/bin/bash" });
|
|
111
|
+
import_utils.logger.info("临时目录建立完成");
|
|
112
|
+
try {
|
|
113
|
+
import_utils.logger.ready(`准备clone 源代码到临时目录下的 ${import_constants.TARGET} 文件夹`);
|
|
114
|
+
let stderr, failed;
|
|
115
|
+
({ stderr, failed } = await import_utils.execa.execa(`git clone ${gitUrl} ${today}/${import_constants.TARGET}`, { shell: "/bin/bash" }));
|
|
116
|
+
(0, import_handleExecaError.handleExecaError)({ failed, stderr });
|
|
117
|
+
import_utils.logger.info("源代码clone完成");
|
|
118
|
+
import_utils.logger.wait("检测项目类型");
|
|
119
|
+
const repoType = await (0, import_getRepoSupportFlag.getRepoType)((0, import_path.join)(process.cwd(), today, import_constants.TARGET, "package.json"));
|
|
120
|
+
import_utils.logger.info(`项目类型为: ${repoType}`);
|
|
121
|
+
if (!repoType) {
|
|
122
|
+
import_utils.logger.error("该项目不支持检测");
|
|
123
|
+
(0, import_utils.rimraf)((0, import_path.join)(process.cwd(), today), () => {
|
|
124
|
+
import_utils.logger.info("临时目录已删除");
|
|
125
|
+
});
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
128
|
+
import_utils.logger.ready(`准备clone 源代码到临时目录下的 ${import_constants.SOURCE} 文件夹`);
|
|
129
|
+
({ stderr, failed } = await import_utils.execa.execa(`git clone ${gitUrl} ${today}/${import_constants.SOURCE}`, { shell: "/bin/bash" }));
|
|
130
|
+
(0, import_handleExecaError.handleExecaError)({ failed, stderr });
|
|
131
|
+
import_utils.logger.info("源代码clone完成");
|
|
132
|
+
if (baseBranch !== "master") {
|
|
133
|
+
import_utils.logger.ready("准备切换到基准分支");
|
|
134
|
+
({ stderr, failed } = await import_utils.execa.execa(`cd ${today}/${import_constants.SOURCE} && git fetch origin ${baseBranch}:${baseBranch} && git checkout ${baseBranch}`, { shell: "/bin/bash" }));
|
|
135
|
+
(0, import_handleExecaError.handleExecaError)({ failed, stderr });
|
|
136
|
+
import_utils.logger.info("源代码切换到基准分支完成");
|
|
137
|
+
}
|
|
138
|
+
import_utils.logger.ready("准备切换到目标分支");
|
|
139
|
+
({ stderr, failed } = await import_utils.execa.execa(`cd ${today}/${import_constants.TARGET} && git fetch origin ${branchName}:${branchName} && git checkout ${branchName}`, { shell: "/bin/bash" }));
|
|
140
|
+
(0, import_handleExecaError.handleExecaError)({ failed, stderr });
|
|
141
|
+
import_utils.logger.info("分支切换完成");
|
|
142
|
+
import_utils.logger.ready("准备生成git_diff.txt文件");
|
|
143
|
+
({ stderr, failed } = await import_utils.execa.execa(`cd ${today}/${import_constants.TARGET} && git diff ${baseBranch}..${branchName} --unified=0 --output=${import__.gitDiffFileName}`, { shell: "/bin/bash" }));
|
|
144
|
+
(0, import_handleExecaError.handleExecaError)({ failed, stderr });
|
|
145
|
+
import_utils.logger.info("git_diff.txt文件生成完成");
|
|
146
|
+
if (repoType === "umi") {
|
|
147
|
+
const { madgeResult, shellExeResult, parsedAlias } = await (0, import_umi4ProjectUtil.umi4SetUp)({ targetDirPath: (0, import_path.join)(process.cwd(), today, import_constants.TARGET) });
|
|
148
|
+
({ stderr, failed } = shellExeResult);
|
|
149
|
+
(0, import_handleExecaError.handleExecaError)({ failed, stderr });
|
|
150
|
+
return await (0, import_generateGitDiffReport.generateGitDiffReport)({ madgeResult, parsedAlias, targetDirPath: (0, import_path.join)(process.cwd(), today, import_constants.TARGET), generateFile });
|
|
151
|
+
} else if (repoType === "vue") {
|
|
152
|
+
const { madgeResult, shellExeResult, parsedAlias } = await (0, import_vueProjectUtil.vueSetUp)({ targetDir: `${today}/${import_constants.TARGET}` });
|
|
153
|
+
({ stderr, failed } = shellExeResult);
|
|
154
|
+
(0, import_handleExecaError.handleExecaError)({ failed, stderr });
|
|
155
|
+
return await (0, import_generateGitDiffReport.generateGitDiffReport)({ madgeResult, parsedAlias, targetDirPath: (0, import_path.join)(process.cwd(), today, import_constants.TARGET), generateFile });
|
|
156
|
+
}
|
|
157
|
+
} catch (error) {
|
|
158
|
+
import_utils.logger.error(error.message);
|
|
159
|
+
} finally {
|
|
160
|
+
(0, import_utils.rimraf)((0, import_path.join)(process.cwd(), today), () => {
|
|
161
|
+
import_utils.logger.info("临时目录已删除");
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
166
|
+
0 && (module.exports = {
|
|
167
|
+
cloneGitRepo,
|
|
168
|
+
cloneGitRepoAndGetDiff,
|
|
169
|
+
gitDiffTool
|
|
170
|
+
});
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { execa } from "@umijs/utils";
|
|
2
|
+
export declare function umi4SetUp({ targetDirPath }: {
|
|
3
|
+
targetDirPath: string;
|
|
4
|
+
}): Promise<{
|
|
5
|
+
shellExeResult: execa.ExecaReturnValue<string>;
|
|
6
|
+
madgeResult: import("../report_util/getMadgeInstance").IMadgeInstance;
|
|
7
|
+
parsedAlias: Record<string, any>;
|
|
8
|
+
}>;
|
|
@@ -0,0 +1,86 @@
|
|
|
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/util/shared/umi4ProjectUtil.ts
|
|
20
|
+
var umi4ProjectUtil_exports = {};
|
|
21
|
+
__export(umi4ProjectUtil_exports, {
|
|
22
|
+
umi4SetUp: () => umi4SetUp
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(umi4ProjectUtil_exports);
|
|
25
|
+
var import_utils = require("@umijs/utils");
|
|
26
|
+
var import_fs = require("fs");
|
|
27
|
+
var import_path = require("path");
|
|
28
|
+
var import_getMadgeInstance = require("../report_util/getMadgeInstance");
|
|
29
|
+
var userAliasGetter = (cwd, appData) => {
|
|
30
|
+
var _a;
|
|
31
|
+
return ((_a = appData.config) == null ? void 0 : _a.alias) || {
|
|
32
|
+
umi: "@@/exports",
|
|
33
|
+
"@": cwd + "/src",
|
|
34
|
+
"@@": cwd + "/src/.umi",
|
|
35
|
+
"@umijs/max": "@@/exports"
|
|
36
|
+
};
|
|
37
|
+
};
|
|
38
|
+
async function umi4SetUp({ targetDirPath }) {
|
|
39
|
+
const shellExeResult = await import_utils.execa.execa(`cd ${targetDirPath} && npx max setup`, { shell: "/bin/bash" });
|
|
40
|
+
const tsconfig = await import_utils.tsconfigPaths.loadConfig(targetDirPath);
|
|
41
|
+
const appDataContent = (0, import_fs.readFileSync)((0, import_path.join)(targetDirPath, "src", ".umi", "appData.json"), "utf-8");
|
|
42
|
+
let appData = { config: null };
|
|
43
|
+
try {
|
|
44
|
+
appData = JSON.parse(appDataContent);
|
|
45
|
+
} catch (e) {
|
|
46
|
+
console.warn("appData.json 解析失败,将使用默认别名");
|
|
47
|
+
}
|
|
48
|
+
const userAlias = userAliasGetter(targetDirPath, appData);
|
|
49
|
+
const exclude = [/node_modules/, /\.d\.ts$/, /\.umi/];
|
|
50
|
+
const isExclude = (path) => {
|
|
51
|
+
return exclude.some((reg) => reg.test(path));
|
|
52
|
+
};
|
|
53
|
+
const parsedAlias = import_utils.aliasUtils.parseCircleAlias({
|
|
54
|
+
alias: userAlias
|
|
55
|
+
});
|
|
56
|
+
const filteredAlias = Object.keys(parsedAlias).reduce(
|
|
57
|
+
(acc, key) => {
|
|
58
|
+
var _a, _b;
|
|
59
|
+
const value = parsedAlias[key];
|
|
60
|
+
if (isExclude(value)) {
|
|
61
|
+
return acc;
|
|
62
|
+
}
|
|
63
|
+
if ((_a = tsconfig.paths) == null ? void 0 : _a[key]) {
|
|
64
|
+
return acc;
|
|
65
|
+
}
|
|
66
|
+
const tsconfigValue = [(0, import_path.join)((0, import_path.relative)(targetDirPath, value), "/*")];
|
|
67
|
+
const tsconfigKey = `${key}/*`;
|
|
68
|
+
if ((_b = tsconfig.paths) == null ? void 0 : _b[tsconfigKey]) {
|
|
69
|
+
return acc;
|
|
70
|
+
}
|
|
71
|
+
acc[tsconfigKey] = tsconfigValue;
|
|
72
|
+
return acc;
|
|
73
|
+
},
|
|
74
|
+
{}
|
|
75
|
+
);
|
|
76
|
+
const madgeResult = await (0, import_getMadgeInstance.getMadgeInstance)((0, import_path.join)(targetDirPath, "src", ".umi"), targetDirPath, exclude, filteredAlias, tsconfig);
|
|
77
|
+
return {
|
|
78
|
+
shellExeResult,
|
|
79
|
+
madgeResult,
|
|
80
|
+
parsedAlias
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
84
|
+
0 && (module.exports = {
|
|
85
|
+
umi4SetUp
|
|
86
|
+
});
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { execa } from "@umijs/utils";
|
|
2
|
+
export declare function vueSetUp({ targetDir }: {
|
|
3
|
+
targetDir: string;
|
|
4
|
+
}): Promise<{
|
|
5
|
+
shellExeResult: execa.ExecaReturnValue<string>;
|
|
6
|
+
madgeResult: import("../report_util/getMadgeInstance").IMadgeInstance;
|
|
7
|
+
parsedAlias: Record<string, any>;
|
|
8
|
+
}>;
|
|
@@ -0,0 +1,65 @@
|
|
|
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/util/shared/vueProjectUtil.ts
|
|
20
|
+
var vueProjectUtil_exports = {};
|
|
21
|
+
__export(vueProjectUtil_exports, {
|
|
22
|
+
vueSetUp: () => vueSetUp
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(vueProjectUtil_exports);
|
|
25
|
+
var import_path = require("path");
|
|
26
|
+
var import_fs = require("fs");
|
|
27
|
+
var import_utils = require("@umijs/utils");
|
|
28
|
+
var webpackConfigFileName = "__webpack.config.js";
|
|
29
|
+
async function vueSetUp({ targetDir }) {
|
|
30
|
+
const shellExeResult = await import_utils.execa.execa(`cd ${targetDir} && npx vue-cli-service inspect --verbose`, { shell: "/bin/bash" });
|
|
31
|
+
const { failed, stdout } = shellExeResult;
|
|
32
|
+
const filePath = (0, import_path.join)(targetDir, webpackConfigFileName);
|
|
33
|
+
if (!failed) {
|
|
34
|
+
(0, import_fs.writeFileSync)(filePath, `module.exports = ${stdout}`);
|
|
35
|
+
}
|
|
36
|
+
;
|
|
37
|
+
let userAlias = {};
|
|
38
|
+
let entryFiles = [];
|
|
39
|
+
try {
|
|
40
|
+
const webpackConfig = eval(`(${stdout})`);
|
|
41
|
+
userAlias = webpackConfig.resolve.alias;
|
|
42
|
+
entryFiles = Object.values(webpackConfig.entry).flat();
|
|
43
|
+
} catch (error) {
|
|
44
|
+
import_utils.logger.error("解析webpack配置出错", error);
|
|
45
|
+
}
|
|
46
|
+
const madge = require("madge");
|
|
47
|
+
const madgeResult = await madge(entryFiles[0], {
|
|
48
|
+
webpackConfig: filePath,
|
|
49
|
+
// fileExtensions: ['.vue', '.js'],
|
|
50
|
+
// excludeRegExp: [/node_modules/],
|
|
51
|
+
baseDir: targetDir
|
|
52
|
+
});
|
|
53
|
+
const parsedAlias = import_utils.aliasUtils.parseCircleAlias({
|
|
54
|
+
alias: userAlias
|
|
55
|
+
});
|
|
56
|
+
return {
|
|
57
|
+
shellExeResult,
|
|
58
|
+
madgeResult,
|
|
59
|
+
parsedAlias
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
63
|
+
0 && (module.exports = {
|
|
64
|
+
vueSetUp
|
|
65
|
+
});
|