-
Notifications
You must be signed in to change notification settings - Fork 68
fix(ct): correctly works with vite-style imports #1169
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
base: master
Are you sure you want to change the base?
Conversation
commit: |
| "ts-node": ">=10.5.0" | ||
| }, | ||
| "peerDependenciesMeta": { | ||
| "@babel/parser": { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I use @babel/parser because I can't implement a plugin for esbuild when use transformSync in order to remove vite-style imports. For swc I can implement it in Rust, but it won't be a complete solution.
In next major we should move to use only swc parser.
| registerTransformHook(this.isWorker()); | ||
|
|
||
| this._config = Config.create(config); | ||
| updateTransformHook(this._config); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I need config in order to check if tests run in node env or in browser env
| const isJsxOrTsx = extname === ".jsx" || extname === ".tsx"; | ||
|
|
||
| if (!isJsxOrTsx) { | ||
| return code; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do nothing if file is not jsx or tsx
| if (typeof source === "string") { | ||
| const extname = path.extname(source); | ||
|
|
||
| if (extname && extname.includes("?")) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove only imports which has query symbol in extension name, like - file.svg?react
| ); | ||
| return code; | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately, this file is not covered by tests, as it requires integration tests, but we do not have a ready infrastructure for them.
What is done:
Implement ability to remove vite-style imports with query parameters when parse .jsx and .tsx files in node. More info about these imports here - https://vite.dev/guide/assets#explicit-url-imports.
Problem reproduced when using vite-plugin-svgr - https://github.com/pd4d10/vite-plugin-svgr