js-code-detector 0.0.43 → 0.0.47
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/runDiffDetect.js +3 -0
- package/dist/cjs/index.d.ts +35 -12
- package/dist/cjs/index.js +23 -8
- package/dist/cjs/services/DetectService.d.ts +35 -0
- package/dist/cjs/services/DetectService.js +177 -0
- package/dist/cjs/services/ProjectService.d.ts +16 -0
- package/dist/cjs/services/ProjectService.js +17 -0
- package/dist/cjs/services/projectServiceClass/UmiProjectService.d.ts +13 -0
- package/dist/cjs/services/projectServiceClass/UmiProjectService.js +97 -0
- package/dist/cjs/util/ast_util/AstUtil.d.ts +4 -7
- package/dist/cjs/util/ast_util/AstUtil.js +158 -50
- package/dist/cjs/util/ast_util/FileUtil.js +5 -1
- package/dist/cjs/util/createRandomStr.d.ts +1 -0
- package/dist/cjs/util/createRandomStr.js +38 -0
- package/dist/cjs/util/parseGitLabDiffUril.js +1 -1
- package/dist/cjs/util/report_util/createDependenceMap.d.ts +6 -1
- package/dist/cjs/util/report_util/createDependenceMap.js +73 -28
- package/dist/cjs/util/report_util/filterEffectedCode.d.ts +13 -0
- package/dist/cjs/util/report_util/filterEffectedCode.js +72 -0
- package/dist/cjs/util/report_util/filterEffectedExportMember.d.ts +1 -0
- package/dist/cjs/util/report_util/filterEffectedExportMember.js +43 -0
- package/dist/cjs/util/report_util/generateGitDiffReport.d.ts +9 -4
- package/dist/cjs/util/report_util/generateGitDiffReport.js +24 -19
- package/dist/cjs/util/report_util.d.ts +3 -1
- package/dist/cjs/util/report_util.js +10 -0
- package/dist/cjs/util/shared/collectUpstreamFiles.d.ts +2 -0
- package/dist/cjs/util/shared/collectUpstreamFiles.js +39 -0
- package/dist/cjs/util/shared/getRepoSupportFlag.d.ts +2 -1
- package/dist/cjs/util/shared/getRepoSupportFlag.js +15 -6
- package/dist/cjs/util/shared/gitDiffTool.d.ts +45 -7
- package/dist/cjs/util/shared/gitDiffTool.js +80 -29
- package/dist/cjs/util/shared/gitUtil.d.ts +4 -0
- package/dist/cjs/util/shared/gitUtil.js +18 -2
- package/dist/cjs/util/shared/umi4ProjectUtil.d.ts +2 -1
- package/dist/cjs/util/shared/umi4ProjectUtil.js +6 -8
- package/package.json +3 -2
- package/bin/eslintOutput.js +0 -3
- package/dist/cjs/sh/detect.sh +0 -15
|
@@ -123,7 +123,7 @@ var _AstUtil = class {
|
|
|
123
123
|
return node;
|
|
124
124
|
}
|
|
125
125
|
Object.keys(node).forEach((nodeKey) => {
|
|
126
|
-
if (this.invalidNodeKey.includes(nodeKey)
|
|
126
|
+
if (this.invalidNodeKey.includes(nodeKey)) {
|
|
127
127
|
return;
|
|
128
128
|
}
|
|
129
129
|
const nodeValue = node[nodeKey];
|
|
@@ -190,7 +190,95 @@ var _AstUtil = class {
|
|
|
190
190
|
}
|
|
191
191
|
return node;
|
|
192
192
|
}
|
|
193
|
+
static findRelatedExportNameOfDeclarationIdentifier(id) {
|
|
194
|
+
var _a;
|
|
195
|
+
const occupationInExport = [...id._util.occupation].filter((op) => {
|
|
196
|
+
var _a2;
|
|
197
|
+
return ["ExportSpecifier", "ExportDefaultDeclaration"].includes((_a2 = op._util.parent) == null ? void 0 : _a2.type);
|
|
198
|
+
});
|
|
199
|
+
for (const op of occupationInExport) {
|
|
200
|
+
const occupationParentType = (_a = op._util.parent) == null ? void 0 : _a.type;
|
|
201
|
+
if (occupationParentType === "ExportSpecifier") {
|
|
202
|
+
return op._util.parent.exported.name;
|
|
203
|
+
}
|
|
204
|
+
if (occupationParentType === "ExportDefaultDeclaration") {
|
|
205
|
+
return "default";
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
static findExportedMembersNameFromAncestors(node) {
|
|
210
|
+
var _a, _b;
|
|
211
|
+
if (!node) {
|
|
212
|
+
console.warn("findExportedMembersNameFromAncestors: node is null");
|
|
213
|
+
return [];
|
|
214
|
+
}
|
|
215
|
+
const ancestors = node._util.ancestors;
|
|
216
|
+
const nodeArray = [...ancestors, node];
|
|
217
|
+
const nameList = /* @__PURE__ */ new Set();
|
|
218
|
+
outer:
|
|
219
|
+
for (const ancestor of nodeArray) {
|
|
220
|
+
if (ancestor.type === "ExportDefaultDeclaration") {
|
|
221
|
+
const { declaration } = ancestor;
|
|
222
|
+
if (declaration) {
|
|
223
|
+
nameList.add("default");
|
|
224
|
+
break outer;
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
if (ancestor.type === "ExportNamedDeclaration") {
|
|
228
|
+
const declarationType = (_a = ancestor.declaration) == null ? void 0 : _a.type;
|
|
229
|
+
if (this.EXPORT_DECLARATION_TYPES.includes(declarationType)) {
|
|
230
|
+
const nameToAdd = ancestor.declaration.id.name;
|
|
231
|
+
if (nameToAdd) {
|
|
232
|
+
nameList.add(nameToAdd);
|
|
233
|
+
}
|
|
234
|
+
break outer;
|
|
235
|
+
} else if (["VariableDeclaration"].includes(declarationType)) {
|
|
236
|
+
this.findIdOfVariable(ancestor.declaration, (identifier) => {
|
|
237
|
+
nameList.add(identifier.name);
|
|
238
|
+
});
|
|
239
|
+
break outer;
|
|
240
|
+
} else if (declarationType) {
|
|
241
|
+
console.log("未处理的 declarationType :", declarationType);
|
|
242
|
+
}
|
|
243
|
+
const specifiers = ancestor.specifiers;
|
|
244
|
+
if (Array.isArray(specifiers)) {
|
|
245
|
+
for (const specifier of specifiers) {
|
|
246
|
+
if (specifier.type === "ExportSpecifier" || specifier.type === "ExportNamespaceSpecifier") {
|
|
247
|
+
nameList.add(specifier.exported.name);
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
break outer;
|
|
252
|
+
}
|
|
253
|
+
if (["FunctionDeclaration", "ClassDeclaration"].includes(ancestor.type) && "Program" === ((_b = ancestor._util.parent) == null ? void 0 : _b.type)) {
|
|
254
|
+
const ancestorId = ancestor.id;
|
|
255
|
+
if (ancestorId) {
|
|
256
|
+
const nameToAdd = this.findRelatedExportNameOfDeclarationIdentifier(ancestorId);
|
|
257
|
+
if (nameToAdd) {
|
|
258
|
+
nameList.add(nameToAdd);
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
break outer;
|
|
262
|
+
}
|
|
263
|
+
if (["VariableDeclarator"].includes(ancestor.type)) {
|
|
264
|
+
const id = ancestor.id;
|
|
265
|
+
const varIdentifierSet = /* @__PURE__ */ new Set();
|
|
266
|
+
this._deepFindIdentifier(id, (identifier) => {
|
|
267
|
+
varIdentifierSet.add(identifier);
|
|
268
|
+
});
|
|
269
|
+
for (const identifier of varIdentifierSet) {
|
|
270
|
+
const nameToAdd = this.findRelatedExportNameOfDeclarationIdentifier(identifier);
|
|
271
|
+
if (nameToAdd) {
|
|
272
|
+
nameList.add(nameToAdd);
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
break outer;
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
return Array.from(nameList);
|
|
279
|
+
}
|
|
193
280
|
static updateImportedAndExportedMember(node, programNode) {
|
|
281
|
+
var _a;
|
|
194
282
|
const { type, source, declaration, specifiers, _util } = node;
|
|
195
283
|
const { filePath } = _util;
|
|
196
284
|
const sourceValue = (source == null ? void 0 : source.value) || filePath;
|
|
@@ -210,10 +298,19 @@ var _AstUtil = class {
|
|
|
210
298
|
});
|
|
211
299
|
return;
|
|
212
300
|
}
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
301
|
+
if (specifier.type === "ImportDefaultSpecifier") {
|
|
302
|
+
target.members.push({
|
|
303
|
+
localName: local.name,
|
|
304
|
+
importedName: "default"
|
|
305
|
+
});
|
|
306
|
+
return;
|
|
307
|
+
}
|
|
308
|
+
if (specifier.type === "ImportSpecifier") {
|
|
309
|
+
target.members.push({
|
|
310
|
+
localName: local.name,
|
|
311
|
+
importedName: imported.name
|
|
312
|
+
});
|
|
313
|
+
}
|
|
217
314
|
});
|
|
218
315
|
}
|
|
219
316
|
if (type === "ExportAllDeclaration") {
|
|
@@ -223,32 +320,61 @@ var _AstUtil = class {
|
|
|
223
320
|
}
|
|
224
321
|
}
|
|
225
322
|
if (type === "ExportNamedDeclaration") {
|
|
226
|
-
specifiers.forEach((specifier) => {
|
|
323
|
+
Array.isArray(specifiers) && specifiers.forEach((specifier) => {
|
|
227
324
|
const { local, exported } = specifier;
|
|
228
325
|
let target = exportedMember.find((v) => v.sourcePath === sourceValue);
|
|
229
326
|
if (!target) {
|
|
230
327
|
target = { sourcePath: sourceValue, members: [], ExportAllDeclaration: false };
|
|
231
328
|
exportedMember.push(target);
|
|
232
329
|
}
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
330
|
+
if (specifier.type === "ExportNamespaceSpecifier") {
|
|
331
|
+
target.members.push({
|
|
332
|
+
localName: "*",
|
|
333
|
+
exportedName: exported.name
|
|
334
|
+
});
|
|
335
|
+
return;
|
|
336
|
+
}
|
|
337
|
+
if (specifier.type === "ExportSpecifier") {
|
|
338
|
+
target.members.push({
|
|
339
|
+
localName: local.name,
|
|
340
|
+
exportedName: exported.name
|
|
341
|
+
});
|
|
342
|
+
return;
|
|
343
|
+
}
|
|
237
344
|
});
|
|
238
345
|
if (Array.isArray(declaration == null ? void 0 : declaration.declarations)) {
|
|
239
346
|
declaration == null ? void 0 : declaration.declarations.forEach((dec) => {
|
|
240
|
-
var
|
|
347
|
+
var _a2;
|
|
241
348
|
let target = exportedMember.find((v) => v.sourcePath === sourceValue);
|
|
242
349
|
if (!target) {
|
|
243
350
|
target = { sourcePath: sourceValue, members: [], ExportAllDeclaration: false };
|
|
244
351
|
exportedMember.push(target);
|
|
245
352
|
}
|
|
246
|
-
|
|
353
|
+
try {
|
|
354
|
+
const idName = (_a2 = dec.id) == null ? void 0 : _a2.name;
|
|
355
|
+
target.members.push({
|
|
356
|
+
localName: idName,
|
|
357
|
+
exportedName: idName
|
|
358
|
+
});
|
|
359
|
+
} catch (e) {
|
|
360
|
+
console.log("declaration?.declarations.forEach", e.message);
|
|
361
|
+
}
|
|
362
|
+
});
|
|
363
|
+
} else if (this.EXPORT_DECLARATION_TYPES.includes(declaration == null ? void 0 : declaration.type)) {
|
|
364
|
+
let target = exportedMember.find((v) => v.sourcePath === filePath);
|
|
365
|
+
if (!target) {
|
|
366
|
+
target = { sourcePath: filePath, members: [], ExportAllDeclaration: false };
|
|
367
|
+
exportedMember.push(target);
|
|
368
|
+
}
|
|
369
|
+
try {
|
|
370
|
+
const idName = (_a = declaration.id) == null ? void 0 : _a.name;
|
|
247
371
|
target.members.push({
|
|
248
372
|
localName: idName,
|
|
249
373
|
exportedName: idName
|
|
250
374
|
});
|
|
251
|
-
})
|
|
375
|
+
} catch (e) {
|
|
376
|
+
console.log("declaration " + e.message);
|
|
377
|
+
}
|
|
252
378
|
}
|
|
253
379
|
}
|
|
254
380
|
if (type === "ExportDefaultDeclaration") {
|
|
@@ -299,7 +425,7 @@ var _AstUtil = class {
|
|
|
299
425
|
});
|
|
300
426
|
}
|
|
301
427
|
static handleDeclaration(node, callback) {
|
|
302
|
-
if (
|
|
428
|
+
if (this.EXPORT_DECLARATION_TYPES.includes(node.type)) {
|
|
303
429
|
const id = node.id;
|
|
304
430
|
if (id) {
|
|
305
431
|
callback(id);
|
|
@@ -387,14 +513,6 @@ var _AstUtil = class {
|
|
|
387
513
|
holdingIdNameMap.set(holdingIdName, nodeSetOfIdName);
|
|
388
514
|
});
|
|
389
515
|
}
|
|
390
|
-
static isVarInit(node) {
|
|
391
|
-
var _a;
|
|
392
|
-
return node._util.parentProperty === "init" && ((_a = node._util.parent) == null ? void 0 : _a.type) === "VariableDeclarator";
|
|
393
|
-
}
|
|
394
|
-
static isReturnArgument(node) {
|
|
395
|
-
var _a;
|
|
396
|
-
return node._util.parentProperty === "argument" && ((_a = node._util.parent) == null ? void 0 : _a.type) === "ReturnStatement";
|
|
397
|
-
}
|
|
398
516
|
static collectDependenceIds(node) {
|
|
399
517
|
const { _util } = node;
|
|
400
518
|
const { dependenceIds, holdingIdNameMap, children, dependenceIdsNoScope } = _util;
|
|
@@ -613,17 +731,17 @@ var _AstUtil = class {
|
|
|
613
731
|
callback(node.declaration);
|
|
614
732
|
return;
|
|
615
733
|
}
|
|
616
|
-
if (node.type === "ExportNamedDeclaration"
|
|
617
|
-
|
|
734
|
+
if (node.type === "ExportNamedDeclaration") {
|
|
735
|
+
Array.isArray(node.specifiers) && node.specifiers.forEach((specifier) => {
|
|
618
736
|
if (specifier.type === "ExportSpecifier") {
|
|
619
737
|
callback(specifier.local);
|
|
620
738
|
}
|
|
739
|
+
});
|
|
740
|
+
if (node.declaration) {
|
|
741
|
+
this.handleDeclaration(node.declaration, callback);
|
|
621
742
|
}
|
|
622
743
|
}
|
|
623
744
|
}
|
|
624
|
-
static expressionTypeIsIdentifier(exp) {
|
|
625
|
-
return (exp == null ? void 0 : exp.type) === "Identifier";
|
|
626
|
-
}
|
|
627
745
|
static collectExpressionIdentifiersShallow(exp, callback) {
|
|
628
746
|
if (!exp || exp.type === "ThisExpression") {
|
|
629
747
|
return;
|
|
@@ -796,50 +914,40 @@ var _AstUtil = class {
|
|
|
796
914
|
static isStandardAttribute(node) {
|
|
797
915
|
return node._util.parent.type === "JSXAttribute" && typeof node.name === "string" && this.standardAttributes.includes(node.name);
|
|
798
916
|
}
|
|
799
|
-
static getTopScopeNodesByLineNumberRange(mapFileLineToNodeSet, lineNumberStart, lineNumberEnd) {
|
|
917
|
+
static getTopScopeNodesByLineNumberRange(mapFileLineToNodeSet, lineNumberStart, lineNumberEnd, loose = false) {
|
|
800
918
|
const nodeSet = /* @__PURE__ */ new Set();
|
|
801
919
|
for (let i = lineNumberStart; i <= lineNumberEnd; i++) {
|
|
802
920
|
const astNode = mapFileLineToNodeSet.get(i);
|
|
803
921
|
if (!astNode) {
|
|
804
922
|
continue;
|
|
805
923
|
}
|
|
924
|
+
let added = false;
|
|
806
925
|
for (const nodeItem of astNode) {
|
|
807
926
|
const { startLine, endLine } = nodeItem._util;
|
|
808
927
|
if (startLine >= lineNumberStart && endLine <= lineNumberEnd) {
|
|
809
|
-
|
|
928
|
+
if (!["File", "Program"].includes(nodeItem.type)) {
|
|
929
|
+
nodeSet.add(nodeItem);
|
|
930
|
+
}
|
|
931
|
+
added = true;
|
|
932
|
+
}
|
|
933
|
+
}
|
|
934
|
+
if (!added && loose) {
|
|
935
|
+
const firstNode = [...astNode][0];
|
|
936
|
+
if (!["File", "Program"].includes(firstNode.type)) {
|
|
937
|
+
nodeSet.add(firstNode);
|
|
810
938
|
}
|
|
811
939
|
}
|
|
812
940
|
}
|
|
813
941
|
const collections = [...nodeSet].map((e) => e._util.nodeCollection).flat();
|
|
814
942
|
return [...nodeSet].filter((e) => !collections.includes(e));
|
|
815
943
|
}
|
|
816
|
-
static getTopScopeNodesByLineNumber(mapFileLineToNodeSet, lineNumber) {
|
|
817
|
-
const astNode = mapFileLineToNodeSet.get(lineNumber);
|
|
818
|
-
const lineOfNodes = [...new Set(astNode)].filter((e) => {
|
|
819
|
-
const { startLine, endLine } = e._util;
|
|
820
|
-
return startLine === lineNumber && endLine === lineNumber;
|
|
821
|
-
});
|
|
822
|
-
const collections = [...lineOfNodes].map((e) => e._util.nodeCollection).flat();
|
|
823
|
-
return lineOfNodes.filter((e) => !collections.includes(e));
|
|
824
|
-
}
|
|
825
|
-
static isSubNodeOfVariableDeclarator(node) {
|
|
826
|
-
const { ancestors } = node._util;
|
|
827
|
-
const typeList = ancestors.map((e) => e.type);
|
|
828
|
-
const index = typeList.lastIndexOf("VariableDeclarator");
|
|
829
|
-
if (index === -1) {
|
|
830
|
-
return false;
|
|
831
|
-
}
|
|
832
|
-
return ancestors.slice(index).every((ancestor) => ["Identifier", "ObjectPattern", "ArrayPattern"].includes(ancestor.type));
|
|
833
|
-
}
|
|
834
|
-
static createScopeContent(node) {
|
|
835
|
-
return [node._util.filePath, ":", node._util.startLine, "-", node._util.endLine, ":[", node.name || node.value, "]"].join("");
|
|
836
|
-
}
|
|
837
944
|
};
|
|
838
945
|
var AstUtil = _AstUtil;
|
|
839
946
|
AstUtil.invalidNodeKey = [
|
|
840
947
|
"comments",
|
|
841
948
|
"tokens"
|
|
842
949
|
];
|
|
950
|
+
AstUtil.EXPORT_DECLARATION_TYPES = ["FunctionDeclaration", "TSEnumDeclaration", "TSInterfaceDeclaration", "TSTypeAliasDeclaration", "ClassDeclaration"];
|
|
843
951
|
AstUtil.windowProperties = import_windowProperties.windowProperties;
|
|
844
952
|
AstUtil.intrinsicElements = import_intrinsicElements.intrinsicElements;
|
|
845
953
|
AstUtil.standardAttributes = import_intrinsicElements.standardAttributes;
|
|
@@ -135,7 +135,11 @@ var FileUtil = class {
|
|
|
135
135
|
const existFlag = import_fs.default.existsSync(filePath);
|
|
136
136
|
if (existFlag) {
|
|
137
137
|
const fileContent = import_fs.default.readFileSync(filePath, "utf8");
|
|
138
|
-
|
|
138
|
+
const [_, ast] = this.parseFile(filePath, fileContent);
|
|
139
|
+
if (ast) {
|
|
140
|
+
ast.__fileContent = fileContent;
|
|
141
|
+
}
|
|
142
|
+
return ast;
|
|
139
143
|
}
|
|
140
144
|
console.warn("文件不存在: " + filePath);
|
|
141
145
|
return null;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function createRandomStr(): string;
|
|
@@ -0,0 +1,38 @@
|
|
|
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/createRandomStr.ts
|
|
30
|
+
var createRandomStr_exports = {};
|
|
31
|
+
__export(createRandomStr_exports, {
|
|
32
|
+
default: () => createRandomStr
|
|
33
|
+
});
|
|
34
|
+
module.exports = __toCommonJS(createRandomStr_exports);
|
|
35
|
+
var import_dayjs = __toESM(require("dayjs"));
|
|
36
|
+
function createRandomStr() {
|
|
37
|
+
return (0, import_dayjs.default)().format("YYYYMDD_HHmmss") + Math.random().toString(36).slice(-5);
|
|
38
|
+
}
|
|
@@ -67,7 +67,7 @@ function getGitRepoUrlByToken(gitRepoUrl, gitlabToken) {
|
|
|
67
67
|
const gitlabDomain = urlObj.hostname;
|
|
68
68
|
const projectPath = urlObj.pathname.replace(/\.git/, "");
|
|
69
69
|
if (!gitlabToken) {
|
|
70
|
-
throw new Error("
|
|
70
|
+
throw new Error("未传入 GitLab accessToken");
|
|
71
71
|
}
|
|
72
72
|
if (!projectPath) {
|
|
73
73
|
throw new Error("请传入 GitLab 项目路径(如 dev-team/my-project)");
|
|
@@ -1 +1,6 @@
|
|
|
1
|
-
export declare function
|
|
1
|
+
export declare function createExportedNameToReferenceLocalSet(upstreamFileFullPaths: string[], parsedAlias: Record<string, string>, absPathPrefix: string, projectFilePaths: string[]): {
|
|
2
|
+
import2export: Record<string, string>;
|
|
3
|
+
export2export: Record<string, string>;
|
|
4
|
+
mapFilePathToExportAllSources: Record<string, string[]>;
|
|
5
|
+
indirectExportMembers: Record<string, string>;
|
|
6
|
+
};
|
|
@@ -29,54 +29,99 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
29
29
|
// src/util/report_util/createDependenceMap.ts
|
|
30
30
|
var createDependenceMap_exports = {};
|
|
31
31
|
__export(createDependenceMap_exports, {
|
|
32
|
-
|
|
32
|
+
createExportedNameToReferenceLocalSet: () => createExportedNameToReferenceLocalSet
|
|
33
33
|
});
|
|
34
34
|
module.exports = __toCommonJS(createDependenceMap_exports);
|
|
35
35
|
var import_getAstKitByFilePath = __toESM(require("../ast_util/getAstKitByFilePath"));
|
|
36
36
|
var import_filePathResolver = require("../ast_util/filePathResolver");
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
const
|
|
40
|
-
const
|
|
41
|
-
|
|
37
|
+
var import_path = require("path");
|
|
38
|
+
function createExportedNameToReferenceLocalSet(upstreamFileFullPaths, parsedAlias, absPathPrefix, projectFilePaths) {
|
|
39
|
+
const cwd = process.cwd();
|
|
40
|
+
const systemAbsPathPrefix = absPathPrefix.startsWith(cwd) ? absPathPrefix : (0, import_path.join)(cwd, absPathPrefix);
|
|
41
|
+
const localAlias = Object.fromEntries(Object.entries(parsedAlias).map(([k, v]) => [k, v.startsWith(systemAbsPathPrefix) ? v.replace(systemAbsPathPrefix, "") : v]));
|
|
42
|
+
const import2export = {};
|
|
43
|
+
const export2export = {};
|
|
44
|
+
const mapFilePathToExportAllSources = {};
|
|
45
|
+
const validFiles = upstreamFileFullPaths.filter((e) => [".ts", ".tsx", ".js", ".jsx", ".vue"].some((ext) => e.endsWith(ext) && !e.endsWith(".d.ts")));
|
|
46
|
+
for (const absFilePath of validFiles) {
|
|
42
47
|
const { mapUuidToNode } = (0, import_getAstKitByFilePath.default)(absFilePath, absPathPrefix, (travelNode) => ["ImportDeclaration", "ExportAllDeclaration", "ExportNamedDeclaration", "ExportDefaultDeclaration"].includes(travelNode.type));
|
|
43
48
|
const programNode = mapUuidToNode.get("Program");
|
|
44
49
|
if (!programNode) {
|
|
45
|
-
|
|
50
|
+
continue;
|
|
46
51
|
}
|
|
47
52
|
const { importedMember, exportedMember } = programNode._util;
|
|
48
|
-
const
|
|
49
|
-
const { importedMap, exportedMap } = mapFilePathToDependenceDetail.set(currentFilePath, mapFilePathToDependenceDetail.get(currentFilePath) || {
|
|
50
|
-
importedMap: /* @__PURE__ */ new Map(),
|
|
51
|
-
exportedMap: /* @__PURE__ */ new Map()
|
|
52
|
-
}).get(currentFilePath);
|
|
53
|
+
const relativeFilePath = absFilePath.replace(absPathPrefix, "");
|
|
53
54
|
for (const { sourcePath, members } of importedMember) {
|
|
54
|
-
const { fullPath, isExternal } = (0, import_filePathResolver.resolveImportPath)(localAlias, sourcePath,
|
|
55
|
-
const finalSourcePath =
|
|
56
|
-
const importedMemberDetail = importedMap.set(finalSourcePath, importedMap.get(finalSourcePath) || []).get(finalSourcePath);
|
|
55
|
+
const { fullPath, isExternal } = (0, import_filePathResolver.resolveImportPath)(localAlias, sourcePath, relativeFilePath);
|
|
56
|
+
const finalSourcePath = createRealSourcePath(sourcePath, isExternal, projectFilePaths, fullPath);
|
|
57
57
|
for (const { importedName: imported, localName: local } of members) {
|
|
58
|
-
|
|
58
|
+
const importLocal = `${relativeFilePath}#${local}`;
|
|
59
|
+
const exportedName = `${finalSourcePath}#${imported}`;
|
|
60
|
+
import2export[importLocal] = exportedName;
|
|
61
|
+
}
|
|
62
|
+
if (members.length === 0) {
|
|
63
|
+
import2export[relativeFilePath] = finalSourcePath;
|
|
59
64
|
}
|
|
60
65
|
}
|
|
61
66
|
for (const { sourcePath, members, ExportAllDeclaration } of exportedMember) {
|
|
62
|
-
const { fullPath, isExternal } = (0, import_filePathResolver.resolveImportPath)(localAlias, sourcePath,
|
|
63
|
-
const finalSourcePath =
|
|
64
|
-
const exportedMemberDetail = exportedMap.set(finalSourcePath, exportedMap.get(finalSourcePath) || []).get(finalSourcePath);
|
|
67
|
+
const { fullPath, isExternal } = (0, import_filePathResolver.resolveImportPath)(localAlias, sourcePath, relativeFilePath);
|
|
68
|
+
const finalSourcePath = createRealSourcePath(sourcePath, isExternal, projectFilePaths, fullPath);
|
|
65
69
|
for (const { exportedName: exported, localName: local } of members) {
|
|
66
|
-
|
|
70
|
+
const exportedName = `${relativeFilePath}#${exported}`;
|
|
71
|
+
const importLocal = `${finalSourcePath}#${local}`;
|
|
72
|
+
export2export[exportedName] = importLocal;
|
|
67
73
|
}
|
|
68
74
|
if (ExportAllDeclaration) {
|
|
69
|
-
|
|
75
|
+
mapFilePathToExportAllSources[relativeFilePath] = [...mapFilePathToExportAllSources[relativeFilePath] || [], finalSourcePath];
|
|
70
76
|
}
|
|
71
77
|
}
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
+
}
|
|
79
|
+
;
|
|
80
|
+
const indirectExportMembers = genIndirectExportMembers(mapFilePathToExportAllSources, export2export, import2export);
|
|
81
|
+
return {
|
|
82
|
+
import2export,
|
|
83
|
+
export2export,
|
|
84
|
+
mapFilePathToExportAllSources,
|
|
85
|
+
indirectExportMembers
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
function createRealSourcePath(sourcePath, isExternal, projectFilePaths, fullPath) {
|
|
89
|
+
return isExternal ? sourcePath : (fullPath == null ? void 0 : fullPath.find((p) => projectFilePaths.includes(p))) || sourcePath;
|
|
90
|
+
}
|
|
91
|
+
function genIndirectExportMembers(mapFilePathToExportAllSources, export2export, import2export) {
|
|
92
|
+
const export2exportEntries = Object.entries(export2export);
|
|
93
|
+
const potentialExportMap = {};
|
|
94
|
+
for (const exportAllSourcesKey in mapFilePathToExportAllSources) {
|
|
95
|
+
const exportAllSources = mapFilePathToExportAllSources[exportAllSourcesKey];
|
|
96
|
+
deepIterExportAllSources(exportAllSources, mapFilePathToExportAllSources, export2exportEntries, exportAllSourcesKey, potentialExportMap, [exportAllSourcesKey]);
|
|
97
|
+
}
|
|
98
|
+
const import2exportEntries = Object.entries(import2export);
|
|
99
|
+
return import2exportEntries.reduce((acc, [importMemberPath, exportMemberPath]) => {
|
|
100
|
+
const realExportPath = potentialExportMap[exportMemberPath];
|
|
101
|
+
if (realExportPath) {
|
|
102
|
+
acc[importMemberPath] = realExportPath;
|
|
103
|
+
}
|
|
104
|
+
return acc;
|
|
105
|
+
}, {});
|
|
106
|
+
}
|
|
107
|
+
function deepIterExportAllSources(exportAllSources, mapFilePathToExportAllSources, export2exportEntries, exportAllSourcesKey, potentialExportMap, travelledPaths) {
|
|
108
|
+
var _a;
|
|
109
|
+
for (const exportAllSource of exportAllSources) {
|
|
110
|
+
const existingExportMembers = export2exportEntries.filter(([exportPath]) => exportPath.startsWith(exportAllSource));
|
|
111
|
+
for (const [exportPath, exportRealSource] of existingExportMembers) {
|
|
112
|
+
const memberName = exportPath.split("#")[1];
|
|
113
|
+
if (memberName) {
|
|
114
|
+
potentialExportMap[`${exportAllSourcesKey}#${memberName}`] = exportRealSource;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
travelledPaths.push(exportAllSource);
|
|
118
|
+
const tmpList = (_a = mapFilePathToExportAllSources[exportAllSource]) == null ? void 0 : _a.filter((e) => !travelledPaths.includes(e));
|
|
119
|
+
if (Array.isArray(tmpList) && tmpList.length > 0) {
|
|
120
|
+
deepIterExportAllSources(tmpList, mapFilePathToExportAllSources, export2exportEntries, exportAllSource, potentialExportMap, travelledPaths);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
78
123
|
}
|
|
79
124
|
// Annotate the CommonJS export names for ESM import in node:
|
|
80
125
|
0 && (module.exports = {
|
|
81
|
-
|
|
126
|
+
createExportedNameToReferenceLocalSet
|
|
82
127
|
});
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { createDetectReport } from "../report_util";
|
|
2
|
+
import { createExportedNameToReferenceLocalSet } from "./createDependenceMap";
|
|
3
|
+
export default function filterEffectedCode(reports: ReturnType<typeof createDetectReport>, depMemberInfo: ReturnType<typeof createExportedNameToReferenceLocalSet>): ({
|
|
4
|
+
filePath: string;
|
|
5
|
+
type: "add";
|
|
6
|
+
effectedExports: string[];
|
|
7
|
+
usages: string[];
|
|
8
|
+
} | {
|
|
9
|
+
filePath: string;
|
|
10
|
+
type: "modify" | "delete";
|
|
11
|
+
effectedExports: string[];
|
|
12
|
+
usages: string[];
|
|
13
|
+
})[];
|
|
@@ -0,0 +1,72 @@
|
|
|
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/filterEffectedCode.ts
|
|
20
|
+
var filterEffectedCode_exports = {};
|
|
21
|
+
__export(filterEffectedCode_exports, {
|
|
22
|
+
default: () => filterEffectedCode
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(filterEffectedCode_exports);
|
|
25
|
+
function filterEffectedCode(reports, depMemberInfo) {
|
|
26
|
+
const { import2export, export2export } = depMemberInfo;
|
|
27
|
+
const import2exportEntries = Object.entries(import2export);
|
|
28
|
+
const export2exportEntries = Object.entries(export2export);
|
|
29
|
+
return reports.map((report) => {
|
|
30
|
+
const { filePath, type, topEffectedExportsRemoved, topEffectedExportsAdded } = report;
|
|
31
|
+
if (type === "add") {
|
|
32
|
+
const directUsages2 = getDirectUsages(filePath, import2exportEntries);
|
|
33
|
+
const effectedExports1 = getEffectedExportsOfAddedFile(filePath, import2exportEntries);
|
|
34
|
+
const effectedExports2 = getExportMembersOfFile(filePath, export2exportEntries).map((exportedName) => `${filePath}#${exportedName}`);
|
|
35
|
+
const effectedExports3 = [.../* @__PURE__ */ new Set([...effectedExports1, ...effectedExports2])];
|
|
36
|
+
const inDirectUsages2 = getIndirectUsages(filePath, import2exportEntries, export2exportEntries, effectedExports3);
|
|
37
|
+
return {
|
|
38
|
+
filePath,
|
|
39
|
+
type,
|
|
40
|
+
effectedExports: [...new Set(effectedExports3.map((e) => e.split("#")[1]))],
|
|
41
|
+
usages: [.../* @__PURE__ */ new Set([...directUsages2, ...inDirectUsages2])]
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
const effectedExports = [.../* @__PURE__ */ new Set([...topEffectedExportsRemoved, ...topEffectedExportsAdded])];
|
|
45
|
+
const directUsages = getDirectUsages(filePath, import2exportEntries, effectedExports);
|
|
46
|
+
const inDirectUsages = getIndirectUsages(filePath, import2exportEntries, export2exportEntries, effectedExports.map((exportedName) => `${filePath}#${exportedName}`));
|
|
47
|
+
return {
|
|
48
|
+
filePath,
|
|
49
|
+
type,
|
|
50
|
+
effectedExports,
|
|
51
|
+
usages: [.../* @__PURE__ */ new Set([...directUsages, ...inDirectUsages])]
|
|
52
|
+
};
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
function getEffectedExportsOfAddedFile(filePath, import2exportEntries) {
|
|
56
|
+
const exportedMembersUsing = import2exportEntries.filter((item) => item[1].startsWith(`${filePath}#`)).map((item) => item[1]);
|
|
57
|
+
return exportedMembersUsing;
|
|
58
|
+
}
|
|
59
|
+
function getDirectUsages(filePath, import2exportEntries, givenExports) {
|
|
60
|
+
if (givenExports) {
|
|
61
|
+
const currentExportPaths = givenExports.map((exportedName) => `${filePath}#${exportedName}`);
|
|
62
|
+
return import2exportEntries.filter((item) => currentExportPaths.includes(item[1])).map((item) => item[0]);
|
|
63
|
+
}
|
|
64
|
+
return import2exportEntries.filter((item) => item[1].startsWith(`${filePath}#`)).map((item) => item[0]);
|
|
65
|
+
}
|
|
66
|
+
function getIndirectUsages(filePath, import2exportEntries, export2exportEntries, givenExports) {
|
|
67
|
+
const indirectlyExportedMembers = export2exportEntries.filter((item) => givenExports.includes(item[1])).map((item) => item[0]);
|
|
68
|
+
return import2exportEntries.filter((item) => indirectlyExportedMembers.includes(item[1])).map((item) => item[0]);
|
|
69
|
+
}
|
|
70
|
+
function getExportMembersOfFile(filePath, export2exportEntries) {
|
|
71
|
+
return export2exportEntries.filter((item) => item[0].startsWith(`${filePath}#`)).map((item) => item[0].split("#")[1]);
|
|
72
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function filterEffectedExportMember(filePath: string, absPathPrefix: string, startLine: number, endLine: number): string[];
|
|
@@ -0,0 +1,43 @@
|
|
|
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/filterEffectedExportMember.ts
|
|
30
|
+
var filterEffectedExportMember_exports = {};
|
|
31
|
+
__export(filterEffectedExportMember_exports, {
|
|
32
|
+
default: () => filterEffectedExportMember
|
|
33
|
+
});
|
|
34
|
+
module.exports = __toCommonJS(filterEffectedExportMember_exports);
|
|
35
|
+
var import_getAstKitByFilePath = __toESM(require("../ast_util/getAstKitByFilePath"));
|
|
36
|
+
var import_AstUtil = __toESM(require("../ast_util/AstUtil"));
|
|
37
|
+
function filterEffectedExportMember(filePath, absPathPrefix, startLine, endLine) {
|
|
38
|
+
const astKit = (0, import_getAstKitByFilePath.default)(filePath, absPathPrefix);
|
|
39
|
+
const { mapFileLineToNodeSet } = astKit;
|
|
40
|
+
const topScopeNodes = import_AstUtil.default.getTopScopeNodesByLineNumberRange(mapFileLineToNodeSet, startLine, endLine);
|
|
41
|
+
const exportMembers = topScopeNodes.map((node) => import_AstUtil.default.findExportedMembersNameFromAncestors(node)).flat();
|
|
42
|
+
return [...new Set(exportMembers)];
|
|
43
|
+
}
|