@angular-modernizer/plugin-analyzer 0.3.0 → 1.1.0

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
@@ -4,20 +4,17 @@ Framework detection and project structure analysis plugin for the Angular Modern
4
4
 
5
5
  ## Overview
6
6
 
7
- The `@angular-modernizer/plugin-analyzer` package provides analysis rules for understanding Angular project structures, detecting build frameworks, and analyzing architectural patterns. This plugin powers the `analyze-project` MCP tool.
7
+ The `@angular-modernizer/plugin-analyzer` package provides general analysis rules for Angular projects. It currently ships one rule, the framework detector. The `analyze-project` MCP tool runs this plugin (registered under the name `analyzer`).
8
8
 
9
9
  ## Architecture
10
10
 
11
- This plugin follows the API-driven plugin pattern, using `PublicApi` for all analysis operations:
11
+ This plugin follows the plugin contract from `@angular-modernizer/plugin-system`. The framework detector needs no `PublicApi` tool; it reads the project and its file system from the context:
12
12
 
13
13
  ```typescript
14
14
  class FrameworkDetectorRule implements AnalysisRule {
15
- analyze(context: AnalysisContext) {
16
- const { api, sourceFile } = context;
17
-
18
- const dependencies =
19
- api.analysis.dependencyAnalyzer.analyzeDependencies(sourceFile);
20
- // analysis logic
15
+ async analyze(context: AnalysisContext): Promise<AnalysisResult[]> {
16
+ const { project, filePath } = context;
17
+ // checks nx.json and angular.json in the project root
21
18
  }
22
19
  }
23
20
  ```
@@ -26,78 +23,35 @@ class FrameworkDetectorRule implements AnalysisRule {
26
23
 
27
24
  ### FrameworkDetectorRule
28
25
 
29
- **Rule ID:** `analyzer:framework-detection`
26
+ **Rule ID:** `analyzer:framework-detector`
30
27
 
31
- Detects whether a project uses Angular CLI or Nx, and identifies the technology stack.
28
+ Detects whether a project uses Angular CLI or Nx from the configuration files in the project root (the directory of the tsconfig, otherwise the directory of the analyzed file).
32
29
 
33
30
  **Detection Priority:**
34
31
 
35
- 1. Nx — `nx.json` present, workspace structure
36
- 2. Angular CLI — `angular.json` present, standard structure
37
- 3. Unknown — no clear indicators
32
+ 1. Nx: `nx.json` present
33
+ 2. Angular CLI: `angular.json` present
34
+ 3. Unknown: neither file present
38
35
 
39
36
  **Example Output:**
40
37
 
41
38
  ```json
42
- {
43
- "ruleId": "framework-detector",
44
- "violations": [],
45
- "metadata": {
46
- "framework": "angular-cli",
47
- "confidence": 0.95,
48
- "evidence": [
49
- "angular.json detected",
50
- "@angular/core in package.json",
51
- "src/main.ts with bootstrapApplication"
52
- ],
53
- "projectType": "application",
54
- "technologyStack": {
55
- "angular": "17.x",
56
- "typescript": "5.x",
57
- "rxjs": "7.x"
39
+ [
40
+ {
41
+ "ruleId": "analyzer:framework-detector",
42
+ "message": "Project uses Angular CLI",
43
+ "filePath": "/path/to/project/src/main.ts",
44
+ "metadata": {
45
+ "framework": "Angular CLI",
46
+ "hasNxConfig": false,
47
+ "hasAngularConfig": true,
48
+ "projectRoot": "/path/to/project"
58
49
  }
59
50
  }
60
- }
61
- ```
62
-
63
- **Detection Logic:**
64
-
65
- ```typescript
66
- class FrameworkDetectorRule implements AnalysisRule {
67
- async analyze(context: AnalysisContext): Promise<AnalysisResult> {
68
- const { project } = context;
69
-
70
- const nxIndicators = await this.checkNxIndicators(project);
71
- const angularIndicators = await this.checkAngularIndicators(project);
72
- const framework = this.determineFramework(nxIndicators, angularIndicators);
73
- const structure = await this.analyzeProjectStructure(project);
74
-
75
- return {
76
- ruleId: this.id,
77
- violations: [],
78
- metadata: {
79
- framework: framework.type,
80
- confidence: framework.confidence,
81
- evidence: framework.evidence,
82
- projectType: structure.type,
83
- technologyStack: structure.stack,
84
- },
85
- };
86
- }
87
- }
51
+ ]
88
52
  ```
89
53
 
90
- ### LayerDetectorRule (Planned)
91
-
92
- **Rule ID:** `layer-detector`
93
-
94
- Analyzes project layering and architectural boundaries via directory structure and import patterns.
95
-
96
- ### TechnologyStackAnalyzerRule (Planned)
97
-
98
- **Rule ID:** `technology-stack-analyzer`
99
-
100
- Identifies technologies and versions used in the project via `package.json` analysis.
54
+ `framework` is `Nx`, `Angular CLI` or `Unknown`.
101
55
 
102
56
  ## Usage Examples
103
57
 
@@ -105,6 +59,8 @@ Identifies technologies and versions used in the project via `package.json` anal
105
59
 
106
60
  ```typescript
107
61
  import { Kernel, RealFileSystemAdapter } from '@angular-modernizer/core';
62
+ import { createPublicApi } from '@angular-modernizer/api';
63
+ import { ContextFactory } from '@angular-modernizer/plugin-system';
108
64
  import { AnalyzerPlugin } from '@angular-modernizer/plugin-analyzer';
109
65
 
110
66
  const kernel = new Kernel({
@@ -115,29 +71,28 @@ const kernel = new Kernel({
115
71
 
116
72
  await kernel.initialize();
117
73
 
118
- const plugin = kernel.getPlugin('@angular-modernizer/plugin-analyzer');
119
- const rules = plugin.getAnalysisRules();
120
- const frameworkRule = rules.find((r) => r.id === 'framework-detector');
74
+ const plugin = kernel.getPlugin('analyzer')!;
75
+ const frameworkRule = plugin
76
+ .getAnalysisRules()
77
+ .find((r) => r.id === 'analyzer:framework-detector')!;
121
78
 
122
79
  const project = kernel.getProject();
123
- const sourceFile = project.addSourceFileAtPath('./package.json');
80
+ const sourceFile = project.getSourceFiles()[0]!;
124
81
 
125
82
  const context = ContextFactory.createAnalysisContext({
126
83
  sourceFile,
127
84
  project,
128
- api: createPublicApi(),
129
- config: {},
85
+ api: createPublicApi(project),
130
86
  });
131
87
 
132
- const result = await frameworkRule.analyze(context);
88
+ const [result] = await frameworkRule.analyze(context);
133
89
 
134
- console.log('Framework detected:', result.metadata.framework);
135
- console.log('Confidence:', result.metadata.confidence);
90
+ console.log('Framework detected:', result?.metadata?.framework);
136
91
  ```
137
92
 
138
93
  ### MCP Tool Integration
139
94
 
140
- This plugin powers the `analyze-project` MCP tool:
95
+ The `analyze-project` MCP tool creates a kernel with `AnalyzerPlugin` and runs its rules over the project files; with `includeDetails` the rule findings are returned in `results`. Framework, architecture and technology stack in the tool result are detected by the tool itself:
141
96
 
142
97
  ```typescript
143
98
  const analysis = await callTool('analyze-project', {
@@ -145,75 +100,15 @@ const analysis = await callTool('analyze-project', {
145
100
  includeDetails: true,
146
101
  });
147
102
 
148
- // Result structure
103
+ // structuredContent (abridged)
149
104
  {
150
- "framework": "nx",
151
- "architecture": {
152
- "pattern": "nx-monorepo",
153
- "layers": ["apps", "libs", "tools"],
154
- "confidence": 0.98
155
- },
156
- "technologyStack": {
157
- "angular": "17.0.0",
158
- "nx": "16.0.0",
159
- "typescript": "5.1.0"
160
- },
161
- "migrationReadiness": {
162
- "standaloneComponents": 0.75,
163
- "modernSyntax": 0.60,
164
- "overall": 0.68
165
- }
166
- }
167
- ```
168
-
169
- ## Configuration Options
170
-
171
- ```typescript
172
- interface FrameworkDetectorConfig {
173
- /**
174
- * Minimum confidence threshold for framework detection.
175
- * Default: 0.5
176
- */
177
- minConfidence?: number;
178
-
179
- /**
180
- * Include detailed evidence in results.
181
- * Default: true
182
- */
183
- includeEvidence?: boolean;
184
-
185
- /**
186
- * Custom framework indicators.
187
- */
188
- customIndicators?: FrameworkIndicators;
189
- }
190
-
191
- interface FrameworkIndicators {
192
- angular: string[];
193
- nx: string[];
194
- custom: Record<string, string[]>;
105
+ "framework": { "detected": true, "type": "...", "confidence": 0.9, "indicators": ["..."] },
106
+ "architecture": { "pattern": "...", "confidence": 0.8, "layers": [] },
107
+ "technologyStack": { "languages": [], "frameworks": [], "buildTools": [], "packageManager": "pnpm" },
108
+ "results": [{ "ruleId": "analyzer:framework-detector", "message": "...", "filePath": "..." }]
195
109
  }
196
110
  ```
197
111
 
198
- ### Example Configuration
199
-
200
- ```typescript
201
- const context = ContextFactory.createAnalysisContext({
202
- sourceFile,
203
- project,
204
- api: createPublicApi(),
205
- config: {
206
- minConfidence: 0.8,
207
- includeEvidence: true,
208
- customIndicators: {
209
- custom: {
210
- 'my-framework': ['my-framework.json', 'custom-config.js'],
211
- },
212
- },
213
- },
214
- });
215
- ```
216
-
217
112
  ## Package Structure
218
113
 
219
114
  ```
@@ -221,15 +116,10 @@ packages/plugin-analyzer/
221
116
  src/
222
117
  rules/
223
118
  framework-detector.rule.ts
224
- layer-detector.rule.ts (planned)
225
- technology-stack-analyzer.rule.ts (planned)
226
- analyzer-plugin.ts
227
- index.ts
228
- types.ts
119
+ index.ts # AnalyzerPlugin, FrameworkDetectorRule
229
120
  __tests__/
230
- rules/
231
- framework-detector.rule.test.ts
232
- analyzer-plugin.test.ts
121
+ framework-detector.rule.test.ts
122
+ fixtures/
233
123
  package.json
234
124
  tsconfig.json
235
125
  jest.config.js
@@ -240,7 +130,7 @@ packages/plugin-analyzer/
240
130
 
241
131
  ```bash
242
132
  pnpm --filter @angular-modernizer/plugin-analyzer test
243
- pnpm --filter @angular-modernizer/plugin-analyzer test --coverage
133
+ pnpm --filter @angular-modernizer/plugin-analyzer test -- --coverage
244
134
  ```
245
135
 
246
136
  ### Test Fixtures
@@ -249,56 +139,52 @@ pnpm --filter @angular-modernizer/plugin-analyzer test --coverage
249
139
  __tests__/fixtures/
250
140
  sample-angular-cli-app/
251
141
  angular.json
252
- package.json
142
+ tsconfig.json
253
143
  src/main.ts
254
144
  sample-nx-app/
255
145
  nx.json
256
- workspace.json
257
- apps/
146
+ tsconfig.json
147
+ src/main.ts
258
148
  sample-unknown-app/
259
- package.json
149
+ tsconfig.json
150
+ src/main.ts
151
+ sample-app/
152
+ legacy.component.ts
153
+ legacy.directive.ts
154
+ modern.component.ts
260
155
  ```
261
156
 
262
157
  ### Test Example
263
158
 
264
159
  ```typescript
265
- describe('FrameworkDetectorRule', () => {
266
- let rule: FrameworkDetectorRule;
267
-
268
- beforeEach(() => {
269
- rule = new FrameworkDetectorRule();
270
- });
160
+ import { Kernel } from '@angular-modernizer/core';
161
+ import { ContextFactory } from '@angular-modernizer/plugin-system';
162
+ import { AnalyzerPlugin } from '../src/index.js';
163
+ import { resolve } from 'path';
271
164
 
165
+ describe('FrameworkDetectorRule', () => {
272
166
  it('should detect Angular CLI project', async () => {
273
- const project = new Project();
274
- project.addSourceFilesAtPaths('__tests__/fixtures/sample-angular-cli-app/**/*');
275
-
276
- const context = ContextFactory.createAnalysisContext({
277
- sourceFile: project.getSourceFile('package.json')!,
278
- project,
279
- api: createPublicApi(),
167
+ const plugin = new AnalyzerPlugin();
168
+ const kernel = new Kernel({
169
+ tsConfigPath: resolve(__dirname, './fixtures/sample-angular-cli-app/tsconfig.json'),
170
+ plugins: [plugin],
280
171
  });
172
+ await kernel.initialize();
281
173
 
282
- const result = await rule.analyze(context);
283
-
284
- expect(result.metadata.framework).toBe('angular-cli');
285
- expect(result.metadata.confidence).toBeGreaterThan(0.8);
286
- });
287
-
288
- it('should detect Nx project', async () => {
289
- const project = new Project();
290
- project.addSourceFilesAtPaths('__tests__/fixtures/sample-nx-app/**/*');
174
+ const project = kernel.getProject();
175
+ const rule = plugin
176
+ .getAnalysisRules()
177
+ .find((r) => r.id === 'analyzer:framework-detector')!;
291
178
 
292
179
  const context = ContextFactory.createAnalysisContext({
293
- sourceFile: project.getSourceFile('nx.json')!,
180
+ sourceFile: project.getSourceFiles()[0]!,
294
181
  project,
295
- api: createPublicApi(),
182
+ api: {},
296
183
  });
297
184
 
298
- const result = await rule.analyze(context);
185
+ const [result] = await rule.analyze(context);
299
186
 
300
- expect(result.metadata.framework).toBe('nx');
301
- expect(result.metadata.confidence).toBeGreaterThan(0.9);
187
+ expect(result?.metadata?.framework).toBe('Angular CLI');
302
188
  });
303
189
  });
304
190
  ```
@@ -313,44 +199,35 @@ describe('FrameworkDetectorRule', () => {
313
199
 
314
200
  When adding new analysis rules:
315
201
 
316
- 1. Follow the `AnalysisRule` interface — implement all required methods
317
- 2. Use `PublicApi` tools — do not implement low-level AST logic directly
202
+ 1. Follow the `AnalysisRule` interface: implement all required members
203
+ 2. Use `PublicApi` tools: do not implement low-level AST logic directly
318
204
  3. Include comprehensive tests using real fixtures where possible
319
- 4. Provide meaningful metadata including confidence scores and evidence
205
+ 4. Provide meaningful metadata
320
206
  5. Update this README with configuration options
321
207
 
322
208
  ### Adding a New Analysis Rule
323
209
 
324
210
  ```typescript
325
- // 1. Implement the rule
211
+ // 1. Implement the rule in src/rules/
326
212
  class MyAnalysisRule implements AnalysisRule {
327
- readonly id = 'my-analysis';
213
+ readonly id = 'analyzer:my-analysis';
328
214
  readonly name = 'My Analysis Rule';
329
215
  readonly description = 'Analyzes something specific';
216
+ readonly severity = 'info' as const;
217
+ readonly category = 'project-analysis';
330
218
 
331
- async analyze(context: AnalysisContext): Promise<AnalysisResult> {
332
- const { api, sourceFile } = context;
333
-
334
- const findings = await api.analysis.someTool.analyze(sourceFile);
219
+ async analyze(context: AnalysisContext): Promise<AnalysisResult[]> {
220
+ const { api, sourceFile, filePath } = context;
221
+ const usesInject = api.transformation.importManager.hasImport(sourceFile, 'inject', '@angular/core');
335
222
 
336
- return {
337
- ruleId: this.id,
338
- violations: [],
339
- metadata: {
340
- findings,
341
- confidence: 0.9,
342
- },
343
- };
223
+ return [{ ruleId: this.id, message: `inject imported: ${usesInject}`, filePath }];
344
224
  }
345
225
  }
346
226
 
347
- // 2. Add to plugin
227
+ // 2. Add to the plugin (src/index.ts)
348
228
  class AnalyzerPlugin implements Plugin {
349
229
  getAnalysisRules(): AnalysisRule[] {
350
- return [
351
- new FrameworkDetectorRule(),
352
- new MyAnalysisRule(),
353
- ];
230
+ return [this.frameworkDetectorRule, new MyAnalysisRule()];
354
231
  }
355
232
  }
356
233
  ```
package/dist/index.d.ts CHANGED
@@ -1,23 +1,19 @@
1
1
  /**
2
- * @angular-modernizer/plugin-analyzer
2
+ * Project-level analysis plugin for the Angular Modernizer.
3
3
  *
4
- * Analysis plugin for detecting project architecture, framework, and layers.
5
- * This plugin provides rules for high-level project analysis.
4
+ * {@link AnalyzerPlugin} registers {@link FrameworkDetectorRule}, which
5
+ * reports whether the project is an Angular CLI or an Nx workspace. The rules
6
+ * of this plugin only report; they never modify code.
6
7
  *
7
- * Philosophy: "Know Before You Transform"
8
- * - Analysis rules run first to understand the codebase
9
- * - They provide insights that guide transformation decisions
10
- * - They never modify code, only observe and report
8
+ * @packageDocumentation
11
9
  */
12
10
  import type { IKernel } from '@angular-modernizer/plugin-system';
13
11
  import type { Plugin, AnalysisRule, TransformRule, ValidationRule } from '@angular-modernizer/plugin-system';
14
12
  /**
15
- * Analyzer Plugin - Provides project-level analysis capabilities.
13
+ * Analyzer plugin (`analyzer`): project-level analysis.
16
14
  *
17
- * Rules provided:
18
- * - FrameworkDetectorRule: Detects Angular CLI vs Nx
19
- * - [Future] LayerDetectorRule: Identifies architectural layers
20
- * - [Future] DependencyAnalyzerRule: Analyzes dependency structure
15
+ * Provides one analysis rule, {@link FrameworkDetectorRule}, and no
16
+ * transformation or validation rules.
21
17
  */
22
18
  export declare class AnalyzerPlugin implements Plugin {
23
19
  readonly name = "analyzer";
package/dist/index.js CHANGED
@@ -1,25 +1,21 @@
1
1
  "use strict";
2
2
  /**
3
- * @angular-modernizer/plugin-analyzer
3
+ * Project-level analysis plugin for the Angular Modernizer.
4
4
  *
5
- * Analysis plugin for detecting project architecture, framework, and layers.
6
- * This plugin provides rules for high-level project analysis.
5
+ * {@link AnalyzerPlugin} registers {@link FrameworkDetectorRule}, which
6
+ * reports whether the project is an Angular CLI or an Nx workspace. The rules
7
+ * of this plugin only report; they never modify code.
7
8
  *
8
- * Philosophy: "Know Before You Transform"
9
- * - Analysis rules run first to understand the codebase
10
- * - They provide insights that guide transformation decisions
11
- * - They never modify code, only observe and report
9
+ * @packageDocumentation
12
10
  */
13
11
  Object.defineProperty(exports, "__esModule", { value: true });
14
12
  exports.FrameworkDetectorRule = exports.AnalyzerPlugin = void 0;
15
13
  const framework_detector_rule_js_1 = require("./rules/framework-detector.rule.js");
16
14
  /**
17
- * Analyzer Plugin - Provides project-level analysis capabilities.
15
+ * Analyzer plugin (`analyzer`): project-level analysis.
18
16
  *
19
- * Rules provided:
20
- * - FrameworkDetectorRule: Detects Angular CLI vs Nx
21
- * - [Future] LayerDetectorRule: Identifies architectural layers
22
- * - [Future] DependencyAnalyzerRule: Analyzes dependency structure
17
+ * Provides one analysis rule, {@link FrameworkDetectorRule}, and no
18
+ * transformation or validation rules.
23
19
  */
24
20
  class AnalyzerPlugin {
25
21
  name = 'analyzer';
@@ -1,18 +1,16 @@
1
+ import type { AnalysisRule, AnalysisContext, AnalysisResult } from '@angular-modernizer/plugin-system';
1
2
  /**
2
- * @angular-modernizer/plugin-analyzer - Framework Detector Rule
3
+ * Framework detection rule (`analyzer:framework-detector`).
3
4
  *
4
- * Detects the Angular framework type (Angular CLI vs Nx) by analyzing
5
- * configuration files in the project root.
5
+ * Detects the workspace type from configuration files in the project root
6
+ * (the directory of the tsconfig, otherwise the directory of the analyzed
7
+ * file):
8
+ * - `nx.json` exists: framework is `Nx`
9
+ * - `angular.json` exists: framework is `Angular CLI`
10
+ * - neither exists: framework is `Unknown`
6
11
  *
7
- * Detection Logic:
8
- * - If nx.json exists: Framework is "Nx"
9
- * - If angular.json exists: Framework is "Angular CLI"
10
- * - If neither exists: Framework is "Unknown"
11
- */
12
- import type { AnalysisRule, AnalysisContext, AnalysisResult } from '@angular-modernizer/plugin-system';
13
- /**
14
- * Framework detection rule.
15
- * This is a project-level rule that examines configuration files.
12
+ * Reports one `info` result with `framework`, `hasNxConfig`,
13
+ * `hasAngularConfig` and `projectRoot` in its metadata.
16
14
  */
17
15
  export declare class FrameworkDetectorRule implements AnalysisRule {
18
16
  readonly id = "analyzer:framework-detector";
@@ -1,21 +1,19 @@
1
1
  "use strict";
2
- /**
3
- * @angular-modernizer/plugin-analyzer - Framework Detector Rule
4
- *
5
- * Detects the Angular framework type (Angular CLI vs Nx) by analyzing
6
- * configuration files in the project root.
7
- *
8
- * Detection Logic:
9
- * - If nx.json exists: Framework is "Nx"
10
- * - If angular.json exists: Framework is "Angular CLI"
11
- * - If neither exists: Framework is "Unknown"
12
- */
13
2
  Object.defineProperty(exports, "__esModule", { value: true });
14
3
  exports.FrameworkDetectorRule = void 0;
15
4
  const node_path_1 = require("node:path");
16
5
  /**
17
- * Framework detection rule.
18
- * This is a project-level rule that examines configuration files.
6
+ * Framework detection rule (`analyzer:framework-detector`).
7
+ *
8
+ * Detects the workspace type from configuration files in the project root
9
+ * (the directory of the tsconfig, otherwise the directory of the analyzed
10
+ * file):
11
+ * - `nx.json` exists: framework is `Nx`
12
+ * - `angular.json` exists: framework is `Angular CLI`
13
+ * - neither exists: framework is `Unknown`
14
+ *
15
+ * Reports one `info` result with `framework`, `hasNxConfig`,
16
+ * `hasAngularConfig` and `projectRoot` in its metadata.
19
17
  */
20
18
  class FrameworkDetectorRule {
21
19
  id = 'analyzer:framework-detector';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@angular-modernizer/plugin-analyzer",
3
- "version": "0.3.0",
3
+ "version": "1.1.0",
4
4
  "description": "Analysis plugin for detecting project architecture, framework, and layers.",
5
5
  "keywords": [
6
6
  "angular",
@@ -11,26 +11,18 @@
11
11
  "code-analysis"
12
12
  ],
13
13
  "license": "MIT",
14
- "repository": {
15
- "type": "git",
16
- "url": "git+https://github.com/eiweiss/tsanalyzer.git",
17
- "directory": "packages/plugin-analyzer"
18
- },
19
- "homepage": "https://github.com/eiweiss/tsanalyzer#readme",
20
- "bugs": "https://github.com/eiweiss/tsanalyzer/issues",
21
- "main": "dist/index.js",
14
+ "author": "Christian Weiss",
15
+ "homepage": "https://eiweiss.github.io/angular-modernizer-docs/",
16
+ "main": "./dist/index.js",
22
17
  "files": [
23
18
  "dist",
24
- "src",
25
19
  "!dist/**/__tests__/**",
26
- "!src/**/__tests__/**",
27
- "!src/**/*.test.ts",
28
- "!src/**/*.spec.ts"
20
+ "!dist/**/*.map"
29
21
  ],
30
22
  "dependencies": {
31
- "@angular-modernizer/plugin-system": "0.3.0",
32
- "@angular-modernizer/core": "0.3.0",
33
- "@angular-modernizer/api": "0.3.0"
23
+ "@angular-modernizer/core": "1.1.0",
24
+ "@angular-modernizer/plugin-system": "1.1.0",
25
+ "@angular-modernizer/api": "1.1.0"
34
26
  },
35
27
  "devDependencies": {
36
28
  "@types/jest": "^30.0.0",
@@ -46,6 +38,18 @@
46
38
  ],
47
39
  "tsconfig": "./tsconfig.json"
48
40
  },
41
+ "engines": {
42
+ "node": "^20.19.0 || ^22.12.0 || >=24.0.0"
43
+ },
44
+ "types": "./dist/index.d.ts",
45
+ "exports": {
46
+ ".": {
47
+ "types": "./dist/index.d.ts",
48
+ "require": "./dist/index.js",
49
+ "default": "./dist/index.js"
50
+ },
51
+ "./package.json": "./package.json"
52
+ },
49
53
  "scripts": {
50
54
  "build": "tsc --build",
51
55
  "test": "jest --passWithNoTests",
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,mCAAmC,CAAC;AACjE,OAAO,KAAK,EACV,MAAM,EACN,YAAY,EACZ,aAAa,EACb,cAAc,EACf,MAAM,mCAAmC,CAAC;AAG3C;;;;;;;GAOG;AACH,qBAAa,cAAe,YAAW,MAAM;IAC3C,QAAQ,CAAC,IAAI,cAAc;IAC3B,QAAQ,CAAC,OAAO,WAAW;IAC3B,QAAQ,CAAC,WAAW,iDAAiD;IACrE,QAAQ,CAAC,MAAM,wBAAwB;IAEvC,OAAO,CAAC,qBAAqB,CAAwB;;IAOrD;;;OAGG;IACG,UAAU,CAAC,MAAM,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC;IAMhD;;OAEG;IACH,gBAAgB,IAAI,YAAY,EAAE;IAIlC;;;OAGG;IACH,iBAAiB,IAAI,aAAa,EAAE;IAIpC;;;OAGG;IACH,kBAAkB,IAAI,cAAc,EAAE;CAGvC;AAGD,OAAO,EAAE,qBAAqB,EAAE,MAAM,oCAAoC,CAAC"}
package/dist/index.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;GAUG;;;AASH,mFAA2E;AAE3E;;;;;;;GAOG;AACH,MAAa,cAAc;IAChB,IAAI,GAAG,UAAU,CAAC;IAClB,OAAO,GAAG,OAAO,CAAC;IAClB,WAAW,GAAG,6CAA6C,CAAC;IAC5D,MAAM,GAAG,oBAAoB,CAAC;IAE/B,qBAAqB,CAAwB;IAErD;QACE,mBAAmB;QACnB,IAAI,CAAC,qBAAqB,GAAG,IAAI,kDAAqB,EAAE,CAAC;IAC3D,CAAC;IAED;;;OAGG;IACH,KAAK,CAAC,UAAU,CAAC,MAAe;QAC9B,+CAA+C;QAC/C,gEAAgE;QAChE,KAAK,MAAM,CAAC,CAAC,sCAAsC;IACrD,CAAC;IAED;;OAEG;IACH,gBAAgB;QACd,OAAO,CAAC,IAAI,CAAC,qBAAqB,CAAC,CAAC;IACtC,CAAC;IAED;;;OAGG;IACH,iBAAiB;QACf,OAAO,EAAE,CAAC;IACZ,CAAC;IAED;;;OAGG;IACH,kBAAkB;QAChB,OAAO,EAAE,CAAC;IACZ,CAAC;CACF;AA7CD,wCA6CC;AAED,oCAAoC;AACpC,iFAA2E;AAAlE,mIAAA,qBAAqB,OAAA"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"framework-detector.rule.d.ts","sourceRoot":"","sources":["../../src/rules/framework-detector.rule.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,KAAK,EACV,YAAY,EACZ,eAAe,EACf,cAAc,EACf,MAAM,mCAAmC,CAAC;AAG3C;;;GAGG;AACH,qBAAa,qBAAsB,YAAW,YAAY;IACxD,QAAQ,CAAC,EAAE,iCAAiC;IAC5C,QAAQ,CAAC,IAAI,wBAAwB;IACrC,QAAQ,CAAC,WAAW,wDAAwD;IAC5E,QAAQ,CAAC,QAAQ,EAAG,MAAM,CAAU;IACpC,QAAQ,CAAC,QAAQ,sBAAsB;IACvC,QAAQ,CAAC,IAAI,WAAyC;IAEhD,OAAO,CAAC,OAAO,EAAE,eAAe,GAAG,OAAO,CAAC,cAAc,EAAE,CAAC;IA+ClE;;;OAGG;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AAa,GAAG,OAAO,CAAC,OAE7B,CAAC;YACF,MAAM,UAAU,GAAG,aAAa,CAAC,aAAa,EAAE,EAAE,CAAC;YACnD,IAAI,UAAU,IAAI,OAAO,UAAU,CAAC,cAAc,KAAK,UAAU,EAAE,CAAC;gBAClE,OAAO,UAAU,CAAC,cAAc,CAAC,QAAQ,CAAC,CAAC;YAC7C,CAAC;YAED,8BAA8B;YAC9B,OAAO,KAAK,CAAC;QACf,CAAC;QAAC,MAAM,CAAC;YACP,OAAO,KAAK,CAAC;QACf,CAAC;IACH,CAAC;CACF;AAzHD,sDAyHC"}
package/src/index.ts DELETED
@@ -1,78 +0,0 @@
1
- /**
2
- * @angular-modernizer/plugin-analyzer
3
- *
4
- * Analysis plugin for detecting project architecture, framework, and layers.
5
- * This plugin provides rules for high-level project analysis.
6
- *
7
- * Philosophy: "Know Before You Transform"
8
- * - Analysis rules run first to understand the codebase
9
- * - They provide insights that guide transformation decisions
10
- * - They never modify code, only observe and report
11
- */
12
-
13
- import type { IKernel } from '@angular-modernizer/plugin-system';
14
- import type {
15
- Plugin,
16
- AnalysisRule,
17
- TransformRule,
18
- ValidationRule,
19
- } from '@angular-modernizer/plugin-system';
20
- import { FrameworkDetectorRule } from './rules/framework-detector.rule.js';
21
-
22
- /**
23
- * Analyzer Plugin - Provides project-level analysis capabilities.
24
- *
25
- * Rules provided:
26
- * - FrameworkDetectorRule: Detects Angular CLI vs Nx
27
- * - [Future] LayerDetectorRule: Identifies architectural layers
28
- * - [Future] DependencyAnalyzerRule: Analyzes dependency structure
29
- */
30
- export class AnalyzerPlugin implements Plugin {
31
- readonly name = 'analyzer';
32
- readonly version = '1.0.0';
33
- readonly description = 'Project architecture and framework analysis';
34
- readonly author = 'Angular Modernizer';
35
-
36
- private frameworkDetectorRule: FrameworkDetectorRule;
37
-
38
- constructor() {
39
- // Initialize rules
40
- this.frameworkDetectorRule = new FrameworkDetectorRule();
41
- }
42
-
43
- /**
44
- * Initialize the plugin.
45
- * Called once during Kernel initialization.
46
- */
47
- async initialize(kernel: IKernel): Promise<void> {
48
- // No initialization needed for this plugin yet
49
- // Future: Could load configuration, validate dependencies, etc.
50
- void kernel; // Mark as used to avoid linting error
51
- }
52
-
53
- /**
54
- * Get all analysis rules provided by this plugin.
55
- */
56
- getAnalysisRules(): AnalysisRule[] {
57
- return [this.frameworkDetectorRule];
58
- }
59
-
60
- /**
61
- * Get all transformation rules provided by this plugin.
62
- * This plugin doesn't provide transformations.
63
- */
64
- getTransformRules(): TransformRule[] {
65
- return [];
66
- }
67
-
68
- /**
69
- * Get all validation rules provided by this plugin.
70
- * This plugin doesn't provide validations.
71
- */
72
- getValidationRules(): ValidationRule[] {
73
- return [];
74
- }
75
- }
76
-
77
- // Export the plugin class and rules
78
- export { FrameworkDetectorRule } from './rules/framework-detector.rule.js';
@@ -1,145 +0,0 @@
1
- /**
2
- * @angular-modernizer/plugin-analyzer - Framework Detector Rule
3
- *
4
- * Detects the Angular framework type (Angular CLI vs Nx) by analyzing
5
- * configuration files in the project root.
6
- *
7
- * Detection Logic:
8
- * - If nx.json exists: Framework is "Nx"
9
- * - If angular.json exists: Framework is "Angular CLI"
10
- * - If neither exists: Framework is "Unknown"
11
- */
12
-
13
- import type {
14
- AnalysisRule,
15
- AnalysisContext,
16
- AnalysisResult,
17
- } from '@angular-modernizer/plugin-system';
18
- import { dirname, join } from 'node:path';
19
-
20
- /**
21
- * Framework detection rule.
22
- * This is a project-level rule that examines configuration files.
23
- */
24
- export class FrameworkDetectorRule implements AnalysisRule {
25
- readonly id = 'analyzer:framework-detector';
26
- readonly name = 'Framework Detector';
27
- readonly description = 'Detects whether the project uses Angular CLI or Nx';
28
- readonly severity = 'info' as const;
29
- readonly category = 'project-analysis';
30
- readonly tags = ['framework', 'detection', 'project'];
31
-
32
- async analyze(context: AnalysisContext): Promise<AnalysisResult[]> {
33
- // Get the project root directory
34
- // We'll use the directory containing the tsconfig file as the project root
35
- const projectRoot = this.getProjectRoot(context);
36
-
37
- // Check for framework configuration files
38
- const hasNxConfig = await this.fileExists(
39
- context,
40
- join(projectRoot, 'nx.json'),
41
- );
42
- const hasAngularConfig = await this.fileExists(
43
- context,
44
- join(projectRoot, 'angular.json'),
45
- );
46
-
47
- // Determine framework type
48
- let framework: string;
49
- let message: string;
50
-
51
- if (hasNxConfig) {
52
- framework = 'Nx';
53
- message = 'Project uses Nx workspace';
54
- } else if (hasAngularConfig) {
55
- framework = 'Angular CLI';
56
- message = 'Project uses Angular CLI';
57
- } else {
58
- framework = 'Unknown';
59
- message =
60
- 'Could not determine framework type (no nx.json or angular.json found)';
61
- }
62
-
63
- // Return analysis result
64
- return [
65
- {
66
- ruleId: this.id,
67
- message,
68
- filePath: context.filePath,
69
- metadata: {
70
- framework,
71
- hasNxConfig,
72
- hasAngularConfig,
73
- projectRoot,
74
- },
75
- },
76
- ];
77
- }
78
-
79
- /**
80
- * Get the project root directory.
81
- * Uses the directory containing the first tsconfig.json found.
82
- */
83
- private getProjectRoot(context: AnalysisContext): string {
84
- // Get all tsconfig files from the project
85
- const compilerOptions = context.project.getCompilerOptions();
86
- const configFiles = compilerOptions['configFilePath'];
87
-
88
- if (configFiles && typeof configFiles === 'string') {
89
- return dirname(configFiles);
90
- }
91
-
92
- // Fallback: use the directory of the current source file and traverse up
93
- return this.findProjectRoot(context.filePath);
94
- }
95
-
96
- /**
97
- * Find project root by traversing up the directory tree.
98
- * Looks for tsconfig.json, package.json, or stops at root.
99
- */
100
- private findProjectRoot(startPath: string): string {
101
- const current = dirname(startPath);
102
- const root = '/';
103
-
104
- // Keep traversing up until we find a project marker or hit root
105
- while (current !== root) {
106
- // TODO: In a real implementation, we'd check for files here
107
- // For now, just return the directory
108
- return current;
109
- }
110
-
111
- return current;
112
- }
113
-
114
- /**
115
- * Check if a file exists in the file system.
116
- * Uses the file system adapter from the context if available.
117
- */
118
- private async fileExists(
119
- context: AnalysisContext,
120
- filePath: string,
121
- ): Promise<boolean> {
122
- try {
123
- // Try using ts-morph to check if the file exists
124
- const sourceFile = context.project.getSourceFile(filePath);
125
- if (sourceFile) {
126
- return true;
127
- }
128
-
129
- // Try using the file system directly
130
- // The project should have a file system we can query
131
- const projectWithFs = context.project as unknown as {
132
- getFileSystem?: () => { fileExistsSync?: (path: string) => boolean };
133
- };
134
- const fileSystem = projectWithFs.getFileSystem?.();
135
- if (fileSystem && typeof fileSystem.fileExistsSync === 'function') {
136
- return fileSystem.fileExistsSync(filePath);
137
- }
138
-
139
- // Fallback: just return false
140
- return false;
141
- } catch {
142
- return false;
143
- }
144
- }
145
- }