coderaph 0.1.0 → 0.2.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/dist/cli/analyzer.d.ts +1 -0
- package/dist/cli/analyzer.js +49 -8
- package/dist/cli/index.js +2 -0
- package/package.json +1 -1
package/dist/cli/analyzer.d.ts
CHANGED
package/dist/cli/analyzer.js
CHANGED
|
@@ -16,13 +16,55 @@ function matchGlob(filePath, pattern) {
|
|
|
16
16
|
const regex = new RegExp(`^${escaped}$`);
|
|
17
17
|
return regex.test(filePath);
|
|
18
18
|
}
|
|
19
|
+
const TSCONFIG_CANDIDATES = [
|
|
20
|
+
'tsconfig.json',
|
|
21
|
+
'tsconfig.build.json',
|
|
22
|
+
'tsconfig.base.json',
|
|
23
|
+
'tsconfig.app.json',
|
|
24
|
+
];
|
|
25
|
+
/**
|
|
26
|
+
* Finds a tsconfig file in the given directory.
|
|
27
|
+
* Checks common tsconfig filenames, then searches subdirectories (1 level deep).
|
|
28
|
+
*/
|
|
29
|
+
function findTsConfig(projectPath) {
|
|
30
|
+
// Check common names in project root
|
|
31
|
+
for (const candidate of TSCONFIG_CANDIDATES) {
|
|
32
|
+
const fullPath = path.resolve(projectPath, candidate);
|
|
33
|
+
if (fs.existsSync(fullPath))
|
|
34
|
+
return fullPath;
|
|
35
|
+
}
|
|
36
|
+
// Search one level of subdirectories (for monorepos: packages/*, apps/*)
|
|
37
|
+
const entries = fs.readdirSync(projectPath, { withFileTypes: true });
|
|
38
|
+
for (const entry of entries) {
|
|
39
|
+
if (!entry.isDirectory() || entry.name === 'node_modules' || entry.name.startsWith('.'))
|
|
40
|
+
continue;
|
|
41
|
+
const subTsConfig = path.resolve(projectPath, entry.name, 'tsconfig.json');
|
|
42
|
+
if (fs.existsSync(subTsConfig))
|
|
43
|
+
return subTsConfig;
|
|
44
|
+
}
|
|
45
|
+
return null;
|
|
46
|
+
}
|
|
19
47
|
/**
|
|
20
48
|
* Loads a TypeScript project and returns filtered source files.
|
|
21
49
|
*/
|
|
22
50
|
export function loadProject(options) {
|
|
23
|
-
|
|
24
|
-
if (
|
|
25
|
-
|
|
51
|
+
let tsConfigFilePath;
|
|
52
|
+
if (options.tsConfigPath) {
|
|
53
|
+
tsConfigFilePath = path.resolve(options.projectPath, options.tsConfigPath);
|
|
54
|
+
if (!fs.existsSync(tsConfigFilePath)) {
|
|
55
|
+
throw new Error(`tsconfig not found at ${tsConfigFilePath}. Please check the --tsconfig path.`);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
else {
|
|
59
|
+
const found = findTsConfig(options.projectPath);
|
|
60
|
+
if (!found) {
|
|
61
|
+
throw new Error(`No tsconfig.json found in ${options.projectPath} or its subdirectories. ` +
|
|
62
|
+
`Use --tsconfig to specify the path (e.g. --tsconfig packages/app/tsconfig.json).`);
|
|
63
|
+
}
|
|
64
|
+
tsConfigFilePath = found;
|
|
65
|
+
if (path.basename(tsConfigFilePath) !== 'tsconfig.json' || path.dirname(tsConfigFilePath) !== options.projectPath) {
|
|
66
|
+
console.log(`Using tsconfig: ${path.relative(options.projectPath, tsConfigFilePath)}`);
|
|
67
|
+
}
|
|
26
68
|
}
|
|
27
69
|
const project = new Project({ tsConfigFilePath });
|
|
28
70
|
let sourceFiles = project.getSourceFiles().filter((file) => {
|
|
@@ -50,13 +92,12 @@ export function loadProject(options) {
|
|
|
50
92
|
return !excludePatterns.some((pattern) => matchGlob(relativePath, pattern));
|
|
51
93
|
});
|
|
52
94
|
}
|
|
53
|
-
//
|
|
95
|
+
// Skip files with actual syntax errors (not type errors — those are fine for graph analysis)
|
|
54
96
|
sourceFiles = sourceFiles.filter((file) => {
|
|
55
|
-
const
|
|
56
|
-
const syntaxErrors = diagnostics.filter((d) => d.getCategory() === 1 // DiagnosticCategory.Error
|
|
97
|
+
const syntaxDiagnostics = file.getPreEmitDiagnostics().filter((d) => d.getCode() >= 1000 && d.getCode() < 2000 // TS1xxx = syntax errors only
|
|
57
98
|
);
|
|
58
|
-
if (
|
|
59
|
-
console.warn(`Warning: Skipping ${path.relative(options.projectPath, file.getFilePath())} due to ${
|
|
99
|
+
if (syntaxDiagnostics.length > 0) {
|
|
100
|
+
console.warn(`Warning: Skipping ${path.relative(options.projectPath, file.getFilePath())} due to ${syntaxDiagnostics.length} syntax error(s)`);
|
|
60
101
|
return false;
|
|
61
102
|
}
|
|
62
103
|
return true;
|
package/dist/cli/index.js
CHANGED
|
@@ -14,6 +14,7 @@ program
|
|
|
14
14
|
.command('analyze <project-path>')
|
|
15
15
|
.description('Analyze TypeScript project and generate dependency graph JSON')
|
|
16
16
|
.option('-o, --output <path>', 'Output JSON file path', 'coderaph-output.json')
|
|
17
|
+
.option('--tsconfig <path>', 'Path to tsconfig.json (relative to project path)')
|
|
17
18
|
.option('--include <patterns...>', 'Include glob patterns')
|
|
18
19
|
.option('--exclude <patterns...>', 'Exclude glob patterns')
|
|
19
20
|
.action((projectPath, options) => {
|
|
@@ -22,6 +23,7 @@ program
|
|
|
22
23
|
console.log(`Analyzing ${resolvedPath}...`);
|
|
23
24
|
const { sourceFiles } = loadProject({
|
|
24
25
|
projectPath: resolvedPath,
|
|
26
|
+
tsConfigPath: options.tsconfig,
|
|
25
27
|
include: options.include,
|
|
26
28
|
exclude: options.exclude,
|
|
27
29
|
});
|