@devflow-tools/plugin-nest 0.11.0 → 0.12.6
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/package.json +2 -2
- package/dist/analyzers/diagnose-bug.d.ts +0 -7
- package/dist/analyzers/diagnose-bug.d.ts.map +0 -1
- package/dist/analyzers/diagnose-bug.js +0 -66
- package/dist/analyzers/diagnose-bug.js.map +0 -1
- package/dist/analyzers/new-module.d.ts +0 -3
- package/dist/analyzers/new-module.d.ts.map +0 -1
- package/dist/analyzers/new-module.js +0 -108
- package/dist/analyzers/new-module.js.map +0 -1
- package/dist/analyzers/types.d.ts +0 -19
- package/dist/analyzers/types.d.ts.map +0 -1
- package/dist/analyzers/types.js +0 -2
- package/dist/analyzers/types.js.map +0 -1
- package/dist/index.d.ts +0 -3
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js +0 -1626
- package/dist/index.js.map +0 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@devflow-tools/plugin-nest",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.12.6",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -26,5 +26,5 @@
|
|
|
26
26
|
"files": [
|
|
27
27
|
"dist"
|
|
28
28
|
],
|
|
29
|
-
"gitHead": "
|
|
29
|
+
"gitHead": "d544427472016eb332c6c2107f0fc98d8ae59c14"
|
|
30
30
|
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"diagnose-bug.d.ts","sourceRoot":"","sources":["../../src/analyzers/diagnose-bug.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAEjD,wBAAgB,WAAW,CAAC,KAAK,EAAE;IAAE,WAAW,EAAE,MAAM,CAAC;IAAC,YAAY,EAAE,MAAM,CAAC;IAAC,UAAU,CAAC,EAAE,MAAM,CAAA;CAAE,GAAG,cAAc,CAgDrH"}
|
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
import { readFileSync } from 'fs';
|
|
2
|
-
import { readdirSync, statSync } from 'fs';
|
|
3
|
-
import { join, relative } from 'path';
|
|
4
|
-
export function diagnoseBug(input) {
|
|
5
|
-
const { projectRoot, errorMessage } = input;
|
|
6
|
-
const rootCauses = [];
|
|
7
|
-
const files = scanProjectFiles(projectRoot);
|
|
8
|
-
for (const file of files) {
|
|
9
|
-
const content = readFileSync(file, 'utf-8');
|
|
10
|
-
const relPath = relative(projectRoot, file);
|
|
11
|
-
const lines = content.split('\n');
|
|
12
|
-
// Check DI issues
|
|
13
|
-
if (/inject|provider|module|can't resolve/.test(errorMessage.toLowerCase())) {
|
|
14
|
-
for (let i = 0; i < lines.length; i++) {
|
|
15
|
-
// Check for missing @Injectable() decorator
|
|
16
|
-
if (/export\s+class\s+\w+Service/.test(lines[i]) && !content.includes('@Injectable()')) {
|
|
17
|
-
rootCauses.push({
|
|
18
|
-
probability: 'high',
|
|
19
|
-
description: 'Service 缺少 @Injectable() 装饰器',
|
|
20
|
-
file: relPath,
|
|
21
|
-
line: i + 1,
|
|
22
|
-
fix: '添加 @Injectable() 装饰器',
|
|
23
|
-
});
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
return {
|
|
29
|
-
success: true,
|
|
30
|
-
summary: `分析错误 "${errorMessage.substring(0, 50)}...",发现 ${rootCauses.length} 个可能原因`,
|
|
31
|
-
data: { rootCauses },
|
|
32
|
-
findings: rootCauses.map(rc => ({
|
|
33
|
-
severity: rc.probability === 'high' ? 'critical' : 'warning',
|
|
34
|
-
category: 'bug-root-cause',
|
|
35
|
-
title: rc.description,
|
|
36
|
-
description: rc.evidence ?? rc.description,
|
|
37
|
-
file: rc.file,
|
|
38
|
-
line: rc.line,
|
|
39
|
-
suggestion: rc.fix,
|
|
40
|
-
})),
|
|
41
|
-
};
|
|
42
|
-
}
|
|
43
|
-
function scanProjectFiles(root) {
|
|
44
|
-
const files = [];
|
|
45
|
-
function walk(dir) {
|
|
46
|
-
try {
|
|
47
|
-
for (const entry of readdirSync(dir)) {
|
|
48
|
-
if (['node_modules', 'dist', 'build', '.git'].includes(entry))
|
|
49
|
-
continue;
|
|
50
|
-
const fullPath = join(dir, entry);
|
|
51
|
-
try {
|
|
52
|
-
const stat = statSync(fullPath);
|
|
53
|
-
if (stat.isDirectory())
|
|
54
|
-
walk(fullPath);
|
|
55
|
-
else if (/\.tsx?$/.test(entry))
|
|
56
|
-
files.push(fullPath);
|
|
57
|
-
}
|
|
58
|
-
catch { }
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
catch { }
|
|
62
|
-
}
|
|
63
|
-
walk(root);
|
|
64
|
-
return files;
|
|
65
|
-
}
|
|
66
|
-
//# sourceMappingURL=diagnose-bug.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"diagnose-bug.js","sourceRoot":"","sources":["../../src/analyzers/diagnose-bug.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,IAAI,CAAC;AAClC,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,IAAI,CAAC;AAC3C,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,MAAM,CAAC;AAGtC,MAAM,UAAU,WAAW,CAAC,KAAyE;IACnG,MAAM,EAAE,WAAW,EAAE,YAAY,EAAE,GAAG,KAAK,CAAC;IAC5C,MAAM,UAAU,GAOX,EAAE,CAAC;IAER,MAAM,KAAK,GAAG,gBAAgB,CAAC,WAAW,CAAC,CAAC;IAC5C,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QACzB,MAAM,OAAO,GAAG,YAAY,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;QAC5C,MAAM,OAAO,GAAG,QAAQ,CAAC,WAAW,EAAE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,EAAE,CAAC,GAAG;SACnB,CAAC,CAAC;KACJ,CAAC;AACJ,CAAC;AAED,SAAS,gBAAgB,CAAC,IAAY;IACpC,MAAM,KAAK,GAAa,EAAE,CAAC;IAC3B,SAAS,IAAI,CAAC,GAAW;QACvB,IAAI,CAAC;YACH,KAAK,MAAM,KAAK,IAAI,WAAW,CAAC,GAAG,CAAC,EAAE,CAAC;gBACrC,IAAI,CAAC,cAAc,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC;oBAAE,SAAS;gBACxE,MAAM,QAAQ,GAAG,IAAI,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;gBAClC,IAAI,CAAC;oBACH,MAAM,IAAI,GAAG,QAAQ,CAAC,QAAQ,CAAC,CAAC;oBAChC,IAAI,IAAI,CAAC,WAAW,EAAE;wBAAE,IAAI,CAAC,QAAQ,CAAC,CAAC;yBAClC,IAAI,SAAS,CAAC,IAAI,CAAC,KAAK,CAAC;wBAAE,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;gBACvD,CAAC;gBAAC,MAAM,CAAC,CAAA,CAAC;YACZ,CAAC;QACH,CAAC;QAAC,MAAM,CAAC,CAAA,CAAC;IACZ,CAAC;IACD,IAAI,CAAC,IAAI,CAAC,CAAC;IACX,OAAO,KAAK,CAAC;AACf,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"new-module.d.ts","sourceRoot":"","sources":["../../src/analyzers/new-module.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAEjD,wBAAgB,cAAc,CAAC,UAAU,EAAE,MAAM,GAAG,cAAc,CAgHjE"}
|
|
@@ -1,108 +0,0 @@
|
|
|
1
|
-
export function generateModule(moduleName) {
|
|
2
|
-
const name = moduleName.charAt(0).toUpperCase() + moduleName.slice(1);
|
|
3
|
-
const nameLower = name.toLowerCase();
|
|
4
|
-
const moduleCode = `import { Module } from '@nestjs/common';
|
|
5
|
-
import { ${name}Controller } from './${nameLower}.controller';
|
|
6
|
-
import { ${name}Service } from './${nameLower}.service';
|
|
7
|
-
|
|
8
|
-
@Module({
|
|
9
|
-
controllers: [${name}Controller],
|
|
10
|
-
providers: [${name}Service],
|
|
11
|
-
exports: [${name}Service],
|
|
12
|
-
})
|
|
13
|
-
export class ${name}Module {}
|
|
14
|
-
`;
|
|
15
|
-
const controllerCode = `import { Controller, Get, Post, Body, Param } from '@nestjs/common';
|
|
16
|
-
import { ${name}Service } from './${nameLower}.service';
|
|
17
|
-
|
|
18
|
-
@Controller('${nameLower}')
|
|
19
|
-
export class ${name}Controller {
|
|
20
|
-
constructor(private readonly ${nameLower}Service: ${name}Service) {}
|
|
21
|
-
|
|
22
|
-
@Get()
|
|
23
|
-
findAll() {
|
|
24
|
-
return this.${nameLower}Service.findAll();
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
@Get(':id')
|
|
28
|
-
findOne(@Param('id') id: string) {
|
|
29
|
-
return this.${nameLower}Service.findOne(id);
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
@Post()
|
|
33
|
-
create(@Body() data: any) {
|
|
34
|
-
return this.${nameLower}Service.create(data);
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
`;
|
|
38
|
-
const serviceCode = `import { Injectable } from '@nestjs/common';
|
|
39
|
-
|
|
40
|
-
@Injectable()
|
|
41
|
-
export class ${name}Service {
|
|
42
|
-
findAll() {
|
|
43
|
-
return [];
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
findOne(id: string) {
|
|
47
|
-
return { id };
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
create(data: any) {
|
|
51
|
-
return data;
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
`;
|
|
55
|
-
const dtoCode = `export class Create${name}Dto {
|
|
56
|
-
name: string;
|
|
57
|
-
description?: string;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
export class ${name}Dto {
|
|
61
|
-
id: string;
|
|
62
|
-
name: string;
|
|
63
|
-
description?: string;
|
|
64
|
-
}
|
|
65
|
-
`;
|
|
66
|
-
const testCode = `import { Test, TestingModule } from '@nestjs/testing';
|
|
67
|
-
import { ${name}Controller } from './${nameLower}.controller';
|
|
68
|
-
import { ${name}Service } from './${nameLower}.service';
|
|
69
|
-
|
|
70
|
-
describe('${name}Controller', () => {
|
|
71
|
-
let controller: ${name}Controller;
|
|
72
|
-
|
|
73
|
-
beforeEach(async () => {
|
|
74
|
-
const module: TestingModule = await Test.createTestingModule({
|
|
75
|
-
controllers: [${name}Controller],
|
|
76
|
-
providers: [${name}Service],
|
|
77
|
-
}).compile();
|
|
78
|
-
|
|
79
|
-
controller = module.get<${name}Controller>(${name}Controller);
|
|
80
|
-
});
|
|
81
|
-
|
|
82
|
-
it('should be defined', () => {
|
|
83
|
-
expect(controller).toBeDefined();
|
|
84
|
-
});
|
|
85
|
-
});
|
|
86
|
-
`;
|
|
87
|
-
return {
|
|
88
|
-
success: true,
|
|
89
|
-
summary: `生成 ${name} 模块(Controller + Service + Module + DTO + Test)`,
|
|
90
|
-
data: {
|
|
91
|
-
generatedCode: {
|
|
92
|
-
module: moduleCode,
|
|
93
|
-
controller: controllerCode,
|
|
94
|
-
service: serviceCode,
|
|
95
|
-
dto: dtoCode,
|
|
96
|
-
test: testCode,
|
|
97
|
-
},
|
|
98
|
-
filesToCreate: [
|
|
99
|
-
{ path: `src/${nameLower}/${nameLower}.module.ts`, type: 'module' },
|
|
100
|
-
{ path: `src/${nameLower}/${nameLower}.controller.ts`, type: 'controller' },
|
|
101
|
-
{ path: `src/${nameLower}/${nameLower}.service.ts`, type: 'service' },
|
|
102
|
-
{ path: `src/${nameLower}/dto/create-${nameLower}.dto.ts`, type: 'dto' },
|
|
103
|
-
{ path: `src/${nameLower}/${nameLower}.controller.spec.ts`, type: 'test' },
|
|
104
|
-
],
|
|
105
|
-
},
|
|
106
|
-
};
|
|
107
|
-
}
|
|
108
|
-
//# sourceMappingURL=new-module.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"new-module.js","sourceRoot":"","sources":["../../src/analyzers/new-module.ts"],"names":[],"mappings":"AAEA,MAAM,UAAU,cAAc,CAAC,UAAkB;IAC/C,MAAM,IAAI,GAAG,UAAU,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,GAAG,UAAU,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;IACtE,MAAM,SAAS,GAAG,IAAI,CAAC,WAAW,EAAE,CAAC;IAErC,MAAM,UAAU,GAAG;WACV,IAAI,wBAAwB,SAAS;WACrC,IAAI,qBAAqB,SAAS;;;kBAG3B,IAAI;gBACN,IAAI;cACN,IAAI;;eAEH,IAAI;CAClB,CAAC;IAEA,MAAM,cAAc,GAAG;WACd,IAAI,qBAAqB,SAAS;;eAE9B,SAAS;eACT,IAAI;iCACc,SAAS,YAAY,IAAI;;;;kBAIxC,SAAS;;;;;kBAKT,SAAS;;;;;kBAKT,SAAS;;;CAG1B,CAAC;IAEA,MAAM,WAAW,GAAG;;;eAGP,IAAI;;;;;;;;;;;;;CAalB,CAAC;IAEA,MAAM,OAAO,GAAG,sBAAsB,IAAI;;;;;eAK7B,IAAI;;;;;CAKlB,CAAC;IAEA,MAAM,QAAQ,GAAG;WACR,IAAI,wBAAwB,SAAS;WACrC,IAAI,qBAAqB,SAAS;;YAEjC,IAAI;oBACI,IAAI;;;;sBAIF,IAAI;oBACN,IAAI;;;8BAGM,IAAI,eAAe,IAAI;;;;;;;CAOpD,CAAC;IAEA,OAAO;QACL,OAAO,EAAE,IAAI;QACb,OAAO,EAAE,MAAM,IAAI,iDAAiD;QACpE,IAAI,EAAE;YACJ,aAAa,EAAE;gBACb,MAAM,EAAE,UAAU;gBAClB,UAAU,EAAE,cAAc;gBAC1B,OAAO,EAAE,WAAW;gBACpB,GAAG,EAAE,OAAO;gBACZ,IAAI,EAAE,QAAQ;aACf;YACD,aAAa,EAAE;gBACb,EAAE,IAAI,EAAE,OAAO,SAAS,IAAI,SAAS,YAAY,EAAE,IAAI,EAAE,QAAQ,EAAE;gBACnE,EAAE,IAAI,EAAE,OAAO,SAAS,IAAI,SAAS,gBAAgB,EAAE,IAAI,EAAE,YAAY,EAAE;gBAC3E,EAAE,IAAI,EAAE,OAAO,SAAS,IAAI,SAAS,aAAa,EAAE,IAAI,EAAE,SAAS,EAAE;gBACrE,EAAE,IAAI,EAAE,OAAO,SAAS,eAAe,SAAS,SAAS,EAAE,IAAI,EAAE,KAAK,EAAE;gBACxE,EAAE,IAAI,EAAE,OAAO,SAAS,IAAI,SAAS,qBAAqB,EAAE,IAAI,EAAE,MAAM,EAAE;aAC3E;SACF;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
export interface AnalysisResult {
|
|
2
|
-
success: boolean;
|
|
3
|
-
summary: string;
|
|
4
|
-
findings?: Finding[];
|
|
5
|
-
metrics?: Record<string, number | string>;
|
|
6
|
-
data?: unknown;
|
|
7
|
-
error?: string;
|
|
8
|
-
}
|
|
9
|
-
export interface Finding {
|
|
10
|
-
severity: 'critical' | 'warning' | 'info' | 'suggestion';
|
|
11
|
-
category: string;
|
|
12
|
-
title: string;
|
|
13
|
-
description: string;
|
|
14
|
-
file?: string;
|
|
15
|
-
line?: number;
|
|
16
|
-
suggestion?: string;
|
|
17
|
-
codeSnippet?: string;
|
|
18
|
-
}
|
|
19
|
-
//# sourceMappingURL=types.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/analyzers/types.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,cAAc;IAC7B,OAAO,EAAE,OAAO,CAAC;IACjB,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,CAAC,EAAE,OAAO,EAAE,CAAC;IACrB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAAC,CAAC;IAC1C,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,WAAW,OAAO;IACtB,QAAQ,EAAE,UAAU,GAAG,SAAS,GAAG,MAAM,GAAG,YAAY,CAAC;IACzD,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE,MAAM,CAAC;IACd,WAAW,EAAE,MAAM,CAAC;IACpB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB"}
|
package/dist/analyzers/types.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/analyzers/types.ts"],"names":[],"mappings":""}
|
package/dist/index.d.ts
DELETED
package/dist/index.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAGxD,eAAO,MAAM,UAAU,EAAE,aA6lDxB,CAAC"}
|