js-code-detector 0.0.23 → 0.0.25

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.
@@ -1,12 +1,8 @@
1
1
  export declare const gitDiffFileName = "git_diff.txt";
2
- export declare const gitDiffJsonName = "git_diff.json";
3
- export declare function umiPluginCallback(api: any): Promise<void>;
4
- export declare function writeGitDiffTxt(gitUrl: string, branchName: string): Promise<string>;
5
2
  export declare function getGitRepositoryAndBranch(): Promise<{
6
3
  gitUrl: string;
7
4
  branchName: string;
8
5
  }>;
9
- export declare function generateReport(content: string): void;
10
6
  export declare function sameCodeDetect(dirOfCwd?: string): Promise<void>;
11
7
  export declare function gitDiffDetect(): Promise<void>;
12
8
  export declare function getEslintCheckResult(today: string): Promise<void>;
package/dist/cjs/index.js CHANGED
@@ -29,88 +29,26 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
29
29
  // src/index.ts
30
30
  var src_exports = {};
31
31
  __export(src_exports, {
32
- generateReport: () => generateReport,
33
32
  getEslintCheckResult: () => getEslintCheckResult,
34
33
  getGitRepositoryAndBranch: () => getGitRepositoryAndBranch,
35
34
  gitDiffDetect: () => gitDiffDetect,
36
35
  gitDiffFileName: () => gitDiffFileName,
37
- gitDiffJsonName: () => gitDiffJsonName,
38
- sameCodeDetect: () => sameCodeDetect,
39
- umiPluginCallback: () => umiPluginCallback,
40
- writeGitDiffTxt: () => writeGitDiffTxt
36
+ sameCodeDetect: () => sameCodeDetect
41
37
  });
42
38
  module.exports = __toCommonJS(src_exports);
43
39
  var import_fs = require("fs");
44
40
  var import_path = require("path");
45
- var import_format_git_diff_content = require("./util/format_git_diff_content");
46
- var import_madge_util = __toESM(require("./util/madge_util"));
47
41
  var import_fs2 = require("fs");
48
- var import_report_util = require("./util/report_util");
49
42
  var import_utils = require("@umijs/utils");
50
43
  var import_dayjs = __toESM(require("dayjs"));
51
- var import_createMdByJson = require("./util/report_util/createMdByJson");
52
44
  var import_readDirFiles = require("./util/shared/readDirFiles");
53
45
  var import_Core = __toESM(require("./util/ast_util/Core"));
54
46
  var import_constants = require("./util/constants");
55
47
  var import_await_to_js = __toESM(require("await-to-js"));
56
48
  var import_generateGitDiffReport = require("./util/report_util/generateGitDiffReport");
57
- var jsonName = "git_diff_report.md";
58
49
  var gitDiffFileName = "git_diff.txt";
59
- var gitDiffJsonName = "git_diff.json";
60
50
  var eslintJsonName = "eslint-report.json";
61
51
  var eslintFinalJsonName = "eslint-final-report.json";
62
- async function umiPluginCallback(api) {
63
- const diff_txt = (0, import_fs.readFileSync)((0, import_path.join)(api.cwd, gitDiffFileName), "utf-8");
64
- const gitDiffDetail = (0, import_format_git_diff_content.formatGitDiffContent)(diff_txt);
65
- (0, import_fs2.writeFileSync)((0, import_path.join)(api.cwd, gitDiffJsonName), JSON.stringify(gitDiffDetail, null, 2), { encoding: "utf-8", flag: "w" });
66
- const madgeUtil = await (0, import_madge_util.default)(api);
67
- if (!madgeUtil) {
68
- return;
69
- }
70
- const { madgeInstance: { tree }, usingFiles } = madgeUtil;
71
- const cwd = api.cwd;
72
- const absPathPrefix = cwd + "/";
73
- const usingFileNoPrefix = usingFiles.map((item) => item.filePath.replace(absPathPrefix, ""));
74
- const groupGitDiffLines = gitDiffDetail.filter((item) => usingFileNoPrefix.includes(item.filePath));
75
- const reports = (0, import_report_util.createDetectReport)({ groupGitDiffLines, tree, absPathPrefix });
76
- (0, import_fs2.writeFileSync)((0, import_path.join)(api.cwd, "reports.json"), JSON.stringify(reports, null, 2), { encoding: "utf-8", flag: "w" });
77
- const mdContent = (0, import_createMdByJson.createMdByJson)(reports);
78
- (0, import_fs2.writeFileSync)((0, import_path.join)(api.cwd, jsonName), mdContent, { encoding: "utf-8", flag: "w" });
79
- }
80
- var shellFileContent = `#!/bin/sh
81
- time=$(date "+%Y%-m%d")
82
- mkdir -p $time
83
- cd $time
84
-
85
- git clone $1 target
86
- cd target
87
- yarn install
88
-
89
- git fetch origin $2:$2
90
- git checkout $2
91
-
92
- git diff master..$2 --unified=0 --output=git_diff.txt
93
- cd ..
94
- git clone $1 source
95
- `;
96
- var pluginFileContent = `import * as cb from "js-code-detector"
97
-
98
- export default async (api: any) => {
99
- const buildCallback = () => cb.umiPluginCallback(api);
100
- api.onBuildComplete(buildCallback);
101
- }`;
102
- async function writeGitDiffTxt(gitUrl, branchName) {
103
- const today = (0, import_dayjs.default)().format("YYYYMDD");
104
- (0, import_fs2.writeFileSync)((0, import_path.join)(process.cwd(), "detect.sh"), shellFileContent, { encoding: "utf-8", flag: "w" });
105
- await import_utils.execa.execa("chmod +x detect.sh", { shell: "/bin/bash" });
106
- const res0 = await import_utils.execa.execa("sh detect.sh", [gitUrl, branchName], { shell: "/bin/bash" });
107
- import_utils.chalk.green(["临时文件夹建立,源代码clone完成"]);
108
- (0, import_fs2.writeFileSync)((0, import_path.join)(process.cwd(), today, "target", "plugin.ts"), pluginFileContent, { encoding: "utf-8", flag: "w" });
109
- import_utils.chalk.green(["临时文件写入完成"]);
110
- await import_utils.execa.execa(`cd ${today}/target && npm run build`, { shell: "/bin/bash" });
111
- import_utils.chalk.green(["临时入口文件生成"]);
112
- return (0, import_fs.readFileSync)((0, import_path.join)(process.cwd(), today, "target", jsonName), "utf-8");
113
- }
114
52
  async function getGitRepositoryAndBranch() {
115
53
  const res = await import_utils.execa.execa("git remote get-url origin", { shell: "/bin/bash" });
116
54
  import_utils.chalk.green(["仓库地址:", res.stdout]);
@@ -121,9 +59,6 @@ async function getGitRepositoryAndBranch() {
121
59
  branchName: branch.stdout
122
60
  };
123
61
  }
124
- function generateReport(content) {
125
- (0, import_fs2.writeFileSync)((0, import_path.join)(process.cwd(), `${(0, import_dayjs.default)().format("YYYYMDD_HHmm")}_${jsonName}`), content, { encoding: "utf-8", flag: "w" });
126
- }
127
62
  async function sameCodeDetect(dirOfCwd) {
128
63
  const filesAndContent = await (0, import_readDirFiles.readSrcFiles)(dirOfCwd);
129
64
  const { nodeContentGroupList, depthList } = import_Core.default.investigate(filesAndContent);
@@ -137,6 +72,10 @@ async function gitDiffDetect() {
137
72
  const today = (0, import_dayjs.default)().format("YYYYMDD");
138
73
  const { gitUrl, branchName } = await getGitRepositoryAndBranch();
139
74
  import_utils.logger.ready("准备生成临时工作目录...");
75
+ const [err] = await (0, import_await_to_js.default)(import_utils.execa.execa(`rm -rf ${today}`, { shell: "/bin/bash" }));
76
+ if (err) {
77
+ import_utils.logger.error("临时目录删除失败");
78
+ }
140
79
  await import_utils.execa.execa(`mkdir -p ${today}`, { shell: "/bin/bash" });
141
80
  import_utils.logger.info("临时目录建立完成");
142
81
  import_utils.logger.ready(`准备clone源代码到临时目录下的 ${import_constants.TARGET} 文件夹`);
@@ -155,13 +94,8 @@ async function gitDiffDetect() {
155
94
  await import_utils.execa.execa(`cd ${today}/${import_constants.TARGET} && npx max setup`, { shell: "/bin/bash" });
156
95
  import_utils.logger.info("入口文件 生成完成!");
157
96
  import_utils.logger.ready("准备生成报告");
158
- await (0, import_generateGitDiffReport.generateGitDiffReport)({ targetDirPath: (0, import_path.join)(process.cwd(), today, "target") });
97
+ await (0, import_generateGitDiffReport.generateGitDiffReport)({ targetDirPath: (0, import_path.join)(process.cwd(), today, import_constants.TARGET) });
159
98
  import_utils.logger.info("报告完成");
160
- import_utils.logger.ready("准备移动报告");
161
- const content = (0, import_fs.readFileSync)((0, import_path.join)(process.cwd(), today, import_constants.TARGET, jsonName), "utf-8");
162
- const mdFileName = `${(0, import_dayjs.default)().format("YYYYMDD_HHmm")}_${jsonName}`;
163
- (0, import_fs2.writeFileSync)((0, import_path.join)(process.cwd(), mdFileName), content, { encoding: "utf-8", flag: "w" });
164
- import_utils.logger.info("报告完成: " + mdFileName);
165
99
  (0, import_utils.rimraf)((0, import_path.join)(process.cwd(), today), () => {
166
100
  import_utils.logger.info("临时目录已删除");
167
101
  });
@@ -190,13 +124,9 @@ async function getEslintCheckResult(today) {
190
124
  }
191
125
  // Annotate the CommonJS export names for ESM import in node:
192
126
  0 && (module.exports = {
193
- generateReport,
194
127
  getEslintCheckResult,
195
128
  getGitRepositoryAndBranch,
196
129
  gitDiffDetect,
197
130
  gitDiffFileName,
198
- gitDiffJsonName,
199
- sameCodeDetect,
200
- umiPluginCallback,
201
- writeGitDiffTxt
131
+ sameCodeDetect
202
132
  });
@@ -33,6 +33,21 @@ export interface AstNode {
33
33
  provide: Set<AstNode>;
34
34
  effectIds: Set<AstNode>;
35
35
  occupation: Set<AstNode>;
36
+ importedMember: {
37
+ sourcePath: string;
38
+ members: {
39
+ importedName: string;
40
+ localName: string;
41
+ }[];
42
+ }[];
43
+ exportedMember: {
44
+ sourcePath: string;
45
+ members: {
46
+ exportedName: string;
47
+ localName: string;
48
+ }[];
49
+ ExportAllDeclaration: boolean;
50
+ }[];
36
51
  };
37
52
  }
38
53
  export default class AstUtil {
@@ -42,8 +57,9 @@ export default class AstUtil {
42
57
  static getAncestorsFromBirth(occupationId: AstNode, sourceId: AstNode): AstNode[];
43
58
  static getNearestImpactedNode(ancestors: AstNode[]): AstNode | undefined;
44
59
  private static getImpactedNode;
45
- static deepFirstTravel(node: AstNode, filePath: string, mapUuidToNode: Map<string, AstNode>, mapFileLineToNodeSet: Map<number, Set<AstNode>>, mapPathToNodeSet: Map<string, Set<AstNode>>): AstNode | undefined;
60
+ 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;
46
61
  private static _deepFirstTravel;
62
+ private static updateImportedAndExportedMember;
47
63
  private static collectInjectAndProvide;
48
64
  private static handleDeclaration;
49
65
  private static collectHoldingIds;
@@ -59,20 +59,14 @@ var _AstUtil = class {
59
59
  if (type === "JSXOpeningElement") {
60
60
  const { name } = ancestor.name;
61
61
  if (name && typeof name === "object") {
62
- const realName = name.name;
63
- if (!this.intrinsicElements.includes(realName)) {
64
- return name;
65
- }
62
+ return name;
66
63
  }
67
64
  }
68
65
  if (type === "JSXElement") {
69
66
  const { openingElement } = ancestor;
70
67
  const { name } = openingElement;
71
68
  if (name && typeof name === "object") {
72
- const realName = name.name;
73
- if (!this.intrinsicElements.includes(realName)) {
74
- return name;
75
- }
69
+ return name;
76
70
  }
77
71
  }
78
72
  if (type === "VariableDeclarator") {
@@ -86,16 +80,16 @@ var _AstUtil = class {
86
80
  }
87
81
  return null;
88
82
  }
89
- static deepFirstTravel(node, filePath, mapUuidToNode, mapFileLineToNodeSet, mapPathToNodeSet) {
83
+ static deepFirstTravel(node, filePath, mapUuidToNode, mapFileLineToNodeSet, mapPathToNodeSet, stopTravelCallback) {
90
84
  const visitedNodeSet = /* @__PURE__ */ new Set();
91
85
  if (!node) {
92
86
  return;
93
87
  }
94
- return this._deepFirstTravel(node, visitedNodeSet, { filePath, depth: 0, mapUuidToNode, mapFileLineToNodeSet, mapPathToNodeSet });
88
+ return this._deepFirstTravel(node, visitedNodeSet, { filePath, depth: 0, mapUuidToNode, mapFileLineToNodeSet, mapPathToNodeSet, stopTravelCallback });
95
89
  }
96
90
  static _deepFirstTravel(node, visitedNodeSet, extra) {
97
91
  visitedNodeSet.add(node);
98
- const { filePath, depth, mapUuidToNode, mapFileLineToNodeSet, mapPathToNodeSet } = extra;
92
+ const { filePath, depth, mapUuidToNode, mapFileLineToNodeSet, mapPathToNodeSet, stopTravelCallback } = extra;
99
93
  const _util = {
100
94
  startLine: NaN,
101
95
  endLine: NaN,
@@ -118,10 +112,16 @@ var _AstUtil = class {
118
112
  inject: /* @__PURE__ */ new Set(),
119
113
  provide: /* @__PURE__ */ new Set(),
120
114
  effectIds: /* @__PURE__ */ new Set(),
121
- occupation: /* @__PURE__ */ new Set()
115
+ occupation: /* @__PURE__ */ new Set(),
116
+ importedMember: [],
117
+ exportedMember: []
122
118
  };
123
119
  node._util = _util;
124
120
  const { nodeCollection, children } = _util;
121
+ const stopTravel = stopTravelCallback == null ? void 0 : stopTravelCallback(node);
122
+ if (stopTravel) {
123
+ return node;
124
+ }
125
125
  Object.keys(node).forEach((nodeKey) => {
126
126
  if (this.invalidNodeKey.includes(nodeKey) || nodeKey.startsWith("TS") || nodeKey.endsWith("Annotation")) {
127
127
  return;
@@ -131,13 +131,13 @@ var _AstUtil = class {
131
131
  return;
132
132
  }
133
133
  if (this.isValidNodeCollect(nodeValue)) {
134
- const childNode = this._deepFirstTravel(nodeValue, visitedNodeSet, { filePath, depth: depth + 1, mapUuidToNode, mapFileLineToNodeSet, mapPathToNodeSet });
134
+ const childNode = this._deepFirstTravel(nodeValue, visitedNodeSet, { filePath, depth: depth + 1, mapUuidToNode, mapFileLineToNodeSet, mapPathToNodeSet, stopTravelCallback });
135
135
  nodeCollection.push(childNode, ...childNode._util.nodeCollection);
136
136
  children.push(childNode);
137
137
  childNode._util.parentProperty = nodeKey;
138
138
  } else if (this.isValidArrayNodeCollect(nodeValue)) {
139
139
  const validNodeArray = nodeValue.filter((nodeItem) => this.isValidNodeCollect(nodeItem)).map((v) => {
140
- return this._deepFirstTravel(v, visitedNodeSet, { filePath, depth: depth + 1, mapUuidToNode, mapFileLineToNodeSet, mapPathToNodeSet });
140
+ return this._deepFirstTravel(v, visitedNodeSet, { filePath, depth: depth + 1, mapUuidToNode, mapFileLineToNodeSet, mapPathToNodeSet, stopTravelCallback });
141
141
  });
142
142
  nodeCollection.push(...validNodeArray.map((n) => [n, ...n._util.nodeCollection]).flat());
143
143
  children.push(...validNodeArray);
@@ -147,17 +147,115 @@ var _AstUtil = class {
147
147
  });
148
148
  }
149
149
  });
150
- children.forEach((child) => child._util.parent = node);
151
- nodeCollection.forEach((nodeItem) => nodeItem._util.ancestors.unshift(node));
152
- this.collectHoldingIds(node);
153
- this.collectDependenceIds(node);
154
- this.collectInjectAndProvide(node);
150
+ try {
151
+ children.forEach((child) => child._util.parent = node);
152
+ nodeCollection.forEach((nodeItem) => nodeItem._util.ancestors.unshift(node));
153
+ } catch (e) {
154
+ console.error("parent ancestors update", e.message);
155
+ }
156
+ try {
157
+ const skip = nodeCollection.some((nodeItem) => stopTravelCallback == null ? void 0 : stopTravelCallback(nodeItem));
158
+ if (!skip) {
159
+ this.collectHoldingIds(node);
160
+ }
161
+ } catch (e) {
162
+ console.error("collectHoldingIds", e.message);
163
+ }
164
+ try {
165
+ this.collectDependenceIds(node);
166
+ } catch (e) {
167
+ console.error("collectDependenceIds", e.message);
168
+ }
169
+ try {
170
+ this.collectInjectAndProvide(node);
171
+ } catch (e) {
172
+ console.error("collectInjectAndProvide", e.message);
173
+ }
155
174
  if (node.type === "Program") {
156
- nodeCollection.forEach((child) => this.collectEffectId(child));
175
+ try {
176
+ nodeCollection.forEach((child) => this.collectEffectId(child));
177
+ } catch (e) {
178
+ console.error("collectEffectId", e.message);
179
+ }
180
+ try {
181
+ node.body.forEach((child) => this.updateImportedAndExportedMember(child, node));
182
+ } catch (e) {
183
+ console.error("updateImportedAndExportedMember", e.message);
184
+ }
185
+ }
186
+ try {
187
+ this.updateLoc(node, { mapUuidToNode, mapFileLineToNodeSet, mapPathToNodeSet });
188
+ } catch (e) {
189
+ console.error("updateLoc", e.message);
157
190
  }
158
- this.updateLoc(node, { mapUuidToNode, mapFileLineToNodeSet, mapPathToNodeSet });
159
191
  return node;
160
192
  }
193
+ static updateImportedAndExportedMember(node, programNode) {
194
+ const { type, source, declaration, specifiers, _util } = node;
195
+ const { filePath } = _util;
196
+ const sourceValue = (source == null ? void 0 : source.value) || filePath;
197
+ const { importedMember, exportedMember } = programNode._util;
198
+ if (type === "ImportDeclaration") {
199
+ specifiers.forEach((specifier) => {
200
+ const { local, imported } = specifier;
201
+ let target = importedMember.find((v) => v.sourcePath === sourceValue);
202
+ if (!target) {
203
+ target = { sourcePath: sourceValue, members: [] };
204
+ importedMember.push(target);
205
+ }
206
+ target.members.push({
207
+ localName: local.name,
208
+ importedName: (imported == null ? void 0 : imported.name) || "default"
209
+ });
210
+ });
211
+ }
212
+ if (type === "ExportAllDeclaration") {
213
+ const target = exportedMember.find((v) => v.sourcePath === sourceValue);
214
+ if (!target) {
215
+ exportedMember.push({ sourcePath: sourceValue, members: [], ExportAllDeclaration: true });
216
+ }
217
+ }
218
+ if (type === "ExportNamedDeclaration") {
219
+ specifiers.forEach((specifier) => {
220
+ const { local, exported } = specifier;
221
+ let target = exportedMember.find((v) => v.sourcePath === sourceValue);
222
+ if (!target) {
223
+ target = { sourcePath: sourceValue, members: [], ExportAllDeclaration: false };
224
+ exportedMember.push(target);
225
+ }
226
+ target.members.push({
227
+ localName: (local == null ? void 0 : local.name) || "",
228
+ exportedName: exported.name
229
+ });
230
+ });
231
+ if (Array.isArray(declaration == null ? void 0 : declaration.declarations)) {
232
+ declaration == null ? void 0 : declaration.declarations.forEach((dec) => {
233
+ var _a;
234
+ let target = exportedMember.find((v) => v.sourcePath === sourceValue);
235
+ if (!target) {
236
+ target = { sourcePath: sourceValue, members: [], ExportAllDeclaration: false };
237
+ exportedMember.push(target);
238
+ }
239
+ const idName = (_a = dec.id) == null ? void 0 : _a.name;
240
+ target.members.push({
241
+ localName: idName,
242
+ exportedName: idName
243
+ });
244
+ });
245
+ }
246
+ }
247
+ if (type === "ExportDefaultDeclaration") {
248
+ let target = exportedMember.find((v) => v.sourcePath === filePath);
249
+ if (!target) {
250
+ target = { sourcePath: filePath, members: [], ExportAllDeclaration: false };
251
+ exportedMember.push(target);
252
+ }
253
+ target.members.push({
254
+ localName: "default",
255
+ exportedName: "default"
256
+ });
257
+ }
258
+ }
161
259
  static collectInjectAndProvide(ast) {
162
260
  const { type, _util: { inject, provide, holdingIds } } = ast;
163
261
  if (type !== "Program" || !this.isBodyArray(ast)) {
@@ -301,6 +399,9 @@ var _AstUtil = class {
301
399
  this.collectExpressionIdentifiersShallow(child, (id) => dependenceIds.add(id));
302
400
  });
303
401
  for (const dependenceId of dependenceIds) {
402
+ if (!dependenceId._util) {
403
+ continue;
404
+ }
304
405
  if (dependenceId._util.variableScope.length === 0 && typeof dependenceId.name === "string" && holdingIdNameMap.has(dependenceId.name)) {
305
406
  dependenceId._util.variableScope.push(...[...holdingIdNameMap.get(dependenceId.name)]);
306
407
  const firstPick = dependenceId._util.variableScope[0];
@@ -0,0 +1,15 @@
1
+ /**
2
+ * 解析导入路径为全路径,支持相对路径
3
+ * @param {Object} alias - 路径别名配置对象
4
+ * @param {string} importPath - 导入路径
5
+ * @param {string} currentFilePath - 当前文件的绝对路径(已处理)
6
+ * @param {string[]} [extensions=['.js', '.ts', '.jsx', '.tsx']] - 可能的文件扩展名
7
+ * @returns {Object} 包含全路径和是否为外部路径的对象
8
+ */
9
+ export declare function resolveImportPath(alias: Record<string, string>, importPath: string, currentFilePath: string, extensions?: string[]): {
10
+ fullPath: string[];
11
+ isExternal: boolean;
12
+ } | {
13
+ fullPath: null;
14
+ isExternal: boolean;
15
+ };
@@ -0,0 +1,131 @@
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/ast_util/filePathResolver.ts
20
+ var filePathResolver_exports = {};
21
+ __export(filePathResolver_exports, {
22
+ resolveImportPath: () => resolveImportPath
23
+ });
24
+ module.exports = __toCommonJS(filePathResolver_exports);
25
+ function joinPath(...paths) {
26
+ const isAbsolute = paths.some(
27
+ (path) => path.startsWith("/") || path.startsWith("\\") || path.length >= 2 && path[1] === ":"
28
+ // 处理Windows路径如C:
29
+ );
30
+ let joined = paths.filter(Boolean).join("/").replace(/[\\/]+/g, "/");
31
+ if (isAbsolute && joined.length >= 2 && joined[1] === ":") {
32
+ joined = joined[0] + ":" + joined.slice(2);
33
+ }
34
+ const segments = joined.split("/");
35
+ const result = [];
36
+ for (const segment of segments) {
37
+ if (segment === ".")
38
+ continue;
39
+ if (segment === "..") {
40
+ if (result.length && result[result.length - 1] !== "..") {
41
+ result.pop();
42
+ } else if (!isAbsolute) {
43
+ result.push("..");
44
+ }
45
+ } else {
46
+ result.push(segment);
47
+ }
48
+ }
49
+ let finalPath = result.join("/");
50
+ if (isAbsolute && !finalPath.startsWith("/") && !(finalPath.length >= 2 && finalPath[1] === ":")) {
51
+ finalPath = "/" + finalPath;
52
+ }
53
+ return finalPath;
54
+ }
55
+ function getDirName(filePath) {
56
+ const normalized = filePath.replace(/[\\/]+/g, "/");
57
+ const lastSlashIndex = normalized.lastIndexOf("/");
58
+ if (lastSlashIndex === -1)
59
+ return ".";
60
+ if (lastSlashIndex === 0) {
61
+ return normalized[0] === "/" ? "/" : ".";
62
+ }
63
+ return normalized.slice(0, lastSlashIndex);
64
+ }
65
+ function resolveImportPath(alias, importPath, currentFilePath, extensions = [".js", ".ts", ".jsx", ".tsx"]) {
66
+ if (importPath.startsWith(".")) {
67
+ const currentDir = getDirName(currentFilePath);
68
+ const absolutePath = joinPath(currentDir, importPath);
69
+ const possiblePaths2 = [absolutePath];
70
+ extensions.forEach((ext) => {
71
+ possiblePaths2.push(`${absolutePath}${ext}`);
72
+ });
73
+ extensions.forEach((ext) => {
74
+ possiblePaths2.push(joinPath(absolutePath, `index${ext}`));
75
+ });
76
+ return {
77
+ fullPath: possiblePaths2,
78
+ isExternal: false
79
+ };
80
+ }
81
+ const isExternal = !Object.keys(alias).some((aliasKey) => {
82
+ if (aliasKey.endsWith("$")) {
83
+ return importPath === aliasKey.slice(0, -1);
84
+ }
85
+ return importPath === aliasKey || importPath.startsWith(`${aliasKey}/`);
86
+ });
87
+ if (isExternal) {
88
+ return {
89
+ fullPath: null,
90
+ isExternal: true
91
+ };
92
+ }
93
+ let matchedAlias = null;
94
+ let matchedKey = "";
95
+ Object.entries(alias).forEach(([key, value]) => {
96
+ if (key.endsWith("$") && importPath === key.slice(0, -1)) {
97
+ matchedAlias = value;
98
+ matchedKey = key.slice(0, -1);
99
+ }
100
+ });
101
+ if (!matchedAlias) {
102
+ Object.entries(alias).forEach(([key, value]) => {
103
+ if (!key.endsWith("$") && (importPath === key || importPath.startsWith(`${key}/`))) {
104
+ matchedAlias = value;
105
+ matchedKey = key;
106
+ }
107
+ });
108
+ }
109
+ let basePath;
110
+ if (importPath === matchedKey) {
111
+ basePath = matchedAlias;
112
+ } else {
113
+ const relativePath = importPath.slice(matchedKey.length + 1);
114
+ basePath = joinPath(matchedAlias, relativePath);
115
+ }
116
+ const possiblePaths = [basePath];
117
+ extensions.forEach((ext) => {
118
+ possiblePaths.push(`${basePath}${ext}`);
119
+ });
120
+ extensions.forEach((ext) => {
121
+ possiblePaths.push(joinPath(basePath, `index${ext}`));
122
+ });
123
+ return {
124
+ fullPath: possiblePaths,
125
+ isExternal: false
126
+ };
127
+ }
128
+ // Annotate the CommonJS export names for ESM import in node:
129
+ 0 && (module.exports = {
130
+ resolveImportPath
131
+ });
@@ -1,5 +1,5 @@
1
- import { AstNode } from "./AstUtil";
2
- export default function getAstKitByFilePath(filePath: string, absPathPrefix: string): {
1
+ import AstUtil, { AstNode } from "./AstUtil";
2
+ export default function getAstKitByFilePath(filePath: string, absPathPrefix: string, stopTravelCallback?: Parameters<typeof AstUtil.deepFirstTravel>[5]): {
3
3
  mapFileLineToNodeSet: Map<number, Set<AstNode>>;
4
4
  mapUuidToNode: Map<string, AstNode>;
5
5
  mapPathToNodeSet: Map<string, Set<AstNode>>;
@@ -35,19 +35,22 @@ module.exports = __toCommonJS(getAstKitByFilePath_exports);
35
35
  var import_AstUtil = __toESM(require("./AstUtil"));
36
36
  var import_FileUtil = __toESM(require("./FileUtil"));
37
37
  var mapFilePathToTools = /* @__PURE__ */ new Map();
38
- var createMapFileLineToNodeSet = (file, absPathPrefix) => {
38
+ var createMapFileLineToNodeSet = (file, absPathPrefix, stopTravelCallback) => {
39
39
  const mapUuidToNode = /* @__PURE__ */ new Map();
40
40
  const mapPathToNodeSet = /* @__PURE__ */ new Map();
41
41
  const mapFileLineToNodeSet = /* @__PURE__ */ new Map();
42
42
  const ast = import_FileUtil.default.getASTByFilePath(file);
43
43
  const filePathRelative = file.replace(absPathPrefix, "");
44
- import_AstUtil.default.deepFirstTravel(ast, filePathRelative, mapUuidToNode, mapFileLineToNodeSet, mapPathToNodeSet);
44
+ import_AstUtil.default.deepFirstTravel(ast, filePathRelative, mapUuidToNode, mapFileLineToNodeSet, mapPathToNodeSet, stopTravelCallback);
45
45
  return { mapFileLineToNodeSet, mapUuidToNode, mapPathToNodeSet };
46
46
  };
47
- function getAstKitByFilePath(filePath, absPathPrefix) {
47
+ function getAstKitByFilePath(filePath, absPathPrefix, stopTravelCallback) {
48
+ if (stopTravelCallback) {
49
+ return createMapFileLineToNodeSet(filePath, absPathPrefix, stopTravelCallback);
50
+ }
48
51
  let tools = mapFilePathToTools.get(filePath);
49
52
  if (!tools) {
50
- mapFilePathToTools.set(filePath, tools = createMapFileLineToNodeSet(filePath, absPathPrefix));
53
+ mapFilePathToTools.set(filePath, tools = createMapFileLineToNodeSet(filePath, absPathPrefix, stopTravelCallback));
51
54
  }
52
55
  return tools;
53
56
  }
@@ -0,0 +1,11 @@
1
+ /**
2
+ * 解析GitLab分支对比链接的工具函数(含URL解码)
3
+ * @param compareUrl - GitLab分支对比链接,格式需为 http://gitlab.xxx.com/项目路径/-/compare/分支1...分支2
4
+ * @returns 包含项目Git地址和两个解码后分支名的对象
5
+ * @throws 当输入链接格式不符合要求时抛出错误
6
+ */
7
+ declare function parseGitLabCompareUrl(compareUrl: string): {
8
+ gitRepoUrl: string;
9
+ baseBranch: string;
10
+ targetBranch: string;
11
+ };
File without changes
@@ -0,0 +1 @@
1
+ export declare function createDependenceMap(usingFilePaths: string[], parsedAlias: Record<string, string>, absPathPrefix: string): any;
@@ -0,0 +1,82 @@
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/util/report_util/createDependenceMap.ts
30
+ var createDependenceMap_exports = {};
31
+ __export(createDependenceMap_exports, {
32
+ createDependenceMap: () => createDependenceMap
33
+ });
34
+ module.exports = __toCommonJS(createDependenceMap_exports);
35
+ var import_getAstKitByFilePath = __toESM(require("../ast_util/getAstKitByFilePath"));
36
+ var import_filePathResolver = require("../ast_util/filePathResolver");
37
+ function createDependenceMap(usingFilePaths, parsedAlias, absPathPrefix) {
38
+ const usingFileNoPrefix = usingFilePaths.map((item) => item.replace(absPathPrefix, ""));
39
+ const localAlias = Object.fromEntries(Object.entries(parsedAlias).map(([k, v]) => [k, v.startsWith(absPathPrefix) ? v.replace(absPathPrefix, "") : v]));
40
+ const mapFilePathToDependenceDetail = /* @__PURE__ */ new Map();
41
+ usingFilePaths.map((absFilePath, index) => {
42
+ const { mapUuidToNode } = (0, import_getAstKitByFilePath.default)(absFilePath, absPathPrefix, (travelNode) => ["ImportDeclaration", "ExportAllDeclaration", "ExportNamedDeclaration", "ExportDefaultDeclaration"].includes(travelNode.type));
43
+ const programNode = mapUuidToNode.get("Program");
44
+ if (!programNode) {
45
+ return;
46
+ }
47
+ const { importedMember, exportedMember } = programNode._util;
48
+ const currentFilePath = absFilePath.replace(absPathPrefix, "");
49
+ const { importedMap, exportedMap } = mapFilePathToDependenceDetail.set(currentFilePath, mapFilePathToDependenceDetail.get(currentFilePath) || {
50
+ importedMap: /* @__PURE__ */ new Map(),
51
+ exportedMap: /* @__PURE__ */ new Map()
52
+ }).get(currentFilePath);
53
+ for (const { sourcePath, members } of importedMember) {
54
+ const { fullPath, isExternal } = (0, import_filePathResolver.resolveImportPath)(localAlias, sourcePath, currentFilePath);
55
+ const finalSourcePath = isExternal ? sourcePath : (fullPath == null ? void 0 : fullPath.find((p) => usingFileNoPrefix.includes(p))) || sourcePath;
56
+ const importedMemberDetail = importedMap.set(finalSourcePath, importedMap.get(finalSourcePath) || []).get(finalSourcePath);
57
+ for (const { importedName: imported, localName: local } of members) {
58
+ importedMemberDetail.push({ imported, local });
59
+ }
60
+ }
61
+ for (const { sourcePath, members, ExportAllDeclaration } of exportedMember) {
62
+ const { fullPath, isExternal } = (0, import_filePathResolver.resolveImportPath)(localAlias, sourcePath, currentFilePath);
63
+ const finalSourcePath = isExternal ? sourcePath : (fullPath == null ? void 0 : fullPath.find((p) => usingFileNoPrefix.includes(p))) || sourcePath;
64
+ const exportedMemberDetail = exportedMap.set(finalSourcePath, exportedMap.get(finalSourcePath) || []).get(finalSourcePath);
65
+ for (const { exportedName: exported, localName: local } of members) {
66
+ exportedMemberDetail.push({ exported, local });
67
+ }
68
+ if (ExportAllDeclaration) {
69
+ exportedMemberDetail.push({ exported: "*", local: "*" });
70
+ }
71
+ }
72
+ });
73
+ const list = Array.from(mapFilePathToDependenceDetail.entries()).map(([k, v]) => {
74
+ const { importedMap, exportedMap } = v;
75
+ return [k, { importedMap: Object.fromEntries(importedMap.entries()), exportedMap: Object.fromEntries(exportedMap.entries()) }];
76
+ });
77
+ return Object.fromEntries(list);
78
+ }
79
+ // Annotate the CommonJS export names for ESM import in node:
80
+ 0 && (module.exports = {
81
+ createDependenceMap
82
+ });
@@ -40,7 +40,7 @@ function reportItemToMd(report) {
40
40
  `## ${filePath}`,
41
41
  `### 类型: ${mapReportType[type]}`,
42
42
  filesDependsOnMe.length > 0 ? `### 所影响的文件
43
- ${filesDependsOnMe.slice(0, 1).map((files) => files.map((file) => `- ${file}`)).flat().join("\n")}` : "",
43
+ ${filesDependsOnMe.map((file) => `- ${file}`).join("\n")}` : "",
44
44
  undefinedIdentifiers.length > 0 ? `### 未定义的变量
45
45
  > ${undefinedIdentifiers.map((e) => `**${e}**`).join(", ")}` : "",
46
46
  // todo 拿到具体的节点 对应的 文本
@@ -1,6 +1,8 @@
1
+ var __create = Object.create;
1
2
  var __defProp = Object.defineProperty;
2
3
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
4
6
  var __hasOwnProp = Object.prototype.hasOwnProperty;
5
7
  var __export = (target, all) => {
6
8
  for (var name in all)
@@ -14,6 +16,14 @@ var __copyProps = (to, from, except, desc) => {
14
16
  }
15
17
  return to;
16
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
+ ));
17
27
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
28
 
19
29
  // src/util/report_util/generateGitDiffReport.ts
@@ -29,7 +39,9 @@ var import_format_git_diff_content = require("../format_git_diff_content");
29
39
  var import_utils = require("@umijs/utils");
30
40
  var import_report_util = require("../report_util");
31
41
  var import_createMdByJson = require("./createMdByJson");
32
- var MADGE_NAME = "madge";
42
+ var import_getMadgeInstance = require("./getMadgeInstance");
43
+ var import_createDependenceMap = require("./createDependenceMap");
44
+ var import_dayjs = __toESM(require("dayjs"));
33
45
  var userAliasGetter = (cwd, appData) => {
34
46
  var _a;
35
47
  return ((_a = appData.config) == null ? void 0 : _a.alias) || {
@@ -45,7 +57,6 @@ async function generateGitDiffReport(arg) {
45
57
  const absSrcPath = (0, import_path.join)(targetDirPath, "src");
46
58
  const diff_txt = (0, import_fs.readFileSync)((0, import_path.join)(targetDirPath, import__.gitDiffFileName), "utf-8");
47
59
  const gitDiffDetail = (0, import_format_git_diff_content.formatGitDiffContent)(diff_txt);
48
- (0, import_fs.writeFileSync)((0, import_path.join)(targetDirPath, import__.gitDiffJsonName), JSON.stringify(gitDiffDetail, null, 2), { encoding: "utf-8", flag: "w" });
49
60
  const tsconfig = await import_utils.tsconfigPaths.loadConfig(targetDirPath);
50
61
  const appDataContent = (0, import_fs.readFileSync)((0, import_path.join)(targetDirPath, "src", ".umi", "appData.json"), "utf-8");
51
62
  let appData = { config: null };
@@ -83,61 +94,27 @@ async function generateGitDiffReport(arg) {
83
94
  {}
84
95
  );
85
96
  const devTmpDir = (0, import_path.join)(absSrcPath, ".umi");
86
- const exportsFile = (0, import_path.join)(devTmpDir, "exports.ts");
87
- const madgePkg = (0, import_path.dirname)(
88
- import_utils.resolve.sync(`${MADGE_NAME}/package.json`, {
89
- basedir: process.cwd()
90
- })
91
- );
92
- const madge = require(madgePkg);
93
- const madgeConfig = {
94
- tsConfig: {
95
- compilerOptions: {
96
- baseUrl: targetDirPath,
97
- paths: {
98
- ...filteredAlias,
99
- ...tsconfig.paths,
100
- umi: [exportsFile],
101
- "@umijs/max": [exportsFile]
102
- },
103
- target: "esnext",
104
- module: "esnext",
105
- moduleResolution: "node",
106
- importHelpers: true,
107
- jsx: "react-jsx",
108
- esModuleInterop: true,
109
- strict: true,
110
- resolveJsonModule: true,
111
- allowSyntheticDefaultImports: true
112
- }
113
- },
114
- fileExtensions: ["ts", "tsx", "js", "jsx"],
115
- excludeRegExp: exclude,
116
- baseDir: targetDirPath
117
- };
118
- const res = await madge((0, import_path.join)(devTmpDir, "umi.ts"), madgeConfig);
119
- const treeMap = res.tree;
120
- const dependenceMap = Object.keys(treeMap).reduce(
121
- (acc, key) => {
122
- const path = (0, import_utils.winPath)((0, import_path.join)(targetDirPath, key));
123
- acc[path] = true;
124
- return acc;
125
- },
126
- {}
127
- );
128
- const usingFiles = (0, import_utils.readDirFiles)({
129
- dir: absSrcPath,
130
- exclude
131
- }).filter(({ filePath }) => dependenceMap[filePath]);
97
+ const res = await (0, import_getMadgeInstance.getMadgeInstance)(devTmpDir, targetDirPath, exclude, filteredAlias, tsconfig);
132
98
  const tree = res.tree;
133
99
  const absPathPrefix = targetDirPath + "/";
134
- const usingFileNoPrefix = usingFiles.map((item) => item.filePath.replace(absPathPrefix, ""));
100
+ const usingFileNoPrefix = Object.keys(tree);
101
+ const usingFilePaths = usingFileNoPrefix.map((item) => (0, import_utils.winPath)((0, import_path.join)(absPathPrefix, item)));
135
102
  const groupGitDiffLines = gitDiffDetail.filter((item) => usingFileNoPrefix.includes(item.filePath));
136
- (0, import_fs.writeFileSync)((0, import_path.join)(targetDirPath, "reports_helper.json"), JSON.stringify({ groupGitDiffLines, absPathPrefix, tree, filteredAlias, parsedAlias, tsconfig, madgeConfig }, null, 2), { encoding: "utf-8", flag: "w" });
103
+ const changedFilePaths = groupGitDiffLines.map((item) => item.filePath);
104
+ const time = (0, import_dayjs.default)().format("YYYYMDD_HHmm");
105
+ try {
106
+ const dependenceJson = (0, import_createDependenceMap.createDependenceMap)(usingFilePaths, parsedAlias, absPathPrefix);
107
+ (0, import_fs.writeFileSync)((0, import_path.join)(targetDirPath, "..", "..", `${time}_dependence_map.json`), JSON.stringify(dependenceJson, null, 2), { encoding: "utf-8", flag: "w" });
108
+ const partialDependenceJson = Object.fromEntries(changedFilePaths.map((p) => [p, dependenceJson[p]]));
109
+ (0, import_fs.writeFileSync)((0, import_path.join)(targetDirPath, "..", "..", `${time}_partial_dependence_map.json`), JSON.stringify(partialDependenceJson, null, 2), { encoding: "utf-8", flag: "w" });
110
+ } catch (e) {
111
+ console.warn("dependenceJson 生成失败", e);
112
+ }
113
+ (0, import_fs.writeFileSync)((0, import_path.join)(targetDirPath, "..", "..", `${time}_reports_helper.json`), JSON.stringify({ usingFilePaths, groupGitDiffLines, absPathPrefix, tree, filteredAlias, parsedAlias, tsconfig }, null, 2), { encoding: "utf-8", flag: "w" });
137
114
  const reports = (0, import_report_util.createDetectReport)({ groupGitDiffLines, tree, absPathPrefix });
138
- (0, import_fs.writeFileSync)((0, import_path.join)(targetDirPath, "reports.json"), JSON.stringify(reports, null, 2), { encoding: "utf-8", flag: "w" });
115
+ (0, import_fs.writeFileSync)((0, import_path.join)(targetDirPath, "..", "..", `${time}_reports.json`), JSON.stringify(reports, null, 2), { encoding: "utf-8", flag: "w" });
139
116
  const mdContent = (0, import_createMdByJson.createMdByJson)(reports);
140
- (0, import_fs.writeFileSync)((0, import_path.join)(targetDirPath, reportFileName), mdContent, { encoding: "utf-8", flag: "w" });
117
+ (0, import_fs.writeFileSync)((0, import_path.join)(targetDirPath, "..", "..", `${time}_${reportFileName}`), mdContent, { encoding: "utf-8", flag: "w" });
141
118
  }
142
119
  // Annotate the CommonJS export names for ESM import in node:
143
120
  0 && (module.exports = {
@@ -1 +1,6 @@
1
- export declare function getMadgeInstance(devTmpDir: string, targetDirPath: string, exclude: RegExp[], filteredAlias: Record<string, string[]>, tsconfig?: any): Promise<void>;
1
+ import { MadgeInstance } from "madge";
2
+ interface IMadgeInstance extends MadgeInstance {
3
+ tree: Record<string, string[]>;
4
+ }
5
+ export declare function getMadgeInstance(devTmpDir: string, targetDirPath: string, exclude: RegExp[], filteredAlias: Record<string, string[]>, tsconfig?: any): Promise<IMadgeInstance>;
6
+ export {};
@@ -36,7 +36,7 @@ async function getMadgeInstance(devTmpDir, targetDirPath, exclude, filteredAlias
36
36
  const madgeConfig = {
37
37
  tsConfig: {
38
38
  compilerOptions: {
39
- baseUrl: tsconfig.baseUrl,
39
+ baseUrl: targetDirPath,
40
40
  paths: {
41
41
  ...filteredAlias,
42
42
  ...tsconfig.paths,
@@ -59,6 +59,7 @@ async function getMadgeInstance(devTmpDir, targetDirPath, exclude, filteredAlias
59
59
  baseDir: targetDirPath
60
60
  };
61
61
  const res = await madge((0, import_path.join)(devTmpDir, "umi.ts"), madgeConfig);
62
+ return res;
62
63
  }
63
64
  // Annotate the CommonJS export names for ESM import in node:
64
65
  0 && (module.exports = {
@@ -4,7 +4,7 @@ import { BlockReportItem } from "./report_util/diffBlockDetect";
4
4
  export type DetectReport = {
5
5
  filePath: string;
6
6
  type: "modify" | "add" | "delete";
7
- filesDependsOnMe: string[][];
7
+ filesDependsOnMe: string[];
8
8
  undefinedIdentifiers: string[];
9
9
  dangerIdentifiers: string[];
10
10
  _fileAddedNodesPaths: {
@@ -35,8 +35,8 @@ export declare function createDetectReport(arg: Arg): {
35
35
  effectsDownstream: string[];
36
36
  }[];
37
37
  }[];
38
- type: "modify" | "add" | "delete";
39
- filesDependsOnMe: string[][];
38
+ type: "add" | "delete" | "modify";
39
+ filesDependsOnMe: string[];
40
40
  undefinedIdentifiers: string[];
41
41
  filePath: string;
42
42
  }[];
@@ -34,7 +34,6 @@ __export(report_util_exports, {
34
34
  module.exports = __toCommonJS(report_util_exports);
35
35
  var import_AstUtil = __toESM(require("./ast_util/AstUtil"));
36
36
  var import_file_identifier_detect = require("./report_util/file_identifier_detect");
37
- var import_getFileDepends = __toESM(require("./report_util/getFileDepends"));
38
37
  var import_diffBlockDetect = require("./report_util/diffBlockDetect");
39
38
  var import_path = require("path");
40
39
  function createDetectReport(arg) {
@@ -42,7 +41,7 @@ function createDetectReport(arg) {
42
41
  const reports = [];
43
42
  groupGitDiffLines.forEach((item, index) => {
44
43
  const { filePath, type } = item;
45
- const filesDependsOnMe = (0, import_getFileDepends.default)(filePath, tree);
44
+ const filesDependsOnMe = tree[filePath] || [];
46
45
  let reportItem = reports.find((e) => e.filePath === filePath);
47
46
  if (!reportItem) {
48
47
  reportItem = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "js-code-detector",
3
- "version": "0.0.23",
3
+ "version": "0.0.25",
4
4
  "description": "",
5
5
  "main": "dist/cjs/index.js",
6
6
  "types": "dist/cjs/index.d.ts",
@@ -21,7 +21,6 @@
21
21
  "bin"
22
22
  ],
23
23
  "bin": {
24
- "detect": "bin/detect.js",
25
24
  "gitDiffDetect": "bin/gitDiffDetect.js",
26
25
  "sameCodeDetect": "bin/sameCodeDetect.js"
27
26
  },
package/bin/detect.js DELETED
@@ -1,8 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
- const { writeGitDiffTxt, getGitRepositoryAndBranch, generateReport } = require('../dist/cjs/index')
4
- async function main() {
5
- const { gitUrl, branchName } = await getGitRepositoryAndBranch();
6
- writeGitDiffTxt(gitUrl, branchName).then(reportContent => generateReport(reportContent));
7
- }
8
- main();