From 68c6bd977934199f98abe9595267b49370f92be2 Mon Sep 17 00:00:00 2001 From: Ola Okelola Date: Fri, 27 Dec 2024 13:45:50 +0800 Subject: [PATCH] update compiler --- ts/src/tsc/compilerOptions.ts | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/ts/src/tsc/compilerOptions.ts b/ts/src/tsc/compilerOptions.ts index 272797f71..c4df4c362 100644 --- a/ts/src/tsc/compilerOptions.ts +++ b/ts/src/tsc/compilerOptions.ts @@ -35,6 +35,8 @@ export function readCompilerOptions(filePath: string) { if (options.moduleResolution === "node") { options.moduleResolution = ts.ModuleResolutionKind.NodeJs; } + options.target = getTarget(options.target as string | undefined); + options.module = getModule(options.module as string | undefined); return options; } @@ -65,6 +67,37 @@ export function getTarget(target?: string): ts.ScriptTarget { } } +export function getModule(module?: string): ts.ModuleKind { + switch (module?.toLowerCase()) { + case "none": + return ts.ModuleKind.None; + case "commonjs": + return ts.ModuleKind.CommonJS; + case "amd": + return ts.ModuleKind.AMD; + case "umd": + return ts.ModuleKind.UMD; + case "system": + return ts.ModuleKind.System; + case "es2015": + return ts.ModuleKind.ES2015; + case "es2020": + return ts.ModuleKind.ES2020; + case "es2022": + return ts.ModuleKind.ES2022; + case "esnext": + return ts.ModuleKind.ESNext; + case "node16": + return ts.ModuleKind.Node16; + case "nodenext": + return ts.ModuleKind.NodeNext; + case "preserve": + return ts.ModuleKind.Preserve; + default: + return ts.ModuleKind.CommonJS; + } +} + export function getTargetFromCurrentDir(): ts.ScriptTarget { const options = readCompilerOptions("."); return getTarget(options.target?.toString());