Skip to content

Commit 4d544c3

Browse files
committed
feat: 📦 Update svelte to version 5.
1 parent 3cd7c30 commit 4d544c3

File tree

13 files changed

+886
-900
lines changed

13 files changed

+886
-900
lines changed

.github/workflows/test.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Test
1+
name: Check and build
22

33
on:
44
push:
@@ -10,13 +10,13 @@ jobs:
1010
test:
1111
runs-on: ubuntu-latest
1212
steps:
13-
- uses: actions/checkout@v3
14-
- uses: actions/setup-node@v3
13+
- uses: actions/checkout@v4
14+
- uses: actions/setup-node@v4
1515
with:
16-
node-version: 18
16+
node-version: 20
1717
# Install dependencies
1818
- run: npm ci
19+
# Check
20+
- run: npm run check
1921
# Build
2022
- run: npm run build
21-
# Test
22-
- run: npm run check

README.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,8 @@ $ npm run build
3434

3535
## Load unpacked extensions
3636

37-
[Getting Started Tutorial](https://developer.chrome.com/docs/extensions/mv3/getstarted/)
37+
[Getting Started Tutorial](https://developer.chrome.com/docs/extensions/get-started/tutorial/hello-world#load-unpacked)
3838

3939
1. Open the Extension Management page by navigating to `chrome://extensions`.
4040
2. Enable Developer Mode by clicking the toggle switch next to `Developer mode`.
4141
3. Click the `LOAD UNPACKED` button and select the `/dist` directory.
42-
43-
![Example](https://wd.imgix.net/image/BhuKGJaIeLNPW9ehns59NfwqKxF2/vOu7iPbaapkALed96rzN.png?auto=format&w=571)

package-lock.json

Lines changed: 841 additions & 846 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,17 @@
1010
"scripts": {
1111
"dev": "vite",
1212
"build": "vite build",
13-
"check": "svelte-check --tsconfig ./tsconfig.json"
13+
"check": "svelte-check --tsconfig ./tsconfig.json && tsc -p tsconfig.node.json"
1414
},
1515
"devDependencies": {
1616
"@crxjs/vite-plugin": "2.0.0-beta.26",
17-
"@sveltejs/vite-plugin-svelte": "2.4.5",
18-
"@tsconfig/svelte": "5.0.2",
19-
"@types/chrome": "0.0.243",
20-
"svelte": "4.2.0",
21-
"svelte-check": "3.5.0",
22-
"svelte-preprocess": "5.0.4",
23-
"tslib": "2.6.2",
24-
"typescript": "5.2.2",
25-
"vite": "4.2.3"
17+
"@sveltejs/vite-plugin-svelte": "4.0.0",
18+
"@tsconfig/svelte": "5.0.4",
19+
"@types/chrome": "0.0.279",
20+
"svelte": "5.0.5",
21+
"svelte-check": "4.0.5",
22+
"tslib": "2.8.0",
23+
"typescript": "5.6.3",
24+
"vite": "5.4.10"
2625
}
2726
}

src/background/index.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
import { get } from "svelte/store";
21
import { count } from "../storage";
32

43
// Background service workers
54
// https://developer.chrome.com/docs/extensions/mv3/service_workers/
65

76
chrome.runtime.onInstalled.addListener(() => {
8-
console.log(get(count));
7+
count.subscribe(console.log);
98
});
109

1110
// NOTE: If you want to toggle the side panel from the extension's action button,

src/components/Options.svelte

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,18 @@
11
<script lang="ts">
2-
import { onMount } from "svelte";
32
import { type Writable } from "svelte/store";
43
5-
export let count: Writable<number>;
4+
interface Props {
5+
count: Writable<number>;
6+
}
67
7-
onMount(() => {
8-
console.log(`Options onMount count=${$count}`);
9-
});
8+
let { count }: Props = $props();
109
</script>
1110

1211
<div class="container">
1312
<p>Current count: <b>{$count}</b></p>
1413
<div>
15-
<button on:click={() => ($count -= 1)}>-</button>
16-
<button on:click={() => ($count += 1)}>+</button>
14+
<button onclick={() => ($count -= 1)}>-</button>
15+
<button onclick={() => ($count += 1)}>+</button>
1716
</div>
1817
</div>
1918

src/content/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { get } from "svelte/store";
1+
import { mount } from "svelte";
22
import Overlay from "../components/Overlay.svelte";
33
import { count } from "../storage";
44

@@ -9,7 +9,7 @@ import { count } from "../storage";
99
import "./styles.css";
1010

1111
// Some JS on the page
12-
console.log(`CONTENT: ${get(count)}`);
12+
count.subscribe(console.log);
1313

1414
// Some svelte component on the page
15-
new Overlay({ target: document.body });
15+
mount(Overlay, { target: document.body });

src/options/index.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { mount } from "svelte";
12
import Options from "../components/Options.svelte";
23
import { count } from "../storage";
34

@@ -8,10 +9,7 @@ function render() {
89
const target = document.getElementById("app");
910

1011
if (target) {
11-
new Options({
12-
target,
13-
props: { count },
14-
});
12+
mount(Options, { target, props: { count } });
1513
}
1614
}
1715

src/popup/index.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { mount } from "svelte";
12
import Options from "../components/Options.svelte";
23
import { count } from "../storage";
34

@@ -8,10 +9,7 @@ function render() {
89
const target = document.getElementById("app");
910

1011
if (target) {
11-
new Options({
12-
target,
13-
props: { count },
14-
});
12+
mount(Options, { target, props: { count } });
1513
}
1614
}
1715

src/sidepanel/index.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { mount } from "svelte";
12
import Options from "../components/Options.svelte";
23
import { count } from "../storage";
34

@@ -8,10 +9,7 @@ function render() {
89
const target = document.getElementById("app");
910

1011
if (target) {
11-
new Options({
12-
target,
13-
props: { count },
14-
});
12+
mount(Options, { target, props: { count } });
1513
}
1614
}
1715

src/storage.ts

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { writable, type Writable } from 'svelte/store';
1+
import { writable, type Writable } from "svelte/store";
22

33
/**
44
* Creates a persistent Svelte store backed by Chrome's sync storage.
@@ -27,7 +27,7 @@ export function persistentStore<T>(key: string, initialValue: T): Writable<T> {
2727

2828
function watchChrome() {
2929
chrome.storage.sync.onChanged.addListener((changes) => {
30-
if (!(Object.hasOwn(changes, key))) return;
30+
if (!Object.hasOwn(changes, key)) return;
3131

3232
const value = changes[key].newValue as T;
3333
if (storeValueQueue.length > 0 && value === storeValueQueue[0]) {
@@ -42,10 +42,7 @@ export function persistentStore<T>(key: string, initialValue: T): Writable<T> {
4242

4343
// Initialize the store with the value from Chrome storage
4444
chrome.storage.sync.get(key).then((result) => {
45-
let value = Object.hasOwn(result, key) ? result[key] : initialValue;
46-
if (!Object.hasOwn(result, key)) {
47-
console.log(`Persistent store: couldn't find key [${key}] in chrome storage. Default to initial value [${initialValue}]`)
48-
}
45+
const value = Object.hasOwn(result, key) ? result[key] : initialValue;
4946
chromeValueQueue.push(value);
5047
store.set(value);
5148
watchStore();
@@ -55,4 +52,4 @@ export function persistentStore<T>(key: string, initialValue: T): Writable<T> {
5552
return store;
5653
}
5754

58-
export const count = persistentStore("count", 10);
55+
export const count = persistentStore("count", 10);

tsconfig.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,10 @@
1313
*/
1414
"allowJs": true,
1515
"checkJs": true,
16-
"isolatedModules": true
16+
"isolatedModules": true,
17+
"moduleDetection": "force"
1718
},
18-
"include": ["src/**/*.d.ts", "src/**/*.ts", "src/**/*.js", "src/**/*.svelte"],
19+
"include": ["src/**/*.ts", "src/**/*.js", "src/**/*.svelte"],
20+
// https://github.com/vitejs/vite/issues/18139
1921
"references": [{ "path": "./tsconfig.node.json" }]
2022
}

tsconfig.node.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
1-
// vite tsconfig
21
{
32
"compilerOptions": {
43
"composite": true,
4+
"tsBuildInfoFile": "./node_modules/.tmp/tsconfig.node.tsbuildinfo",
55
"skipLibCheck": true,
66
"module": "ESNext",
7-
"moduleResolution": "bundler"
7+
"moduleResolution": "bundler",
8+
"strict": true,
9+
"noEmit": true,
10+
"noUncheckedSideEffectImports": true
811
},
912
"include": ["vite.config.ts", "src/manifest.config.ts", "package.json"]
1013
}

0 commit comments

Comments
 (0)