@vigla/sveltekit 0.0.0-stage → 3.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (149) hide show
  1. package/dist/adapter.d.ts +4 -0
  2. package/dist/adapter.d.ts.map +1 -0
  3. package/dist/adapter.js +5 -0
  4. package/dist/adapter.js.map +1 -0
  5. package/dist/bin.d.ts +3 -0
  6. package/dist/bin.d.ts.map +1 -0
  7. package/dist/bin.js +7 -0
  8. package/dist/bin.js.map +1 -0
  9. package/dist/env.d.ts +2 -0
  10. package/dist/env.d.ts.map +1 -0
  11. package/dist/env.js +2 -0
  12. package/dist/env.js.map +1 -0
  13. package/dist/history/adapter.d.ts +3 -0
  14. package/dist/history/adapter.d.ts.map +1 -0
  15. package/dist/history/adapter.js +31 -0
  16. package/dist/history/adapter.js.map +1 -0
  17. package/dist/history/app/forms.d.ts +4 -0
  18. package/dist/history/app/forms.d.ts.map +1 -0
  19. package/dist/history/app/forms.js +24 -0
  20. package/dist/history/app/forms.js.map +1 -0
  21. package/dist/history/app/hooks.d.ts +8 -0
  22. package/dist/history/app/hooks.d.ts.map +1 -0
  23. package/dist/history/app/hooks.js +27 -0
  24. package/dist/history/app/hooks.js.map +1 -0
  25. package/dist/history/app/navigation.d.ts +10 -0
  26. package/dist/history/app/navigation.d.ts.map +1 -0
  27. package/dist/history/app/navigation.js +41 -0
  28. package/dist/history/app/navigation.js.map +1 -0
  29. package/dist/history/app/navigation.server.d.ts +4 -0
  30. package/dist/history/app/navigation.server.d.ts.map +1 -0
  31. package/dist/history/app/navigation.server.js +9 -0
  32. package/dist/history/app/navigation.server.js.map +1 -0
  33. package/dist/history/app/paths.d.ts +4 -0
  34. package/dist/history/app/paths.d.ts.map +1 -0
  35. package/dist/history/app/paths.js +13 -0
  36. package/dist/history/app/paths.js.map +1 -0
  37. package/dist/history/components.d.ts +3 -0
  38. package/dist/history/components.d.ts.map +1 -0
  39. package/dist/history/components.js +90 -0
  40. package/dist/history/components.js.map +1 -0
  41. package/dist/history/config.d.ts +2 -0
  42. package/dist/history/config.d.ts.map +1 -0
  43. package/dist/history/config.js +80 -0
  44. package/dist/history/config.js.map +1 -0
  45. package/dist/history/diagnostics.d.ts +5 -0
  46. package/dist/history/diagnostics.d.ts.map +1 -0
  47. package/dist/history/diagnostics.js +17 -0
  48. package/dist/history/diagnostics.js.map +1 -0
  49. package/dist/history/plugin.d.ts +7 -0
  50. package/dist/history/plugin.d.ts.map +1 -0
  51. package/dist/history/plugin.js +127 -0
  52. package/dist/history/plugin.js.map +1 -0
  53. package/dist/hooks.d.ts +5 -0
  54. package/dist/hooks.d.ts.map +1 -0
  55. package/dist/hooks.js +9 -0
  56. package/dist/hooks.js.map +1 -0
  57. package/dist/identity.d.ts +3 -0
  58. package/dist/identity.d.ts.map +1 -0
  59. package/dist/identity.js +28 -0
  60. package/dist/identity.js.map +1 -0
  61. package/dist/index.d.ts +8 -0
  62. package/dist/index.d.ts.map +1 -0
  63. package/dist/index.js +18 -0
  64. package/dist/index.js.map +1 -0
  65. package/dist/internal/client.d.ts +2 -0
  66. package/dist/internal/client.d.ts.map +1 -0
  67. package/dist/internal/client.js +2 -0
  68. package/dist/internal/client.js.map +1 -0
  69. package/dist/internal/env.d.ts +2 -0
  70. package/dist/internal/env.d.ts.map +1 -0
  71. package/dist/internal/env.js +2 -0
  72. package/dist/internal/env.js.map +1 -0
  73. package/dist/internal/payload.d.ts +2 -0
  74. package/dist/internal/payload.d.ts.map +1 -0
  75. package/dist/internal/payload.js +2 -0
  76. package/dist/internal/payload.js.map +1 -0
  77. package/dist/internal/restore.d.ts +3 -0
  78. package/dist/internal/restore.d.ts.map +1 -0
  79. package/dist/internal/restore.js +45 -0
  80. package/dist/internal/restore.js.map +1 -0
  81. package/dist/internal/server.d.ts +2 -0
  82. package/dist/internal/server.d.ts.map +1 -0
  83. package/dist/internal/server.js +2 -0
  84. package/dist/internal/server.js.map +1 -0
  85. package/dist/node.d.ts +2 -0
  86. package/dist/node.d.ts.map +1 -0
  87. package/dist/node.js +2 -0
  88. package/dist/node.js.map +1 -0
  89. package/dist/params.d.ts +4 -0
  90. package/dist/params.d.ts.map +1 -0
  91. package/dist/params.js +5 -0
  92. package/dist/params.js.map +1 -0
  93. package/dist/types/adapter.d.ts +2 -0
  94. package/dist/types/adapter.d.ts.map +1 -0
  95. package/dist/types/adapter.js +2 -0
  96. package/dist/types/adapter.js.map +1 -0
  97. package/dist/types/hooks.d.ts +3 -0
  98. package/dist/types/hooks.d.ts.map +1 -0
  99. package/dist/types/hooks.js +2 -0
  100. package/dist/types/hooks.js.map +1 -0
  101. package/dist/types/index.d.ts +28 -0
  102. package/dist/types/index.d.ts.map +1 -0
  103. package/dist/types/index.js +2 -0
  104. package/dist/types/index.js.map +1 -0
  105. package/dist/types/params.d.ts +2 -0
  106. package/dist/types/params.d.ts.map +1 -0
  107. package/dist/types/params.js +2 -0
  108. package/dist/types/params.js.map +1 -0
  109. package/dist/vite.d.ts +8 -0
  110. package/dist/vite.d.ts.map +1 -0
  111. package/dist/vite.js +20 -0
  112. package/dist/vite.js.map +1 -0
  113. package/dist/vite.test-d.d.ts +4 -0
  114. package/dist/vite.test-d.d.ts.map +1 -0
  115. package/dist/vite.test-d.js +9 -0
  116. package/dist/vite.test-d.js.map +1 -0
  117. package/package.json +52 -5
  118. package/src/adapter.ts +7 -0
  119. package/src/bin.ts +7 -0
  120. package/src/env.ts +1 -0
  121. package/src/history/adapter.ts +44 -0
  122. package/src/history/app/forms.ts +42 -0
  123. package/src/history/app/hooks.ts +45 -0
  124. package/src/history/app/navigation.server.ts +11 -0
  125. package/src/history/app/navigation.ts +65 -0
  126. package/src/history/app/paths.ts +17 -0
  127. package/src/history/components.ts +96 -0
  128. package/src/history/config.ts +126 -0
  129. package/src/history/diagnostics.ts +24 -0
  130. package/src/history/plugin.ts +151 -0
  131. package/src/hooks.ts +16 -0
  132. package/src/identity.ts +30 -0
  133. package/src/index.ts +39 -0
  134. package/src/internal/client.ts +1 -0
  135. package/src/internal/env.ts +1 -0
  136. package/src/internal/payload.ts +1 -0
  137. package/src/internal/restore.ts +57 -0
  138. package/src/internal/server.ts +1 -0
  139. package/src/node.ts +1 -0
  140. package/src/params.ts +7 -0
  141. package/src/types/adapter.ts +1 -0
  142. package/src/types/hooks.ts +3 -0
  143. package/src/types/index.ts +29 -0
  144. package/src/types/params.ts +1 -0
  145. package/src/vite.test-d.ts +11 -0
  146. package/src/vite.ts +31 -0
  147. package/types/history.d.ts +14 -0
  148. package/types/index.d.ts +1 -0
  149. package/README.md +0 -3
package/package.json CHANGED
@@ -1,6 +1,53 @@
1
1
  {
2
- "name": "@vigla/sveltekit",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
2
+ "name": "@vigla/sveltekit",
3
+ "version": "3.1.1",
4
+ "type": "module",
5
+ "types": "./types/index.d.ts",
6
+ "files": [
7
+ "dist",
8
+ "src",
9
+ "types"
10
+ ],
11
+ "bin": {
12
+ "svelte-kit": "./dist/bin.js"
13
+ },
14
+ "vigla": {
15
+ "facade": "@vigla/kit"
16
+ },
17
+ "exports": {
18
+ "./package.json": "./package.json",
19
+ ".": {
20
+ "types": "./dist/types/index.d.ts",
21
+ "default": "./dist/index.js"
22
+ },
23
+ "./internal/env": "./dist/internal/env.js",
24
+ "./internal/server": "./dist/internal/server.js",
25
+ "./internal/client": "./dist/internal/client.js",
26
+ "./internal/payload": "./dist/internal/payload.js",
27
+ "./internal/restore": "./dist/internal/restore.js",
28
+ "./adapter": {
29
+ "types": "./dist/types/adapter.d.ts",
30
+ "default": "./dist/adapter.js"
31
+ },
32
+ "./node": "./dist/node.js",
33
+ "./hooks": {
34
+ "types": "./dist/types/hooks.d.ts",
35
+ "default": "./dist/hooks.js"
36
+ },
37
+ "./env": "./dist/env.js",
38
+ "./params": {
39
+ "types": "./dist/types/params.d.ts",
40
+ "default": "./dist/params.js"
41
+ },
42
+ "./vite": "./dist/vite.js"
43
+ },
44
+ "dependencies": {
45
+ "@vigla/kit": "0.1.1",
46
+ "@vigla/vite-plugin-svelte": "7.3.2",
47
+ "esm-env": "^1.2.2"
48
+ },
49
+ "peerDependencies": {
50
+ "svelte": "^5.57.1",
51
+ "vite": "^8.0.12"
52
+ }
53
+ }
package/src/adapter.ts ADDED
@@ -0,0 +1,7 @@
1
+ import type { applyReroute as kitApplyReroute } from '@vigla/kit/adapter';
2
+ import { rerouter } from '@vigla/kit/internal/identity';
3
+ import { identity } from './identity.ts';
4
+
5
+ export * from '@vigla/kit/adapter';
6
+
7
+ export const applyReroute: typeof kitApplyReroute = rerouter(identity);
package/src/bin.ts ADDED
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env node
2
+ import { readFileSync } from 'node:fs';
3
+ import { cli } from '@vigla/kit/cli';
4
+ import { identity } from './identity.ts';
5
+
6
+ const { version } = JSON.parse(readFileSync(new URL('../package.json', import.meta.url), 'utf8'));
7
+ await cli(process.argv.slice(2), version, identity);
package/src/env.ts ADDED
@@ -0,0 +1 @@
1
+ export * from '@vigla/kit/env';
@@ -0,0 +1,44 @@
1
+ import type { Adapter, Builder } from '@vigla/kit';
2
+ import { throwDiagnostic, warnDiagnostic } from './diagnostics.ts';
3
+
4
+ function generateManifest(): never {
5
+ throwDiagnostic(
6
+ 'adapter_generate_manifest_removed',
7
+ 'The `generateManifest` adapter API has been removed — use `generateServerInstance` or `builder.manifest` instead. You may need to update your adapter',
8
+ generateManifest
9
+ );
10
+ }
11
+
12
+ function configWithKit(config: Builder['config']): Builder['config'] {
13
+ let warned = false;
14
+ return Object.create(config, {
15
+ kit: {
16
+ get() {
17
+ if (!warned) {
18
+ warned = true;
19
+ warnDiagnostic(
20
+ 'adapter_config_kit_deprecated',
21
+ 'Reading `config.kit` inside adapters is deprecated — it should access configuration on the `config` object directly. You may need to update your adapter'
22
+ );
23
+ }
24
+ return config;
25
+ }
26
+ }
27
+ });
28
+ }
29
+
30
+ export function retiredBuilder(adapter: Adapter | undefined): Adapter | undefined {
31
+ if (typeof adapter?.adapt !== 'function') return adapter;
32
+ const { adapt } = adapter;
33
+ return {
34
+ ...adapter,
35
+ adapt: (builder: Builder) =>
36
+ adapt.call(
37
+ adapter,
38
+ Object.create(builder, {
39
+ generateManifest: { value: generateManifest },
40
+ config: { value: configWithKit(builder.config) }
41
+ })
42
+ )
43
+ };
44
+ }
@@ -0,0 +1,42 @@
1
+ import { DEV } from 'esm-env';
2
+ import { enhance as enhanceForm, type FormUpdateOptions, type SubmitFunction } from '$app/forms';
3
+ import { warnDiagnostic } from '../diagnostics.ts';
4
+
5
+ export * from '$app/forms';
6
+
7
+ interface Submission {
8
+ update(options?: FormUpdateOptions): Promise<void>;
9
+ }
10
+
11
+ type Callback = (submission: Submission) => unknown;
12
+
13
+ function current(options?: FormUpdateOptions): FormUpdateOptions | undefined {
14
+ if (options?.invalidateAll === undefined) return options;
15
+ if (DEV)
16
+ warnDiagnostic(
17
+ 'enhance_invalidate_all_deprecated',
18
+ 'The `update({ invalidateAll })` option has been deprecated in favour of `update({ refreshAll })`'
19
+ );
20
+ const { invalidateAll, ...rest } = options;
21
+ return { ...rest, refreshAll: rest.refreshAll ?? invalidateAll };
22
+ }
23
+
24
+ function wrap(callback: unknown): unknown {
25
+ if (typeof callback !== 'function') return callback;
26
+ return (submission: Submission) =>
27
+ (callback as Callback)({
28
+ ...submission,
29
+ update: (options) => submission.update(current(options))
30
+ });
31
+ }
32
+
33
+ export function enhance<
34
+ Success extends Record<string, unknown> | undefined,
35
+ Failure extends Record<string, unknown> | undefined
36
+ >(
37
+ form: HTMLFormElement,
38
+ submit: SubmitFunction<Success, Failure> = () => {}
39
+ ): ReturnType<typeof enhanceForm> {
40
+ return enhanceForm<Success, Failure>(form, (async (input) =>
41
+ wrap(await submit(input))) as SubmitFunction<Success, Failure>);
42
+ }
@@ -0,0 +1,45 @@
1
+ import { DEV } from 'esm-env';
2
+ import { warnDiagnostic } from '../diagnostics.ts';
3
+
4
+ interface ErrorInput {
5
+ kind: string;
6
+ error: unknown;
7
+ }
8
+
9
+ interface Fallback {
10
+ status: number;
11
+ message: string;
12
+ }
13
+
14
+ type HandleError = (input: ErrorInput) => unknown;
15
+
16
+ export function retiredProperties(handle: HandleError | undefined): HandleError | undefined {
17
+ if (!DEV || !handle) return handle;
18
+ return (input) => {
19
+ const fallback: Fallback =
20
+ input.kind === 'unknown'
21
+ ? { status: 500, message: 'Internal Error' }
22
+ : (input.error as Fallback);
23
+ Object.defineProperties(input, {
24
+ status: {
25
+ get() {
26
+ warnDiagnostic(
27
+ 'handle_error_status_deprecated',
28
+ 'The `status` property of `handleError` is deprecated. Use `error.status` for expected and framework errors, or `500` for unexpected errors.'
29
+ );
30
+ return fallback.status;
31
+ }
32
+ },
33
+ message: {
34
+ get() {
35
+ warnDiagnostic(
36
+ 'handle_error_message_deprecated',
37
+ "The `message` property of `handleError` is deprecated. Use `error.message` for expected and framework errors, or `'Internal Error'` for unexpected errors."
38
+ );
39
+ return fallback.message;
40
+ }
41
+ }
42
+ });
43
+ return handle(input);
44
+ };
45
+ }
@@ -0,0 +1,11 @@
1
+ import { shallow } from '@vigla/kit/internal/shallow';
2
+
3
+ export * from '$app/navigation';
4
+
5
+ export function pushState(url: string | URL, state: App.PageState): never {
6
+ return shallow('pushState', url, state);
7
+ }
8
+
9
+ export function replaceState(url: string | URL, state: App.PageState): never {
10
+ return shallow('replaceState', url, state);
11
+ }
@@ -0,0 +1,65 @@
1
+ import { DEV } from 'esm-env';
2
+ import { goto as navigate, type GotoOptions } from '$app/navigation';
3
+ import { shallow } from '@vigla/kit/internal/shallow';
4
+ import { throwDiagnostic, warnDiagnostic } from '../diagnostics.ts';
5
+
6
+ export * from '$app/navigation';
7
+
8
+ interface RetiredGotoOptions extends GotoOptions {
9
+ noScroll?: boolean;
10
+ keepFocus?: boolean;
11
+ }
12
+
13
+ const warned = new Set<string>();
14
+
15
+ function warnOnce(code: string, text: string): void {
16
+ if (warned.has(code)) return;
17
+ warned.add(code);
18
+ warnDiagnostic(code, text);
19
+ }
20
+
21
+ export async function goto(url: string | URL, options: RetiredGotoOptions = {}): Promise<void> {
22
+ const { replaceState, invalidateAll, noScroll, keepFocus, ...current } = options;
23
+ if (DEV) {
24
+ if ('replaceState' in options)
25
+ warnOnce(
26
+ 'goto_replace_state_deprecated',
27
+ `The \`goto(..., { replaceState: ${String(replaceState)} })\` option has been deprecated in favour of \`replace\``
28
+ );
29
+ if ('noScroll' in options || 'keepFocus' in options)
30
+ throwDiagnostic(
31
+ 'goto_options_removed',
32
+ 'The `goto(..., { noScroll: true, keepFocus: true })` options have been replaced by `reset: false`',
33
+ goto
34
+ );
35
+ }
36
+ const navigation = navigate(url, {
37
+ ...current,
38
+ replace: current.replace ?? replaceState,
39
+ refreshAll: current.refreshAll ?? invalidateAll
40
+ });
41
+ if (!DEV || !('invalidateAll' in options) || current.shallow) return navigation;
42
+ await navigation;
43
+ warnOnce(
44
+ 'goto_invalidate_all_deprecated',
45
+ `The \`goto(..., { invalidateAll: ${String(invalidateAll)} })\` option has been deprecated in favour of \`refreshAll\``
46
+ );
47
+ }
48
+
49
+ export async function pushState(url: string | URL, state: App.PageState): Promise<void> {
50
+ if (DEV)
51
+ warnOnce(
52
+ 'push_state_deprecated',
53
+ '`pushState(...)` is deprecated. Use `goto(url, { state, shallow: true })` instead.'
54
+ );
55
+ return shallow('pushState', url, state);
56
+ }
57
+
58
+ export async function replaceState(url: string | URL, state: App.PageState): Promise<void> {
59
+ if (DEV)
60
+ warnOnce(
61
+ 'replace_state_deprecated',
62
+ '`replaceState(...)` is deprecated. Use `goto(url, { state, shallow: true, replace: true })` instead.'
63
+ );
64
+ return shallow('replaceState', url, state);
65
+ }
@@ -0,0 +1,17 @@
1
+ import { DEV } from 'esm-env';
2
+ import { asset as resolveAsset } from '$app/paths';
3
+ import type { AssetPath } from '$app/types';
4
+ import { warnDiagnostic } from '../diagnostics.ts';
5
+
6
+ export * from '$app/paths';
7
+
8
+ export function asset(file: AssetPath): string {
9
+ if (!file.startsWith('/')) return resolveAsset(file);
10
+ const fixed = file.slice(1) as AssetPath;
11
+ if (DEV)
12
+ warnDiagnostic(
13
+ 'asset_leading_slash',
14
+ `\`asset('${file}')\` should now be \`asset('${fixed}')\``
15
+ );
16
+ return resolveAsset(fixed);
17
+ }
@@ -0,0 +1,96 @@
1
+ import path from 'node:path';
2
+ import type { Plugin } from 'vite';
3
+ import { identity } from '../identity.ts';
4
+ import { warnDiagnostic } from './diagnostics.ts';
5
+
6
+ type Mode = 'code' | 'single' | 'double' | 'template' | 'line' | 'block' | 'html';
7
+
8
+ const quotes: Partial<Record<Mode, string>> = { single: "'", double: '"', template: '`' };
9
+ const pageOption = /(export\s+const\s+(prerender|csr|ssr|trailingSlash))\s*=/s;
10
+ const scripts = /<script\b[^>]*>([\s\S]*?)<\/script>/g;
11
+ const warned = new Set<string>();
12
+ const docs = 'https://svelte.dev/docs/kit/';
13
+
14
+ function insideStringOrComment(source: string, end: number): boolean {
15
+ let mode: Mode = 'code';
16
+ for (let index = 0; index < end; index++) {
17
+ const char = source[index]!;
18
+ const pair = source.slice(index, index + 2);
19
+ if (mode === 'line') {
20
+ if (char === '\n') mode = 'code';
21
+ } else if (mode === 'block') {
22
+ if (pair === '*/') {
23
+ mode = 'code';
24
+ index++;
25
+ }
26
+ } else if (mode === 'html') {
27
+ if (source.startsWith('-->', index)) {
28
+ mode = 'code';
29
+ index += 2;
30
+ }
31
+ } else if (mode !== 'code') {
32
+ if (char === '\\') index++;
33
+ else if (char === quotes[mode]) mode = 'code';
34
+ } else if (char === "'") mode = 'single';
35
+ else if (char === '"') mode = 'double';
36
+ else if (char === '`') mode = 'template';
37
+ else if (pair === '//') {
38
+ mode = 'line';
39
+ index++;
40
+ } else if (pair === '/*') {
41
+ mode = 'block';
42
+ index++;
43
+ } else if (source.startsWith('<!--', index)) {
44
+ mode = 'html';
45
+ index += 3;
46
+ }
47
+ }
48
+ return mode !== 'code';
49
+ }
50
+
51
+ function hasChildren(source: string): boolean {
52
+ return (
53
+ source.includes('<slot') ||
54
+ source.includes('{@render') ||
55
+ source.includes('{children}') ||
56
+ source.includes('children={')
57
+ );
58
+ }
59
+
60
+ function once(key: string, warn: () => void): void {
61
+ if (warned.has(key)) return;
62
+ warned.add(key);
63
+ warn();
64
+ }
65
+
66
+ export function componentWarnings(): Plugin {
67
+ return {
68
+ name: `${identity.name}:history-components`,
69
+ transform: {
70
+ filter: { id: /[/\\]\+(?:page|layout)[^/\\]*\.svelte$/ },
71
+ handler(code, id) {
72
+ const name = path.basename(id.split('?')[0]!);
73
+ const file = path.relative(process.cwd(), id.split('?')[0]!);
74
+ for (const script of code.matchAll(scripts)) {
75
+ const content = script[1]!;
76
+ const match = pageOption.exec(content);
77
+ if (match && !insideStringOrComment(content, match.index))
78
+ once(`page_option_in_component:${file}:${match[1]}`, () =>
79
+ warnDiagnostic(
80
+ 'page_option_in_component',
81
+ `\`${file}\`: \`${match[1]}\` will be ignored — move it to \`${name.replace('.svelte', '(.server).js/ts')}\` instead. See ${docs}page-options for more information.`
82
+ )
83
+ );
84
+ }
85
+ if (name.startsWith('+layout.') && !hasChildren(code))
86
+ once(`layout_children_missing:${file}`, () =>
87
+ warnDiagnostic(
88
+ 'layout_children_missing',
89
+ `\`${file}\`: \`<slot />\` or \`{@render ...}\` tag missing — inner content will not be rendered`
90
+ )
91
+ );
92
+ return null;
93
+ }
94
+ }
95
+ };
96
+ }
@@ -0,0 +1,126 @@
1
+ import { identity } from '../identity.ts';
2
+ import { throwDiagnostic, warnDiagnostic } from './diagnostics.ts';
3
+
4
+ type Step = [path: string, check: (keypath: string, value: unknown) => void];
5
+
6
+ const docs = 'https://svelte.dev/docs/kit/';
7
+
8
+ function removed(code: string, text: (keypath: string) => string): Step[1] {
9
+ return (keypath) => throwDiagnostic(code, text(keypath), removed);
10
+ }
11
+
12
+ const generic = removed(
13
+ 'config_option_removed',
14
+ (keypath) =>
15
+ `The \`${keypath}\` option has been removed. Please see the list of breaking changes for your major release`
16
+ );
17
+
18
+ const steps: Step[] = [
19
+ [
20
+ 'alias',
21
+ (keypath) =>
22
+ warnDiagnostic(
23
+ 'config_option_deprecated_alias',
24
+ `The \`${keypath}\` option is deprecated, and will be removed in a future version of ${identity.product}. Use subpath imports instead: ${docs}$lib`
25
+ )
26
+ ],
27
+ [
28
+ 'csrf.checkOrigin',
29
+ removed(
30
+ 'config_option_removed_check_origin',
31
+ (keypath) => `\`${keypath}\` has been removed in favour of \`csrf.trustedOrigins\``
32
+ )
33
+ ],
34
+ [
35
+ 'experimental.tracing',
36
+ removed(
37
+ 'config_option_removed_experimental_tracing',
38
+ (keypath) =>
39
+ `\`${keypath}\` has been removed. Server-side tracing is now configured via \`tracing.server\``
40
+ )
41
+ ],
42
+ [
43
+ 'experimental.instrumentation',
44
+ removed(
45
+ 'config_option_removed_experimental_instrumentation',
46
+ (keypath) =>
47
+ `\`${keypath}\` has been removed. \`src/instrumentation.server.js\` is now included in the build automatically when it exists; no opt-in is required`
48
+ )
49
+ ],
50
+ ['experimental.handleRenderingErrors', generic],
51
+ [
52
+ 'files.lib',
53
+ removed(
54
+ 'config_option_removed_files_lib',
55
+ (keypath) => `\`${keypath}\` has been removed. Use \`#lib\` instead of \`$lib\`: ${docs}$lib`
56
+ )
57
+ ],
58
+ [
59
+ 'kit',
60
+ (_, value) =>
61
+ throwDiagnostic(
62
+ 'config_kit_namespace',
63
+ `${identity.product} configuration (${Object.keys(value as object)
64
+ .map((key) => `\`${key}\``)
65
+ .join(
66
+ ', '
67
+ )}) no longer lives inside a \`kit\` namespace. Pass it directly to the \`${identity.plugin}(...)\` Vite plugin`,
68
+ checkConfig
69
+ )
70
+ ],
71
+ [
72
+ 'output.preloadStrategy',
73
+ removed(
74
+ 'config_option_removed_preload_strategy',
75
+ (keypath) => `\`${keypath}\` has been removed. \`modulepreload\` will always be used`
76
+ )
77
+ ],
78
+ [
79
+ 'prerender.origin',
80
+ removed(
81
+ 'config_option_removed_prerender_origin',
82
+ (keypath) => `\`${keypath}\` has been removed in favour of \`config.paths.origin\``
83
+ )
84
+ ],
85
+ ['serviceWorker.files', generic],
86
+ [
87
+ 'typescript',
88
+ (keypath) =>
89
+ warnDiagnostic(
90
+ 'config_option_deprecated_typescript',
91
+ `The \`${keypath}\` option is deprecated, and will be removed in a future version. Add configuration to \`tsconfig.json\` directly`
92
+ )
93
+ ],
94
+ [
95
+ 'vitePlugin',
96
+ removed(
97
+ 'config_option_removed_vite_plugin',
98
+ (keypath) =>
99
+ `\`${keypath}\` has been removed. Pass plugin options directly to the \`${identity.plugin}(...)\` Vite plugin`
100
+ )
101
+ ]
102
+ ];
103
+
104
+ function read(config: object, path: string): unknown {
105
+ let value: unknown = config;
106
+ for (const key of path.split('.')) {
107
+ if (!value || typeof value !== 'object') return undefined;
108
+ value = (value as Record<string, unknown>)[key];
109
+ }
110
+ return value;
111
+ }
112
+
113
+ export function checkConfig(config: unknown): void {
114
+ if (!config || typeof config !== 'object' || Array.isArray(config)) return;
115
+ try {
116
+ for (const [path, check] of steps) {
117
+ const value = read(config, path);
118
+ if (value !== undefined) check(`config.${path}`, value);
119
+ }
120
+ } catch (error) {
121
+ console.log(`\n${error instanceof Error ? error.message : String(error)}\n`);
122
+ const failure = new Error(`Failed to load ${identity.product} options from Vite config`);
123
+ failure.stack = '';
124
+ throw failure;
125
+ }
126
+ }
@@ -0,0 +1,24 @@
1
+ import { identity } from '../identity.ts';
2
+
3
+ export function diagnosticText(code: string, text: string): string {
4
+ return `${code}\n${text}\n${identity.diagnostics}${code}`;
5
+ }
6
+
7
+ export function throwDiagnostic(code: string, text: string, caller: Function): never {
8
+ const error = new Error(diagnosticText(code, text));
9
+ error.name = `${identity.product} error`;
10
+ Error.captureStackTrace?.(error, caller);
11
+ throw error;
12
+ }
13
+
14
+ export function warningSource(code: string, text: string): string {
15
+ return `console.warn(${JSON.stringify(`%c[${identity.name}] ${diagnosticText(code, text).replace('\n', '\n%c')}`)}, 'font-weight: bold', 'font-weight: normal');`;
16
+ }
17
+
18
+ export function warnDiagnostic(code: string, text: string): void {
19
+ console.warn(
20
+ `%c[${identity.name}] ${code}\n%c${text}\n${identity.diagnostics}${code}`,
21
+ 'font-weight: bold',
22
+ 'font-weight: normal'
23
+ );
24
+ }