Skip to content

Commit

Permalink
fix: Implicitly set noEmit unless --emit is provided
Browse files Browse the repository at this point in the history
Closes #1639
  • Loading branch information
Gerrit0 committed Jul 31, 2021
1 parent 8f6992a commit 71ceaaa
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 23 deletions.
8 changes: 4 additions & 4 deletions scripts/rebuild_specs.js
Expand Up @@ -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) {
Expand Down
44 changes: 33 additions & 11 deletions src/lib/application.ts
Expand Up @@ -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<DocumentationEntryPoint>();
// --packages arguments are workspace tree roots, or glob patterns
Expand Down Expand Up @@ -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) {
Expand All @@ -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?$/,
Expand Down Expand Up @@ -181,20 +192,21 @@ export class Application extends ChildableComponent<

options: Options;

/** @internal */
@BindOption("logger")
loggerType!: string | Function;

/** @internal */
@BindOption("exclude")
exclude!: Array<string>;

/** @internal */
@BindOption("entryPoints")
entryPoints!: string[];

@BindOption("options")
optionsFile!: string;

@BindOption("tsconfig")
project!: string;
/** @internal */
@BindOption("emit")
emit!: boolean;

/**
* The version number of TypeDoc.
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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(),
});

Expand All @@ -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,
})
Expand Down
8 changes: 4 additions & 4 deletions src/test/converter.test.ts
Expand Up @@ -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, []);
Expand Down
8 changes: 4 additions & 4 deletions src/test/converter2.test.ts
Expand Up @@ -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);
Expand Down

0 comments on commit 71ceaaa

Please sign in to comment.