@sveltejs/kit 1.0.0-next.23 → 1.0.0-next.233

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 (84) 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/{runtime/app → app}/stores.js +19 -15
  6. package/assets/chunks/utils.js +13 -0
  7. package/assets/client/singletons.js +21 -0
  8. package/assets/client/start.js +1382 -0
  9. package/assets/components/error.svelte +19 -3
  10. package/assets/env.js +8 -0
  11. package/assets/paths.js +13 -0
  12. package/assets/server/index.js +2004 -0
  13. package/dist/chunks/build.js +658 -0
  14. package/dist/chunks/cert.js +28154 -0
  15. package/dist/chunks/index.js +2420 -0
  16. package/dist/chunks/index2.js +807 -0
  17. package/dist/chunks/index3.js +648 -0
  18. package/dist/chunks/index4.js +109 -0
  19. package/dist/chunks/index5.js +760 -0
  20. package/dist/chunks/index6.js +178 -0
  21. package/dist/chunks/index7.js +15574 -0
  22. package/dist/chunks/index8.js +4207 -0
  23. package/dist/chunks/misc.js +3 -0
  24. package/dist/chunks/multipart-parser.js +449 -0
  25. package/dist/chunks/url.js +62 -0
  26. package/dist/cli.js +1039 -84
  27. package/dist/hooks.js +28 -0
  28. package/dist/install-fetch.js +6518 -0
  29. package/dist/node.js +51 -0
  30. package/package.json +93 -54
  31. package/svelte-kit.js +2 -0
  32. package/types/ambient-modules.d.ts +204 -0
  33. package/types/app.d.ts +45 -0
  34. package/types/config.d.ts +169 -0
  35. package/types/endpoint.d.ts +20 -0
  36. package/types/helper.d.ts +53 -0
  37. package/types/hooks.d.ts +55 -0
  38. package/types/index.d.ts +18 -0
  39. package/types/internal.d.ts +237 -0
  40. package/types/page.d.ts +73 -0
  41. package/CHANGELOG.md +0 -294
  42. package/assets/runtime/app/navigation.js +0 -23
  43. package/assets/runtime/app/navigation.js.map +0 -1
  44. package/assets/runtime/app/paths.js +0 -2
  45. package/assets/runtime/app/paths.js.map +0 -1
  46. package/assets/runtime/app/stores.js.map +0 -1
  47. package/assets/runtime/internal/singletons.js +0 -15
  48. package/assets/runtime/internal/singletons.js.map +0 -1
  49. package/assets/runtime/internal/start.js +0 -591
  50. package/assets/runtime/internal/start.js.map +0 -1
  51. package/assets/runtime/utils-85ebcc60.js +0 -18
  52. package/assets/runtime/utils-85ebcc60.js.map +0 -1
  53. package/dist/api.js +0 -44
  54. package/dist/api.js.map +0 -1
  55. package/dist/build.js +0 -246
  56. package/dist/build.js.map +0 -1
  57. package/dist/cli.js.map +0 -1
  58. package/dist/colors.js +0 -37
  59. package/dist/colors.js.map +0 -1
  60. package/dist/create_app.js +0 -578
  61. package/dist/create_app.js.map +0 -1
  62. package/dist/index.js +0 -367
  63. package/dist/index.js.map +0 -1
  64. package/dist/index2.js +0 -12044
  65. package/dist/index2.js.map +0 -1
  66. package/dist/index3.js +0 -547
  67. package/dist/index3.js.map +0 -1
  68. package/dist/index4.js +0 -73
  69. package/dist/index4.js.map +0 -1
  70. package/dist/index5.js +0 -464
  71. package/dist/index5.js.map +0 -1
  72. package/dist/index6.js +0 -729
  73. package/dist/index6.js.map +0 -1
  74. package/dist/logging.js +0 -43
  75. package/dist/logging.js.map +0 -1
  76. package/dist/package.js +0 -432
  77. package/dist/package.js.map +0 -1
  78. package/dist/renderer.js +0 -2391
  79. package/dist/renderer.js.map +0 -1
  80. package/dist/standard.js +0 -101
  81. package/dist/standard.js.map +0 -1
  82. package/dist/utils.js +0 -54
  83. package/dist/utils.js.map +0 -1
  84. package/svelte-kit +0 -3
@@ -0,0 +1,178 @@
1
+ import fs__default from 'fs';
2
+ import http from 'http';
3
+ import https from 'https';
4
+ import { resolve, join } from 'path';
5
+ import { s as sirv } from './build.js';
6
+ import { pathToFileURL } from 'url';
7
+ import { getRawBody } from '../node.js';
8
+ import { __fetch_polyfill } from '../install-fetch.js';
9
+ import { a as SVELTE_KIT, S as SVELTE_KIT_ASSETS } from '../cli.js';
10
+ import 'querystring';
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
+ import 'sade';
19
+ import 'child_process';
20
+ import 'os';
21
+
22
+ /** @param {string} dir */
23
+ const mutable = (dir) =>
24
+ sirv(dir, {
25
+ etag: true,
26
+ maxAge: 0
27
+ });
28
+
29
+ /**
30
+ * @param {{
31
+ * port: number;
32
+ * host?: string;
33
+ * config: import('types/config').ValidatedConfig;
34
+ * https?: boolean;
35
+ * cwd?: string;
36
+ * }} opts
37
+ */
38
+ async function preview({
39
+ port,
40
+ host,
41
+ config,
42
+ https: use_https = false,
43
+ cwd = process.cwd()
44
+ }) {
45
+ __fetch_polyfill();
46
+
47
+ const app_file = resolve(cwd, `${SVELTE_KIT}/output/server/app.js`);
48
+ const manifest_file = resolve(cwd, `${SVELTE_KIT}/output/server/manifest.js`);
49
+
50
+ /** @type {import('types/internal').AppModule} */
51
+ const { App, override } = await import(pathToFileURL(app_file).href);
52
+
53
+ const { manifest } = await import(pathToFileURL(manifest_file).href);
54
+
55
+ /** @type {import('sirv').RequestHandler} */
56
+ const static_handler = fs__default.existsSync(config.kit.files.assets)
57
+ ? mutable(config.kit.files.assets)
58
+ : (_req, _res, next) => {
59
+ if (!next) throw new Error('No next() handler is available');
60
+ return next();
61
+ };
62
+
63
+ const assets_handler = sirv(resolve(cwd, `${SVELTE_KIT}/output/client`), {
64
+ maxAge: 31536000,
65
+ immutable: true
66
+ });
67
+
68
+ const has_asset_path = !!config.kit.paths.assets;
69
+
70
+ override({
71
+ paths: {
72
+ base: config.kit.paths.base,
73
+ assets: has_asset_path ? SVELTE_KIT_ASSETS : config.kit.paths.base
74
+ },
75
+ prerendering: false,
76
+ protocol: use_https ? 'https' : 'http',
77
+ read: (file) => fs__default.readFileSync(join(config.kit.files.assets, file))
78
+ });
79
+
80
+ const app = new App(manifest);
81
+
82
+ /** @type {import('vite').UserConfig} */
83
+ const vite_config = (config.kit.vite && config.kit.vite()) || {};
84
+
85
+ const server = await get_server(use_https, vite_config, (req, res) => {
86
+ if (req.url == null) {
87
+ throw new Error('Invalid request url');
88
+ }
89
+
90
+ const initial_url = req.url;
91
+
92
+ const render_handler = async () => {
93
+ if (!req.method) throw new Error('Incomplete request');
94
+
95
+ let body;
96
+
97
+ try {
98
+ body = await getRawBody(req);
99
+ } catch (/** @type {any} */ err) {
100
+ res.statusCode = err.status || 400;
101
+ return res.end(err.reason || 'Invalid request body');
102
+ }
103
+
104
+ const rendered =
105
+ initial_url.startsWith(config.kit.paths.base) &&
106
+ (await app.render({
107
+ url: initial_url,
108
+ method: req.method,
109
+ headers: /** @type {import('types/helper').RequestHeaders} */ (req.headers),
110
+ rawBody: body
111
+ }));
112
+
113
+ if (rendered) {
114
+ res.writeHead(rendered.status, rendered.headers);
115
+ if (rendered.body) res.write(rendered.body);
116
+ res.end();
117
+ } else {
118
+ res.statusCode = 404;
119
+ res.end('Not found');
120
+ }
121
+ };
122
+
123
+ if (has_asset_path) {
124
+ if (initial_url.startsWith(SVELTE_KIT_ASSETS)) {
125
+ // custom assets path
126
+ req.url = initial_url.slice(SVELTE_KIT_ASSETS.length);
127
+ assets_handler(req, res, () => {
128
+ static_handler(req, res, render_handler);
129
+ });
130
+ } else {
131
+ render_handler();
132
+ }
133
+ } else {
134
+ if (initial_url.startsWith(config.kit.paths.base)) {
135
+ req.url = initial_url.slice(config.kit.paths.base.length);
136
+ }
137
+ assets_handler(req, res, () => {
138
+ static_handler(req, res, render_handler);
139
+ });
140
+ }
141
+ });
142
+
143
+ await server.listen(port, host || '0.0.0.0');
144
+
145
+ return Promise.resolve(server);
146
+ }
147
+
148
+ /**
149
+ * @param {boolean} use_https
150
+ * @param {import('vite').UserConfig} user_config
151
+ * @param {(req: http.IncomingMessage, res: http.ServerResponse) => void} handler
152
+ * @returns {Promise<import('net').Server>}
153
+ */
154
+ async function get_server(use_https, user_config, handler) {
155
+ /** @type {https.ServerOptions} */
156
+ const https_options = {};
157
+
158
+ if (use_https) {
159
+ const secure_opts = user_config.server
160
+ ? /** @type {import('tls').SecureContextOptions} */ (user_config.server.https)
161
+ : {};
162
+
163
+ if (secure_opts.key && secure_opts.cert) {
164
+ https_options.key = secure_opts.key.toString();
165
+ https_options.cert = secure_opts.cert.toString();
166
+ } else {
167
+ https_options.key = https_options.cert = (await import('./cert.js')).createCertificate();
168
+ }
169
+ }
170
+
171
+ return Promise.resolve(
172
+ use_https
173
+ ? https.createServer(/** @type {https.ServerOptions} */ (https_options), handler)
174
+ : http.createServer(handler)
175
+ );
176
+ }
177
+
178
+ export { preview };