Skip to content

Commit

Permalink
update compiler
Browse files Browse the repository at this point in the history
  • Loading branch information
lolopinto committed Dec 27, 2024
1 parent aa049d5 commit 68c6bd9
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions ts/src/tsc/compilerOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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());
Expand Down

0 comments on commit 68c6bd9

Please sign in to comment.