@sveltejs/kit 1.0.0-next.25 → 1.0.0-next.250

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