Skip to content

Commit c936eb8

Browse files
fix: Generated types no longer permanently delete themselves (#5063)
* fix: sync no longer permanently deletes directory * Changelog * DRY, you idiot * fix: Lint
1 parent 5d58703 commit c936eb8

File tree

3 files changed

+18
-8
lines changed

3 files changed

+18
-8
lines changed

.changeset/lemon-planets-sit.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@sveltejs/kit': patch
3+
---
4+
5+
[fix] svelte-kit sync no longer permanently deletes the types directory

packages/kit/src/core/sync/utils.js

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,20 @@ const previous_contents = new Map();
1111
*/
1212
export function write_if_changed(file, code) {
1313
if (code !== previous_contents.get(file)) {
14-
previous_contents.set(file, code);
15-
mkdirp(path.dirname(file));
16-
fs.writeFileSync(file, code);
14+
write(file, code);
1715
}
1816
}
1917

18+
/**
19+
* @param {string} file
20+
* @param {string} code
21+
*/
22+
export function write(file, code) {
23+
previous_contents.set(file, code);
24+
mkdirp(path.dirname(file));
25+
fs.writeFileSync(file, code);
26+
}
27+
2028
/** @param {string} str */
2129
export function trim(str) {
2230
const indentation = /** @type {RegExpExecArray} */ (/\n?(\s*)/.exec(str))[1];

packages/kit/src/core/sync/write_types.js

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { rimraf } from '../../utils/filesystem.js';
22
import { parse_route_id } from '../../utils/routing.js';
3-
import { write_if_changed } from './utils.js';
3+
import { write } from './utils.js';
44

55
/** @param {string} imports */
66
const header = (imports) => `
@@ -76,9 +76,6 @@ export function write_types(config, manifest_data) {
7676
const parts = (key || 'index').split('/');
7777
parts.push('__types', /** @type {string} */ (parts.pop()));
7878

79-
write_if_changed(
80-
`${config.kit.outDir}/types/${parts.join('/')}.d.ts`,
81-
content.join('\n').trim()
82-
);
79+
write(`${config.kit.outDir}/types/${parts.join('/')}.d.ts`, content.join('\n').trim());
8380
});
8481
}

0 commit comments

Comments
 (0)