js-code-detector 0.0.48 → 0.0.51

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 (47) hide show
  1. package/dist/cjs/index.d.ts +1 -43
  2. package/dist/cjs/index.js +3 -25
  3. package/dist/cjs/services/DetectService.d.ts +3 -1
  4. package/dist/cjs/services/DetectService.js +30 -7
  5. package/dist/cjs/services/ProjectService.d.ts +1 -2
  6. package/dist/cjs/services/projectServiceClass/UmiProjectService.d.ts +4 -0
  7. package/dist/cjs/services/projectServiceClass/UmiProjectService.js +11 -7
  8. package/dist/cjs/services/projectServiceClass/VueProjectService.d.ts +31 -0
  9. package/dist/cjs/services/projectServiceClass/VueProjectService.js +191 -0
  10. package/dist/cjs/util/ast_util/AstFeatUtil.js +2 -4
  11. package/dist/cjs/util/ast_util/AstKit.d.ts +30 -0
  12. package/dist/cjs/util/ast_util/AstKit.js +574 -0
  13. package/dist/cjs/util/ast_util/AstUtil.d.ts +7 -7
  14. package/dist/cjs/util/ast_util/AstUtil.js +18 -14
  15. package/dist/cjs/util/ast_util/SHARED_CONSTANTS.d.ts +3 -0
  16. package/dist/cjs/util/ast_util/SHARED_CONSTANTS.js +35 -0
  17. package/dist/cjs/util/constants.d.ts +1 -0
  18. package/dist/cjs/util/constants.js +5 -2
  19. package/dist/cjs/util/{shared/gitUtil.d.ts → git_util/cloneRepoWithBranchAndDefault.d.ts} +1 -5
  20. package/dist/cjs/util/{shared/gitUtil.js → git_util/cloneRepoWithBranchAndDefault.js} +5 -25
  21. package/dist/cjs/util/git_util/execGitDiff.d.ts +4 -0
  22. package/dist/cjs/util/git_util/execGitDiff.js +39 -0
  23. package/dist/cjs/util/git_util/getGitRepositoryAndBranch.d.ts +4 -0
  24. package/dist/cjs/util/{report_util/getFileDepends.js → git_util/getGitRepositoryAndBranch.js} +15 -18
  25. package/dist/cjs/util/{parseGitLabDiffUril.js → git_util/parseGitLabDiffUril.js} +2 -2
  26. package/dist/cjs/util/{shared → project_umi_util}/umi4ProjectUtil.js +1 -1
  27. package/dist/cjs/util/{shared → project_umi_util}/vueProjectUtil.js +1 -1
  28. package/dist/cjs/util/report_util/createDependenceMap.js +3 -3
  29. package/dist/cjs/util/report_util/filterEffectedCode.d.ts +1 -1
  30. package/dist/cjs/util/report_util/filterEffectedExportMember.js +5 -1
  31. package/dist/cjs/util/report_util/generateGitDiffReport.d.ts +1 -1
  32. package/dist/cjs/util/report_util/generateGitDiffReport.js +2 -2
  33. package/dist/cjs/util/{ast_util/filePathResolver.d.ts → report_util/resolveImportPath.d.ts} +1 -1
  34. package/dist/cjs/util/{ast_util/filePathResolver.js → report_util/resolveImportPath.js} +5 -9
  35. package/dist/cjs/util/{createRandomStr.js → shared/createRandomStr.js} +1 -1
  36. package/dist/cjs/util/shared/getRepoSupportFlag.d.ts +1 -3
  37. package/dist/cjs/util/shared/getRepoSupportFlag.js +1 -18
  38. package/dist/cjs/util/shared/gitDiffTool.d.ts +0 -40
  39. package/dist/cjs/util/shared/gitDiffTool.js +7 -116
  40. package/package.json +5 -1
  41. package/dist/cjs/util/madge_util.d.ts +0 -12
  42. package/dist/cjs/util/madge_util.js +0 -120
  43. package/dist/cjs/util/report_util/getFileDepends.d.ts +0 -1
  44. /package/dist/cjs/util/{parseGitLabDiffUril.d.ts → git_util/parseGitLabDiffUril.d.ts} +0 -0
  45. /package/dist/cjs/util/{shared → project_umi_util}/umi4ProjectUtil.d.ts +0 -0
  46. /package/dist/cjs/util/{shared → project_umi_util}/vueProjectUtil.d.ts +0 -0
  47. /package/dist/cjs/util/{createRandomStr.d.ts → shared/createRandomStr.d.ts} +0 -0
@@ -0,0 +1,35 @@
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/SHARED_CONSTANTS.ts
20
+ var SHARED_CONSTANTS_exports = {};
21
+ __export(SHARED_CONSTANTS_exports, {
22
+ EXPORT_DECLARATION_TYPES: () => EXPORT_DECLARATION_TYPES,
23
+ FUNCTION_TYPES: () => FUNCTION_TYPES,
24
+ INVALID_NODE_KEY: () => INVALID_NODE_KEY
25
+ });
26
+ module.exports = __toCommonJS(SHARED_CONSTANTS_exports);
27
+ var INVALID_NODE_KEY = ["comments", "tokens"];
28
+ var EXPORT_DECLARATION_TYPES = ["FunctionDeclaration", "TSEnumDeclaration", "TSInterfaceDeclaration", "TSTypeAliasDeclaration", "ClassDeclaration"];
29
+ var FUNCTION_TYPES = ["FunctionDeclaration", "ArrowFunctionExpression", "FunctionExpression", "ObjectMethod", "ClassMethod"];
30
+ // Annotate the CommonJS export names for ESM import in node:
31
+ 0 && (module.exports = {
32
+ EXPORT_DECLARATION_TYPES,
33
+ FUNCTION_TYPES,
34
+ INVALID_NODE_KEY
35
+ });
@@ -1,2 +1,3 @@
1
1
  export declare const SOURCE = "source";
2
2
  export declare const TARGET = "target";
3
+ export declare const gitDiffFileName = "git_diff.txt";
@@ -20,13 +20,16 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
20
20
  var constants_exports = {};
21
21
  __export(constants_exports, {
22
22
  SOURCE: () => SOURCE,
23
- TARGET: () => TARGET
23
+ TARGET: () => TARGET,
24
+ gitDiffFileName: () => gitDiffFileName
24
25
  });
25
26
  module.exports = __toCommonJS(constants_exports);
26
27
  var SOURCE = "source";
27
28
  var TARGET = "target";
29
+ var gitDiffFileName = "git_diff.txt";
28
30
  // Annotate the CommonJS export names for ESM import in node:
29
31
  0 && (module.exports = {
30
32
  SOURCE,
31
- TARGET
33
+ TARGET,
34
+ gitDiffFileName
32
35
  });
@@ -5,8 +5,4 @@
5
5
  * @param {string} targetDir - 本地目标目录
6
6
  * @returns {Promise<string>} 克隆目录路径
7
7
  */
8
- export declare function cloneRepoWithBranchAndDefault(repoUrl: string, targetBranch: string, targetDir: string): Promise<string>;
9
- /**
10
- * 执行 baseBranch 和 targetBranch 的 diff
11
- */
12
- export declare function execGitDiff(targetDir: string, baseBranch: string, targetBranch: string): Promise<any>;
8
+ export default function cloneRepoWithBranchAndDefault(repoUrl: string, targetBranch: string, targetDir: string): Promise<string>;
@@ -16,14 +16,12 @@ var __copyProps = (to, from, except, desc) => {
16
16
  };
17
17
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
18
 
19
- // src/util/shared/gitUtil.ts
20
- var gitUtil_exports = {};
21
- __export(gitUtil_exports, {
22
- cloneRepoWithBranchAndDefault: () => cloneRepoWithBranchAndDefault,
23
- execGitDiff: () => execGitDiff
19
+ // src/util/git_util/cloneRepoWithBranchAndDefault.ts
20
+ var cloneRepoWithBranchAndDefault_exports = {};
21
+ __export(cloneRepoWithBranchAndDefault_exports, {
22
+ default: () => cloneRepoWithBranchAndDefault
24
23
  });
25
- module.exports = __toCommonJS(gitUtil_exports);
26
- var import__ = require("../../index");
24
+ module.exports = __toCommonJS(cloneRepoWithBranchAndDefault_exports);
27
25
  var simpleGit = require("simple-git");
28
26
  async function cloneRepoWithBranchAndDefault(repoUrl, targetBranch, targetDir) {
29
27
  try {
@@ -47,21 +45,3 @@ async function cloneRepoWithBranchAndDefault(repoUrl, targetBranch, targetDir) {
47
45
  throw error;
48
46
  }
49
47
  }
50
- async function execGitDiff(targetDir, baseBranch, targetBranch) {
51
- try {
52
- const repoGit = simpleGit(targetDir);
53
- await repoGit.checkout(targetBranch);
54
- await repoGit.pull("origin", targetBranch);
55
- const diffFiles = await repoGit.diffSummary([baseBranch, "--unified=0", `--output=${import__.gitDiffFileName}`]);
56
- console.log(`${targetBranch} 与 ${baseBranch} 的差异:`, diffFiles);
57
- return diffFiles;
58
- } catch (error) {
59
- console.error(`获取差异失败:${error.message}`);
60
- throw error;
61
- }
62
- }
63
- // Annotate the CommonJS export names for ESM import in node:
64
- 0 && (module.exports = {
65
- cloneRepoWithBranchAndDefault,
66
- execGitDiff
67
- });
@@ -0,0 +1,4 @@
1
+ /**
2
+ * 执行 baseBranch 和 targetBranch 的 diff
3
+ */
4
+ export default function execGitDiff(targetDir: string, baseBranch: string, targetBranch: string): Promise<any>;
@@ -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/git_util/execGitDiff.ts
20
+ var execGitDiff_exports = {};
21
+ __export(execGitDiff_exports, {
22
+ default: () => execGitDiff
23
+ });
24
+ module.exports = __toCommonJS(execGitDiff_exports);
25
+ var import_constants = require("../constants");
26
+ var simpleGit = require("simple-git");
27
+ async function execGitDiff(targetDir, baseBranch, targetBranch) {
28
+ try {
29
+ const repoGit = simpleGit(targetDir);
30
+ await repoGit.checkout(targetBranch);
31
+ await repoGit.pull("origin", targetBranch);
32
+ const diffFiles = await repoGit.diffSummary([baseBranch, "--unified=0", `--output=${import_constants.gitDiffFileName}`]);
33
+ console.log(`${targetBranch} 与 ${baseBranch} 的差异:`, diffFiles);
34
+ return diffFiles;
35
+ } catch (error) {
36
+ console.error(`获取差异失败:${error.message}`);
37
+ throw error;
38
+ }
39
+ }
@@ -0,0 +1,4 @@
1
+ export default function getGitRepositoryAndBranch(): Promise<{
2
+ gitUrl: string;
3
+ branchName: string;
4
+ }>;
@@ -16,23 +16,20 @@ var __copyProps = (to, from, except, desc) => {
16
16
  };
17
17
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
18
 
19
- // src/util/report_util/getFileDepends.ts
20
- var getFileDepends_exports = {};
21
- __export(getFileDepends_exports, {
22
- default: () => getFileDepends
19
+ // src/util/git_util/getGitRepositoryAndBranch.ts
20
+ var getGitRepositoryAndBranch_exports = {};
21
+ __export(getGitRepositoryAndBranch_exports, {
22
+ default: () => getGitRepositoryAndBranch
23
23
  });
24
- module.exports = __toCommonJS(getFileDepends_exports);
25
- function getFileDepends(filePath, tree) {
26
- const res = [];
27
- getFileDependsRecursive(res, [filePath], Object.entries(tree), 2);
28
- return res;
29
- }
30
- function getFileDependsRecursive(res, filePaths, treeEntries, maxTry) {
31
- const depends = filePaths.map((f) => treeEntries.filter((entry) => entry[1].includes(f)).map((e) => e[0])).flat();
32
- if (depends.length > 0) {
33
- res.push(depends);
34
- if (maxTry === 0)
35
- return;
36
- getFileDependsRecursive(res, depends, treeEntries, maxTry - 1);
37
- }
24
+ module.exports = __toCommonJS(getGitRepositoryAndBranch_exports);
25
+ var import_utils = require("@umijs/utils");
26
+ async function getGitRepositoryAndBranch() {
27
+ const res = await import_utils.execa.execa("git remote get-url origin", { shell: true });
28
+ import_utils.chalk.green(["仓库地址:", res.stdout]);
29
+ const branch = await import_utils.execa.execa("git rev-parse --abbrev-ref HEAD", { shell: true });
30
+ import_utils.chalk.green(["分支名称:", branch.stdout]);
31
+ return {
32
+ gitUrl: res.stdout,
33
+ branchName: branch.stdout
34
+ };
38
35
  }
@@ -16,7 +16,7 @@ var __copyProps = (to, from, except, desc) => {
16
16
  };
17
17
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
18
 
19
- // src/util/parseGitLabDiffUril.ts
19
+ // src/util/git_util/parseGitLabDiffUril.ts
20
20
  var parseGitLabDiffUril_exports = {};
21
21
  __export(parseGitLabDiffUril_exports, {
22
22
  getGitRepoUrlByToken: () => getGitRepoUrlByToken,
@@ -72,7 +72,7 @@ function getGitRepoUrlByToken(gitRepoUrl, gitlabToken) {
72
72
  if (!projectPath) {
73
73
  throw new Error("请传入 GitLab 项目路径(如 dev-team/my-project)");
74
74
  }
75
- return `http://oauth:${gitlabToken}@${gitlabDomain}/${projectPath}.git`;
75
+ return `http://oauth:${gitlabToken}@${gitlabDomain}${projectPath}.git`;
76
76
  }
77
77
  // Annotate the CommonJS export names for ESM import in node:
78
78
  0 && (module.exports = {
@@ -16,7 +16,7 @@ var __copyProps = (to, from, except, desc) => {
16
16
  };
17
17
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
18
 
19
- // src/util/shared/umi4ProjectUtil.ts
19
+ // src/util/project_umi_util/umi4ProjectUtil.ts
20
20
  var umi4ProjectUtil_exports = {};
21
21
  __export(umi4ProjectUtil_exports, {
22
22
  umi4SetUp: () => umi4SetUp
@@ -16,7 +16,7 @@ var __copyProps = (to, from, except, desc) => {
16
16
  };
17
17
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
18
 
19
- // src/util/shared/vueProjectUtil.ts
19
+ // src/util/project_umi_util/vueProjectUtil.ts
20
20
  var vueProjectUtil_exports = {};
21
21
  __export(vueProjectUtil_exports, {
22
22
  vueSetUp: () => vueSetUp
@@ -33,8 +33,8 @@ __export(createDependenceMap_exports, {
33
33
  });
34
34
  module.exports = __toCommonJS(createDependenceMap_exports);
35
35
  var import_getAstKitByFilePath = __toESM(require("../ast_util/getAstKitByFilePath"));
36
- var import_filePathResolver = require("../ast_util/filePathResolver");
37
36
  var import_path = require("path");
37
+ var import_resolveImportPath = __toESM(require("./resolveImportPath"));
38
38
  function createExportedNameToReferenceLocalSet(upstreamFileFullPaths, parsedAlias, absPathPrefix, projectFilePaths) {
39
39
  const cwd = process.cwd();
40
40
  const systemAbsPathPrefix = absPathPrefix.startsWith(cwd) ? absPathPrefix : (0, import_path.join)(cwd, absPathPrefix);
@@ -52,7 +52,7 @@ function createExportedNameToReferenceLocalSet(upstreamFileFullPaths, parsedAlia
52
52
  const { importedMember, exportedMember } = programNode._util;
53
53
  const relativeFilePath = absFilePath.replace(absPathPrefix, "");
54
54
  for (const { sourcePath, members } of importedMember) {
55
- const { fullPath, isExternal } = (0, import_filePathResolver.resolveImportPath)(localAlias, sourcePath, relativeFilePath);
55
+ const { fullPath, isExternal } = (0, import_resolveImportPath.default)(localAlias, sourcePath, relativeFilePath);
56
56
  const finalSourcePath = createRealSourcePath(sourcePath, isExternal, projectFilePaths, fullPath);
57
57
  for (const { importedName: imported, localName: local } of members) {
58
58
  const importLocal = `${relativeFilePath}#${local}`;
@@ -64,7 +64,7 @@ function createExportedNameToReferenceLocalSet(upstreamFileFullPaths, parsedAlia
64
64
  }
65
65
  }
66
66
  for (const { sourcePath, members, ExportAllDeclaration } of exportedMember) {
67
- const { fullPath, isExternal } = (0, import_filePathResolver.resolveImportPath)(localAlias, sourcePath, relativeFilePath);
67
+ const { fullPath, isExternal } = (0, import_resolveImportPath.default)(localAlias, sourcePath, relativeFilePath);
68
68
  const finalSourcePath = createRealSourcePath(sourcePath, isExternal, projectFilePaths, fullPath);
69
69
  for (const { exportedName: exported, localName: local } of members) {
70
70
  const exportedName = `${relativeFilePath}#${exported}`;
@@ -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
  })[];
@@ -39,5 +39,9 @@ function filterEffectedExportMember(filePath, absPathPrefix, startLine, endLine)
39
39
  const { mapFileLineToNodeSet } = astKit;
40
40
  const topScopeNodes = import_AstUtil.default.getTopScopeNodesByLineNumberRange(mapFileLineToNodeSet, startLine, endLine);
41
41
  const exportMembers = topScopeNodes.map((node) => import_AstUtil.default.findExportedMembersNameFromAncestors(node)).flat();
42
- return [...new Set(exportMembers)];
42
+ const res = [...new Set(exportMembers)];
43
+ if (res.length === 0 && filePath.endsWith(".vue")) {
44
+ res.push("default");
45
+ }
46
+ return res;
43
47
  }
@@ -26,7 +26,7 @@ export declare function generateGitDiffReport(arg: {
26
26
  effectsDownstream: string[];
27
27
  }[];
28
28
  }[];
29
- type: "modify" | "add" | "delete";
29
+ type: "delete" | "modify" | "add";
30
30
  filesDependsOnMe: string[];
31
31
  undefinedIdentifiers: string[];
32
32
  filePath: string;
@@ -34,7 +34,7 @@ __export(generateGitDiffReport_exports, {
34
34
  module.exports = __toCommonJS(generateGitDiffReport_exports);
35
35
  var import_fs = require("fs");
36
36
  var import_path = require("path");
37
- var import__ = require("../../index");
37
+ var import_constants = require("../constants");
38
38
  var import_format_git_diff_content = require("../format_git_diff_content");
39
39
  var import_utils = require("@umijs/utils");
40
40
  var import_report_util = require("../report_util");
@@ -49,7 +49,7 @@ async function generateGitDiffReport(arg) {
49
49
  const { tree } = madgeResult;
50
50
  const projectFilePaths = Object.keys(tree);
51
51
  import_utils.logger.info("读取 git diff 内容,生成 json 文件");
52
- const diff_txt = (0, import_fs.readFileSync)((0, import_path.join)(targetDirPath, import__.gitDiffFileName), "utf-8");
52
+ const diff_txt = (0, import_fs.readFileSync)((0, import_path.join)(targetDirPath, import_constants.gitDiffFileName), "utf-8");
53
53
  const gitDiffDetail = (0, import_format_git_diff_content.formatGitDiffContent)(diff_txt);
54
54
  const modifiedFilePaths = gitDiffDetail.map((item) => item.filePath);
55
55
  const upstreamFilePaths = (0, import_collectUpstreamFiles.default)(madgeResult, modifiedFilePaths);
@@ -6,7 +6,7 @@
6
6
  * @param {string[]} [extensions=['.js', '.ts', '.jsx', '.tsx']] - 可能的文件扩展名
7
7
  * @returns {Object} 包含全路径和是否为外部路径的对象
8
8
  */
9
- export declare function resolveImportPath(alias: Record<string, string>, importPath: string, currentFilePath: string, extensions?: string[]): {
9
+ export default function resolveImportPath(alias: Record<string, string>, importPath: string, currentFilePath: string, extensions?: string[]): {
10
10
  fullPath: string[];
11
11
  isExternal: boolean;
12
12
  } | {
@@ -16,12 +16,12 @@ var __copyProps = (to, from, except, desc) => {
16
16
  };
17
17
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
18
 
19
- // src/util/ast_util/filePathResolver.ts
20
- var filePathResolver_exports = {};
21
- __export(filePathResolver_exports, {
22
- resolveImportPath: () => resolveImportPath
19
+ // src/util/report_util/resolveImportPath.ts
20
+ var resolveImportPath_exports = {};
21
+ __export(resolveImportPath_exports, {
22
+ default: () => resolveImportPath
23
23
  });
24
- module.exports = __toCommonJS(filePathResolver_exports);
24
+ module.exports = __toCommonJS(resolveImportPath_exports);
25
25
  function joinPath(...paths) {
26
26
  const isAbsolute = paths.some(
27
27
  (path) => path.startsWith("/") || path.startsWith("\\") || path.length >= 2 && path[1] === ":"
@@ -125,7 +125,3 @@ function resolveImportPath(alias, importPath, currentFilePath, extensions = [".j
125
125
  isExternal: false
126
126
  };
127
127
  }
128
- // Annotate the CommonJS export names for ESM import in node:
129
- 0 && (module.exports = {
130
- resolveImportPath
131
- });
@@ -26,7 +26,7 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
26
26
  ));
27
27
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
28
28
 
29
- // src/util/createRandomStr.ts
29
+ // src/util/shared/createRandomStr.ts
30
30
  var createRandomStr_exports = {};
31
31
  __export(createRandomStr_exports, {
32
32
  default: () => createRandomStr
@@ -1,4 +1,2 @@
1
- import { semver } from "@umijs/utils";
2
1
  export declare function isRepoTypeSupported(repoType: string): boolean;
3
- export declare function getRepoType(jsonPath: string): "unknown" | "umi" | "vue2";
4
- export declare function getMinVersion(jsonPath: string, depName: string): semver.SemVer | null | undefined;
2
+ export declare function getRepoType(jsonPath: string): "umi" | "vue2" | "unknown";
@@ -19,7 +19,6 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
19
19
  // src/util/shared/getRepoSupportFlag.ts
20
20
  var getRepoSupportFlag_exports = {};
21
21
  __export(getRepoSupportFlag_exports, {
22
- getMinVersion: () => getMinVersion,
23
22
  getRepoType: () => getRepoType,
24
23
  isRepoTypeSupported: () => isRepoTypeSupported
25
24
  });
@@ -27,7 +26,7 @@ module.exports = __toCommonJS(getRepoSupportFlag_exports);
27
26
  var import_fs = require("fs");
28
27
  var import_utils = require("@umijs/utils");
29
28
  function isRepoTypeSupported(repoType) {
30
- return ["umi"].includes(repoType);
29
+ return ["umi", "vue2"].includes(repoType);
31
30
  }
32
31
  function getRepoType(jsonPath) {
33
32
  var _a, _b, _c;
@@ -50,24 +49,8 @@ function getRepoType(jsonPath) {
50
49
  }
51
50
  return "unknown";
52
51
  }
53
- function getMinVersion(jsonPath, depName) {
54
- var _a, _b;
55
- const packageJson = (0, import_fs.readFileSync)(jsonPath, "utf-8");
56
- if (!packageJson)
57
- return null;
58
- try {
59
- const packageJsonObj = JSON.parse(packageJson);
60
- const v = ((_a = packageJsonObj == null ? void 0 : packageJsonObj.dependencies) == null ? void 0 : _a[depName]) || ((_b = packageJsonObj == null ? void 0 : packageJsonObj.devDependencies) == null ? void 0 : _b[depName]);
61
- if (v) {
62
- return import_utils.semver.minVersion(v);
63
- }
64
- } catch (e) {
65
- return null;
66
- }
67
- }
68
52
  // Annotate the CommonJS export names for ESM import in node:
69
53
  0 && (module.exports = {
70
- getMinVersion,
71
54
  getRepoType,
72
55
  isRepoTypeSupported
73
56
  });
@@ -1,44 +1,4 @@
1
1
  import { generateGitDiffReport } from "../report_util/generateGitDiffReport";
2
- export declare function cloneGitRepoAndGetDiff(gitRepoUrl: string, branchName: string, extra?: {
3
- token?: string;
4
- jsonKeys?: (keyof Awaited<ReturnType<typeof cloneGitRepoAndGetDiff>>)[];
5
- }): Promise<{
6
- reports: {
7
- dangerIdentifiers: string[];
8
- topEffectedExportsAdded: string[];
9
- topEffectedExportsRemoved: string[];
10
- blockReports: {
11
- diff_txt: string[];
12
- infos: {
13
- causeBy: string;
14
- effectsUpstream: string[];
15
- occupations: string[];
16
- effectsDownstream: string[];
17
- }[];
18
- }[];
19
- type: "modify" | "add" | "delete";
20
- filesDependsOnMe: string[];
21
- undefinedIdentifiers: string[];
22
- filePath: string;
23
- }[];
24
- dependenceJson: {
25
- import2export: Record<string, string>;
26
- export2export: Record<string, string>;
27
- mapFilePathToExportAllSources: Record<string, string[]>;
28
- indirectExportMembers: Record<string, string>;
29
- };
30
- effectedCode: Record<string, any>;
31
- upstreamDependenceJson: {};
32
- repoType: string;
33
- message: string;
34
- } | {
35
- effectedCode: Record<string, any>;
36
- upstreamDependenceJson: {};
37
- repoType: string;
38
- message: any;
39
- reports?: undefined;
40
- dependenceJson?: undefined;
41
- }>;
42
2
  export declare function gitDiffTool(arg: {
43
3
  gitRepoUrl: string;
44
4
  baseBranch: string;
@@ -29,128 +29,20 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
29
29
  // src/util/shared/gitDiffTool.ts
30
30
  var gitDiffTool_exports = {};
31
31
  __export(gitDiffTool_exports, {
32
- cloneGitRepoAndGetDiff: () => cloneGitRepoAndGetDiff,
33
32
  gitDiffTool: () => gitDiffTool
34
33
  });
35
34
  module.exports = __toCommonJS(gitDiffTool_exports);
36
- var import_parseGitLabDiffUril = require("../parseGitLabDiffUril");
37
35
  var import_utils = require("@umijs/utils");
38
36
  var import_await_to_js = __toESM(require("await-to-js"));
39
37
  var import_constants = require("../constants");
40
38
  var import_handleExecaError = require("./handleExecaError");
41
39
  var import_getRepoSupportFlag = require("./getRepoSupportFlag");
42
40
  var import_path = require("path");
43
- var import_umi4ProjectUtil = require("./umi4ProjectUtil");
41
+ var import_umi4ProjectUtil = require("../project_umi_util/umi4ProjectUtil");
44
42
  var import_generateGitDiffReport = require("../report_util/generateGitDiffReport");
45
- var import_vueProjectUtil = require("./vueProjectUtil");
46
- var import__ = require("../../index");
47
- var import_fs = require("fs");
48
- var import_format_git_diff_content = require("../format_git_diff_content");
49
- var import_gitUtil = require("./gitUtil");
50
- var import_perf_hooks = require("perf_hooks");
51
- var import_createDependenceMap = require("../report_util/createDependenceMap");
52
- var import_collectUpstreamFiles = __toESM(require("./collectUpstreamFiles"));
53
- var import_filterEffectedCode = __toESM(require("../report_util/filterEffectedCode"));
54
- var import_report_util = require("../report_util");
55
- var import_createRandomStr = __toESM(require("../createRandomStr"));
56
- async function cloneGitRepoAndGetDiff(gitRepoUrl, branchName, extra = {}) {
57
- import_perf_hooks.performance.mark("stage 0");
58
- const { token, jsonKeys = ["upstreamDependenceJson"] } = extra;
59
- const today = (0, import_createRandomStr.default)();
60
- import_utils.logger.ready("准备生成临时工作目录...");
61
- const [err] = await (0, import_await_to_js.default)(import_utils.execa.execa(`rm -rf ${today}`, { shell: true }));
62
- if (err) {
63
- import_utils.logger.error("临时目录删除失败");
64
- }
65
- let stderr, failed;
66
- ({ stderr, failed } = await import_utils.execa.execa(`mkdir -p ${today}`, { shell: true }));
67
- (0, import_handleExecaError.handleExecaError)({ failed, stderr });
68
- import_utils.logger.info("临时目录建立完成");
69
- let upstreamDependenceJson = {};
70
- let dependenceJson = {
71
- indirectExportMembers: {},
72
- import2export: {},
73
- export2export: {},
74
- mapFilePathToExportAllSources: {}
75
- };
76
- let effectedCode = {};
77
- let reports = [];
78
- try {
79
- import_utils.logger.ready(`准备clone 源代码到临时目录下的 ${today}/${import_constants.TARGET} 文件夹`);
80
- const repoUrl = (0, import_parseGitLabDiffUril.getGitRepoUrlByToken)(gitRepoUrl, token || "");
81
- import_perf_hooks.performance.mark("stage 1");
82
- await (0, import_gitUtil.cloneRepoWithBranchAndDefault)(repoUrl, branchName, (0, import_path.join)(today, import_constants.TARGET));
83
- import_perf_hooks.performance.mark("stage 2");
84
- import_utils.logger.info(`stage 1 --> stage 2 耗时: ${import_perf_hooks.performance.measure("stage 1 --> stage 2", "stage 1", "stage 2").duration}ms`);
85
- await (0, import_gitUtil.cloneRepoWithBranchAndDefault)(repoUrl, "master", (0, import_path.join)(today, import_constants.SOURCE));
86
- import_perf_hooks.performance.mark("stage 3");
87
- import_utils.logger.info(`stage 2 --> stage 3 耗时: ${import_perf_hooks.performance.measure("stage 2 --> stage 3", "stage 2", "stage 3").duration}ms`);
88
- import_utils.logger.ready("准备生成git_diff.txt文件");
89
- ({ stderr, failed } = await import_utils.execa.execa(`cd ${today}/${import_constants.TARGET} && git diff master..${branchName} --unified=0 --output=${import__.gitDiffFileName}`, { shell: true }));
90
- import_perf_hooks.performance.mark("stage 4");
91
- import_utils.logger.info(`stage 3 --> stage 4 耗时: ${import_perf_hooks.performance.measure("stage 3 --> stage 4", "stage 3", "stage 4").duration}ms`);
92
- (0, import_handleExecaError.handleExecaError)({ failed, stderr });
93
- const repoType = await (0, import_getRepoSupportFlag.getRepoType)((0, import_path.join)(process.cwd(), today, import_constants.TARGET, "package.json"));
94
- import_utils.logger.info(`项目类型为: ${repoType}`);
95
- if (repoType === "umi") {
96
- const { madgeResult, shellExeResult, parsedAlias } = await (0, import_umi4ProjectUtil.umi4SetUp)({ targetDirPath: (0, import_path.join)(process.cwd(), today, import_constants.TARGET), invokeType: "remote" });
97
- import_perf_hooks.performance.mark("stage 5");
98
- import_utils.logger.info(`stage 4 --> stage 5 耗时: ${import_perf_hooks.performance.measure("stage 4 --> stage 5", "stage 4", "stage 5").duration}ms`);
99
- ({ stderr, failed } = shellExeResult);
100
- (0, import_handleExecaError.handleExecaError)({ failed, stderr });
101
- const targetDirPath = (0, import_path.join)(process.cwd(), today, import_constants.TARGET);
102
- const diff_txt = (0, import_fs.readFileSync)((0, import_path.join)(targetDirPath, import__.gitDiffFileName), "utf-8");
103
- const gitDiffDetail = (0, import_format_git_diff_content.formatGitDiffContent)(diff_txt);
104
- const usingFileNoPrefix = Object.keys(madgeResult.tree);
105
- const groupGitDiffLines = gitDiffDetail.filter((item) => usingFileNoPrefix.includes(item.filePath));
106
- const changedFilePaths = groupGitDiffLines.map((item) => item.filePath);
107
- upstreamDependenceJson = Object.fromEntries(changedFilePaths.map((p) => [p, madgeResult.depends(p)]));
108
- const absPathPrefix = targetDirPath + "/";
109
- const modifiedFilePaths = gitDiffDetail.map((item) => item.filePath);
110
- import_perf_hooks.performance.mark("stage 6");
111
- import_utils.logger.info(`stage 5 --> stage 6 耗时: ${import_perf_hooks.performance.measure("stage 5 --> stage 6", "stage 5", "stage 6").duration}ms`);
112
- const effectedFilePaths = (0, import_collectUpstreamFiles.default)(madgeResult, modifiedFilePaths).map((item) => (0, import_utils.winPath)((0, import_path.join)(absPathPrefix, item)));
113
- import_perf_hooks.performance.mark("stage 7");
114
- import_utils.logger.info(`stage 6 --> stage 7 耗时: ${import_perf_hooks.performance.measure("stage 6 --> stage 7", "stage 6", "stage 7").duration}ms`);
115
- if (jsonKeys.includes("dependenceJson")) {
116
- dependenceJson = (0, import_createDependenceMap.createExportedNameToReferenceLocalSet)(effectedFilePaths, parsedAlias, absPathPrefix, Object.keys(madgeResult.tree));
117
- }
118
- import_perf_hooks.performance.mark("stage 8");
119
- import_utils.logger.info(`stage 7 --> stage 8 耗时: ${import_perf_hooks.performance.measure("stage 7 --> stage 8", "stage 7", "stage 8").duration}ms`);
120
- if (jsonKeys.includes("reports")) {
121
- reports = (0, import_report_util.createDetectReport)({ groupGitDiffLines, tree: madgeResult.tree, absPathPrefix });
122
- }
123
- import_perf_hooks.performance.mark("stage 9");
124
- import_utils.logger.info(`stage 8 --> stage 9 耗时: ${import_perf_hooks.performance.measure("stage 8 --> stage 9", "stage 8", "stage 9").duration}ms`);
125
- if (jsonKeys.includes("effectedCode")) {
126
- effectedCode = (0, import_filterEffectedCode.default)(reports, dependenceJson);
127
- }
128
- import_perf_hooks.performance.mark("stage 10");
129
- import_utils.logger.info(`stage 9 --> stage 10 耗时: ${import_perf_hooks.performance.measure("stage 9 --> stage 10", "stage 9", "stage 10").duration}ms`);
130
- import_utils.logger.info(`total 耗时: ${import_perf_hooks.performance.measure("stage 0 --> stage 10", "stage 0", "stage 10").duration}ms`);
131
- }
132
- return {
133
- reports,
134
- dependenceJson,
135
- effectedCode,
136
- upstreamDependenceJson,
137
- repoType,
138
- message: ""
139
- };
140
- } catch (error) {
141
- import_utils.logger.error(error);
142
- return {
143
- effectedCode,
144
- upstreamDependenceJson,
145
- repoType: "",
146
- message: error.message
147
- };
148
- } finally {
149
- (0, import_utils.rimraf)((0, import_path.join)(process.cwd(), today), () => {
150
- import_utils.logger.info("临时目录已删除");
151
- });
152
- }
153
- }
43
+ var import_vueProjectUtil = require("../project_umi_util/vueProjectUtil");
44
+ var import_constants2 = require("../constants");
45
+ var import_cloneRepoWithBranchAndDefault = __toESM(require("../git_util/cloneRepoWithBranchAndDefault"));
154
46
  async function gitDiffTool(arg) {
155
47
  const { gitRepoUrl: gitUrl, baseBranch, targetBranch: branchName, tempDirPath: today, generateFile } = arg;
156
48
  import_utils.logger.ready("准备生成临时工作目录...");
@@ -162,7 +54,7 @@ async function gitDiffTool(arg) {
162
54
  import_utils.logger.info("临时目录建立完成");
163
55
  try {
164
56
  import_utils.logger.ready(`准备clone 源代码 分支:${branchName} 到临时目录下的 ${import_constants.TARGET} 文件夹`);
165
- await (0, import_gitUtil.cloneRepoWithBranchAndDefault)(gitUrl, branchName, (0, import_path.join)(process.cwd(), today, import_constants.TARGET));
57
+ await (0, import_cloneRepoWithBranchAndDefault.default)(gitUrl, branchName, (0, import_path.join)(process.cwd(), today, import_constants.TARGET));
166
58
  let stderr, failed;
167
59
  import_utils.logger.info("源代码clone完成");
168
60
  import_utils.logger.wait("检测项目类型");
@@ -176,10 +68,10 @@ async function gitDiffTool(arg) {
176
68
  return;
177
69
  }
178
70
  import_utils.logger.ready(`准备clone 源代码 分支:master 到临时目录下的 ${import_constants.SOURCE} 文件夹`);
179
- await (0, import_gitUtil.cloneRepoWithBranchAndDefault)(gitUrl, "master", (0, import_path.join)(process.cwd(), today, import_constants.SOURCE));
71
+ await (0, import_cloneRepoWithBranchAndDefault.default)(gitUrl, "master", (0, import_path.join)(process.cwd(), today, import_constants.SOURCE));
180
72
  import_utils.logger.info(`分支 ${branchName} 代码 clone 完成`);
181
73
  import_utils.logger.ready("准备生成git_diff.txt文件");
182
- ({ stderr, failed } = await import_utils.execa.execa(`cd ${today}/${import_constants.TARGET} && git diff ${baseBranch}..${branchName} --unified=0 --output=${import__.gitDiffFileName}`, { shell: true }));
74
+ ({ stderr, failed } = await import_utils.execa.execa(`cd ${today}/${import_constants.TARGET} && git diff ${baseBranch}..${branchName} --unified=0 --output=${import_constants2.gitDiffFileName}`, { shell: true }));
183
75
  (0, import_handleExecaError.handleExecaError)({ failed, stderr });
184
76
  import_utils.logger.info("git_diff.txt文件生成完成");
185
77
  if (repoType === "umi") {
@@ -204,6 +96,5 @@ async function gitDiffTool(arg) {
204
96
  }
205
97
  // Annotate the CommonJS export names for ESM import in node:
206
98
  0 && (module.exports = {
207
- cloneGitRepoAndGetDiff,
208
99
  gitDiffTool
209
100
  });