Skip to content

Commit

Permalink
Merge pull request #1891 from schlusslicht/feat/override-tsconfig
Browse files Browse the repository at this point in the history
Allow overriding tsconfig options from within tsconfig.json
  • Loading branch information
Gerrit0 committed Apr 9, 2022
2 parents 934206d + c675715 commit 3cb756e
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 0 deletions.
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

0 comments on commit 3cb756e

Please sign in to comment.