diff --git a/src/lib/utils/options/options.ts b/src/lib/utils/options/options.ts index ef7fbd3e7..3f3cd1f12 100644 --- a/src/lib/utils/options/options.ts +++ b/src/lib/utils/options/options.ts @@ -1,3 +1,4 @@ +import { isDeepStrictEqual } from 'util'; import * as _ from 'lodash'; import * as ts from 'typescript'; @@ -214,14 +215,14 @@ export class Options { } /** - * Checks if the given option has a set value or if the value is the default value. + * Checks if the given option's value is deeply strict equal to the default. * @param name */ isDefault(name: keyof TypeDocAndTSOptions): boolean; isDefault(name: string): boolean; isDefault(name: string): boolean { // getValue will throw if the declaration does not exist. - return this.getValue(name) === this.getDeclaration(name)!.defaultValue; + return isDeepStrictEqual(this.getValue(name), this.getDefaultOptionValue(this.getDeclaration(name)!)); } /** @@ -317,17 +318,21 @@ export class Options { /** * Sets the value of a given option to its default value. - * @param declaration The option whoes value should be reset. + * @param declaration The option whose value should be reset. */ private setOptionValueToDefault(declaration: Readonly): void { if (declaration.scope !== ParameterScope.TypeScript) { - // No nead to convert the defaultValue for a map type as it has to be of a specific type - if (declaration.type === ParameterType.Map) { - this._values[declaration.name] = declaration.defaultValue; - } else { - this._values[declaration.name] = convert(declaration.defaultValue, declaration) - .expect(`Failed to validate default value for ${declaration.name}`); - } + this._values[declaration.name] = this.getDefaultOptionValue(declaration); + } + } + + private getDefaultOptionValue(declaration: Readonly): unknown { + // No need to convert the defaultValue for a map type as it has to be of a specific type + if (declaration.type === ParameterType.Map) { + return declaration.defaultValue; + } else { + return convert(declaration.defaultValue, declaration) + .expect(`Failed to validate default value for ${declaration.name}`); } } } diff --git a/src/lib/utils/options/readers/tsconfig.ts b/src/lib/utils/options/readers/tsconfig.ts index 07c28d01b..3cb7b7a98 100644 --- a/src/lib/utils/options/readers/tsconfig.ts +++ b/src/lib/utils/options/readers/tsconfig.ts @@ -51,14 +51,19 @@ export class TSConfigReader implements OptionsReader { fileToRead = resolve(fileToRead); const { config } = ts.readConfigFile(fileToRead, ts.sys.readFile); - const { fileNames, options, raw: { typedocOptions = {} }} = ts.parseJsonConfigFileContent( + const { fileNames, errors, options, raw: { typedocOptions = {} }} = ts.parseJsonConfigFileContent( config, ts.sys, dirname(fileToRead), {}, fileToRead); - container.setValue('inputFiles', fileNames).unwrap(); + logger?.diagnostics(errors); + + if (container.isDefault('inputFiles')) { + container.setValue('inputFiles', fileNames).unwrap(); + } + for (const key of IGNORED) { delete options[key]; } diff --git a/src/test/utils/options/readers/data/file.ts b/src/test/utils/options/readers/data/file.ts new file mode 100644 index 000000000..a5e460907 --- /dev/null +++ b/src/test/utils/options/readers/data/file.ts @@ -0,0 +1,2 @@ +// This is referenced in valid.tsconfig.json +export const test = true; diff --git a/src/test/utils/options/readers/data/valid.tsconfig.json b/src/test/utils/options/readers/data/valid.tsconfig.json index fc47f601e..854836627 100644 --- a/src/test/utils/options/readers/data/valid.tsconfig.json +++ b/src/test/utils/options/readers/data/valid.tsconfig.json @@ -1,7 +1,12 @@ { + "$schema": "http://json.schemastore.org/tsconfig", "compilerOptions": { "target": "ESNext" }, + "files": [ + // This has to specify a file that exists or TS will drop it. + "./file.ts" + ], "typedocOptions": { "help": true } diff --git a/src/test/utils/options/readers/tsconfig.test.ts b/src/test/utils/options/readers/tsconfig.test.ts index 8ed918ece..bd7f4a822 100644 --- a/src/test/utils/options/readers/tsconfig.test.ts +++ b/src/test/utils/options/readers/tsconfig.test.ts @@ -1,4 +1,4 @@ -import { join } from 'path'; +import { join, resolve } from 'path'; import { deepStrictEqual as equal } from 'assert'; import { TSConfigReader } from '../../../../lib/utils/options/readers'; @@ -48,4 +48,19 @@ describe('Options - TSConfigReader', () => { equal(options.getValue('help'), true); equal(options.getCompilerOptions().target, ScriptTarget.ESNext); }); + + it('Sets inputFiles if they have not been set', () => { + options.reset(); + options.setValue('tsconfig', join(__dirname, 'data/valid.tsconfig.json')).unwrap(); + options.read(new Logger()); + equal(options.getValue('inputFiles').map(f => resolve(f)), [resolve(__dirname, './data/file.ts')]); + }); + + it('Does not set inputFiles if they have been set', () => { + options.reset(); + options.setValue('tsconfig', join(__dirname, 'data/valid.tsconfig.json')).unwrap(); + options.setValue('inputFiles', ['foo.ts']).unwrap(); + options.read(new Logger()); + equal(options.getValue('inputFiles'), ['foo.ts']); + }); });