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

Normalize dependency graph paths - Fix broken dependencies on Windows #286

Merged
merged 1 commit into from
Oct 11, 2016

Conversation

pzavolinsky
Copy link

instance.dependencyGraph gets created using a raw containingFile value:

var servicesHost = {
    // ...
    resolveModuleNames: (moduleNames: string[], containingFile: string) => {
        // ...
        instance.dependencyGraph[containingFile] = ...
        // ...
    }
    // ...
}

But is later accessed with a normalized path:

function loader(contents) {
    // ...
    var filePath = path.normalize(this.resourcePath);
    // ...
    let additionalDependencies = instance.dependencyGraph[filePath];
    // ...
}

This breaks every scenario where path.normalize is not identity.

For example, in Windows, you get:

containingFile: 'C:/project/dir/file.ts'

path.normalize(containingFile): 'C:\\project\\dir\\file.ts'

@johnnyreilly
Copy link
Member

Hi @pzavolinsky,

could you refork and resubmit this PR please? I've just got CI cleaned so the tests pass but i can't requeue a build for your PR manually...

@pzavolinsky
Copy link
Author

Hi @johnnyreilly , I've just rebased my fork against ts-loader/master. You should be able to merge without conflicts now.

@johnnyreilly
Copy link
Member

Hi @pzavolinsky,

Thanks for submitting that - happily the tests are passing with your change in place. 😄 The change looks good.

Could you tell me how you discovered this issue? I'm guessing there was some kind of a problem that you encountered.

I ask as I'm wondering if it may be worth adding a test to ensure there are no future regressions.

@pzavolinsky
Copy link
Author

Could you tell me how you discovered this issue? I'm guessing there was some kind of a problem that you encountered.

Sure, here it goes:

We have lots of files called types.ts that define just reusable types. ts-loader was not picking up changes in those files. After a bit of debugging I found the path normalization issue and that dependencyGraph lookup always failing.

There must be something special going on for types.ts files, because other files work just fine, so you might want to look into that too.

Hope this helps!

@johnnyreilly
Copy link
Member

Thanks for the explanation @pzavolinsky. Very helpful. I'm not too sure if there's a good way to cover this with a test but I want to have a think first. Assuming I don't come with anything I'll plan to merge this.

Thanks again!

@pzavolinsky
Copy link
Author

Great, let me know if you need anything else!

@johnnyreilly johnnyreilly merged commit 922d9bb into TypeStrong:master Oct 11, 2016
@johnnyreilly
Copy link
Member

Awesome - thanks!

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.

2 participants