diff --git a/src/lib/utils/options/options.ts b/src/lib/utils/options/options.ts index 381855018..dbd96819c 100644 --- a/src/lib/utils/options/options.ts +++ b/src/lib/utils/options/options.ts @@ -24,6 +24,8 @@ export class DiscoverEvent extends Event { mode: OptionsReadMode; + compilerOptions?: CompileOptions; + inputFiles: string[] = []; errors: string[] = []; @@ -72,6 +74,10 @@ export class Options extends ChildableComponent { this.trigger(event); this.setValues(event.data, '', event.addError.bind(event)); + if (event.compilerOptions) { + _.assign(this.compilerOptions, event.compilerOptions); + } + if (mode === OptionsReadMode.Fetch) { const logger = this.application.logger; for (let error of event.errors) { diff --git a/src/lib/utils/options/readers/tsconfig.ts b/src/lib/utils/options/readers/tsconfig.ts index 35f3d3428..03afe514c 100644 --- a/src/lib/utils/options/readers/tsconfig.ts +++ b/src/lib/utils/options/readers/tsconfig.ts @@ -51,31 +51,45 @@ export class TSConfigReader extends OptionsComponent { return; } - let data = ts.readConfigFile(fileName, ts.sys.readFile).config; + const data = ts.readConfigFile(fileName, ts.sys.readFile).config; + if (data === undefined) { event.addError('The tsconfig file %s does not contain valid JSON.', fileName); return; } + if (!_.isPlainObject(data)) { event.addError('The tsconfig file %s does not contain a JSON object.', fileName); return; } - data = ts.parseJsonConfigFileContent( + let {options, fileNames} = ts.parseJsonConfigFileContent( data, ts.sys, Path.resolve(Path.dirname(fileName)), {}, Path.resolve(fileName)); - event.inputFiles = data.fileNames; + event.inputFiles = fileNames; + options = _.clone(options); + + if (!data.typedocOptions) { + data.typedocOptions = Object.create(null); + } + + for (const key of TypeScriptSource.IGNORED) { + delete options[key]; + delete data.typedocOptions[key]; + } + + _.defaults(event.data, data.typedocOptions); - const ignored = TypeScriptSource.IGNORED; - let compilerOptions = _.clone(data.raw.compilerOptions); - for (const key of ignored) { - delete compilerOptions[key]; + for (const key in options) { + if (!_.isUndefined(event.data[key])) { + delete options[key]; + } } - _.defaults(event.data, data.raw.typedocOptions, compilerOptions); + event.compilerOptions = options; } }