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

Plugin doesn't follow the same module-loader search paths #30

Closed
richardspence opened this issue Aug 6, 2019 · 4 comments
Closed

Plugin doesn't follow the same module-loader search paths #30

richardspence opened this issue Aug 6, 2019 · 4 comments
Labels
Bug Something isn't working

Comments

@richardspence
Copy link

richardspence commented Aug 6, 2019

Summary

The plugin treats the paths in the tsconfig as gospel for adjusting the resolution path. It should instead use it as the primary search folder for determining where the module is located before falling back to the default module resolution strategies.

Repro steps

tsconfig:

    "baseUrl": ".",
    "paths": {
            "*": ["*"]
        },

foo/IFoo

export interface IFoo {}

foo/File2

import {IFoo} from './IFoo';

Expected

The plugin to not transform the relative imports (since they aren't available of the root). Paths should be performed first and only applied if the module can be loaded from that location. Then it should fallback to the module resolution strategy defined for the project https://www.typescriptlang.org/docs/handbook/module-resolution.html#module-resolution-strategies

Actual

foo/File2.d.ts

import {IFoo} from '../IFoo';
@richardspence
Copy link
Author

richardspence commented Aug 6, 2019

The fix should be to adjust bindModuleToFile to only return if the targetFile[.ts|.js|.d.ts|.json|.jsx|.tsx] exists on the location. JS, JSON and JSX or TSX only if the applicable compiler options are turned on.

@danielpza danielpza added the Bug Something isn't working label Aug 6, 2019
@danielpza
Copy link
Member

This could be tricky, as those are not the only extensions a module could have, eg it could be .css:
https://webpack.js.org/guides/typescript/#importing-other-assets

@richardspence
Copy link
Author

Yup and you could have something like this as well:

declare module 'css!*' {
   var e: string;
   export default e;
}

...
import myCss from 'css!foo/myCss';

One option is to ignore the additional loaders like css!

For the other extensions you could make it configurable to add/replace/remove

@danielpza
Copy link
Member

danielpza commented Aug 20, 2019

Hi @richardspence, I reread the tsconfig docs and yes, the only extensions allowed are .ts, .d.ts, .jsx, etc...

I released a fix, please upgrade to v1.1.10.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants