Skip to content

Commit

Permalink
feat: delay emptying dist folder in svelte-package
Browse files Browse the repository at this point in the history
  • Loading branch information
kwangure committed Aug 9, 2023
1 parent 737eb67 commit fae09a7
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
20 changes: 15 additions & 5 deletions packages/package/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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 = {
Expand All @@ -155,6 +164,7 @@ function normalize_options(options) {
return {
input,
output,
temp,
extensions,
alias
};
Expand Down
1 change: 1 addition & 0 deletions packages/package/src/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export interface Options {
files?: {
lib?: string;
};
outDir?: string;
};
preprocess?: PreprocessorGroup;
};
Expand Down

0 comments on commit fae09a7

Please sign in to comment.