-
Notifications
You must be signed in to change notification settings - Fork 718
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(readers/tsconfig.ts): support "extends" #436
feat(readers/tsconfig.ts): support "extends" #436
Conversation
@@ -26,6 +26,30 @@ export class TSConfigReader extends OptionsComponent | |||
private static OPTIONS_KEY:string = 'tsconfig'; | |||
|
|||
|
|||
private readConfigFile(event:DiscoverEvent, fileName:string) { | |||
if (!FS.existsSync(fileName)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@blakeembrey Not sure if this check is needed here, what do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably not if it's already handled. However, is it possible to skip most of this code and have ts
read the entire file with extends
instead? I thought there was a method for it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As I get it we need the raw compiler options/content. parseJsonConfigFileContent()
does follow the extends
chain and aggregate the data but not in the raw form. If we use the options: CompilerOptions
property from the result of parseJsonConfigFileContent()
we will have to remove all internal options and map the enum represented ones(ModuleKind
, ScriptTarget
, NewLineKind
, ...) to the correct string values. Don't like the maintenance perspective or using APIs marked as internal.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you know where we use the raw compiler options? My primary concern is that we may implement extends "wrong" if the compiler options ever change. If I've learnt anything from using the TypeScript compiler, it's that things can change at any time so implementing your own is usually bad.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not very familiar with the project so here is how I've understood it so far:
- Here a typedoc intended only options may be present in the tsconfig.json, those options get merged with the raw
compilerOptions
from the tsconfig.json. - The conversion of the raw options to
CompilerOptions
and separation - TS/TypeDoc , is done here by OptionDeclaration.
Why the conversion is done by typedoc and not TS I do not understand, I'm probably missing something or it is legacy. That's why I went with aggregating the raw options and not using the parsed ones returned from the parseJsonConfigFileContent()
method used here - it returns ParsedCommandLine which has the parsed options - options:CompilerOptions
.
If you have any suggestions please do tell.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel like it would be legacy and we should be able to tidy it up instead of trying to build our own extends. However, if there's too much to correct, let me know.
# Conflicts: # src/lib/utils/options/options.ts # src/lib/utils/options/readers/tsconfig.ts
data, | ||
ts.sys, | ||
Path.resolve(Path.dirname(fileName)), | ||
{}, | ||
Path.resolve(fileName)); | ||
|
||
event.inputFiles = data.fileNames; | ||
event.inputFiles = fileNames; | ||
options = _.clone(options); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we care about cloning the options here? The config parse function should be generating a plain object that wouldn't be used anywhere else anyway.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you also point out where extends
is now handled? I'm not sure I'm reading this snippet correctly, but it seems to move things around but I can't tell what/where something new was introduced.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
extends
is handled by ts.parseJsonConfigFileContent()
. The rest of the changes here are for preserving the precedence of the options(cli, ..., tsconfig.compilerOptions) and clearing the unsupported options.
@@ -72,6 +74,10 @@ export class Options extends ChildableComponent<Application, OptionsComponent> { | |||
this.trigger(event); | |||
this.setValues(event.data, '', event.addError.bind(event)); | |||
|
|||
if (event.compilerOptions) { | |||
_.assign(this.compilerOptions, event.compilerOptions); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we use event.data
for everything instead of having two ways to pass this data?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It can be used, but currently event.data
is more like event.rawOptions
so whatever additional data is added it should not be in conflict with any of the options and should be deleted before parsing them.
If the following is OK I'll make the changes:
- in
readers/tsconfig.ts
- addparsedCompilerOptions: CompilerOptions
to theevent.data
- in
options/options.ts
- deleteparsedCompilerOptions
fromevent.data
before parsing
@blakeembrey ping |
close #380