js-code-detector 0.0.57 → 0.0.59

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.
Files changed (26) hide show
  1. package/dist/cjs/index.d.ts +12 -3
  2. package/dist/cjs/services/DetectService.d.ts +2 -2
  3. package/dist/cjs/services/ProjectService.d.ts +2 -0
  4. package/dist/cjs/services/projectServiceClass/UmiProjectService.js +7 -3
  5. package/dist/cjs/services/projectServiceClass/ViteProjectService.js +4 -2
  6. package/dist/cjs/services/projectServiceClass/VueProjectService.js +6 -5
  7. package/dist/cjs/util/ast_util/AstUtil.d.ts +1 -0
  8. package/dist/cjs/util/ast_util/helper/createAstNodeExt.d.ts +2 -1
  9. package/dist/cjs/util/ast_util/helper/findNoMatchExportMember.d.ts +9 -0
  10. package/dist/cjs/util/ast_util/helper/findNoMatchExportMember.js +38 -0
  11. package/dist/cjs/util/ast_util/helper/findOrCreateImportedMember.d.ts +1 -0
  12. package/dist/cjs/util/ast_util/helper/getEffectedExportMembersOfLineRange.js +7 -9
  13. package/dist/cjs/util/ast_util/helper/syncTravel.js +13 -2
  14. package/dist/cjs/util/ast_util/helper/updateImportedAndExportedMember.js +19 -16
  15. package/dist/cjs/util/report_util/createDependenceMap.d.ts +9 -0
  16. package/dist/cjs/util/report_util/createDependenceMap.js +9 -1
  17. package/dist/cjs/util/report_util/create_mmd.d.ts +2 -0
  18. package/dist/cjs/util/report_util/create_mmd.js +32 -0
  19. package/dist/cjs/util/report_util/filterEffectedCode.d.ts +1 -1
  20. package/dist/cjs/util/report_util/generateGitDiffReport.d.ts +10 -1
  21. package/dist/cjs/util/report_util/generateGitDiffReport.js +2 -1
  22. package/dist/cjs/util/report_util/mmd_html.d.ts +1 -0
  23. package/dist/cjs/util/report_util/mmd_html.js +39 -0
  24. package/dist/cjs/util/report_util.d.ts +1 -1
  25. package/dist/cjs/util/shared/gitDiffTool.d.ts +10 -1
  26. package/package.json +1 -1
@@ -1,6 +1,15 @@
1
1
  export declare function sameCodeDetect(dirOfCwd?: string): Promise<void>;
2
2
  export declare function gitDiffDetect(): Promise<{
3
3
  dependenceJson: {
4
+ noMatchExportMembers: {
5
+ file: string;
6
+ member: string;
7
+ useless: boolean;
8
+ from: {
9
+ file: string;
10
+ member: string;
11
+ };
12
+ }[];
4
13
  import2export: Record<string, string>;
5
14
  export2export: Record<string, string>;
6
15
  mapFilePathToExportAllSources: Record<string, string[]>;
@@ -20,7 +29,7 @@ export declare function gitDiffDetect(): Promise<{
20
29
  effectsDownstream: string[];
21
30
  }[];
22
31
  }[];
23
- type: "delete" | "modify" | "add";
32
+ type: "add" | "delete" | "modify";
24
33
  filesDependsOnMe: string[];
25
34
  undefinedIdentifiers: string[];
26
35
  filePath: string;
@@ -30,6 +39,6 @@ export { isRepoTypeSupported } from "./util/shared/getRepoSupportFlag";
30
39
  export declare function runDiffDetect(compareUrl?: string, token?: string): Promise<{
31
40
  error: Error | null;
32
41
  repoType: string;
33
- effectedImportUsage: [string, string][];
34
- relatedExportUsage: import("src/util/ast_util/helper/findRelateUsageOfExport").RelateUsageOfExport[];
42
+ effectedImportUsage: never[] | [string, string][];
43
+ relatedExportUsage: never[] | import("src/util/ast_util/helper/findRelateUsageOfExport").RelateUsageOfExport[];
35
44
  }>;
@@ -32,7 +32,7 @@ export declare class DetectService {
32
32
  formatResult(): {
33
33
  error: Error | null;
34
34
  repoType: string;
35
- effectedImportUsage: [string, string][];
36
- relatedExportUsage: import("src/util/ast_util/helper/findRelateUsageOfExport").RelateUsageOfExport[];
35
+ effectedImportUsage: never[] | [string, string][];
36
+ relatedExportUsage: never[] | import("src/util/ast_util/helper/findRelateUsageOfExport").RelateUsageOfExport[];
37
37
  };
38
38
  }
@@ -1,6 +1,7 @@
1
1
  import { DetectService } from "./DetectService";
2
2
  import { formatGitDiffContent } from "../util/format_git_diff_content";
3
3
  import { RelateUsageOfExport } from "../util/ast_util/helper/findRelateUsageOfExport";
4
+ import findNoMatchExportMember from "../util/ast_util/helper/findNoMatchExportMember";
4
5
  export interface ProjectService {
5
6
  detectService: DetectService;
6
7
  gitDiffDetail: ReturnType<typeof formatGitDiffContent>;
@@ -12,6 +13,7 @@ export interface ProjectService {
12
13
  effectedImportUsage: [string, string][];
13
14
  error: Error | null;
14
15
  relatedExportUsage: RelateUsageOfExport[];
16
+ noMatchExportMembers: ReturnType<typeof findNoMatchExportMember>;
15
17
  };
16
18
  run(): void;
17
19
  }
@@ -41,6 +41,8 @@ var import_createDependenceMap = require("../../util/report_util/createDependenc
41
41
  var import_filterEffectedExportMember = __toESM(require("../../util/report_util/filterEffectedExportMember"));
42
42
  var import_constants = require("../../util/constants");
43
43
  var import_findRelateUsageOfExport = __toESM(require("../../util/ast_util/helper/findRelateUsageOfExport"));
44
+ var import_create_mmd = __toESM(require("../../util/report_util/create_mmd"));
45
+ var import_mmd_html = __toESM(require("../../util/report_util/mmd_html"));
44
46
  var UmiProjectService = class {
45
47
  constructor(detectService) {
46
48
  this.detectService = detectService;
@@ -50,6 +52,7 @@ var UmiProjectService = class {
50
52
  parsedAlias: {}
51
53
  };
52
54
  this.outputResult = {
55
+ noMatchExportMembers: [],
53
56
  relatedExportUsage: [],
54
57
  effectedImportUsage: [],
55
58
  error: null
@@ -85,13 +88,12 @@ var UmiProjectService = class {
85
88
  return acc;
86
89
  }, []);
87
90
  const possibleEffectedFiles = (0, import_collectUpstreamFiles.default)(madgeResult, validModifiedFiles);
88
- const possibleEffectedFilesFullPath = possibleEffectedFiles.map((file) => (0, import_path.join)(absPathPrefix, file));
89
- const { import2export, indirectExportMembers } = (0, import_createDependenceMap.createExportedNameToReferenceLocalSet)(possibleEffectedFilesFullPath, parsedAlias, absPathPrefix, projectFileList);
91
+ const { import2export, indirectExportMembers, noMatchExportMembers } = (0, import_createDependenceMap.createExportedNameToReferenceLocalSet)(projectFileList.map((file) => (0, import_path.join)(absPathPrefix, file)), parsedAlias, absPathPrefix, projectFileList);
90
92
  const gitDiffDetail = this.gitDiffDetail;
91
93
  const validGitDiffDetail = gitDiffDetail.filter((item) => possibleEffectedFiles.includes(item.filePath));
92
94
  const effectedExportNames = validGitDiffDetail.map((item) => {
93
95
  const { filePath, newBranchLineScope, startLineOfNew } = item;
94
- const exportedNames = (0, import_filterEffectedExportMember.default)((0, import_path.join)(absPathPrefix, filePath), absPathPrefix, Number(startLineOfNew), Number(startLineOfNew) + Number(newBranchLineScope));
96
+ const exportedNames = (0, import_filterEffectedExportMember.default)((0, import_path.join)(absPathPrefix, filePath), absPathPrefix, Number(startLineOfNew), Number(startLineOfNew) + Number(newBranchLineScope) - 1);
95
97
  return exportedNames.map((name) => [filePath, name].join("#"));
96
98
  }).flat();
97
99
  const effectedImportUsage = [...Object.entries(import2export), ...Object.entries(indirectExportMembers)].filter(([_, value]) => {
@@ -100,10 +102,12 @@ var UmiProjectService = class {
100
102
  this.outputResult.effectedImportUsage = effectedImportUsage;
101
103
  const effectedImportUsageUnique = [...new Set(effectedImportUsage.map((item) => item[0]))].map((importFileAndMember) => importFileAndMember.split("#"));
102
104
  this.outputResult.relatedExportUsage = (0, import_findRelateUsageOfExport.default)(effectedImportUsageUnique, import2export, indirectExportMembers, absPathPrefix);
105
+ this.outputResult.noMatchExportMembers = noMatchExportMembers;
103
106
  const token = this.detectService.gitInfo.token;
104
107
  if (!token) {
105
108
  const pwd = (0, import_path.join)(this.detectService.directoryInfo.tmpWorkDir, "..");
106
109
  (0, import_fs.writeFileSync)((0, import_path.join)(pwd, "effectedImportUsage.json"), JSON.stringify({ tree: madgeResult == null ? void 0 : madgeResult.tree, projectFileList, possibleEffectedFiles, gitDiffDetailFiles: gitDiffDetail.map((e) => e.filePath), validGitDiffDetail, ...this.outputResult }, null, 2));
110
+ (0, import_mmd_html.default)((0, import_path.join)(pwd, "relation.html"), (0, import_create_mmd.default)(this.outputResult.relatedExportUsage));
107
111
  }
108
112
  }
109
113
  };
@@ -53,6 +53,7 @@ var ViteProjectService = class {
53
53
  parsedAlias: {}
54
54
  };
55
55
  this.outputResult = {
56
+ noMatchExportMembers: [],
56
57
  relatedExportUsage: [],
57
58
  effectedImportUsage: [],
58
59
  error: null
@@ -123,12 +124,12 @@ var ViteProjectService = class {
123
124
  const possibleEffectedFiles = (0, import_collectUpstreamFiles.default)(madgeResult, validModifiedFiles);
124
125
  const possibleEffectedFilesFullPath = possibleEffectedFiles.map((file) => (0, import_path.join)(absPathPrefix, file));
125
126
  const mapRef = (0, import_createDependenceMap.createExportedNameToReferenceLocalSet)(possibleEffectedFilesFullPath, parsedAlias, absPathPrefix, projectFileList);
126
- const { import2export, indirectExportMembers } = mapRef;
127
+ const { import2export, indirectExportMembers, noMatchExportMembers } = mapRef;
127
128
  const gitDiffDetail = this.gitDiffDetail;
128
129
  const validGitDiffDetail = gitDiffDetail.filter((item) => possibleEffectedFiles.includes(item.filePath));
129
130
  const effectedExportNames = validGitDiffDetail.map((item) => {
130
131
  const { filePath, newBranchLineScope, startLineOfNew } = item;
131
- const exportedNames = (0, import_filterEffectedExportMember.default)((0, import_path.join)(absPathPrefix, filePath), absPathPrefix, Number(startLineOfNew), Number(startLineOfNew) + Number(newBranchLineScope));
132
+ const exportedNames = (0, import_filterEffectedExportMember.default)((0, import_path.join)(absPathPrefix, filePath), absPathPrefix, Number(startLineOfNew), Number(startLineOfNew) + Number(newBranchLineScope) - 1);
132
133
  return exportedNames.map((name) => [filePath, name].join("#"));
133
134
  }).flat();
134
135
  const effectedImportUsage = [...Object.entries(import2export), ...Object.entries(indirectExportMembers)].filter(([_, value]) => {
@@ -137,6 +138,7 @@ var ViteProjectService = class {
137
138
  this.outputResult.effectedImportUsage = effectedImportUsage;
138
139
  const effectedImportUsageUnique = [...new Set(effectedImportUsage.map((item) => item[0]))].map((importFileAndMember) => importFileAndMember.split("#"));
139
140
  this.outputResult.relatedExportUsage = (0, import_findRelateUsageOfExport.default)(effectedImportUsageUnique, import2export, indirectExportMembers, absPathPrefix);
141
+ this.outputResult.noMatchExportMembers = noMatchExportMembers;
140
142
  const token = this.detectService.gitInfo.token;
141
143
  if (!token) {
142
144
  const pwd = (0, import_path.join)(this.detectService.directoryInfo.tmpWorkDir, "..");
@@ -52,6 +52,7 @@ var VueProjectService = class {
52
52
  parsedAlias: {}
53
53
  };
54
54
  this.outputResult = {
55
+ noMatchExportMembers: [],
55
56
  relatedExportUsage: [],
56
57
  effectedImportUsage: [],
57
58
  error: null
@@ -196,14 +197,13 @@ var VueProjectService = class {
196
197
  return acc;
197
198
  }, []);
198
199
  const possibleEffectedFiles = (0, import_collectUpstreamFiles.default)(madgeResult, validModifiedFiles);
199
- const possibleEffectedFilesFullPath = possibleEffectedFiles.map((file) => (0, import_path.join)(absPathPrefix, file));
200
- const mapRef = (0, import_createDependenceMap.createExportedNameToReferenceLocalSet)(possibleEffectedFilesFullPath, parsedAlias, absPathPrefix, projectFileList);
201
- const { import2export, indirectExportMembers } = mapRef;
200
+ const mapRef = (0, import_createDependenceMap.createExportedNameToReferenceLocalSet)(projectFileList.map((file) => (0, import_path.join)(absPathPrefix, file)), parsedAlias, absPathPrefix, projectFileList);
201
+ const { import2export, indirectExportMembers, noMatchExportMembers } = mapRef;
202
202
  const gitDiffDetail = this.gitDiffDetail;
203
203
  const validGitDiffDetail = gitDiffDetail.filter((item) => possibleEffectedFiles.includes(item.filePath));
204
204
  const effectedExportNames = validGitDiffDetail.map((item) => {
205
205
  const { filePath, newBranchLineScope, startLineOfNew } = item;
206
- const exportedNames = (0, import_filterEffectedExportMember.default)((0, import_path.join)(absPathPrefix, filePath), absPathPrefix, Number(startLineOfNew), Number(startLineOfNew) + Number(newBranchLineScope));
206
+ const exportedNames = (0, import_filterEffectedExportMember.default)((0, import_path.join)(absPathPrefix, filePath), absPathPrefix, Number(startLineOfNew), Number(startLineOfNew) + Number(newBranchLineScope) - 1);
207
207
  return exportedNames.map((name) => [filePath, name].join("#"));
208
208
  }).flat();
209
209
  const effectedImportUsage = [...Object.entries(import2export), ...Object.entries(indirectExportMembers)].filter(([_, value]) => {
@@ -212,10 +212,11 @@ var VueProjectService = class {
212
212
  this.outputResult.effectedImportUsage = effectedImportUsage;
213
213
  const effectedImportUsageUnique = [...new Set(effectedImportUsage.map((item) => item[0]))].map((importFileAndMember) => importFileAndMember.split("#"));
214
214
  this.outputResult.relatedExportUsage = (0, import_findRelateUsageOfExport.default)(effectedImportUsageUnique, import2export, indirectExportMembers, absPathPrefix);
215
+ this.outputResult.noMatchExportMembers = noMatchExportMembers;
215
216
  const token = this.detectService.gitInfo.token;
216
217
  if (!token) {
217
218
  const pwd = (0, import_path.join)(this.detectService.directoryInfo.tmpWorkDir, "..");
218
- (0, import_fs.writeFileSync)((0, import_path.join)(pwd, "effectedImportUsage.json"), JSON.stringify({ webpackConfig: this.createSimpleWebpackConfig(), tree: madgeResult == null ? void 0 : madgeResult.tree, projectFileList, possibleEffectedFiles, gitDiffDetailFiles: gitDiffDetail.map((e) => e.filePath), validGitDiffDetail, ...this.outputResult, ...mapRef }, null, 2));
219
+ (0, import_fs.writeFileSync)((0, import_path.join)(pwd, "effectedImportUsage.json"), JSON.stringify({ webpackConfig: this.createSimpleWebpackConfig(), tree: madgeResult == null ? void 0 : madgeResult.tree, projectFileList, possibleEffectedFiles, gitDiffDetailFiles: gitDiffDetail.map((e) => e.filePath), validGitDiffDetail, ...this.outputResult, ...mapRef, noMatchExportMembers }, null, 2));
219
220
  }
220
221
  }
221
222
  };
@@ -38,6 +38,7 @@ export interface AstNode {
38
38
  members: {
39
39
  importedName: string;
40
40
  localName: string;
41
+ useless?: boolean;
41
42
  }[];
42
43
  }[];
43
44
  exportedMember: {
@@ -17,7 +17,7 @@ export default function createAstNodeExt(ext: Partial<AstNode['_util']>): {
17
17
  dependenceIdsNoScope: Set<AstNode>;
18
18
  holdingIds: Set<AstNode>;
19
19
  holdingIdNameMap: Map<string, Set<AstNode>>;
20
- holdingIdType: "Import" | "Variable" | "Function" | "Class" | "Param" | "Enum" | "Interface" | "TypeAlias" | null;
20
+ holdingIdType: "Import" | "TypeAlias" | "Function" | "Variable" | "Class" | "Param" | "Enum" | "Interface" | null;
21
21
  inject: Set<AstNode>;
22
22
  provide: Set<AstNode>;
23
23
  effectIds: Set<AstNode>;
@@ -27,6 +27,7 @@ export default function createAstNodeExt(ext: Partial<AstNode['_util']>): {
27
27
  members: {
28
28
  importedName: string;
29
29
  localName: string;
30
+ useless?: boolean | undefined;
30
31
  }[];
31
32
  }[];
32
33
  exportedMember: {
@@ -0,0 +1,9 @@
1
+ export default function findNoMatchExportMember(import2export: Record<string, string>, export2export: Record<string, string>, uselessImportMembers: string[]): {
2
+ file: string;
3
+ member: string;
4
+ useless: boolean;
5
+ from: {
6
+ file: string;
7
+ member: string;
8
+ };
9
+ }[];
@@ -0,0 +1,38 @@
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/helper/findNoMatchExportMember.ts
20
+ var findNoMatchExportMember_exports = {};
21
+ __export(findNoMatchExportMember_exports, {
22
+ default: () => findNoMatchExportMember
23
+ });
24
+ module.exports = __toCommonJS(findNoMatchExportMember_exports);
25
+ function findNoMatchExportMember(import2export, export2export, uselessImportMembers) {
26
+ const missingExportOfImport = Object.entries(import2export).filter(([, ele]) => ele.startsWith("src/") && !ele.endsWith("#*") && !export2export[ele]);
27
+ return missingExportOfImport.map(([importFileAndMember, exportFileAndMember]) => {
28
+ return {
29
+ file: importFileAndMember.split("#")[0],
30
+ member: importFileAndMember.split("#")[1],
31
+ useless: uselessImportMembers.includes(importFileAndMember),
32
+ from: {
33
+ file: exportFileAndMember.split("#")[0],
34
+ member: exportFileAndMember.split("#")[1]
35
+ }
36
+ };
37
+ });
38
+ }
@@ -4,5 +4,6 @@ export default function findOrCreateImportedMember(importedMember: AstNode['_uti
4
4
  members: {
5
5
  importedName: string;
6
6
  localName: string;
7
+ useless?: boolean | undefined;
7
8
  }[];
8
9
  };
@@ -105,15 +105,13 @@ function getEffectedExportMembersOfLineRange(mapFileLineToNodeSet, startLine, en
105
105
  }
106
106
  }
107
107
  if (type === "ExportNamedDeclaration" && Array.isArray(declaration == null ? void 0 : declaration.declarations)) {
108
- declaration == null ? void 0 : declaration.declarations.forEach((dec) => {
109
- (0, import_collectVariableDeclarationIdentifiers.default)(dec, (identifier) => {
110
- try {
111
- const idName = identifier.name;
112
- typeof idName === "string" && effectedExportMembers.add(idName);
113
- } catch (e) {
114
- console.log("getEffectedExportMembersOfLineRange", e.message);
115
- }
116
- });
108
+ (0, import_collectVariableDeclarationIdentifiers.default)(declaration, (identifier) => {
109
+ try {
110
+ const idName = identifier.name;
111
+ typeof idName === "string" && effectedExportMembers.add(idName);
112
+ } catch (e) {
113
+ console.log("getEffectedExportMembersOfLineRange", e.message);
114
+ }
117
115
  });
118
116
  }
119
117
  }
@@ -40,6 +40,7 @@ var import_deepSearchParamsIdentifier = __toESM(require("./deepSearchParamsIdent
40
40
  var import_updateImportedAndExportedMember = __toESM(require("./updateImportedAndExportedMember"));
41
41
  var import_updateLoc = __toESM(require("./updateLoc"));
42
42
  var import_intrinsicElements = require("../intrinsicElements");
43
+ var import_windowProperties = require("../windowProperties");
43
44
  function syncTravel(astNode, extra, travelFn) {
44
45
  if (!astNode)
45
46
  return;
@@ -54,6 +55,7 @@ function syncTravel(astNode, extra, travelFn) {
54
55
  }
55
56
  }
56
57
  function wideTravel(wideTravelNodeList, extra, travelFn) {
58
+ var _a;
57
59
  const { visitedNodeSet, filePath } = extra;
58
60
  const wideTravelNodes = [];
59
61
  for (const wideTravelNode of wideTravelNodeList) {
@@ -128,6 +130,11 @@ function wideTravel(wideTravelNodeList, extra, travelFn) {
128
130
  importIdentifiers.forEach((identifier) => {
129
131
  identifier._util.holdingIdType = "Import";
130
132
  });
133
+ if (((_a = wideTravelNodeList[0]) == null ? void 0 : _a.type) === "Program") {
134
+ const program = wideTravelNodeList[0];
135
+ (0, import_updateLoc.default)(program, extra);
136
+ program.body.forEach((bodyElement) => (0, import_updateImportedAndExportedMember.default)(bodyElement, program));
137
+ }
131
138
  }
132
139
  function deepTravel(deepTravelNode, extra, travelFn) {
133
140
  const { upstreamIdentifiers } = extra;
@@ -303,11 +310,15 @@ function updateVariableScopeAndOccupation(deepTravelNode, holdingIdentifiers) {
303
310
  if (!valid) {
304
311
  return;
305
312
  }
313
+ const variableScope = [...deepTravelNode._util.holdingIdNameMap.get(nodeName) || []];
314
+ deepTravelNode._util.variableScope = variableScope;
315
+ const firstPick = deepTravelNode._util.variableScope[0];
316
+ const isGlobalVariable = !firstPick && deepTravelNode.type === "Identifier" && import_windowProperties.windowProperties.includes(nodeName);
306
317
  !holdingIdentifierSet.has(deepTravelNode) && deepTravelNode._util.ancestors.forEach((ancestor) => {
307
318
  ancestor._util.dependenceIds.add(deepTravelNode);
319
+ if (ancestor.type === "Program" && isGlobalVariable) {
320
+ }
308
321
  });
309
- deepTravelNode._util.variableScope = [...deepTravelNode._util.holdingIdNameMap.get(nodeName) || []];
310
- const firstPick = deepTravelNode._util.variableScope[0];
311
322
  if (firstPick && firstPick !== deepTravelNode) {
312
323
  if (firstPick._util) {
313
324
  if (!firstPick._util.occupation) {
@@ -44,26 +44,31 @@ function updateImportedAndExportedMember(node, programNode) {
44
44
  const { importedMember, exportedMember } = programNode._util;
45
45
  if (type === "ImportDeclaration") {
46
46
  specifiers.forEach((specifier) => {
47
+ var _a2, _b;
47
48
  const { local, imported } = specifier;
49
+ const extendInfo = !((_b = (_a2 = local._util) == null ? void 0 : _a2.occupation) == null ? void 0 : _b.size) ? { useless: true } : {};
48
50
  const target = (0, import_findOrCreateImportedMember.default)(importedMember, sourceValue);
49
51
  if (specifier.type === "ImportNamespaceSpecifier") {
50
52
  target.members.push({
51
53
  localName: local.name,
52
- importedName: "*"
54
+ importedName: "*",
55
+ ...extendInfo
53
56
  });
54
57
  return;
55
58
  }
56
59
  if (specifier.type === "ImportDefaultSpecifier") {
57
60
  target.members.push({
58
61
  localName: local.name,
59
- importedName: "default"
62
+ importedName: "default",
63
+ ...extendInfo
60
64
  });
61
65
  return;
62
66
  }
63
67
  if (specifier.type === "ImportSpecifier") {
64
68
  target.members.push({
65
69
  localName: local.name,
66
- importedName: imported.name
70
+ importedName: imported.name,
71
+ ...extendInfo
67
72
  });
68
73
  }
69
74
  });
@@ -94,19 +99,17 @@ function updateImportedAndExportedMember(node, programNode) {
94
99
  }
95
100
  });
96
101
  if (Array.isArray(declaration == null ? void 0 : declaration.declarations)) {
97
- declaration == null ? void 0 : declaration.declarations.forEach((dec) => {
98
- const target = (0, import_findOrCreateExportedMember.default)(exportedMember, sourceValue);
99
- (0, import_collectVariableDeclarationIdentifiers.default)(dec, (identifier) => {
100
- try {
101
- const idName = identifier.name;
102
- target.members.push({
103
- localName: idName,
104
- exportedName: idName
105
- });
106
- } catch (e) {
107
- console.log("declaration?.declarations.forEach", e.message);
108
- }
109
- });
102
+ const target = (0, import_findOrCreateExportedMember.default)(exportedMember, sourceValue);
103
+ (0, import_collectVariableDeclarationIdentifiers.default)(declaration, (identifier) => {
104
+ try {
105
+ const idName = identifier.name;
106
+ target.members.push({
107
+ localName: idName,
108
+ exportedName: idName
109
+ });
110
+ } catch (e) {
111
+ console.log("declaration?.declarations.forEach", e.message);
112
+ }
110
113
  });
111
114
  } else if (import_SHARED_CONSTANTS.EXPORT_DECLARATION_TYPES.includes(declaration == null ? void 0 : declaration.type)) {
112
115
  const target = (0, import_findOrCreateExportedMember.default)(exportedMember, sourceValue);
@@ -1,4 +1,13 @@
1
1
  export declare function createExportedNameToReferenceLocalSet(upstreamFileFullPaths: string[], parsedAlias: Record<string, string>, absPathPrefix: string, projectFilePaths: string[]): {
2
+ noMatchExportMembers: {
3
+ file: string;
4
+ member: string;
5
+ useless: boolean;
6
+ from: {
7
+ file: string;
8
+ member: string;
9
+ };
10
+ }[];
2
11
  import2export: Record<string, string>;
3
12
  export2export: Record<string, string>;
4
13
  mapFilePathToExportAllSources: Record<string, string[]>;
@@ -35,18 +35,21 @@ module.exports = __toCommonJS(createDependenceMap_exports);
35
35
  var import_getAstKitByFilePath = __toESM(require("../ast_util/getAstKitByFilePath"));
36
36
  var import_path = require("path");
37
37
  var import_resolveImportPath = __toESM(require("./resolveImportPath"));
38
+ var import_findNoMatchExportMember = __toESM(require("../ast_util/helper/findNoMatchExportMember"));
38
39
  function createExportedNameToReferenceLocalSet(upstreamFileFullPaths, parsedAlias, absPathPrefix, projectFilePaths) {
39
40
  const cwd = process.cwd();
40
41
  const systemAbsPathPrefix = absPathPrefix.startsWith(cwd) ? absPathPrefix : (0, import_path.join)(cwd, absPathPrefix);
41
42
  const localAlias = Object.fromEntries(Object.entries(parsedAlias).map(([k, v]) => [k, v.startsWith(systemAbsPathPrefix) ? v.replace(systemAbsPathPrefix, "") : v]));
42
43
  const import2export = {};
43
44
  const export2export = {};
45
+ const uselessImportMembers = [];
44
46
  const mapFilePathToExportAllSources = {};
45
47
  const validFiles = upstreamFileFullPaths.filter((e) => [".ts", ".tsx", ".js", ".jsx", ".vue"].some((ext) => e.endsWith(ext) && !e.endsWith(".d.ts")));
46
48
  for (const absFilePath of validFiles) {
47
49
  const { mapUuidToNode } = (0, import_getAstKitByFilePath.default)(absFilePath, absPathPrefix, (travelNode) => ["ImportDeclaration", "ExportAllDeclaration", "ExportNamedDeclaration", "ExportDefaultDeclaration"].includes(travelNode.type));
48
50
  const programNode = mapUuidToNode.get("Program");
49
51
  if (!programNode) {
52
+ console.log("no program node in file: " + absFilePath.replace(absPathPrefix, ""));
50
53
  continue;
51
54
  }
52
55
  const { importedMember, exportedMember } = programNode._util;
@@ -54,10 +57,13 @@ function createExportedNameToReferenceLocalSet(upstreamFileFullPaths, parsedAlia
54
57
  for (const { sourcePath, members } of importedMember) {
55
58
  const { fullPath, isExternal } = (0, import_resolveImportPath.default)(localAlias, sourcePath, relativeFilePath);
56
59
  const finalSourcePath = createRealSourcePath(sourcePath, isExternal, projectFilePaths, fullPath);
57
- for (const { importedName: imported, localName: local } of members) {
60
+ for (const { importedName: imported, localName: local, useless } of members) {
58
61
  const importLocal = `${relativeFilePath}#${local}`;
59
62
  const exportedName = `${finalSourcePath}#${imported}`;
60
63
  import2export[importLocal] = exportedName;
64
+ if (useless) {
65
+ uselessImportMembers.push(importLocal);
66
+ }
61
67
  }
62
68
  if (members.length === 0) {
63
69
  import2export[relativeFilePath] = finalSourcePath;
@@ -78,7 +84,9 @@ function createExportedNameToReferenceLocalSet(upstreamFileFullPaths, parsedAlia
78
84
  }
79
85
  ;
80
86
  const indirectExportMembers = genIndirectExportMembers(mapFilePathToExportAllSources, export2export, import2export);
87
+ const noMatchExportMembers = (0, import_findNoMatchExportMember.default)(import2export, export2export, uselessImportMembers);
81
88
  return {
89
+ noMatchExportMembers,
82
90
  import2export,
83
91
  export2export,
84
92
  mapFilePathToExportAllSources,
@@ -0,0 +1,2 @@
1
+ import { RelateUsageOfExport } from "../ast_util/helper/findRelateUsageOfExport";
2
+ export default function create_mmd(relatedExportUsage: RelateUsageOfExport[]): string;
@@ -0,0 +1,32 @@
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/report_util/create_mmd.ts
20
+ var create_mmd_exports = {};
21
+ __export(create_mmd_exports, {
22
+ default: () => create_mmd
23
+ });
24
+ module.exports = __toCommonJS(create_mmd_exports);
25
+ function create_mmd(relatedExportUsage) {
26
+ const fileList = relatedExportUsage.map((item) => [item.filePath, ...item.importMemberAndFile.map((e) => e.fromFile)]).flat();
27
+ const fileListStr = fileList.join("\n");
28
+ const linkList = relatedExportUsage.map((item) => item.importMemberAndFile.map((e) => `${e.fromFile} --> |${e.localName}>>>${item.exportMember}|${item.filePath}`)).flat();
29
+ const linkListStr = linkList.join("\n");
30
+ return `graph TD
31
+ ` + fileListStr + "\n" + linkListStr;
32
+ }
@@ -7,7 +7,7 @@ export default function filterEffectedCode(reports: ReturnType<typeof createDete
7
7
  usages: string[];
8
8
  } | {
9
9
  filePath: string;
10
- type: "modify" | "delete";
10
+ type: "delete" | "modify";
11
11
  effectedExports: string[];
12
12
  usages: string[];
13
13
  })[];
@@ -7,6 +7,15 @@ export declare function generateGitDiffReport(arg: {
7
7
  generateFile?: ('dependence_map.json' | 'partial_dependence_map.json' | 'report.json' | 'gitDiffDetail.json' | typeof reportFileName)[];
8
8
  }): Promise<{
9
9
  dependenceJson: {
10
+ noMatchExportMembers: {
11
+ file: string;
12
+ member: string;
13
+ useless: boolean;
14
+ from: {
15
+ file: string;
16
+ member: string;
17
+ };
18
+ }[];
10
19
  import2export: Record<string, string>;
11
20
  export2export: Record<string, string>;
12
21
  mapFilePathToExportAllSources: Record<string, string[]>;
@@ -26,7 +35,7 @@ export declare function generateGitDiffReport(arg: {
26
35
  effectsDownstream: string[];
27
36
  }[];
28
37
  }[];
29
- type: "modify" | "add" | "delete";
38
+ type: "add" | "delete" | "modify";
30
39
  filesDependsOnMe: string[];
31
40
  undefinedIdentifiers: string[];
32
41
  filePath: string;
@@ -60,7 +60,8 @@ async function generateGitDiffReport(arg) {
60
60
  indirectExportMembers: {},
61
61
  import2export: {},
62
62
  export2export: {},
63
- mapFilePathToExportAllSources: {}
63
+ mapFilePathToExportAllSources: {},
64
+ noMatchExportMembers: []
64
65
  };
65
66
  let partialDependenceJson = {};
66
67
  let reports = [];
@@ -0,0 +1 @@
1
+ export default function mmd_html(filePath: string, mmd_content: string): void;
@@ -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/report_util/mmd_html.ts
20
+ var mmd_html_exports = {};
21
+ __export(mmd_html_exports, {
22
+ default: () => mmd_html
23
+ });
24
+ module.exports = __toCommonJS(mmd_html_exports);
25
+ var import_fs = require("fs");
26
+ function mmd_html(filePath, mmd_content) {
27
+ const content = `<!doctype html>
28
+ <html lang="en">
29
+ <body>
30
+ <pre class="mermaid">
31
+ ${mmd_content}
32
+ </pre>
33
+ <script type="module">
34
+ import mermaid from 'https://cdn.jsdelivr.net/npm/mermaid@11/dist/mermaid.esm.min.mjs';
35
+ </script>
36
+ </body>
37
+ </html>`;
38
+ (0, import_fs.writeFileSync)(filePath, content);
39
+ }
@@ -37,7 +37,7 @@ export declare function createDetectReport(arg: Arg): {
37
37
  effectsDownstream: string[];
38
38
  }[];
39
39
  }[];
40
- type: "modify" | "add" | "delete";
40
+ type: "add" | "delete" | "modify";
41
41
  filesDependsOnMe: string[];
42
42
  undefinedIdentifiers: string[];
43
43
  filePath: string;
@@ -7,6 +7,15 @@ export declare function gitDiffTool(arg: {
7
7
  generateFile: Parameters<typeof generateGitDiffReport>[0]['generateFile'];
8
8
  }): Promise<{
9
9
  dependenceJson: {
10
+ noMatchExportMembers: {
11
+ file: string;
12
+ member: string;
13
+ useless: boolean;
14
+ from: {
15
+ file: string;
16
+ member: string;
17
+ };
18
+ }[];
10
19
  import2export: Record<string, string>;
11
20
  export2export: Record<string, string>;
12
21
  mapFilePathToExportAllSources: Record<string, string[]>;
@@ -26,7 +35,7 @@ export declare function gitDiffTool(arg: {
26
35
  effectsDownstream: string[];
27
36
  }[];
28
37
  }[];
29
- type: "modify" | "add" | "delete";
38
+ type: "add" | "delete" | "modify";
30
39
  filesDependsOnMe: string[];
31
40
  undefinedIdentifiers: string[];
32
41
  filePath: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "js-code-detector",
3
- "version": "0.0.57",
3
+ "version": "0.0.59",
4
4
  "description": "",
5
5
  "main": "dist/cjs/index.js",
6
6
  "types": "dist/cjs/index.d.ts",