@sveltejs/kit 1.0.0-next.29 → 1.0.0-next.290

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 (80) hide show
  1. package/README.md +12 -9
  2. package/assets/app/env.js +20 -0
  3. package/assets/app/navigation.js +79 -0
  4. package/assets/app/paths.js +1 -0
  5. package/assets/app/stores.js +97 -0
  6. package/assets/chunks/utils.js +13 -0
  7. package/assets/client/singletons.js +21 -0
  8. package/assets/client/start.js +1578 -0
  9. package/assets/components/error.svelte +18 -2
  10. package/assets/env.js +8 -0
  11. package/assets/paths.js +13 -0
  12. package/assets/server/index.js +2783 -0
  13. package/dist/chunks/amp_hook.js +56 -0
  14. package/dist/chunks/cert.js +28154 -0
  15. package/dist/chunks/constants.js +663 -0
  16. package/dist/chunks/index.js +509 -0
  17. package/dist/chunks/index2.js +653 -0
  18. package/dist/chunks/index3.js +120 -0
  19. package/dist/chunks/index4.js +892 -0
  20. package/dist/chunks/index5.js +160 -0
  21. package/dist/chunks/index6.js +15584 -0
  22. package/dist/chunks/index7.js +4207 -0
  23. package/dist/chunks/misc.js +3 -0
  24. package/dist/chunks/multipart-parser.js +449 -0
  25. package/dist/chunks/tsconfig.js +1032 -0
  26. package/dist/cli.js +1130 -86
  27. package/dist/hooks.js +28 -0
  28. package/dist/install-fetch.js +6518 -0
  29. package/dist/node.js +94 -0
  30. package/package.json +106 -54
  31. package/svelte-kit.js +2 -0
  32. package/types/ambient.d.ts +299 -0
  33. package/types/index.d.ts +164 -0
  34. package/types/internal.d.ts +313 -0
  35. package/types/private.d.ts +349 -0
  36. package/CHANGELOG.md +0 -332
  37. package/assets/runtime/app/navigation.js +0 -23
  38. package/assets/runtime/app/navigation.js.map +0 -1
  39. package/assets/runtime/app/paths.js +0 -2
  40. package/assets/runtime/app/paths.js.map +0 -1
  41. package/assets/runtime/app/stores.js +0 -78
  42. package/assets/runtime/app/stores.js.map +0 -1
  43. package/assets/runtime/internal/singletons.js +0 -15
  44. package/assets/runtime/internal/singletons.js.map +0 -1
  45. package/assets/runtime/internal/start.js +0 -591
  46. package/assets/runtime/internal/start.js.map +0 -1
  47. package/assets/runtime/utils-85ebcc60.js +0 -18
  48. package/assets/runtime/utils-85ebcc60.js.map +0 -1
  49. package/dist/api.js +0 -44
  50. package/dist/api.js.map +0 -1
  51. package/dist/build.js +0 -246
  52. package/dist/build.js.map +0 -1
  53. package/dist/cli.js.map +0 -1
  54. package/dist/colors.js +0 -37
  55. package/dist/colors.js.map +0 -1
  56. package/dist/create_app.js +0 -580
  57. package/dist/create_app.js.map +0 -1
  58. package/dist/index.js +0 -368
  59. package/dist/index.js.map +0 -1
  60. package/dist/index2.js +0 -12035
  61. package/dist/index2.js.map +0 -1
  62. package/dist/index3.js +0 -549
  63. package/dist/index3.js.map +0 -1
  64. package/dist/index4.js +0 -74
  65. package/dist/index4.js.map +0 -1
  66. package/dist/index5.js +0 -464
  67. package/dist/index5.js.map +0 -1
  68. package/dist/index6.js +0 -735
  69. package/dist/index6.js.map +0 -1
  70. package/dist/logging.js +0 -43
  71. package/dist/logging.js.map +0 -1
  72. package/dist/package.js +0 -432
  73. package/dist/package.js.map +0 -1
  74. package/dist/renderer.js +0 -2425
  75. package/dist/renderer.js.map +0 -1
  76. package/dist/standard.js +0 -101
  77. package/dist/standard.js.map +0 -1
  78. package/dist/utils.js +0 -58
  79. package/dist/utils.js.map +0 -1
  80. package/svelte-kit +0 -3
@@ -0,0 +1,160 @@
1
+ import fs__default from 'fs';
2
+ import http from 'http';
3
+ import https from 'https';
4
+ import { join } from 'path';
5
+ import { s as sirv, S as SVELTE_KIT_ASSETS } from './constants.js';
6
+ import { pathToFileURL } from 'url';
7
+ import { getRequest, setResponse } from '../node.js';
8
+ import { installFetch } from '../install-fetch.js';
9
+ import 'querystring';
10
+ import 'stream';
11
+ import 'node:http';
12
+ import 'node:https';
13
+ import 'node:zlib';
14
+ import 'node:stream';
15
+ import 'node:util';
16
+ import 'node:url';
17
+ import 'net';
18
+
19
+ /** @param {string} dir */
20
+ const mutable = (dir) =>
21
+ sirv(dir, {
22
+ etag: true,
23
+ maxAge: 0
24
+ });
25
+
26
+ /**
27
+ * @param {{
28
+ * port: number;
29
+ * host?: string;
30
+ * config: import('types').ValidatedConfig;
31
+ * https?: boolean;
32
+ * cwd?: string;
33
+ * }} opts
34
+ */
35
+ async function preview({ port, host, config, https: use_https = false }) {
36
+ installFetch();
37
+
38
+ const index_file = join(config.kit.outDir, 'output/server/index.js');
39
+ const manifest_file = join(config.kit.outDir, 'output/server/manifest.js');
40
+
41
+ /** @type {import('types').ServerModule} */
42
+ const { Server, override } = await import(pathToFileURL(index_file).href);
43
+
44
+ const { manifest } = await import(pathToFileURL(manifest_file).href);
45
+
46
+ /** @type {import('sirv').RequestHandler} */
47
+ const static_handler = fs__default.existsSync(config.kit.files.assets)
48
+ ? mutable(config.kit.files.assets)
49
+ : (_req, _res, next) => {
50
+ if (!next) throw new Error('No next() handler is available');
51
+ return next();
52
+ };
53
+
54
+ const assets_handler = sirv(join(config.kit.outDir, 'output/client'), {
55
+ maxAge: 31536000,
56
+ immutable: true
57
+ });
58
+
59
+ const has_asset_path = !!config.kit.paths.assets;
60
+
61
+ override({
62
+ paths: {
63
+ base: config.kit.paths.base,
64
+ assets: has_asset_path ? SVELTE_KIT_ASSETS : config.kit.paths.base
65
+ },
66
+ prerendering: false,
67
+ protocol: use_https ? 'https' : 'http',
68
+ read: (file) => fs__default.readFileSync(join(config.kit.files.assets, file))
69
+ });
70
+
71
+ const server = new Server(manifest);
72
+
73
+ /** @type {import('vite').UserConfig} */
74
+ const vite_config = (config.kit.vite && (await config.kit.vite())) || {};
75
+
76
+ const http_server = await get_server(use_https, vite_config, (req, res) => {
77
+ if (req.url == null) {
78
+ throw new Error('Invalid request url');
79
+ }
80
+
81
+ const initial_url = req.url;
82
+
83
+ const render_handler = async () => {
84
+ if (initial_url.startsWith(config.kit.paths.base)) {
85
+ const protocol = use_https ? 'https' : 'http';
86
+ const host = req.headers['host'];
87
+
88
+ let request;
89
+
90
+ try {
91
+ req.url = initial_url;
92
+ request = await getRequest(`${protocol}://${host}`, req);
93
+ } catch (/** @type {any} */ err) {
94
+ res.statusCode = err.status || 400;
95
+ return res.end(err.reason || 'Invalid request body');
96
+ }
97
+
98
+ setResponse(res, await server.respond(request));
99
+ } else {
100
+ res.statusCode = 404;
101
+ res.end('Not found');
102
+ }
103
+ };
104
+
105
+ if (has_asset_path) {
106
+ if (initial_url.startsWith(SVELTE_KIT_ASSETS)) {
107
+ // custom assets path
108
+ req.url = initial_url.slice(SVELTE_KIT_ASSETS.length);
109
+ assets_handler(req, res, () => {
110
+ static_handler(req, res, render_handler);
111
+ });
112
+ } else {
113
+ render_handler();
114
+ }
115
+ } else {
116
+ if (initial_url.startsWith(config.kit.paths.base)) {
117
+ req.url = initial_url.slice(config.kit.paths.base.length);
118
+ }
119
+ assets_handler(req, res, () => {
120
+ static_handler(req, res, render_handler);
121
+ });
122
+ }
123
+ });
124
+
125
+ await http_server.listen(port, host || '0.0.0.0');
126
+
127
+ return Promise.resolve(http_server);
128
+ }
129
+
130
+ /**
131
+ * @param {boolean} use_https
132
+ * @param {import('vite').UserConfig} user_config
133
+ * @param {(req: http.IncomingMessage, res: http.ServerResponse) => void} handler
134
+ * @returns {Promise<import('net').Server>}
135
+ */
136
+ async function get_server(use_https, user_config, handler) {
137
+ /** @type {https.ServerOptions} */
138
+ const https_options = {};
139
+
140
+ if (use_https) {
141
+ const secure_opts = user_config.server
142
+ ? /** @type {import('tls').SecureContextOptions} */ (user_config.server.https)
143
+ : {};
144
+
145
+ if (secure_opts.key && secure_opts.cert) {
146
+ https_options.key = secure_opts.key.toString();
147
+ https_options.cert = secure_opts.cert.toString();
148
+ } else {
149
+ https_options.key = https_options.cert = (await import('./cert.js')).createCertificate();
150
+ }
151
+ }
152
+
153
+ return Promise.resolve(
154
+ use_https
155
+ ? https.createServer(/** @type {https.ServerOptions} */ (https_options), handler)
156
+ : http.createServer(handler)
157
+ );
158
+ }
159
+
160
+ export { preview };