Skip to content

Delay emptying of dist folder in package #10507

@kwangure

Description

@kwangure

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions