Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow overriding tsconfig options from within tsconfig.json #1891

Merged
merged 1 commit into from Apr 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions src/lib/utils/options/declaration.ts
Expand Up @@ -110,6 +110,7 @@ export interface TypeDocOptionMap {
logger: unknown; // string | Function
logLevel: typeof LogLevel;
markedOptions: unknown;
compilerOptions: unknown;

// Validation
treatWarningsAsErrors: boolean;
Expand Down
5 changes: 5 additions & 0 deletions src/lib/utils/options/options.ts
Expand Up @@ -328,8 +328,13 @@ export class Options {
fixCompilerOptions(
options: Readonly<ts.CompilerOptions>
): ts.CompilerOptions {
const overrides = this.getValue("compilerOptions");
const result = { ...options };

if (overrides) {
Object.assign(result, overrides);
}

if (
this.getValue("emit") !== "both" &&
this.getValue("emit") !== true
Expand Down
16 changes: 16 additions & 0 deletions src/lib/utils/options/sources/typedoc.ts
Expand Up @@ -327,6 +327,22 @@ export function addTypeDocOptions(options: Pick<Options, "addDeclaration">) {
}
},
});
options.addDeclaration({
name: "compilerOptions",
help: "Selectively override the TypeScript compiler options used by TypeDoc.",
type: ParameterType.Mixed,
validate(value) {
if (
typeof value !== "object" ||
Array.isArray(value) ||
value == null
) {
throw new Error(
"The 'compilerOptions' option must be a non-array object."
);
}
},
});

options.addDeclaration({
name: "treatWarningsAsErrors",
Expand Down
8 changes: 8 additions & 0 deletions src/test/utils/options/default-options.test.ts
Expand Up @@ -55,6 +55,14 @@ describe("Default Options", () => {
});
});

describe("compilerOptions", () => {
it("Errors if given a non-object", () => {
throws(() => opts.setValue("markedOptions", null));
throws(() => opts.setValue("markedOptions", "bad"));
throws(() => opts.setValue("markedOptions", []));
});
});

describe("requiredToBeDocumented", () => {
it("Works with valid values", () => {
doesNotThrow(() =>
Expand Down