Skip to content
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: svelte types generation during build #14

Merged
merged 5 commits into from
May 9, 2024

Conversation

paoloricciuti
Copy link
Contributor

This should fix the type problems for the svelte renderer

cc. @mattcroat

@mattcroat
Copy link
Contributor

@antfu this should fix and close #13

@@ -1,8 +1,8 @@
<script lang="ts">
import { codeToKeyedTokens, createMagicMoveMachine } from '../core'
import { codeToKeyedTokens, createMagicMoveMachine } from '../core.mjs'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will break dev (the playground)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure how to fix it

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shipping core.ts, renderer.ts and types.ts will fix it. Because svelte files are compiled with the svelte version of the user of the library through vite. Do you think it will be feasible and possible through unbuild?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for the moment i've added some other fs.copyFile, i don't know if there's a better way but this should make everything works both in the playground and in imported svelte projects.

Do you have a quick way to test this in react and vue too?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think shipping source files is a good idea. I feel it would be better if we could somehow compile the svelte file to pure JS, or rewrite the path on build

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if we could replace the extension at build time it would be great

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coming in from left field to suggest either:

  • all build files are outputted as .js (you have type module set so shouldn't break anything). That way in TS files you can import with .js extensions which will work during both dev and builds (being explicit is usually better anyway)
  • dev uses a built version of the library rather than the TS source

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think shipping source files is a good idea. I feel it would be better if we could somehow compile the svelte file to pure JS, or rewrite the path on build

Compile svelte files to js is not the right approach because that would mean the compilation is stuck at the build moment. This basically means that if the user uses a different svelte version it might be uncompatible.

We can rewrite path on build although i see this solution as a bit more brittle than actually shipping the typescript files to allow them to be compiled at build time by the user.

The suggestion from @ghostdevv is also a good compromise imho.

@antfu antfu merged commit c135e0a into shikijs:main May 9, 2024
8 checks passed
@antfu
Copy link
Member

antfu commented May 9, 2024

Released as v0.4.1 - let me know if it works or not

@mattcroat
Copy link
Contributor

@antfu everything seems to work great, thank you! 🙏

@paoloricciuti
Copy link
Contributor Author

Released as v0.4.1 - let me know if it works or not

Very good solution. Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants