Merge branch 'main' into aa-coordination

aa-coordination
Rich Harris 7 months ago
commit b4ee140632

@ -26,6 +26,15 @@ function mkdirp(dir) {
} catch {} } catch {}
} }
/**
* @param {string} file
* @param {string} contents
*/
function write(file, contents) {
mkdirp(path.dirname(file));
fs.writeFileSync(file, contents);
}
const svelte_modules = glob('**/*.svelte', { cwd: `${cwd}/src` }); const svelte_modules = glob('**/*.svelte', { cwd: `${cwd}/src` });
const js_modules = glob('**/*.js', { cwd: `${cwd}/src` }); const js_modules = glob('**/*.js', { cwd: `${cwd}/src` });
@ -46,7 +55,7 @@ for (const generate of /** @type {const} */ (['client', 'server'])) {
modern: true modern: true
}); });
fs.writeFileSync( write(
`${cwd}/output/${file}.json`, `${cwd}/output/${file}.json`,
JSON.stringify( JSON.stringify(
ast, ast,
@ -57,7 +66,7 @@ for (const generate of /** @type {const} */ (['client', 'server'])) {
try { try {
const migrated = migrate(source); const migrated = migrate(source);
fs.writeFileSync(`${cwd}/output/${file}.migrated.svelte`, migrated.code); write(`${cwd}/output/${file}.migrated.svelte`, migrated.code);
} catch (e) { } catch (e) {
console.warn(`Error migrating ${file}`, e); console.warn(`Error migrating ${file}`, e);
} }
@ -78,15 +87,12 @@ for (const generate of /** @type {const} */ (['client', 'server'])) {
console.warn(warning.frame); console.warn(warning.frame);
} }
fs.writeFileSync( write(output_js, compiled.js.code + '\n//# sourceMappingURL=' + path.basename(output_map));
output_js,
compiled.js.code + '\n//# sourceMappingURL=' + path.basename(output_map)
);
fs.writeFileSync(output_map, compiled.js.map.toString()); write(output_map, compiled.js.map.toString());
if (compiled.css) { if (compiled.css) {
fs.writeFileSync(output_css, compiled.css.code); write(output_css, compiled.css.code);
} }
} }
@ -106,6 +112,6 @@ for (const generate of /** @type {const} */ (['client', 'server'])) {
const output_js = `${cwd}/output/${generate}/${file}`; const output_js = `${cwd}/output/${generate}/${file}`;
mkdirp(path.dirname(output_js)); mkdirp(path.dirname(output_js));
fs.writeFileSync(output_js, compiled.js.code); write(output_js, compiled.js.code);
} }
} }

Loading…
Cancel
Save