diff --git a/scripts/rebuild_specs.js b/scripts/rebuild_specs.js index b21b9c5e3..094ac1ea8 100644 --- a/scripts/rebuild_specs.js +++ b/scripts/rebuild_specs.js @@ -56,10 +56,10 @@ const conversions = [ * @param {string[]} dirs */ function rebuildConverterTests(dirs) { - const program = ts.createProgram( - app.options.getFileNames(), - app.options.getCompilerOptions() - ); + const program = ts.createProgram(app.options.getFileNames(), { + ...app.options.getCompilerOptions(), + noEmit: true, + }); const errors = ts.getPreEmitDiagnostics(program); if (errors.length) { diff --git a/src/lib/application.ts b/src/lib/application.ts index 618f59286..14ad9c396 100644 --- a/src/lib/application.ts +++ b/src/lib/application.ts @@ -55,7 +55,8 @@ const supportedVersionMajorMinor = packageInfo.peerDependencies.typescript */ function getEntryPointsForPackages( logger: Logger, - packageGlobPaths: string[] + packageGlobPaths: string[], + willEmit: boolean ): DocumentationEntryPoint[] | undefined { const results = new Array(); // --packages arguments are workspace tree roots, or glob patterns @@ -114,7 +115,7 @@ function getEntryPointsForPackages( } const program = ts.createProgram({ rootNames: parsedCommandLine.fileNames, - options: parsedCommandLine.options, + options: fixCompilerOptions(parsedCommandLine.options, willEmit), }); const sourceFile = program.getSourceFile(packageEntryPoint); if (sourceFile === undefined) { @@ -133,6 +134,16 @@ function getEntryPointsForPackages( return results; } +function fixCompilerOptions( + options: ts.CompilerOptions, + willEmit: boolean +): ts.CompilerOptions { + return { + ...options, + noEmit: willEmit === false, + }; +} + function getModuleName(fileName: string, baseDir: string) { return normalizePath(Path.relative(baseDir, fileName)).replace( /(\/index)?(\.d)?\.[tj]sx?$/, @@ -181,20 +192,21 @@ export class Application extends ChildableComponent< options: Options; + /** @internal */ @BindOption("logger") loggerType!: string | Function; + /** @internal */ @BindOption("exclude") exclude!: Array; + /** @internal */ @BindOption("entryPoints") entryPoints!: string[]; - @BindOption("options") - optionsFile!: string; - - @BindOption("tsconfig") - project!: string; + /** @internal */ + @BindOption("emit") + emit!: boolean; /** * The version number of TypeDoc. @@ -324,7 +336,11 @@ export class Application extends ChildableComponent< } const packages = this.options.getValue("packages").map(normalizePath); - const entryPoints = getEntryPointsForPackages(this.logger, packages); + const entryPoints = getEntryPointsForPackages( + this.logger, + packages, + this.emit + ); if (entryPoints === undefined) { return; } @@ -422,7 +438,7 @@ export class Application extends ChildableComponent< const host = ts.createWatchCompilerHost( tsconfigFile, - { noEmit: !this.options.getValue("emit") }, + fixCompilerOptions({}, this.emit), ts.sys, ts.createEmitAndSemanticDiagnosticsBuilderProgram, (diagnostic) => this.logger.diagnostic(diagnostic), @@ -599,7 +615,10 @@ export class Application extends ChildableComponent< private getEntryPrograms() { const rootProgram = ts.createProgram({ rootNames: this.options.getFileNames(), - options: this.options.getCompilerOptions(), + options: fixCompilerOptions( + this.options.getCompilerOptions(), + this.emit + ), projectReferences: this.options.getProjectReferences(), }); @@ -617,7 +636,10 @@ export class Application extends ChildableComponent< programs.push( ts.createProgram({ - options: ref.commandLine.options, + options: fixCompilerOptions( + ref.commandLine.options, + this.emit + ), rootNames: ref.commandLine.fileNames, projectReferences: ref.commandLine.projectReferences, }) diff --git a/src/test/converter.test.ts b/src/test/converter.test.ts index 477531484..2f0844700 100644 --- a/src/test/converter.test.ts +++ b/src/test/converter.test.ts @@ -26,10 +26,10 @@ describe("Converter", function () { let program: ts.Program; it("Compiles", () => { - program = ts.createProgram( - app.options.getFileNames(), - app.options.getCompilerOptions() - ); + program = ts.createProgram(app.options.getFileNames(), { + ...app.options.getCompilerOptions(), + noEmit: true, + }); const errors = ts.getPreEmitDiagnostics(program); equal(errors, []); diff --git a/src/test/converter2.test.ts b/src/test/converter2.test.ts index fdcbceb70..17608a2a9 100644 --- a/src/test/converter2.test.ts +++ b/src/test/converter2.test.ts @@ -246,10 +246,10 @@ describe("Converter2", () => { let program: ts.Program; before("Compiles", () => { - program = ts.createProgram( - app.options.getFileNames(), - app.options.getCompilerOptions() - ); + program = ts.createProgram(app.options.getFileNames(), { + ...app.options.getCompilerOptions(), + noEmit: true, + }); const errors = ts.getPreEmitDiagnostics(program); app.logger.diagnostics(errors);