Skip to content

Commit 261f9af

Browse files
committed
feat: add incremental parsing with cross-file edge preservation
- Implement deterministic node IDs based on coreType + filePath + name - Add file change detection using mtime, size, and content hash - Save cross-file edges before deletion and restore after import - Load existing nodes from Neo4j for outgoing edge detection - Fix missing await on parseChildNodes causing nodes to be lost - Add FairSquare monorepo auto-detection (@fairsquare/source) - Add debug logging utilities for troubleshooting This enables fast incremental updates when modifying individual files, preserving relationships like INJECTS edges between services.
1 parent f3ba155 commit 261f9af

File tree

9 files changed

+458
-112
lines changed

9 files changed

+458
-112
lines changed

src/constants.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,24 @@
11
export const MAX_TRAVERSAL_DEPTH = 5;
2+
3+
// Shared exclude patterns for file parsing and change detection
4+
// Regex patterns (escaped dots, anchored to end)
5+
export const EXCLUDE_PATTERNS_REGEX = [
6+
'node_modules/',
7+
'dist/',
8+
'build/',
9+
'coverage/',
10+
'\\.d\\.ts$',
11+
'\\.spec\\.ts$',
12+
'\\.test\\.ts$',
13+
];
14+
15+
// Glob patterns for use with glob library
16+
export const EXCLUDE_PATTERNS_GLOB = [
17+
'node_modules/**',
18+
'dist/**',
19+
'build/**',
20+
'coverage/**',
21+
'**/*.d.ts',
22+
'**/*.spec.ts',
23+
'**/*.test.ts',
24+
];

src/core/config/nestjs-framework-schema.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
/* eslint-disable prefer-arrow/prefer-arrow-functions */
22
/* eslint-disable @typescript-eslint/no-explicit-any */
33

4+
import { EXCLUDE_PATTERNS_REGEX } from '../../constants.js';
5+
46
import {
57
CoreNodeType,
68
FrameworkSchema,
@@ -940,7 +942,7 @@ export const NESTJS_FRAMEWORK_SCHEMA: FrameworkSchema = {
940942

941943
export const NESTJS_PARSE_OPTIONS: ParseOptions = {
942944
includePatterns: ['**/*.ts', '**/*.tsx'],
943-
excludePatterns: ['node_modules/', 'dist/', 'coverage/', '.d.ts', '.spec.ts', '.test.ts'],
945+
excludePatterns: EXCLUDE_PATTERNS_REGEX,
944946
maxFiles: 1000,
945947
frameworkSchemas: [NESTJS_FRAMEWORK_SCHEMA],
946948
};

src/core/config/schema.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
/* eslint-disable @typescript-eslint/no-explicit-any */
22
// graph.ts - Optimized for Neo4j performance with context-based framework properties
33

4+
import { EXCLUDE_PATTERNS_REGEX } from '../../constants.js';
5+
46
// ============================================================================
57
// CORE ENUMS
68
// ============================================================================
@@ -141,6 +143,9 @@ export interface Neo4jNodeProperties {
141143
endLine: number;
142144
sourceCode: string;
143145
createdAt: string;
146+
contentHash?: string;
147+
mtime?: number;
148+
size?: number;
144149

145150
// === FRAMEWORK-SPECIFIC (Dynamic) ===
146151
context?: Record<string, any>;
@@ -1170,7 +1175,7 @@ export interface ParseOptions {
11701175

11711176
export const DEFAULT_PARSE_OPTIONS: ParseOptions = {
11721177
includePatterns: ['**/*.ts', '**/*.tsx'],
1173-
excludePatterns: ['node_modules/', 'dist/', 'coverage/', '.d.ts', '.spec.ts', '.test.ts'],
1178+
excludePatterns: EXCLUDE_PATTERNS_REGEX,
11741179
maxFiles: 1000,
11751180
coreSchema: CORE_TYPESCRIPT_SCHEMA,
11761181
frameworkSchemas: [],

src/core/parsers/parser-factory.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* Creates TypeScript parsers with appropriate framework schemas
44
*/
55

6+
import { EXCLUDE_PATTERNS_REGEX } from '../../constants.js';
67
import { FAIRSQUARE_FRAMEWORK_SCHEMA } from '../config/fairsquare-framework-schema.js';
78
import { NESTJS_FRAMEWORK_SCHEMA } from '../config/nestjs-framework-schema.js';
89
import { CORE_TYPESCRIPT_SCHEMA, FrameworkSchema, CoreNodeType } from '../config/schema.js';
@@ -35,7 +36,7 @@ export class ParserFactory {
3536
tsConfigPath = 'tsconfig.json',
3637
projectType = ProjectType.NESTJS, // Default to NestJS (use auto-detect for best results)
3738
customFrameworkSchemas = [],
38-
excludePatterns = ['node_modules', 'dist', 'build', '.spec.', '.test.'],
39+
excludePatterns = EXCLUDE_PATTERNS_REGEX,
3940
excludedNodeTypes = [CoreNodeType.PARAMETER_DECLARATION],
4041
} = options;
4142

@@ -100,7 +101,10 @@ export class ParserFactory {
100101
};
101102

102103
const hasNestJS = '@nestjs/common' in deps || '@nestjs/core' in deps;
103-
const hasFairSquare = '@fairsquare/core' in deps || '@fairsquare/server' in deps;
104+
const hasFairSquare =
105+
'@fairsquare/core' in deps ||
106+
'@fairsquare/server' in deps ||
107+
packageJson.name === '@fairsquare/source';
104108

105109
if (hasFairSquare && hasNestJS) {
106110
return ProjectType.BOTH;

0 commit comments

Comments
 (0)