relaycode
Version:
A developer assistant that automates applying code changes from LLMs.
1 lines • 6.84 kB
Source Map (JSON)
{"version":3,"sources":["../../src/utils/typescript.ts"],"names":["countErrors","diagnostics","d","ts","parseTscCommand","command","projectFlagRegex","buildFlagRegex","projectPath","projectMatch","buildPath","buildMatch","getTsConfigPath","cwd","options","tsconfigPath","path","logger","getTypeScriptErrorCount","linterCommand","commandOptions","reportDiagnostic","host","configFile","parsedCommandLine","program"],"mappings":"2PAIMA,CAAAA,CAAeC,CAAAA,EACZA,CAAAA,CAAY,MAAA,CAAOC,GAAKA,CAAAA,CAAE,QAAA,GAAaC,kBAAAA,CAAG,kBAAA,CAAmB,KAAK,CAAA,CAAE,MAAA,CAGvEC,CAAAA,CAAmBC,GAAoB,CAC3C,MAAMC,CAAAA,CAAmB,6BAAA,CACnBC,EAAiB,gBAAA,CAEvB,IAAIC,CAAAA,CACJ,MAAMC,EAAeJ,CAAAA,CAAQ,KAAA,CAAMC,CAAgB,CAAA,CAC/CG,CAAAA,GACFD,CAAAA,CAAcC,CAAAA,CAAa,CAAC,GAG9B,IAAIC,CAAAA,CACJ,MAAMC,CAAAA,CAAaN,EAAQ,KAAA,CAAM,2BAA2B,CAAA,CAC5D,OAAIM,IACFD,CAAAA,CAAYC,CAAAA,CAAW,CAAC,CAAA,CAAA,CAGnB,CACL,OAAA,CAASH,CAAAA,CACT,KAAA,CAAOD,CAAAA,CAAe,KAAKF,CAAO,CAAA,CAClC,SAAA,CAAWK,CACb,CACF,CAAA,CAEME,CAAAA,CAAkB,CAACP,CAAAA,CAAiBQ,IAAoC,CAC5E,MAAMC,CAAAA,CAAUV,CAAAA,CAAgBC,CAAO,CAAA,CACvC,IAAIU,CAAAA,CAgBJ,GAdID,CAAAA,CAAQ,SAAA,CACVC,CAAAA,CAAeC,kBAAAA,CAAK,QAAQH,CAAAA,CAAKC,CAAAA,CAAQ,SAAS,CAAA,CACzCA,EAAQ,OAAA,GACjBC,CAAAA,CAAeC,kBAAAA,CAAK,OAA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AACP,CAAY,CAAA,CAAG,CAAE,KAAA,CAAO,CAAA,CAAA,CAAM,QAAS,CAAA,CAAM,CAAC,CAAA,CACtF,KAAA,GAEDf,CAAAA,CAAYC,CAAW,CAChC,CAAA,KAAO,CACL,MAAMsB,CAAAA,CAAapB,kBAAAA,CAAG,cAAA,CAAeY,EAAcZ,kBAAAA,CAAG,GAAA,CAAI,QAAQ,CAAA,CAClE,GAAIoB,CAAAA,CAAW,KAAA,CACb,OAAAtB,EAAY,IAAA,CAAKsB,CAAAA,CAAW,KAAK,CAAA,CAC1BvB,EAAYC,CAAW,CAAA,CAGhC,MAAMuB,CAAAA,CAAoBrB,mBAAG,0BAAA,CAC3BoB,CAAAA,CAAW,MAAA,CACXpB,kBAAAA,CAAG,IACHa,kBAAAA,CAAK,OAAA,CAAQD,CAAY,CAC3B,EAEIS,CAAAA,CAAkB,MAAA,CAAO,MAAA,CAAS,CAAA,EACpCvB,EAAY,IAAA,CAAK,GAAGuB,CAAAA,CAAkB,MAAM,EAG9C,MAAMC,CAAAA,CAAUtB,kBAAAA,CAAG,aAAA,CAAcqB,CAAAA,CAAkB,SAAA,CAAWA,CAAAA,CAAkB,OAAO,EACvF,OAAAvB,CAAAA,CAAY,IAAA,CAAK,GAAGE,mBAAG,qBAAA,CAAsBsB,CAAO,CAAC,CAAA,CAE9CzB,EAAYC,CAAW,CAChC,CACF,CAAA,MAAS,EAAG,CACV,OAAAgB,aAAAA,CAAO,KAAA,CAAM,8CAA8C,CAAA,YAAa,KAAA,CAAQ,CAAA,CAAE,OAAA,CAAU,OAAO,CAAC,CAAC,CAAA,CAAE,CAAA,CAChG,EACT,CACF","file":"typescript.cjs","sourcesContent":["import ts from 'typescript';\nimport path from 'path';\nimport { logger } from './logger';\n\nconst countErrors = (diagnostics: readonly ts.Diagnostic[]): number => {\n return diagnostics.filter(d => d.category === ts.DiagnosticCategory.Error).length;\n};\n\nconst parseTscCommand = (command: string) => {\n const projectFlagRegex = /(?:--project|-p)\\s+([^\\s]+)/;\n const buildFlagRegex = /(?:--build|-b)/;\n\n let projectPath: string | undefined;\n const projectMatch = command.match(projectFlagRegex);\n if (projectMatch) {\n projectPath = projectMatch[1];\n }\n\n let buildPath: string | undefined;\n const buildMatch = command.match(/(?:--build|-b)\\s+([^\\s]+)/);\n if (buildMatch) {\n buildPath = buildMatch[1];\n }\n\n return {\n project: projectPath,\n build: buildFlagRegex.test(command),\n buildPath: buildPath\n };\n};\n\nconst getTsConfigPath = (command: string, cwd: string): string | undefined => {\n const options = parseTscCommand(command);\n let tsconfigPath: string | undefined;\n\n if (options.buildPath) {\n tsconfigPath = path.resolve(cwd, options.buildPath);\n } else if (options.project) {\n tsconfigPath = path.resolve(cwd, options.project);\n }\n\n if (tsconfigPath && ts.sys.directoryExists(tsconfigPath)) {\n tsconfigPath = path.join(tsconfigPath, 'tsconfig.json');\n }\n\n if (!tsconfigPath) {\n tsconfigPath = ts.findConfigFile(cwd, ts.sys.fileExists, 'tsconfig.json');\n }\n\n if (!tsconfigPath || !ts.sys.fileExists(tsconfigPath)) {\n logger.debug(`Could not find tsconfig.json to use with TypeScript API.`);\n return undefined;\n }\n\n logger.debug(`Using tsconfig for API-based linting: ${tsconfigPath}`);\n return tsconfigPath;\n};\n\n\nexport const getTypeScriptErrorCount = (linterCommand: string, cwd: string): number => {\n const commandOptions = parseTscCommand(linterCommand);\n const tsconfigPath = getTsConfigPath(linterCommand, cwd);\n\n if (!tsconfigPath) {\n return -1; // Sentinel value to indicate fallback\n }\n\n const diagnostics: ts.Diagnostic[] = [];\n const reportDiagnostic = (d: ts.Diagnostic) => diagnostics.push(d);\n\n try {\n if (commandOptions.build) {\n const host = ts.createSolutionBuilderHost(ts.sys, undefined, reportDiagnostic, reportDiagnostic);\n\n // To prevent emitting files if --noEmit is not in tsconfig, we can't easily override compilerOptions\n // for each project in the solution build. Instead, we can just intercept writeFile.\n host.writeFile = (path) => {\n logger.debug(`Intercepted write for ${path} during API-based linting.`);\n };\n\n const builder = ts.createSolutionBuilder(host, [tsconfigPath], { force: true, verbose: false });\n builder.build();\n\n return countErrors(diagnostics);\n } else {\n const configFile = ts.readConfigFile(tsconfigPath, ts.sys.readFile);\n if (configFile.error) {\n diagnostics.push(configFile.error);\n return countErrors(diagnostics);\n }\n\n const parsedCommandLine = ts.parseJsonConfigFileContent(\n configFile.config,\n ts.sys,\n path.dirname(tsconfigPath)\n );\n\n if (parsedCommandLine.errors.length > 0) {\n diagnostics.push(...parsedCommandLine.errors);\n }\n\n const program = ts.createProgram(parsedCommandLine.fileNames, parsedCommandLine.options);\n diagnostics.push(...ts.getPreEmitDiagnostics(program));\n\n return countErrors(diagnostics);\n }\n } catch (e) {\n logger.debug(`Error during TypeScript API-based linting: ${e instanceof Error ? e.message : String(e)}`);\n return -1; // Fallback on any error\n }\n};\n"]}