Skip to content

Commit e87dfd2

Browse files
authored
feat: allow sub path migration or none at all (#391)
* feat: allow sub path migration or none at all This adds two new prompts to the Svelte migration: - custom folder prompt (from multiselect); if selected you can specify what folders exactly to migrate. closes #390 - adds a way to skip migrating your components if you want to do it incrementally but still benefit from having your package.json and entry points migrated automatically * feedback
1 parent 2a87573 commit e87dfd2

File tree

2 files changed

+39
-7
lines changed

2 files changed

+39
-7
lines changed

.changeset/strange-ducks-melt.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'svelte-migrate': minor
3+
---
4+
5+
feat: allow sub path migration or none at all for Svelte 5 migration

packages/migrate/migrations/svelte-5/index.js

Lines changed: 34 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,6 @@ export async function migrate() {
1818
bail('Please re-run this script in a directory with a package.json');
1919
}
2020

21-
console.log(
22-
'This migration is experimental — please report any bugs to https://github.com/sveltejs/svelte/issues'
23-
);
24-
2521
const pkg = JSON.parse(fs.readFileSync('package.json', 'utf8'));
2622

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

146149
if (!folders.value?.length) {
147150
process.exit(1);
148151
}
149152

153+
if (folders.value.includes(',')) {
154+
const custom = await prompts({
155+
type: 'list',
156+
name: 'value',
157+
message: 'Specify folder paths (comma separated)'
158+
});
159+
160+
if (!custom.value) {
161+
process.exit(1);
162+
}
163+
164+
folders.value = custom.value.map((/** @type {string} */ folder) => (folder = folder.trim()));
165+
}
166+
167+
const do_migration = await prompts({
168+
type: 'confirm',
169+
name: 'value',
170+
message:
171+
'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)',
172+
initial: true
173+
});
174+
150175
update_pkg_json();
151176

152177
const use_ts = fs.existsSync('tsconfig.json');
@@ -171,9 +196,11 @@ export async function migrate() {
171196
for (const file of files) {
172197
if (extensions.some((ext) => file.endsWith(ext))) {
173198
if (svelte_extensions.some((ext) => file.endsWith(ext))) {
174-
update_svelte_file(file, transform_module_code, (code) =>
175-
transform_svelte_code(code, migrate, { filename: file, use_ts })
176-
);
199+
if (do_migration.value) {
200+
update_svelte_file(file, transform_module_code, (code) =>
201+
transform_svelte_code(code, migrate, { filename: file, use_ts })
202+
);
203+
}
177204
} else {
178205
update_js_file(file, transform_module_code);
179206
}

0 commit comments

Comments
 (0)