Skip to content

Commit

Permalink
feat(typescript): add build support for es2020+ (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
DRiFTy17 committed Sep 5, 2023
1 parent f4bc0c2 commit 475bc5a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 36 deletions.
34 changes: 0 additions & 34 deletions src/constants.ts

This file was deleted.

18 changes: 16 additions & 2 deletions src/typescript/typescript.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import * as ts from 'typescript';

import { TS_LIB_MAP } from '../constants';
import { isGlob, log, logError, logInfo, logWarn } from '../utils';
import { readJsonFile, globFilesAsync } from '../fs';

Expand Down Expand Up @@ -31,7 +30,7 @@ export async function compileTypeScript(files: string[] | string, options: IType
// filename (i.e. lib.es2015.d.ts), which differs from the regular tsconfig lib entries. This allows
// lib entries to specified the same way (i.e. es2015 => lib.es2015.d.ts)
if (options.lib) {
options.lib = options.lib.map(lib => TS_LIB_MAP[lib] || lib);
options.lib = options.lib.map(lib => `lib.${lib}.d.ts`);
}

const program = ts.createProgram(files, options);
Expand Down Expand Up @@ -96,6 +95,12 @@ export function normalizeCompilerOptions(options: ts.CompilerOptions): ts.Compil
case 'es2015':
options.module = ts.ModuleKind.ES2015;
break;
case 'es2020':
options.module = ts.ModuleKind.ES2020;
break;
case 'es2022':
options.module = ts.ModuleKind.ES2022;
break;
case 'esnext':
options.module = ts.ModuleKind.ESNext;
break;
Expand Down Expand Up @@ -134,6 +139,15 @@ export function normalizeCompilerOptions(options: ts.CompilerOptions): ts.Compil
case 'ES2018':
options.target = ts.ScriptTarget.ES2018;
break;
case 'ES2019':
options.target = ts.ScriptTarget.ES2019;
break;
case 'ES2020':
options.target = ts.ScriptTarget.ES2020;
break;
case 'ES2021':
options.target = ts.ScriptTarget.ES2021;
break;
case 'ESNEXT':
options.target = ts.ScriptTarget.ESNext;
break;
Expand Down

0 comments on commit 475bc5a

Please sign in to comment.