Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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/empty-path-never.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sveltejs/kit': patch
---

fix: generate a `never` `Path` type when there are no routes
18 changes: 18 additions & 0 deletions packages/kit/src/core/sync/sync.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { load_explicit_env } from '../env.js';
import { relative_path } from '../../utils/filesystem.js';
import { posixify } from '../../utils/os.js';
import { create, update } from './sync.js';
import { write_app_types } from './write_app_types.js';
import create_manifest_data from './create_manifest_data/index.js';

test('generates client manifest imports relative to the project root', () => {
Expand Down Expand Up @@ -38,6 +39,23 @@ test('generates client manifest imports relative to the project root', () => {
}
});

test('generates a `never` Path type when there are no routes', () => {
const root = fs.mkdtempSync(path.join(os.tmpdir(), 'svelte-kit-sync-'));

try {
const config = process_config(validate_config({}), root);
write_app_types(config, create_manifest_data(config, root), root);
const generated = fs.readFileSync(
path.join(root, 'node_modules/$app/types/index.d.ts'),
'utf8'
);

expect(generated).toContain('\t\tPath(): never;');
} finally {
fs.rmSync(root, { recursive: true, force: true });
}
});

test('explains circular imports through $app/env/private', async () => {
const root = path.resolve(import.meta.dirname, '../../../test/apps/basics');
const dir = fs.mkdtempSync(path.join(root, 'node_modules/.svelte-kit-env-'));
Expand Down
2 changes: 1 addition & 1 deletion packages/kit/src/core/sync/write_app_types.js
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ function generate_app_types(manifest_data, config, dir) {
`\t\tRouteId(): ${app_route_ids.join(' | ') || 'never'};`,
`\t\tRouteParams(): {\n\t\t\t${dynamic_routes.join(';\n\t\t\t')}\n\t\t};`,
`\t\tLayoutParams(): {\n\t\t\t${layouts.join(';\n\t\t\t')}\n\t\t};`,
`\t\tPath(): ${Array.from(pathnames).join(' | ')};`,
`\t\tPath(): ${Array.from(pathnames).join(' | ') || 'never'};`,
'\t\tResolvedPathname(): `${"/" | `/${string}/`}${ReturnType<AppTypes[\'Path\']>}`;',
`\t\tAssetPath(): ${assets.join(' | ') || 'never'};`,
'\t}',
Expand Down
Loading