@sveltejs/kit 1.1.3 → 1.2.0
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 +3 -2
- package/src/core/config/index.js +24 -15
- package/src/core/sync/write_server.js +6 -2
- package/src/exports/index.js +25 -1
- package/src/exports/vite/build/build_server.js +17 -52
- package/src/exports/vite/build/utils.js +2 -135
- package/src/exports/vite/dev/index.js +7 -8
- package/src/exports/vite/index.js +252 -222
- package/src/exports/vite/utils.js +1 -88
- package/src/runtime/client/client.js +1 -1
- package/src/runtime/env-public.js +1 -0
- package/src/runtime/server/data/index.js +2 -1
- package/src/runtime/server/page/index.js +4 -3
- package/src/runtime/server/page/render.js +4 -2
- package/src/runtime/server/respond.js +6 -6
- package/src/runtime/server/utils.js +5 -5
- package/types/ambient.d.ts +1 -1
- package/types/index.d.ts +8 -1
- package/types/internal.d.ts +7 -1
|
@@ -1,80 +1,8 @@
|
|
|
1
1
|
import path from 'path';
|
|
2
|
-
import {
|
|
3
|
-
import { runtime_directory } from '../../core/utils.js';
|
|
2
|
+
import { loadEnv } from 'vite';
|
|
4
3
|
import { posixify } from '../../utils/filesystem.js';
|
|
5
4
|
import { negotiate } from '../../utils/http.js';
|
|
6
5
|
|
|
7
|
-
/**
|
|
8
|
-
* @param {import('vite').ResolvedConfig} config
|
|
9
|
-
* @param {import('vite').ConfigEnv} config_env
|
|
10
|
-
* @return {Promise<import('vite').UserConfig>}
|
|
11
|
-
*/
|
|
12
|
-
export async function get_vite_config(config, config_env) {
|
|
13
|
-
const loaded = await loadConfigFromFile(
|
|
14
|
-
config_env,
|
|
15
|
-
config.configFile,
|
|
16
|
-
undefined,
|
|
17
|
-
config.logLevel
|
|
18
|
-
);
|
|
19
|
-
|
|
20
|
-
if (!loaded) {
|
|
21
|
-
throw new Error('Could not load Vite config');
|
|
22
|
-
}
|
|
23
|
-
return mergeConfig(loaded.config, {
|
|
24
|
-
// CLI opts
|
|
25
|
-
mode: config_env.mode,
|
|
26
|
-
logLevel: config.logLevel,
|
|
27
|
-
clearScreen: config.clearScreen,
|
|
28
|
-
optimizeDeps: { force: config.optimizeDeps.force }
|
|
29
|
-
});
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* Takes zero or more objects and returns a new object that has all the values
|
|
34
|
-
* deeply merged together. None of the original objects will be mutated at any
|
|
35
|
-
* level, and the returned object will have no references to the original
|
|
36
|
-
* objects at any depth. If there's a conflict the last one wins, except for
|
|
37
|
-
* arrays which will be combined.
|
|
38
|
-
* @param {...Object} objects
|
|
39
|
-
* @returns {Record<string, any>} the merged object
|
|
40
|
-
*/
|
|
41
|
-
export function deep_merge(...objects) {
|
|
42
|
-
const result = {};
|
|
43
|
-
/** @type {string[]} */
|
|
44
|
-
objects.forEach((o) => merge_into(result, o));
|
|
45
|
-
return result;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
/**
|
|
49
|
-
* Merges b into a, recursively, mutating a.
|
|
50
|
-
* @param {Record<string, any>} a
|
|
51
|
-
* @param {Record<string, any>} b
|
|
52
|
-
*/
|
|
53
|
-
function merge_into(a, b) {
|
|
54
|
-
/**
|
|
55
|
-
* Checks for "plain old Javascript object", typically made as an object
|
|
56
|
-
* literal. Excludes Arrays and built-in types like Buffer.
|
|
57
|
-
* @param {any} x
|
|
58
|
-
*/
|
|
59
|
-
const is_plain_object = (x) => typeof x === 'object' && x.constructor === Object;
|
|
60
|
-
|
|
61
|
-
for (const prop in b) {
|
|
62
|
-
if (is_plain_object(b[prop])) {
|
|
63
|
-
if (!is_plain_object(a[prop])) {
|
|
64
|
-
a[prop] = {};
|
|
65
|
-
}
|
|
66
|
-
merge_into(a[prop], b[prop]);
|
|
67
|
-
} else if (Array.isArray(b[prop])) {
|
|
68
|
-
if (!Array.isArray(a[prop])) {
|
|
69
|
-
a[prop] = [];
|
|
70
|
-
}
|
|
71
|
-
a[prop].push(...b[prop]);
|
|
72
|
-
} else {
|
|
73
|
-
a[prop] = b[prop];
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
|
|
78
6
|
/**
|
|
79
7
|
* Transforms kit.alias to a valid vite.resolve.alias array.
|
|
80
8
|
*
|
|
@@ -115,21 +43,6 @@ export function get_config_aliases(config) {
|
|
|
115
43
|
return alias;
|
|
116
44
|
}
|
|
117
45
|
|
|
118
|
-
/**
|
|
119
|
-
* Returns Vite aliases for generated and runtime files.
|
|
120
|
-
*
|
|
121
|
-
* @param {import('types').ValidatedKitConfig} config
|
|
122
|
-
* */
|
|
123
|
-
export function get_app_aliases(config) {
|
|
124
|
-
/** @type {import('vite').Alias[]} */
|
|
125
|
-
const alias = [
|
|
126
|
-
{ find: '__GENERATED__', replacement: path.posix.join(config.outDir, 'generated') },
|
|
127
|
-
{ find: '$app', replacement: `${runtime_directory}/app` }
|
|
128
|
-
];
|
|
129
|
-
|
|
130
|
-
return alias;
|
|
131
|
-
}
|
|
132
|
-
|
|
133
46
|
/**
|
|
134
47
|
* @param {string} str
|
|
135
48
|
*/
|
|
@@ -1737,7 +1737,7 @@ if (DEV) {
|
|
|
1737
1737
|
console.warn = function warn(...args) {
|
|
1738
1738
|
if (
|
|
1739
1739
|
args.length === 1 &&
|
|
1740
|
-
/<(Layout|Page)(_[\w$]+)?> was created (with unknown|without expected) prop '(data|form)'/.test(
|
|
1740
|
+
/<(Layout|Page|Error)(_[\w$]+)?> was created (with unknown|without expected) prop '(data|form)'/.test(
|
|
1741
1741
|
args[0]
|
|
1742
1742
|
)
|
|
1743
1743
|
) {
|
|
@@ -4,6 +4,7 @@ import { once } from '../../../utils/functions.js';
|
|
|
4
4
|
import { load_server_data } from '../page/load_data.js';
|
|
5
5
|
import { clarify_devalue_error, handle_error_and_jsonify, serialize_data_node } from '../utils.js';
|
|
6
6
|
import { normalize_path } from '../../../utils/url.js';
|
|
7
|
+
import { text } from '../../../exports/index.js';
|
|
7
8
|
|
|
8
9
|
export const INVALIDATED_PARAM = 'x-sveltekit-invalidated';
|
|
9
10
|
|
|
@@ -139,7 +140,7 @@ export async function render_data(
|
|
|
139
140
|
* @param {number} [status]
|
|
140
141
|
*/
|
|
141
142
|
function json_response(json, status = 200) {
|
|
142
|
-
return
|
|
143
|
+
return text(json, {
|
|
143
144
|
status,
|
|
144
145
|
headers: {
|
|
145
146
|
'content-type': 'application/json',
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { text } from '../../../exports/index.js';
|
|
1
2
|
import { compact } from '../../../utils/array.js';
|
|
2
3
|
import { normalize_error } from '../../../utils/error.js';
|
|
3
4
|
import { add_data_suffix } from '../../../utils/url.js';
|
|
@@ -32,7 +33,7 @@ import { respond_with_error } from './respond_with_error.js';
|
|
|
32
33
|
export async function render_page(event, route, page, options, manifest, state, resolve_opts) {
|
|
33
34
|
if (state.initiator === route) {
|
|
34
35
|
// infinite request cycle detected
|
|
35
|
-
return
|
|
36
|
+
return text(`Not found: ${event.url.pathname}`, {
|
|
36
37
|
status: 404
|
|
37
38
|
});
|
|
38
39
|
}
|
|
@@ -239,7 +240,7 @@ export async function render_page(event, route, page, options, manifest, state,
|
|
|
239
240
|
});
|
|
240
241
|
|
|
241
242
|
state.prerendering.dependencies.set(data_pathname, {
|
|
242
|
-
response:
|
|
243
|
+
response: text(body),
|
|
243
244
|
body
|
|
244
245
|
});
|
|
245
246
|
}
|
|
@@ -294,7 +295,7 @@ export async function render_page(event, route, page, options, manifest, state,
|
|
|
294
295
|
.join(',')}]}`;
|
|
295
296
|
|
|
296
297
|
state.prerendering.dependencies.set(data_pathname, {
|
|
297
|
-
response:
|
|
298
|
+
response: text(body),
|
|
298
299
|
body
|
|
299
300
|
});
|
|
300
301
|
}
|
|
@@ -9,6 +9,7 @@ import { uneval_action_response } from './actions.js';
|
|
|
9
9
|
import { clarify_devalue_error } from '../utils.js';
|
|
10
10
|
import { assets, base, version } from '../../shared.js';
|
|
11
11
|
import { env } from '../../env-public.js';
|
|
12
|
+
import { text } from '../../../exports/index.js';
|
|
12
13
|
|
|
13
14
|
// TODO rename this function/module
|
|
14
15
|
|
|
@@ -366,7 +367,8 @@ export async function render_response({
|
|
|
366
367
|
head,
|
|
367
368
|
body,
|
|
368
369
|
assets: resolved_assets,
|
|
369
|
-
nonce: /** @type {string} */ (csp.nonce)
|
|
370
|
+
nonce: /** @type {string} */ (csp.nonce),
|
|
371
|
+
env
|
|
370
372
|
});
|
|
371
373
|
|
|
372
374
|
// TODO flush chunks as early as we can
|
|
@@ -407,7 +409,7 @@ export async function render_response({
|
|
|
407
409
|
}
|
|
408
410
|
}
|
|
409
411
|
|
|
410
|
-
return
|
|
412
|
+
return text(transformed, {
|
|
411
413
|
status,
|
|
412
414
|
headers
|
|
413
415
|
});
|
|
@@ -23,7 +23,7 @@ import {
|
|
|
23
23
|
validate_page_server_exports,
|
|
24
24
|
validate_server_exports
|
|
25
25
|
} from '../../utils/exports.js';
|
|
26
|
-
import { error, json } from '../../exports/index.js';
|
|
26
|
+
import { error, json, text } from '../../exports/index.js';
|
|
27
27
|
import * as paths from '../shared.js';
|
|
28
28
|
|
|
29
29
|
/* global __SVELTEKIT_ADAPTER_NAME__ */
|
|
@@ -53,7 +53,7 @@ export async function respond(request, options, manifest, state) {
|
|
|
53
53
|
if (request.headers.get('accept') === 'application/json') {
|
|
54
54
|
return json(csrf_error.body, { status: csrf_error.status });
|
|
55
55
|
}
|
|
56
|
-
return
|
|
56
|
+
return text(csrf_error.body.message, { status: csrf_error.status });
|
|
57
57
|
}
|
|
58
58
|
}
|
|
59
59
|
|
|
@@ -61,7 +61,7 @@ export async function respond(request, options, manifest, state) {
|
|
|
61
61
|
try {
|
|
62
62
|
decoded = decode_pathname(url.pathname);
|
|
63
63
|
} catch {
|
|
64
|
-
return
|
|
64
|
+
return text('Malformed URI', { status: 400 });
|
|
65
65
|
}
|
|
66
66
|
|
|
67
67
|
/** @type {import('types').SSRRoute | null} */
|
|
@@ -72,7 +72,7 @@ export async function respond(request, options, manifest, state) {
|
|
|
72
72
|
|
|
73
73
|
if (paths.base && !state.prerendering?.fallback) {
|
|
74
74
|
if (!decoded.startsWith(paths.base)) {
|
|
75
|
-
return
|
|
75
|
+
return text('Not found', { status: 404 });
|
|
76
76
|
}
|
|
77
77
|
decoded = decoded.slice(paths.base.length) || '/';
|
|
78
78
|
}
|
|
@@ -374,7 +374,7 @@ export async function respond(request, options, manifest, state) {
|
|
|
374
374
|
}
|
|
375
375
|
|
|
376
376
|
if (state.initiator === GENERIC_ERROR) {
|
|
377
|
-
return
|
|
377
|
+
return text('Internal Server Error', {
|
|
378
378
|
status: 500
|
|
379
379
|
});
|
|
380
380
|
}
|
|
@@ -394,7 +394,7 @@ export async function respond(request, options, manifest, state) {
|
|
|
394
394
|
}
|
|
395
395
|
|
|
396
396
|
if (state.prerendering) {
|
|
397
|
-
return
|
|
397
|
+
return text('not found', { status: 404 });
|
|
398
398
|
}
|
|
399
399
|
|
|
400
400
|
// we can't load the endpoint from our own manifest,
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import * as devalue from 'devalue';
|
|
2
|
+
import { json, text } from '../../exports/index.js';
|
|
2
3
|
import { coalesce_to_error } from '../../utils/error.js';
|
|
3
4
|
import { negotiate } from '../../utils/http.js';
|
|
4
5
|
import { has_data_suffix } from '../../utils/url.js';
|
|
@@ -27,7 +28,7 @@ export const GENERIC_ERROR = {
|
|
|
27
28
|
* @param {import('types').HttpMethod} method
|
|
28
29
|
*/
|
|
29
30
|
export function method_not_allowed(mod, method) {
|
|
30
|
-
return
|
|
31
|
+
return text(`${method} method not allowed`, {
|
|
31
32
|
status: 405,
|
|
32
33
|
headers: {
|
|
33
34
|
// https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/405
|
|
@@ -75,7 +76,7 @@ export function get_option(nodes, option) {
|
|
|
75
76
|
* @param {string} message
|
|
76
77
|
*/
|
|
77
78
|
export function static_error_page(options, status, message) {
|
|
78
|
-
return
|
|
79
|
+
return text(options.templates.error({ status, message }), {
|
|
79
80
|
headers: { 'content-type': 'text/html; charset=utf-8' },
|
|
80
81
|
status
|
|
81
82
|
});
|
|
@@ -98,9 +99,8 @@ export async function handle_fatal_error(event, options, error) {
|
|
|
98
99
|
]);
|
|
99
100
|
|
|
100
101
|
if (has_data_suffix(new URL(event.request.url).pathname) || type === 'application/json') {
|
|
101
|
-
return
|
|
102
|
-
status
|
|
103
|
-
headers: { 'content-type': 'application/json; charset=utf-8' }
|
|
102
|
+
return json(body, {
|
|
103
|
+
status
|
|
104
104
|
});
|
|
105
105
|
}
|
|
106
106
|
|
package/types/ambient.d.ts
CHANGED
|
@@ -40,7 +40,7 @@ declare namespace App {
|
|
|
40
40
|
export interface PageData {}
|
|
41
41
|
|
|
42
42
|
/**
|
|
43
|
-
* If your adapter provides [platform-specific context](https://kit.svelte.dev/docs/adapters#
|
|
43
|
+
* If your adapter provides [platform-specific context](https://kit.svelte.dev/docs/adapters#platform-specific-context) via `event.platform`, you can specify it here.
|
|
44
44
|
*/
|
|
45
45
|
export interface Platform {}
|
|
46
46
|
}
|
package/types/index.d.ts
CHANGED
|
@@ -1123,10 +1123,17 @@ export interface Redirect {
|
|
|
1123
1123
|
/**
|
|
1124
1124
|
* Create a JSON `Response` object from the supplied data.
|
|
1125
1125
|
* @param data The value that will be serialized as JSON.
|
|
1126
|
-
* @param init Options such as `status` and `headers` that will be added to the response.
|
|
1126
|
+
* @param init Options such as `status` and `headers` that will be added to the response. `Content-Type: application/json` and `Content-Length` headers will be added automatically.
|
|
1127
1127
|
*/
|
|
1128
1128
|
export function json(data: any, init?: ResponseInit): Response;
|
|
1129
1129
|
|
|
1130
|
+
/**
|
|
1131
|
+
* Create a `Response` object from the supplied body.
|
|
1132
|
+
* @param body The value that will be used as-is.
|
|
1133
|
+
* @param init Options such as `status` and `headers` that will be added to the response. A `Content-Length` header will be added automatically.
|
|
1134
|
+
*/
|
|
1135
|
+
export function text(body: string, init?: ResponseInit): Response;
|
|
1136
|
+
|
|
1130
1137
|
/**
|
|
1131
1138
|
* Create an `ActionFailure` object.
|
|
1132
1139
|
* @param status The [HTTP status code](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status#client_error_responses). Must be in the range 400-599.
|
package/types/internal.d.ts
CHANGED
|
@@ -306,7 +306,13 @@ export interface SSROptions {
|
|
|
306
306
|
root: SSRComponent['default'];
|
|
307
307
|
service_worker: boolean;
|
|
308
308
|
templates: {
|
|
309
|
-
app(values: {
|
|
309
|
+
app(values: {
|
|
310
|
+
head: string;
|
|
311
|
+
body: string;
|
|
312
|
+
assets: string;
|
|
313
|
+
nonce: string;
|
|
314
|
+
env: Record<string, string>;
|
|
315
|
+
}): string;
|
|
310
316
|
error(values: { message: string; status: number }): string;
|
|
311
317
|
};
|
|
312
318
|
}
|