1
1
import { BehaviorSubject , Observable , OperatorFunction } from 'rxjs' ;
2
2
import * as TsTypes from 'typescript' ;
3
+ import { map , tap } from 'rxjs/operators' ;
3
4
import { getTypeScript } from '../loaders/loaders' ;
4
5
5
6
const ts = getTypeScript ( ) ;
6
7
7
- // TODO(sancheez): Duplication
8
-
9
8
export interface Files {
10
9
[ key : string ] : string ;
11
10
}
@@ -30,8 +29,9 @@ interface Output {
30
29
}
31
30
32
31
const compilerOptions : TsTypes . CompilerOptions = {
32
+ baseUrl : './' ,
33
33
module : ts . ModuleKind . System ,
34
- target : ts . ScriptTarget . ES2017 ,
34
+ target : ts . ScriptTarget . ES2022 ,
35
35
experimentalDecorators : true ,
36
36
emitDecoratorMetadata : true ,
37
37
noImplicitAny : true ,
@@ -67,11 +67,13 @@ function watch(
67
67
return undefined ;
68
68
}
69
69
70
+ const baseName = fileName . replace ( '.ts' , '' ) ;
71
+
70
72
return ts . ScriptSnapshot . fromString (
71
- `/// <amd-module name="${ fileName . replace ( '.ts' , '' ) } " />\n` + file . file
73
+ `/// <amd-module name="./ ${ baseName } " />\n` + file . file
72
74
) ;
73
75
} ,
74
- getCurrentDirectory : ( ) => '/' ,
76
+ getCurrentDirectory : ( ) => options . baseUrl ,
75
77
getCompilationSettings : ( ) => options ,
76
78
getDefaultLibFileName : ( ) => 'lib.d.ts' ,
77
79
fileExists : ( a ) => ! ! files [ a ] ,
@@ -190,6 +192,14 @@ export function compileTsFilesWatch(
190
192
options = compilerOptions
191
193
) : OperatorFunction < Record < string , string > , Output > {
192
194
return ( source : Observable < Record < string , string > > ) => {
193
- return watch ( source , options ) ;
195
+ return watch (
196
+ source . pipe (
197
+ map ( ( files ) => ( {
198
+ 'code.ts' : 'export class Code {}' , // TODO(sancheez): code file, maybe needs another files
199
+ ...files ,
200
+ } ) )
201
+ ) ,
202
+ options
203
+ ) . pipe ( tap ( console . log ) ) ;
194
204
} ;
195
205
}
0 commit comments