Skip to content

Commit 71ceaaa

Browse files
committed
fix: Implicitly set noEmit unless --emit is provided
Closes #1639
1 parent 8f6992a commit 71ceaaa

File tree

4 files changed

+45
-23
lines changed

4 files changed

+45
-23
lines changed

scripts/rebuild_specs.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,10 @@ const conversions = [
5656
* @param {string[]} dirs
5757
*/
5858
function rebuildConverterTests(dirs) {
59-
const program = ts.createProgram(
60-
app.options.getFileNames(),
61-
app.options.getCompilerOptions()
62-
);
59+
const program = ts.createProgram(app.options.getFileNames(), {
60+
...app.options.getCompilerOptions(),
61+
noEmit: true,
62+
});
6363

6464
const errors = ts.getPreEmitDiagnostics(program);
6565
if (errors.length) {

src/lib/application.ts

Lines changed: 33 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,8 @@ const supportedVersionMajorMinor = packageInfo.peerDependencies.typescript
5555
*/
5656
function getEntryPointsForPackages(
5757
logger: Logger,
58-
packageGlobPaths: string[]
58+
packageGlobPaths: string[],
59+
willEmit: boolean
5960
): DocumentationEntryPoint[] | undefined {
6061
const results = new Array<DocumentationEntryPoint>();
6162
// --packages arguments are workspace tree roots, or glob patterns
@@ -114,7 +115,7 @@ function getEntryPointsForPackages(
114115
}
115116
const program = ts.createProgram({
116117
rootNames: parsedCommandLine.fileNames,
117-
options: parsedCommandLine.options,
118+
options: fixCompilerOptions(parsedCommandLine.options, willEmit),
118119
});
119120
const sourceFile = program.getSourceFile(packageEntryPoint);
120121
if (sourceFile === undefined) {
@@ -133,6 +134,16 @@ function getEntryPointsForPackages(
133134
return results;
134135
}
135136

137+
function fixCompilerOptions(
138+
options: ts.CompilerOptions,
139+
willEmit: boolean
140+
): ts.CompilerOptions {
141+
return {
142+
...options,
143+
noEmit: willEmit === false,
144+
};
145+
}
146+
136147
function getModuleName(fileName: string, baseDir: string) {
137148
return normalizePath(Path.relative(baseDir, fileName)).replace(
138149
/(\/index)?(\.d)?\.[tj]sx?$/,
@@ -181,20 +192,21 @@ export class Application extends ChildableComponent<
181192

182193
options: Options;
183194

195+
/** @internal */
184196
@BindOption("logger")
185197
loggerType!: string | Function;
186198

199+
/** @internal */
187200
@BindOption("exclude")
188201
exclude!: Array<string>;
189202

203+
/** @internal */
190204
@BindOption("entryPoints")
191205
entryPoints!: string[];
192206

193-
@BindOption("options")
194-
optionsFile!: string;
195-
196-
@BindOption("tsconfig")
197-
project!: string;
207+
/** @internal */
208+
@BindOption("emit")
209+
emit!: boolean;
198210

199211
/**
200212
* The version number of TypeDoc.
@@ -324,7 +336,11 @@ export class Application extends ChildableComponent<
324336
}
325337

326338
const packages = this.options.getValue("packages").map(normalizePath);
327-
const entryPoints = getEntryPointsForPackages(this.logger, packages);
339+
const entryPoints = getEntryPointsForPackages(
340+
this.logger,
341+
packages,
342+
this.emit
343+
);
328344
if (entryPoints === undefined) {
329345
return;
330346
}
@@ -422,7 +438,7 @@ export class Application extends ChildableComponent<
422438

423439
const host = ts.createWatchCompilerHost(
424440
tsconfigFile,
425-
{ noEmit: !this.options.getValue("emit") },
441+
fixCompilerOptions({}, this.emit),
426442
ts.sys,
427443
ts.createEmitAndSemanticDiagnosticsBuilderProgram,
428444
(diagnostic) => this.logger.diagnostic(diagnostic),
@@ -599,7 +615,10 @@ export class Application extends ChildableComponent<
599615
private getEntryPrograms() {
600616
const rootProgram = ts.createProgram({
601617
rootNames: this.options.getFileNames(),
602-
options: this.options.getCompilerOptions(),
618+
options: fixCompilerOptions(
619+
this.options.getCompilerOptions(),
620+
this.emit
621+
),
603622
projectReferences: this.options.getProjectReferences(),
604623
});
605624

@@ -617,7 +636,10 @@ export class Application extends ChildableComponent<
617636

618637
programs.push(
619638
ts.createProgram({
620-
options: ref.commandLine.options,
639+
options: fixCompilerOptions(
640+
ref.commandLine.options,
641+
this.emit
642+
),
621643
rootNames: ref.commandLine.fileNames,
622644
projectReferences: ref.commandLine.projectReferences,
623645
})

src/test/converter.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@ describe("Converter", function () {
2626

2727
let program: ts.Program;
2828
it("Compiles", () => {
29-
program = ts.createProgram(
30-
app.options.getFileNames(),
31-
app.options.getCompilerOptions()
32-
);
29+
program = ts.createProgram(app.options.getFileNames(), {
30+
...app.options.getCompilerOptions(),
31+
noEmit: true,
32+
});
3333

3434
const errors = ts.getPreEmitDiagnostics(program);
3535
equal(errors, []);

src/test/converter2.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -246,10 +246,10 @@ describe("Converter2", () => {
246246

247247
let program: ts.Program;
248248
before("Compiles", () => {
249-
program = ts.createProgram(
250-
app.options.getFileNames(),
251-
app.options.getCompilerOptions()
252-
);
249+
program = ts.createProgram(app.options.getFileNames(), {
250+
...app.options.getCompilerOptions(),
251+
noEmit: true,
252+
});
253253

254254
const errors = ts.getPreEmitDiagnostics(program);
255255
app.logger.diagnostics(errors);

0 commit comments

Comments
 (0)