Skip to content

Commit

Permalink
add migration task
Browse files Browse the repository at this point in the history
  • Loading branch information
Rich-Harris committed Dec 16, 2024
1 parent 4d2e5dd commit 25a948b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
10 changes: 10 additions & 0 deletions packages/migrate/migrations/app-state/migrate.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ export function transform_svelte_code(code) {
});
let modified = code.replace('$app/stores', '$app/state');

let needs_navigating_migration_task = false;

for (const [store, alias] of stores) {
// if someone uses that they're deep into stores and we better not touch this file
if (store === 'getStores') return code;
Expand Down Expand Up @@ -68,10 +70,18 @@ export function transform_svelte_code(code) {
return code;
}

if (store === 'navigating' && after[0] !== '.') {
needs_navigating_migration_task = true;
}

modified = before.slice(0, -1) + alias + (store === 'updated' ? '.current' : '') + after;
count_removed++;
}
}

if (needs_navigating_migration_task) {
modified = `<!-- @migration task: review uses of \`navigating\` -->\n${modified}`;
}

return modified;
}
2 changes: 1 addition & 1 deletion packages/migrate/migrations/app-state/migrate.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ test('Updates $app/store #2', () => {
);
assert.equal(
result,
`<script>
`<!-- @migration task: review uses of \`navigating\` -->\n<script>
import { navigating, updated } from '$app/state';
updated.current;
updated.check();
Expand Down

0 comments on commit 25a948b

Please sign in to comment.