Skip to content

Commit

Permalink
Merge branch 'main' into chore/explore-parsers-and-printers
Browse files Browse the repository at this point in the history
  • Loading branch information
manuel3108 committed Jan 10, 2025
2 parents 3e2ee46 + e87dfd2 commit 72ad646
Show file tree
Hide file tree
Showing 10 changed files with 58 additions and 22 deletions.
5 changes: 0 additions & 5 deletions .changeset/lemon-cycles-mix.md

This file was deleted.

5 changes: 5 additions & 0 deletions .changeset/strange-ducks-melt.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'svelte-migrate': minor
---

feat: allow sub path migration or none at all for Svelte 5 migration
2 changes: 1 addition & 1 deletion documentation/docs/20-commands/40-sv-migrate.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ npx sv migrate [migration]

### `app-state`

Migrates `$app/store` usage to `$app/state` in `.svelte` files. See the [migration guide](/docs/kit/migrating-to-sveltekit-2#SvelteKit-2.12:-$app-stores-deprecated) for more details.
Migrates `$app/stores` usage to `$app/state` in `.svelte` files. See the [migration guide](/docs/kit/migrating-to-sveltekit-2#SvelteKit-2.12:-$app-stores-deprecated) for more details.

### `svelte-5`

Expand Down
4 changes: 2 additions & 2 deletions packages/addons/paraglide/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ export default defineAddon({

imports.addDefault(script.ast, '$lib/paraglide/messages.js', '* as m');
imports.addNamed(script.ast, '$app/navigation', { goto: 'goto' });
imports.addNamed(script.ast, '$app/stores', { page: 'page' });
imports.addNamed(script.ast, '$app/state', { page: 'page' });
imports.addNamed(script.ast, '$lib/i18n', { i18n: 'i18n' });
if (typescript) {
imports.addNamed(
Expand All @@ -253,7 +253,7 @@ export default defineAddon({
${ts('', '* @param {import("$lib/paraglide/runtime").AvailableLanguageTag} newLanguage')}
${ts('', '*/')}
function switchToLanguage(newLanguage${ts(': AvailableLanguageTag')}) {
const canonicalPath = i18n.route($page.url.pathname);
const canonicalPath = i18n.route(page.url.pathname);
const localisedPath = i18n.resolveRoute(canonicalPath, newLanguage);
goto(localisedPath);
}
Expand Down
9 changes: 9 additions & 0 deletions packages/cli/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
# sv

## 0.6.11
### Patch Changes


- fix: properly add `eslint` dependency ([#375](https://github.com/sveltejs/cli/pull/375))


- feat: migrate to `$app/state` ([#358](https://github.com/sveltejs/cli/pull/358))

## 0.6.10
### Patch Changes

Expand Down
2 changes: 1 addition & 1 deletion packages/cli/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "sv",
"version": "0.6.10",
"version": "0.6.11",
"type": "module",
"description": "A CLI for creating and updating SvelteKit projects",
"license": "MIT",
Expand Down
2 changes: 1 addition & 1 deletion packages/core/tests/js/common/jsdoc-comment/input.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
function switchToLanguage(newLanguage) {
const canonicalPath = i18n.route($page.url.pathname);
const canonicalPath = i18n.route(page.url.pathname);
const localisedPath = i18n.resolveRoute(canonicalPath, newLanguage);
goto(localisedPath);
}
2 changes: 1 addition & 1 deletion packages/core/tests/js/common/jsdoc-comment/output.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* @param {import("$lib/paraglide/runtime").AvailableLanguageTag} newLanguage
*/
function switchToLanguage(newLanguage) {
const canonicalPath = i18n.route($page.url.pathname);
const canonicalPath = i18n.route(page.url.pathname);
const localisedPath = i18n.resolveRoute(canonicalPath, newLanguage);

goto(localisedPath);
Expand Down
8 changes: 4 additions & 4 deletions packages/create/templates/demo/src/routes/Header.svelte
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<script lang="ts">
import { page } from '$app/stores';
import { page } from '$app/state';
import logo from '$lib/images/svelte-logo.svg';
import github from '$lib/images/github.svg';
</script>
Expand All @@ -16,13 +16,13 @@
<path d="M0,0 L1,2 C1.5,3 1.5,3 2,3 L2,0 Z" />
</svg>
<ul>
<li aria-current={$page.url.pathname === '/' ? 'page' : undefined}>
<li aria-current={page.url.pathname === '/' ? 'page' : undefined}>
<a href="/">Home</a>
</li>
<li aria-current={$page.url.pathname === '/about' ? 'page' : undefined}>
<li aria-current={page.url.pathname === '/about' ? 'page' : undefined}>
<a href="/about">About</a>
</li>
<li aria-current={$page.url.pathname.startsWith('/sverdle') ? 'page' : undefined}>
<li aria-current={page.url.pathname.startsWith('/sverdle') ? 'page' : undefined}>
<a href="/sverdle">Sverdle</a>
</li>
</ul>
Expand Down
41 changes: 34 additions & 7 deletions packages/migrate/migrations/svelte-5/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,6 @@ export async function migrate() {
bail('Please re-run this script in a directory with a package.json');
}

console.log(
'This migration is experimental — please report any bugs to https://github.com/sveltejs/svelte/issues'
);

const pkg = JSON.parse(fs.readFileSync('package.json', 'utf8'));

const svelte_dep = pkg.devDependencies?.svelte ?? pkg.dependencies?.svelte;
Expand Down Expand Up @@ -141,12 +137,41 @@ export async function migrate() {
(dir) => fs.statSync(dir).isDirectory() && dir !== 'node_modules' && !dir.startsWith('.')
)
.map((dir) => ({ title: dir, value: dir, selected: true }))
.concat([
{
title: 'custom (overrides selection, allows to specify sub folders)',
value: ',', // a value that definitely isn't a valid folder name so it cannot clash
selected: false
}
])
});

if (!folders.value?.length) {
process.exit(1);
}

if (folders.value.includes(',')) {
const custom = await prompts({
type: 'list',
name: 'value',
message: 'Specify folder paths (comma separated)'
});

if (!custom.value) {
process.exit(1);
}

folders.value = custom.value.map((/** @type {string} */ folder) => (folder = folder.trim()));
}

const do_migration = await prompts({
type: 'confirm',
name: 'value',
message:
'Do you want to use the migration tool to convert your Svelte components to the new syntax? (You can also do this per component or sub path later)',
initial: true
});

update_pkg_json();

const use_ts = fs.existsSync('tsconfig.json');
Expand All @@ -171,9 +196,11 @@ export async function migrate() {
for (const file of files) {
if (extensions.some((ext) => file.endsWith(ext))) {
if (svelte_extensions.some((ext) => file.endsWith(ext))) {
update_svelte_file(file, transform_module_code, (code) =>
transform_svelte_code(code, migrate, { filename: file, use_ts })
);
if (do_migration.value) {
update_svelte_file(file, transform_module_code, (code) =>
transform_svelte_code(code, migrate, { filename: file, use_ts })
);
}
} else {
update_js_file(file, transform_module_code);
}
Expand Down

0 comments on commit 72ad646

Please sign in to comment.