import ts from 'typescript' import { ConfigConverter } from './ConfigConverter' import { CliArgs } from './interfaces' import { pathsLoadPlugin } from './plugins/paths' // https://github.com/search?l=TypeScript&q=parseJsonSourceFileConfigFileContent&type=Code export function composeEsbuildOptions(cwd: string = process.cwd(), cliArgs: CliArgs = {}) { const tsConfigFile = ts.findConfigFile(cwd, ts.sys.fileExists, 'tsconfig.json') if (!tsConfigFile) { throw new Error(`tsconfig.json not found in the current directory!`) } const configFile = ts.readJsonConfigFile(tsConfigFile, ts.sys.readFile) const parsedConfigFile = ts.parseJsonSourceFileConfigFileContent(configFile, ts.sys, cwd) const converter = new ConfigConverter({ parsedCommandLine: parsedConfigFile, cwd }) converter.mergeCliArgs(cliArgs) const esbuildOptions = converter.convert() // esbuildOptions.plugins = [pathsLoadPlugin({})] return esbuildOptions }