Skip to content

Commit 49d38fc

Browse files
authored
fix: Update +error.svelte creation template in vscode extension (#2811)
* Update +error.svelte creation syntax (#2810) * Add Svelte 5 variants to +error.svelte creation syntax template (#2810) * Change withRunes to withProps in +error.svelte template * Add withAppState option * Change withRunes to withAppState in +error.svelte template * Remove trailing comma * Add type for withAppState
1 parent 28cdfb2 commit 49d38fc

File tree

3 files changed

+34
-3
lines changed

3 files changed

+34
-3
lines changed

packages/svelte-vscode/src/sveltekit/generateFiles/templates/error.ts

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,14 @@ const defaultScriptTemplate = `
88
<h1>{$page.status}: {$page.error.message}</h1>
99
`;
1010

11+
const jsSv5ScriptTemplateAppState = `
12+
<script>
13+
import { page } from '$app/state';
14+
</script>
15+
16+
<h1>{page.status}: {page.error.message}</h1>
17+
`;
18+
1119
const tsScriptTemplate = `
1220
<script lang="ts">
1321
import { page } from '$app/stores';
@@ -16,12 +24,26 @@ const tsScriptTemplate = `
1624
<h1>{$page.status}: {$page.error?.message}</h1>
1725
`;
1826

27+
const tsSv5ScriptTemplateAppState = `
28+
<script lang="ts">
29+
import { page } from '$app/state';
30+
</script>
31+
32+
<h1>{page.status}: {page.error?.message}</h1>
33+
`;
34+
1935
export default async function (config: GenerateConfig): ReturnType<Resource['generate']> {
20-
const { withTs } = config.kind;
36+
const { withTs, withAppState } = config.kind;
2137
let template = defaultScriptTemplate;
2238

23-
if (withTs) {
39+
if (withAppState && withTs) {
40+
template = tsSv5ScriptTemplateAppState;
41+
} else if (withAppState && !withTs) {
42+
template = jsSv5ScriptTemplateAppState;
43+
} else if (!withAppState && withTs) {
2444
template = tsScriptTemplate;
45+
} else if (!withAppState && !withTs) {
46+
template = defaultScriptTemplate;
2547
}
2648

2749
return template.trim();

packages/svelte-vscode/src/sveltekit/generateFiles/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ export interface GenerateConfig {
3939
withSatisfies: boolean;
4040
withRunes: boolean;
4141
withProps: boolean;
42+
withAppState: boolean;
4243
};
4344
pageExtension: string;
4445
scriptExtension: string;

packages/svelte-vscode/src/sveltekit/utils.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,13 @@ export async function checkProjectKind(path: string): Promise<GenerateConfig['ki
4747
fallback: true
4848
});
4949

50+
let withAppState = atLeast({
51+
packageName: '@sveltejs/kit',
52+
versionMin: '2.12',
53+
versionToCheck: svelteKitVersion ?? '',
54+
fallback: true
55+
});
56+
5057
const withTs = !!tsconfig && (!jsconfig || tsconfig.length >= jsconfig.length);
5158
let withSatisfies = false;
5259
if (withTs) {
@@ -70,7 +77,8 @@ export async function checkProjectKind(path: string): Promise<GenerateConfig['ki
7077
withTs,
7178
withSatisfies,
7279
withRunes,
73-
withProps
80+
withProps,
81+
withAppState
7482
};
7583
}
7684

0 commit comments

Comments
 (0)