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

Feature request: Svelte 5 support #962

Closed
alex-knyaz opened this issue Oct 30, 2024 · 4 comments · Fixed by #963
Closed

Feature request: Svelte 5 support #962

alex-knyaz opened this issue Oct 30, 2024 · 4 comments · Fixed by #963

Comments

@alex-knyaz
Copy link

Context

Dependency-cruiser doesn't officially support Svelte 5 while analyzing project dependencies.
Svelte 4 support was implemented in #948

Expected Behavior

Parse and analyze Svelte 5 files properly.

Current Behavior

No official Svelte 5 support, but adding .svelte to options.extensions array in .dependency-cruiser.cjs seems to make it work anyway?

Possible Solution

Extend current Svelte 4 handling to support Svelte 5. Should not be difficult if it just works with workaround.

Considered alternatives

Using .svelte extension workaround, but proper support would be better.

@sverweij
Copy link
Owner

Hi @alex-knyaz thanks for your interest to getting dependency-cruiser to work with svelte 5. A while ago I attempted an upgrade as part of a 3rd party dependency bump of a bunch of dependencies but aborted as it took more than the time I had for doing an upgrade. The svelte compile function got a different profile (calling it as is makes that it throws) and the generated code looks quite different (so my integration tests threw a hissy fit as well).

So it's definitely some effort to make it work. Slightly better rested with more time + prior knowledge I attempted again just now. It seems it's working now. I'll see if I can publish a beta for you to check tonight.

No official Svelte 5 support, but adding .svelte to options.extensions array in .dependency-cruiser.cjs seems to make it work anyway?

That will indeed work in many cases, but not why you'd think. If dependency-cruiser doesn't find a suitable svelte compiler it'll treat the .svelte file as if it's plain javascript. That will error out and fall back to the error tolerant acorn-loose parser, that often will be able to get a remarkable amount of information out of svelte (, vue, typescript, tsx, typo ridden javascript, ...) files.

The results you get as current behavior are very likely because of this fallback for the fallback scenario...

@sverweij
Copy link
Owner

sverweij commented Oct 31, 2024

@alex-knyaz I've published a version of dependency-cruiser with svelte 5 support to npm with the beta tag: [email protected]

Let me know if it works for you.

@alex-knyaz
Copy link
Author

Thank you for the quick response and implementation! The beta works perfectly. Really appreciate the detailed explanation and the swift response. Dependency-cruiser is amazing. Thanks for maintaining it!

sverweij added a commit that referenced this issue Nov 2, 2024
## Description

- updates the svelte _compile_ call to include an empty object as a 2nd
parameter.
This is required for svelte 5 and svelte 4 seems to ignore it so it
seems we're in luck and don't need funky branching.
- Adjusts the supported compiler range for svelte
- Adjusts the  integration & unit tests to expect svelte 5 output

## Motivation and Context

Svelte 5 seems to have become stable and in their release notes they
encourage users to upgrade.

Also fixes #962 

## How Has This Been Tested?


- [x] green ci
- [x] adjusted  automated non-regression  tests

## Types of changes


- [ ] Bug fix (non-breaking change which fixes an issue)
- [ ] Documentation only change
- [ ] Refactor (non-breaking change which fixes an issue without
changing functionality)
- [x] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing
functionality to change)
@sverweij
Copy link
Owner

sverweij commented Nov 3, 2024

@alex-knyaz I've just released [email protected] onto npm which contains (a.o.) the linked pull request. Thanks again for raising this issue!

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 a pull request may close this issue.

2 participants