@@ -31,6 +31,7 @@ namespace ts {
31
31
protected projectService : server . ProjectService ;
32
32
constructor ( private readonly host : server . ServerHost ) {
33
33
super ( ) ;
34
+ this . init ( ) ;
34
35
}
35
36
36
37
abstract cachePath : string ;
@@ -259,6 +260,8 @@ namespace ts {
259
260
260
261
readonly watchedDirectories : MapLike < { cb : DirectoryWatcherCallback , recursive : boolean } [ ] > = { } ;
261
262
readonly watchedFiles : MapLike < FileWatcherCallback [ ] > = { } ;
263
+
264
+ private filesOrFolders : FileOrFolder [ ] ;
262
265
263
266
constructor ( public useCaseSensitiveFileNames : boolean , private executingFilePath : string , private currentDirectory : string , fileOrFolderList : FileOrFolder [ ] ) {
264
267
this . getCanonicalFileName = createGetCanonicalFileName ( useCaseSensitiveFileNames ) ;
@@ -268,6 +271,7 @@ namespace ts {
268
271
}
269
272
270
273
reloadFS ( filesOrFolders : FileOrFolder [ ] ) {
274
+ this . filesOrFolders = filesOrFolders ;
271
275
this . fs = createFileMap < FSEntry > ( ) ;
272
276
for ( const fileOrFolder of filesOrFolders ) {
273
277
const path = this . toPath ( fileOrFolder . path ) ;
@@ -419,15 +423,36 @@ namespace ts {
419
423
this . immediateCallbacks . unregister ( timeoutId ) ;
420
424
} ;
421
425
426
+ createDirectory ( directoryName : string ) : void {
427
+ this . createFileOrFolder ( { path : directoryName } ) ;
428
+ }
422
429
430
+ writeFile ( path : string , content : string ) : void {
431
+ this . createFileOrFolder ( { path, content, fileSize : content . length } )
432
+ }
433
+
434
+ createFileOrFolder ( f : FileOrFolder , createParentDirectory = false ) : void {
435
+ const base = getDirectoryPath ( f . path ) ;
436
+ if ( base !== f . path && ! this . directoryExists ( base ) ) {
437
+ if ( createParentDirectory ) {
438
+ // TODO: avoid reloading FS on every creation
439
+ this . createFileOrFolder ( { path : base } , createParentDirectory ) ;
440
+ }
441
+ else {
442
+ throw new Error ( `directory ${ base } does not exist` ) ;
443
+ }
444
+ }
445
+ const filesOrFolders = this . filesOrFolders . slice ( 0 ) ;
446
+ filesOrFolders . push ( f ) ;
447
+ this . reloadFS ( filesOrFolders ) ;
448
+ }
449
+
423
450
readonly readFile = ( s : string ) => ( < File > this . fs . get ( this . toPath ( s ) ) ) . content ;
424
451
readonly resolvePath = ( s : string ) => s ;
425
452
readonly getExecutingFilePath = ( ) => this . executingFilePath ;
426
453
readonly getCurrentDirectory = ( ) => this . currentDirectory ;
427
- readonly writeFile = ( path : string , content : string ) => notImplemented ( ) ;
428
454
readonly writeCompressedData = ( ) => notImplemented ( ) ;
429
455
readonly write = ( s : string ) => notImplemented ( ) ;
430
- readonly createDirectory = ( s : string ) => notImplemented ( ) ;
431
456
readonly exit = ( ) => notImplemented ( ) ;
432
457
}
433
458
@@ -1496,7 +1521,7 @@ namespace ts {
1496
1521
class TypingInstaller extends TestTypingsInstaller {
1497
1522
cachePath = "/a/data/" ;
1498
1523
constructor ( host : server . ServerHost ) {
1499
- super ( host )
1524
+ super ( host ) ;
1500
1525
}
1501
1526
} ;
1502
1527
const installer = new TypingInstaller ( host ) ;
@@ -1507,9 +1532,11 @@ namespace ts {
1507
1532
const p = projectService . configuredProjects [ 0 ] ;
1508
1533
checkProjectActualFiles ( p , [ file1 . path ] ) ;
1509
1534
1535
+ assert ( host . fileExists ( combinePaths ( installer . cachePath , "tsd.json" ) ) ) ;
1536
+
1510
1537
installer . runPostInstallActions ( t => {
1511
1538
assert . deepEqual ( t , [ "jquery" ] ) ;
1512
- host . reloadFS ( [ file1 , tsconfig , packageJson , jquery ] ) ;
1539
+ host . createFileOrFolder ( jquery , /*createParentDirectory*/ true ) ;
1513
1540
return [ "jquery/jquery.d.ts" ] ;
1514
1541
} ) ;
1515
1542
checkNumberOfProjects ( projectService , { configuredProjects : 1 } )
0 commit comments