-
Notifications
You must be signed in to change notification settings - Fork 33
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
Fix unplugin path resolution (#774) #786
Fix unplugin path resolution (#774) #786
Conversation
I tested this on Windows and Linux, and found However, |
integration/unplugin/src/index.ts
Outdated
@@ -178,7 +178,7 @@ const civetUnplugin = createUnplugin((options: PluginOptions = {}) => { | |||
|
|||
const relativeId = path.relative( | |||
process.cwd(), | |||
path.resolve(path.dirname(importer ?? ''), id) | |||
path.join(path.dirname(importer ?? ''), id) |
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.
Actually, I wonder whether this is correct... I would have guessed:
- If the path is relative, use
path.join
withimporter
, as you have it here - If the path is absolute, use
path.join
with the project'sroot
setting (which probably also needs to bejoin
ed withprocess.cwd()
because it too can be relative).
This is somewhat confirmed because I find src/main.civet
can successfully import /module.civet
, but I don't think it should be able to; it should have to import /src/module.civet
I believe.
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.
Oops yeah you're correct, I overlooked that case.
I am very sure that |
integration/unplugin/src/index.ts
Outdated
|
||
const absolutePath = path.isAbsolute(id) | ||
? path.join(path.join(process.cwd(), viteConfig.root ?? ''), id) | ||
: path.join(path.dirname(importer ?? ''), id); |
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'm pretty sure the latter case should use path.resolve
, not path.join
.
I pushed a new commit that cleans up this code. Could you check it?
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.
The result should be the same with path.resolve
and path.join
as we're already handling the case where id
is an absolute path which is the only case where resolve and join differ
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.
Rest of the changes look good 👍
This PR should fix #774 and also make #785 not required.
path.resolve
would not consider the parent path if the child path starts with/
, which made paths like/src/main.civet
be considered as system-absolute path instead of project-absolute.path.join
should take them into account always, and make this work.The only issue this would face is not supporting system-absolute paths for civet, though I'm not sure if that is a feature that is actually used that much