Skip to content

Commit

Permalink
fix: Errors due to bad options in tsconfig file were dropped
Browse files Browse the repository at this point in the history
Closes #1444
  • Loading branch information
Gerrit0 committed Jan 3, 2021
1 parent 09bf048 commit f76b521
Showing 1 changed file with 12 additions and 22 deletions.
34 changes: 12 additions & 22 deletions src/lib/utils/options/readers/tsconfig.ts
Expand Up @@ -20,22 +20,8 @@ export class TSConfigReader implements OptionsReader {
name = "tsconfig-json";

read(container: Options, logger: Logger): void {
const tsconfigOpt = container.getValue("tsconfig");
const file = container.getValue("tsconfig");

if (!container.isDefault("tsconfig")) {
this._tryReadOptions(tsconfigOpt, container, logger);
return;
}

// Don't log errors if we try to read by default.
this._tryReadOptions(tsconfigOpt, container);
}

private _tryReadOptions(
file: string,
container: Options & { setValue(name: string, value: unknown): void },
logger?: Logger
): void {
let fileToRead: string | undefined = file;
if (!isFile(fileToRead)) {
fileToRead = ts.findConfigFile(
Expand All @@ -48,7 +34,10 @@ export class TSConfigReader implements OptionsReader {
}

if (!fileToRead || !isFile(fileToRead)) {
logger?.error(`The tsconfig file ${file} does not exist`);
// If the user didn't give us this option, we shouldn't complain about not being able to find it.
if (!container.isDefault("tsconfig")) {
logger.error(`The tsconfig file ${file} does not exist`);
}
return;
}

Expand All @@ -61,7 +50,7 @@ export class TSConfigReader implements OptionsReader {
{
...ts.sys,
onUnRecoverableConfigFileDiagnostic(error) {
logger?.diagnostic(error);
logger.diagnostic(error);
fatalError = true;
},
}
Expand All @@ -71,11 +60,11 @@ export class TSConfigReader implements OptionsReader {
return;
}

logger?.diagnostics(parsed.errors);
logger.diagnostics(parsed.errors);

const typedocOptions = parsed.raw?.typedocOptions ?? {};
if (typedocOptions.options) {
logger?.error(
logger.error(
[
"typedocOptions in tsconfig file specifies an option file to read but the option",
"file has already been read. This is likely a misconfiguration.",
Expand All @@ -84,7 +73,7 @@ export class TSConfigReader implements OptionsReader {
delete typedocOptions.options;
}
if (typedocOptions.tsconfig) {
logger?.error(
logger.error(
"typedocOptions in tsconfig file may not specify a tsconfig file to read"
);
delete typedocOptions.tsconfig;
Expand All @@ -97,9 +86,10 @@ export class TSConfigReader implements OptionsReader {
);
for (const [key, val] of Object.entries(typedocOptions || {})) {
try {
container.setValue(key, val);
// We catch the error, so can ignore the strict type checks
container.setValue(key as never, val as never);
} catch (error) {
logger?.error(error.message);
logger.error(error.message);
}
}
}
Expand Down

0 comments on commit f76b521

Please sign in to comment.