Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: delay emptying dist folder in svelte-package #10514

Merged
merged 3 commits into from
Aug 10, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/red-dots-notice.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sveltejs/package': patch
---

Delay empty dist folder in `svelte-package`
kwangure marked this conversation as resolved.
Show resolved Hide resolved
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);
ghostdevv marked this conversation as resolved.
Show resolved Hide resolved
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