@sveltejs/kit 1.0.0-next.340 → 1.0.0-next.341
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/assets/client/start.js +4 -0
- package/assets/server/index.js +11 -28
- package/dist/chunks/cert.js +1 -1
- package/dist/chunks/index.js +16 -13
- package/dist/chunks/index2.js +3 -2
- package/dist/chunks/index5.js +3 -2
- package/dist/chunks/multipart-parser.js +2 -1
- package/dist/cli.js +3 -7
- package/dist/{install-fetch.js → node/polyfills.js} +21 -25
- package/dist/node.js +210 -3
- package/package.json +4 -4
- package/types/ambient.d.ts +8 -3
package/assets/client/start.js
CHANGED
|
@@ -682,6 +682,10 @@ function create_client({ target, session, base, trailing_slash }) {
|
|
|
682
682
|
if (started) {
|
|
683
683
|
current = navigation_result.state;
|
|
684
684
|
|
|
685
|
+
if (navigation_result.props.page) {
|
|
686
|
+
navigation_result.props.page.url = url;
|
|
687
|
+
}
|
|
688
|
+
|
|
685
689
|
root.$set(navigation_result.props);
|
|
686
690
|
} else {
|
|
687
691
|
initialize(navigation_result);
|
package/assets/server/index.js
CHANGED
|
@@ -885,33 +885,11 @@ function base64(bytes) {
|
|
|
885
885
|
/** @type {Promise<void>} */
|
|
886
886
|
let csp_ready;
|
|
887
887
|
|
|
888
|
-
|
|
889
|
-
let generate_nonce;
|
|
888
|
+
const array = new Uint8Array(16);
|
|
890
889
|
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
if (typeof crypto !== 'undefined') {
|
|
895
|
-
const array = new Uint8Array(16);
|
|
896
|
-
|
|
897
|
-
generate_nonce = () => {
|
|
898
|
-
crypto.getRandomValues(array);
|
|
899
|
-
return base64(array);
|
|
900
|
-
};
|
|
901
|
-
|
|
902
|
-
generate_hash = sha256;
|
|
903
|
-
} else {
|
|
904
|
-
// TODO: remove this in favor of web crypto API once we no longer support Node 14
|
|
905
|
-
const name = 'crypto'; // store in a variable to fool esbuild when adapters bundle kit
|
|
906
|
-
csp_ready = import(name).then((crypto) => {
|
|
907
|
-
generate_nonce = () => {
|
|
908
|
-
return crypto.randomBytes(16).toString('base64');
|
|
909
|
-
};
|
|
910
|
-
|
|
911
|
-
generate_hash = (input) => {
|
|
912
|
-
return crypto.createHash('sha256').update(input, 'utf-8').digest().toString('base64');
|
|
913
|
-
};
|
|
914
|
-
});
|
|
890
|
+
function generate_nonce() {
|
|
891
|
+
crypto.getRandomValues(array);
|
|
892
|
+
return base64(array);
|
|
915
893
|
}
|
|
916
894
|
|
|
917
895
|
const quoted = new Set([
|
|
@@ -1014,7 +992,7 @@ class Csp {
|
|
|
1014
992
|
add_script(content) {
|
|
1015
993
|
if (this.#script_needs_csp) {
|
|
1016
994
|
if (this.#use_hashes) {
|
|
1017
|
-
this.#script_src.push(`sha256-${
|
|
995
|
+
this.#script_src.push(`sha256-${sha256(content)}`);
|
|
1018
996
|
} else if (this.#script_src.length === 0) {
|
|
1019
997
|
this.#script_src.push(`nonce-${this.nonce}`);
|
|
1020
998
|
}
|
|
@@ -1025,7 +1003,7 @@ class Csp {
|
|
|
1025
1003
|
add_style(content) {
|
|
1026
1004
|
if (this.#style_needs_csp) {
|
|
1027
1005
|
if (this.#use_hashes) {
|
|
1028
|
-
this.#style_src.push(`sha256-${
|
|
1006
|
+
this.#style_src.push(`sha256-${sha256(content)}`);
|
|
1029
1007
|
} else if (this.#style_src.length === 0) {
|
|
1030
1008
|
this.#style_src.push(`nonce-${this.nonce}`);
|
|
1031
1009
|
}
|
|
@@ -2132,6 +2110,11 @@ async function load_node({
|
|
|
2132
2110
|
props: shadow.body || {},
|
|
2133
2111
|
routeId: event.routeId,
|
|
2134
2112
|
get session() {
|
|
2113
|
+
if (node.module.prerender ?? options.prerender.default) {
|
|
2114
|
+
throw Error(
|
|
2115
|
+
'Attempted to access session from a prerendered page. Session would never be populated.'
|
|
2116
|
+
);
|
|
2117
|
+
}
|
|
2135
2118
|
uses_credentials = true;
|
|
2136
2119
|
return $session;
|
|
2137
2120
|
},
|
package/dist/chunks/cert.js
CHANGED
package/dist/chunks/index.js
CHANGED
|
@@ -6,7 +6,7 @@ import { g as get_runtime_path, r as resolve_entry, $, l as load_template, c as
|
|
|
6
6
|
import fs__default from 'fs';
|
|
7
7
|
import { URL } from 'url';
|
|
8
8
|
import { S as SVELTE_KIT_ASSETS, s as sirv } from './constants.js';
|
|
9
|
-
import {
|
|
9
|
+
import { installPolyfills } from '../node/polyfills.js';
|
|
10
10
|
import { update, init } from './sync.js';
|
|
11
11
|
import { getRequest, setResponse } from '../node.js';
|
|
12
12
|
import { p as posixify } from './filesystem.js';
|
|
@@ -23,6 +23,7 @@ import 'node:zlib';
|
|
|
23
23
|
import 'node:stream';
|
|
24
24
|
import 'node:util';
|
|
25
25
|
import 'node:url';
|
|
26
|
+
import 'crypto';
|
|
26
27
|
import './write_tsconfig.js';
|
|
27
28
|
import 'stream';
|
|
28
29
|
|
|
@@ -30,12 +31,13 @@ import 'stream';
|
|
|
30
31
|
// https://github.com/vitejs/vite/blob/3edd1af56e980aef56641a5a51cf2932bb580d41/packages/vite/src/node/plugins/css.ts#L96
|
|
31
32
|
const style_pattern = /\.(css|less|sass|scss|styl|stylus|pcss|postcss)$/;
|
|
32
33
|
|
|
34
|
+
const cwd$1 = process.cwd();
|
|
35
|
+
|
|
33
36
|
/**
|
|
34
37
|
* @param {import('types').ValidatedConfig} config
|
|
35
|
-
* @param {string} cwd
|
|
36
38
|
* @returns {Promise<import('vite').Plugin>}
|
|
37
39
|
*/
|
|
38
|
-
async function create_plugin(config
|
|
40
|
+
async function create_plugin(config) {
|
|
39
41
|
const runtime = get_runtime_path(config);
|
|
40
42
|
|
|
41
43
|
process.env.VITE_SVELTEKIT_APP_VERSION_POLL_INTERVAL = '0';
|
|
@@ -47,7 +49,7 @@ async function create_plugin(config, cwd) {
|
|
|
47
49
|
name: 'vite-plugin-svelte-kit',
|
|
48
50
|
|
|
49
51
|
configureServer(vite) {
|
|
50
|
-
|
|
52
|
+
installPolyfills();
|
|
51
53
|
|
|
52
54
|
/** @type {import('types').SSRManifest} */
|
|
53
55
|
let manifest;
|
|
@@ -123,7 +125,7 @@ async function create_plugin(config, cwd) {
|
|
|
123
125
|
types,
|
|
124
126
|
shadow: route.shadow
|
|
125
127
|
? async () => {
|
|
126
|
-
const url = path__default.resolve(cwd, /** @type {string} */ (route.shadow));
|
|
128
|
+
const url = path__default.resolve(cwd$1, /** @type {string} */ (route.shadow));
|
|
127
129
|
return await vite.ssrLoadModule(url, { fixStacktrace: false });
|
|
128
130
|
}
|
|
129
131
|
: null,
|
|
@@ -139,7 +141,7 @@ async function create_plugin(config, cwd) {
|
|
|
139
141
|
names,
|
|
140
142
|
types,
|
|
141
143
|
load: async () => {
|
|
142
|
-
const url = path__default.resolve(cwd, route.file);
|
|
144
|
+
const url = path__default.resolve(cwd$1, route.file);
|
|
143
145
|
return await vite.ssrLoadModule(url, { fixStacktrace: false });
|
|
144
146
|
}
|
|
145
147
|
};
|
|
@@ -150,7 +152,7 @@ async function create_plugin(config, cwd) {
|
|
|
150
152
|
|
|
151
153
|
for (const key in manifest_data.matchers) {
|
|
152
154
|
const file = manifest_data.matchers[key];
|
|
153
|
-
const url = path__default.resolve(cwd, file);
|
|
155
|
+
const url = path__default.resolve(cwd$1, file);
|
|
154
156
|
const module = await vite.ssrLoadModule(url, { fixStacktrace: false });
|
|
155
157
|
|
|
156
158
|
if (module.match) {
|
|
@@ -261,13 +263,13 @@ async function create_plugin(config, cwd) {
|
|
|
261
263
|
// can get loaded twice via different URLs, which causes failures. Might
|
|
262
264
|
// require changes to Vite to fix
|
|
263
265
|
const { default: root } = await vite.ssrLoadModule(
|
|
264
|
-
`/${posixify(path__default.relative(cwd, `${config.kit.outDir}/generated/root.svelte`))}`,
|
|
266
|
+
`/${posixify(path__default.relative(cwd$1, `${config.kit.outDir}/generated/root.svelte`))}`,
|
|
265
267
|
{ fixStacktrace: false }
|
|
266
268
|
);
|
|
267
269
|
|
|
268
270
|
const paths = await vite.ssrLoadModule(
|
|
269
271
|
true
|
|
270
|
-
? `/${posixify(path__default.relative(cwd, `${config.kit.outDir}/runtime/paths.js`))}`
|
|
272
|
+
? `/${posixify(path__default.relative(cwd$1, `${config.kit.outDir}/runtime/paths.js`))}`
|
|
271
273
|
: `/@fs${runtime}/paths.js`,
|
|
272
274
|
{ fixStacktrace: false }
|
|
273
275
|
);
|
|
@@ -286,7 +288,7 @@ async function create_plugin(config, cwd) {
|
|
|
286
288
|
return res.end(err.reason || 'Invalid request body');
|
|
287
289
|
}
|
|
288
290
|
|
|
289
|
-
const template = load_template(cwd, config);
|
|
291
|
+
const template = load_template(cwd$1, config);
|
|
290
292
|
|
|
291
293
|
const rendered = await respond(
|
|
292
294
|
request,
|
|
@@ -440,9 +442,10 @@ async function find_deps(vite, node, deps) {
|
|
|
440
442
|
await Promise.all(branches);
|
|
441
443
|
}
|
|
442
444
|
|
|
445
|
+
const cwd = process.cwd();
|
|
446
|
+
|
|
443
447
|
/**
|
|
444
448
|
* @typedef {{
|
|
445
|
-
* cwd: string,
|
|
446
449
|
* port: number,
|
|
447
450
|
* host?: string,
|
|
448
451
|
* https: boolean,
|
|
@@ -452,7 +455,7 @@ async function find_deps(vite, node, deps) {
|
|
|
452
455
|
*/
|
|
453
456
|
|
|
454
457
|
/** @param {Options} opts */
|
|
455
|
-
async function dev({
|
|
458
|
+
async function dev({ port, host, https, config }) {
|
|
456
459
|
init(config);
|
|
457
460
|
|
|
458
461
|
const [vite_config] = deep_merge(
|
|
@@ -504,7 +507,7 @@ async function dev({ cwd, port, host, https, config }) {
|
|
|
504
507
|
},
|
|
505
508
|
configFile: false
|
|
506
509
|
}),
|
|
507
|
-
await create_plugin(config
|
|
510
|
+
await create_plugin(config)
|
|
508
511
|
],
|
|
509
512
|
base: '/'
|
|
510
513
|
});
|
package/dist/chunks/index2.js
CHANGED
|
@@ -9,7 +9,7 @@ import { s } from './misc.js';
|
|
|
9
9
|
import { d as deep_merge } from './object.js';
|
|
10
10
|
import { svelte } from '@sveltejs/vite-plugin-svelte';
|
|
11
11
|
import { pathToFileURL, URL as URL$1 } from 'url';
|
|
12
|
-
import {
|
|
12
|
+
import { installPolyfills } from '../node/polyfills.js';
|
|
13
13
|
import './write_tsconfig.js';
|
|
14
14
|
import 'sade';
|
|
15
15
|
import 'child_process';
|
|
@@ -22,6 +22,7 @@ import 'node:zlib';
|
|
|
22
22
|
import 'node:stream';
|
|
23
23
|
import 'node:util';
|
|
24
24
|
import 'node:url';
|
|
25
|
+
import 'crypto';
|
|
25
26
|
|
|
26
27
|
const absolute = /^([a-z]+:)?\/?\//;
|
|
27
28
|
const scheme = /^[a-z]+:/;
|
|
@@ -1068,7 +1069,7 @@ async function prerender({ config, entries, files, log }) {
|
|
|
1068
1069
|
return prerendered;
|
|
1069
1070
|
}
|
|
1070
1071
|
|
|
1071
|
-
|
|
1072
|
+
installPolyfills();
|
|
1072
1073
|
|
|
1073
1074
|
const server_root = join(config.kit.outDir, 'output');
|
|
1074
1075
|
|
package/dist/chunks/index5.js
CHANGED
|
@@ -5,7 +5,7 @@ import { join } from 'path';
|
|
|
5
5
|
import { S as SVELTE_KIT_ASSETS, s as sirv } from './constants.js';
|
|
6
6
|
import { pathToFileURL } from 'url';
|
|
7
7
|
import { getRequest, setResponse } from '../node.js';
|
|
8
|
-
import {
|
|
8
|
+
import { installPolyfills } from '../node/polyfills.js';
|
|
9
9
|
import 'querystring';
|
|
10
10
|
import 'stream';
|
|
11
11
|
import 'node:http';
|
|
@@ -15,6 +15,7 @@ import 'node:stream';
|
|
|
15
15
|
import 'node:util';
|
|
16
16
|
import 'node:url';
|
|
17
17
|
import 'net';
|
|
18
|
+
import 'crypto';
|
|
18
19
|
|
|
19
20
|
/** @typedef {import('http').IncomingMessage} Req */
|
|
20
21
|
/** @typedef {import('http').ServerResponse} Res */
|
|
@@ -42,7 +43,7 @@ const mutable = (dir) =>
|
|
|
42
43
|
* }} opts
|
|
43
44
|
*/
|
|
44
45
|
async function preview({ port, host, config, https: use_https = false }) {
|
|
45
|
-
|
|
46
|
+
installPolyfills();
|
|
46
47
|
|
|
47
48
|
const { paths } = config.kit;
|
|
48
49
|
const base = paths.base;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import 'node:fs';
|
|
2
2
|
import 'node:path';
|
|
3
3
|
import { MessageChannel } from 'node:worker_threads';
|
|
4
|
-
import { F as FormData, a as File } from '../
|
|
4
|
+
import { F as FormData, a as File } from '../node/polyfills.js';
|
|
5
5
|
import 'node:http';
|
|
6
6
|
import 'node:https';
|
|
7
7
|
import 'node:zlib';
|
|
@@ -9,6 +9,7 @@ import 'node:stream';
|
|
|
9
9
|
import 'node:util';
|
|
10
10
|
import 'node:url';
|
|
11
11
|
import 'net';
|
|
12
|
+
import 'crypto';
|
|
12
13
|
|
|
13
14
|
globalThis.DOMException || (() => {
|
|
14
15
|
const port = new MessageChannel().port1;
|
package/dist/cli.js
CHANGED
|
@@ -904,7 +904,7 @@ async function launch(port, https, base) {
|
|
|
904
904
|
exec(`${cmd} ${https ? 'https' : 'http'}://localhost:${port}${base}`);
|
|
905
905
|
}
|
|
906
906
|
|
|
907
|
-
const prog = sade('svelte-kit').version('1.0.0-next.
|
|
907
|
+
const prog = sade('svelte-kit').version('1.0.0-next.341');
|
|
908
908
|
|
|
909
909
|
prog
|
|
910
910
|
.command('dev')
|
|
@@ -926,10 +926,7 @@ prog
|
|
|
926
926
|
async function start(config) {
|
|
927
927
|
const { dev } = await import('./chunks/index.js');
|
|
928
928
|
|
|
929
|
-
const cwd = process.cwd();
|
|
930
|
-
|
|
931
929
|
const { address_info, server_config, close } = await dev({
|
|
932
|
-
cwd,
|
|
933
930
|
port,
|
|
934
931
|
host,
|
|
935
932
|
https,
|
|
@@ -943,8 +940,7 @@ prog
|
|
|
943
940
|
open: first && (open || !!server_config.open),
|
|
944
941
|
base: config.kit.paths.base,
|
|
945
942
|
loose: server_config.fs.strict === false,
|
|
946
|
-
allow: server_config.fs.allow
|
|
947
|
-
cwd
|
|
943
|
+
allow: server_config.fs.allow
|
|
948
944
|
});
|
|
949
945
|
|
|
950
946
|
first = false;
|
|
@@ -1126,7 +1122,7 @@ async function check_port(port) {
|
|
|
1126
1122
|
function welcome({ port, host, https, open, base, loose, allow, cwd }) {
|
|
1127
1123
|
if (open) launch(port, https, base);
|
|
1128
1124
|
|
|
1129
|
-
console.log($.bold().cyan(`\n SvelteKit v${'1.0.0-next.
|
|
1125
|
+
console.log($.bold().cyan(`\n SvelteKit v${'1.0.0-next.341'}\n`));
|
|
1130
1126
|
|
|
1131
1127
|
const protocol = https ? 'https:' : 'http:';
|
|
1132
1128
|
const exposed = typeof host !== 'undefined' && host !== 'localhost' && host !== '127.0.0.1';
|
|
@@ -5,6 +5,9 @@ import Stream, { PassThrough, pipeline } from 'node:stream';
|
|
|
5
5
|
import { types, deprecate } from 'node:util';
|
|
6
6
|
import { format } from 'node:url';
|
|
7
7
|
import { isIP } from 'net';
|
|
8
|
+
import { webcrypto } from 'crypto';
|
|
9
|
+
|
|
10
|
+
var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
|
|
8
11
|
|
|
9
12
|
/**
|
|
10
13
|
* Returns a `Buffer` instance from the given data URI `uri`.
|
|
@@ -58,8 +61,6 @@ function dataUriToBuffer(uri) {
|
|
|
58
61
|
return buffer;
|
|
59
62
|
}
|
|
60
63
|
|
|
61
|
-
var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
|
|
62
|
-
|
|
63
64
|
var ponyfill_es2018 = {exports: {}};
|
|
64
65
|
|
|
65
66
|
/**
|
|
@@ -4840,7 +4841,7 @@ class Body {
|
|
|
4840
4841
|
return formData;
|
|
4841
4842
|
}
|
|
4842
4843
|
|
|
4843
|
-
const {toFormData} = await import('
|
|
4844
|
+
const {toFormData} = await import('../chunks/multipart-parser.js');
|
|
4844
4845
|
return toFormData(this.body, ct);
|
|
4845
4846
|
}
|
|
4846
4847
|
|
|
@@ -6489,30 +6490,25 @@ function fixResponseChunkedTransferBadEnding(request, errorCallback) {
|
|
|
6489
6490
|
});
|
|
6490
6491
|
}
|
|
6491
6492
|
|
|
6493
|
+
/** @type {Record<string, any>} */
|
|
6494
|
+
const globals = {
|
|
6495
|
+
crypto: webcrypto,
|
|
6496
|
+
fetch,
|
|
6497
|
+
Response,
|
|
6498
|
+
Request,
|
|
6499
|
+
Headers
|
|
6500
|
+
};
|
|
6501
|
+
|
|
6492
6502
|
// exported for dev/preview and node environments
|
|
6493
|
-
function
|
|
6494
|
-
|
|
6495
|
-
fetch
|
|
6496
|
-
|
|
6497
|
-
configurable: true,
|
|
6498
|
-
value: fetch
|
|
6499
|
-
},
|
|
6500
|
-
Response: {
|
|
6503
|
+
function installPolyfills() {
|
|
6504
|
+
for (const name in globals) {
|
|
6505
|
+
// TODO use built-in fetch once https://github.com/nodejs/undici/issues/1262 is resolved
|
|
6506
|
+
Object.defineProperty(globalThis, name, {
|
|
6501
6507
|
enumerable: true,
|
|
6502
6508
|
configurable: true,
|
|
6503
|
-
value:
|
|
6504
|
-
}
|
|
6505
|
-
|
|
6506
|
-
enumerable: true,
|
|
6507
|
-
configurable: true,
|
|
6508
|
-
value: Request
|
|
6509
|
-
},
|
|
6510
|
-
Headers: {
|
|
6511
|
-
enumerable: true,
|
|
6512
|
-
configurable: true,
|
|
6513
|
-
value: Headers
|
|
6514
|
-
}
|
|
6515
|
-
});
|
|
6509
|
+
value: globals[name]
|
|
6510
|
+
});
|
|
6511
|
+
}
|
|
6516
6512
|
}
|
|
6517
6513
|
|
|
6518
|
-
export { FormData as F, File as a, commonjsGlobal as c,
|
|
6514
|
+
export { FormData as F, File as a, commonjsGlobal as c, installPolyfills };
|
package/dist/node.js
CHANGED
|
@@ -1,5 +1,208 @@
|
|
|
1
1
|
import { Readable } from 'stream';
|
|
2
2
|
|
|
3
|
+
var setCookie = {exports: {}};
|
|
4
|
+
|
|
5
|
+
var defaultParseOptions = {
|
|
6
|
+
decodeValues: true,
|
|
7
|
+
map: false,
|
|
8
|
+
silent: false,
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
function isNonEmptyString(str) {
|
|
12
|
+
return typeof str === "string" && !!str.trim();
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
function parseString(setCookieValue, options) {
|
|
16
|
+
var parts = setCookieValue.split(";").filter(isNonEmptyString);
|
|
17
|
+
var nameValue = parts.shift().split("=");
|
|
18
|
+
var name = nameValue.shift();
|
|
19
|
+
var value = nameValue.join("="); // everything after the first =, joined by a "=" if there was more than one part
|
|
20
|
+
|
|
21
|
+
options = options
|
|
22
|
+
? Object.assign({}, defaultParseOptions, options)
|
|
23
|
+
: defaultParseOptions;
|
|
24
|
+
|
|
25
|
+
try {
|
|
26
|
+
value = options.decodeValues ? decodeURIComponent(value) : value; // decode cookie value
|
|
27
|
+
} catch (e) {
|
|
28
|
+
console.error(
|
|
29
|
+
"set-cookie-parser encountered an error while decoding a cookie with value '" +
|
|
30
|
+
value +
|
|
31
|
+
"'. Set options.decodeValues to false to disable this feature.",
|
|
32
|
+
e
|
|
33
|
+
);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
var cookie = {
|
|
37
|
+
name: name, // grab everything before the first =
|
|
38
|
+
value: value,
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
parts.forEach(function (part) {
|
|
42
|
+
var sides = part.split("=");
|
|
43
|
+
var key = sides.shift().trimLeft().toLowerCase();
|
|
44
|
+
var value = sides.join("=");
|
|
45
|
+
if (key === "expires") {
|
|
46
|
+
cookie.expires = new Date(value);
|
|
47
|
+
} else if (key === "max-age") {
|
|
48
|
+
cookie.maxAge = parseInt(value, 10);
|
|
49
|
+
} else if (key === "secure") {
|
|
50
|
+
cookie.secure = true;
|
|
51
|
+
} else if (key === "httponly") {
|
|
52
|
+
cookie.httpOnly = true;
|
|
53
|
+
} else if (key === "samesite") {
|
|
54
|
+
cookie.sameSite = value;
|
|
55
|
+
} else {
|
|
56
|
+
cookie[key] = value;
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
return cookie;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
function parse(input, options) {
|
|
64
|
+
options = options
|
|
65
|
+
? Object.assign({}, defaultParseOptions, options)
|
|
66
|
+
: defaultParseOptions;
|
|
67
|
+
|
|
68
|
+
if (!input) {
|
|
69
|
+
if (!options.map) {
|
|
70
|
+
return [];
|
|
71
|
+
} else {
|
|
72
|
+
return {};
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
if (input.headers && input.headers["set-cookie"]) {
|
|
77
|
+
// fast-path for node.js (which automatically normalizes header names to lower-case
|
|
78
|
+
input = input.headers["set-cookie"];
|
|
79
|
+
} else if (input.headers) {
|
|
80
|
+
// slow-path for other environments - see #25
|
|
81
|
+
var sch =
|
|
82
|
+
input.headers[
|
|
83
|
+
Object.keys(input.headers).find(function (key) {
|
|
84
|
+
return key.toLowerCase() === "set-cookie";
|
|
85
|
+
})
|
|
86
|
+
];
|
|
87
|
+
// warn if called on a request-like object with a cookie header rather than a set-cookie header - see #34, 36
|
|
88
|
+
if (!sch && input.headers.cookie && !options.silent) {
|
|
89
|
+
console.warn(
|
|
90
|
+
"Warning: set-cookie-parser appears to have been called on a request object. It is designed to parse Set-Cookie headers from responses, not Cookie headers from requests. Set the option {silent: true} to suppress this warning."
|
|
91
|
+
);
|
|
92
|
+
}
|
|
93
|
+
input = sch;
|
|
94
|
+
}
|
|
95
|
+
if (!Array.isArray(input)) {
|
|
96
|
+
input = [input];
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
options = options
|
|
100
|
+
? Object.assign({}, defaultParseOptions, options)
|
|
101
|
+
: defaultParseOptions;
|
|
102
|
+
|
|
103
|
+
if (!options.map) {
|
|
104
|
+
return input.filter(isNonEmptyString).map(function (str) {
|
|
105
|
+
return parseString(str, options);
|
|
106
|
+
});
|
|
107
|
+
} else {
|
|
108
|
+
var cookies = {};
|
|
109
|
+
return input.filter(isNonEmptyString).reduce(function (cookies, str) {
|
|
110
|
+
var cookie = parseString(str, options);
|
|
111
|
+
cookies[cookie.name] = cookie;
|
|
112
|
+
return cookies;
|
|
113
|
+
}, cookies);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/*
|
|
118
|
+
Set-Cookie header field-values are sometimes comma joined in one string. This splits them without choking on commas
|
|
119
|
+
that are within a single set-cookie field-value, such as in the Expires portion.
|
|
120
|
+
|
|
121
|
+
This is uncommon, but explicitly allowed - see https://tools.ietf.org/html/rfc2616#section-4.2
|
|
122
|
+
Node.js does this for every header *except* set-cookie - see https://github.com/nodejs/node/blob/d5e363b77ebaf1caf67cd7528224b651c86815c1/lib/_http_incoming.js#L128
|
|
123
|
+
React Native's fetch does this for *every* header, including set-cookie.
|
|
124
|
+
|
|
125
|
+
Based on: https://github.com/google/j2objc/commit/16820fdbc8f76ca0c33472810ce0cb03d20efe25
|
|
126
|
+
Credits to: https://github.com/tomball for original and https://github.com/chrusart for JavaScript implementation
|
|
127
|
+
*/
|
|
128
|
+
function splitCookiesString(cookiesString) {
|
|
129
|
+
if (Array.isArray(cookiesString)) {
|
|
130
|
+
return cookiesString;
|
|
131
|
+
}
|
|
132
|
+
if (typeof cookiesString !== "string") {
|
|
133
|
+
return [];
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
var cookiesStrings = [];
|
|
137
|
+
var pos = 0;
|
|
138
|
+
var start;
|
|
139
|
+
var ch;
|
|
140
|
+
var lastComma;
|
|
141
|
+
var nextStart;
|
|
142
|
+
var cookiesSeparatorFound;
|
|
143
|
+
|
|
144
|
+
function skipWhitespace() {
|
|
145
|
+
while (pos < cookiesString.length && /\s/.test(cookiesString.charAt(pos))) {
|
|
146
|
+
pos += 1;
|
|
147
|
+
}
|
|
148
|
+
return pos < cookiesString.length;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
function notSpecialChar() {
|
|
152
|
+
ch = cookiesString.charAt(pos);
|
|
153
|
+
|
|
154
|
+
return ch !== "=" && ch !== ";" && ch !== ",";
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
while (pos < cookiesString.length) {
|
|
158
|
+
start = pos;
|
|
159
|
+
cookiesSeparatorFound = false;
|
|
160
|
+
|
|
161
|
+
while (skipWhitespace()) {
|
|
162
|
+
ch = cookiesString.charAt(pos);
|
|
163
|
+
if (ch === ",") {
|
|
164
|
+
// ',' is a cookie separator if we have later first '=', not ';' or ','
|
|
165
|
+
lastComma = pos;
|
|
166
|
+
pos += 1;
|
|
167
|
+
|
|
168
|
+
skipWhitespace();
|
|
169
|
+
nextStart = pos;
|
|
170
|
+
|
|
171
|
+
while (pos < cookiesString.length && notSpecialChar()) {
|
|
172
|
+
pos += 1;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
// currently special character
|
|
176
|
+
if (pos < cookiesString.length && cookiesString.charAt(pos) === "=") {
|
|
177
|
+
// we found cookies separator
|
|
178
|
+
cookiesSeparatorFound = true;
|
|
179
|
+
// pos is inside the next cookie, so back up and return it.
|
|
180
|
+
pos = nextStart;
|
|
181
|
+
cookiesStrings.push(cookiesString.substring(start, lastComma));
|
|
182
|
+
start = pos;
|
|
183
|
+
} else {
|
|
184
|
+
// in param ',' or param separator ';',
|
|
185
|
+
// we continue from that comma
|
|
186
|
+
pos = lastComma + 1;
|
|
187
|
+
}
|
|
188
|
+
} else {
|
|
189
|
+
pos += 1;
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
if (!cookiesSeparatorFound || pos >= cookiesString.length) {
|
|
194
|
+
cookiesStrings.push(cookiesString.substring(start, cookiesString.length));
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
return cookiesStrings;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
setCookie.exports = parse;
|
|
202
|
+
setCookie.exports.parse = parse;
|
|
203
|
+
setCookie.exports.parseString = parseString;
|
|
204
|
+
var splitCookiesString_1 = setCookie.exports.splitCookiesString = splitCookiesString;
|
|
205
|
+
|
|
3
206
|
/** @param {import('http').IncomingMessage} req */
|
|
4
207
|
function get_raw_body(req) {
|
|
5
208
|
return new Promise((fulfil, reject) => {
|
|
@@ -56,6 +259,7 @@ async function getRequest(base, req) {
|
|
|
56
259
|
if (req.httpVersionMajor === 2) {
|
|
57
260
|
// we need to strip out the HTTP/2 pseudo-headers because node-fetch's
|
|
58
261
|
// Request implementation doesn't like them
|
|
262
|
+
// TODO is this still true with Node 18
|
|
59
263
|
headers = Object.assign({}, headers);
|
|
60
264
|
delete headers[':method'];
|
|
61
265
|
delete headers[':path'];
|
|
@@ -74,8 +278,11 @@ async function setResponse(res, response) {
|
|
|
74
278
|
const headers = Object.fromEntries(response.headers);
|
|
75
279
|
|
|
76
280
|
if (response.headers.has('set-cookie')) {
|
|
77
|
-
|
|
78
|
-
|
|
281
|
+
const header = /** @type {string} */ (response.headers.get('set-cookie'));
|
|
282
|
+
const split = splitCookiesString_1(header);
|
|
283
|
+
|
|
284
|
+
// @ts-expect-error
|
|
285
|
+
headers['set-cookie'] = split;
|
|
79
286
|
}
|
|
80
287
|
|
|
81
288
|
res.writeHead(response.status, headers);
|
|
@@ -84,7 +291,7 @@ async function setResponse(res, response) {
|
|
|
84
291
|
response.body.pipe(res);
|
|
85
292
|
} else {
|
|
86
293
|
if (response.body) {
|
|
87
|
-
res.write(await response.arrayBuffer());
|
|
294
|
+
res.write(new Uint8Array(await response.arrayBuffer()));
|
|
88
295
|
}
|
|
89
296
|
|
|
90
297
|
res.end();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sveltejs/kit",
|
|
3
|
-
"version": "1.0.0-next.
|
|
3
|
+
"version": "1.0.0-next.341",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "https://github.com/sveltejs/kit",
|
|
@@ -52,11 +52,11 @@
|
|
|
52
52
|
"./node": {
|
|
53
53
|
"import": "./dist/node.js"
|
|
54
54
|
},
|
|
55
|
+
"./node/polyfills": {
|
|
56
|
+
"import": "./dist/node/polyfills.js"
|
|
57
|
+
},
|
|
55
58
|
"./hooks": {
|
|
56
59
|
"import": "./dist/hooks.js"
|
|
57
|
-
},
|
|
58
|
-
"./install-fetch": {
|
|
59
|
-
"import": "./dist/install-fetch.js"
|
|
60
60
|
}
|
|
61
61
|
},
|
|
62
62
|
"types": "types/index.d.ts",
|
package/types/ambient.d.ts
CHANGED
|
@@ -283,11 +283,16 @@ declare module '@sveltejs/kit/hooks' {
|
|
|
283
283
|
/**
|
|
284
284
|
* A polyfill for `fetch` and its related interfaces, used by adapters for environments that don't provide a native implementation.
|
|
285
285
|
*/
|
|
286
|
-
declare module '@sveltejs/kit/
|
|
286
|
+
declare module '@sveltejs/kit/node/polyfills' {
|
|
287
287
|
/**
|
|
288
|
-
* Make
|
|
288
|
+
* Make various web APIs available as globals:
|
|
289
|
+
* - `crypto`
|
|
290
|
+
* - `fetch`
|
|
291
|
+
* - `Headers`
|
|
292
|
+
* - `Request`
|
|
293
|
+
* - `Response`
|
|
289
294
|
*/
|
|
290
|
-
export function
|
|
295
|
+
export function installPolyfills(): void;
|
|
291
296
|
}
|
|
292
297
|
|
|
293
298
|
/**
|