Skip to content

Commit 73fa9d3

Browse files
authored
chore: create intermediate directories as needed when compiling sandbox (#15163)
1 parent e83ab1c commit 73fa9d3

File tree

1 file changed

+15
-9
lines changed

1 file changed

+15
-9
lines changed

playgrounds/sandbox/run.js

+15-9
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,15 @@ function mkdirp(dir) {
2626
} catch {}
2727
}
2828

29+
/**
30+
* @param {string} file
31+
* @param {string} contents
32+
*/
33+
function write(file, contents) {
34+
mkdirp(path.dirname(file));
35+
fs.writeFileSync(file, contents);
36+
}
37+
2938
const svelte_modules = glob('**/*.svelte', { cwd: `${cwd}/src` });
3039
const js_modules = glob('**/*.js', { cwd: `${cwd}/src` });
3140

@@ -46,7 +55,7 @@ for (const generate of /** @type {const} */ (['client', 'server'])) {
4655
modern: true
4756
});
4857

49-
fs.writeFileSync(
58+
write(
5059
`${cwd}/output/${file}.json`,
5160
JSON.stringify(
5261
ast,
@@ -57,7 +66,7 @@ for (const generate of /** @type {const} */ (['client', 'server'])) {
5766

5867
try {
5968
const migrated = migrate(source);
60-
fs.writeFileSync(`${cwd}/output/${file}.migrated.svelte`, migrated.code);
69+
write(`${cwd}/output/${file}.migrated.svelte`, migrated.code);
6170
} catch (e) {
6271
console.warn(`Error migrating ${file}`, e);
6372
}
@@ -75,15 +84,12 @@ for (const generate of /** @type {const} */ (['client', 'server'])) {
7584
console.warn(warning.frame);
7685
}
7786

78-
fs.writeFileSync(
79-
output_js,
80-
compiled.js.code + '\n//# sourceMappingURL=' + path.basename(output_map)
81-
);
87+
write(output_js, compiled.js.code + '\n//# sourceMappingURL=' + path.basename(output_map));
8288

83-
fs.writeFileSync(output_map, compiled.js.map.toString());
89+
write(output_map, compiled.js.map.toString());
8490

8591
if (compiled.css) {
86-
fs.writeFileSync(output_css, compiled.css.code);
92+
write(output_css, compiled.css.code);
8793
}
8894
}
8995

@@ -100,6 +106,6 @@ for (const generate of /** @type {const} */ (['client', 'server'])) {
100106
const output_js = `${cwd}/output/${generate}/${file}`;
101107

102108
mkdirp(path.dirname(output_js));
103-
fs.writeFileSync(output_js, compiled.js.code);
109+
write(output_js, compiled.js.code);
104110
}
105111
}

0 commit comments

Comments
 (0)