11import { BehaviorSubject , Observable , OperatorFunction } from 'rxjs' ;
22import * as TsTypes from 'typescript' ;
3+ import { map , tap } from 'rxjs/operators' ;
34import { getTypeScript } from '../loaders/loaders' ;
45
56const ts = getTypeScript ( ) ;
67
7- // TODO(sancheez): Duplication
8-
98export interface Files {
109 [ key : string ] : string ;
1110}
@@ -30,8 +29,9 @@ interface Output {
3029}
3130
3231const compilerOptions : TsTypes . CompilerOptions = {
32+ baseUrl : './' ,
3333 module : ts . ModuleKind . System ,
34- target : ts . ScriptTarget . ES2017 ,
34+ target : ts . ScriptTarget . ES2022 ,
3535 experimentalDecorators : true ,
3636 emitDecoratorMetadata : true ,
3737 noImplicitAny : true ,
@@ -67,11 +67,13 @@ function watch(
6767 return undefined ;
6868 }
6969
70+ const baseName = fileName . replace ( '.ts' , '' ) ;
71+
7072 return ts . ScriptSnapshot . fromString (
71- `/// <amd-module name="${ fileName . replace ( '.ts' , '' ) } " />\n` + file . file
73+ `/// <amd-module name="./ ${ baseName } " />\n` + file . file
7274 ) ;
7375 } ,
74- getCurrentDirectory : ( ) => '/' ,
76+ getCurrentDirectory : ( ) => options . baseUrl ,
7577 getCompilationSettings : ( ) => options ,
7678 getDefaultLibFileName : ( ) => 'lib.d.ts' ,
7779 fileExists : ( a ) => ! ! files [ a ] ,
@@ -190,6 +192,14 @@ export function compileTsFilesWatch(
190192 options = compilerOptions
191193) : OperatorFunction < Record < string , string > , Output > {
192194 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 ) ) ;
194204 } ;
195205}
0 commit comments