@sveltejs/kit 1.0.0-next.99 → 1.0.1
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 +5 -1
- package/package.json +91 -77
- package/postinstall.js +47 -0
- package/src/cli.js +44 -0
- package/src/constants.js +5 -0
- package/src/core/adapt/builder.js +221 -0
- package/src/core/adapt/index.js +31 -0
- package/src/core/config/default-error.html +56 -0
- package/src/core/config/index.js +100 -0
- package/src/core/config/options.js +387 -0
- package/src/core/config/types.d.ts +1 -0
- package/src/core/env.js +138 -0
- package/src/core/generate_manifest/index.js +116 -0
- package/src/core/prerender/crawl.js +207 -0
- package/src/core/prerender/entities.js +2252 -0
- package/src/core/prerender/fallback.js +43 -0
- package/src/core/prerender/prerender.js +459 -0
- package/src/core/prerender/queue.js +80 -0
- package/src/core/sync/create_manifest_data/conflict.js +0 -0
- package/src/core/sync/create_manifest_data/index.js +523 -0
- package/src/core/sync/create_manifest_data/sort.js +161 -0
- package/src/core/sync/create_manifest_data/types.d.ts +37 -0
- package/src/core/sync/sync.js +59 -0
- package/src/core/sync/utils.js +33 -0
- package/src/core/sync/write_ambient.js +58 -0
- package/src/core/sync/write_client_manifest.js +107 -0
- package/src/core/sync/write_matchers.js +25 -0
- package/src/core/sync/write_root.js +91 -0
- package/src/core/sync/write_tsconfig.js +195 -0
- package/src/core/sync/write_types/index.js +809 -0
- package/src/core/utils.js +67 -0
- package/src/exports/hooks/index.js +1 -0
- package/src/exports/hooks/sequence.js +44 -0
- package/src/exports/index.js +55 -0
- package/src/exports/node/index.js +172 -0
- package/src/exports/node/polyfills.js +28 -0
- package/src/exports/vite/build/build_server.js +359 -0
- package/src/exports/vite/build/build_service_worker.js +85 -0
- package/src/exports/vite/build/utils.js +230 -0
- package/src/exports/vite/dev/index.js +597 -0
- package/src/exports/vite/graph_analysis/index.js +99 -0
- package/src/exports/vite/graph_analysis/types.d.ts +5 -0
- package/src/exports/vite/graph_analysis/utils.js +6 -0
- package/src/exports/vite/index.js +708 -0
- package/src/exports/vite/preview/index.js +194 -0
- package/src/exports/vite/types.d.ts +3 -0
- package/src/exports/vite/utils.js +184 -0
- package/src/runtime/app/env.js +1 -0
- package/src/runtime/app/environment.js +13 -0
- package/src/runtime/app/forms.js +135 -0
- package/src/runtime/app/navigation.js +22 -0
- package/src/runtime/app/paths.js +1 -0
- package/src/runtime/app/stores.js +57 -0
- package/src/runtime/client/ambient.d.ts +30 -0
- package/src/runtime/client/client.js +1725 -0
- package/src/runtime/client/constants.js +10 -0
- package/src/runtime/client/fetcher.js +127 -0
- package/src/runtime/client/parse.js +60 -0
- package/src/runtime/client/singletons.js +21 -0
- package/src/runtime/client/start.js +45 -0
- package/src/runtime/client/types.d.ts +86 -0
- package/src/runtime/client/utils.js +257 -0
- package/src/runtime/components/error.svelte +6 -0
- package/{assets → src/runtime}/components/layout.svelte +0 -0
- package/src/runtime/control.js +45 -0
- package/src/runtime/env/dynamic/private.js +1 -0
- package/src/runtime/env/dynamic/public.js +1 -0
- package/src/runtime/env-private.js +6 -0
- package/src/runtime/env-public.js +6 -0
- package/src/runtime/env.js +12 -0
- package/src/runtime/hash.js +20 -0
- package/src/runtime/paths.js +11 -0
- package/src/runtime/server/cookie.js +228 -0
- package/src/runtime/server/data/index.js +158 -0
- package/src/runtime/server/endpoint.js +86 -0
- package/src/runtime/server/fetch.js +175 -0
- package/src/runtime/server/index.js +405 -0
- package/src/runtime/server/page/actions.js +267 -0
- package/src/runtime/server/page/crypto.js +239 -0
- package/src/runtime/server/page/csp.js +250 -0
- package/src/runtime/server/page/index.js +326 -0
- package/src/runtime/server/page/load_data.js +270 -0
- package/src/runtime/server/page/render.js +393 -0
- package/src/runtime/server/page/respond_with_error.js +103 -0
- package/src/runtime/server/page/serialize_data.js +87 -0
- package/src/runtime/server/page/types.d.ts +35 -0
- package/src/runtime/server/utils.js +179 -0
- package/src/utils/array.js +9 -0
- package/src/utils/error.js +22 -0
- package/src/utils/escape.js +46 -0
- package/src/utils/exports.js +54 -0
- package/src/utils/filesystem.js +178 -0
- package/src/utils/functions.js +16 -0
- package/src/utils/http.js +72 -0
- package/src/utils/misc.js +1 -0
- package/src/utils/promises.js +17 -0
- package/src/utils/routing.js +201 -0
- package/src/utils/unit_test.js +11 -0
- package/src/utils/url.js +161 -0
- package/svelte-kit.js +1 -1
- package/types/ambient.d.ts +451 -0
- package/types/index.d.ts +1168 -5
- package/types/internal.d.ts +348 -159
- package/types/private.d.ts +237 -0
- package/types/synthetic/$env+dynamic+private.md +10 -0
- package/types/synthetic/$env+dynamic+public.md +8 -0
- package/types/synthetic/$env+static+private.md +19 -0
- package/types/synthetic/$env+static+public.md +7 -0
- package/types/synthetic/$lib.md +5 -0
- package/CHANGELOG.md +0 -825
- package/assets/components/error.svelte +0 -21
- package/assets/runtime/app/env.js +0 -16
- package/assets/runtime/app/navigation.js +0 -53
- package/assets/runtime/app/paths.js +0 -1
- package/assets/runtime/app/stores.js +0 -87
- package/assets/runtime/chunks/utils.js +0 -13
- package/assets/runtime/env.js +0 -8
- package/assets/runtime/internal/singletons.js +0 -20
- package/assets/runtime/internal/start.js +0 -1061
- package/assets/runtime/paths.js +0 -12
- package/dist/chunks/_commonjsHelpers.js +0 -8
- package/dist/chunks/cert.js +0 -29079
- package/dist/chunks/constants.js +0 -3
- package/dist/chunks/index.js +0 -3532
- package/dist/chunks/index2.js +0 -583
- package/dist/chunks/index3.js +0 -31
- package/dist/chunks/index4.js +0 -1004
- package/dist/chunks/index5.js +0 -327
- package/dist/chunks/index6.js +0 -325
- package/dist/chunks/standard.js +0 -99
- package/dist/chunks/utils.js +0 -149
- package/dist/cli.js +0 -711
- package/dist/http.js +0 -66
- package/dist/install-fetch.js +0 -1699
- package/dist/ssr.js +0 -1523
- package/types/ambient-modules.d.ts +0 -115
- package/types/config.d.ts +0 -101
- package/types/endpoint.d.ts +0 -23
- package/types/helper.d.ts +0 -19
- package/types/hooks.d.ts +0 -21
- package/types/page.d.ts +0 -30
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { readFileSync, writeFileSync } from 'fs';
|
|
2
|
+
import { dirname, join } from 'path';
|
|
3
|
+
import { pathToFileURL } from 'url';
|
|
4
|
+
import { mkdirp } from '../../utils/filesystem.js';
|
|
5
|
+
import { installPolyfills } from '../../exports/node/polyfills.js';
|
|
6
|
+
import { load_config } from '../config/index.js';
|
|
7
|
+
|
|
8
|
+
const [, , dest, manifest_path, env] = process.argv;
|
|
9
|
+
|
|
10
|
+
/** @type {import('types').ValidatedKitConfig} */
|
|
11
|
+
const config = (await load_config()).kit;
|
|
12
|
+
|
|
13
|
+
installPolyfills();
|
|
14
|
+
|
|
15
|
+
const server_root = join(config.outDir, 'output');
|
|
16
|
+
|
|
17
|
+
/** @type {import('types').ServerModule} */
|
|
18
|
+
const { Server, override } = await import(pathToFileURL(`${server_root}/server/index.js`).href);
|
|
19
|
+
|
|
20
|
+
/** @type {import('types').SSRManifest} */
|
|
21
|
+
const manifest = (await import(pathToFileURL(manifest_path).href)).manifest;
|
|
22
|
+
|
|
23
|
+
override({
|
|
24
|
+
building: true,
|
|
25
|
+
paths: config.paths,
|
|
26
|
+
read: (file) => readFileSync(join(config.files.assets, file))
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
const server = new Server(manifest);
|
|
30
|
+
await server.init({ env: JSON.parse(env) });
|
|
31
|
+
|
|
32
|
+
const rendered = await server.respond(new Request(config.prerender.origin + '/[fallback]'), {
|
|
33
|
+
getClientAddress: () => {
|
|
34
|
+
throw new Error('Cannot read clientAddress during prerendering');
|
|
35
|
+
},
|
|
36
|
+
prerendering: {
|
|
37
|
+
fallback: true,
|
|
38
|
+
dependencies: new Map()
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
mkdirp(dirname(dest));
|
|
43
|
+
writeFileSync(dest, await rendered.text());
|
|
@@ -0,0 +1,459 @@
|
|
|
1
|
+
import { readFileSync, writeFileSync } from 'fs';
|
|
2
|
+
import { dirname, join } from 'path';
|
|
3
|
+
import { pathToFileURL, URL } from 'url';
|
|
4
|
+
import { mkdirp, posixify, walk } from '../../utils/filesystem.js';
|
|
5
|
+
import { installPolyfills } from '../../exports/node/polyfills.js';
|
|
6
|
+
import { is_root_relative, resolve } from '../../utils/url.js';
|
|
7
|
+
import { queue } from './queue.js';
|
|
8
|
+
import { crawl } from './crawl.js';
|
|
9
|
+
import { escape_html_attr } from '../../utils/escape.js';
|
|
10
|
+
import { logger } from '../utils.js';
|
|
11
|
+
import { load_config } from '../config/index.js';
|
|
12
|
+
import { get_route_segments } from '../../utils/routing.js';
|
|
13
|
+
import { get_option } from '../../runtime/server/utils.js';
|
|
14
|
+
import {
|
|
15
|
+
validate_common_exports,
|
|
16
|
+
validate_page_server_exports,
|
|
17
|
+
validate_server_exports
|
|
18
|
+
} from '../../utils/exports.js';
|
|
19
|
+
|
|
20
|
+
const [, , client_out_dir, manifest_path, results_path, verbose, env] = process.argv;
|
|
21
|
+
|
|
22
|
+
prerender();
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* @template {{message: string}} T
|
|
26
|
+
* @template {Omit<T, 'message'>} K
|
|
27
|
+
* @param {import('types').Logger} log
|
|
28
|
+
* @param {'fail' | 'warn' | 'ignore' | ((details: T) => void)} input
|
|
29
|
+
* @param {(details: K) => string} format
|
|
30
|
+
* @returns {(details: K) => void}
|
|
31
|
+
*/
|
|
32
|
+
function normalise_error_handler(log, input, format) {
|
|
33
|
+
switch (input) {
|
|
34
|
+
case 'fail':
|
|
35
|
+
return (details) => {
|
|
36
|
+
throw new Error(format(details));
|
|
37
|
+
};
|
|
38
|
+
case 'warn':
|
|
39
|
+
return (details) => {
|
|
40
|
+
log.error(format(details));
|
|
41
|
+
};
|
|
42
|
+
case 'ignore':
|
|
43
|
+
return () => {};
|
|
44
|
+
default:
|
|
45
|
+
// @ts-expect-error TS thinks T might be of a different kind, but it's not
|
|
46
|
+
return (details) => input({ ...details, message: format(details) });
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const OK = 2;
|
|
51
|
+
const REDIRECT = 3;
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* @param {{
|
|
55
|
+
* prerendered: import('types').Prerendered;
|
|
56
|
+
* prerender_map: import('types').PrerenderMap;
|
|
57
|
+
* }} data
|
|
58
|
+
*/
|
|
59
|
+
const output_and_exit = (data) => {
|
|
60
|
+
writeFileSync(
|
|
61
|
+
results_path,
|
|
62
|
+
JSON.stringify(data, (_key, value) =>
|
|
63
|
+
value instanceof Map ? Array.from(value.entries()) : value
|
|
64
|
+
)
|
|
65
|
+
);
|
|
66
|
+
process.exit(0);
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
export async function prerender() {
|
|
70
|
+
/** @type {import('types').Prerendered} */
|
|
71
|
+
const prerendered = {
|
|
72
|
+
pages: new Map(),
|
|
73
|
+
assets: new Map(),
|
|
74
|
+
redirects: new Map(),
|
|
75
|
+
paths: []
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
/** @type {import('types').PrerenderMap} */
|
|
79
|
+
const prerender_map = new Map();
|
|
80
|
+
|
|
81
|
+
/** @type {Set<string>} */
|
|
82
|
+
const prerendered_routes = new Set();
|
|
83
|
+
|
|
84
|
+
/** @type {import('types').ValidatedKitConfig} */
|
|
85
|
+
const config = (await load_config()).kit;
|
|
86
|
+
|
|
87
|
+
/** @type {import('types').Logger} */
|
|
88
|
+
const log = logger({
|
|
89
|
+
verbose: verbose === 'true'
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
installPolyfills();
|
|
93
|
+
|
|
94
|
+
const server_root = join(config.outDir, 'output');
|
|
95
|
+
|
|
96
|
+
/** @type {import('types').ServerModule} */
|
|
97
|
+
const { Server, override } = await import(pathToFileURL(`${server_root}/server/index.js`).href);
|
|
98
|
+
|
|
99
|
+
/** @type {import('types').SSRManifest} */
|
|
100
|
+
const manifest = (await import(pathToFileURL(manifest_path).href)).manifest;
|
|
101
|
+
|
|
102
|
+
override({
|
|
103
|
+
building: true,
|
|
104
|
+
paths: config.paths,
|
|
105
|
+
read: (file) => readFileSync(join(config.files.assets, file))
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
const server = new Server(manifest);
|
|
109
|
+
await server.init({ env: JSON.parse(env) });
|
|
110
|
+
|
|
111
|
+
const handle_http_error = normalise_error_handler(
|
|
112
|
+
log,
|
|
113
|
+
config.prerender.handleHttpError,
|
|
114
|
+
({ status, path, referrer, referenceType }) => {
|
|
115
|
+
const message =
|
|
116
|
+
status === 404 && !path.startsWith(config.paths.base)
|
|
117
|
+
? `${path} does not begin with \`base\`, which is configured in \`paths.base\` and can be imported from \`$app/paths\` - see https://kit.svelte.dev/docs/configuration#paths for more info`
|
|
118
|
+
: path;
|
|
119
|
+
|
|
120
|
+
return `${status} ${message}${referrer ? ` (${referenceType} from ${referrer})` : ''}`;
|
|
121
|
+
}
|
|
122
|
+
);
|
|
123
|
+
|
|
124
|
+
const handle_missing_id = normalise_error_handler(
|
|
125
|
+
log,
|
|
126
|
+
config.prerender.handleMissingId,
|
|
127
|
+
({ path, id, referrers }) => {
|
|
128
|
+
return (
|
|
129
|
+
`The following pages contain links to ${path}#${id}, but no element with id="${id}" exists on ${path} - see the \`handleMissingId\` option in https://kit.svelte.dev/docs/configuration#prerender for more info:` +
|
|
130
|
+
referrers.map((l) => `\n - ${l}`).join('')
|
|
131
|
+
);
|
|
132
|
+
}
|
|
133
|
+
);
|
|
134
|
+
|
|
135
|
+
const q = queue(config.prerender.concurrency);
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* @param {string} path
|
|
139
|
+
* @param {boolean} is_html
|
|
140
|
+
*/
|
|
141
|
+
function output_filename(path, is_html) {
|
|
142
|
+
const file = path.slice(config.paths.base.length + 1) || 'index.html';
|
|
143
|
+
|
|
144
|
+
if (is_html && !file.endsWith('.html')) {
|
|
145
|
+
return file + (file.endsWith('/') ? 'index.html' : '.html');
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
return file;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
const files = new Set(walk(client_out_dir).map(posixify));
|
|
152
|
+
const seen = new Set();
|
|
153
|
+
const written = new Set();
|
|
154
|
+
|
|
155
|
+
/** @type {Map<string, Set<string>>} */
|
|
156
|
+
const expected_hashlinks = new Map();
|
|
157
|
+
|
|
158
|
+
/** @type {Map<string, string[]>} */
|
|
159
|
+
const actual_hashlinks = new Map();
|
|
160
|
+
|
|
161
|
+
/**
|
|
162
|
+
* @param {string | null} referrer
|
|
163
|
+
* @param {string} decoded
|
|
164
|
+
* @param {string} [encoded]
|
|
165
|
+
*/
|
|
166
|
+
function enqueue(referrer, decoded, encoded) {
|
|
167
|
+
if (seen.has(decoded)) return;
|
|
168
|
+
seen.add(decoded);
|
|
169
|
+
|
|
170
|
+
const file = decoded.slice(config.paths.base.length + 1);
|
|
171
|
+
if (files.has(file)) return;
|
|
172
|
+
|
|
173
|
+
return q.add(() => visit(decoded, encoded || encodeURI(decoded), referrer));
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
/**
|
|
177
|
+
* @param {string} decoded
|
|
178
|
+
* @param {string} encoded
|
|
179
|
+
* @param {string?} referrer
|
|
180
|
+
*/
|
|
181
|
+
async function visit(decoded, encoded, referrer) {
|
|
182
|
+
if (!decoded.startsWith(config.paths.base)) {
|
|
183
|
+
handle_http_error({ status: 404, path: decoded, referrer, referenceType: 'linked' });
|
|
184
|
+
return;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
/** @type {Map<string, import('types').PrerenderDependency>} */
|
|
188
|
+
const dependencies = new Map();
|
|
189
|
+
|
|
190
|
+
const response = await server.respond(new Request(config.prerender.origin + encoded), {
|
|
191
|
+
getClientAddress,
|
|
192
|
+
prerendering: {
|
|
193
|
+
dependencies
|
|
194
|
+
}
|
|
195
|
+
});
|
|
196
|
+
|
|
197
|
+
const body = Buffer.from(await response.arrayBuffer());
|
|
198
|
+
|
|
199
|
+
save('pages', response, body, decoded, encoded, referrer, 'linked');
|
|
200
|
+
|
|
201
|
+
for (const [dependency_path, result] of dependencies) {
|
|
202
|
+
// this seems circuitous, but using new URL allows us to not care
|
|
203
|
+
// whether dependency_path is encoded or not
|
|
204
|
+
const encoded_dependency_path = new URL(dependency_path, 'http://localhost').pathname;
|
|
205
|
+
const decoded_dependency_path = decodeURI(encoded_dependency_path);
|
|
206
|
+
|
|
207
|
+
const headers = Object.fromEntries(result.response.headers);
|
|
208
|
+
|
|
209
|
+
const prerender = headers['x-sveltekit-prerender'];
|
|
210
|
+
if (prerender) {
|
|
211
|
+
const encoded_route_id = headers['x-sveltekit-routeid'];
|
|
212
|
+
if (encoded_route_id != null) {
|
|
213
|
+
const route_id = decodeURI(encoded_route_id);
|
|
214
|
+
const existing_value = prerender_map.get(route_id);
|
|
215
|
+
if (existing_value !== 'auto') {
|
|
216
|
+
prerender_map.set(route_id, prerender === 'true' ? true : 'auto');
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
const body = result.body ?? new Uint8Array(await result.response.arrayBuffer());
|
|
222
|
+
save(
|
|
223
|
+
'dependencies',
|
|
224
|
+
result.response,
|
|
225
|
+
body,
|
|
226
|
+
decoded_dependency_path,
|
|
227
|
+
encoded_dependency_path,
|
|
228
|
+
decoded,
|
|
229
|
+
'fetched'
|
|
230
|
+
);
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
// avoid triggering `filterSerializeResponseHeaders` guard
|
|
234
|
+
const headers = Object.fromEntries(response.headers);
|
|
235
|
+
|
|
236
|
+
if (config.prerender.crawl && headers['content-type'] === 'text/html') {
|
|
237
|
+
const { ids, hrefs } = crawl(body.toString());
|
|
238
|
+
|
|
239
|
+
actual_hashlinks.set(decoded, ids);
|
|
240
|
+
|
|
241
|
+
for (const href of hrefs) {
|
|
242
|
+
if (href.startsWith('data:')) continue;
|
|
243
|
+
|
|
244
|
+
const resolved = resolve(encoded, href);
|
|
245
|
+
if (!is_root_relative(resolved)) continue;
|
|
246
|
+
|
|
247
|
+
const { pathname, search, hash } = new URL(resolved, 'http://localhost');
|
|
248
|
+
|
|
249
|
+
if (search) {
|
|
250
|
+
// TODO warn that query strings have no effect on statically-exported pages
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
if (hash) {
|
|
254
|
+
const key = decodeURI(pathname + hash);
|
|
255
|
+
|
|
256
|
+
if (!expected_hashlinks.has(key)) {
|
|
257
|
+
expected_hashlinks.set(key, new Set());
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
/** @type {Set<string>} */ (expected_hashlinks.get(key)).add(decoded);
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
enqueue(decoded, decodeURI(pathname), pathname);
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
/**
|
|
269
|
+
* @param {'pages' | 'dependencies'} category
|
|
270
|
+
* @param {Response} response
|
|
271
|
+
* @param {string | Uint8Array} body
|
|
272
|
+
* @param {string} decoded
|
|
273
|
+
* @param {string} encoded
|
|
274
|
+
* @param {string | null} referrer
|
|
275
|
+
* @param {'linked' | 'fetched'} referenceType
|
|
276
|
+
*/
|
|
277
|
+
function save(category, response, body, decoded, encoded, referrer, referenceType) {
|
|
278
|
+
const response_type = Math.floor(response.status / 100);
|
|
279
|
+
const headers = Object.fromEntries(response.headers);
|
|
280
|
+
|
|
281
|
+
const type = headers['content-type'];
|
|
282
|
+
const is_html = response_type === REDIRECT || type === 'text/html';
|
|
283
|
+
|
|
284
|
+
const file = output_filename(decoded, is_html);
|
|
285
|
+
const dest = `${config.outDir}/output/prerendered/${category}/${file}`;
|
|
286
|
+
|
|
287
|
+
if (written.has(file)) return;
|
|
288
|
+
|
|
289
|
+
const encoded_route_id = response.headers.get('x-sveltekit-routeid');
|
|
290
|
+
const route_id = encoded_route_id != null ? decodeURI(encoded_route_id) : null;
|
|
291
|
+
if (route_id !== null) prerendered_routes.add(route_id);
|
|
292
|
+
|
|
293
|
+
if (response_type === REDIRECT) {
|
|
294
|
+
const location = headers['location'];
|
|
295
|
+
|
|
296
|
+
if (location) {
|
|
297
|
+
const resolved = resolve(encoded, location);
|
|
298
|
+
if (is_root_relative(resolved)) {
|
|
299
|
+
enqueue(decoded, decodeURI(resolved), resolved);
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
if (!headers['x-sveltekit-normalize']) {
|
|
303
|
+
mkdirp(dirname(dest));
|
|
304
|
+
|
|
305
|
+
log.warn(`${response.status} ${decoded} -> ${location}`);
|
|
306
|
+
|
|
307
|
+
writeFileSync(
|
|
308
|
+
dest,
|
|
309
|
+
`<meta http-equiv="refresh" content=${escape_html_attr(`0;url=${location}`)}>`
|
|
310
|
+
);
|
|
311
|
+
|
|
312
|
+
written.add(file);
|
|
313
|
+
|
|
314
|
+
if (!prerendered.redirects.has(decoded)) {
|
|
315
|
+
prerendered.redirects.set(decoded, {
|
|
316
|
+
status: response.status,
|
|
317
|
+
location: resolved
|
|
318
|
+
});
|
|
319
|
+
|
|
320
|
+
prerendered.paths.push(decoded);
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
} else {
|
|
324
|
+
log.warn(`location header missing on redirect received from ${decoded}`);
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
return;
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
if (response.status === 200) {
|
|
331
|
+
mkdirp(dirname(dest));
|
|
332
|
+
|
|
333
|
+
log.info(`${response.status} ${decoded}`);
|
|
334
|
+
writeFileSync(dest, body);
|
|
335
|
+
written.add(file);
|
|
336
|
+
|
|
337
|
+
if (is_html) {
|
|
338
|
+
prerendered.pages.set(decoded, {
|
|
339
|
+
file
|
|
340
|
+
});
|
|
341
|
+
} else {
|
|
342
|
+
prerendered.assets.set(decoded, {
|
|
343
|
+
type
|
|
344
|
+
});
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
prerendered.paths.push(decoded);
|
|
348
|
+
} else if (response_type !== OK) {
|
|
349
|
+
handle_http_error({ status: response.status, path: decoded, referrer, referenceType });
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
for (const route of manifest._.routes) {
|
|
354
|
+
if (route.endpoint) {
|
|
355
|
+
const mod = await route.endpoint();
|
|
356
|
+
if (mod.prerender !== undefined) {
|
|
357
|
+
validate_server_exports(mod, route.id);
|
|
358
|
+
|
|
359
|
+
if (mod.prerender && (mod.POST || mod.PATCH || mod.PUT || mod.DELETE)) {
|
|
360
|
+
throw new Error(
|
|
361
|
+
`Cannot prerender a +server file with POST, PATCH, PUT, or DELETE (${route.id})`
|
|
362
|
+
);
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
prerender_map.set(route.id, mod.prerender);
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
if (route.page) {
|
|
370
|
+
const nodes = await Promise.all(
|
|
371
|
+
[...route.page.layouts, route.page.leaf].map((n) => {
|
|
372
|
+
if (n !== undefined) return manifest._.nodes[n]();
|
|
373
|
+
})
|
|
374
|
+
);
|
|
375
|
+
|
|
376
|
+
const layouts = nodes.slice(0, -1);
|
|
377
|
+
const page = nodes.at(-1);
|
|
378
|
+
|
|
379
|
+
for (const layout of layouts) {
|
|
380
|
+
if (layout) {
|
|
381
|
+
validate_common_exports(layout.server, route.id);
|
|
382
|
+
validate_common_exports(layout.universal, route.id);
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
if (page) {
|
|
387
|
+
validate_page_server_exports(page.server, route.id);
|
|
388
|
+
validate_common_exports(page.universal, route.id);
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
const should_prerender = get_option(nodes, 'prerender');
|
|
392
|
+
const prerender =
|
|
393
|
+
should_prerender === true ||
|
|
394
|
+
// Try prerendering if ssr is false and no server needed. Set it to 'auto' so that
|
|
395
|
+
// the route is not removed from the manifest, there could be a server load function.
|
|
396
|
+
// People can opt out of this behavior by explicitly setting prerender to false
|
|
397
|
+
(should_prerender !== false && get_option(nodes, 'ssr') === false && !page?.server?.actions
|
|
398
|
+
? 'auto'
|
|
399
|
+
: false);
|
|
400
|
+
|
|
401
|
+
prerender_map.set(route.id, prerender);
|
|
402
|
+
}
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
for (const entry of config.prerender.entries) {
|
|
406
|
+
if (entry === '*') {
|
|
407
|
+
for (const [id, prerender] of prerender_map) {
|
|
408
|
+
if (prerender) {
|
|
409
|
+
if (id.includes('[')) continue;
|
|
410
|
+
const path = `/${get_route_segments(id).join('/')}`;
|
|
411
|
+
enqueue(null, config.paths.base + path);
|
|
412
|
+
}
|
|
413
|
+
}
|
|
414
|
+
} else {
|
|
415
|
+
enqueue(null, config.paths.base + entry);
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
await q.done();
|
|
420
|
+
|
|
421
|
+
// handle invalid fragment links
|
|
422
|
+
for (const [key, referrers] of expected_hashlinks) {
|
|
423
|
+
const index = key.indexOf('#');
|
|
424
|
+
const path = key.slice(0, index);
|
|
425
|
+
const id = key.slice(index + 1);
|
|
426
|
+
|
|
427
|
+
const hashlinks = actual_hashlinks.get(path);
|
|
428
|
+
// ignore fragment links to pages that were not prerendered
|
|
429
|
+
if (!hashlinks) continue;
|
|
430
|
+
|
|
431
|
+
if (!hashlinks.includes(id)) {
|
|
432
|
+
handle_missing_id({ id, path, referrers: Array.from(referrers) });
|
|
433
|
+
}
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
/** @type {string[]} */
|
|
437
|
+
const not_prerendered = [];
|
|
438
|
+
|
|
439
|
+
for (const [route_id, prerender] of prerender_map) {
|
|
440
|
+
if (prerender === true && !prerendered_routes.has(route_id)) {
|
|
441
|
+
not_prerendered.push(route_id);
|
|
442
|
+
}
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
if (not_prerendered.length > 0) {
|
|
446
|
+
throw new Error(
|
|
447
|
+
`The following routes were marked as prerenderable, but were not prerendered because they were not found while crawling your app:\n${not_prerendered.map(
|
|
448
|
+
(id) => ` - ${id}`
|
|
449
|
+
)}\n\nSee https://kit.svelte.dev/docs/page-options#prerender-troubleshooting for info on how to solve this`
|
|
450
|
+
);
|
|
451
|
+
}
|
|
452
|
+
|
|
453
|
+
output_and_exit({ prerendered, prerender_map });
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
/** @return {string} */
|
|
457
|
+
function getClientAddress() {
|
|
458
|
+
throw new Error('Cannot read clientAddress during prerendering');
|
|
459
|
+
}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @typedef {{
|
|
3
|
+
* fn: () => Promise<any>,
|
|
4
|
+
* fulfil: (value: any) => void,
|
|
5
|
+
* reject: (error: Error) => void
|
|
6
|
+
* }} Task
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
/** @param {number} concurrency */
|
|
10
|
+
export function queue(concurrency) {
|
|
11
|
+
/** @type {Task[]} */
|
|
12
|
+
const tasks = [];
|
|
13
|
+
|
|
14
|
+
let current = 0;
|
|
15
|
+
|
|
16
|
+
/** @type {(value?: any) => void} */
|
|
17
|
+
let fulfil;
|
|
18
|
+
|
|
19
|
+
/** @type {(error: Error) => void} */
|
|
20
|
+
let reject;
|
|
21
|
+
|
|
22
|
+
let closed = false;
|
|
23
|
+
|
|
24
|
+
const done = new Promise((f, r) => {
|
|
25
|
+
fulfil = f;
|
|
26
|
+
reject = r;
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
done.catch(() => {
|
|
30
|
+
// this is necessary in case a catch handler is never added
|
|
31
|
+
// to the done promise by the user
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
function dequeue() {
|
|
35
|
+
if (current < concurrency) {
|
|
36
|
+
const task = tasks.shift();
|
|
37
|
+
|
|
38
|
+
if (task) {
|
|
39
|
+
current += 1;
|
|
40
|
+
const promise = Promise.resolve(task.fn());
|
|
41
|
+
|
|
42
|
+
promise
|
|
43
|
+
.then(task.fulfil, (err) => {
|
|
44
|
+
task.reject(err);
|
|
45
|
+
reject(err);
|
|
46
|
+
})
|
|
47
|
+
.then(() => {
|
|
48
|
+
current -= 1;
|
|
49
|
+
dequeue();
|
|
50
|
+
});
|
|
51
|
+
} else if (current === 0) {
|
|
52
|
+
closed = true;
|
|
53
|
+
fulfil();
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
return {
|
|
59
|
+
/** @param {() => any} fn */
|
|
60
|
+
add: (fn) => {
|
|
61
|
+
if (closed) throw new Error('Cannot add tasks to a queue that has ended');
|
|
62
|
+
|
|
63
|
+
const promise = new Promise((fulfil, reject) => {
|
|
64
|
+
tasks.push({ fn, fulfil, reject });
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
dequeue();
|
|
68
|
+
return promise;
|
|
69
|
+
},
|
|
70
|
+
|
|
71
|
+
done: () => {
|
|
72
|
+
if (current === 0) {
|
|
73
|
+
closed = true;
|
|
74
|
+
fulfil();
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
return done;
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
}
|
|
File without changes
|