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

trouble resolving file if resolved file is in folder with '.js' in name. #4

Closed
pjordaan opened this issue Feb 15, 2017 · 4 comments
Closed

Comments

@pjordaan
Copy link

Hi, when I enable tsconfig-paths, tsconfig-paths works very well, except when I try to resolve bignumber.js

In my tsconfig.json I have
"*": ["*", "src/*", "test/*", "vendor/node_modules/@types/*", "vendor/node_modules/*"],
Somewhere in the code it does require('bignumber.js');

If I trace the code then in match-path.js in function tryResolve() the string replacement is done incorrectly.

if (packageJson && packageJson.main && fileExists(path.join(physicalPath, packageJson.main))) {
        var file = path.join(physicalPath, packageJson.main);
        return file.replace(path.extname(file), "");
}

variable file is resolved to vendor/node_modules/bignumber.js/bignumber.js.

the file.replace removes the first '.js', so it incorrectly resolves into "vendor/node_modules/bignumber/bignumber.js", not "vendor/node_modules/bignumber.js/bignumber"

@pjordaan
Copy link
Author

possible solutions

return file.replace(new RegExp(path.extname(file).replace('.', '\\.') + '$'), "");
return path.dirname(file) + path.sep + path.basename(file, path.extname(file));

@jonaskello
Copy link
Member

I'll have a look when I get some time, or maybe @Jontem can look at it. However, if you have the time a PR with a failing test would be helpful :-).

@pjordaan pjordaan changed the title trouble resolving file if folder resolved file is in folder with '.js' in name. trouble resolving file if resolved file is in folder with '.js' in name. Feb 15, 2017
@Jontem
Copy link
Collaborator

Jontem commented Feb 15, 2017

I've fixed this in d6b7c53 and published a new version(2.1.1)

@Jontem Jontem closed this as completed Feb 15, 2017
@pjordaan
Copy link
Author

thx for the quick fix!

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

No branches or pull requests

3 participants