@sveltejs/kit 1.0.0-next.37 → 1.0.0-next.372

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 (64) hide show
  1. package/README.md +12 -9
  2. package/assets/app/env.js +28 -0
  3. package/assets/app/navigation.js +24 -0
  4. package/assets/app/paths.js +1 -0
  5. package/assets/app/stores.js +97 -0
  6. package/assets/client/singletons.js +13 -0
  7. package/assets/client/start.js +1796 -0
  8. package/assets/components/error.svelte +18 -2
  9. package/assets/env.js +8 -0
  10. package/assets/paths.js +13 -0
  11. package/assets/server/index.js +3526 -0
  12. package/dist/chunks/_commonjsHelpers.js +3 -0
  13. package/dist/chunks/error.js +664 -0
  14. package/dist/chunks/index.js +15744 -0
  15. package/dist/chunks/index2.js +210 -0
  16. package/dist/chunks/multipart-parser.js +445 -0
  17. package/dist/chunks/sync.js +992 -0
  18. package/dist/chunks/write_tsconfig.js +274 -0
  19. package/dist/cli.js +66 -127
  20. package/dist/hooks.js +28 -0
  21. package/dist/node/polyfills.js +12237 -0
  22. package/dist/node.js +5869 -0
  23. package/dist/vite.js +3167 -0
  24. package/package.json +99 -55
  25. package/types/ambient.d.ts +345 -0
  26. package/types/index.d.ts +295 -0
  27. package/types/internal.d.ts +318 -0
  28. package/types/private.d.ts +235 -0
  29. package/CHANGELOG.md +0 -385
  30. package/assets/runtime/app/navigation.js +0 -23
  31. package/assets/runtime/app/navigation.js.map +0 -1
  32. package/assets/runtime/app/paths.js +0 -2
  33. package/assets/runtime/app/paths.js.map +0 -1
  34. package/assets/runtime/app/stores.js +0 -78
  35. package/assets/runtime/app/stores.js.map +0 -1
  36. package/assets/runtime/internal/singletons.js +0 -15
  37. package/assets/runtime/internal/singletons.js.map +0 -1
  38. package/assets/runtime/internal/start.js +0 -614
  39. package/assets/runtime/internal/start.js.map +0 -1
  40. package/assets/runtime/utils-85ebcc60.js +0 -18
  41. package/assets/runtime/utils-85ebcc60.js.map +0 -1
  42. package/dist/api.js +0 -28
  43. package/dist/api.js.map +0 -1
  44. package/dist/cli.js.map +0 -1
  45. package/dist/create_app.js +0 -502
  46. package/dist/create_app.js.map +0 -1
  47. package/dist/index.js +0 -327
  48. package/dist/index.js.map +0 -1
  49. package/dist/index2.js +0 -3497
  50. package/dist/index2.js.map +0 -1
  51. package/dist/index3.js +0 -295
  52. package/dist/index3.js.map +0 -1
  53. package/dist/index4.js +0 -311
  54. package/dist/index4.js.map +0 -1
  55. package/dist/index5.js +0 -221
  56. package/dist/index5.js.map +0 -1
  57. package/dist/index6.js +0 -732
  58. package/dist/index6.js.map +0 -1
  59. package/dist/renderer.js +0 -2429
  60. package/dist/renderer.js.map +0 -1
  61. package/dist/standard.js +0 -100
  62. package/dist/standard.js.map +0 -1
  63. package/dist/utils.js +0 -61
  64. package/dist/utils.js.map +0 -1
@@ -0,0 +1,210 @@
1
+ import { $ } from './error.js';
2
+ import { r as rimraf, m as mkdirp, c as copy } from './write_tsconfig.js';
3
+ import { g as generate_manifest } from '../vite.js';
4
+ import 'fs';
5
+ import 'path';
6
+ import 'url';
7
+ import '@sveltejs/vite-plugin-svelte';
8
+ import 'vite';
9
+ import './sync.js';
10
+ import '../node/polyfills.js';
11
+ import 'assert';
12
+ import 'net';
13
+ import 'http';
14
+ import 'stream';
15
+ import 'buffer';
16
+ import 'util';
17
+ import 'stream/web';
18
+ import 'perf_hooks';
19
+ import 'util/types';
20
+ import 'events';
21
+ import 'tls';
22
+ import './_commonjsHelpers.js';
23
+ import 'async_hooks';
24
+ import 'console';
25
+ import 'zlib';
26
+ import 'crypto';
27
+ import 'querystring';
28
+ import '../node.js';
29
+ import 'node:http';
30
+ import 'node:https';
31
+ import 'node:zlib';
32
+ import 'node:stream';
33
+ import 'node:buffer';
34
+ import 'node:util';
35
+ import 'node:url';
36
+ import 'node:net';
37
+ import 'node:fs';
38
+ import 'node:path';
39
+
40
+ /**
41
+ * Creates the Builder which is passed to adapters for building the application.
42
+ * @param {{
43
+ * config: import('types').ValidatedConfig;
44
+ * build_data: import('types').BuildData;
45
+ * prerendered: import('types').Prerendered;
46
+ * log: import('types').Logger;
47
+ * }} opts
48
+ * @returns {import('types').Builder}
49
+ */
50
+ function create_builder({ config, build_data, prerendered, log }) {
51
+ /** @type {Set<string>} */
52
+ const prerendered_paths = new Set(prerendered.paths);
53
+
54
+ /** @param {import('types').RouteData} route */
55
+ // TODO routes should come pre-filtered
56
+ function not_prerendered(route) {
57
+ if (route.type === 'page' && route.path) {
58
+ return !prerendered_paths.has(route.path);
59
+ }
60
+
61
+ return true;
62
+ }
63
+
64
+ return {
65
+ log,
66
+ rimraf,
67
+ mkdirp,
68
+ copy,
69
+
70
+ config,
71
+ prerendered,
72
+
73
+ async createEntries(fn) {
74
+ const { routes } = build_data.manifest_data;
75
+
76
+ /** @type {import('types').RouteDefinition[]} */
77
+ const facades = routes.map((route) => ({
78
+ id: route.id,
79
+ type: route.type,
80
+ segments: route.id.split('/').map((segment) => ({
81
+ dynamic: segment.includes('['),
82
+ rest: segment.includes('[...'),
83
+ content: segment
84
+ })),
85
+ pattern: route.pattern,
86
+ methods: route.type === 'page' ? ['get'] : build_data.server.methods[route.file]
87
+ }));
88
+
89
+ const seen = new Set();
90
+
91
+ for (let i = 0; i < routes.length; i += 1) {
92
+ const route = routes[i];
93
+ const { id, filter, complete } = fn(facades[i]);
94
+
95
+ if (seen.has(id)) continue;
96
+ seen.add(id);
97
+
98
+ const group = [route];
99
+
100
+ // figure out which lower priority routes should be considered fallbacks
101
+ for (let j = i + 1; j < routes.length; j += 1) {
102
+ if (filter(facades[j])) {
103
+ group.push(routes[j]);
104
+ }
105
+ }
106
+
107
+ const filtered = new Set(group.filter(not_prerendered));
108
+
109
+ // heuristic: if /foo/[bar] is included, /foo/[bar].json should
110
+ // also be included, since the page likely needs the endpoint
111
+ filtered.forEach((route) => {
112
+ if (route.type === 'page') {
113
+ const endpoint = routes.find((candidate) => candidate.id === route.id + '.json');
114
+
115
+ if (endpoint) {
116
+ filtered.add(endpoint);
117
+ }
118
+ }
119
+ });
120
+
121
+ if (filtered.size > 0) {
122
+ await complete({
123
+ generateManifest: ({ relativePath, format }) =>
124
+ generate_manifest({
125
+ build_data,
126
+ relative_path: relativePath,
127
+ routes: Array.from(filtered),
128
+ format
129
+ })
130
+ });
131
+ }
132
+ }
133
+ },
134
+
135
+ generateManifest: ({ relativePath, format }) => {
136
+ return generate_manifest({
137
+ build_data,
138
+ relative_path: relativePath,
139
+ routes: build_data.manifest_data.routes.filter(not_prerendered),
140
+ format
141
+ });
142
+ },
143
+
144
+ getBuildDirectory(name) {
145
+ return `${config.kit.outDir}/${name}`;
146
+ },
147
+
148
+ getClientDirectory() {
149
+ return `${config.kit.outDir}/output/client`;
150
+ },
151
+
152
+ getServerDirectory() {
153
+ return `${config.kit.outDir}/output/server`;
154
+ },
155
+
156
+ getStaticDirectory() {
157
+ return config.kit.files.assets;
158
+ },
159
+
160
+ writeClient(dest) {
161
+ return copy(`${config.kit.outDir}/output/client`, dest);
162
+ },
163
+
164
+ writePrerendered(dest, { fallback } = {}) {
165
+ const source = `${config.kit.outDir}/output/prerendered`;
166
+ const files = [...copy(`${source}/pages`, dest), ...copy(`${source}/dependencies`, dest)];
167
+
168
+ if (fallback) {
169
+ files.push(fallback);
170
+ copy(`${source}/fallback.html`, `${dest}/${fallback}`);
171
+ }
172
+
173
+ return files;
174
+ },
175
+
176
+ writeServer(dest) {
177
+ return copy(`${config.kit.outDir}/output/server`, dest);
178
+ },
179
+
180
+ writeStatic(dest) {
181
+ return copy(config.kit.files.assets, dest);
182
+ },
183
+
184
+ // @ts-expect-error
185
+ async prerender() {
186
+ throw new Error(
187
+ 'builder.prerender() has been removed. Prerendering now takes place in the build phase — see builder.prerender and builder.writePrerendered'
188
+ );
189
+ }
190
+ };
191
+ }
192
+
193
+ /**
194
+ * @param {import('types').ValidatedConfig} config
195
+ * @param {import('types').BuildData} build_data
196
+ * @param {import('types').Prerendered} prerendered
197
+ * @param {{ log: import('types').Logger }} opts
198
+ */
199
+ async function adapt(config, build_data, prerendered, { log }) {
200
+ const { name, adapt } = config.kit.adapter;
201
+
202
+ console.log($.bold().cyan(`\n> Using ${name}`));
203
+
204
+ const builder = create_builder({ config, build_data, prerendered, log });
205
+ await adapt(builder);
206
+
207
+ log.success('done');
208
+ }
209
+
210
+ export { adapt };
@@ -0,0 +1,445 @@
1
+ import 'node:fs';
2
+ import 'node:path';
3
+ import { F as FormData, a as File } from '../node.js';
4
+ import 'node:http';
5
+ import 'node:https';
6
+ import 'node:zlib';
7
+ import 'node:stream';
8
+ import 'node:buffer';
9
+ import 'node:util';
10
+ import './_commonjsHelpers.js';
11
+ import 'node:url';
12
+ import 'node:net';
13
+ import 'stream';
14
+
15
+ let s = 0;
16
+ const S = {
17
+ START_BOUNDARY: s++,
18
+ HEADER_FIELD_START: s++,
19
+ HEADER_FIELD: s++,
20
+ HEADER_VALUE_START: s++,
21
+ HEADER_VALUE: s++,
22
+ HEADER_VALUE_ALMOST_DONE: s++,
23
+ HEADERS_ALMOST_DONE: s++,
24
+ PART_DATA_START: s++,
25
+ PART_DATA: s++,
26
+ END: s++
27
+ };
28
+
29
+ let f = 1;
30
+ const F = {
31
+ PART_BOUNDARY: f,
32
+ LAST_BOUNDARY: f *= 2
33
+ };
34
+
35
+ const LF = 10;
36
+ const CR = 13;
37
+ const SPACE = 32;
38
+ const HYPHEN = 45;
39
+ const COLON = 58;
40
+ const A = 97;
41
+ const Z = 122;
42
+
43
+ const lower = c => c | 0x20;
44
+
45
+ const noop = () => {};
46
+
47
+ class MultipartParser {
48
+ /**
49
+ * @param {string} boundary
50
+ */
51
+ constructor(boundary) {
52
+ this.index = 0;
53
+ this.flags = 0;
54
+
55
+ this.onHeaderEnd = noop;
56
+ this.onHeaderField = noop;
57
+ this.onHeadersEnd = noop;
58
+ this.onHeaderValue = noop;
59
+ this.onPartBegin = noop;
60
+ this.onPartData = noop;
61
+ this.onPartEnd = noop;
62
+
63
+ this.boundaryChars = {};
64
+
65
+ boundary = '\r\n--' + boundary;
66
+ const ui8a = new Uint8Array(boundary.length);
67
+ for (let i = 0; i < boundary.length; i++) {
68
+ ui8a[i] = boundary.charCodeAt(i);
69
+ this.boundaryChars[ui8a[i]] = true;
70
+ }
71
+
72
+ this.boundary = ui8a;
73
+ this.lookbehind = new Uint8Array(this.boundary.length + 8);
74
+ this.state = S.START_BOUNDARY;
75
+ }
76
+
77
+ /**
78
+ * @param {Uint8Array} data
79
+ */
80
+ write(data) {
81
+ let i = 0;
82
+ const length_ = data.length;
83
+ let previousIndex = this.index;
84
+ let {lookbehind, boundary, boundaryChars, index, state, flags} = this;
85
+ const boundaryLength = this.boundary.length;
86
+ const boundaryEnd = boundaryLength - 1;
87
+ const bufferLength = data.length;
88
+ let c;
89
+ let cl;
90
+
91
+ const mark = name => {
92
+ this[name + 'Mark'] = i;
93
+ };
94
+
95
+ const clear = name => {
96
+ delete this[name + 'Mark'];
97
+ };
98
+
99
+ const callback = (callbackSymbol, start, end, ui8a) => {
100
+ if (start === undefined || start !== end) {
101
+ this[callbackSymbol](ui8a && ui8a.subarray(start, end));
102
+ }
103
+ };
104
+
105
+ const dataCallback = (name, clear) => {
106
+ const markSymbol = name + 'Mark';
107
+ if (!(markSymbol in this)) {
108
+ return;
109
+ }
110
+
111
+ if (clear) {
112
+ callback(name, this[markSymbol], i, data);
113
+ delete this[markSymbol];
114
+ } else {
115
+ callback(name, this[markSymbol], data.length, data);
116
+ this[markSymbol] = 0;
117
+ }
118
+ };
119
+
120
+ for (i = 0; i < length_; i++) {
121
+ c = data[i];
122
+
123
+ switch (state) {
124
+ case S.START_BOUNDARY:
125
+ if (index === boundary.length - 2) {
126
+ if (c === HYPHEN) {
127
+ flags |= F.LAST_BOUNDARY;
128
+ } else if (c !== CR) {
129
+ return;
130
+ }
131
+
132
+ index++;
133
+ break;
134
+ } else if (index - 1 === boundary.length - 2) {
135
+ if (flags & F.LAST_BOUNDARY && c === HYPHEN) {
136
+ state = S.END;
137
+ flags = 0;
138
+ } else if (!(flags & F.LAST_BOUNDARY) && c === LF) {
139
+ index = 0;
140
+ callback('onPartBegin');
141
+ state = S.HEADER_FIELD_START;
142
+ } else {
143
+ return;
144
+ }
145
+
146
+ break;
147
+ }
148
+
149
+ if (c !== boundary[index + 2]) {
150
+ index = -2;
151
+ }
152
+
153
+ if (c === boundary[index + 2]) {
154
+ index++;
155
+ }
156
+
157
+ break;
158
+ case S.HEADER_FIELD_START:
159
+ state = S.HEADER_FIELD;
160
+ mark('onHeaderField');
161
+ index = 0;
162
+ // falls through
163
+ case S.HEADER_FIELD:
164
+ if (c === CR) {
165
+ clear('onHeaderField');
166
+ state = S.HEADERS_ALMOST_DONE;
167
+ break;
168
+ }
169
+
170
+ index++;
171
+ if (c === HYPHEN) {
172
+ break;
173
+ }
174
+
175
+ if (c === COLON) {
176
+ if (index === 1) {
177
+ // empty header field
178
+ return;
179
+ }
180
+
181
+ dataCallback('onHeaderField', true);
182
+ state = S.HEADER_VALUE_START;
183
+ break;
184
+ }
185
+
186
+ cl = lower(c);
187
+ if (cl < A || cl > Z) {
188
+ return;
189
+ }
190
+
191
+ break;
192
+ case S.HEADER_VALUE_START:
193
+ if (c === SPACE) {
194
+ break;
195
+ }
196
+
197
+ mark('onHeaderValue');
198
+ state = S.HEADER_VALUE;
199
+ // falls through
200
+ case S.HEADER_VALUE:
201
+ if (c === CR) {
202
+ dataCallback('onHeaderValue', true);
203
+ callback('onHeaderEnd');
204
+ state = S.HEADER_VALUE_ALMOST_DONE;
205
+ }
206
+
207
+ break;
208
+ case S.HEADER_VALUE_ALMOST_DONE:
209
+ if (c !== LF) {
210
+ return;
211
+ }
212
+
213
+ state = S.HEADER_FIELD_START;
214
+ break;
215
+ case S.HEADERS_ALMOST_DONE:
216
+ if (c !== LF) {
217
+ return;
218
+ }
219
+
220
+ callback('onHeadersEnd');
221
+ state = S.PART_DATA_START;
222
+ break;
223
+ case S.PART_DATA_START:
224
+ state = S.PART_DATA;
225
+ mark('onPartData');
226
+ // falls through
227
+ case S.PART_DATA:
228
+ previousIndex = index;
229
+
230
+ if (index === 0) {
231
+ // boyer-moore derrived algorithm to safely skip non-boundary data
232
+ i += boundaryEnd;
233
+ while (i < bufferLength && !(data[i] in boundaryChars)) {
234
+ i += boundaryLength;
235
+ }
236
+
237
+ i -= boundaryEnd;
238
+ c = data[i];
239
+ }
240
+
241
+ if (index < boundary.length) {
242
+ if (boundary[index] === c) {
243
+ if (index === 0) {
244
+ dataCallback('onPartData', true);
245
+ }
246
+
247
+ index++;
248
+ } else {
249
+ index = 0;
250
+ }
251
+ } else if (index === boundary.length) {
252
+ index++;
253
+ if (c === CR) {
254
+ // CR = part boundary
255
+ flags |= F.PART_BOUNDARY;
256
+ } else if (c === HYPHEN) {
257
+ // HYPHEN = end boundary
258
+ flags |= F.LAST_BOUNDARY;
259
+ } else {
260
+ index = 0;
261
+ }
262
+ } else if (index - 1 === boundary.length) {
263
+ if (flags & F.PART_BOUNDARY) {
264
+ index = 0;
265
+ if (c === LF) {
266
+ // unset the PART_BOUNDARY flag
267
+ flags &= ~F.PART_BOUNDARY;
268
+ callback('onPartEnd');
269
+ callback('onPartBegin');
270
+ state = S.HEADER_FIELD_START;
271
+ break;
272
+ }
273
+ } else if (flags & F.LAST_BOUNDARY) {
274
+ if (c === HYPHEN) {
275
+ callback('onPartEnd');
276
+ state = S.END;
277
+ flags = 0;
278
+ } else {
279
+ index = 0;
280
+ }
281
+ } else {
282
+ index = 0;
283
+ }
284
+ }
285
+
286
+ if (index > 0) {
287
+ // when matching a possible boundary, keep a lookbehind reference
288
+ // in case it turns out to be a false lead
289
+ lookbehind[index - 1] = c;
290
+ } else if (previousIndex > 0) {
291
+ // if our boundary turned out to be rubbish, the captured lookbehind
292
+ // belongs to partData
293
+ const _lookbehind = new Uint8Array(lookbehind.buffer, lookbehind.byteOffset, lookbehind.byteLength);
294
+ callback('onPartData', 0, previousIndex, _lookbehind);
295
+ previousIndex = 0;
296
+ mark('onPartData');
297
+
298
+ // reconsider the current character even so it interrupted the sequence
299
+ // it could be the beginning of a new sequence
300
+ i--;
301
+ }
302
+
303
+ break;
304
+ case S.END:
305
+ break;
306
+ default:
307
+ throw new Error(`Unexpected state entered: ${state}`);
308
+ }
309
+ }
310
+
311
+ dataCallback('onHeaderField');
312
+ dataCallback('onHeaderValue');
313
+ dataCallback('onPartData');
314
+
315
+ // Update properties for the next call
316
+ this.index = index;
317
+ this.state = state;
318
+ this.flags = flags;
319
+ }
320
+
321
+ end() {
322
+ if ((this.state === S.HEADER_FIELD_START && this.index === 0) ||
323
+ (this.state === S.PART_DATA && this.index === this.boundary.length)) {
324
+ this.onPartEnd();
325
+ } else if (this.state !== S.END) {
326
+ throw new Error('MultipartParser.end(): stream ended unexpectedly');
327
+ }
328
+ }
329
+ }
330
+
331
+ function _fileName(headerValue) {
332
+ // matches either a quoted-string or a token (RFC 2616 section 19.5.1)
333
+ const m = headerValue.match(/\bfilename=("(.*?)"|([^()<>@,;:\\"/[\]?={}\s\t]+))($|;\s)/i);
334
+ if (!m) {
335
+ return;
336
+ }
337
+
338
+ const match = m[2] || m[3] || '';
339
+ let filename = match.slice(match.lastIndexOf('\\') + 1);
340
+ filename = filename.replace(/%22/g, '"');
341
+ filename = filename.replace(/&#(\d{4});/g, (m, code) => {
342
+ return String.fromCharCode(code);
343
+ });
344
+ return filename;
345
+ }
346
+
347
+ async function toFormData(Body, ct) {
348
+ if (!/multipart/i.test(ct)) {
349
+ throw new TypeError('Failed to fetch');
350
+ }
351
+
352
+ const m = ct.match(/boundary=(?:"([^"]+)"|([^;]+))/i);
353
+
354
+ if (!m) {
355
+ throw new TypeError('no or bad content-type header, no multipart boundary');
356
+ }
357
+
358
+ const parser = new MultipartParser(m[1] || m[2]);
359
+
360
+ let headerField;
361
+ let headerValue;
362
+ let entryValue;
363
+ let entryName;
364
+ let contentType;
365
+ let filename;
366
+ const entryChunks = [];
367
+ const formData = new FormData();
368
+
369
+ const onPartData = ui8a => {
370
+ entryValue += decoder.decode(ui8a, {stream: true});
371
+ };
372
+
373
+ const appendToFile = ui8a => {
374
+ entryChunks.push(ui8a);
375
+ };
376
+
377
+ const appendFileToFormData = () => {
378
+ const file = new File(entryChunks, filename, {type: contentType});
379
+ formData.append(entryName, file);
380
+ };
381
+
382
+ const appendEntryToFormData = () => {
383
+ formData.append(entryName, entryValue);
384
+ };
385
+
386
+ const decoder = new TextDecoder('utf-8');
387
+ decoder.decode();
388
+
389
+ parser.onPartBegin = function () {
390
+ parser.onPartData = onPartData;
391
+ parser.onPartEnd = appendEntryToFormData;
392
+
393
+ headerField = '';
394
+ headerValue = '';
395
+ entryValue = '';
396
+ entryName = '';
397
+ contentType = '';
398
+ filename = null;
399
+ entryChunks.length = 0;
400
+ };
401
+
402
+ parser.onHeaderField = function (ui8a) {
403
+ headerField += decoder.decode(ui8a, {stream: true});
404
+ };
405
+
406
+ parser.onHeaderValue = function (ui8a) {
407
+ headerValue += decoder.decode(ui8a, {stream: true});
408
+ };
409
+
410
+ parser.onHeaderEnd = function () {
411
+ headerValue += decoder.decode();
412
+ headerField = headerField.toLowerCase();
413
+
414
+ if (headerField === 'content-disposition') {
415
+ // matches either a quoted-string or a token (RFC 2616 section 19.5.1)
416
+ const m = headerValue.match(/\bname=("([^"]*)"|([^()<>@,;:\\"/[\]?={}\s\t]+))/i);
417
+
418
+ if (m) {
419
+ entryName = m[2] || m[3] || '';
420
+ }
421
+
422
+ filename = _fileName(headerValue);
423
+
424
+ if (filename) {
425
+ parser.onPartData = appendToFile;
426
+ parser.onPartEnd = appendFileToFormData;
427
+ }
428
+ } else if (headerField === 'content-type') {
429
+ contentType = headerValue;
430
+ }
431
+
432
+ headerValue = '';
433
+ headerField = '';
434
+ };
435
+
436
+ for await (const chunk of Body) {
437
+ parser.write(chunk);
438
+ }
439
+
440
+ parser.end();
441
+
442
+ return formData;
443
+ }
444
+
445
+ export { toFormData };