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

Make optimizeImports compatible with Svelte 5 #62

Merged
merged 3 commits into from
Apr 30, 2024
Merged

Make optimizeImports compatible with Svelte 5 #62

merged 3 commits into from
Apr 30, 2024

Conversation

metonym
Copy link
Collaborator

@metonym metonym commented Apr 30, 2024

Closes #61

Svelte 5 contains breaking changes. One of them is that svelte/compiler no longer exports the walk function.

carbon-preprocess-svelte uses walk to walk the AST in order to re-write Carbon-related imports at compile time.

The officially recommended approach is to import walk from street-walker directly. However, in my initial testing, I found that the latest major version of estree-walker is ESM-only (see Rich-Harris/estree-walker#26).

My goals for this package include the following:

  • Keep any direct dependencies to an absolute minimum.
  • Ensure the package is broadly compatible. This means continuing to distribute the package in CJS, as Vite-based set-ups support this format (presumably the predominant bundler given the popularity of SvelteKit etc..).
  • Avoid including svelte as a direct dependency. I want to avoid using a specific version of svelte with this package. What I mean by this is that the package should use the parser from the Svelte version the user uses. For example, if a user is running Svelte 3/4, it should use the parse from their exact Svelte version.

As such, I've arrived at the following:

  • Use walk from estree-walker@2 (which is still CJS-compatible)

From my testing, this approach works with Svelte 4 and Svelte 5.

@metonym metonym merged commit ebabe39 into main Apr 30, 2024
1 check passed
@metonym metonym deleted the svelte-5 branch April 30, 2024 03:49
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.

Compatibility issues with Svelte 5
1 participant