-
Notifications
You must be signed in to change notification settings - Fork 21
Handle "extends" #27
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
base: master
Are you sure you want to change the base?
Handle "extends" #27
Conversation
1 similar comment
…xtending. This is needed cause code coverage is collected from the compiled JS files and not from the TS ones.
|
|
||
| if (obj.extends !== undefined) { | ||
| const filepath = filename.replace(path.basename(filename), '') | ||
| const extendsFilename = resolveSync(filepath, obj.extends) as string |
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.
You can't do a synchronous operation in an async context, it defeats the purpose of supporting an async API.
| return reject(err) | ||
| } | ||
|
|
||
| let obj |
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.
No need for let here, mergeObjects is mutating target anyway.
|
|
||
| let obj | ||
| try { | ||
| return resolve(parse(contents, 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.
You'd need to keep the signature backward compatible here, otherwise it's a breaking change. I'd just make it optional, it used to be used for debugging and would still be useful to figure out which file has the syntax error.
| * Simple object merging | ||
| */ | ||
| function mergeObjects (target: any, source: any): any { | ||
| for (let key of Object.keys(source)) { |
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.
const key
| */ | ||
| function mergeObjects (target: any, source: any): any { | ||
| for (let key of Object.keys(source)) { | ||
| if (source[key] instanceof Object) { |
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'd make a little isObject helper over using instanceof personally.
| function mergeObjects (target: any, source: any): any { | ||
| for (let key of Object.keys(source)) { | ||
| if (source[key] instanceof Object) { | ||
| Object.assign(source[key], mergeObjects(target[key], source[key])) |
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.
This is kind of confusing, you're assigning backward onto the source and then copying back onto the target in a roundabout way - you could just use an else statement and make both assign to target and delete the final Object.assign to avoid additional work.
With this pull request we can handle "extends" at tsconfig. Multiple extends are possible too. The only thing to note is that a small part of readFile is not async cause we have to await some results.
I also removed the filename parameter from the parse method cause it was never used.
At least i've added a test with some mockups for extending tsconfig.