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
package/dist/cjs/index.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { cloneGitRepoAndGetDiff } from "./util/shared/gitDiffTool";
|
|
1
2
|
export declare const gitDiffFileName = "git_diff.txt";
|
|
2
3
|
export declare function getGitRepositoryAndBranch(): Promise<{
|
|
3
4
|
gitUrl: string;
|
|
@@ -5,12 +6,17 @@ export declare function getGitRepositoryAndBranch(): Promise<{
|
|
|
5
6
|
}>;
|
|
6
7
|
export declare function sameCodeDetect(dirOfCwd?: string): Promise<void>;
|
|
7
8
|
export declare function gitDiffDetect(): Promise<{
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
9
|
+
dependenceJson: {
|
|
10
|
+
import2export: Record<string, string>;
|
|
11
|
+
export2export: Record<string, string>;
|
|
12
|
+
mapFilePathToExportAllSources: Record<string, string[]>;
|
|
13
|
+
indirectExportMembers: Record<string, string>;
|
|
14
|
+
};
|
|
11
15
|
partialDependenceJson: Record<string, any>;
|
|
12
16
|
reports: {
|
|
13
17
|
dangerIdentifiers: string[];
|
|
18
|
+
topEffectedExportsAdded: string[];
|
|
19
|
+
topEffectedExportsRemoved: string[];
|
|
14
20
|
blockReports: {
|
|
15
21
|
diff_txt: string[];
|
|
16
22
|
infos: {
|
|
@@ -26,13 +32,11 @@ export declare function gitDiffDetect(): Promise<{
|
|
|
26
32
|
filePath: string;
|
|
27
33
|
}[];
|
|
28
34
|
} | undefined>;
|
|
29
|
-
export declare function
|
|
30
|
-
mdContent: string;
|
|
31
|
-
dependenceJson: Record<string, any>;
|
|
32
|
-
upstreamDependenceJson: Record<string, any>;
|
|
33
|
-
partialDependenceJson: Record<string, any>;
|
|
35
|
+
export declare function getUpstreamDependenceJson(inputUrl: string, token: string, jsonKeys?: (keyof Awaited<ReturnType<typeof cloneGitRepoAndGetDiff>>)[]): Promise<{
|
|
34
36
|
reports: {
|
|
35
37
|
dangerIdentifiers: string[];
|
|
38
|
+
topEffectedExportsAdded: string[];
|
|
39
|
+
topEffectedExportsRemoved: string[];
|
|
36
40
|
blockReports: {
|
|
37
41
|
diff_txt: string[];
|
|
38
42
|
infos: {
|
|
@@ -47,7 +51,26 @@ export declare function gitDiffDetectByUrl(inputUrl: string): Promise<{
|
|
|
47
51
|
undefinedIdentifiers: string[];
|
|
48
52
|
filePath: string;
|
|
49
53
|
}[];
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
+
dependenceJson: {
|
|
55
|
+
import2export: Record<string, string>;
|
|
56
|
+
export2export: Record<string, string>;
|
|
57
|
+
mapFilePathToExportAllSources: Record<string, string[]>;
|
|
58
|
+
indirectExportMembers: Record<string, string>;
|
|
59
|
+
};
|
|
60
|
+
effectedCode: Record<string, any>;
|
|
61
|
+
upstreamDependenceJson: {};
|
|
62
|
+
repoType: string;
|
|
63
|
+
message: string;
|
|
64
|
+
} | {
|
|
65
|
+
effectedCode: Record<string, any>;
|
|
66
|
+
upstreamDependenceJson: {};
|
|
67
|
+
repoType: string;
|
|
68
|
+
message: any;
|
|
69
|
+
reports?: undefined;
|
|
70
|
+
dependenceJson?: undefined;
|
|
71
|
+
}>;
|
|
72
|
+
export { isRepoTypeSupported } from "./util/shared/getRepoSupportFlag";
|
|
73
|
+
export declare function runDiffDetect(compareUrl?: string, token?: string): Promise<{
|
|
74
|
+
repoType: string;
|
|
75
|
+
effectedImportUsage: [string, string][];
|
|
76
|
+
}>;
|
package/dist/cjs/index.js
CHANGED
|
@@ -32,8 +32,9 @@ __export(src_exports, {
|
|
|
32
32
|
getGitRepositoryAndBranch: () => getGitRepositoryAndBranch,
|
|
33
33
|
getUpstreamDependenceJson: () => getUpstreamDependenceJson,
|
|
34
34
|
gitDiffDetect: () => gitDiffDetect,
|
|
35
|
-
gitDiffDetectByUrl: () => gitDiffDetectByUrl,
|
|
36
35
|
gitDiffFileName: () => gitDiffFileName,
|
|
36
|
+
isRepoTypeSupported: () => import_getRepoSupportFlag.isRepoTypeSupported,
|
|
37
|
+
runDiffDetect: () => runDiffDetect,
|
|
37
38
|
sameCodeDetect: () => sameCodeDetect
|
|
38
39
|
});
|
|
39
40
|
module.exports = __toCommonJS(src_exports);
|
|
@@ -45,6 +46,8 @@ var import_readDirFiles = require("./util/shared/readDirFiles");
|
|
|
45
46
|
var import_Core = __toESM(require("./util/ast_util/Core"));
|
|
46
47
|
var import_parseGitLabDiffUril = require("./util/parseGitLabDiffUril");
|
|
47
48
|
var import_gitDiffTool = require("./util/shared/gitDiffTool");
|
|
49
|
+
var import_DetectService = require("./services/DetectService");
|
|
50
|
+
var import_getRepoSupportFlag = require("./util/shared/getRepoSupportFlag");
|
|
48
51
|
var gitDiffFileName = "git_diff.txt";
|
|
49
52
|
async function getGitRepositoryAndBranch() {
|
|
50
53
|
const res = await import_utils.execa.execa("git remote get-url origin", { shell: true });
|
|
@@ -70,21 +73,33 @@ async function gitDiffDetect() {
|
|
|
70
73
|
const today = (0, import_dayjs.default)().format("YYYYMDD_HHmmss");
|
|
71
74
|
return (0, import_gitDiffTool.gitDiffTool)({ gitRepoUrl: gitUrl, targetBranch: branchName, baseBranch: "master", tempDirPath: today, generateFile: void 0 });
|
|
72
75
|
}
|
|
73
|
-
async function
|
|
74
|
-
const today = (0, import_dayjs.default)().format("YYYYMDD_HHmmss") + Math.random().toString(36).slice(-5);
|
|
76
|
+
async function getUpstreamDependenceJson(inputUrl, token, jsonKeys) {
|
|
75
77
|
const gitInfo = (0, import_parseGitLabDiffUril.parseGitLabCompareUrl)(inputUrl);
|
|
76
|
-
return (0, import_gitDiffTool.
|
|
78
|
+
return (0, import_gitDiffTool.cloneGitRepoAndGetDiff)(gitInfo.gitRepoUrl, gitInfo.targetBranch, { token, jsonKeys });
|
|
77
79
|
}
|
|
78
|
-
async function
|
|
79
|
-
const
|
|
80
|
-
|
|
80
|
+
async function runDiffDetect(compareUrl, token) {
|
|
81
|
+
const option = {
|
|
82
|
+
compareUrl,
|
|
83
|
+
token,
|
|
84
|
+
gitRepoUrl: "",
|
|
85
|
+
branchName: ""
|
|
86
|
+
};
|
|
87
|
+
if (!compareUrl || !token) {
|
|
88
|
+
const { gitUrl, branchName } = await getGitRepositoryAndBranch();
|
|
89
|
+
option.gitRepoUrl = gitUrl;
|
|
90
|
+
option.branchName = branchName;
|
|
91
|
+
}
|
|
92
|
+
const service = new import_DetectService.DetectService(option);
|
|
93
|
+
await service.run();
|
|
94
|
+
return service.formatResult();
|
|
81
95
|
}
|
|
82
96
|
// Annotate the CommonJS export names for ESM import in node:
|
|
83
97
|
0 && (module.exports = {
|
|
84
98
|
getGitRepositoryAndBranch,
|
|
85
99
|
getUpstreamDependenceJson,
|
|
86
100
|
gitDiffDetect,
|
|
87
|
-
gitDiffDetectByUrl,
|
|
88
101
|
gitDiffFileName,
|
|
102
|
+
isRepoTypeSupported,
|
|
103
|
+
runDiffDetect,
|
|
89
104
|
sameCodeDetect
|
|
90
105
|
});
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { parseGitLabCompareUrl } from "../util/parseGitLabDiffUril";
|
|
2
|
+
import { ProjectService } from "./ProjectService";
|
|
3
|
+
export declare class DetectService {
|
|
4
|
+
directoryInfo: {
|
|
5
|
+
tmpWorkDir: string;
|
|
6
|
+
sourceBranchDir: string;
|
|
7
|
+
targetBranchDir: string;
|
|
8
|
+
};
|
|
9
|
+
gitInfo: {
|
|
10
|
+
token: string;
|
|
11
|
+
repoType: string;
|
|
12
|
+
} & ReturnType<typeof parseGitLabCompareUrl>;
|
|
13
|
+
projectService: ProjectService | null;
|
|
14
|
+
constructor(option: {
|
|
15
|
+
compareUrl?: string;
|
|
16
|
+
gitRepoUrl?: string;
|
|
17
|
+
token?: string;
|
|
18
|
+
branchName?: string;
|
|
19
|
+
});
|
|
20
|
+
init(option: {
|
|
21
|
+
compareUrl?: string;
|
|
22
|
+
gitRepoUrl?: string;
|
|
23
|
+
token?: string;
|
|
24
|
+
branchName?: string;
|
|
25
|
+
}): Promise<void>;
|
|
26
|
+
run(): Promise<void>;
|
|
27
|
+
clean(): Promise<void>;
|
|
28
|
+
mkdir(): Promise<void>;
|
|
29
|
+
clone(): Promise<void>;
|
|
30
|
+
projectHandle(): Promise<void>;
|
|
31
|
+
formatResult(): {
|
|
32
|
+
repoType: string;
|
|
33
|
+
effectedImportUsage: [string, string][];
|
|
34
|
+
};
|
|
35
|
+
}
|
|
@@ -0,0 +1,177 @@
|
|
|
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/services/DetectService.ts
|
|
30
|
+
var DetectService_exports = {};
|
|
31
|
+
__export(DetectService_exports, {
|
|
32
|
+
DetectService: () => DetectService
|
|
33
|
+
});
|
|
34
|
+
module.exports = __toCommonJS(DetectService_exports);
|
|
35
|
+
var import_path = require("path");
|
|
36
|
+
var import_await_to_js = __toESM(require("await-to-js"));
|
|
37
|
+
var import_utils = require("@umijs/utils");
|
|
38
|
+
var import_parseGitLabDiffUril = require("../util/parseGitLabDiffUril");
|
|
39
|
+
var import_createRandomStr = __toESM(require("../util/createRandomStr"));
|
|
40
|
+
var import_constants = require("../util/constants");
|
|
41
|
+
var import_gitUtil = require("../util/shared/gitUtil");
|
|
42
|
+
var import_getRepoSupportFlag = require("../util/shared/getRepoSupportFlag");
|
|
43
|
+
var import_UmiProjectService = __toESM(require("./projectServiceClass/UmiProjectService"));
|
|
44
|
+
var import_perf_hooks = require("perf_hooks");
|
|
45
|
+
var DetectService = class {
|
|
46
|
+
constructor(option) {
|
|
47
|
+
this.directoryInfo = {
|
|
48
|
+
tmpWorkDir: "",
|
|
49
|
+
sourceBranchDir: "",
|
|
50
|
+
targetBranchDir: ""
|
|
51
|
+
};
|
|
52
|
+
this.gitInfo = {
|
|
53
|
+
token: "",
|
|
54
|
+
gitRepoUrl: "",
|
|
55
|
+
baseBranch: "",
|
|
56
|
+
targetBranch: "",
|
|
57
|
+
projectPathPart: "",
|
|
58
|
+
repoType: ""
|
|
59
|
+
};
|
|
60
|
+
this.projectService = null;
|
|
61
|
+
this.init(option);
|
|
62
|
+
}
|
|
63
|
+
async init(option) {
|
|
64
|
+
const { compareUrl, token, gitRepoUrl, branchName } = option;
|
|
65
|
+
const tmpWorkDir = (0, import_createRandomStr.default)();
|
|
66
|
+
this.directoryInfo = {
|
|
67
|
+
tmpWorkDir,
|
|
68
|
+
sourceBranchDir: (0, import_path.join)(tmpWorkDir, import_constants.SOURCE),
|
|
69
|
+
targetBranchDir: (0, import_path.join)(tmpWorkDir, import_constants.TARGET)
|
|
70
|
+
};
|
|
71
|
+
if (compareUrl) {
|
|
72
|
+
this.gitInfo = {
|
|
73
|
+
...this.gitInfo,
|
|
74
|
+
...(0, import_parseGitLabDiffUril.parseGitLabCompareUrl)(compareUrl),
|
|
75
|
+
repoType: ""
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
if (gitRepoUrl) {
|
|
79
|
+
this.gitInfo = {
|
|
80
|
+
...this.gitInfo,
|
|
81
|
+
baseBranch: "master",
|
|
82
|
+
targetBranch: branchName || "master",
|
|
83
|
+
gitRepoUrl,
|
|
84
|
+
token: token || "",
|
|
85
|
+
repoType: ""
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
async run() {
|
|
90
|
+
await this.clean();
|
|
91
|
+
try {
|
|
92
|
+
import_perf_hooks.performance.mark("mkdir");
|
|
93
|
+
await this.mkdir();
|
|
94
|
+
import_perf_hooks.performance.mark("clone");
|
|
95
|
+
{
|
|
96
|
+
const duration = import_perf_hooks.performance.measure("mkdir", "mkdir", "clone").duration;
|
|
97
|
+
import_utils.logger.info(`mkdir 耗时: ${duration}ms`);
|
|
98
|
+
}
|
|
99
|
+
await this.clone();
|
|
100
|
+
import_perf_hooks.performance.mark("projectHandle");
|
|
101
|
+
{
|
|
102
|
+
const duration = import_perf_hooks.performance.measure("clone", "clone", "projectHandle").duration;
|
|
103
|
+
import_utils.logger.info(`clone 耗时: ${duration}ms`);
|
|
104
|
+
}
|
|
105
|
+
await this.projectHandle();
|
|
106
|
+
{
|
|
107
|
+
const duration = import_perf_hooks.performance.measure("projectHandle", "projectHandle").duration;
|
|
108
|
+
import_utils.logger.info(`项目处理耗时: ${duration}ms`);
|
|
109
|
+
}
|
|
110
|
+
} catch (e) {
|
|
111
|
+
import_utils.logger.error("失败:" + e.message);
|
|
112
|
+
} finally {
|
|
113
|
+
this.clean();
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
async clean() {
|
|
117
|
+
const dirPath = this.directoryInfo.tmpWorkDir;
|
|
118
|
+
if (!dirPath)
|
|
119
|
+
return;
|
|
120
|
+
const [err] = await (0, import_await_to_js.default)(import_utils.execa.execa(`rm -rf ${dirPath}`, { shell: true }));
|
|
121
|
+
if (err) {
|
|
122
|
+
import_utils.logger.error("临时目录删除失败");
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
async mkdir() {
|
|
126
|
+
const dirPath = this.directoryInfo.tmpWorkDir;
|
|
127
|
+
await import_utils.execa.execa(`mkdir -p ${dirPath}`, { shell: true });
|
|
128
|
+
}
|
|
129
|
+
async clone() {
|
|
130
|
+
import_utils.logger.info("开始克隆仓库");
|
|
131
|
+
const { tmpWorkDir } = this.directoryInfo;
|
|
132
|
+
const { gitRepoUrl, token, baseBranch, targetBranch } = this.gitInfo;
|
|
133
|
+
const repoUrl = token ? (0, import_parseGitLabDiffUril.getGitRepoUrlByToken)(gitRepoUrl, token || "") : gitRepoUrl;
|
|
134
|
+
const branchesAndTargetDirPaths = [
|
|
135
|
+
{
|
|
136
|
+
branch: baseBranch,
|
|
137
|
+
targetDirPath: (0, import_path.join)(tmpWorkDir, import_constants.SOURCE)
|
|
138
|
+
},
|
|
139
|
+
{
|
|
140
|
+
branch: targetBranch,
|
|
141
|
+
targetDirPath: (0, import_path.join)(tmpWorkDir, import_constants.TARGET)
|
|
142
|
+
}
|
|
143
|
+
];
|
|
144
|
+
await Promise.all(branchesAndTargetDirPaths.map(({ branch, targetDirPath: targetDirPath2 }) => {
|
|
145
|
+
return (0, import_gitUtil.cloneRepoWithBranchAndDefault)(repoUrl, branch, targetDirPath2);
|
|
146
|
+
}));
|
|
147
|
+
const targetDirPath = (0, import_path.join)(tmpWorkDir, import_constants.TARGET);
|
|
148
|
+
await (0, import_gitUtil.execGitDiff)(targetDirPath, baseBranch, targetBranch);
|
|
149
|
+
const repoType = await (0, import_getRepoSupportFlag.getRepoType)((0, import_path.join)(targetDirPath, "package.json"));
|
|
150
|
+
this.gitInfo.repoType = repoType;
|
|
151
|
+
import_utils.logger.info("克隆仓库成功");
|
|
152
|
+
}
|
|
153
|
+
async projectHandle() {
|
|
154
|
+
var _a;
|
|
155
|
+
const { repoType } = this.gitInfo;
|
|
156
|
+
if (!(0, import_getRepoSupportFlag.isRepoTypeSupported)(repoType)) {
|
|
157
|
+
return;
|
|
158
|
+
}
|
|
159
|
+
if (repoType === "umi") {
|
|
160
|
+
this.projectService = new import_UmiProjectService.default(this);
|
|
161
|
+
}
|
|
162
|
+
await ((_a = this.projectService) == null ? void 0 : _a.run());
|
|
163
|
+
}
|
|
164
|
+
formatResult() {
|
|
165
|
+
var _a;
|
|
166
|
+
const repoType = this.gitInfo.repoType;
|
|
167
|
+
const { effectedImportUsage } = ((_a = this.projectService) == null ? void 0 : _a.outputResult) || { effectedImportUsage: [] };
|
|
168
|
+
return {
|
|
169
|
+
repoType,
|
|
170
|
+
effectedImportUsage
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
};
|
|
174
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
175
|
+
0 && (module.exports = {
|
|
176
|
+
DetectService
|
|
177
|
+
});
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { DetectService } from "./DetectService";
|
|
2
|
+
import { formatGitDiffContent } from "../util/format_git_diff_content";
|
|
3
|
+
import { IMadgeInstance } from "../util/report_util/getMadgeInstance";
|
|
4
|
+
export interface ProjectService {
|
|
5
|
+
detectService: DetectService;
|
|
6
|
+
gitDiffDetail: ReturnType<typeof formatGitDiffContent>;
|
|
7
|
+
helpInfo: {
|
|
8
|
+
projectFileList: string[];
|
|
9
|
+
madgeResult: IMadgeInstance | null;
|
|
10
|
+
parsedAlias: Record<string, any>;
|
|
11
|
+
};
|
|
12
|
+
outputResult: {
|
|
13
|
+
effectedImportUsage: [string, string][];
|
|
14
|
+
};
|
|
15
|
+
run(): void;
|
|
16
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __copyProps = (to, from, except, desc) => {
|
|
6
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
7
|
+
for (let key of __getOwnPropNames(from))
|
|
8
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
9
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
10
|
+
}
|
|
11
|
+
return to;
|
|
12
|
+
};
|
|
13
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
14
|
+
|
|
15
|
+
// src/services/ProjectService.ts
|
|
16
|
+
var ProjectService_exports = {};
|
|
17
|
+
module.exports = __toCommonJS(ProjectService_exports);
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { GitDiffDetail } from "../../util/format_git_diff_content";
|
|
2
|
+
import { DetectService } from "../DetectService";
|
|
3
|
+
import { ProjectService } from "../ProjectService";
|
|
4
|
+
export default class UmiProjectService implements ProjectService {
|
|
5
|
+
detectService: DetectService;
|
|
6
|
+
gitDiffDetail: GitDiffDetail[];
|
|
7
|
+
helpInfo: ProjectService['helpInfo'];
|
|
8
|
+
outputResult: ProjectService['outputResult'];
|
|
9
|
+
constructor(detectService: DetectService);
|
|
10
|
+
run(): Promise<void>;
|
|
11
|
+
parseGitDiffContent(): Promise<void>;
|
|
12
|
+
collectEffectedFiles(): Promise<void>;
|
|
13
|
+
}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
// 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/services/projectServiceClass/UmiProjectService.ts
|
|
30
|
+
var UmiProjectService_exports = {};
|
|
31
|
+
__export(UmiProjectService_exports, {
|
|
32
|
+
default: () => UmiProjectService
|
|
33
|
+
});
|
|
34
|
+
module.exports = __toCommonJS(UmiProjectService_exports);
|
|
35
|
+
var import_format_git_diff_content = require("../../util/format_git_diff_content");
|
|
36
|
+
var import_umi4ProjectUtil = require("../../util/shared/umi4ProjectUtil");
|
|
37
|
+
var import_fs = require("fs");
|
|
38
|
+
var import_path = require("path");
|
|
39
|
+
var import__ = require("../../index");
|
|
40
|
+
var import_collectUpstreamFiles = __toESM(require("../../util/shared/collectUpstreamFiles"));
|
|
41
|
+
var import_createDependenceMap = require("../../util/report_util/createDependenceMap");
|
|
42
|
+
var import_filterEffectedExportMember = __toESM(require("../../util/report_util/filterEffectedExportMember"));
|
|
43
|
+
var UmiProjectService = class {
|
|
44
|
+
constructor(detectService) {
|
|
45
|
+
this.detectService = detectService;
|
|
46
|
+
this.gitDiffDetail = [];
|
|
47
|
+
this.helpInfo = {
|
|
48
|
+
projectFileList: [],
|
|
49
|
+
madgeResult: null,
|
|
50
|
+
parsedAlias: {}
|
|
51
|
+
};
|
|
52
|
+
this.outputResult = {
|
|
53
|
+
effectedImportUsage: []
|
|
54
|
+
};
|
|
55
|
+
this.detectService = detectService;
|
|
56
|
+
}
|
|
57
|
+
async run() {
|
|
58
|
+
const targetDirPath = this.detectService.directoryInfo.targetBranchDir;
|
|
59
|
+
const { madgeResult, parsedAlias } = await (0, import_umi4ProjectUtil.umi4SetUp)({ targetDirPath, invokeType: "remote" });
|
|
60
|
+
this.helpInfo.projectFileList = Object.keys(madgeResult.tree);
|
|
61
|
+
this.helpInfo.madgeResult = madgeResult;
|
|
62
|
+
this.helpInfo.parsedAlias = parsedAlias;
|
|
63
|
+
await this.parseGitDiffContent();
|
|
64
|
+
await this.collectEffectedFiles();
|
|
65
|
+
}
|
|
66
|
+
async parseGitDiffContent() {
|
|
67
|
+
const targetDirPath = this.detectService.directoryInfo.targetBranchDir;
|
|
68
|
+
const diff_txt = (0, import_fs.readFileSync)((0, import_path.join)(targetDirPath, import__.gitDiffFileName), "utf-8");
|
|
69
|
+
this.gitDiffDetail = (0, import_format_git_diff_content.formatGitDiffContent)(diff_txt);
|
|
70
|
+
}
|
|
71
|
+
async collectEffectedFiles() {
|
|
72
|
+
const { madgeResult, parsedAlias } = this.helpInfo;
|
|
73
|
+
const projectFileList = this.helpInfo.projectFileList;
|
|
74
|
+
const targetBranchDir = this.detectService.directoryInfo.targetBranchDir;
|
|
75
|
+
const absPathPrefix = (0, import_path.join)(targetBranchDir, "/");
|
|
76
|
+
const validModifiedFiles = this.gitDiffDetail.reduce((acc, item) => {
|
|
77
|
+
const { filePath } = item;
|
|
78
|
+
this.helpInfo.projectFileList.includes(filePath) && acc.push(filePath);
|
|
79
|
+
return acc;
|
|
80
|
+
}, []);
|
|
81
|
+
const possibleEffectedFiles = (0, import_collectUpstreamFiles.default)(madgeResult, validModifiedFiles);
|
|
82
|
+
const possibleEffectedFilesFullPath = possibleEffectedFiles.map((file) => (0, import_path.join)(absPathPrefix, file));
|
|
83
|
+
const { import2export, indirectExportMembers } = (0, import_createDependenceMap.createExportedNameToReferenceLocalSet)(possibleEffectedFilesFullPath, parsedAlias, absPathPrefix, projectFileList);
|
|
84
|
+
const gitDiffDetail = this.gitDiffDetail;
|
|
85
|
+
const validGitDiffDetail = gitDiffDetail.filter((item) => possibleEffectedFiles.includes(item.filePath));
|
|
86
|
+
const effectedExportNames = validGitDiffDetail.map((item) => {
|
|
87
|
+
const { filePath, newBranchLineScope, startLineOfNew } = item;
|
|
88
|
+
const exportedNames = (0, import_filterEffectedExportMember.default)((0, import_path.join)(absPathPrefix, filePath), absPathPrefix, Number(startLineOfNew), Number(startLineOfNew) + Number(newBranchLineScope));
|
|
89
|
+
return exportedNames.map((name) => [filePath, name].join("#"));
|
|
90
|
+
}).flat();
|
|
91
|
+
const effectedImportUsage = [...Object.entries(import2export), ...Object.entries(indirectExportMembers)].filter(([_, value]) => {
|
|
92
|
+
return effectedExportNames.includes(value);
|
|
93
|
+
});
|
|
94
|
+
this.outputResult.effectedImportUsage = effectedImportUsage;
|
|
95
|
+
}
|
|
96
|
+
};
|
|
@@ -52,6 +52,7 @@ export interface AstNode {
|
|
|
52
52
|
}
|
|
53
53
|
export default class AstUtil {
|
|
54
54
|
static invalidNodeKey: string[];
|
|
55
|
+
static EXPORT_DECLARATION_TYPES: string[];
|
|
55
56
|
static getNodePath(node: AstNode): string;
|
|
56
57
|
static getShortNodeMsg(node: AstNode, hideParentProperty?: boolean): string;
|
|
57
58
|
static getAncestorsFromBirth(occupationId: AstNode, sourceId: AstNode): AstNode[];
|
|
@@ -59,12 +60,12 @@ export default class AstUtil {
|
|
|
59
60
|
private static getImpactedNode;
|
|
60
61
|
static deepFirstTravel(node: AstNode, filePath: string, mapUuidToNode: Map<string, AstNode>, mapFileLineToNodeSet: Map<number, Set<AstNode>>, mapPathToNodeSet: Map<string, Set<AstNode>>, stopTravelCallback?: (node: AstNode) => boolean | void): AstNode | undefined;
|
|
61
62
|
private static _deepFirstTravel;
|
|
63
|
+
private static findRelatedExportNameOfDeclarationIdentifier;
|
|
64
|
+
static findExportedMembersNameFromAncestors(node: AstNode | undefined | null): string[];
|
|
62
65
|
private static updateImportedAndExportedMember;
|
|
63
66
|
private static collectInjectAndProvide;
|
|
64
67
|
private static handleDeclaration;
|
|
65
68
|
private static collectHoldingIds;
|
|
66
|
-
private static isVarInit;
|
|
67
|
-
static isReturnArgument(node: AstNode): boolean;
|
|
68
69
|
private static collectDependenceIds;
|
|
69
70
|
private static isUseStateVarDec;
|
|
70
71
|
static isUseMemoVarDec(node: AstNode): boolean;
|
|
@@ -79,7 +80,6 @@ export default class AstUtil {
|
|
|
79
80
|
private static collectEffectIdOfUnaryUpdate;
|
|
80
81
|
private static isBodyArray;
|
|
81
82
|
private static findExportIdentifiers;
|
|
82
|
-
private static expressionTypeIsIdentifier;
|
|
83
83
|
static collectExpressionIdentifiersShallow(exp: AstNode | null, callback: (identifier: AstNode) => void): void;
|
|
84
84
|
private static _collectExpressionIdentifiersShallow;
|
|
85
85
|
static collectExpressionIdentifiers(exp: AstNode | null, callback: (identifier: AstNode) => void): void;
|
|
@@ -97,8 +97,5 @@ export default class AstUtil {
|
|
|
97
97
|
static isPropertyOfGlobal(node: AstNode): boolean;
|
|
98
98
|
static isIntrinsicElement(node: AstNode): boolean | "" | undefined;
|
|
99
99
|
static isStandardAttribute(node: AstNode): boolean;
|
|
100
|
-
static getTopScopeNodesByLineNumberRange(mapFileLineToNodeSet: Map<number, Set<AstNode>>, lineNumberStart: number, lineNumberEnd: number): AstNode[];
|
|
101
|
-
static getTopScopeNodesByLineNumber(mapFileLineToNodeSet: Map<number, Set<AstNode>>, lineNumber: number): AstNode[];
|
|
102
|
-
static isSubNodeOfVariableDeclarator(node: AstNode): boolean;
|
|
103
|
-
static createScopeContent(node: AstNode): string;
|
|
100
|
+
static getTopScopeNodesByLineNumberRange(mapFileLineToNodeSet: Map<number, Set<AstNode>>, lineNumberStart: number, lineNumberEnd: number, loose?: boolean): AstNode[];
|
|
104
101
|
}
|