diff --git a/.changeset/red-dots-notice.md b/.changeset/red-dots-notice.md new file mode 100644 index 000000000000..56ebc5dc5f5b --- /dev/null +++ b/.changeset/red-dots-notice.md @@ -0,0 +1,5 @@ +--- +'@sveltejs/package': patch +--- + +fix: delay emptying `dist/` folder diff --git a/packages/package/src/index.js b/packages/package/src/index.js index fb8690934f7a..8e1398577247 100644 --- a/packages/package/src/index.js +++ b/packages/package/src/index.js @@ -22,25 +22,29 @@ export async function build(options) { * @param {(name: string, code: string) => void} analyse_code */ async function do_build(options, analyse_code) { - const { input, output, extensions, alias } = normalize_options(options); + const { input, output, temp, extensions, alias } = normalize_options(options); if (!fs.existsSync(input)) { throw new Error(`${path.relative('.', input)} does not exist`); } - rimraf(output); - mkdirp(output); + rimraf(temp); + mkdirp(temp); const files = scan(input, extensions); if (options.types) { - await emit_dts(input, output, options.cwd, alias, files); + await emit_dts(input, temp, options.cwd, alias, files); } for (const file of files) { - await process_file(input, output, file, options.config.preprocess, alias, analyse_code); + await process_file(input, temp, file, options.config.preprocess, alias, analyse_code); } + rimraf(output); + mkdirp(output); + copy(temp, output); + console.log( colors .bold() @@ -145,6 +149,11 @@ export async function watch(options) { function normalize_options(options) { const input = path.resolve(options.cwd, options.input); const output = path.resolve(options.cwd, options.output); + const temp = path.resolve( + options.cwd, + options.config.kit?.outDir ?? '.svelte-kit', + '__package__' + ); const extensions = options.config.extensions ?? ['.svelte']; const alias = { @@ -155,6 +164,7 @@ function normalize_options(options) { return { input, output, + temp, extensions, alias }; diff --git a/packages/package/src/types.d.ts b/packages/package/src/types.d.ts index 3e481ed2bef9..6724137d8d1d 100644 --- a/packages/package/src/types.d.ts +++ b/packages/package/src/types.d.ts @@ -12,6 +12,7 @@ export interface Options { files?: { lib?: string; }; + outDir?: string; }; preprocess?: PreprocessorGroup; };