@@ -13,6 +13,7 @@ import {
1313 writeFile ,
1414 discoverNpmPlugins ,
1515 NeverIfInternal ,
16+ TSConfigReader ,
1617} from "./utils/index" ;
1718
1819import {
@@ -23,13 +24,13 @@ import {
2324import { Options , BindOption } from "./utils" ;
2425import type { TypeDocOptions } from "./utils/options/declaration" ;
2526import { flatMap , unique } from "./utils/array" ;
26- import { basename } from "path" ;
2727import { validateExports } from "./validation/exports" ;
2828import { ok } from "assert" ;
2929import {
3030 DocumentationEntryPoint ,
3131 EntryPointStrategy ,
3232 getEntryPoints ,
33+ getWatchEntryPoints ,
3334} from "./utils/entry-point" ;
3435import { nicePath } from "./utils/paths" ;
3536
@@ -297,24 +298,17 @@ export class Application extends ChildableComponent<
297298 return ;
298299 }
299300
300- // Matches the behavior of the tsconfig option reader.
301- let tsconfigFile = this . options . getValue ( "tsconfig" ) ;
302- tsconfigFile =
303- ts . findConfigFile (
304- tsconfigFile ,
305- ts . sys . fileExists ,
306- tsconfigFile . toLowerCase ( ) . endsWith ( ".json" )
307- ? basename ( tsconfigFile )
308- : undefined
309- ) ?? "tsconfig.json" ;
301+ const tsconfigFile =
302+ TSConfigReader . findConfigFile ( this . options . getValue ( "tsconfig" ) ) ??
303+ "tsconfig.json" ;
310304
311305 // We don't want to do it the first time to preserve initial debug status messages. They'll be lost
312306 // after the user saves a file, but better than nothing...
313307 let firstStatusReport = true ;
314308
315309 const host = ts . createWatchCompilerHost (
316310 tsconfigFile ,
317- this . options . fixCompilerOptions ( { } ) ,
311+ { } ,
318312 ts . sys ,
319313 ts . createEmitAndSemanticDiagnosticsBuilderProgram ,
320314 ( diagnostic ) => this . logger . diagnostic ( diagnostic ) ,
@@ -343,8 +337,20 @@ export class Application extends ChildableComponent<
343337 }
344338
345339 if ( successFinished ) {
340+ if (
341+ this . options . getValue ( "emit" ) === "both" ||
342+ this . options . getValue ( "emit" ) === true
343+ ) {
344+ currentProgram . emit ( ) ;
345+ }
346+
346347 this . logger . resetErrors ( ) ;
347- const entryPoints = this . getEntryPoints ( ) ;
348+ this . logger . resetWarnings ( ) ;
349+ const entryPoints = getWatchEntryPoints (
350+ this . logger ,
351+ this . options ,
352+ currentProgram
353+ ) ;
348354 if ( ! entryPoints ) {
349355 return ;
350356 }
@@ -358,6 +364,30 @@ export class Application extends ChildableComponent<
358364 }
359365 } ;
360366
367+ const origCreateProgram = host . createProgram ;
368+ host . createProgram = (
369+ rootNames ,
370+ options ,
371+ host ,
372+ oldProgram ,
373+ configDiagnostics ,
374+ references
375+ ) => {
376+ // If we always do this, we'll get a crash the second time a program is created.
377+ if ( rootNames !== undefined ) {
378+ options = this . options . fixCompilerOptions ( options || { } ) ;
379+ }
380+
381+ return origCreateProgram (
382+ rootNames ,
383+ options ,
384+ host ,
385+ oldProgram ,
386+ configDiagnostics ,
387+ references
388+ ) ;
389+ } ;
390+
361391 const origAfterProgramCreate = host . afterProgramCreate ;
362392 host . afterProgramCreate = ( program ) => {
363393 if ( ts . getPreEmitDiagnostics ( program . getProgram ( ) ) . length === 0 ) {
0 commit comments