Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: allow sub path migration or none at all #391

Merged
merged 2 commits into from
Jan 10, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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: ',',
dummdidumm marked this conversation as resolved.
Show resolved Hide resolved
selected: false
}
])
});

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

if (folders.value.includes(',')) {
const custom = await prompts({
type: 'list',
name: 'value',
message: 'Specify folders (comma separated)'
dummdidumm marked this conversation as resolved.
Show resolved Hide resolved
});

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
Loading