@sveltejs/kit 1.0.0-next.24 → 1.0.0-next.243
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.
- package/README.md +12 -9
- package/assets/app/env.js +20 -0
- package/assets/app/navigation.js +79 -0
- package/assets/app/paths.js +1 -0
- package/assets/{runtime/app → app}/stores.js +19 -15
- package/assets/chunks/utils.js +13 -0
- package/assets/client/singletons.js +21 -0
- package/assets/client/start.js +1382 -0
- package/assets/components/error.svelte +19 -3
- package/assets/env.js +8 -0
- package/assets/paths.js +13 -0
- package/assets/server/index.js +1842 -0
- package/dist/chunks/build.js +658 -0
- package/dist/chunks/cert.js +28154 -0
- package/dist/chunks/index.js +2202 -0
- package/dist/chunks/index2.js +807 -0
- package/dist/chunks/index3.js +643 -0
- package/dist/chunks/index4.js +109 -0
- package/dist/chunks/index5.js +752 -0
- package/dist/chunks/index6.js +170 -0
- package/dist/chunks/index7.js +15578 -0
- package/dist/chunks/index8.js +4207 -0
- package/dist/chunks/misc.js +3 -0
- package/dist/chunks/multipart-parser.js +449 -0
- package/dist/chunks/url.js +119 -0
- package/dist/cli.js +1060 -84
- package/dist/hooks.js +28 -0
- package/dist/install-fetch.js +6518 -0
- package/dist/node.js +85 -0
- package/package.json +95 -54
- package/svelte-kit.js +2 -0
- package/types/ambient-modules.d.ts +201 -0
- package/types/app.d.ts +31 -0
- package/types/config.d.ts +164 -0
- package/types/endpoint.d.ts +20 -0
- package/types/helper.d.ts +32 -0
- package/types/hooks.d.ts +42 -0
- package/types/index.d.ts +10 -0
- package/types/internal.d.ts +234 -0
- package/types/page.d.ts +85 -0
- package/CHANGELOG.md +0 -300
- package/assets/runtime/app/navigation.js +0 -23
- package/assets/runtime/app/navigation.js.map +0 -1
- package/assets/runtime/app/paths.js +0 -2
- package/assets/runtime/app/paths.js.map +0 -1
- package/assets/runtime/app/stores.js.map +0 -1
- package/assets/runtime/internal/singletons.js +0 -15
- package/assets/runtime/internal/singletons.js.map +0 -1
- package/assets/runtime/internal/start.js +0 -591
- package/assets/runtime/internal/start.js.map +0 -1
- package/assets/runtime/utils-85ebcc60.js +0 -18
- package/assets/runtime/utils-85ebcc60.js.map +0 -1
- package/dist/api.js +0 -44
- package/dist/api.js.map +0 -1
- package/dist/build.js +0 -246
- package/dist/build.js.map +0 -1
- package/dist/cli.js.map +0 -1
- package/dist/colors.js +0 -37
- package/dist/colors.js.map +0 -1
- package/dist/create_app.js +0 -578
- package/dist/create_app.js.map +0 -1
- package/dist/index.js +0 -367
- package/dist/index.js.map +0 -1
- package/dist/index2.js +0 -12044
- package/dist/index2.js.map +0 -1
- package/dist/index3.js +0 -547
- package/dist/index3.js.map +0 -1
- package/dist/index4.js +0 -73
- package/dist/index4.js.map +0 -1
- package/dist/index5.js +0 -464
- package/dist/index5.js.map +0 -1
- package/dist/index6.js +0 -727
- package/dist/index6.js.map +0 -1
- package/dist/logging.js +0 -43
- package/dist/logging.js.map +0 -1
- package/dist/package.js +0 -432
- package/dist/package.js.map +0 -1
- package/dist/renderer.js +0 -2391
- package/dist/renderer.js.map +0 -1
- package/dist/standard.js +0 -101
- package/dist/standard.js.map +0 -1
- package/dist/utils.js +0 -54
- package/dist/utils.js.map +0 -1
- 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 };
|