-
Notifications
You must be signed in to change notification settings - Fork 41
Support for .civet files outputting .svelte.ts/.svelte.js for Svelte Runes reactive compatibility #1733
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: main
Are you sure you want to change the base?
Conversation
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.
Thanks for this PR, and sorry for the delay. Do you think it would be possible to use outputExtension
instead of hard-coding Svelte support? That would be better, I think, but it may require a bit more restructuring.
You mean something like this? outExt :=
options.outputExtension ?? (ts is "preserve" ? ".tsx" : ".jsx")
cleanOutExt := outExt.replace(/\./g, '\\.')
cleanOutputExtRE := new RegExp(`${cleanOutExt}$`)
isCivetTranspiled := new RegExp(`(\\.civet)(?:${cleanOutExt})?([?#].*)?$`)
function cleanCivetId(id: string): {id: string, postfix: string}
let postfix = ''
id = id
.replace postfixRE, (match) =>
postfix = match
''
.replace cleanOutputExtRE, ''
{id, postfix} Also while experimenting I noticed it's adding it to the end, so it's file.civet.ts / file.civet.svelte.ts without stripping stripCivet := options.stripCivetExtension ?? false and some extra logic to make it possible > file.ts / file.svelte.ts / file.tsx or there is no point for doing that? |
If we stick to regular expressions, you'll need to escape all active regexp characters, not just cleanOutExt := outExt.replace(/[.*+?^${}()|[\]\\]/g, '\\$&') But I wonder if we could instead just remove do the
I don't think this can work in the unplugin, because we wouldn't be able to detect transformed files, because they no longer have |
1 - no more dynamic regex for validation 2 - splitIdPostfix - only removes ? or # part 3 - validateAndExtractCivetBase - - removes postfix - checks if id ends with outputextension - checks if id before ends with .civet true > returns base .civet path, otherwise null 4 - resolveId now uses splitIdPostfix to only remove postfix = path without striping outext, then it appends everything 5 - loadinclude = direct, clear validation (is not null) 6 - load - uses validateAndExtractCivetBase to both validate and extract civet file
Hey, sorry for the delay, could you review my code in latest commit is it overcoooked or a nice one Basically
4 - resolveId now uses splitIdPostfix to only remove postfix = path without striping outext, then it appends everything |
Summary
.civet
files to support output extensions like.svelte.ts
or.svelte.js
.isCivetTranspiled
regex to match.civet.svelte.ts
and.civet.svelte.js
.cleanCivetId()
to correctly strip new suffixes (.svelte.ts
,.svelte.js
)..civet
files to output TypeScript-compatible.svelte
files, which are needed for Svelte's new Runes API..civet.jsx
/.civet.tsx
are still supported as before.Motivation
.svelte.ts
from.civet
files.(even tho for now IDE will not recognize syntax of it out of the box, have to manually do .d.ts)
Thanks for reading! 🚀 Happy to adjust anything if needed