diff --git a/src/eval-server/controllers/index.ts b/src/eval-server/controllers/index.ts index 0320249..7df2efe 100644 --- a/src/eval-server/controllers/index.ts +++ b/src/eval-server/controllers/index.ts @@ -405,6 +405,8 @@ export async function addEvalPreference(req: Request, res: Response) { preferenceTimestamp: new Date(), }, }) + + res.status(200).json({}) } catch (e) { log("eval-server", LogLevel.Error, e) res.status(StatusCodes.INTERNAL_ERROR).json({}) diff --git a/src/eval-server/index.ts b/src/eval-server/index.ts index c5a6671..991ce18 100644 --- a/src/eval-server/index.ts +++ b/src/eval-server/index.ts @@ -9,7 +9,7 @@ import express from "express" export async function evalServerImpl() { const evalServer = express() - evalServer.use(cors({ origin: "*" })) + evalServer.use(cors({ origin: true })) evalServer.use(express.json()) diff --git a/src/parsers/typescript/index.ts b/src/parsers/typescript/index.ts index 5660bfd..ea5db23 100644 --- a/src/parsers/typescript/index.ts +++ b/src/parsers/typescript/index.ts @@ -54,6 +54,33 @@ class TypescriptParser extends Parser { } parseProject() { + // Include package.json for dependency management as well + const packageJsonPath = path.resolve(this.projectPath, "package.json") + + let packageJSONExists = false + + try { + const packageJsonCheck = fsSync.statSync(packageJsonPath) + + const packageJSONContents = fsSync.readFileSync(packageJsonPath, { + encoding: "utf-8", + }) + + this.dependencyGraph.addModuleNode({ + modulePath: this.getPathRelativeToProjectRoot(packageJsonPath), + moduleSourceCode: packageJSONContents, + }) + + packageJSONExists = true + } catch (e) { + log( + "parser.typescript", + LogLevel.Info, + "package.json does not exist", + e, + ) + } + const sourceFiles = this.tsProject.getSourceFiles() sourceFiles.forEach((sourceFile) => { @@ -67,6 +94,14 @@ class TypescriptParser extends Parser { moduleSourceCode: sourceCode, }) + if (packageJSONExists) { + this.dependencyGraph.addModuleToModuleDependency({ + dependentModulePath: relativeFilePath, + dependencyModulePath: + this.getPathRelativeToProjectRoot(packageJsonPath), + }) + } + // Imports const sourceFileImports = sourceFile.getImportDeclarations() @@ -112,7 +147,7 @@ class TypescriptParser extends Parser { }, ) - const mergedDeclarations = textDeclarations.join(" ") + const mergedDeclarations = textDeclarations.join("\n") this.dependencyGraph.addSymbolNode({ symbolIdentifier: exportName, symbolPath: relativeFilePath, @@ -126,6 +161,26 @@ class TypescriptParser extends Parser { dependentSymbolIdentifier: exportName, dependentSymbolPath: relativeFilePath, }) + + // Copy all imports of a module to the dependencies of the export as well + this.dependencyGraph + .getSymbolDependenciesOfModule(relativeFilePath) + .forEach((modSymDependency) => { + const symbolNode = this.dependencyGraph.getSymbolNode( + modSymDependency.dependencySymbolPath, + modSymDependency.dependencySymbolIdentifier, + ) + + if (symbolNode) { + this.dependencyGraph.addSymbolToSymbolDependency({ + dependencySymbolIdentifier: + symbolNode.symbolIdentifier, + dependencySymbolPath: symbolNode.symbolPath, + dependentSymbolPath: relativeFilePath, + dependentSymbolIdentifier: exportName, + }) + } + }) } })