test: resolve using absolute dep path#5495
Conversation
3141615 to
2a56595
Compare
|
It would also be great if we can add a test for this. I think the |
But the path will be used in runtime code, such as import xxx from 'absolute-path'. |
Ahh you're right. Hmm this one's hard to test, I'm fine if we leave it out for now as long as we add a comment in the code to explain the motivation (as you've proposed). |
We can execute a script in npm script, such as Then replace the outlet path with real absolute path. |
I think it's a bit brittle to do this (and may affect CI?). If someone run tests locally too, git would show a change for that file which could be confusing and lead to accidental updates. |
|
Couldnt you use a plugin to rewrite a placeholder for the import path, or even use define directly? |
Thanks,i will use resolve.alias replace the path. |
|
You need to run |
c7172b5 to
99c0a3e
Compare
@bluwy @patak-js @Shinigami92 @daaku Hello, I'm not clear why does CI test always fail in windows environment.Can you help? |
|
I think it is better if you use define instead here And in config use https://vitejs.dev/config/#define If you are going to use an alias (that I think should also work), better to also use a constant name like the one above. Maybe Windows is having issues with the But for Windows you are probably missing a |
99c0a3e to
df76e7b
Compare
55867c0 to
bcb1c41
Compare
| // extract the package absolute path | ||
| const packageFPath = require.resolve('test-package-f').replace(/(\/|\\)index.js/, '') |
There was a problem hiding this comment.
We may need to apply normalizePath here as well so that the server._optimizeDepsMetadata?.optimized[normalizePath(id)] expression below matches.
This brings up the edgecase as well, that we need to normalize the file path for optimizeDeps.include. I'm not sure if it's something we want, because otherwise we would need to omit the normalizePath usage in server._optimizeDepsMetadata?.optimized[normalizePath(id)], but that seems to cause CI errors too? I can't find the logs for when we had the code for that.
There was a problem hiding this comment.
This is tricky, I'm not seeing consistent normalization in config options. Should assetsInclude be normalized? If you want it to work in both posix and windows, then all harcoded options should be normalized to posix, but if you are getting one with resolve, it may work without normalization. I'll ask in the next team meeting what is expected here. One option would normalize both when testing.
There was a problem hiding this comment.
In windows, normalized path will be like D_home_vite_test and if such a path is placed in the include, esbuild will not be able to resolve it.
There was a problem hiding this comment.
No, normalized paths using normalizePath only swap the windows \ by POSIX /
There was a problem hiding this comment.
@patak-js I have added leading slash in the windows environment and now CI has succeeded。
570969f to
da22e20
Compare
6c4b117 to
37ae5b2
Compare
37ae5b2 to
53a4569
Compare
patak-cat
left a comment
There was a problem hiding this comment.
Merged main removing the code change and only leaving the test cases, and these seem to work already without any modifications. I think we can merge this as a test PR
Closes #5494
Description
Return the result of the pre-bundle product before resolvePlugin when import absolute dep path instead of bare import. See details in issue
What is the purpose of this pull request?
Before submitting the PR, please make sure you do the following
fixes #123).