fix: resolve src imports using resolved SFC-relative paths#202
Open
pont1s wants to merge 1 commit into
Open
Conversation
SFC block `src` attributes were resolved via `pluginContext.resolve`, but the resolved path was not used in generated imports. This could leave raw relative paths in emitted code and trigger ENOENT in raw Rollup/Rolldown when `cwd` did not match the SFC directory. Use a single helper, `resolveAndLinkSrcToDescriptor`, to both: - resolve and normalize the `src` path (strip query), - link the resolved file to the owner SFC descriptor. Then use the returned resolved path in all block generators (template/script/style/custom blocks), so emitted imports are stable and correct across environments. Tests were updated to exercise SFC-relative `src` fixture paths, and Rollup parity with `@vitejs/plugin-vue` is skipped for `sfc-src` because upstream still relies on Vite pre-resolution in this case. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
|
|
There was a problem hiding this comment.
Pull request overview
This PR fixes incorrect handling of <template/src>, <script/src>, <style/src>, and custom block src attributes in Vue SFCs when running under raw Rollup/Rolldown, where leaving un-resolved relative paths in generated imports could lead to ENOENT when cwd differs from the SFC’s directory.
Changes:
- Introduces
resolveAndLinkSrcToDescriptorto resolve/cleansrcfile paths and link them to the owning SFC descriptor in one step. - Updates generated import requests for SFC blocks to use the resolved (SFC-relative) file path instead of the raw
srcstring. - Adjusts Rollup parity testing to skip
sfc-src*fixtures vs@vitejs/plugin-vue, and updates thesfc-src.vuefixture to use SFC-relativesrcpaths.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
src/core/main.ts |
Uses resolved src paths when generating imports for template/script/style/custom blocks and links resolved files to descriptor cache. |
tests/rollup.test.ts |
Skips parity comparisons for sfc-src* fixtures where upstream still differs under raw Rollup. |
tests/fixtures/sfc-src.vue |
Updates src attributes to be SFC-relative (./…) to validate correct resolution behavior. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
433
to
+451
| async function genStyleCode( | ||
| descriptor: SFCDescriptor, | ||
| pluginContext: Context, | ||
| customElement: boolean, | ||
| attachedProps: [string, string][], | ||
| ) { | ||
| let stylesCode = `` | ||
| let cssModulesMap: Record<string, string> | undefined | ||
| if (descriptor.styles.length > 0) { | ||
| for (let i = 0; i < descriptor.styles.length; i++) { | ||
| const style = descriptor.styles[i] | ||
| if (style.src) { | ||
| await linkSrcToDescriptor( | ||
| style.src, | ||
| descriptor, | ||
| pluginContext, | ||
| style.scoped, | ||
| ) | ||
| } | ||
| const src = style.src || descriptor.filename | ||
| const src = style.src | ||
| ? await resolveAndLinkSrcToDescriptor( | ||
| style.src, | ||
| descriptor, | ||
| pluginContext, | ||
| style.scoped, | ||
| ) | ||
| : descriptor.filename |
Comment on lines
519
to
+533
| async function genCustomBlockCode( | ||
| descriptor: SFCDescriptor, | ||
| pluginContext: Context, | ||
| ) { | ||
| let code = '' | ||
| for (let index = 0; index < descriptor.customBlocks.length; index++) { | ||
| const block = descriptor.customBlocks[index] | ||
| if (block.src) { | ||
| await linkSrcToDescriptor(block.src, descriptor, pluginContext, false) | ||
| } | ||
| const src = block.src || descriptor.filename | ||
| const src = block.src | ||
| ? await resolveAndLinkSrcToDescriptor( | ||
| block.src, | ||
| descriptor, | ||
| pluginContext, | ||
| false, | ||
| ) | ||
| : descriptor.filename |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Fixed resolving relative path inside , <script src="./foo.ts">, <style src="./foo.css">, and custom blocks in the SFC files.
SFC block
srcattributes were resolved viapluginContext.resolve, but the resolved path was not used in generated imports. This could leave raw relative paths in emitted code and trigger ENOENT in raw Rollup/Rolldown whencwddid not match the SFC directory.Use a single helper,
resolveAndLinkSrcToDescriptor, to both:srcpath,Linked Issues
#201
Additional context
Rollup parity tests were adjusted to skip sfc-src* comparison with @vitejs/plugin-vue, since upstream still has this latent issue under raw Rollup bundler