From 26e7a6ab81e626ccf6d0e332447aa66f7671c5a3 Mon Sep 17 00:00:00 2001 From: Ola Okelola <10857143+lolopinto@users.noreply.github.com> Date: Sun, 29 Dec 2024 16:18:13 +0800 Subject: [PATCH] update compiler (#1868) * update compiler * remove preserve --- ts/src/tsc/compilerOptions.ts | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/ts/src/tsc/compilerOptions.ts b/ts/src/tsc/compilerOptions.ts index 272797f71..1074c6c5b 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,35 @@ 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; + default: + return ts.ModuleKind.CommonJS; + } +} + export function getTargetFromCurrentDir(): ts.ScriptTarget { const options = readCompilerOptions("."); return getTarget(options.target?.toString());