@fairfox/polly 0.10.1 → 0.11.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 +186 -0
- package/dist/tools/teach/src/cli.js +237 -13
- package/dist/tools/teach/src/cli.js.map +4 -4
- package/dist/tools/teach/src/index.js +89 -13
- package/dist/tools/teach/src/index.js.map +3 -3
- package/dist/tools/verify/src/cli.js +95 -16
- package/dist/tools/verify/src/cli.js.map +5 -5
- package/dist/tools/visualize/src/cli.js +89 -13
- package/dist/tools/visualize/src/cli.js.map +3 -3
- package/package.json +21 -2
|
@@ -236634,40 +236634,116 @@ class HandlerExtractor {
|
|
|
236634
236634
|
project;
|
|
236635
236635
|
typeGuardCache;
|
|
236636
236636
|
relationshipExtractor;
|
|
236637
|
+
analyzedFiles;
|
|
236638
|
+
packageRoot;
|
|
236637
236639
|
constructor(tsConfigPath) {
|
|
236638
236640
|
this.project = new import_ts_morph4.Project({
|
|
236639
236641
|
tsConfigFilePath: tsConfigPath
|
|
236640
236642
|
});
|
|
236641
236643
|
this.typeGuardCache = new WeakMap;
|
|
236642
236644
|
this.relationshipExtractor = new RelationshipExtractor;
|
|
236645
|
+
this.analyzedFiles = new Set;
|
|
236646
|
+
this.packageRoot = this.findPackageRoot(tsConfigPath);
|
|
236647
|
+
}
|
|
236648
|
+
findPackageRoot(tsConfigPath) {
|
|
236649
|
+
let dir = tsConfigPath.substring(0, tsConfigPath.lastIndexOf("/"));
|
|
236650
|
+
while (dir.length > 1) {
|
|
236651
|
+
try {
|
|
236652
|
+
const packageJsonPath = `${dir}/package.json`;
|
|
236653
|
+
const file = Bun.file(packageJsonPath);
|
|
236654
|
+
if (file.size > 0) {
|
|
236655
|
+
return dir;
|
|
236656
|
+
}
|
|
236657
|
+
} catch {}
|
|
236658
|
+
const parentDir = dir.substring(0, dir.lastIndexOf("/"));
|
|
236659
|
+
if (parentDir === dir)
|
|
236660
|
+
break;
|
|
236661
|
+
dir = parentDir;
|
|
236662
|
+
}
|
|
236663
|
+
return tsConfigPath.substring(0, tsConfigPath.lastIndexOf("/"));
|
|
236643
236664
|
}
|
|
236644
236665
|
extractHandlers() {
|
|
236645
236666
|
const handlers = [];
|
|
236646
236667
|
const messageTypes = new Set;
|
|
236647
236668
|
const invalidMessageTypes = new Set;
|
|
236648
236669
|
const stateConstraints = [];
|
|
236649
|
-
const
|
|
236650
|
-
this.
|
|
236651
|
-
|
|
236652
|
-
|
|
236653
|
-
|
|
236654
|
-
this.categorizeHandlerMessageTypes(fileHandlers, messageTypes, invalidMessageTypes);
|
|
236655
|
-
const fileConstraints = this.extractStateConstraintsFromFile(sourceFile);
|
|
236656
|
-
stateConstraints.push(...fileConstraints);
|
|
236670
|
+
const allSourceFiles = this.project.getSourceFiles();
|
|
236671
|
+
const entryPoints = allSourceFiles.filter((f) => this.isWithinPackage(f.getFilePath()));
|
|
236672
|
+
this.debugLogSourceFiles(allSourceFiles, entryPoints);
|
|
236673
|
+
for (const entryPoint of entryPoints) {
|
|
236674
|
+
this.analyzeFileAndImports(entryPoint, handlers, messageTypes, invalidMessageTypes, stateConstraints);
|
|
236657
236675
|
}
|
|
236658
236676
|
this.debugLogExtractionResults(handlers.length, invalidMessageTypes.size);
|
|
236677
|
+
this.debugLogAnalysisStats(allSourceFiles.length, entryPoints.length);
|
|
236659
236678
|
return {
|
|
236660
236679
|
handlers,
|
|
236661
236680
|
messageTypes,
|
|
236662
236681
|
stateConstraints
|
|
236663
236682
|
};
|
|
236664
236683
|
}
|
|
236665
|
-
|
|
236684
|
+
analyzeFileAndImports(sourceFile, handlers, messageTypes, invalidMessageTypes, stateConstraints) {
|
|
236685
|
+
const filePath = sourceFile.getFilePath();
|
|
236686
|
+
if (this.analyzedFiles.has(filePath)) {
|
|
236687
|
+
return;
|
|
236688
|
+
}
|
|
236689
|
+
this.analyzedFiles.add(filePath);
|
|
236690
|
+
if (process.env["POLLY_DEBUG"]) {
|
|
236691
|
+
console.log(`[DEBUG] Analyzing: ${filePath}`);
|
|
236692
|
+
}
|
|
236693
|
+
const fileHandlers = this.extractFromFile(sourceFile);
|
|
236694
|
+
handlers.push(...fileHandlers);
|
|
236695
|
+
this.categorizeHandlerMessageTypes(fileHandlers, messageTypes, invalidMessageTypes);
|
|
236696
|
+
const fileConstraints = this.extractStateConstraintsFromFile(sourceFile);
|
|
236697
|
+
stateConstraints.push(...fileConstraints);
|
|
236698
|
+
const importDeclarations = sourceFile.getImportDeclarations();
|
|
236699
|
+
for (const importDecl of importDeclarations) {
|
|
236700
|
+
const importedFile = importDecl.getModuleSpecifierSourceFile();
|
|
236701
|
+
if (importedFile) {
|
|
236702
|
+
const importedPath = importedFile.getFilePath();
|
|
236703
|
+
if (!this.isWithinPackage(importedPath)) {
|
|
236704
|
+
if (process.env["POLLY_DEBUG"]) {
|
|
236705
|
+
console.log(`[DEBUG] Skipping external import: ${importedPath}`);
|
|
236706
|
+
}
|
|
236707
|
+
continue;
|
|
236708
|
+
}
|
|
236709
|
+
this.analyzeFileAndImports(importedFile, handlers, messageTypes, invalidMessageTypes, stateConstraints);
|
|
236710
|
+
} else if (process.env["POLLY_DEBUG"]) {
|
|
236711
|
+
const specifier = importDecl.getModuleSpecifierValue();
|
|
236712
|
+
if (!specifier.startsWith("node:") && !this.isNodeModuleImport(specifier)) {
|
|
236713
|
+
console.log(`[DEBUG] Could not resolve import: ${specifier} in ${filePath}`);
|
|
236714
|
+
}
|
|
236715
|
+
}
|
|
236716
|
+
}
|
|
236717
|
+
}
|
|
236718
|
+
isWithinPackage(filePath) {
|
|
236719
|
+
if (!filePath.startsWith(this.packageRoot)) {
|
|
236720
|
+
return false;
|
|
236721
|
+
}
|
|
236722
|
+
if (filePath.includes("/node_modules/")) {
|
|
236723
|
+
return false;
|
|
236724
|
+
}
|
|
236725
|
+
return true;
|
|
236726
|
+
}
|
|
236727
|
+
isNodeModuleImport(specifier) {
|
|
236728
|
+
return !specifier.startsWith(".") && !specifier.startsWith("/");
|
|
236729
|
+
}
|
|
236730
|
+
debugLogAnalysisStats(totalSourceFiles, entryPointCount) {
|
|
236731
|
+
if (!process.env["POLLY_DEBUG"])
|
|
236732
|
+
return;
|
|
236733
|
+
console.log(`[DEBUG] Analysis Statistics:`);
|
|
236734
|
+
console.log(`[DEBUG] Package root: ${this.packageRoot}`);
|
|
236735
|
+
console.log(`[DEBUG] Source files from tsconfig: ${totalSourceFiles}`);
|
|
236736
|
+
console.log(`[DEBUG] Entry points (in package): ${entryPointCount}`);
|
|
236737
|
+
console.log(`[DEBUG] Files analyzed (including imports): ${this.analyzedFiles.size}`);
|
|
236738
|
+
console.log(`[DEBUG] Additional files discovered: ${this.analyzedFiles.size - entryPointCount}`);
|
|
236739
|
+
}
|
|
236740
|
+
debugLogSourceFiles(allSourceFiles, entryPoints) {
|
|
236666
236741
|
if (!process.env["POLLY_DEBUG"])
|
|
236667
236742
|
return;
|
|
236668
|
-
console.log(`[DEBUG] Loaded ${
|
|
236669
|
-
|
|
236670
|
-
|
|
236743
|
+
console.log(`[DEBUG] Loaded ${allSourceFiles.length} source files from tsconfig`);
|
|
236744
|
+
console.log(`[DEBUG] Filtered to ${entryPoints.length} entry points within package`);
|
|
236745
|
+
if (entryPoints.length <= 20) {
|
|
236746
|
+
for (const sf of entryPoints) {
|
|
236671
236747
|
console.log(`[DEBUG] - ${sf.getFilePath()}`);
|
|
236672
236748
|
}
|
|
236673
236749
|
}
|
|
@@ -240519,4 +240595,4 @@ export {
|
|
|
240519
240595
|
generateTeachingMaterial
|
|
240520
240596
|
};
|
|
240521
240597
|
|
|
240522
|
-
//# debugId=
|
|
240598
|
+
//# debugId=F2EE93360E450F6364756E2164756E21
|