js-code-detector 0.0.44 → 0.0.48
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/bin/runDiffDetect.js +3 -0
- package/dist/cjs/index.d.ts +35 -12
- package/dist/cjs/index.js +23 -8
- package/dist/cjs/services/DetectService.d.ts +35 -0
- package/dist/cjs/services/DetectService.js +177 -0
- package/dist/cjs/services/ProjectService.d.ts +16 -0
- package/dist/cjs/services/ProjectService.js +17 -0
- package/dist/cjs/services/projectServiceClass/UmiProjectService.d.ts +13 -0
- package/dist/cjs/services/projectServiceClass/UmiProjectService.js +96 -0
- package/dist/cjs/util/ast_util/AstUtil.d.ts +4 -7
- package/dist/cjs/util/ast_util/AstUtil.js +158 -50
- package/dist/cjs/util/ast_util/FileUtil.js +5 -1
- package/dist/cjs/util/createRandomStr.d.ts +1 -0
- package/dist/cjs/util/createRandomStr.js +38 -0
- package/dist/cjs/util/report_util/createDependenceMap.d.ts +6 -1
- package/dist/cjs/util/report_util/createDependenceMap.js +73 -28
- package/dist/cjs/util/report_util/filterEffectedCode.d.ts +13 -0
- package/dist/cjs/util/report_util/filterEffectedCode.js +72 -0
- package/dist/cjs/util/report_util/filterEffectedExportMember.d.ts +1 -0
- package/dist/cjs/util/report_util/filterEffectedExportMember.js +43 -0
- package/dist/cjs/util/report_util/generateGitDiffReport.d.ts +9 -4
- package/dist/cjs/util/report_util/generateGitDiffReport.js +24 -19
- package/dist/cjs/util/report_util.d.ts +3 -1
- package/dist/cjs/util/report_util.js +10 -0
- package/dist/cjs/util/shared/collectUpstreamFiles.d.ts +2 -0
- package/dist/cjs/util/shared/collectUpstreamFiles.js +39 -0
- package/dist/cjs/util/shared/getRepoSupportFlag.d.ts +2 -1
- package/dist/cjs/util/shared/getRepoSupportFlag.js +15 -6
- package/dist/cjs/util/shared/gitDiffTool.d.ts +45 -7
- package/dist/cjs/util/shared/gitDiffTool.js +77 -27
- package/dist/cjs/util/shared/gitUtil.d.ts +4 -0
- package/dist/cjs/util/shared/gitUtil.js +18 -2
- package/dist/cjs/util/shared/umi4ProjectUtil.d.ts +2 -1
- package/dist/cjs/util/shared/umi4ProjectUtil.js +6 -8
- package/package.json +3 -2
- package/bin/eslintOutput.js +0 -3
- package/dist/cjs/sh/detect.sh +0 -15
|
@@ -38,42 +38,47 @@ var import__ = require("../../index");
|
|
|
38
38
|
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
|
-
var import_createMdByJson = require("./createMdByJson");
|
|
42
41
|
var import_createDependenceMap = require("./createDependenceMap");
|
|
43
42
|
var import_dayjs = __toESM(require("dayjs"));
|
|
43
|
+
var import_collectUpstreamFiles = __toESM(require("../shared/collectUpstreamFiles"));
|
|
44
|
+
var import_filterEffectedCode = __toESM(require("./filterEffectedCode"));
|
|
44
45
|
var reportFileName = "git_diff_report.md";
|
|
45
46
|
async function generateGitDiffReport(arg) {
|
|
46
|
-
const { madgeResult, parsedAlias, targetDirPath, generateFile = ["upstream_dependence_map.json", "dependence_map.json", "partial_dependence_map.json", "report.json", reportFileName] } = arg;
|
|
47
|
+
const { madgeResult, parsedAlias, targetDirPath, generateFile = ["upstream_dependence_map.json", "dependence_map.json", "partial_dependence_map.json", "report.json", "gitDiffDetail.json", reportFileName] } = arg;
|
|
48
|
+
const absPathPrefix = targetDirPath + "/";
|
|
47
49
|
const { tree } = madgeResult;
|
|
50
|
+
const projectFilePaths = Object.keys(tree);
|
|
51
|
+
import_utils.logger.info("读取 git diff 内容,生成 json 文件");
|
|
48
52
|
const diff_txt = (0, import_fs.readFileSync)((0, import_path.join)(targetDirPath, import__.gitDiffFileName), "utf-8");
|
|
49
53
|
const gitDiffDetail = (0, import_format_git_diff_content.formatGitDiffContent)(diff_txt);
|
|
50
|
-
const
|
|
51
|
-
const
|
|
52
|
-
const
|
|
53
|
-
const groupGitDiffLines = gitDiffDetail.filter((item) =>
|
|
54
|
-
const changedFilePaths = groupGitDiffLines.map((item) => item.filePath);
|
|
54
|
+
const modifiedFilePaths = gitDiffDetail.map((item) => item.filePath);
|
|
55
|
+
const upstreamFilePaths = (0, import_collectUpstreamFiles.default)(madgeResult, modifiedFilePaths);
|
|
56
|
+
const upstreamFileFullPaths = upstreamFilePaths.map((item) => (0, import_utils.winPath)((0, import_path.join)(absPathPrefix, item)));
|
|
57
|
+
const groupGitDiffLines = gitDiffDetail.filter((item) => upstreamFilePaths.includes(item.filePath));
|
|
55
58
|
const time = (0, import_dayjs.default)().format("YYYYMDD_HHmm");
|
|
56
|
-
let dependenceJson = {
|
|
59
|
+
let dependenceJson = {
|
|
60
|
+
indirectExportMembers: {},
|
|
61
|
+
import2export: {},
|
|
62
|
+
export2export: {},
|
|
63
|
+
mapFilePathToExportAllSources: {}
|
|
64
|
+
};
|
|
57
65
|
let partialDependenceJson = {};
|
|
58
|
-
let
|
|
66
|
+
let reports = [];
|
|
59
67
|
try {
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
68
|
+
import_utils.logger.info("生成 dependenceJson ...");
|
|
69
|
+
dependenceJson = (0, import_createDependenceMap.createExportedNameToReferenceLocalSet)(upstreamFileFullPaths, parsedAlias, absPathPrefix, projectFilePaths);
|
|
70
|
+
reports = (0, import_report_util.createDetectReport)({ groupGitDiffLines, tree, absPathPrefix });
|
|
71
|
+
partialDependenceJson = (0, import_filterEffectedCode.default)(reports, dependenceJson);
|
|
63
72
|
} catch (e) {
|
|
64
|
-
|
|
73
|
+
import_utils.logger.warn("dependenceJson 生成失败", e);
|
|
65
74
|
}
|
|
66
|
-
|
|
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" });
|
|
75
|
+
import_utils.logger.info("完成");
|
|
69
76
|
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" });
|
|
70
77
|
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" });
|
|
71
78
|
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" });
|
|
72
|
-
generateFile.includes(
|
|
79
|
+
generateFile.includes("gitDiffDetail.json") && (0, import_fs.writeFileSync)((0, import_path.join)(targetDirPath, "..", "..", `${time}_gitDiffDetail.json`), JSON.stringify(gitDiffDetail, null, 2), { encoding: "utf-8", flag: "w" });
|
|
73
80
|
return {
|
|
74
|
-
mdContent,
|
|
75
81
|
dependenceJson,
|
|
76
|
-
upstreamDependenceJson,
|
|
77
82
|
partialDependenceJson,
|
|
78
83
|
reports
|
|
79
84
|
};
|
|
@@ -26,6 +26,8 @@ type Arg = {
|
|
|
26
26
|
};
|
|
27
27
|
export declare function createDetectReport(arg: Arg): {
|
|
28
28
|
dangerIdentifiers: string[];
|
|
29
|
+
topEffectedExportsAdded: string[];
|
|
30
|
+
topEffectedExportsRemoved: string[];
|
|
29
31
|
blockReports: {
|
|
30
32
|
diff_txt: string[];
|
|
31
33
|
infos: {
|
|
@@ -35,7 +37,7 @@ export declare function createDetectReport(arg: Arg): {
|
|
|
35
37
|
effectsDownstream: string[];
|
|
36
38
|
}[];
|
|
37
39
|
}[];
|
|
38
|
-
type: "
|
|
40
|
+
type: "delete" | "modify" | "add";
|
|
39
41
|
filesDependsOnMe: string[];
|
|
40
42
|
undefinedIdentifiers: string[];
|
|
41
43
|
filePath: string;
|
|
@@ -63,6 +63,14 @@ function createDetectReport(arg) {
|
|
|
63
63
|
});
|
|
64
64
|
return reports.map((reportItem) => {
|
|
65
65
|
const { _fileAddedNodesPaths, _fileRemovedNodesPaths, filePath, blockReports, ...reportProperties } = reportItem;
|
|
66
|
+
const topEffectedExportsAdded = _fileAddedNodesPaths.map((e) => {
|
|
67
|
+
const { node } = e;
|
|
68
|
+
return import_AstUtil.default.findExportedMembersNameFromAncestors(node);
|
|
69
|
+
}).flat();
|
|
70
|
+
const topEffectedExportsRemoved = _fileRemovedNodesPaths.map((e) => {
|
|
71
|
+
const { node } = e;
|
|
72
|
+
return import_AstUtil.default.findExportedMembersNameFromAncestors(node);
|
|
73
|
+
}).flat();
|
|
66
74
|
(0, import_diffBlockDetect.reportItemDetect)(reportItem, absPathPrefix);
|
|
67
75
|
const fileAddedNodesPaths = reportItem._fileAddedNodesPaths.map((item) => item.nodePath);
|
|
68
76
|
const fileRemovedNodesPaths = reportItem._fileRemovedNodesPaths.map((item) => import_AstUtil.default.getShortNodeMsg(item.node, true));
|
|
@@ -70,6 +78,8 @@ function createDetectReport(arg) {
|
|
|
70
78
|
filePath,
|
|
71
79
|
...reportProperties,
|
|
72
80
|
dangerIdentifiers: fileRemovedNodesPaths,
|
|
81
|
+
topEffectedExportsAdded: [...new Set(topEffectedExportsAdded)],
|
|
82
|
+
topEffectedExportsRemoved: [...new Set(topEffectedExportsRemoved)],
|
|
73
83
|
blockReports: blockReports.map((blockReport) => {
|
|
74
84
|
const { diff_txt } = blockReport;
|
|
75
85
|
const addNodeAndPaths = blockReport.addNodeAndPaths.filter((e) => fileAddedNodesPaths.includes(e.nodePath));
|
|
@@ -0,0 +1,39 @@
|
|
|
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/collectUpstreamFiles.ts
|
|
20
|
+
var collectUpstreamFiles_exports = {};
|
|
21
|
+
__export(collectUpstreamFiles_exports, {
|
|
22
|
+
default: () => collectUpstreamFiles
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(collectUpstreamFiles_exports);
|
|
25
|
+
function collectUpstreamFiles(madgeResult, modifiedFilePaths, maxCount = 30) {
|
|
26
|
+
const changedFilePaths = [...modifiedFilePaths];
|
|
27
|
+
let tmpFiles = [...modifiedFilePaths];
|
|
28
|
+
for (let i = 0; i < 3; i++) {
|
|
29
|
+
tmpFiles = tmpFiles.map((file) => madgeResult.depends(file)).flat();
|
|
30
|
+
if (tmpFiles.length === 0) {
|
|
31
|
+
break;
|
|
32
|
+
}
|
|
33
|
+
changedFilePaths.push(...tmpFiles);
|
|
34
|
+
if (changedFilePaths.length > maxCount) {
|
|
35
|
+
break;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
return [...new Set(changedFilePaths)];
|
|
39
|
+
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
import { semver } from "@umijs/utils";
|
|
2
|
-
export declare function
|
|
2
|
+
export declare function isRepoTypeSupported(repoType: string): boolean;
|
|
3
|
+
export declare function getRepoType(jsonPath: string): "unknown" | "umi" | "vue2";
|
|
3
4
|
export declare function getMinVersion(jsonPath: string, depName: string): semver.SemVer | null | undefined;
|
|
@@ -20,27 +20,35 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
20
20
|
var getRepoSupportFlag_exports = {};
|
|
21
21
|
__export(getRepoSupportFlag_exports, {
|
|
22
22
|
getMinVersion: () => getMinVersion,
|
|
23
|
-
getRepoType: () => getRepoType
|
|
23
|
+
getRepoType: () => getRepoType,
|
|
24
|
+
isRepoTypeSupported: () => isRepoTypeSupported
|
|
24
25
|
});
|
|
25
26
|
module.exports = __toCommonJS(getRepoSupportFlag_exports);
|
|
26
27
|
var import_fs = require("fs");
|
|
27
28
|
var import_utils = require("@umijs/utils");
|
|
29
|
+
function isRepoTypeSupported(repoType) {
|
|
30
|
+
return ["umi"].includes(repoType);
|
|
31
|
+
}
|
|
28
32
|
function getRepoType(jsonPath) {
|
|
29
|
-
var _a;
|
|
33
|
+
var _a, _b, _c;
|
|
30
34
|
const isExist = (0, import_fs.existsSync)(jsonPath);
|
|
31
35
|
if (!isExist)
|
|
32
|
-
return
|
|
36
|
+
return "unknown";
|
|
33
37
|
const packageJson = (0, import_fs.readFileSync)(jsonPath, "utf-8");
|
|
34
38
|
if (!packageJson)
|
|
35
|
-
return
|
|
39
|
+
return "unknown";
|
|
36
40
|
try {
|
|
37
41
|
const packageJsonObj = JSON.parse(packageJson);
|
|
38
42
|
if ((_a = packageJsonObj == null ? void 0 : packageJsonObj.dependencies) == null ? void 0 : _a["@umijs/max"]) {
|
|
39
43
|
return "umi";
|
|
40
44
|
}
|
|
45
|
+
if (((_b = packageJsonObj == null ? void 0 : packageJsonObj.dependencies) == null ? void 0 : _b["@vue/cli-service"]) || ((_c = packageJsonObj == null ? void 0 : packageJsonObj.devDependencies) == null ? void 0 : _c["@vue/cli-service"])) {
|
|
46
|
+
return "vue2";
|
|
47
|
+
}
|
|
41
48
|
} catch (e) {
|
|
42
|
-
|
|
49
|
+
import_utils.logger.error(e.message);
|
|
43
50
|
}
|
|
51
|
+
return "unknown";
|
|
44
52
|
}
|
|
45
53
|
function getMinVersion(jsonPath, depName) {
|
|
46
54
|
var _a, _b;
|
|
@@ -60,5 +68,6 @@ function getMinVersion(jsonPath, depName) {
|
|
|
60
68
|
// Annotate the CommonJS export names for ESM import in node:
|
|
61
69
|
0 && (module.exports = {
|
|
62
70
|
getMinVersion,
|
|
63
|
-
getRepoType
|
|
71
|
+
getRepoType,
|
|
72
|
+
isRepoTypeSupported
|
|
64
73
|
});
|
|
@@ -1,11 +1,44 @@
|
|
|
1
1
|
import { generateGitDiffReport } from "../report_util/generateGitDiffReport";
|
|
2
|
-
export type CloneType = 'ssh' | 'token';
|
|
3
2
|
export declare function cloneGitRepoAndGetDiff(gitRepoUrl: string, branchName: string, extra?: {
|
|
4
|
-
cloneType?: CloneType;
|
|
5
3
|
token?: string;
|
|
4
|
+
jsonKeys?: (keyof Awaited<ReturnType<typeof cloneGitRepoAndGetDiff>>)[];
|
|
6
5
|
}): Promise<{
|
|
7
|
-
|
|
8
|
-
|
|
6
|
+
reports: {
|
|
7
|
+
dangerIdentifiers: string[];
|
|
8
|
+
topEffectedExportsAdded: string[];
|
|
9
|
+
topEffectedExportsRemoved: string[];
|
|
10
|
+
blockReports: {
|
|
11
|
+
diff_txt: string[];
|
|
12
|
+
infos: {
|
|
13
|
+
causeBy: string;
|
|
14
|
+
effectsUpstream: string[];
|
|
15
|
+
occupations: string[];
|
|
16
|
+
effectsDownstream: string[];
|
|
17
|
+
}[];
|
|
18
|
+
}[];
|
|
19
|
+
type: "modify" | "add" | "delete";
|
|
20
|
+
filesDependsOnMe: string[];
|
|
21
|
+
undefinedIdentifiers: string[];
|
|
22
|
+
filePath: string;
|
|
23
|
+
}[];
|
|
24
|
+
dependenceJson: {
|
|
25
|
+
import2export: Record<string, string>;
|
|
26
|
+
export2export: Record<string, string>;
|
|
27
|
+
mapFilePathToExportAllSources: Record<string, string[]>;
|
|
28
|
+
indirectExportMembers: Record<string, string>;
|
|
29
|
+
};
|
|
30
|
+
effectedCode: Record<string, any>;
|
|
31
|
+
upstreamDependenceJson: {};
|
|
32
|
+
repoType: string;
|
|
33
|
+
message: string;
|
|
34
|
+
} | {
|
|
35
|
+
effectedCode: Record<string, any>;
|
|
36
|
+
upstreamDependenceJson: {};
|
|
37
|
+
repoType: string;
|
|
38
|
+
message: any;
|
|
39
|
+
reports?: undefined;
|
|
40
|
+
dependenceJson?: undefined;
|
|
41
|
+
}>;
|
|
9
42
|
export declare function gitDiffTool(arg: {
|
|
10
43
|
gitRepoUrl: string;
|
|
11
44
|
baseBranch: string;
|
|
@@ -13,12 +46,17 @@ export declare function gitDiffTool(arg: {
|
|
|
13
46
|
tempDirPath: string;
|
|
14
47
|
generateFile: Parameters<typeof generateGitDiffReport>[0]['generateFile'];
|
|
15
48
|
}): Promise<{
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
49
|
+
dependenceJson: {
|
|
50
|
+
import2export: Record<string, string>;
|
|
51
|
+
export2export: Record<string, string>;
|
|
52
|
+
mapFilePathToExportAllSources: Record<string, string[]>;
|
|
53
|
+
indirectExportMembers: Record<string, string>;
|
|
54
|
+
};
|
|
19
55
|
partialDependenceJson: Record<string, any>;
|
|
20
56
|
reports: {
|
|
21
57
|
dangerIdentifiers: string[];
|
|
58
|
+
topEffectedExportsAdded: string[];
|
|
59
|
+
topEffectedExportsRemoved: string[];
|
|
22
60
|
blockReports: {
|
|
23
61
|
diff_txt: string[];
|
|
24
62
|
infos: {
|
|
@@ -44,13 +44,19 @@ var import_umi4ProjectUtil = require("./umi4ProjectUtil");
|
|
|
44
44
|
var import_generateGitDiffReport = require("../report_util/generateGitDiffReport");
|
|
45
45
|
var import_vueProjectUtil = require("./vueProjectUtil");
|
|
46
46
|
var import__ = require("../../index");
|
|
47
|
-
var import_dayjs = __toESM(require("dayjs"));
|
|
48
47
|
var import_fs = require("fs");
|
|
49
48
|
var import_format_git_diff_content = require("../format_git_diff_content");
|
|
50
49
|
var import_gitUtil = require("./gitUtil");
|
|
50
|
+
var import_perf_hooks = require("perf_hooks");
|
|
51
|
+
var import_createDependenceMap = require("../report_util/createDependenceMap");
|
|
52
|
+
var import_collectUpstreamFiles = __toESM(require("./collectUpstreamFiles"));
|
|
53
|
+
var import_filterEffectedCode = __toESM(require("../report_util/filterEffectedCode"));
|
|
54
|
+
var import_report_util = require("../report_util");
|
|
55
|
+
var import_createRandomStr = __toESM(require("../createRandomStr"));
|
|
51
56
|
async function cloneGitRepoAndGetDiff(gitRepoUrl, branchName, extra = {}) {
|
|
52
|
-
|
|
53
|
-
const
|
|
57
|
+
import_perf_hooks.performance.mark("stage 0");
|
|
58
|
+
const { token, jsonKeys = ["upstreamDependenceJson"] } = extra;
|
|
59
|
+
const today = (0, import_createRandomStr.default)();
|
|
54
60
|
import_utils.logger.ready("准备生成临时工作目录...");
|
|
55
61
|
const [err] = await (0, import_await_to_js.default)(import_utils.execa.execa(`rm -rf ${today}`, { shell: true }));
|
|
56
62
|
if (err) {
|
|
@@ -60,17 +66,36 @@ async function cloneGitRepoAndGetDiff(gitRepoUrl, branchName, extra = {}) {
|
|
|
60
66
|
({ stderr, failed } = await import_utils.execa.execa(`mkdir -p ${today}`, { shell: true }));
|
|
61
67
|
(0, import_handleExecaError.handleExecaError)({ failed, stderr });
|
|
62
68
|
import_utils.logger.info("临时目录建立完成");
|
|
69
|
+
let upstreamDependenceJson = {};
|
|
70
|
+
let dependenceJson = {
|
|
71
|
+
indirectExportMembers: {},
|
|
72
|
+
import2export: {},
|
|
73
|
+
export2export: {},
|
|
74
|
+
mapFilePathToExportAllSources: {}
|
|
75
|
+
};
|
|
76
|
+
let effectedCode = {};
|
|
77
|
+
let reports = [];
|
|
63
78
|
try {
|
|
64
79
|
import_utils.logger.ready(`准备clone 源代码到临时目录下的 ${today}/${import_constants.TARGET} 文件夹`);
|
|
65
80
|
const repoUrl = (0, import_parseGitLabDiffUril.getGitRepoUrlByToken)(gitRepoUrl, token || "");
|
|
81
|
+
import_perf_hooks.performance.mark("stage 1");
|
|
66
82
|
await (0, import_gitUtil.cloneRepoWithBranchAndDefault)(repoUrl, branchName, (0, import_path.join)(today, import_constants.TARGET));
|
|
83
|
+
import_perf_hooks.performance.mark("stage 2");
|
|
84
|
+
import_utils.logger.info(`stage 1 --> stage 2 耗时: ${import_perf_hooks.performance.measure("stage 1 --> stage 2", "stage 1", "stage 2").duration}ms`);
|
|
85
|
+
await (0, import_gitUtil.cloneRepoWithBranchAndDefault)(repoUrl, "master", (0, import_path.join)(today, import_constants.SOURCE));
|
|
86
|
+
import_perf_hooks.performance.mark("stage 3");
|
|
87
|
+
import_utils.logger.info(`stage 2 --> stage 3 耗时: ${import_perf_hooks.performance.measure("stage 2 --> stage 3", "stage 2", "stage 3").duration}ms`);
|
|
67
88
|
import_utils.logger.ready("准备生成git_diff.txt文件");
|
|
68
89
|
({ stderr, failed } = await import_utils.execa.execa(`cd ${today}/${import_constants.TARGET} && git diff master..${branchName} --unified=0 --output=${import__.gitDiffFileName}`, { shell: true }));
|
|
90
|
+
import_perf_hooks.performance.mark("stage 4");
|
|
91
|
+
import_utils.logger.info(`stage 3 --> stage 4 耗时: ${import_perf_hooks.performance.measure("stage 3 --> stage 4", "stage 3", "stage 4").duration}ms`);
|
|
69
92
|
(0, import_handleExecaError.handleExecaError)({ failed, stderr });
|
|
70
93
|
const repoType = await (0, import_getRepoSupportFlag.getRepoType)((0, import_path.join)(process.cwd(), today, import_constants.TARGET, "package.json"));
|
|
71
94
|
import_utils.logger.info(`项目类型为: ${repoType}`);
|
|
72
95
|
if (repoType === "umi") {
|
|
73
|
-
const { madgeResult, shellExeResult } = await (0, import_umi4ProjectUtil.umi4SetUp)({ targetDirPath: (0, import_path.join)(process.cwd(), today, import_constants.TARGET) });
|
|
96
|
+
const { madgeResult, shellExeResult, parsedAlias } = await (0, import_umi4ProjectUtil.umi4SetUp)({ targetDirPath: (0, import_path.join)(process.cwd(), today, import_constants.TARGET), invokeType: "remote" });
|
|
97
|
+
import_perf_hooks.performance.mark("stage 5");
|
|
98
|
+
import_utils.logger.info(`stage 4 --> stage 5 耗时: ${import_perf_hooks.performance.measure("stage 4 --> stage 5", "stage 4", "stage 5").duration}ms`);
|
|
74
99
|
({ stderr, failed } = shellExeResult);
|
|
75
100
|
(0, import_handleExecaError.handleExecaError)({ failed, stderr });
|
|
76
101
|
const targetDirPath = (0, import_path.join)(process.cwd(), today, import_constants.TARGET);
|
|
@@ -79,11 +104,47 @@ async function cloneGitRepoAndGetDiff(gitRepoUrl, branchName, extra = {}) {
|
|
|
79
104
|
const usingFileNoPrefix = Object.keys(madgeResult.tree);
|
|
80
105
|
const groupGitDiffLines = gitDiffDetail.filter((item) => usingFileNoPrefix.includes(item.filePath));
|
|
81
106
|
const changedFilePaths = groupGitDiffLines.map((item) => item.filePath);
|
|
82
|
-
|
|
83
|
-
|
|
107
|
+
upstreamDependenceJson = Object.fromEntries(changedFilePaths.map((p) => [p, madgeResult.depends(p)]));
|
|
108
|
+
const absPathPrefix = targetDirPath + "/";
|
|
109
|
+
const modifiedFilePaths = gitDiffDetail.map((item) => item.filePath);
|
|
110
|
+
import_perf_hooks.performance.mark("stage 6");
|
|
111
|
+
import_utils.logger.info(`stage 5 --> stage 6 耗时: ${import_perf_hooks.performance.measure("stage 5 --> stage 6", "stage 5", "stage 6").duration}ms`);
|
|
112
|
+
const effectedFilePaths = (0, import_collectUpstreamFiles.default)(madgeResult, modifiedFilePaths).map((item) => (0, import_utils.winPath)((0, import_path.join)(absPathPrefix, item)));
|
|
113
|
+
import_perf_hooks.performance.mark("stage 7");
|
|
114
|
+
import_utils.logger.info(`stage 6 --> stage 7 耗时: ${import_perf_hooks.performance.measure("stage 6 --> stage 7", "stage 6", "stage 7").duration}ms`);
|
|
115
|
+
if (jsonKeys.includes("dependenceJson")) {
|
|
116
|
+
dependenceJson = (0, import_createDependenceMap.createExportedNameToReferenceLocalSet)(effectedFilePaths, parsedAlias, absPathPrefix, Object.keys(madgeResult.tree));
|
|
117
|
+
}
|
|
118
|
+
import_perf_hooks.performance.mark("stage 8");
|
|
119
|
+
import_utils.logger.info(`stage 7 --> stage 8 耗时: ${import_perf_hooks.performance.measure("stage 7 --> stage 8", "stage 7", "stage 8").duration}ms`);
|
|
120
|
+
if (jsonKeys.includes("reports")) {
|
|
121
|
+
reports = (0, import_report_util.createDetectReport)({ groupGitDiffLines, tree: madgeResult.tree, absPathPrefix });
|
|
122
|
+
}
|
|
123
|
+
import_perf_hooks.performance.mark("stage 9");
|
|
124
|
+
import_utils.logger.info(`stage 8 --> stage 9 耗时: ${import_perf_hooks.performance.measure("stage 8 --> stage 9", "stage 8", "stage 9").duration}ms`);
|
|
125
|
+
if (jsonKeys.includes("effectedCode")) {
|
|
126
|
+
effectedCode = (0, import_filterEffectedCode.default)(reports, dependenceJson);
|
|
127
|
+
}
|
|
128
|
+
import_perf_hooks.performance.mark("stage 10");
|
|
129
|
+
import_utils.logger.info(`stage 9 --> stage 10 耗时: ${import_perf_hooks.performance.measure("stage 9 --> stage 10", "stage 9", "stage 10").duration}ms`);
|
|
130
|
+
import_utils.logger.info(`total 耗时: ${import_perf_hooks.performance.measure("stage 0 --> stage 10", "stage 0", "stage 10").duration}ms`);
|
|
84
131
|
}
|
|
132
|
+
return {
|
|
133
|
+
reports,
|
|
134
|
+
dependenceJson,
|
|
135
|
+
effectedCode,
|
|
136
|
+
upstreamDependenceJson,
|
|
137
|
+
repoType,
|
|
138
|
+
message: ""
|
|
139
|
+
};
|
|
85
140
|
} catch (error) {
|
|
86
141
|
import_utils.logger.error(error);
|
|
142
|
+
return {
|
|
143
|
+
effectedCode,
|
|
144
|
+
upstreamDependenceJson,
|
|
145
|
+
repoType: "",
|
|
146
|
+
message: error.message
|
|
147
|
+
};
|
|
87
148
|
} finally {
|
|
88
149
|
(0, import_utils.rimraf)((0, import_path.join)(process.cwd(), today), () => {
|
|
89
150
|
import_utils.logger.info("临时目录已删除");
|
|
@@ -100,45 +161,34 @@ async function gitDiffTool(arg) {
|
|
|
100
161
|
await import_utils.execa.execa(`mkdir -p ${today}`, { shell: true });
|
|
101
162
|
import_utils.logger.info("临时目录建立完成");
|
|
102
163
|
try {
|
|
103
|
-
import_utils.logger.ready(`准备clone
|
|
164
|
+
import_utils.logger.ready(`准备clone 源代码 分支:${branchName} 到临时目录下的 ${import_constants.TARGET} 文件夹`);
|
|
165
|
+
await (0, import_gitUtil.cloneRepoWithBranchAndDefault)(gitUrl, branchName, (0, import_path.join)(process.cwd(), today, import_constants.TARGET));
|
|
104
166
|
let stderr, failed;
|
|
105
|
-
({ stderr, failed } = await import_utils.execa.execa(`git clone ${gitUrl} ${today}/${import_constants.TARGET}`, { shell: true }));
|
|
106
|
-
(0, import_handleExecaError.handleExecaError)({ failed, stderr });
|
|
107
167
|
import_utils.logger.info("源代码clone完成");
|
|
108
168
|
import_utils.logger.wait("检测项目类型");
|
|
109
169
|
const repoType = await (0, import_getRepoSupportFlag.getRepoType)((0, import_path.join)(process.cwd(), today, import_constants.TARGET, "package.json"));
|
|
110
170
|
import_utils.logger.info(`项目类型为: ${repoType}`);
|
|
111
|
-
if (!repoType) {
|
|
171
|
+
if (!(0, import_getRepoSupportFlag.isRepoTypeSupported)(repoType)) {
|
|
112
172
|
import_utils.logger.error("该项目不支持检测");
|
|
113
173
|
(0, import_utils.rimraf)((0, import_path.join)(process.cwd(), today), () => {
|
|
114
174
|
import_utils.logger.info("临时目录已删除");
|
|
115
175
|
});
|
|
116
176
|
return;
|
|
117
177
|
}
|
|
118
|
-
import_utils.logger.ready(`准备clone
|
|
119
|
-
(
|
|
120
|
-
(
|
|
121
|
-
import_utils.logger.info("源代码clone完成");
|
|
122
|
-
if (baseBranch !== "master") {
|
|
123
|
-
import_utils.logger.ready("准备切换到基准分支");
|
|
124
|
-
({ stderr, failed } = await import_utils.execa.execa(`cd ${today}/${import_constants.SOURCE} && git fetch origin ${baseBranch}:${baseBranch} && git checkout ${baseBranch}`, { shell: true }));
|
|
125
|
-
(0, import_handleExecaError.handleExecaError)({ failed, stderr });
|
|
126
|
-
import_utils.logger.info("源代码切换到基准分支完成");
|
|
127
|
-
}
|
|
128
|
-
import_utils.logger.ready("准备切换到目标分支");
|
|
129
|
-
({ stderr, failed } = await import_utils.execa.execa(`cd ${today}/${import_constants.TARGET} && git fetch origin ${branchName}:${branchName} && git checkout ${branchName}`, { shell: true }));
|
|
130
|
-
(0, import_handleExecaError.handleExecaError)({ failed, stderr });
|
|
131
|
-
import_utils.logger.info("分支切换完成");
|
|
178
|
+
import_utils.logger.ready(`准备clone 源代码 分支:master 到临时目录下的 ${import_constants.SOURCE} 文件夹`);
|
|
179
|
+
await (0, import_gitUtil.cloneRepoWithBranchAndDefault)(gitUrl, "master", (0, import_path.join)(process.cwd(), today, import_constants.SOURCE));
|
|
180
|
+
import_utils.logger.info(`分支 ${branchName} 代码 clone 完成`);
|
|
132
181
|
import_utils.logger.ready("准备生成git_diff.txt文件");
|
|
133
182
|
({ stderr, failed } = await import_utils.execa.execa(`cd ${today}/${import_constants.TARGET} && git diff ${baseBranch}..${branchName} --unified=0 --output=${import__.gitDiffFileName}`, { shell: true }));
|
|
134
183
|
(0, import_handleExecaError.handleExecaError)({ failed, stderr });
|
|
135
184
|
import_utils.logger.info("git_diff.txt文件生成完成");
|
|
136
185
|
if (repoType === "umi") {
|
|
137
|
-
const { madgeResult, shellExeResult, parsedAlias } = await (0, import_umi4ProjectUtil.umi4SetUp)({ targetDirPath: (0, import_path.join)(process.cwd(), today, import_constants.TARGET) });
|
|
186
|
+
const { madgeResult, shellExeResult, parsedAlias } = await (0, import_umi4ProjectUtil.umi4SetUp)({ targetDirPath: (0, import_path.join)(process.cwd(), today, import_constants.TARGET), invokeType: "local" });
|
|
138
187
|
({ stderr, failed } = shellExeResult);
|
|
139
188
|
(0, import_handleExecaError.handleExecaError)({ failed, stderr });
|
|
140
|
-
|
|
141
|
-
|
|
189
|
+
const reports = await (0, import_generateGitDiffReport.generateGitDiffReport)({ madgeResult, parsedAlias, targetDirPath: (0, import_path.join)(process.cwd(), today, import_constants.TARGET), generateFile });
|
|
190
|
+
return reports;
|
|
191
|
+
} else if (repoType === "vue2") {
|
|
142
192
|
const { madgeResult, shellExeResult, parsedAlias } = await (0, import_vueProjectUtil.vueSetUp)({ targetDir: `${today}/${import_constants.TARGET}` });
|
|
143
193
|
({ stderr, failed } = shellExeResult);
|
|
144
194
|
(0, import_handleExecaError.handleExecaError)({ failed, stderr });
|
|
@@ -6,3 +6,7 @@
|
|
|
6
6
|
* @returns {Promise<string>} 克隆目录路径
|
|
7
7
|
*/
|
|
8
8
|
export declare function cloneRepoWithBranchAndDefault(repoUrl: string, targetBranch: string, targetDir: string): Promise<string>;
|
|
9
|
+
/**
|
|
10
|
+
* 执行 baseBranch 和 targetBranch 的 diff
|
|
11
|
+
*/
|
|
12
|
+
export declare function execGitDiff(targetDir: string, baseBranch: string, targetBranch: string): Promise<any>;
|
|
@@ -19,9 +19,11 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
19
19
|
// src/util/shared/gitUtil.ts
|
|
20
20
|
var gitUtil_exports = {};
|
|
21
21
|
__export(gitUtil_exports, {
|
|
22
|
-
cloneRepoWithBranchAndDefault: () => cloneRepoWithBranchAndDefault
|
|
22
|
+
cloneRepoWithBranchAndDefault: () => cloneRepoWithBranchAndDefault,
|
|
23
|
+
execGitDiff: () => execGitDiff
|
|
23
24
|
});
|
|
24
25
|
module.exports = __toCommonJS(gitUtil_exports);
|
|
26
|
+
var import__ = require("../../index");
|
|
25
27
|
var simpleGit = require("simple-git");
|
|
26
28
|
async function cloneRepoWithBranchAndDefault(repoUrl, targetBranch, targetDir) {
|
|
27
29
|
try {
|
|
@@ -45,7 +47,21 @@ async function cloneRepoWithBranchAndDefault(repoUrl, targetBranch, targetDir) {
|
|
|
45
47
|
throw error;
|
|
46
48
|
}
|
|
47
49
|
}
|
|
50
|
+
async function execGitDiff(targetDir, baseBranch, targetBranch) {
|
|
51
|
+
try {
|
|
52
|
+
const repoGit = simpleGit(targetDir);
|
|
53
|
+
await repoGit.checkout(targetBranch);
|
|
54
|
+
await repoGit.pull("origin", targetBranch);
|
|
55
|
+
const diffFiles = await repoGit.diffSummary([baseBranch, "--unified=0", `--output=${import__.gitDiffFileName}`]);
|
|
56
|
+
console.log(`${targetBranch} 与 ${baseBranch} 的差异:`, diffFiles);
|
|
57
|
+
return diffFiles;
|
|
58
|
+
} catch (error) {
|
|
59
|
+
console.error(`获取差异失败:${error.message}`);
|
|
60
|
+
throw error;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
48
63
|
// Annotate the CommonJS export names for ESM import in node:
|
|
49
64
|
0 && (module.exports = {
|
|
50
|
-
cloneRepoWithBranchAndDefault
|
|
65
|
+
cloneRepoWithBranchAndDefault,
|
|
66
|
+
execGitDiff
|
|
51
67
|
});
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { execa } from "@umijs/utils";
|
|
2
|
-
export declare function umi4SetUp({ targetDirPath }: {
|
|
2
|
+
export declare function umi4SetUp({ targetDirPath, invokeType }: {
|
|
3
3
|
targetDirPath: string;
|
|
4
|
+
invokeType: 'local' | 'remote';
|
|
4
5
|
}): Promise<{
|
|
5
6
|
shellExeResult: execa.ExecaReturnValue<string>;
|
|
6
7
|
madgeResult: import("../report_util/getMadgeInstance").IMadgeInstance;
|
|
@@ -35,14 +35,12 @@ var userAliasGetter = (cwd, appData) => {
|
|
|
35
35
|
"@umijs/max": "@@/exports"
|
|
36
36
|
};
|
|
37
37
|
};
|
|
38
|
-
async function
|
|
39
|
-
import_utils.
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
import_utils.logger.info(`正在安装 @umijs/max 并执行 setup 脚本...`);
|
|
45
|
-
const shellExeResult = await import_utils.execa.execa(`cd ${targetDirPath} && npm uninstall @umijs/max && npm install @umijs/max && npx max setup`, { shell: true });
|
|
38
|
+
async function getUmiInvokeResult(targetDirPath, invokeType) {
|
|
39
|
+
return await import_utils.execa.execa(`cd ${targetDirPath} && npx max setup`, { shell: true });
|
|
40
|
+
}
|
|
41
|
+
async function umi4SetUp({ targetDirPath, invokeType }) {
|
|
42
|
+
import_utils.logger.info(`正在执行 setup 脚本...`);
|
|
43
|
+
const shellExeResult = await getUmiInvokeResult(targetDirPath, invokeType);
|
|
46
44
|
const tsconfig = await import_utils.tsconfigPaths.loadConfig(targetDirPath);
|
|
47
45
|
let appData = { config: null };
|
|
48
46
|
try {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "js-code-detector",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.48",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/cjs/index.js",
|
|
6
6
|
"types": "dist/cjs/index.d.ts",
|
|
@@ -31,7 +31,8 @@
|
|
|
31
31
|
"@types/crypto-js": "^4.2.2",
|
|
32
32
|
"@types/lodash": "^4.17.20",
|
|
33
33
|
"@types/madge": "^5.0.3",
|
|
34
|
-
"father": "^4.6.3"
|
|
34
|
+
"father": "^4.6.3",
|
|
35
|
+
"tsx": "^4.20.6"
|
|
35
36
|
},
|
|
36
37
|
"dependencies": {
|
|
37
38
|
"@babel/parser": "^7.28.3",
|
package/bin/eslintOutput.js
DELETED
package/dist/cjs/sh/detect.sh
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
#!/bin/sh
|
|
2
|
-
time=$(date "+%Y%-m%d%H%M%S")
|
|
3
|
-
mkdir -p $time
|
|
4
|
-
cd $time
|
|
5
|
-
|
|
6
|
-
git clone $1 target
|
|
7
|
-
cd target
|
|
8
|
-
yarn install
|
|
9
|
-
|
|
10
|
-
git fetch origin $2:$2
|
|
11
|
-
git checkout $2
|
|
12
|
-
|
|
13
|
-
git diff master..$2 --unified=0 --output=git_diff.txt
|
|
14
|
-
cd ..
|
|
15
|
-
git clone $1 source
|