js-code-detector 0.0.2 → 0.0.4

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/README.md CHANGED
@@ -14,9 +14,30 @@ $ npm run dev
14
14
  $ npm run build
15
15
  ```
16
16
 
17
- ## Options
17
+ ## 说明
18
+
19
+ 包用于检测项目当前分支 与 master分支的差异,并出具报告,展示代码改动的影响
20
+ 目前适用于 umi4.x 版本的项目
21
+
22
+ ## 使用
23
+
24
+ 1.项目安装 **js-code-detector**
25
+ 2.package.json 中添加 scripts 命令 ```detect```
26
+ 3.执行该命令可在当前项目目录下生成报告
27
+
28
+ ## 报告说明
29
+ - filePath 文件路径
30
+ - type 改动类型 add remove modify
31
+ - filesDependsOnMe 依赖当前文件的文件
32
+ - dangerIdentifiers 危险标识符(包括 1、找不到定义的, 2、函数的参数是一个函数,并进行调用的)
33
+ - blockReports 区块报告(每个diff块产生一个报告)
34
+ - kind 区块类型,目前把重点的类型单独提取处理,包括 "Import"|"Declaration"|"Assignment"|"SelfUpdate"|"Invoke"
35
+ - diff 区块的原始改动内容
36
+ - added 增加的标识符
37
+ - addedEffects 增加的标识符的影响
38
+ - causeBy 增加的标识符的来源
39
+ - effects 影响到的标识符的位置
18
40
 
19
- TODO
20
41
 
21
42
  ## LICENSE
22
43
 
package/bin/detect.js CHANGED
@@ -1,7 +1,8 @@
1
1
  #!/usr/bin/env node
2
2
 
3
+ const { writeGitDiffTxt, getGitRepositoryAndBranch, generateReport } = require('../dist/cjs/index')
3
4
  async function main() {
4
- const { gitUrl, branchName } = await require('../dist/cjs/index').getGitRepositoryAndBranch();
5
- require('../dist/cjs/index').writeGitDiffTxt(gitUrl, branchName);
5
+ const { gitUrl, branchName } = await getGitRepositoryAndBranch();
6
+ writeGitDiffTxt(gitUrl, branchName).then(reportContent => generateReport(reportContent));
6
7
  }
7
8
  main();
@@ -4,3 +4,4 @@ export declare function getGitRepositoryAndBranch(): Promise<{
4
4
  gitUrl: string;
5
5
  branchName: string;
6
6
  }>;
7
+ export declare function generateReport(jsonStr: string): void;
package/dist/cjs/index.js CHANGED
@@ -29,6 +29,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
29
29
  // src/index.ts
30
30
  var src_exports = {};
31
31
  __export(src_exports, {
32
+ generateReport: () => generateReport,
32
33
  getGitRepositoryAndBranch: () => getGitRepositoryAndBranch,
33
34
  umiPluginCallback: () => umiPluginCallback,
34
35
  writeGitDiffTxt: () => writeGitDiffTxt
@@ -42,7 +43,8 @@ var import_fs2 = require("fs");
42
43
  var import_report_util = require("./util/report_util");
43
44
  var import_utils = require("@umijs/utils");
44
45
  var import_dayjs = __toESM(require("dayjs"));
45
- var jsonName = "git_diff_report.json";
46
+ var import_createMdByJson = require("./util/report_util/createMdByJson");
47
+ var jsonName = "git_diff_report.md";
46
48
  async function umiPluginCallback(api) {
47
49
  const diff_txt = (0, import_fs.readFileSync)((0, import_path.join)(api.cwd, "git_diff.txt"), "utf-8");
48
50
  const gitDiffDetail = (0, import_format_git_diff_content.formatGitDiffContent)(diff_txt);
@@ -56,7 +58,8 @@ async function umiPluginCallback(api) {
56
58
  const usingFileNoPrefix = usingFiles.map((item) => item.filePath.replace(absPathPrefix, ""));
57
59
  const groupGitDiffLines = gitDiffDetail.filter((item) => usingFileNoPrefix.includes(item.filePath));
58
60
  const reports = (0, import_report_util.createDetectReport)({ groupGitDiffLines, tree, absPathPrefix });
59
- (0, import_fs2.writeFileSync)((0, import_path.join)(api.cwd, jsonName), JSON.stringify(reports, null, 2), { encoding: "utf-8", flag: "w" });
61
+ const mdContent = (0, import_createMdByJson.createMdByJson)(reports);
62
+ (0, import_fs2.writeFileSync)((0, import_path.join)(api.cwd, jsonName), mdContent, { encoding: "utf-8", flag: "w" });
60
63
  }
61
64
  var shellFileContent = `#!/bin/sh
62
65
  time=$(date "+%Y%-m%d")
@@ -102,8 +105,12 @@ async function getGitRepositoryAndBranch() {
102
105
  branchName: branch.stdout
103
106
  };
104
107
  }
108
+ function generateReport(jsonStr) {
109
+ (0, import_fs2.writeFileSync)((0, import_path.join)(process.cwd(), `${(0, import_dayjs.default)().format("YYYYMDD_HHmm")}_${jsonName}`), jsonStr, { encoding: "utf-8", flag: "w" });
110
+ }
105
111
  // Annotate the CommonJS export names for ESM import in node:
106
112
  0 && (module.exports = {
113
+ generateReport,
107
114
  getGitRepositoryAndBranch,
108
115
  umiPluginCallback,
109
116
  writeGitDiffTxt
@@ -49,7 +49,7 @@ export default class AstUtil {
49
49
  static isVarInit(node: AstNode): boolean;
50
50
  static isReturnArgument(node: AstNode): boolean;
51
51
  static collectDependenceIds(node: AstNode): void;
52
- static markDependenceIdAsCrossScope(node: AstNode, scopeId: AstNode): void;
52
+ static markDependenceIdCrossScope(node: AstNode, scopeId: AstNode): void;
53
53
  static isUseStateVarDec(node: AstNode): node is (AstNode & {
54
54
  type: "VariableDeclarator";
55
55
  id: {
@@ -92,7 +92,12 @@ export default class AstUtil {
92
92
  static isValidArrayNodeCollect(astNode: any): astNode is AstNode[];
93
93
  static isValidNodeCollect(astNode: AstNode): astNode is AstNode;
94
94
  static windowProperties: string[];
95
+ static intrinsicElements: string[];
96
+ static standardAttributes: string[];
97
+ static isUntrackedId(id: AstNode): boolean;
95
98
  static isPropertyOfGlobal(node: AstNode): boolean;
99
+ static isIntrinsicElement(node: AstNode): boolean | "" | undefined;
100
+ static isStandardAttribute(node: AstNode): boolean;
96
101
  static getTopScopeNodesByLineNumberRange(mapFileLineToNodeSet: Map<number, Set<AstNode>>, lineNumberStart: number, lineNumberEnd: number): AstNode[];
97
102
  static getTopScopeNodesByLineNumber(mapFileLineToNodeSet: Map<number, Set<AstNode>>, lineNumber: number): AstNode[];
98
103
  static isSubNodeOfVariableDeclarator(node: AstNode): boolean;
@@ -23,6 +23,7 @@ __export(AstUtil_exports, {
23
23
  });
24
24
  module.exports = __toCommonJS(AstUtil_exports);
25
25
  var import_windowProperties = require("./windowProperties");
26
+ var import_intrinsicElements = require("./intrinsicElements");
26
27
  var AstUtil = class {
27
28
  static getNodePath(node) {
28
29
  return [...node._util.ancestors, node].map((n) => n.type).join(":") + ":" + node.name;
@@ -185,12 +186,12 @@ var AstUtil = class {
185
186
  const firstPick = sameNameIds[0];
186
187
  if (firstPick) {
187
188
  firstPick._util.effectIds.add(dependenceId);
188
- this.markDependenceIdAsCrossScope(dependenceId, firstPick);
189
+ this.markDependenceIdCrossScope(dependenceId, firstPick);
189
190
  }
190
191
  }
191
192
  }
192
193
  }
193
- static markDependenceIdAsCrossScope(node, scopeId) {
194
+ static markDependenceIdCrossScope(node, scopeId) {
194
195
  var _a, _b, _c;
195
196
  const isParamsElement = scopeId._util.parentProperty === "params";
196
197
  const isCalleeId = ((_a = node._util.parent) == null ? void 0 : _a.type) === "CallExpression" && node._util.parentProperty === "callee";
@@ -425,6 +426,18 @@ var AstUtil = class {
425
426
  expression.name && callback(expression);
426
427
  } else if (exp.type === "JSXIdentifier") {
427
428
  callback(exp);
429
+ } else if (exp.type === "JSXAttribute") {
430
+ const value = exp.value;
431
+ value && this._deepFindIdOfExpression(value, callback);
432
+ } else if (exp.type === "JSXElement") {
433
+ const openingElement = exp.openingElement;
434
+ this._deepFindIdOfExpression(openingElement, callback);
435
+ } else if (exp.type === "JSXOpeningElement") {
436
+ const { name, attributes } = exp;
437
+ this._deepFindIdOfExpression(name, callback);
438
+ for (const attribute of attributes) {
439
+ this._deepFindIdOfExpression(attribute, callback);
440
+ }
428
441
  }
429
442
  }
430
443
  static getRootIdentifierOfMemberExpression(memExp) {
@@ -522,9 +535,19 @@ var AstUtil = class {
522
535
  static isValidNodeCollect(astNode) {
523
536
  return typeof (astNode == null ? void 0 : astNode.type) === "string";
524
537
  }
538
+ static isUntrackedId(id) {
539
+ return id._util.variableScope.length === 0 && !this.isPropertyOfGlobal(id) && !this.isIntrinsicElement(id) && !this.isStandardAttribute(id);
540
+ }
525
541
  static isPropertyOfGlobal(node) {
526
542
  return node.type === "Identifier" && !node._util.variableScope.length && this.windowProperties.includes(node.name);
527
543
  }
544
+ static isIntrinsicElement(node) {
545
+ var _a;
546
+ return node.type === "JSXIdentifier" && ((_a = node._util.parent) == null ? void 0 : _a.type) && ["JSXOpeningElement", "JSXClosingElement"].includes(node._util.parent.type) && this.intrinsicElements.includes(node.name);
547
+ }
548
+ static isStandardAttribute(node) {
549
+ return node._util.parent.type === "JSXAttribute" && this.standardAttributes.includes(node.name);
550
+ }
528
551
  static getTopScopeNodesByLineNumberRange(mapFileLineToNodeSet, lineNumberStart, lineNumberEnd) {
529
552
  const nodeSet = /* @__PURE__ */ new Set();
530
553
  for (let i = lineNumberStart; i <= lineNumberEnd; i++) {
@@ -569,3 +592,5 @@ AstUtil.invalidNodeKey = [
569
592
  "tokens"
570
593
  ];
571
594
  AstUtil.windowProperties = import_windowProperties.windowProperties;
595
+ AstUtil.intrinsicElements = import_intrinsicElements.intrinsicElements;
596
+ AstUtil.standardAttributes = import_intrinsicElements.standardAttributes;
@@ -0,0 +1,2 @@
1
+ export declare const intrinsicElements: string[];
2
+ export declare const standardAttributes: string[];
@@ -0,0 +1,495 @@
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/intrinsicElements.ts
20
+ var intrinsicElements_exports = {};
21
+ __export(intrinsicElements_exports, {
22
+ intrinsicElements: () => intrinsicElements,
23
+ standardAttributes: () => standardAttributes
24
+ });
25
+ module.exports = __toCommonJS(intrinsicElements_exports);
26
+ var intrinsicElements = [
27
+ "a",
28
+ "abbr",
29
+ "address",
30
+ "area",
31
+ "article",
32
+ "aside",
33
+ "audio",
34
+ "b",
35
+ "base",
36
+ "bdi",
37
+ "bdo",
38
+ "big",
39
+ "blockquote",
40
+ "body",
41
+ "br",
42
+ "button",
43
+ "canvas",
44
+ "caption",
45
+ "cite",
46
+ "code",
47
+ "col",
48
+ "colgroup",
49
+ "data",
50
+ "datalist",
51
+ "dd",
52
+ "del",
53
+ "details",
54
+ "dfn",
55
+ "dialog",
56
+ "div",
57
+ "dl",
58
+ "dt",
59
+ "em",
60
+ "embed",
61
+ "fieldset",
62
+ "figcaption",
63
+ "figure",
64
+ "footer",
65
+ "form",
66
+ "h1",
67
+ "h2",
68
+ "h3",
69
+ "h4",
70
+ "h5",
71
+ "h6",
72
+ "head",
73
+ "header",
74
+ "hgroup",
75
+ "hr",
76
+ "html",
77
+ "i",
78
+ "iframe",
79
+ "img",
80
+ "input",
81
+ "ins",
82
+ "kbd",
83
+ "keygen",
84
+ "label",
85
+ "legend",
86
+ "li",
87
+ "link",
88
+ "main",
89
+ "map",
90
+ "mark",
91
+ "menu",
92
+ "menuitem",
93
+ "meta",
94
+ "meter",
95
+ "nav",
96
+ "noindex",
97
+ "noscript",
98
+ "object",
99
+ "ol",
100
+ "optgroup",
101
+ "option",
102
+ "output",
103
+ "p",
104
+ "param",
105
+ "picture",
106
+ "pre",
107
+ "progress",
108
+ "q",
109
+ "rp",
110
+ "rt",
111
+ "ruby",
112
+ "s",
113
+ "samp",
114
+ "slot",
115
+ "script",
116
+ "section",
117
+ "select",
118
+ "small",
119
+ "source",
120
+ "span",
121
+ "strong",
122
+ "style",
123
+ "sub",
124
+ "summary",
125
+ "sup",
126
+ "table",
127
+ "template",
128
+ "tbody",
129
+ "td",
130
+ "textarea",
131
+ "tfoot",
132
+ "th",
133
+ "thead",
134
+ "time",
135
+ "title",
136
+ "tr",
137
+ "track",
138
+ "u",
139
+ "ul",
140
+ "video",
141
+ "wbr",
142
+ "webview",
143
+ "svg",
144
+ "animate",
145
+ "animateMotion",
146
+ "animateTransform",
147
+ "circle",
148
+ "clipPath",
149
+ "defs",
150
+ "desc",
151
+ "ellipse",
152
+ "feBlend",
153
+ "feColorMatrix",
154
+ "feComponentTransfer",
155
+ "feComposite",
156
+ "feConvolveMatrix",
157
+ "feDiffuseLighting",
158
+ "feDisplacementMap",
159
+ "feDistantLight",
160
+ "feDropShadow",
161
+ "feFlood",
162
+ "feFuncA",
163
+ "feFuncB",
164
+ "feFuncG",
165
+ "feFuncR",
166
+ "feGaussianBlur",
167
+ "feImage",
168
+ "feMerge",
169
+ "feMergeNode",
170
+ "feMorphology",
171
+ "feOffset",
172
+ "fePointLight",
173
+ "feSpecularLighting",
174
+ "feSpotLight",
175
+ "feTile",
176
+ "feTurbulence",
177
+ "filter",
178
+ "foreignObject",
179
+ "g",
180
+ "image",
181
+ "line",
182
+ "linearGradient",
183
+ "marker",
184
+ "mask",
185
+ "metadata",
186
+ "mpath",
187
+ "path",
188
+ "pattern",
189
+ "polygon",
190
+ "polyline",
191
+ "radialGradient",
192
+ "rect",
193
+ "stop",
194
+ "switch",
195
+ "symbol",
196
+ "text",
197
+ "textPath",
198
+ "tspan",
199
+ "use",
200
+ "view"
201
+ ];
202
+ var standardAttributes = [
203
+ "key",
204
+ "defaultChecked",
205
+ "defaultValue",
206
+ "accessKey",
207
+ "className",
208
+ "contentEditable",
209
+ "contextMenu",
210
+ "dir",
211
+ "draggable",
212
+ "hidden",
213
+ "id",
214
+ "lang",
215
+ "placeholder",
216
+ "slot",
217
+ "spellCheck",
218
+ "style",
219
+ "tabIndex",
220
+ "title",
221
+ "translate",
222
+ "children",
223
+ "dangerouslySetInnerHTML",
224
+ "onCopy",
225
+ "onCopyCapture",
226
+ "onCut",
227
+ "onCutCapture",
228
+ "onPaste",
229
+ "onPasteCapture",
230
+ "onCompositionEnd",
231
+ "onCompositionEndCapture",
232
+ "onCompositionStart",
233
+ "onCompositionStartCapture",
234
+ "onCompositionUpdate",
235
+ "onCompositionUpdateCapture",
236
+ "onFocus",
237
+ "onFocusCapture",
238
+ "onBlur",
239
+ "onBlurCapture",
240
+ "onChange",
241
+ "onChangeCapture",
242
+ "onBeforeInput",
243
+ "onBeforeInputCapture",
244
+ "onInput",
245
+ "onInputCapture",
246
+ "onReset",
247
+ "onResetCapture",
248
+ "onSubmit",
249
+ "onSubmitCapture",
250
+ "onInvalid",
251
+ "onInvalidCapture",
252
+ "onLoad",
253
+ "onLoadCapture",
254
+ "onError",
255
+ "onErrorCapture",
256
+ "onKeyDown",
257
+ "onKeyDownCapture",
258
+ "onKeyPress",
259
+ "onKeyPressCapture",
260
+ "onKeyUp",
261
+ "onKeyUpCapture",
262
+ "onAbort",
263
+ "onAbortCapture",
264
+ "onCanPlay",
265
+ "onCanPlayCapture",
266
+ "onCanPlayThrough",
267
+ "onCanPlayThroughCapture",
268
+ "onDurationChange",
269
+ "onDurationChangeCapture",
270
+ "onEmptied",
271
+ "onEmptiedCapture",
272
+ "onEncrypted",
273
+ "onEncryptedCapture",
274
+ "onEnded",
275
+ "onEndedCapture",
276
+ "onLoadedData",
277
+ "onLoadedDataCapture",
278
+ "onLoadedMetadata",
279
+ "onLoadedMetadataCapture",
280
+ "onLoadStart",
281
+ "onLoadStartCapture",
282
+ "onPause",
283
+ "onPauseCapture",
284
+ "onPlay",
285
+ "onPlayCapture",
286
+ "onPlaying",
287
+ "onPlayingCapture",
288
+ "onProgress",
289
+ "onProgressCapture",
290
+ "onRateChange",
291
+ "onRateChangeCapture",
292
+ "onSeeked",
293
+ "onSeekedCapture",
294
+ "onSeeking",
295
+ "onSeekingCapture",
296
+ "onStalled",
297
+ "onStalledCapture",
298
+ "onSuspend",
299
+ "onSuspendCapture",
300
+ "onTimeUpdate",
301
+ "onTimeUpdateCapture",
302
+ "onVolumeChange",
303
+ "onVolumeChangeCapture",
304
+ "onWaiting",
305
+ "onWaitingCapture",
306
+ "onAuxClick",
307
+ "onAuxClickCapture",
308
+ "onClick",
309
+ "onClickCapture",
310
+ "onContextMenu",
311
+ "onContextMenuCapture",
312
+ "onDoubleClick",
313
+ "onDoubleClickCapture",
314
+ "onDrag",
315
+ "onDragCapture",
316
+ "onDragEnd",
317
+ "onDragEndCapture",
318
+ "onDragEnter",
319
+ "onDragEnterCapture",
320
+ "onDragExit",
321
+ "onDragExitCapture",
322
+ "onDragLeave",
323
+ "onDragLeaveCapture",
324
+ "onDragOver",
325
+ "onDragOverCapture",
326
+ "onDragStart",
327
+ "onDragStartCapture",
328
+ "onDrop",
329
+ "onDropCapture",
330
+ "onMouseDown",
331
+ "onMouseDownCapture",
332
+ "onMouseEnter",
333
+ "onMouseLeave",
334
+ "onMouseMove",
335
+ "onMouseMoveCapture",
336
+ "onMouseOut",
337
+ "onMouseOutCapture",
338
+ "onMouseOver",
339
+ "onMouseOverCapture",
340
+ "onMouseUp",
341
+ "onMouseUpCapture",
342
+ "onSelect",
343
+ "onSelectCapture",
344
+ "onTouchCancel",
345
+ "onTouchCancelCapture",
346
+ "onTouchEnd",
347
+ "onTouchEndCapture",
348
+ "onTouchMove",
349
+ "onTouchMoveCapture",
350
+ "onTouchStart",
351
+ "onTouchStartCapture",
352
+ "onPointerDown",
353
+ "onPointerDownCapture",
354
+ "onPointerMove",
355
+ "onPointerMoveCapture",
356
+ "onPointerUp",
357
+ "onPointerUpCapture",
358
+ "onPointerCancel",
359
+ "onPointerCancelCapture",
360
+ "onPointerEnter",
361
+ "onPointerEnterCapture",
362
+ "onPointerLeave",
363
+ "onPointerLeaveCapture",
364
+ "onPointerOver",
365
+ "onPointerOverCapture",
366
+ "onPointerOut",
367
+ "onPointerOutCapture",
368
+ "onGotPointerCapture",
369
+ "onGotPointerCaptureCapture",
370
+ "onLostPointerCapture",
371
+ "onLostPointerCaptureCapture",
372
+ "onScroll",
373
+ "onScrollCapture",
374
+ "onWheel",
375
+ "onWheelCapture",
376
+ "onAnimationStart",
377
+ "onAnimationStartCapture",
378
+ "onAnimationEnd",
379
+ "onAnimationEndCapture",
380
+ "onAnimationIteration",
381
+ "onAnimationIterationCapture",
382
+ "onTransitionEnd",
383
+ "onTransitionEndCapture",
384
+ "accept",
385
+ "acceptCharset",
386
+ "action",
387
+ "allowFullScreen",
388
+ "allowTransparency",
389
+ "alt",
390
+ "as",
391
+ "async",
392
+ "autoComplete",
393
+ "autoFocus",
394
+ "autoPlay",
395
+ "capture",
396
+ "cellPadding",
397
+ "cellSpacing",
398
+ "charSet",
399
+ "challenge",
400
+ "checked",
401
+ "cite",
402
+ "classID",
403
+ "cols",
404
+ "colSpan",
405
+ "content",
406
+ "controls",
407
+ "coords",
408
+ "crossOrigin",
409
+ "data",
410
+ "dateTime",
411
+ "default",
412
+ "defer",
413
+ "disabled",
414
+ "download",
415
+ "encType",
416
+ "form",
417
+ "formAction",
418
+ "formEncType",
419
+ "formMethod",
420
+ "formNoValidate",
421
+ "formTarget",
422
+ "frameBorder",
423
+ "headers",
424
+ "height",
425
+ "high",
426
+ "href",
427
+ "hrefLang",
428
+ "htmlFor",
429
+ "httpEquiv",
430
+ "integrity",
431
+ "keyParams",
432
+ "keyType",
433
+ "kind",
434
+ "label",
435
+ "list",
436
+ "loop",
437
+ "low",
438
+ "manifest",
439
+ "marginHeight",
440
+ "marginWidth",
441
+ "max",
442
+ "maxLength",
443
+ "media",
444
+ "mediaGroup",
445
+ "method",
446
+ "min",
447
+ "minLength",
448
+ "multiple",
449
+ "muted",
450
+ "name",
451
+ "nonce",
452
+ "noValidate",
453
+ "open",
454
+ "optimum",
455
+ "pattern",
456
+ "placeholder",
457
+ "playsInline",
458
+ "poster",
459
+ "preload",
460
+ "readOnly",
461
+ "rel",
462
+ "required",
463
+ "reversed",
464
+ "rows",
465
+ "rowSpan",
466
+ "sandbox",
467
+ "scope",
468
+ "scoped",
469
+ "scrolling",
470
+ "seamless",
471
+ "selected",
472
+ "shape",
473
+ "size",
474
+ "sizes",
475
+ "span",
476
+ "src",
477
+ "srcDoc",
478
+ "srcLang",
479
+ "srcSet",
480
+ "start",
481
+ "step",
482
+ "summary",
483
+ "target",
484
+ "type",
485
+ "useMap",
486
+ "value",
487
+ "width",
488
+ "wmode",
489
+ "wrap"
490
+ ];
491
+ // Annotate the CommonJS export names for ESM import in node:
492
+ 0 && (module.exports = {
493
+ intrinsicElements,
494
+ standardAttributes
495
+ });
@@ -113,6 +113,12 @@ function pushBlockReport(blockReports, blockReport, programNode) {
113
113
  blockReport[key] = blockReport[key].filter((path) => !sameNames.includes(path));
114
114
  });
115
115
  }
116
+ if (blockReport.kind.startsWith("Other:")) {
117
+ ["added", "removed"].forEach((key) => {
118
+ const tailElements = blockReport[key].map((ele) => ele.split(":").at(-1)).filter(Boolean);
119
+ blockReport[key] = [...new Set(tailElements)];
120
+ });
121
+ }
116
122
  const addedEffectsList = mapNodePath(blockReport.addedEffects);
117
123
  const removedEffectsList = mapNodePath(blockReport.removedEffects);
118
124
  const addedEffectsPaths = addedEffectsList.map((item) => item.effects.map(({ path }) => path)).flat();
@@ -0,0 +1,2 @@
1
+ import { createDetectReport } from "../report_util";
2
+ export declare function createMdByJson(report: ReturnType<typeof createDetectReport>): string;
@@ -0,0 +1,74 @@
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/createMdByJson.ts
20
+ var createMdByJson_exports = {};
21
+ __export(createMdByJson_exports, {
22
+ createMdByJson: () => createMdByJson
23
+ });
24
+ module.exports = __toCommonJS(createMdByJson_exports);
25
+ var mapReportType = {
26
+ modify: "修改",
27
+ add: "新增",
28
+ delete: "删除"
29
+ };
30
+ function createMdByJson(report) {
31
+ return report.map(reportItemToMd).join("\n\n\n");
32
+ }
33
+ function reportItemToMd(report) {
34
+ const { filePath, filesDependsOnMe, type, dangerIdentifiers, blockReports } = report;
35
+ return [
36
+ `## ${filePath}`,
37
+ `- 类型: ${mapReportType[type]}`,
38
+ filesDependsOnMe.length > 0 ? `- 依赖${filePath}的文件` : "",
39
+ ...filesDependsOnMe.map((file, i) => `${i + 1}. ${file}`),
40
+ dangerIdentifiers.length > 0 ? `- 重点检查使用的变量` : "",
41
+ dangerIdentifiers.length > 0 ? `> ${dangerIdentifiers.join(", ")}` : "",
42
+ blockReports.length > 0 ? `### 代码块分析` : "",
43
+ ...blockReports.map(blockReportToMd)
44
+ ].filter(Boolean).join("\n\n");
45
+ }
46
+ function blockReportToMd(block) {
47
+ const {
48
+ kind,
49
+ diff_txt,
50
+ added,
51
+ addedEffects,
52
+ removed,
53
+ removedEffects
54
+ } = block;
55
+ return [
56
+ `#### 修改分类: ${kind}`,
57
+ `- 原始diff内容`,
58
+ `\`\`\`txt
59
+ ${diff_txt.join("\n")}
60
+ \`\`\``,
61
+ added.length > 0 ? `- 新增标识符` : "",
62
+ added.length > 0 ? `> ${added.join(", ")}` : "",
63
+ addedEffects.length > 0 ? `- 新增标识符影响` : "",
64
+ addedEffects.map(({ causeBy, effects }) => `> ${causeBy}相关: ${effects.join()}`).join("\n\n"),
65
+ removed.length > 0 ? `- 删除标识符` : "",
66
+ removed.length > 0 ? `> ${removed.join(", ")}` : "",
67
+ removedEffects.length > 0 ? `- 删除标识符影响` : "",
68
+ removedEffects.map(({ causeBy, effects }) => `> ${causeBy}相关: ${effects.join()}`).join("\n\n")
69
+ ].filter(Boolean).join("\n\n");
70
+ }
71
+ // Annotate the CommonJS export names for ESM import in node:
72
+ 0 && (module.exports = {
73
+ createMdByJson
74
+ });
@@ -0,0 +1 @@
1
+ export declare function fileIdentifierDetect(filePath: string, absPathPrefix: string): string[];
@@ -0,0 +1,59 @@
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/file_identifier_detect.ts
30
+ var file_identifier_detect_exports = {};
31
+ __export(file_identifier_detect_exports, {
32
+ fileIdentifierDetect: () => fileIdentifierDetect
33
+ });
34
+ module.exports = __toCommonJS(file_identifier_detect_exports);
35
+ var import_getAstKitByFilePath = __toESM(require("../ast_util/getAstKitByFilePath"));
36
+ var import_AstUtil = __toESM(require("../ast_util/AstUtil"));
37
+ function fileIdentifierDetect(filePath, absPathPrefix) {
38
+ const { mapUuidToNode } = (0, import_getAstKitByFilePath.default)(filePath, absPathPrefix);
39
+ const programNode = mapUuidToNode.get("Program");
40
+ const { dependenceIds } = programNode._util;
41
+ const ids = [...dependenceIds].filter((id) => {
42
+ return import_AstUtil.default.isUntrackedId(id) || id._util.crossScope.size > 0;
43
+ });
44
+ return ids.map((id) => {
45
+ const { name, _util } = id;
46
+ const { crossScope } = _util;
47
+ const isUntracked = import_AstUtil.default.isUntrackedId(id);
48
+ const notFoundInfo = isUntracked ? `${name}:「${_util.startLine}:${_util.startColumn},${_util.endLine}:${_util.endColumn}」` : "";
49
+ const dangerScopeInfo = [...crossScope].map((scope) => {
50
+ const { _util: _util2 } = scope;
51
+ return `${scope.name}:「${_util2.startLine}:${_util2.startColumn},${_util2.endLine}:${_util2.endColumn}」`;
52
+ }).join(",");
53
+ return [notFoundInfo, dangerScopeInfo].filter(Boolean).join(",");
54
+ });
55
+ }
56
+ // Annotate the CommonJS export names for ESM import in node:
57
+ 0 && (module.exports = {
58
+ fileIdentifierDetect
59
+ });
@@ -1,4 +1,12 @@
1
1
  import { GitDiffDetail } from "./format_git_diff_content";
2
+ import { BlockReport } from "./report_util/code_block_detect";
3
+ export type DetectReport = {
4
+ filePath: string;
5
+ type: "modify" | "add" | "delete";
6
+ filesDependsOnMe: string[];
7
+ dangerIdentifiers: string[];
8
+ blockReports: BlockReport[];
9
+ };
2
10
  type Arg = {
3
11
  groupGitDiffLines: GitDiffDetail[];
4
12
  tree: Record<string, string[]>;
@@ -23,7 +31,8 @@ export declare function createDetectReport(arg: Arg): {
23
31
  kind: "Import" | "Declaration" | "Assignment" | "SelfUpdate" | "Invoke" | "Other" | "Never";
24
32
  }[];
25
33
  filePath: string;
26
- type: "add" | "delete" | "modify";
34
+ type: "modify" | "add" | "delete";
27
35
  filesDependsOnMe: string[];
36
+ dangerIdentifiers: string[];
28
37
  }[];
29
38
  export {};
@@ -35,6 +35,7 @@ module.exports = __toCommonJS(report_util_exports);
35
35
  var import_code_block_detect = __toESM(require("./report_util/code_block_detect"));
36
36
  var import_getAstKitByFilePath = __toESM(require("./ast_util/getAstKitByFilePath"));
37
37
  var import_AstUtil = __toESM(require("./ast_util/AstUtil"));
38
+ var import_file_identifier_detect = require("./report_util/file_identifier_detect");
38
39
  function createDetectReport(arg) {
39
40
  const { groupGitDiffLines, tree, absPathPrefix } = arg;
40
41
  const reports = [];
@@ -48,10 +49,12 @@ function createDetectReport(arg) {
48
49
  filePath,
49
50
  type,
50
51
  filesDependsOnMe,
52
+ dangerIdentifiers: [],
51
53
  blockReports: []
52
54
  };
53
55
  reports.push(reportItem);
54
56
  }
57
+ reportItem.dangerIdentifiers = (0, import_file_identifier_detect.fileIdentifierDetect)(filePath, absPathPrefix);
55
58
  if (type === "modify") {
56
59
  (0, import_code_block_detect.default)({ gitDiffItem: item, absPathPrefix, blockReports: reportItem.blockReports });
57
60
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "js-code-detector",
3
- "version": "0.0.2",
3
+ "version": "0.0.4",
4
4
  "description": "",
5
5
  "main": "dist/cjs/index.js",
6
6
  "types": "dist/cjs/index.d.ts",