Skip to content

Commit

Permalink
feat: support svelte 4 (#948)
Browse files Browse the repository at this point in the history
## Description
This pull request adds support for Svelte version 4. While Svelte's next
version will be 5, this pull request provides support up to version 4.

## Motivation and Context
Dependency Cruiser does not currently support the latest version of
Svelte, which is version 4. This update aims to address that. The syntax
between Svelte 3 and 4 has not fundamentally changed, so only minimal
modifications were needed to support version 4.

https://svelte.dev/docs/v4-migration-guide

## How Has This Been Tested?

- [x] green ci

## 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)

## Checklist

- [x] 📖
  - it _does_ and I have updated it

- [x] ⚖️
- The contribution will be subject to [The MIT
license](https://github.com/sverweij/dependency-cruiser/blob/main/LICENSE),
and I'm OK with that.
  - The contribution is my own original work.
- I am ok with the stuff in
[**CONTRIBUTING.md**](https://github.com/sverweij/dependency-cruiser/blob/main/.github/CONTRIBUTING.md).

---------

Co-authored-by: Sander Verweij <[email protected]>
  • Loading branch information
kubotak-is and sverweij authored Jul 17, 2024
1 parent 8e9a6cd commit 72373ea
Show file tree
Hide file tree
Showing 8 changed files with 159 additions and 21 deletions.
2 changes: 1 addition & 1 deletion doc/faq.md
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,7 @@ manually.
<details>
<summary>Background</summary>
For `.svelte` single file components it uses the `svelte` (version 3.x)
For `.svelte` single file components it uses the `svelte` (version 4.x)
- which will be in your module dependencies if you're developing with Svelte.
- because of how svelte works, all `.svelte` files depend on `"svelte/internal"`.
Expand Down
143 changes: 139 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@
"npm-run-all": "4.1.5",
"prettier": "3.3.3",
"proxyquire": "2.1.3",
"svelte": "3.59.1",
"svelte": "4.2.18",
"symlink-dir": "6.0.1",
"typescript": "5.5.3",
"upem": "9.0.4",
Expand Down Expand Up @@ -294,7 +294,7 @@
{
"package": "svelte",
"policy": "pin",
"because": "upgrading to supporting svelte 4 will require a non-trivial amount of labour (which we are going to invest, but not right now)"
"because": "upgrading to supporting svelte 5 will require a non-trivial amount of labour (which we are going to invest, but not right now)"
}
]
},
Expand All @@ -306,7 +306,7 @@
"coffee-script": ">=1.0.0 <2.0.0",
"coffeescript": ">=1.0.0 <3.0.0",
"livescript": ">=1.0.0 <2.0.0",
"svelte": ">=3.0.0 <4.0.0",
"svelte": ">=3.0.0 <5.0.0",
"swc": ">=1.0.0 <2.0.0",
"typescript": ">=2.0.0 <6.0.0",
"vue-template-compiler": ">=2.0.0 <3.0.0",
Expand Down
2 changes: 1 addition & 1 deletion src/meta.cjs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 7 additions & 5 deletions test/extract/transpile/__fixtures__/svelte-too.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* generated by Svelte v3.59.1 */
/* generated by Svelte v4.2.18 */
import {
SvelteComponent,
append,
Expand All @@ -15,6 +15,7 @@ import {
transition_out,
} from "svelte/internal";

import "svelte/internal/disclose-version";
import "./page.css";
import Header from "./Header.svelte";

Expand All @@ -39,9 +40,7 @@ function create_fragment(ctx) {
create_component(header.$$.fragment);
t0 = space();
section = element("section");

section.innerHTML = `<h2>Pages in Storybook</h2>
<img src="./my.png" alt="my alt"/>`;
section.innerHTML = `<h2>Pages in Storybook</h2> <img src="./my.png" alt="my alt"/>`;
},
m(target, anchor) {
insert(target, article, anchor);
Expand All @@ -66,7 +65,10 @@ function create_fragment(ctx) {
current = false;
},
d(detaching) {
if (detaching) detach(article);
if (detaching) {
detach(article);
}

destroy_component(header);
},
};
Expand Down
12 changes: 7 additions & 5 deletions test/extract/transpile/__fixtures__/svelte.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* generated by Svelte v3.59.1 */
/* generated by Svelte v4.2.18 */
import {
SvelteComponent,
append,
Expand All @@ -15,6 +15,7 @@ import {
transition_out,
} from "svelte/internal";

import "svelte/internal/disclose-version";
import "./page.css";

function create_fragment(ctx) {
Expand All @@ -38,9 +39,7 @@ function create_fragment(ctx) {
create_component(header.$$.fragment);
t0 = space();
section = element("section");

section.innerHTML = `<h2>Pages in Storybook</h2>
<img src="./my.png" alt="my alt"/>`;
section.innerHTML = `<h2>Pages in Storybook</h2> <img src="./my.png" alt="my alt"/>`;
},
m(target, anchor) {
insert(target, article, anchor);
Expand All @@ -65,7 +64,10 @@ function create_fragment(ctx) {
current = false;
},
d(detaching) {
if (detaching) detach(article);
if (detaching) {
detach(article);
}

destroy_component(header);
},
};
Expand Down
2 changes: 1 addition & 1 deletion test/extract/transpile/meta.spec.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ describe("[U] extract/transpile/meta", () => {
},
{
name: "svelte",
version: ">=3.0.0 <4.0.0",
version: ">=3.0.0 <5.0.0",
available: true,
},
{
Expand Down
1 change: 0 additions & 1 deletion test/extract/transpile/svelte-preprocess.spec.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { equal } from "node:assert/strict";
// eslint-disable-next-line node/file-extension-in-import
import * as svelteCompiler from "svelte/compiler";
import normalizeNewline from "normalize-newline";
import thing from "#extract/transpile/typescript-wrap.mjs";
Expand Down

0 comments on commit 72373ea

Please sign in to comment.