@sveltejs/kit 1.0.0-next.40 → 1.0.0-next.402
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 +13 -0
- package/assets/app/navigation.js +24 -0
- package/assets/app/paths.js +1 -0
- package/assets/{runtime/app → app}/stores.js +33 -29
- package/assets/client/singletons.js +13 -0
- package/assets/client/start.js +1845 -0
- package/assets/components/error.svelte +18 -2
- package/assets/env/dynamic/private.js +1 -0
- package/assets/env/dynamic/public.js +1 -0
- package/assets/env-private.js +9 -0
- package/assets/env-public.js +9 -0
- package/assets/env.js +8 -0
- package/assets/{runtime/chunks/paths.js → paths.js} +4 -3
- package/assets/server/index.js +3579 -0
- package/dist/chunks/error.js +12 -0
- package/dist/chunks/filesystem.js +110 -0
- package/dist/chunks/index.js +541 -3385
- package/dist/chunks/index2.js +15631 -473
- package/dist/chunks/index3.js +189 -217
- package/dist/chunks/multipart-parser.js +458 -0
- package/dist/chunks/sync.js +1366 -0
- package/dist/chunks/utils.js +40 -57
- package/dist/chunks/write_tsconfig.js +273 -0
- package/dist/cli.js +85 -513
- package/dist/hooks.js +28 -0
- package/dist/node/polyfills.js +17778 -0
- package/dist/node.js +348 -0
- package/dist/prerender.js +788 -0
- package/dist/vite.js +2520 -0
- package/package.json +98 -64
- package/svelte-kit.js +10 -1
- package/types/ambient.d.ts +375 -0
- package/types/index.d.ts +298 -0
- package/types/internal.d.ts +335 -0
- package/types/private.d.ts +235 -0
- package/CHANGELOG.md +0 -411
- package/assets/runtime/app/env.js +0 -5
- package/assets/runtime/app/navigation.js +0 -41
- package/assets/runtime/app/paths.js +0 -1
- package/assets/runtime/chunks/utils.js +0 -19
- package/assets/runtime/internal/singletons.js +0 -23
- package/assets/runtime/internal/start.js +0 -770
- package/dist/chunks/index4.js +0 -526
- package/dist/chunks/index5.js +0 -761
- package/dist/chunks/index6.js +0 -322
- package/dist/chunks/standard.js +0 -99
- package/dist/ssr.js +0 -2523
package/dist/chunks/index3.js
CHANGED
|
@@ -1,246 +1,218 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import { $ } from './index.js';
|
|
2
|
+
import { r as rimraf, m as mkdirp, c as copy } from './filesystem.js';
|
|
3
|
+
import { g as generate_manifest } from '../vite.js';
|
|
4
|
+
import 'fs';
|
|
5
|
+
import 'path';
|
|
6
|
+
import 'url';
|
|
7
|
+
import 'node:child_process';
|
|
8
|
+
import 'node:fs';
|
|
9
|
+
import 'node:path';
|
|
10
|
+
import '@sveltejs/vite-plugin-svelte';
|
|
11
|
+
import 'vite';
|
|
12
|
+
import './sync.js';
|
|
13
|
+
import './utils.js';
|
|
14
|
+
import './write_tsconfig.js';
|
|
15
|
+
import 'querystring';
|
|
16
|
+
import '../node.js';
|
|
17
|
+
import '../node/polyfills.js';
|
|
18
|
+
import 'assert';
|
|
19
|
+
import 'net';
|
|
20
|
+
import 'http';
|
|
21
|
+
import 'stream';
|
|
22
|
+
import 'buffer';
|
|
23
|
+
import 'util';
|
|
24
|
+
import 'stream/web';
|
|
25
|
+
import 'perf_hooks';
|
|
26
|
+
import 'util/types';
|
|
27
|
+
import 'events';
|
|
28
|
+
import 'tls';
|
|
29
|
+
import 'async_hooks';
|
|
30
|
+
import 'console';
|
|
31
|
+
import 'zlib';
|
|
32
|
+
import 'node:http';
|
|
33
|
+
import 'node:https';
|
|
34
|
+
import 'node:zlib';
|
|
35
|
+
import 'node:stream';
|
|
36
|
+
import 'node:buffer';
|
|
37
|
+
import 'node:util';
|
|
38
|
+
import 'node:url';
|
|
39
|
+
import 'node:net';
|
|
40
|
+
import 'crypto';
|
|
41
|
+
import './error.js';
|
|
4
42
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
#map;
|
|
25
|
-
|
|
26
|
-
/** @param {Map<string, string[]>} map */
|
|
27
|
-
constructor(map) {
|
|
28
|
-
this.#map = map;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
/** @param {string} key */
|
|
32
|
-
get(key) {
|
|
33
|
-
const value = this.#map.get(key);
|
|
34
|
-
return value && value[0];
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
/** @param {string} key */
|
|
38
|
-
getAll(key) {
|
|
39
|
-
return this.#map.get(key);
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
/** @param {string} key */
|
|
43
|
-
has(key) {
|
|
44
|
-
return this.#map.has(key);
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
*[Symbol.iterator]() {
|
|
48
|
-
for (const [key, value] of this.#map) {
|
|
49
|
-
for (let i = 0; i < value.length; i += 1) {
|
|
50
|
-
yield [key, value[i]];
|
|
51
|
-
}
|
|
43
|
+
/**
|
|
44
|
+
* Creates the Builder which is passed to adapters for building the application.
|
|
45
|
+
* @param {{
|
|
46
|
+
* config: import('types').ValidatedConfig;
|
|
47
|
+
* build_data: import('types').BuildData;
|
|
48
|
+
* prerendered: import('types').Prerendered;
|
|
49
|
+
* log: import('types').Logger;
|
|
50
|
+
* }} opts
|
|
51
|
+
* @returns {import('types').Builder}
|
|
52
|
+
*/
|
|
53
|
+
function create_builder({ config, build_data, prerendered, log }) {
|
|
54
|
+
/** @type {Set<string>} */
|
|
55
|
+
const prerendered_paths = new Set(prerendered.paths);
|
|
56
|
+
|
|
57
|
+
/** @param {import('types').RouteData} route */
|
|
58
|
+
// TODO routes should come pre-filtered
|
|
59
|
+
function not_prerendered(route) {
|
|
60
|
+
if (route.type === 'page' && route.path) {
|
|
61
|
+
return !prerendered_paths.has(route.path) && !prerendered_paths.has(route.path + '/');
|
|
52
62
|
}
|
|
53
|
-
}
|
|
54
63
|
|
|
55
|
-
|
|
56
|
-
for (const [key, value] of this.#map) {
|
|
57
|
-
for (let i = 0; i < value.length; i += 1) {
|
|
58
|
-
yield [key, value[i]];
|
|
59
|
-
}
|
|
60
|
-
}
|
|
64
|
+
return true;
|
|
61
65
|
}
|
|
62
66
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
67
|
+
return {
|
|
68
|
+
log,
|
|
69
|
+
rimraf,
|
|
70
|
+
mkdirp,
|
|
71
|
+
copy,
|
|
72
|
+
|
|
73
|
+
config,
|
|
74
|
+
prerendered,
|
|
75
|
+
|
|
76
|
+
async createEntries(fn) {
|
|
77
|
+
const { routes } = build_data.manifest_data;
|
|
78
|
+
|
|
79
|
+
/** @type {import('types').RouteDefinition[]} */
|
|
80
|
+
const facades = routes.map((route) => ({
|
|
81
|
+
id: route.id,
|
|
82
|
+
type: route.type,
|
|
83
|
+
segments: route.id.split('/').map((segment) => ({
|
|
84
|
+
dynamic: segment.includes('['),
|
|
85
|
+
rest: segment.includes('[...'),
|
|
86
|
+
content: segment
|
|
87
|
+
})),
|
|
88
|
+
pattern: route.pattern,
|
|
89
|
+
methods: route.type === 'page' ? ['GET'] : build_data.server.methods[route.file]
|
|
90
|
+
}));
|
|
91
|
+
|
|
92
|
+
const seen = new Set();
|
|
93
|
+
|
|
94
|
+
for (let i = 0; i < routes.length; i += 1) {
|
|
95
|
+
const route = routes[i];
|
|
96
|
+
const { id, filter, complete } = fn(facades[i]);
|
|
97
|
+
|
|
98
|
+
if (seen.has(id)) continue;
|
|
99
|
+
seen.add(id);
|
|
100
|
+
|
|
101
|
+
const group = [route];
|
|
102
|
+
|
|
103
|
+
// figure out which lower priority routes should be considered fallbacks
|
|
104
|
+
for (let j = i + 1; j < routes.length; j += 1) {
|
|
105
|
+
if (filter(facades[j])) {
|
|
106
|
+
group.push(routes[j]);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
70
109
|
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
110
|
+
const filtered = new Set(group.filter(not_prerendered));
|
|
111
|
+
|
|
112
|
+
// heuristic: if /foo/[bar] is included, /foo/[bar].json should
|
|
113
|
+
// also be included, since the page likely needs the endpoint
|
|
114
|
+
filtered.forEach((route) => {
|
|
115
|
+
if (route.type === 'page') {
|
|
116
|
+
const endpoint = routes.find((candidate) => candidate.id === route.id + '.json');
|
|
117
|
+
|
|
118
|
+
if (endpoint) {
|
|
119
|
+
filtered.add(endpoint);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
if (filtered.size > 0) {
|
|
125
|
+
await complete({
|
|
126
|
+
generateManifest: ({ relativePath, format }) =>
|
|
127
|
+
generate_manifest({
|
|
128
|
+
build_data,
|
|
129
|
+
relative_path: relativePath,
|
|
130
|
+
routes: Array.from(filtered),
|
|
131
|
+
format
|
|
132
|
+
})
|
|
133
|
+
});
|
|
134
|
+
}
|
|
75
135
|
}
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
/** @param {import('http').IncomingMessage} req */
|
|
81
|
-
function get_body(req) {
|
|
82
|
-
const headers = req.headers;
|
|
83
|
-
const has_body =
|
|
84
|
-
headers['content-type'] !== undefined &&
|
|
85
|
-
// https://github.com/jshttp/type-is/blob/c1f4388c71c8a01f79934e68f630ca4a15fffcd6/index.js#L81-L95
|
|
86
|
-
(headers['transfer-encoding'] !== undefined || !isNaN(Number(headers['content-length'])));
|
|
87
|
-
|
|
88
|
-
if (!has_body) return Promise.resolve(undefined);
|
|
89
|
-
|
|
90
|
-
const [type, ...directives] = headers['content-type'].split(/;\s*/);
|
|
91
|
-
|
|
92
|
-
switch (type) {
|
|
93
|
-
case 'application/octet-stream':
|
|
94
|
-
return get_buffer(req);
|
|
95
|
-
|
|
96
|
-
case 'text/plain':
|
|
97
|
-
return get_text(req);
|
|
98
|
-
|
|
99
|
-
case 'application/json':
|
|
100
|
-
return get_json(req);
|
|
101
|
-
|
|
102
|
-
case 'application/x-www-form-urlencoded':
|
|
103
|
-
return get_urlencoded(req);
|
|
104
|
-
|
|
105
|
-
case 'multipart/form-data': {
|
|
106
|
-
const boundary = directives.find((directive) => directive.startsWith('boundary='));
|
|
107
|
-
if (!boundary) throw new Error('Missing boundary');
|
|
108
|
-
return get_multipart(req, boundary.slice('boundary='.length));
|
|
109
|
-
}
|
|
110
|
-
default:
|
|
111
|
-
throw new Error(`Invalid Content-Type ${type}`);
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
/** @param {import('http').IncomingMessage} req */
|
|
116
|
-
async function get_json(req) {
|
|
117
|
-
return JSON.parse(await get_text(req));
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
/** @param {import('http').IncomingMessage} req */
|
|
121
|
-
async function get_urlencoded(req) {
|
|
122
|
-
const text = await get_text(req);
|
|
123
|
-
|
|
124
|
-
const { data, append } = read_only_form_data();
|
|
125
|
-
|
|
126
|
-
text
|
|
127
|
-
.replace(/\+/g, ' ')
|
|
128
|
-
.split('&')
|
|
129
|
-
.forEach((str) => {
|
|
130
|
-
const [key, value] = str.split('=');
|
|
131
|
-
append(decodeURIComponent(key), decodeURIComponent(value));
|
|
132
|
-
});
|
|
133
|
-
|
|
134
|
-
return data;
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
/**
|
|
138
|
-
* @param {import('http').IncomingMessage} req
|
|
139
|
-
* @param {string} boundary
|
|
140
|
-
*/
|
|
141
|
-
async function get_multipart(req, boundary) {
|
|
142
|
-
const text = await get_text(req);
|
|
143
|
-
const parts = text.split(`--${boundary}`);
|
|
144
|
-
|
|
145
|
-
const nope = () => {
|
|
146
|
-
throw new Error('Malformed form data');
|
|
147
|
-
};
|
|
148
|
-
|
|
149
|
-
if (parts[0] !== '' || parts[parts.length - 1].trim() !== '--') {
|
|
150
|
-
nope();
|
|
151
|
-
}
|
|
136
|
+
},
|
|
152
137
|
|
|
153
|
-
|
|
138
|
+
generateManifest: ({ relativePath, format }) => {
|
|
139
|
+
return generate_manifest({
|
|
140
|
+
build_data,
|
|
141
|
+
relative_path: relativePath,
|
|
142
|
+
routes: build_data.manifest_data.routes.filter(not_prerendered),
|
|
143
|
+
format
|
|
144
|
+
});
|
|
145
|
+
},
|
|
154
146
|
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
const body = match[2].trim();
|
|
147
|
+
getBuildDirectory(name) {
|
|
148
|
+
return `${config.kit.outDir}/${name}`;
|
|
149
|
+
},
|
|
159
150
|
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
let [name, value] = raw_header.split(': ');
|
|
151
|
+
getClientDirectory() {
|
|
152
|
+
return `${config.kit.outDir}/output/client`;
|
|
153
|
+
},
|
|
164
154
|
|
|
165
|
-
|
|
155
|
+
getServerDirectory() {
|
|
156
|
+
return `${config.kit.outDir}/output/server`;
|
|
157
|
+
},
|
|
166
158
|
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
const [name, value] = raw_directive.split('=');
|
|
171
|
-
directives[name] = JSON.parse(value); // TODO is this right?
|
|
172
|
-
});
|
|
159
|
+
getStaticDirectory() {
|
|
160
|
+
return config.kit.files.assets;
|
|
161
|
+
},
|
|
173
162
|
|
|
174
|
-
|
|
175
|
-
|
|
163
|
+
writeClient(dest) {
|
|
164
|
+
return [...copy(`${config.kit.outDir}/output/client`, dest)];
|
|
165
|
+
},
|
|
176
166
|
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
}
|
|
167
|
+
writePrerendered(dest, { fallback } = {}) {
|
|
168
|
+
const source = `${config.kit.outDir}/output/prerendered`;
|
|
169
|
+
const files = [...copy(`${source}/pages`, dest), ...copy(`${source}/dependencies`, dest)];
|
|
181
170
|
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
}
|
|
171
|
+
if (fallback) {
|
|
172
|
+
files.push(fallback);
|
|
173
|
+
copy(`${source}/fallback.html`, `${dest}/${fallback}`);
|
|
185
174
|
}
|
|
186
|
-
});
|
|
187
|
-
|
|
188
|
-
if (!key) nope();
|
|
189
175
|
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
return data;
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
/**
|
|
197
|
-
* @param {import('http').IncomingMessage} req
|
|
198
|
-
* @returns {Promise<string>}
|
|
199
|
-
*/
|
|
200
|
-
function get_text(req) {
|
|
201
|
-
return new Promise((fulfil, reject) => {
|
|
202
|
-
let data = '';
|
|
176
|
+
return files;
|
|
177
|
+
},
|
|
203
178
|
|
|
204
|
-
|
|
179
|
+
writeServer(dest) {
|
|
180
|
+
return copy(`${config.kit.outDir}/output/server`, dest);
|
|
181
|
+
},
|
|
205
182
|
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
183
|
+
// TODO remove these methods for 1.0
|
|
184
|
+
// @ts-expect-error
|
|
185
|
+
writeStatic() {
|
|
186
|
+
throw new Error(
|
|
187
|
+
`writeStatic has been removed. Please ensure you are using the latest version of ${
|
|
188
|
+
config.kit.adapter.name || 'your adapter'
|
|
189
|
+
}`
|
|
190
|
+
);
|
|
191
|
+
},
|
|
209
192
|
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
193
|
+
async prerender() {
|
|
194
|
+
throw new Error(
|
|
195
|
+
'builder.prerender() has been removed. Prerendering now takes place in the build phase — see builder.prerender and builder.writePrerendered'
|
|
196
|
+
);
|
|
197
|
+
}
|
|
198
|
+
};
|
|
214
199
|
}
|
|
215
200
|
|
|
216
201
|
/**
|
|
217
|
-
* @param {import('
|
|
218
|
-
* @
|
|
202
|
+
* @param {import('types').ValidatedConfig} config
|
|
203
|
+
* @param {import('types').BuildData} build_data
|
|
204
|
+
* @param {import('types').Prerendered} prerendered
|
|
205
|
+
* @param {{ log: import('types').Logger }} opts
|
|
219
206
|
*/
|
|
220
|
-
function
|
|
221
|
-
|
|
222
|
-
let data = new Uint8Array(0);
|
|
207
|
+
async function adapt(config, build_data, prerendered, { log }) {
|
|
208
|
+
const { name, adapt } = config.kit.adapter;
|
|
223
209
|
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
req.on('data', (chunk) => {
|
|
227
|
-
const new_data = new Uint8Array(data.length + chunk.length);
|
|
228
|
-
|
|
229
|
-
for (let i = 0; i < data.length; i += 1) {
|
|
230
|
-
new_data[i] = data[i];
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
for (let i = 0; i < chunk.length; i += 1) {
|
|
234
|
-
new_data[i + data.length] = chunk[i];
|
|
235
|
-
}
|
|
210
|
+
console.log($.bold().cyan(`\n> Using ${name}`));
|
|
236
211
|
|
|
237
|
-
|
|
238
|
-
|
|
212
|
+
const builder = create_builder({ config, build_data, prerendered, log });
|
|
213
|
+
await adapt(builder);
|
|
239
214
|
|
|
240
|
-
|
|
241
|
-
fulfil(data.buffer);
|
|
242
|
-
});
|
|
243
|
-
});
|
|
215
|
+
log.success('done');
|
|
244
216
|
}
|
|
245
217
|
|
|
246
|
-
export {
|
|
218
|
+
export { adapt };
|