From fae09a7c4a9546da2c20b34f44d07d24b86d0773 Mon Sep 17 00:00:00 2001 From: kwangure Date: Wed, 9 Aug 2023 15:21:49 +0300 Subject: [PATCH] feat: delay emptying dist folder in `svelte-package` --- packages/package/src/index.js | 20 +++++++++++++++----- packages/package/src/types.d.ts | 1 + 2 files changed, 16 insertions(+), 5 deletions(-) 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; };