@sveltejs/kit 1.0.0-next.551 → 1.0.0-next.553
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.
- package/package.json +1 -1
- package/src/core/sync/create_manifest_data/index.js +14 -0
- package/src/exports/vite/build/build_server.js +4 -2
- package/src/exports/vite/build/utils.js +0 -1
- package/src/exports/vite/dev/index.js +7 -1
- package/src/exports/vite/index.js +7 -12
- package/src/runtime/app/environment.js +1 -1
- package/src/runtime/client/start.js +4 -1
- package/src/runtime/client/utils.js +4 -3
- package/src/runtime/control.js +1 -1
- package/src/runtime/env.js +6 -0
- package/src/runtime/server/fetch.js +11 -0
- package/src/runtime/server/index.js +1 -1
- package/src/runtime/server/page/render.js +2 -1
- package/types/ambient.d.ts +5 -0
- package/types/index.d.ts +29 -8
- package/types/internal.d.ts +1 -0
package/package.json
CHANGED
|
@@ -195,6 +195,20 @@ function create_routes_and_nodes(cwd, config, fallback) {
|
|
|
195
195
|
if (!file.name.startsWith('+')) continue;
|
|
196
196
|
if (!valid_extensions.find((ext) => file.name.endsWith(ext))) continue;
|
|
197
197
|
|
|
198
|
+
if (file.name.endsWith('.d.ts')) {
|
|
199
|
+
let name = file.name.slice(0, -5);
|
|
200
|
+
const ext = valid_extensions.find((ext) => name.endsWith(ext));
|
|
201
|
+
if (ext) name = name.slice(0, -ext.length);
|
|
202
|
+
|
|
203
|
+
const valid =
|
|
204
|
+
/^\+(?:(page(?:@(.*))?)|(layout(?:@(.*))?)|(error))$/.test(name) ||
|
|
205
|
+
/^\+(?:(server)|(page(?:(@[a-zA-Z0-9_-]*))?(\.server)?)|(layout(?:(@[a-zA-Z0-9_-]*))?(\.server)?))$/.test(
|
|
206
|
+
name
|
|
207
|
+
);
|
|
208
|
+
|
|
209
|
+
if (valid) continue;
|
|
210
|
+
}
|
|
211
|
+
|
|
198
212
|
const project_relative = posixify(path.relative(cwd, path.join(dir, file.name)));
|
|
199
213
|
|
|
200
214
|
const item = analyze(
|
|
@@ -27,7 +27,7 @@ const server_template = ({ config, hooks, has_service_worker, runtime, template,
|
|
|
27
27
|
import root from '__GENERATED__/root.svelte';
|
|
28
28
|
import { respond } from '${runtime}/server/index.js';
|
|
29
29
|
import { set_paths, assets, base } from '${runtime}/paths.js';
|
|
30
|
-
import { set_prerendering } from '${runtime}/env.js';
|
|
30
|
+
import { set_prerendering, set_version } from '${runtime}/env.js';
|
|
31
31
|
import { set_private_env } from '${runtime}/env-private.js';
|
|
32
32
|
import { set_public_env } from '${runtime}/env-public.js';
|
|
33
33
|
|
|
@@ -44,6 +44,7 @@ const error_template = ({ status, message }) => ${s(error_page)
|
|
|
44
44
|
let read = null;
|
|
45
45
|
|
|
46
46
|
set_paths(${s(config.kit.paths)});
|
|
47
|
+
set_version(${s(config.kit.version.name)});
|
|
47
48
|
|
|
48
49
|
let default_protocol = 'https';
|
|
49
50
|
|
|
@@ -86,7 +87,8 @@ export class Server {
|
|
|
86
87
|
app_template,
|
|
87
88
|
app_template_contains_nonce: ${template.includes('%sveltekit.nonce%')},
|
|
88
89
|
error_template,
|
|
89
|
-
trailing_slash: ${s(config.kit.trailingSlash)}
|
|
90
|
+
trailing_slash: ${s(config.kit.trailingSlash)},
|
|
91
|
+
version: ${s(config.kit.version.name)}
|
|
90
92
|
};
|
|
91
93
|
}
|
|
92
94
|
|
|
@@ -147,7 +147,6 @@ export function get_default_build_config({ config, input, ssr, outDir }) {
|
|
|
147
147
|
},
|
|
148
148
|
define: {
|
|
149
149
|
__SVELTEKIT_ADAPTER_NAME__: JSON.stringify(config.kit.adapter?.name),
|
|
150
|
-
__SVELTEKIT_APP_VERSION__: JSON.stringify(config.kit.version.name),
|
|
151
150
|
__SVELTEKIT_APP_VERSION_FILE__: JSON.stringify(`${config.kit.appDir}/version.json`),
|
|
152
151
|
__SVELTEKIT_APP_VERSION_POLL_INTERVAL__: JSON.stringify(config.kit.version.pollInterval),
|
|
153
152
|
__SVELTEKIT_BROWSER__: ssr ? 'false' : 'true',
|
|
@@ -271,6 +271,11 @@ export async function dev(vite, vite_config, svelte_config) {
|
|
|
271
271
|
}
|
|
272
272
|
});
|
|
273
273
|
|
|
274
|
+
// set `import { version } from '$app/environment'`
|
|
275
|
+
(await vite.ssrLoadModule(`${runtime_prefix}/env.js`)).set_version(
|
|
276
|
+
svelte_config.kit.version.name
|
|
277
|
+
);
|
|
278
|
+
|
|
274
279
|
return () => {
|
|
275
280
|
const serve_static_middleware = vite.middlewares.stack.find(
|
|
276
281
|
(middleware) =>
|
|
@@ -475,7 +480,8 @@ export async function dev(vite, vite_config, svelte_config) {
|
|
|
475
480
|
service_worker:
|
|
476
481
|
svelte_config.kit.serviceWorker.register &&
|
|
477
482
|
!!resolve_entry(svelte_config.kit.files.serviceWorker),
|
|
478
|
-
trailing_slash: svelte_config.kit.trailingSlash
|
|
483
|
+
trailing_slash: svelte_config.kit.trailingSlash,
|
|
484
|
+
version: svelte_config.kit.version.name
|
|
479
485
|
},
|
|
480
486
|
{
|
|
481
487
|
getClientAddress: () => {
|
|
@@ -107,9 +107,6 @@ function kit() {
|
|
|
107
107
|
/** @type {import('types').BuildData} */
|
|
108
108
|
let build_data;
|
|
109
109
|
|
|
110
|
-
/** @type {string | undefined} */
|
|
111
|
-
let deferred_warning;
|
|
112
|
-
|
|
113
110
|
/** @type {{ public: Record<string, string>; private: Record<string, string> }} */
|
|
114
111
|
let env;
|
|
115
112
|
|
|
@@ -284,7 +281,9 @@ function kit() {
|
|
|
284
281
|
}
|
|
285
282
|
};
|
|
286
283
|
|
|
287
|
-
|
|
284
|
+
const warning = warn_overridden_config(config, result);
|
|
285
|
+
if (warning) console.error(warning);
|
|
286
|
+
|
|
288
287
|
return result;
|
|
289
288
|
},
|
|
290
289
|
|
|
@@ -334,6 +333,10 @@ function kit() {
|
|
|
334
333
|
*/
|
|
335
334
|
configResolved(config) {
|
|
336
335
|
vite_config = config;
|
|
336
|
+
|
|
337
|
+
// This is a hack to prevent Vite from nuking useful logs,
|
|
338
|
+
// pending https://github.com/vitejs/vite/issues/9378
|
|
339
|
+
config.logger.warn('');
|
|
337
340
|
},
|
|
338
341
|
|
|
339
342
|
/**
|
|
@@ -540,14 +543,6 @@ function kit() {
|
|
|
540
543
|
* @see https://vitejs.dev/guide/api-plugin.html#configureserver
|
|
541
544
|
*/
|
|
542
545
|
async configureServer(vite) {
|
|
543
|
-
// This method is called by Vite after clearing the screen.
|
|
544
|
-
// This patch ensures we can log any important messages afterwards for the user to see.
|
|
545
|
-
const print_urls = vite.printUrls;
|
|
546
|
-
vite.printUrls = function () {
|
|
547
|
-
print_urls.apply(this);
|
|
548
|
-
if (deferred_warning) console.error('\n' + deferred_warning);
|
|
549
|
-
};
|
|
550
|
-
|
|
551
546
|
return await dev(vite, vite_config, svelte_config);
|
|
552
547
|
},
|
|
553
548
|
|
|
@@ -2,6 +2,7 @@ import { create_client } from './client.js';
|
|
|
2
2
|
import { init } from './singletons.js';
|
|
3
3
|
import { set_paths } from '../paths.js';
|
|
4
4
|
import { set_public_env } from '../env-public.js';
|
|
5
|
+
import { set_version } from '../env.js';
|
|
5
6
|
|
|
6
7
|
/**
|
|
7
8
|
* @param {{
|
|
@@ -13,11 +14,13 @@ import { set_public_env } from '../env-public.js';
|
|
|
13
14
|
* },
|
|
14
15
|
* target: Element;
|
|
15
16
|
* trailing_slash: import('types').TrailingSlash;
|
|
17
|
+
* version: string;
|
|
16
18
|
* }} opts
|
|
17
19
|
*/
|
|
18
|
-
export async function start({ env, hydrate, paths, target, trailing_slash }) {
|
|
20
|
+
export async function start({ env, hydrate, paths, target, trailing_slash, version }) {
|
|
19
21
|
set_public_env(env);
|
|
20
22
|
set_paths(paths);
|
|
23
|
+
set_version(version);
|
|
21
24
|
|
|
22
25
|
if (__SVELTEKIT_DEV__ && target === document.body) {
|
|
23
26
|
console.warn(
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { writable } from 'svelte/store';
|
|
2
2
|
import { assets } from '../paths.js';
|
|
3
|
+
import { version } from '../env.js';
|
|
3
4
|
|
|
4
|
-
/* global
|
|
5
|
+
/* global __SVELTEKIT_APP_VERSION_FILE__, __SVELTEKIT_APP_VERSION_POLL_INTERVAL__ */
|
|
5
6
|
|
|
6
7
|
/** @param {HTMLDocument} doc */
|
|
7
8
|
export function get_base_uri(doc) {
|
|
@@ -143,8 +144,8 @@ export function create_updated_store() {
|
|
|
143
144
|
});
|
|
144
145
|
|
|
145
146
|
if (res.ok) {
|
|
146
|
-
const
|
|
147
|
-
const updated = version !==
|
|
147
|
+
const data = await res.json();
|
|
148
|
+
const updated = data.version !== version;
|
|
148
149
|
|
|
149
150
|
if (updated) {
|
|
150
151
|
set(true);
|
package/src/runtime/control.js
CHANGED
package/src/runtime/env.js
CHANGED
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
export let prerendering = false;
|
|
2
|
+
export let version = '';
|
|
2
3
|
|
|
3
4
|
/** @param {boolean} value */
|
|
4
5
|
export function set_prerendering(value) {
|
|
5
6
|
prerendering = value;
|
|
6
7
|
}
|
|
8
|
+
|
|
9
|
+
/** @param {string} value */
|
|
10
|
+
export function set_version(value) {
|
|
11
|
+
version = value;
|
|
12
|
+
}
|
|
@@ -128,6 +128,17 @@ export function create_fetch({ event, options, state, get_cookie_header }) {
|
|
|
128
128
|
throw new Error('Request body must be a string or TypedArray');
|
|
129
129
|
}
|
|
130
130
|
|
|
131
|
+
if (!request.headers.has('accept')) {
|
|
132
|
+
request.headers.set('accept', '*/*');
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
if (!request.headers.has('accept-language')) {
|
|
136
|
+
request.headers.set(
|
|
137
|
+
'accept-language',
|
|
138
|
+
/** @type {string} */ (event.request.headers.get('accept-language'))
|
|
139
|
+
);
|
|
140
|
+
}
|
|
141
|
+
|
|
131
142
|
response = await respond(request, options, state);
|
|
132
143
|
|
|
133
144
|
const set_cookie = response.headers.get('set-cookie');
|
|
@@ -27,7 +27,7 @@ const default_transform = ({ html }) => html;
|
|
|
27
27
|
const default_filter = () => false;
|
|
28
28
|
|
|
29
29
|
/** @type {import('types').RequiredResolveOptions['preload']} */
|
|
30
|
-
const default_preload = ({ type }) => type
|
|
30
|
+
const default_preload = ({ type }) => type === 'js' || type === 'css';
|
|
31
31
|
|
|
32
32
|
/** @type {import('types').Respond} */
|
|
33
33
|
export async function respond(request, options, state) {
|
|
@@ -281,7 +281,8 @@ export async function render_response({
|
|
|
281
281
|
}` : 'null'},
|
|
282
282
|
paths: ${s(options.paths)},
|
|
283
283
|
target: document.querySelector('[data-sveltekit-hydrate="${target}"]').parentNode,
|
|
284
|
-
trailing_slash: ${s(options.trailing_slash)}
|
|
284
|
+
trailing_slash: ${s(options.trailing_slash)},
|
|
285
|
+
version: ${s(options.version)}
|
|
285
286
|
});
|
|
286
287
|
`;
|
|
287
288
|
|
package/types/ambient.d.ts
CHANGED
package/types/index.d.ts
CHANGED
|
@@ -18,7 +18,6 @@ import {
|
|
|
18
18
|
UniqueInterface
|
|
19
19
|
} from './private.js';
|
|
20
20
|
import { SSRNodeLoader, SSRRoute, ValidatedConfig } from './internal.js';
|
|
21
|
-
import { HttpError, Redirect } from '../src/runtime/control.js';
|
|
22
21
|
|
|
23
22
|
export { PrerenderOption } from './private.js';
|
|
24
23
|
|
|
@@ -53,13 +52,6 @@ type OptionalUnion<
|
|
|
53
52
|
A extends keyof U = U extends U ? keyof U : never
|
|
54
53
|
> = U extends unknown ? { [P in Exclude<A, keyof U>]?: never } & U : never;
|
|
55
54
|
|
|
56
|
-
// Needs to be here, else ActionData will be resolved to unknown - probably because of "d.ts file imports .js file" in combination with allowJs
|
|
57
|
-
export interface ValidationError<T extends Record<string, unknown> | undefined = undefined>
|
|
58
|
-
extends UniqueInterface {
|
|
59
|
-
status: number;
|
|
60
|
-
data: T;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
55
|
type UnpackValidationError<T> = T extends ValidationError<infer X>
|
|
64
56
|
? X
|
|
65
57
|
: T extends void
|
|
@@ -752,6 +744,16 @@ export function error(
|
|
|
752
744
|
body?: { message: string } extends App.Error ? App.Error | string | undefined : never
|
|
753
745
|
): HttpError;
|
|
754
746
|
|
|
747
|
+
/**
|
|
748
|
+
* The object returned by the `error` function
|
|
749
|
+
*/
|
|
750
|
+
export interface HttpError {
|
|
751
|
+
/** The HTTP status code */
|
|
752
|
+
status: number;
|
|
753
|
+
/** The error message */
|
|
754
|
+
body: App.Error;
|
|
755
|
+
}
|
|
756
|
+
|
|
755
757
|
/**
|
|
756
758
|
* Creates a `Redirect` object. If thrown during request handling, SvelteKit will
|
|
757
759
|
* return a redirect response.
|
|
@@ -761,6 +763,16 @@ export function redirect(
|
|
|
761
763
|
location: string
|
|
762
764
|
): Redirect;
|
|
763
765
|
|
|
766
|
+
/**
|
|
767
|
+
* The object returned by the `redirect` function
|
|
768
|
+
*/
|
|
769
|
+
export interface Redirect {
|
|
770
|
+
/** The HTTP status code */
|
|
771
|
+
status: 300 | 301 | 302 | 303 | 304 | 305 | 306 | 307 | 308;
|
|
772
|
+
/** The location to redirect to */
|
|
773
|
+
location: string;
|
|
774
|
+
}
|
|
775
|
+
|
|
764
776
|
/**
|
|
765
777
|
* Generates a JSON `Response` object from the supplied data.
|
|
766
778
|
*/
|
|
@@ -773,3 +785,12 @@ export function invalid<T extends Record<string, unknown> | undefined>(
|
|
|
773
785
|
status: number,
|
|
774
786
|
data?: T
|
|
775
787
|
): ValidationError<T>;
|
|
788
|
+
|
|
789
|
+
/**
|
|
790
|
+
* The object returned by the `invalid` function
|
|
791
|
+
*/
|
|
792
|
+
export interface ValidationError<T extends Record<string, unknown> | undefined = undefined>
|
|
793
|
+
extends UniqueInterface {
|
|
794
|
+
status: number;
|
|
795
|
+
data: T;
|
|
796
|
+
}
|
package/types/internal.d.ts
CHANGED
|
@@ -313,6 +313,7 @@ export interface SSROptions {
|
|
|
313
313
|
app_template_contains_nonce: boolean;
|
|
314
314
|
error_template({ message, status }: { message: string; status: number }): string;
|
|
315
315
|
trailing_slash: TrailingSlash;
|
|
316
|
+
version: string;
|
|
316
317
|
}
|
|
317
318
|
|
|
318
319
|
export interface SSRErrorPage {
|