Skip to content

Commit

Permalink
fix: handle jsconfig.json (#11325)
Browse files Browse the repository at this point in the history
  • Loading branch information
dummdidumm authored Dec 14, 2023
1 parent b8333cf commit fba4398
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 10 deletions.
5 changes: 5 additions & 0 deletions .changeset/angry-donuts-suffer.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"svelte-migrate": patch
---

fix: handle jsconfig.json
12 changes: 9 additions & 3 deletions packages/migrate/migrations/sveltekit-2/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,18 @@ import fs from 'node:fs';
import prompts from 'prompts';
import semver from 'semver';
import glob from 'tiny-glob/sync.js';
import { bail, check_git, update_js_file, update_svelte_file } from '../../utils.js';
import {
bail,
check_git,
update_js_file,
update_svelte_file,
update_tsconfig
} from '../../utils.js';
import {
transform_code,
update_pkg_json,
update_svelte_config,
update_tsconfig
update_tsconfig_content
} from './migrate.js';
import { migrate as migrate_svelte_4 } from '../svelte-4/index.js';

Expand Down Expand Up @@ -105,7 +111,7 @@ export async function migrate() {
}

update_pkg_json();
update_tsconfig();
update_tsconfig(update_tsconfig_content);
update_svelte_config();

// const { default: config } = fs.existsSync('svelte.config.js')
Expand Down
7 changes: 0 additions & 7 deletions packages/migrate/migrations/sveltekit-2/migrate.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,6 @@ export function update_pkg_json_content(content) {
]);
}

export function update_tsconfig() {
fs.writeFileSync(
'tsconfig.json',
update_tsconfig_content(fs.readFileSync('tsconfig.json', 'utf8'))
);
}

/** @param {string} content */
export function update_tsconfig_content(content) {
if (!content.includes('"extends"')) {
Expand Down
15 changes: 15 additions & 0 deletions packages/migrate/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,21 @@ export function update_js_file(file_path, transform_code) {
}
}

/**
* Updates the tsconfig/jsconfig.json file with the provided function.
* @param {(content: string) => string} update_tsconfig_content
*/
export function update_tsconfig(update_tsconfig_content) {
const file = fs.existsSync('tsconfig.json')
? 'tsconfig.json'
: fs.existsSync('jsconfig.json')
? 'jsconfig.json'
: null;
if (file) {
fs.writeFileSync(file, update_tsconfig_content(fs.readFileSync(file, 'utf8')));
}
}

/** @param {string | URL} test_file */
export function read_samples(test_file) {
const markdown = fs.readFileSync(test_file, 'utf8').replaceAll('\r\n', '\n');
Expand Down

0 comments on commit fba4398

Please sign in to comment.