Skip to content

Commit

Permalink
fix: prefer ts in unclear migration situations if tsconfig.json fou…
Browse files Browse the repository at this point in the history
…nd (#12881)

Fixes #12880, relies on sveltejs/svelte#13929
  • Loading branch information
dummdidumm authored Oct 31, 2024
1 parent 0015474 commit 48f0201
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/rare-glasses-smell.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'svelte-migrate': patch
---

fix: prefer TS in unclear migration situations if `tsconfig.json` found
4 changes: 3 additions & 1 deletion packages/migrate/migrations/svelte-5/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,8 @@ export async function migrate() {

update_pkg_json();

const use_ts = fs.existsSync('tsconfig.json');

// const { default: config } = fs.existsSync('svelte.config.js')
// ? await import(pathToFileURL(path.resolve('svelte.config.js')).href)
// : { default: {} };
Expand All @@ -170,7 +172,7 @@ export async function migrate() {
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 })
transform_svelte_code(code, migrate, { filename: file, use_ts })
);
} else {
update_js_file(file, transform_module_code);
Expand Down
4 changes: 2 additions & 2 deletions packages/migrate/migrations/svelte-5/migrate.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ export function transform_module_code(code) {

/**
* @param {string} code
* @param {(source: string, options: { filename?: string }) => { code: string }} transform_code
* @param {{ filename?: string }} options
* @param {(source: string, options: { filename?: string, use_ts?: boolean }) => { code: string }} transform_code
* @param {{ filename?: string, use_ts?: boolean }} options
*/
export function transform_svelte_code(code, transform_code, options) {
return transform_code(code, options).code;
Expand Down

0 comments on commit 48f0201

Please sign in to comment.