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

Delay emptying of dist folder in package #10507

Closed
kwangure opened this issue Aug 8, 2023 · 2 comments · Fixed by #10514
Closed

Delay emptying of dist folder in package #10507

kwangure opened this issue Aug 8, 2023 · 2 comments · Fixed by #10514
Labels
awaiting submitter p3-edge-case SvelteKit cannot be used in an uncommon way pkg:svelte-package Issues related to svelte-package

Comments

@kwangure
Copy link
Contributor

kwangure commented Aug 8, 2023

Describe the problem

svelte-package currently works as follows 1) Empty dist/ 2) generate Svelte types 3) Emit ts-types. Step 2) and 3) take LOOONG. So if a site-1 depends on package-1, While step 2 and 3 are happening Vite HMR in site-1 sees that there are no files and crashes unrecoverably.

Describe the proposed solution

Change the algorithm to the following:

  1. Empty ./svelte-kit/__package__:
  2. generate Svelte & TS types into ./.svelte-kit folder
  3. Copy output from into ./svelte-kit/__package__ to dist/

https://github.com/sveltejs/kit/blob/master/packages/package/src/index.js#L31

-	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);

It takes slightly longer because of the copying but it doesn't break apps that are depending dist/.

Alternatives considered

The more nuclear option is to avoid svelte-package altogether and generate types using svelte2tsx using a build script. In a monorepo setup you can get away with not pre-processing etc. and do it in the consuming application.

Importance

would make my life easier

Additional Information

No response

@ghostdevv ghostdevv added pkg:svelte-package Issues related to svelte-package p3-edge-case SvelteKit cannot be used in an uncommon way labels Aug 9, 2023
@ghostdevv
Copy link
Member

Hey can you provide a minimal reproduction?

@kwangure
Copy link
Contributor Author

kwangure commented Aug 9, 2023

@ghostdevv ghostdevv changed the title Support svelte-package usage in monorepo Delay emptying of dist folder Aug 9, 2023
@ghostdevv ghostdevv changed the title Delay emptying of dist folder Delay emptying of dist folder in package Aug 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting submitter p3-edge-case SvelteKit cannot be used in an uncommon way pkg:svelte-package Issues related to svelte-package
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants