Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/eval-server/controllers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({})
Expand Down
2 changes: 1 addition & 1 deletion src/eval-server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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())

Expand Down
57 changes: 56 additions & 1 deletion src/parsers/typescript/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand All @@ -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()

Expand Down Expand Up @@ -112,7 +147,7 @@ class TypescriptParser extends Parser {
},
)

const mergedDeclarations = textDeclarations.join(" ")
const mergedDeclarations = textDeclarations.join("\n")
this.dependencyGraph.addSymbolNode({
symbolIdentifier: exportName,
symbolPath: relativeFilePath,
Expand All @@ -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,
})
}
})
}
})

Expand Down