Closed Banou26 closed 4 years ago
There are warnings thrown even though the tests pass, can someone check if it's important or not ?
@tleunen so, i find myself in a bit of a problem, there's a test called
module-resolver › alias › with alias for a relative path (with respect to the cwd) › should alias the file path sharing a directory
which completly prevent the use of alias as extension rewriter since then all of the paths are rewritten relative to the cwd.
Any ideas to be able to have both behaviors ? Is it okay to introduce a flag to prevent that path rewriting ?
I don't see any failing tests?
So basically, this PR mostly introduces the resolution on all paths, not just "absolute" paths. I remember we talked about this in a few other issues but I can't find them. Some people already wanted this (for us to remove the isRelativePath
condition), but we never did that in fear of having bad performance since the plugin would now run everywhere and try to match aliases/root when they would not be needed most of the time.
What do you think @fatfisz? Should we go and remove the condition? Or add a flag to run on all paths? (I'm not a huge fan of keeping adding flags for features too :/)
No tests are failing because i didn't make the breaking change/added a flag for the relative path bypass yet.
Right now the package doesn't allow to just rewrite .ts
to .js
, because the package will rewrite every alias paths relative to the cwd, for example,
project/
├── src/
│ ├── foo.ts
│ └── index.ts
└── package.json
./index.ts
is transformed as such
- import './foo.ts'
+ import '../foo.js'
and to have the correct behavior i need, which is to only rewrite the extension, we'd have to introduce a flag to bypass the mapToRelative
call, which would result in
- import './foo.ts'
+ import './foo.js'
Also, if you don't think your plugin should tackle this kind of behavior or don't want to add new flags i'm fine with it, i'll just fork it for my only need.
ended up using https://github.com/karlprieb/babel-plugin-add-import-extension to replace .ts
import extension names by .js
Moves the relative path conditional under the resolvers and skip it if there is a resolver result
Add corresponding test
https://github.com/tleunen/babel-plugin-module-resolver/issues/381