Skip to content
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

Handle "extends" #27

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open

Handle "extends" #27

wants to merge 3 commits into from

Conversation

Zerogiven
Copy link

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.

@coveralls
Copy link

Coverage Status

Coverage decreased (-2.9%) to 96.316% when pulling 28fa0da on Zerogiven:patch-1 into 5281eaf on TypeStrong:master.

1 similar comment
@coveralls
Copy link

Coverage Status

Coverage decreased (-2.9%) to 96.316% when pulling 28fa0da on Zerogiven:patch-1 into 5281eaf on TypeStrong:master.

…xtending. This is needed cause code coverage is collected from the compiled JS files and not from the TS ones.
@Zerogiven Zerogiven changed the title Patch 1 Handle "extends" Jan 6, 2018

if (obj.extends !== undefined) {
const filepath = filename.replace(path.basename(filename), '')
const extendsFilename = resolveSync(filepath, obj.extends) as string
Copy link
Member

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.

@@ -163,11 +163,23 @@ export function readFile (filename: string): Promise<any> {
return reject(err)
}

let obj
Copy link
Member

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.

try {
return resolve(parse(contents, filename))
Copy link
Member

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)) {
Copy link
Member

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) {
Copy link
Member

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]))
Copy link
Member

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants