Skip to content

Commit

Permalink
chore(lucia): update demo to use svelte 5 syntax (#141)
Browse files Browse the repository at this point in the history
  • Loading branch information
AdrianGonz97 authored Oct 15, 2024
1 parent 98b882e commit 6872dd8
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
5 changes: 5 additions & 0 deletions .changeset/young-pianos-arrive.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@sveltejs/adders": patch
---

chore(lucia): update demo to use svelte 5 syntax
14 changes: 8 additions & 6 deletions packages/adders/lucia/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -485,19 +485,20 @@ export default defineAdder({
{
name: ({ kit }) => `${kit!.routesDirectory}/demo/login/+page.svelte`,
condition: ({ options }) => options.demo,
content({ content, typescript, kit }) {
content({ content, dependencyVersion, typescript, kit }) {
if (content) {
const filePath = `${kit!.routesDirectory}/demo/login/+page.svelte`;
log.warn(`Existing ${colors.yellow(filePath)} file. Could not update.`);
return content;
}

const [ts] = utils.createPrinter(typescript);
const svelte5 = !!dependencyVersion('svelte')?.startsWith('5');
const [ts, s5] = utils.createPrinter(typescript, svelte5);
return dedent`
<script ${ts(`lang='ts'`)}>
import { enhance } from '$app/forms';
${ts(`import type { ActionData } from './$types';\n`)}
export let form${ts(': ActionData')};
${s5(`let { form }${ts(': { form: ActionData }')} = $props();`, `export let form${ts(': ActionData')};`)}
</script>
<h1>Login/Register</h1>
Expand Down Expand Up @@ -558,19 +559,20 @@ export default defineAdder({
{
name: ({ kit }) => `${kit!.routesDirectory}/demo/+page.svelte`,
condition: ({ options }) => options.demo,
content({ content, typescript, kit }) {
content({ content, dependencyVersion, typescript, kit }) {
if (content) {
const filePath = `${kit!.routesDirectory}/demo/+page.svelte`;
log.warn(`Existing ${colors.yellow(filePath)} file. Could not update.`);
return content;
}

const [ts] = utils.createPrinter(typescript);
const svelte5 = !!dependencyVersion('svelte')?.startsWith('5');
const [ts, s5] = utils.createPrinter(typescript, svelte5);
return dedent`
<script ${ts(`lang='ts'`)}>
import { enhance } from '$app/forms';
${ts(`import type { PageServerData } from './$types';\n`)}
export let data${ts(': PageServerData')};
${s5(`let { data }${ts(': { data: PageServerData }')} = $props();`, `export let data${ts(': PageServerData')};`)}
</script>
<h1>Hi, {data.user.username}!</h1>
Expand Down

0 comments on commit 6872dd8

Please sign in to comment.