1
- import * as tsvfs from "@typescript/vfs"
2
- import ts from "typescript"
3
- import { readFileSync } from "fs"
4
- import { join } from "path"
1
+ import * as tsvfs from "@typescript/vfs" ;
2
+ import ts from "typescript" ;
3
+ import { readFileSync } from "fs" ;
4
+ import { join } from "path" ;
5
5
6
6
const getLib = ( name ) => {
7
- const lib = dirname ( require . resolve ( "typescript" ) )
8
- return readFileSync ( join ( lib , name ) , "utf8" )
9
- }
7
+ const lib = dirname ( require . resolve ( "typescript" ) ) ;
8
+ return readFileSync ( join ( lib , name ) , "utf8" ) ;
9
+ } ;
10
10
11
11
const addLib = ( name , map ) => {
12
- map . set ( "/" + name , getLib ( name ) )
13
- }
12
+ map . set ( "/" + name , getLib ( name ) ) ;
13
+ } ;
14
14
15
15
const createDefaultMap2015 = ( ) => {
16
- const fsMap = new Map ( )
17
- addLib ( "lib.es2015.d.ts" , fsMap )
18
- addLib ( "lib.es2015.collection.d.ts" , fsMap )
19
- addLib ( "lib.es2015.core.d.ts" , fsMap )
20
- addLib ( "lib.es2015.generator.d.ts" , fsMap )
21
- addLib ( "lib.es2015.iterable.d.ts" , fsMap )
22
- addLib ( "lib.es2015.promise.d.ts" , fsMap )
23
- addLib ( "lib.es2015.proxy.d.ts" , fsMap )
24
- addLib ( "lib.es2015.reflect.d.ts" , fsMap )
25
- addLib ( "lib.es2015.symbol.d.ts" , fsMap )
26
- addLib ( "lib.es2015.symbol.wellknown.d.ts" , fsMap )
27
- addLib ( "lib.es5.d.ts" , fsMap )
28
- return fsMap
29
- }
16
+ const fsMap = new Map ( ) ;
17
+ addLib ( "lib.es2015.d.ts" , fsMap ) ;
18
+ addLib ( "lib.es2015.collection.d.ts" , fsMap ) ;
19
+ addLib ( "lib.es2015.core.d.ts" , fsMap ) ;
20
+ addLib ( "lib.es2015.generator.d.ts" , fsMap ) ;
21
+ addLib ( "lib.es2015.iterable.d.ts" , fsMap ) ;
22
+ addLib ( "lib.es2015.promise.d.ts" , fsMap ) ;
23
+ addLib ( "lib.es2015.proxy.d.ts" , fsMap ) ;
24
+ addLib ( "lib.es2015.reflect.d.ts" , fsMap ) ;
25
+ addLib ( "lib.es2015.symbol.d.ts" , fsMap ) ;
26
+ addLib ( "lib.es2015.symbol.wellknown.d.ts" , fsMap ) ;
27
+ addLib ( "lib.es5.d.ts" , fsMap ) ;
28
+ return fsMap ;
29
+ } ;
30
30
31
31
function compile ( fsMap , compilerOptions ) {
32
- const baseMap = createDefaultMap2015 ( )
32
+ const baseMap = createDefaultMap2015 ( ) ;
33
33
fsMap . keys . forEach ( ( key ) => {
34
- baseMap . set ( key , fsMap . get ( key ) )
34
+ baseMap . set ( key , fsMap . get ( key ) ) ;
35
35
} ) ;
36
36
37
- const system = tsvfs . createSystem ( fsMap )
38
- const host = tsvfs . createVirtualCompilerHost (
39
- system ,
40
- compilerOptions ,
41
- ts ,
42
- )
37
+ const system = tsvfs . createSystem ( fsMap ) ;
38
+ const host = tsvfs . createVirtualCompilerHost ( system , compilerOptions , ts ) ;
43
39
44
40
const program = ts . createProgram ( {
45
41
rootNames : [ ...fsMap . keys ( ) ] ,
@@ -49,11 +45,9 @@ function compile(fsMap, compilerOptions) {
49
45
50
46
const emitResult = program . emit ( ) ;
51
47
52
- const allDiagnostics = ts
53
- . getPreEmitDiagnostics ( program )
54
- . concat ( emitResult . diagnostics ) ;
48
+ const allDiagnostics = ts . getPreEmitDiagnostics ( program ) . concat ( emitResult . diagnostics ) ;
55
49
56
- allDiagnostics . forEach ( diagnostic => {
50
+ allDiagnostics . forEach ( ( diagnostic ) => {
57
51
if ( diagnostic . file ) {
58
52
let { line, character } = ts . getLineAndCharacterOfPosition ( diagnostic . file , diagnostic . start ) ;
59
53
let message = ts . flattenDiagnosticMessageText ( diagnostic . messageText , "\n" ) ;
@@ -69,10 +63,10 @@ function compile(fsMap, compilerOptions) {
69
63
}
70
64
71
65
export default function entry ( args ) {
72
- console . log ( "Running `tsc`..." , JSON . stringify ( { args : args [ 0 ] } ) ) ;
66
+ console . log ( "Running `tsc`..." , JSON . stringify ( { args : args [ 0 ] } ) ) ;
73
67
const fsMap = new Map ( ) ;
74
68
const exitCode = compile ( args [ 0 ] , { } ) ;
75
- console . log ( "Result of `tsc`:" , { exitCode} ) ;
69
+ console . log ( "Result of `tsc`:" , { exitCode } ) ;
76
70
return exitCode ;
77
71
}
78
72
0 commit comments