@sveltejs/kit 1.0.0-next.405 → 1.0.0-next.408

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 (99) hide show
  1. package/package.json +23 -25
  2. package/{dist → src}/cli.js +19 -18
  3. package/{dist/chunks/index3.js → src/core/adapt/builder.js} +6 -59
  4. package/src/core/adapt/index.js +19 -0
  5. package/src/core/config/index.js +86 -0
  6. package/{dist/chunks/index.js → src/core/config/options.js} +7 -194
  7. package/src/core/config/types.d.ts +1 -0
  8. package/src/core/constants.js +3 -0
  9. package/src/core/generate_manifest/index.js +99 -0
  10. package/src/core/prerender/crawl.js +194 -0
  11. package/src/core/prerender/prerender.js +378 -0
  12. package/src/core/prerender/queue.js +80 -0
  13. package/src/core/sync/create_manifest_data/index.js +492 -0
  14. package/src/core/sync/create_manifest_data/types.d.ts +40 -0
  15. package/src/core/sync/sync.js +59 -0
  16. package/src/core/sync/utils.js +97 -0
  17. package/src/core/sync/write_ambient.js +87 -0
  18. package/src/core/sync/write_client_manifest.js +82 -0
  19. package/src/core/sync/write_matchers.js +25 -0
  20. package/src/core/sync/write_root.js +88 -0
  21. package/{dist/chunks → src/core/sync}/write_tsconfig.js +24 -108
  22. package/src/core/sync/write_types.js +738 -0
  23. package/src/core/utils.js +58 -0
  24. package/{dist → src}/hooks.js +1 -3
  25. package/src/index/index.js +45 -0
  26. package/src/index/private.js +33 -0
  27. package/src/node/index.js +145 -0
  28. package/src/node/polyfills.js +40 -0
  29. package/src/packaging/index.js +218 -0
  30. package/src/packaging/types.d.ts +8 -0
  31. package/src/packaging/typescript.js +150 -0
  32. package/src/packaging/utils.js +143 -0
  33. package/{assets → src/runtime}/app/env.js +3 -5
  34. package/src/runtime/app/navigation.js +22 -0
  35. package/src/runtime/app/paths.js +1 -0
  36. package/{assets → src/runtime}/app/stores.js +6 -9
  37. package/src/runtime/client/ambient.d.ts +17 -0
  38. package/{assets/client/start.js → src/runtime/client/client.js} +302 -878
  39. package/src/runtime/client/fetcher.js +60 -0
  40. package/src/runtime/client/parse.js +36 -0
  41. package/{assets → src/runtime}/client/singletons.js +2 -4
  42. package/src/runtime/client/start.js +48 -0
  43. package/src/runtime/client/types.d.ts +106 -0
  44. package/src/runtime/client/utils.js +113 -0
  45. package/src/runtime/components/error.svelte +16 -0
  46. package/{assets → src/runtime}/components/layout.svelte +0 -0
  47. package/{assets → src/runtime}/env/dynamic/private.js +0 -0
  48. package/{assets → src/runtime}/env/dynamic/public.js +0 -0
  49. package/{assets → src/runtime}/env-private.js +2 -4
  50. package/{assets → src/runtime}/env-public.js +2 -4
  51. package/src/runtime/env.js +6 -0
  52. package/src/runtime/hash.js +16 -0
  53. package/{assets → src/runtime}/paths.js +3 -5
  54. package/src/runtime/server/endpoint.js +42 -0
  55. package/src/runtime/server/index.js +434 -0
  56. package/src/runtime/server/page/cookie.js +25 -0
  57. package/src/runtime/server/page/crypto.js +239 -0
  58. package/src/runtime/server/page/csp.js +249 -0
  59. package/src/runtime/server/page/fetch.js +265 -0
  60. package/src/runtime/server/page/index.js +418 -0
  61. package/src/runtime/server/page/load_data.js +94 -0
  62. package/src/runtime/server/page/render.js +357 -0
  63. package/src/runtime/server/page/respond_with_error.js +105 -0
  64. package/src/runtime/server/page/types.d.ts +44 -0
  65. package/src/runtime/server/utils.js +116 -0
  66. package/src/utils/error.js +22 -0
  67. package/src/utils/escape.js +104 -0
  68. package/{dist/chunks → src/utils}/filesystem.js +22 -24
  69. package/src/utils/http.js +55 -0
  70. package/src/utils/misc.js +1 -0
  71. package/src/utils/routing.js +107 -0
  72. package/src/utils/url.js +97 -0
  73. package/src/vite/build/build_server.js +335 -0
  74. package/src/vite/build/build_service_worker.js +90 -0
  75. package/src/vite/build/utils.js +153 -0
  76. package/src/vite/dev/index.js +565 -0
  77. package/src/vite/index.js +540 -0
  78. package/src/vite/preview/index.js +186 -0
  79. package/src/vite/types.d.ts +3 -0
  80. package/src/vite/utils.js +335 -0
  81. package/svelte-kit.js +1 -10
  82. package/types/ambient.d.ts +5 -12
  83. package/types/index.d.ts +86 -44
  84. package/types/internal.d.ts +50 -72
  85. package/types/private.d.ts +2 -1
  86. package/assets/app/navigation.js +0 -24
  87. package/assets/app/paths.js +0 -1
  88. package/assets/components/error.svelte +0 -29
  89. package/assets/env.js +0 -8
  90. package/assets/server/index.js +0 -3589
  91. package/dist/chunks/error.js +0 -12
  92. package/dist/chunks/index2.js +0 -15745
  93. package/dist/chunks/multipart-parser.js +0 -458
  94. package/dist/chunks/sync.js +0 -1366
  95. package/dist/chunks/utils.js +0 -66
  96. package/dist/node/polyfills.js +0 -17928
  97. package/dist/node.js +0 -348
  98. package/dist/prerender.js +0 -788
  99. package/dist/vite.js +0 -2513
package/dist/node.js DELETED
@@ -1,348 +0,0 @@
1
- var setCookie = {exports: {}};
2
-
3
- var defaultParseOptions = {
4
- decodeValues: true,
5
- map: false,
6
- silent: false,
7
- };
8
-
9
- function isNonEmptyString(str) {
10
- return typeof str === "string" && !!str.trim();
11
- }
12
-
13
- function parseString(setCookieValue, options) {
14
- var parts = setCookieValue.split(";").filter(isNonEmptyString);
15
- var nameValue = parts.shift().split("=");
16
- var name = nameValue.shift();
17
- var value = nameValue.join("="); // everything after the first =, joined by a "=" if there was more than one part
18
-
19
- options = options
20
- ? Object.assign({}, defaultParseOptions, options)
21
- : defaultParseOptions;
22
-
23
- try {
24
- value = options.decodeValues ? decodeURIComponent(value) : value; // decode cookie value
25
- } catch (e) {
26
- console.error(
27
- "set-cookie-parser encountered an error while decoding a cookie with value '" +
28
- value +
29
- "'. Set options.decodeValues to false to disable this feature.",
30
- e
31
- );
32
- }
33
-
34
- var cookie = {
35
- name: name, // grab everything before the first =
36
- value: value,
37
- };
38
-
39
- parts.forEach(function (part) {
40
- var sides = part.split("=");
41
- var key = sides.shift().trimLeft().toLowerCase();
42
- var value = sides.join("=");
43
- if (key === "expires") {
44
- cookie.expires = new Date(value);
45
- } else if (key === "max-age") {
46
- cookie.maxAge = parseInt(value, 10);
47
- } else if (key === "secure") {
48
- cookie.secure = true;
49
- } else if (key === "httponly") {
50
- cookie.httpOnly = true;
51
- } else if (key === "samesite") {
52
- cookie.sameSite = value;
53
- } else {
54
- cookie[key] = value;
55
- }
56
- });
57
-
58
- return cookie;
59
- }
60
-
61
- function parse(input, options) {
62
- options = options
63
- ? Object.assign({}, defaultParseOptions, options)
64
- : defaultParseOptions;
65
-
66
- if (!input) {
67
- if (!options.map) {
68
- return [];
69
- } else {
70
- return {};
71
- }
72
- }
73
-
74
- if (input.headers && input.headers["set-cookie"]) {
75
- // fast-path for node.js (which automatically normalizes header names to lower-case
76
- input = input.headers["set-cookie"];
77
- } else if (input.headers) {
78
- // slow-path for other environments - see #25
79
- var sch =
80
- input.headers[
81
- Object.keys(input.headers).find(function (key) {
82
- return key.toLowerCase() === "set-cookie";
83
- })
84
- ];
85
- // warn if called on a request-like object with a cookie header rather than a set-cookie header - see #34, 36
86
- if (!sch && input.headers.cookie && !options.silent) {
87
- console.warn(
88
- "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."
89
- );
90
- }
91
- input = sch;
92
- }
93
- if (!Array.isArray(input)) {
94
- input = [input];
95
- }
96
-
97
- options = options
98
- ? Object.assign({}, defaultParseOptions, options)
99
- : defaultParseOptions;
100
-
101
- if (!options.map) {
102
- return input.filter(isNonEmptyString).map(function (str) {
103
- return parseString(str, options);
104
- });
105
- } else {
106
- var cookies = {};
107
- return input.filter(isNonEmptyString).reduce(function (cookies, str) {
108
- var cookie = parseString(str, options);
109
- cookies[cookie.name] = cookie;
110
- return cookies;
111
- }, cookies);
112
- }
113
- }
114
-
115
- /*
116
- Set-Cookie header field-values are sometimes comma joined in one string. This splits them without choking on commas
117
- that are within a single set-cookie field-value, such as in the Expires portion.
118
-
119
- This is uncommon, but explicitly allowed - see https://tools.ietf.org/html/rfc2616#section-4.2
120
- Node.js does this for every header *except* set-cookie - see https://github.com/nodejs/node/blob/d5e363b77ebaf1caf67cd7528224b651c86815c1/lib/_http_incoming.js#L128
121
- React Native's fetch does this for *every* header, including set-cookie.
122
-
123
- Based on: https://github.com/google/j2objc/commit/16820fdbc8f76ca0c33472810ce0cb03d20efe25
124
- Credits to: https://github.com/tomball for original and https://github.com/chrusart for JavaScript implementation
125
- */
126
- function splitCookiesString(cookiesString) {
127
- if (Array.isArray(cookiesString)) {
128
- return cookiesString;
129
- }
130
- if (typeof cookiesString !== "string") {
131
- return [];
132
- }
133
-
134
- var cookiesStrings = [];
135
- var pos = 0;
136
- var start;
137
- var ch;
138
- var lastComma;
139
- var nextStart;
140
- var cookiesSeparatorFound;
141
-
142
- function skipWhitespace() {
143
- while (pos < cookiesString.length && /\s/.test(cookiesString.charAt(pos))) {
144
- pos += 1;
145
- }
146
- return pos < cookiesString.length;
147
- }
148
-
149
- function notSpecialChar() {
150
- ch = cookiesString.charAt(pos);
151
-
152
- return ch !== "=" && ch !== ";" && ch !== ",";
153
- }
154
-
155
- while (pos < cookiesString.length) {
156
- start = pos;
157
- cookiesSeparatorFound = false;
158
-
159
- while (skipWhitespace()) {
160
- ch = cookiesString.charAt(pos);
161
- if (ch === ",") {
162
- // ',' is a cookie separator if we have later first '=', not ';' or ','
163
- lastComma = pos;
164
- pos += 1;
165
-
166
- skipWhitespace();
167
- nextStart = pos;
168
-
169
- while (pos < cookiesString.length && notSpecialChar()) {
170
- pos += 1;
171
- }
172
-
173
- // currently special character
174
- if (pos < cookiesString.length && cookiesString.charAt(pos) === "=") {
175
- // we found cookies separator
176
- cookiesSeparatorFound = true;
177
- // pos is inside the next cookie, so back up and return it.
178
- pos = nextStart;
179
- cookiesStrings.push(cookiesString.substring(start, lastComma));
180
- start = pos;
181
- } else {
182
- // in param ',' or param separator ';',
183
- // we continue from that comma
184
- pos = lastComma + 1;
185
- }
186
- } else {
187
- pos += 1;
188
- }
189
- }
190
-
191
- if (!cookiesSeparatorFound || pos >= cookiesString.length) {
192
- cookiesStrings.push(cookiesString.substring(start, cookiesString.length));
193
- }
194
- }
195
-
196
- return cookiesStrings;
197
- }
198
-
199
- setCookie.exports = parse;
200
- setCookie.exports.parse = parse;
201
- setCookie.exports.parseString = parseString;
202
- var splitCookiesString_1 = setCookie.exports.splitCookiesString = splitCookiesString;
203
-
204
- /** @param {import('http').IncomingMessage} req */
205
- function get_raw_body(req) {
206
- const h = req.headers;
207
-
208
- if (!h['content-type']) {
209
- return null;
210
- }
211
-
212
- const length = Number(h['content-length']);
213
-
214
- // check if no request body
215
- // https://github.com/jshttp/type-is/blob/c1f4388c71c8a01f79934e68f630ca4a15fffcd6/index.js#L81-L95
216
- if (isNaN(length) && h['transfer-encoding'] == null) {
217
- return null;
218
- }
219
-
220
- if (req.destroyed) {
221
- const readable = new ReadableStream();
222
- readable.cancel();
223
- return readable;
224
- }
225
-
226
- let size = 0;
227
- let cancelled = false;
228
-
229
- return new ReadableStream({
230
- start(controller) {
231
- req.on('error', (error) => {
232
- controller.error(error);
233
- });
234
-
235
- req.on('end', () => {
236
- if (cancelled) return;
237
- controller.close();
238
- });
239
-
240
- req.on('data', (chunk) => {
241
- if (cancelled) return;
242
-
243
- size += chunk.length;
244
- if (size > length) {
245
- controller.error(new Error('content-length exceeded'));
246
- return;
247
- }
248
-
249
- controller.enqueue(chunk);
250
-
251
- if (controller.desiredSize === null || controller.desiredSize <= 0) {
252
- req.pause();
253
- }
254
- });
255
- },
256
-
257
- pull() {
258
- req.resume();
259
- },
260
-
261
- cancel(reason) {
262
- cancelled = true;
263
- req.destroy(reason);
264
- }
265
- });
266
- }
267
-
268
- /** @type {import('@sveltejs/kit/node').getRequest} */
269
- async function getRequest(base, req) {
270
- let headers = /** @type {Record<string, string>} */ (req.headers);
271
- if (req.httpVersionMajor === 2) {
272
- // we need to strip out the HTTP/2 pseudo-headers because node-fetch's
273
- // Request implementation doesn't like them
274
- // TODO is this still true with Node 18
275
- headers = Object.assign({}, headers);
276
- delete headers[':method'];
277
- delete headers[':path'];
278
- delete headers[':authority'];
279
- delete headers[':scheme'];
280
- }
281
-
282
- return new Request(base + req.url, {
283
- method: req.method,
284
- headers,
285
- body: get_raw_body(req)
286
- });
287
- }
288
-
289
- /** @type {import('@sveltejs/kit/node').setResponse} */
290
- async function setResponse(res, response) {
291
- const headers = Object.fromEntries(response.headers);
292
-
293
- if (response.headers.has('set-cookie')) {
294
- const header = /** @type {string} */ (response.headers.get('set-cookie'));
295
- const split = splitCookiesString_1(header);
296
-
297
- // @ts-expect-error
298
- headers['set-cookie'] = split;
299
- }
300
-
301
- res.writeHead(response.status, headers);
302
-
303
- if (!response.body) {
304
- res.end();
305
- return;
306
- }
307
-
308
- const reader = response.body.getReader();
309
-
310
- if (res.destroyed) {
311
- reader.cancel();
312
- return;
313
- }
314
-
315
- const cancel = (/** @type {Error|undefined} */ error) => {
316
- res.off('close', cancel);
317
- res.off('error', cancel);
318
-
319
- // If the reader has already been interrupted with an error earlier,
320
- // then it will appear here, it is useless, but it needs to be catch.
321
- reader.cancel(error).catch(() => {});
322
- if (error) res.destroy(error);
323
- };
324
-
325
- res.on('close', cancel);
326
- res.on('error', cancel);
327
-
328
- next();
329
- async function next() {
330
- try {
331
- for (;;) {
332
- const { done, value } = await reader.read();
333
-
334
- if (done) break;
335
-
336
- if (!res.write(value)) {
337
- res.once('drain', next);
338
- return;
339
- }
340
- }
341
- res.end();
342
- } catch (error) {
343
- cancel(error instanceof Error ? error : new Error(String(error)));
344
- }
345
- }
346
- }
347
-
348
- export { getRequest, setResponse };