js-code-detector 0.0.51 → 0.0.52
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/index.d.ts +1 -1
- package/dist/cjs/services/projectServiceClass/UmiProjectService.js +5 -0
- package/dist/cjs/services/projectServiceClass/VueProjectService.d.ts +3 -0
- package/dist/cjs/services/projectServiceClass/VueProjectService.js +32 -6
- package/dist/cjs/util/report_util/filterEffectedExportMember.js +1 -1
- package/dist/cjs/util/report_util/generateGitDiffReport.d.ts +1 -1
- package/dist/cjs/util/report_util/resolveImportPath.js +1 -1
- package/dist/cjs/util/report_util.d.ts +1 -1
- package/dist/cjs/util/shared/gitDiffTool.d.ts +1 -1
- package/package.json +1 -1
package/dist/cjs/index.d.ts
CHANGED
|
@@ -20,7 +20,7 @@ export declare function gitDiffDetect(): Promise<{
|
|
|
20
20
|
effectsDownstream: string[];
|
|
21
21
|
}[];
|
|
22
22
|
}[];
|
|
23
|
-
type: "
|
|
23
|
+
type: "add" | "delete" | "modify";
|
|
24
24
|
filesDependsOnMe: string[];
|
|
25
25
|
undefinedIdentifiers: string[];
|
|
26
26
|
filePath: string;
|
|
@@ -96,5 +96,10 @@ var UmiProjectService = class {
|
|
|
96
96
|
return effectedExportNames.includes(value);
|
|
97
97
|
});
|
|
98
98
|
this.outputResult.effectedImportUsage = effectedImportUsage;
|
|
99
|
+
const token = this.detectService.gitInfo.token;
|
|
100
|
+
if (!token) {
|
|
101
|
+
const pwd = (0, import_path.join)(this.detectService.directoryInfo.tmpWorkDir, "..");
|
|
102
|
+
(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, effectedImportUsage }, null, 2));
|
|
103
|
+
}
|
|
99
104
|
}
|
|
100
105
|
};
|
|
@@ -12,6 +12,7 @@ export default class VueProjectService implements ProjectService {
|
|
|
12
12
|
webpackConfigPath: string;
|
|
13
13
|
webpackConfigTextLines: string[];
|
|
14
14
|
entryFiles: string[];
|
|
15
|
+
extensions: string[];
|
|
15
16
|
};
|
|
16
17
|
constructor(detectService: DetectService);
|
|
17
18
|
run(): Promise<void>;
|
|
@@ -22,9 +23,11 @@ export default class VueProjectService implements ProjectService {
|
|
|
22
23
|
createSimpleWebpackConfig(): {
|
|
23
24
|
resolve: {
|
|
24
25
|
alias: Record<string, any>;
|
|
26
|
+
extensions: string[];
|
|
25
27
|
};
|
|
26
28
|
};
|
|
27
29
|
getEntryFiles(): void;
|
|
30
|
+
getWebpackExtensions(): void;
|
|
28
31
|
getWebpackAlias(): void;
|
|
29
32
|
getMadgeResult(): Promise<void>;
|
|
30
33
|
collectEffectedFiles(): Promise<void>;
|
|
@@ -58,7 +58,8 @@ var VueProjectService = class {
|
|
|
58
58
|
madgeResult: null,
|
|
59
59
|
webpackConfigPath: "",
|
|
60
60
|
webpackConfigTextLines: [],
|
|
61
|
-
entryFiles: []
|
|
61
|
+
entryFiles: [],
|
|
62
|
+
extensions: []
|
|
62
63
|
};
|
|
63
64
|
this.detectService = detectService;
|
|
64
65
|
}
|
|
@@ -82,13 +83,16 @@ var VueProjectService = class {
|
|
|
82
83
|
const targetDirPath = this.detectService.directoryInfo.targetBranchDir;
|
|
83
84
|
this.vueHelpInfo.webpackConfigTextLines = webpackConfigText.split("\n");
|
|
84
85
|
this.getWebpackAlias();
|
|
86
|
+
this.getWebpackExtensions();
|
|
85
87
|
this.getEntryFiles();
|
|
88
|
+
import_utils.logger.info("生成简单的 webpack 配置...");
|
|
86
89
|
const wb = this.createSimpleWebpackConfig();
|
|
87
90
|
(0, import_fs.writeFileSync)(this.vueHelpInfo.webpackConfigPath = (0, import_path.join)(targetDirPath, "webpack.config.js"), `module.exports = ${JSON.stringify(wb, null, 2)}`, "utf-8");
|
|
88
91
|
await this.getMadgeResult();
|
|
89
92
|
}
|
|
90
93
|
async getWebpackConfigText() {
|
|
91
94
|
const targetDirPath = this.detectService.directoryInfo.targetBranchDir;
|
|
95
|
+
import_utils.logger.info("执行 npx vue-cli-service inspect");
|
|
92
96
|
let [err, data] = await (0, import_await_to_js.default)(import_utils.execa.execa(`cd ${targetDirPath} && npx vue-cli-service inspect`, { shell: true }));
|
|
93
97
|
if (err) {
|
|
94
98
|
await import_utils.execa.execa(`cd ${targetDirPath} && yarn`, { shell: true });
|
|
@@ -103,7 +107,8 @@ var VueProjectService = class {
|
|
|
103
107
|
createSimpleWebpackConfig() {
|
|
104
108
|
return {
|
|
105
109
|
resolve: {
|
|
106
|
-
alias: this.helpInfo.parsedAlias
|
|
110
|
+
alias: this.helpInfo.parsedAlias,
|
|
111
|
+
extensions: this.vueHelpInfo.extensions
|
|
107
112
|
}
|
|
108
113
|
};
|
|
109
114
|
}
|
|
@@ -127,7 +132,26 @@ var VueProjectService = class {
|
|
|
127
132
|
entryObject = eval(`(${entryLinesJoin})`);
|
|
128
133
|
this.vueHelpInfo.entryFiles = Object.values({ ...entryObject }).flat();
|
|
129
134
|
}
|
|
135
|
+
getWebpackExtensions() {
|
|
136
|
+
import_utils.logger.info("获取 webpack extensions...");
|
|
137
|
+
const lines = this.vueHelpInfo.webpackConfigTextLines;
|
|
138
|
+
let extensions = "";
|
|
139
|
+
let extensionsFind = false;
|
|
140
|
+
for (const line of lines) {
|
|
141
|
+
if (!extensionsFind && line.trim().startsWith("extensions:")) {
|
|
142
|
+
extensionsFind = true;
|
|
143
|
+
extensions += line.trim().replace(/^\s*extensions:\s*/, "");
|
|
144
|
+
} else if (extensionsFind && line.trim().startsWith("]")) {
|
|
145
|
+
extensions += line.replace(/,/g, "");
|
|
146
|
+
break;
|
|
147
|
+
} else if (extensionsFind) {
|
|
148
|
+
extensions += line.trim();
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
this.vueHelpInfo.extensions = eval(`(${extensions})`);
|
|
152
|
+
}
|
|
130
153
|
getWebpackAlias() {
|
|
154
|
+
import_utils.logger.info("获取 webpack alias...");
|
|
131
155
|
const lines = this.vueHelpInfo.webpackConfigTextLines;
|
|
132
156
|
const aliasLines = [];
|
|
133
157
|
let aliasFind = false;
|
|
@@ -150,8 +174,9 @@ var VueProjectService = class {
|
|
|
150
174
|
const entryFilePath = this.vueHelpInfo.entryFiles.map((file) => (0, import_path.join)(targetBranchDir, file));
|
|
151
175
|
const madgeConfig = {
|
|
152
176
|
baseDir: this.detectService.directoryInfo.targetBranchDir,
|
|
153
|
-
fileExtensions:
|
|
154
|
-
webpackConfig: this.vueHelpInfo.webpackConfigPath
|
|
177
|
+
fileExtensions: this.vueHelpInfo.extensions.map((ext) => ext.replace(/^\./, "")),
|
|
178
|
+
webpackConfig: this.vueHelpInfo.webpackConfigPath,
|
|
179
|
+
excludeRegExp: [/node_modules/]
|
|
155
180
|
};
|
|
156
181
|
const res = await (0, import_madge.default)(entryFilePath, madgeConfig);
|
|
157
182
|
this.vueHelpInfo.madgeResult = res;
|
|
@@ -170,7 +195,8 @@ var VueProjectService = class {
|
|
|
170
195
|
}, []);
|
|
171
196
|
const possibleEffectedFiles = (0, import_collectUpstreamFiles.default)(madgeResult, validModifiedFiles);
|
|
172
197
|
const possibleEffectedFilesFullPath = possibleEffectedFiles.map((file) => (0, import_path.join)(absPathPrefix, file));
|
|
173
|
-
const
|
|
198
|
+
const mapRef = (0, import_createDependenceMap.createExportedNameToReferenceLocalSet)(possibleEffectedFilesFullPath, parsedAlias, absPathPrefix, projectFileList);
|
|
199
|
+
const { import2export, indirectExportMembers } = mapRef;
|
|
174
200
|
const gitDiffDetail = this.gitDiffDetail;
|
|
175
201
|
const validGitDiffDetail = gitDiffDetail.filter((item) => possibleEffectedFiles.includes(item.filePath));
|
|
176
202
|
const effectedExportNames = validGitDiffDetail.map((item) => {
|
|
@@ -185,7 +211,7 @@ var VueProjectService = class {
|
|
|
185
211
|
const token = this.detectService.gitInfo.token;
|
|
186
212
|
if (!token) {
|
|
187
213
|
const pwd = (0, import_path.join)(this.detectService.directoryInfo.tmpWorkDir, "..");
|
|
188
|
-
(0, import_fs.writeFileSync)((0, import_path.join)(pwd, "effectedImportUsage.json"), JSON.stringify(effectedImportUsage, null, 2));
|
|
214
|
+
(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, effectedImportUsage, ...mapRef }, null, 2));
|
|
189
215
|
}
|
|
190
216
|
}
|
|
191
217
|
};
|
|
@@ -35,7 +35,7 @@ module.exports = __toCommonJS(filterEffectedExportMember_exports);
|
|
|
35
35
|
var import_getAstKitByFilePath = __toESM(require("../ast_util/getAstKitByFilePath"));
|
|
36
36
|
var import_AstUtil = __toESM(require("../ast_util/AstUtil"));
|
|
37
37
|
function filterEffectedExportMember(filePath, absPathPrefix, startLine, endLine) {
|
|
38
|
-
const astKit = (0, import_getAstKitByFilePath.default)(filePath, absPathPrefix);
|
|
38
|
+
const astKit = (0, import_getAstKitByFilePath.default)(filePath, absPathPrefix, (travelNode) => ["VElement", "ImportDeclaration", "ExportAllDeclaration", "ExportNamedDeclaration", "ExportDefaultDeclaration"].includes(travelNode.type));
|
|
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();
|
|
@@ -26,7 +26,7 @@ export declare function generateGitDiffReport(arg: {
|
|
|
26
26
|
effectsDownstream: string[];
|
|
27
27
|
}[];
|
|
28
28
|
}[];
|
|
29
|
-
type: "
|
|
29
|
+
type: "add" | "delete" | "modify";
|
|
30
30
|
filesDependsOnMe: string[];
|
|
31
31
|
undefinedIdentifiers: string[];
|
|
32
32
|
filePath: string;
|
|
@@ -62,7 +62,7 @@ function getDirName(filePath) {
|
|
|
62
62
|
}
|
|
63
63
|
return normalized.slice(0, lastSlashIndex);
|
|
64
64
|
}
|
|
65
|
-
function resolveImportPath(alias, importPath, currentFilePath, extensions = [".js", ".ts", ".jsx", ".tsx"]) {
|
|
65
|
+
function resolveImportPath(alias, importPath, currentFilePath, extensions = [".js", ".ts", ".jsx", ".tsx", ".vue"]) {
|
|
66
66
|
if (importPath.startsWith(".")) {
|
|
67
67
|
const currentDir = getDirName(currentFilePath);
|
|
68
68
|
const absolutePath = joinPath(currentDir, importPath);
|
|
@@ -37,7 +37,7 @@ export declare function createDetectReport(arg: Arg): {
|
|
|
37
37
|
effectsDownstream: string[];
|
|
38
38
|
}[];
|
|
39
39
|
}[];
|
|
40
|
-
type: "
|
|
40
|
+
type: "add" | "delete" | "modify";
|
|
41
41
|
filesDependsOnMe: string[];
|
|
42
42
|
undefinedIdentifiers: string[];
|
|
43
43
|
filePath: string;
|