Skip to content

Commit b48c714

Browse files
authored
chore: deprecate config.kit.files options (#14152)
* feat: add a `kit.files.src` option * fix ts support check * update comment * regenerate * deprecate config.kit.files * regenerate
1 parent 367c896 commit b48c714

File tree

11 files changed

+117
-20
lines changed

11 files changed

+117
-20
lines changed

.changeset/brave-clowns-behave.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@sveltejs/kit': minor
3+
---
4+
5+
feat: add a `kit.files.src` option

.changeset/social-hounds-jam.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@sveltejs/kit': patch
3+
---
4+
5+
chore: deprecate `config.kit.files` options
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
export default {
2+
kit: {
3+
files: {
4+
src: 'source'
5+
}
6+
}
7+
};

packages/kit/src/core/config/index.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,17 @@ export function validate_config(config) {
126126
}
127127

128128
const validated = options(config, 'config');
129+
const files = validated.kit.files;
130+
131+
files.hooks.client ??= path.join(files.src, 'hooks.client');
132+
files.hooks.server ??= path.join(files.src, 'hooks.server');
133+
files.hooks.universal ??= path.join(files.src, 'hooks');
134+
files.lib ??= path.join(files.src, 'lib');
135+
files.params ??= path.join(files.src, 'params');
136+
files.routes ??= path.join(files.src, 'routes');
137+
files.serviceWorker ??= path.join(files.src, 'service-worker');
138+
files.appTemplate ??= path.join(files.src, 'app.html');
139+
files.errorTemplate ??= path.join(files.src, 'error.html');
129140

130141
if (validated.kit.router.resolution === 'server') {
131142
if (validated.kit.router.type === 'hash') {

packages/kit/src/core/config/index.spec.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ const get_defaults = (prefix = '') => ({
8080
remoteFunctions: false
8181
},
8282
files: {
83+
src: join(prefix, 'src'),
8384
assets: join(prefix, 'static'),
8485
hooks: {
8586
client: join(prefix, 'src/hooks.client'),
@@ -407,3 +408,15 @@ test('errors on loading config with incorrect default export', async () => {
407408
'The Svelte config file must have a configuration object as its default export. See https://svelte.dev/docs/kit/configuration'
408409
);
409410
});
411+
412+
test('uses src prefix for other kit.files options', async () => {
413+
const cwd = join(__dirname, 'fixtures/custom-src');
414+
415+
const config = await load_config({ cwd });
416+
remove_keys(config, ([, v]) => typeof v === 'function');
417+
418+
const defaults = get_defaults(cwd + '/');
419+
defaults.kit.version.name = config.kit.version.name;
420+
421+
expect(config.kit.files.lib).toEqual(join(cwd, 'source/lib'));
422+
});

packages/kit/src/core/config/options.js

Lines changed: 30 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { join } from 'node:path';
21
import process from 'node:process';
32

43
/** @typedef {import('./types.js').Validator} Validator */
@@ -125,18 +124,19 @@ const options = object(
125124
}),
126125

127126
files: object({
128-
assets: string('static'),
127+
src: deprecate(string('src')),
128+
assets: deprecate(string('static')),
129129
hooks: object({
130-
client: string(join('src', 'hooks.client')),
131-
server: string(join('src', 'hooks.server')),
132-
universal: string(join('src', 'hooks'))
130+
client: deprecate(string(null)),
131+
server: deprecate(string(null)),
132+
universal: deprecate(string(null))
133133
}),
134-
lib: string(join('src', 'lib')),
135-
params: string(join('src', 'params')),
136-
routes: string(join('src', 'routes')),
137-
serviceWorker: string(join('src', 'service-worker')),
138-
appTemplate: string(join('src', 'app.html')),
139-
errorTemplate: string(join('src', 'error.html'))
134+
lib: deprecate(string(null)),
135+
params: deprecate(string(null)),
136+
routes: deprecate(string(null)),
137+
serviceWorker: deprecate(string(null)),
138+
appTemplate: deprecate(string(null)),
139+
errorTemplate: deprecate(string(null))
140140
}),
141141

142142
inlineStyleThreshold: number(0),
@@ -287,6 +287,25 @@ const options = object(
287287
true
288288
);
289289

290+
/**
291+
* @param {Validator} fn
292+
* @param {(keypath: string) => string} get_message
293+
* @returns {Validator}
294+
*/
295+
function deprecate(
296+
fn,
297+
get_message = (keypath) =>
298+
`The \`${keypath}\` option is deprecated, and will be removed in a future version`
299+
) {
300+
return (input, keypath) => {
301+
if (input !== undefined) {
302+
console.warn(get_message(keypath));
303+
}
304+
305+
return fn(input, keypath);
306+
};
307+
}
308+
290309
/**
291310
* @param {Record<string, Validator>} children
292311
* @param {boolean} [allow_unknown]

packages/kit/src/core/sync/create_manifest_data/index.spec.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ import path from 'node:path';
33
import { fileURLToPath } from 'node:url';
44
import { assert, expect, test } from 'vitest';
55
import create_manifest_data from './index.js';
6-
import options from '../../config/options.js';
76
import { sort_routes } from './sort.js';
7+
import { validate_config } from '../../config/index.js';
88

99
const cwd = fileURLToPath(new URL('./test', import.meta.url));
1010

@@ -13,7 +13,7 @@ const cwd = fileURLToPath(new URL('./test', import.meta.url));
1313
* @param {import('@sveltejs/kit').Config} config
1414
*/
1515
const create = (dir, config = {}) => {
16-
const initial = options(config, 'config');
16+
const initial = validate_config(config);
1717

1818
initial.kit.files.assets = path.resolve(cwd, 'static');
1919
initial.kit.files.params = path.resolve(cwd, 'params');

packages/kit/src/core/sync/write_types/index.spec.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ import path from 'node:path';
44
import { fileURLToPath } from 'node:url';
55
import { assert, expect, test } from 'vitest';
66
import { rimraf } from '../../../utils/filesystem.js';
7-
import options from '../../config/options.js';
87
import create_manifest_data from '../create_manifest_data/index.js';
98
import { tweak_types, write_all_types } from './index.js';
9+
import { validate_config } from '../../config/index.js';
1010

1111
const cwd = fileURLToPath(new URL('./test', import.meta.url));
1212

@@ -16,7 +16,7 @@ const cwd = fileURLToPath(new URL('./test', import.meta.url));
1616
function run_test(dir) {
1717
rimraf(path.join(cwd, dir, '.svelte-kit'));
1818

19-
const initial = options({}, 'config');
19+
const initial = validate_config({});
2020

2121
initial.kit.files.assets = path.resolve(cwd, 'static');
2222
initial.kit.files.params = path.resolve(cwd, dir, 'params');

packages/kit/src/exports/public.d.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -420,58 +420,76 @@ export interface KitConfig {
420420
};
421421
/**
422422
* Where to find various files within your project.
423+
* @deprecated
423424
*/
424425
files?: {
426+
/**
427+
* the location of your source code
428+
* @deprecated
429+
* @default "src"
430+
* @since 2.28
431+
*/
432+
src?: string;
425433
/**
426434
* a place to put static files that should have stable URLs and undergo no processing, such as `favicon.ico` or `manifest.json`
435+
* @deprecated
427436
* @default "static"
428437
*/
429438
assets?: string;
430439
hooks?: {
431440
/**
432441
* The location of your client [hooks](https://svelte.dev/docs/kit/hooks).
442+
* @deprecated
433443
* @default "src/hooks.client"
434444
*/
435445
client?: string;
436446
/**
437447
* The location of your server [hooks](https://svelte.dev/docs/kit/hooks).
448+
* @deprecated
438449
* @default "src/hooks.server"
439450
*/
440451
server?: string;
441452
/**
442453
* The location of your universal [hooks](https://svelte.dev/docs/kit/hooks).
454+
* @deprecated
443455
* @default "src/hooks"
444456
* @since 2.3.0
445457
*/
446458
universal?: string;
447459
};
448460
/**
449461
* your app's internal library, accessible throughout the codebase as `$lib`
462+
* @deprecated
450463
* @default "src/lib"
451464
*/
452465
lib?: string;
453466
/**
454467
* a directory containing [parameter matchers](https://svelte.dev/docs/kit/advanced-routing#Matching)
468+
* @deprecated
455469
* @default "src/params"
456470
*/
457471
params?: string;
458472
/**
459473
* the files that define the structure of your app (see [Routing](https://svelte.dev/docs/kit/routing))
474+
* @deprecated
460475
* @default "src/routes"
461476
*/
462477
routes?: string;
463478
/**
464479
* the location of your service worker's entry point (see [Service workers](https://svelte.dev/docs/kit/service-workers))
480+
* @deprecated
465481
* @default "src/service-worker"
466482
*/
467483
serviceWorker?: string;
468484
/**
469485
* the location of the template for HTML responses
486+
* @deprecated
470487
* @default "src/app.html"
471488
*/
472489
appTemplate?: string;
473490
/**
474491
* the location of the template for fallback error responses
492+
* @deprecated
475493
* @default "src/error.html"
476494
*/
477495
errorTemplate?: string;

packages/kit/types/index.d.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -397,58 +397,76 @@ declare module '@sveltejs/kit' {
397397
};
398398
/**
399399
* Where to find various files within your project.
400+
* @deprecated
400401
*/
401402
files?: {
403+
/**
404+
* the location of your source code
405+
* @deprecated
406+
* @default "src"
407+
* @since 2.28
408+
*/
409+
src?: string;
402410
/**
403411
* a place to put static files that should have stable URLs and undergo no processing, such as `favicon.ico` or `manifest.json`
412+
* @deprecated
404413
* @default "static"
405414
*/
406415
assets?: string;
407416
hooks?: {
408417
/**
409418
* The location of your client [hooks](https://svelte.dev/docs/kit/hooks).
419+
* @deprecated
410420
* @default "src/hooks.client"
411421
*/
412422
client?: string;
413423
/**
414424
* The location of your server [hooks](https://svelte.dev/docs/kit/hooks).
425+
* @deprecated
415426
* @default "src/hooks.server"
416427
*/
417428
server?: string;
418429
/**
419430
* The location of your universal [hooks](https://svelte.dev/docs/kit/hooks).
431+
* @deprecated
420432
* @default "src/hooks"
421433
* @since 2.3.0
422434
*/
423435
universal?: string;
424436
};
425437
/**
426438
* your app's internal library, accessible throughout the codebase as `$lib`
439+
* @deprecated
427440
* @default "src/lib"
428441
*/
429442
lib?: string;
430443
/**
431444
* a directory containing [parameter matchers](https://svelte.dev/docs/kit/advanced-routing#Matching)
445+
* @deprecated
432446
* @default "src/params"
433447
*/
434448
params?: string;
435449
/**
436450
* the files that define the structure of your app (see [Routing](https://svelte.dev/docs/kit/routing))
451+
* @deprecated
437452
* @default "src/routes"
438453
*/
439454
routes?: string;
440455
/**
441456
* the location of your service worker's entry point (see [Service workers](https://svelte.dev/docs/kit/service-workers))
457+
* @deprecated
442458
* @default "src/service-worker"
443459
*/
444460
serviceWorker?: string;
445461
/**
446462
* the location of the template for HTML responses
463+
* @deprecated
447464
* @default "src/app.html"
448465
*/
449466
appTemplate?: string;
450467
/**
451468
* the location of the template for fallback error responses
469+
* @deprecated
452470
* @default "src/error.html"
453471
*/
454472
errorTemplate?: string;

0 commit comments

Comments
 (0)