fix(vite-plugin-angular): don't shadow Vite ?raw imports of .ts files#2359
Conversation
The Angular transform filter matched query-stringed ids like `foo.ts?raw` via TS_EXT_REGEX and recompiled them as TypeScript, discarding the `export default "<source>"` that Vite's native raw loader produced. This broke `import src from './file.ts?raw'` with "default is not exported". Exclude `?raw` ids from the transform filter in both the AOT and fast -compile plugins so Vite's built-in raw handling stands. Covers all .ts/.cts/.mts files, Angular or not. Closes #2356 https://claude.ai/code/session_01D4SdPZwfD2LtzqmZLQwdmw
✅ Deploy Preview for analog-docs ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. 🗂️ Base branches to auto review (2)
Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
PR Checklist
The Angular
transformfilter matched query-stringed ids likefoo.ts?rawviaTS_EXT_REGEX(
/\.[cm]?ts(?[a-z])/, which is not anchored and ignores the query string). The id entered thehandler, the query was stripped, and Angular/esbuild recompiled the file as TypeScript — discarding
the
export default "<source>"that Vite's native raw loader had already produced. As a resultimport src from './file.ts?raw'failed with"default" is not exported by "….ts?raw". This brokethe documented Vite
?rawimport for every.ts/.cts/.mtsfile (Angular component or plainTypeScript alike), e.g. feeding a story component's source into a Storybook "Show code" panel.
Closes #2356
Affected scope
vite-plugin-angularRecommended merge strategy for maintainer [optional]
What is the new behavior?
?raw-queried ids are now added to thetransform.filter.id.excludearray in both the AOT(
angular-vite-plugin.ts) and fast-compile (fast-compile-plugin.ts) plugins, so the Angulartransform never runs for them and Vite's built-in raw handling stands:
/[?&]raw\b/matchesfoo.ts?rawandfoo.ts?import&raw, but not plainfoo.tsnor legitimatequery ids the handler must still compile (HMR
foo.ts?t=123,foo.ts?component). The fix iscontent-agnostic, so it covers both Angular and non-Angular
.tsfiles.Test plan
nx format:checkpnpm test(vite-plugin-angular — new exclusion specs inangular-vite-plugin.spec.tsandfast-compile-plugin.spec.tsassert?rawids are excluded while plain/HMR ids still compile)Does this PR introduce a breaking change?
Other information
The plugin already routed
.html?rawthrough a virtual id, but that mechanism exists solely tosatisfy Vite's
server.fsDenied-ID security check —.htmlnever reaches the Angular transform.The
.ts?rawproblem is purely the transform filter shadowing Vite's raw output, so the narrowfilter-exclusion fix is the right tool and leaves the
.html?rawpath untouched.Generated by Claude Code