Skip to content

Commit

Permalink
fix: only generate typing files with sync command (#8552)
Browse files Browse the repository at this point in the history
* fix: only generate typing files with sync command

fixes #8525

* Apply suggestions from code review

Co-authored-by: Ben McCann <322311+benmccann@users.noreply.github.com>

* docs

Co-authored-by: Ben McCann <322311+benmccann@users.noreply.github.com>
  • Loading branch information
dummdidumm and benmccann authored Jan 17, 2023
1 parent a48efda commit 3199e77
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .changeset/neat-geckos-end.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sveltejs/kit': patch
---

fix: only generate type definitions with `sync` command
2 changes: 1 addition & 1 deletion documentation/docs/50-reference/20-cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ However SvelteKit includes its own CLI for initialising your project:

## svelte-kit sync

`svelte-kit sync` creates the generated files for your project such as types and a `tsconfig.json`. When you create a new project, it is listed as the `prepare` script and will be run automatically as part of the npm lifecycle, so you should not ordinarily have to run this command.
`svelte-kit sync` creates the `tsconfig.json` and all generated types (which you can import as `./$types` inside routing files) for your project. When you create a new project, it is listed as the `prepare` script and will be run automatically as part of the npm lifecycle, so you should not ordinarily have to run this command.
4 changes: 2 additions & 2 deletions packages/kit/src/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const prog = sade('svelte-kit').version(pkg.version);

prog
.command('sync')
.describe('Synchronise generated files')
.describe('Synchronise generated type definitions')
.option('--mode', 'Specify a mode for loading environment variables', 'development')
.action(async ({ mode }) => {
if (!fs.existsSync('svelte.config.js')) {
Expand All @@ -35,7 +35,7 @@ prog
try {
const config = await load_config();
const sync = await import('./core/sync/sync.js');
await sync.all(config, mode);
await sync.all_types(config, mode);
} catch (error) {
handle_error(error);
}
Expand Down
13 changes: 12 additions & 1 deletion packages/kit/src/core/sync/sync.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export async function update(config, manifest_data, file) {
}

/**
* Run sync.init and sync.update in series, returning the result from sync.update.
* Run sync.init and sync.create in series, returning the result from sync.create.
* @param {import('types').ValidatedConfig} config
* @param {string} mode The Vite mode
*/
Expand All @@ -60,6 +60,17 @@ export async function all(config, mode) {
return await create(config);
}

/**
* Run sync.init and then generate all type files.
* @param {import('types').ValidatedConfig} config
* @param {string} mode The Vite mode
*/
export async function all_types(config, mode) {
init(config, mode);
const manifest_data = create_manifest_data({ config });
await write_all_types(config, manifest_data);
}

/**
* Regenerate server-internal.js in response to src/{app.html,error.html,service-worker.js} changing
* @param {import('types').ValidatedConfig} config
Expand Down

0 comments on commit 3199e77

Please sign in to comment.