Skip to content

Commit cce8bf6

Browse files
committed
Merge remote-tracking branch 'origin/fix/1263'
2 parents 2f8d295 + 4decfbe commit cce8bf6

File tree

5 files changed

+44
-14
lines changed

5 files changed

+44
-14
lines changed

src/lib/utils/options/options.ts

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { isDeepStrictEqual } from 'util';
12
import * as _ from 'lodash';
23
import * as ts from 'typescript';
34

@@ -219,14 +220,14 @@ export class Options {
219220
}
220221

221222
/**
222-
* Checks if the given option has a set value or if the value is the default value.
223+
* Checks if the given option's value is deeply strict equal to the default.
223224
* @param name
224225
*/
225226
isDefault(name: keyof TypeDocOptions): boolean;
226227
isDefault(name: NeverIfInternal<string>): boolean;
227228
isDefault(name: string): boolean {
228229
// getValue will throw if the declaration does not exist.
229-
return this.getValue(name as keyof TypeDocOptions) === this.getDeclaration(name)!.defaultValue;
230+
return isDeepStrictEqual(this.getValue(name as keyof TypeDocOptions), this.getDefaultOptionValue(this.getDeclaration(name)!));
230231
}
231232

232233
/**
@@ -300,15 +301,17 @@ export class Options {
300301
*/
301302
private setOptionValueToDefault(declaration: Readonly<DeclarationOption>): void {
302303
if (declaration.scope !== ParameterScope.TypeScript) {
303-
// No need to convert the defaultValue for a map type as it has to be of a specific type
304-
if (declaration.type === ParameterType.Map) {
305-
this._values[declaration.name] = declaration.defaultValue;
306-
} else if (declaration.type === ParameterType.Number) {
307-
// Don't use convert for number options to allow every possible number as a default value
308-
this._values[declaration.name] = declaration.defaultValue || 0;
309-
} else {
310-
this._values[declaration.name] = convert(declaration.defaultValue, declaration);
311-
}
304+
this._values[declaration.name] = this.getDefaultOptionValue(declaration);
305+
}
306+
}
307+
308+
private getDefaultOptionValue(declaration: Readonly<DeclarationOption>): unknown {
309+
// No need to convert the defaultValue for a map type as it has to be of a specific type
310+
// Also don't use convert for number options to allow every possible number as a default value.
311+
if (declaration.type === ParameterType.Map || declaration.type === ParameterType.Number) {
312+
return declaration.defaultValue;
313+
} else {
314+
return convert(declaration.defaultValue, declaration);
312315
}
313316
}
314317
}

src/lib/utils/options/readers/tsconfig.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,19 @@ export class TSConfigReader implements OptionsReader {
5151
fileToRead = resolve(fileToRead);
5252

5353
const { config } = ts.readConfigFile(fileToRead, ts.sys.readFile);
54-
const { fileNames, options, raw: { typedocOptions = {} }} = ts.parseJsonConfigFileContent(
54+
const { fileNames, errors, options, raw: { typedocOptions = {} }} = ts.parseJsonConfigFileContent(
5555
config,
5656
ts.sys,
5757
dirname(fileToRead),
5858
{},
5959
fileToRead);
6060

61-
container.setValue('inputFiles', fileNames);
61+
logger?.diagnostics(errors);
62+
63+
if (container.isDefault('inputFiles')) {
64+
container.setValue('inputFiles', fileNames);
65+
}
66+
6267
for (const key of IGNORED) {
6368
delete options[key];
6469
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// This is referenced in valid.tsconfig.json
2+
export const test = true;

src/test/utils/options/readers/data/valid.tsconfig.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
{
2+
"$schema": "http://json.schemastore.org/tsconfig",
23
"compilerOptions": {
34
"target": "ESNext"
45
},
6+
"files": [
7+
// This has to specify a file that exists or TS will drop it.
8+
"./file.ts"
9+
],
510
"typedocOptions": {
611
"help": true
712
}

src/test/utils/options/readers/tsconfig.test.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { join } from 'path';
1+
import { join, resolve } from 'path';
22
import { deepStrictEqual as equal } from 'assert';
33

44
import { TSConfigReader } from '../../../../lib/utils/options/readers';
@@ -48,4 +48,19 @@ describe('Options - TSConfigReader', () => {
4848
equal(options.getValue('help'), true);
4949
equal(options.getCompilerOptions().target, ScriptTarget.ESNext);
5050
});
51+
52+
it('Sets inputFiles if they have not been set', () => {
53+
options.reset();
54+
options.setValue('tsconfig', join(__dirname, 'data/valid.tsconfig.json'));
55+
options.read(new Logger());
56+
equal(options.getValue('inputFiles').map(f => resolve(f)), [resolve(__dirname, './data/file.ts')]);
57+
});
58+
59+
it('Does not set inputFiles if they have been set', () => {
60+
options.reset();
61+
options.setValue('tsconfig', join(__dirname, 'data/valid.tsconfig.json'));
62+
options.setValue('inputFiles', ['foo.ts']);
63+
options.read(new Logger());
64+
equal(options.getValue('inputFiles'), ['foo.ts']);
65+
});
5166
});

0 commit comments

Comments
 (0)