@sveltejs/kit 1.0.0-next.346 → 1.0.0-next.349
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/assets/server/index.js +24 -13
- package/dist/chunks/constants.js +1 -1
- package/dist/chunks/index.js +37 -34
- package/dist/chunks/index2.js +2 -0
- package/dist/chunks/index3.js +1 -2
- package/dist/chunks/index4.js +150 -198
- package/dist/chunks/index5.js +1 -3
- package/dist/chunks/multipart-parser.js +2 -8
- package/dist/chunks/plugin.js +41 -28
- package/dist/chunks/sync.js +4 -4
- package/dist/chunks/write_tsconfig.js +15 -14
- package/dist/cli.js +55 -158
- package/dist/node/polyfills.js +212 -72
- package/package.json +24 -9
- package/types/ambient.d.ts +1 -1
- package/types/index.d.ts +61 -59
- package/types/internal.d.ts +3 -0
- package/dist/chunks/cert.js +0 -28154
package/assets/server/index.js
CHANGED
|
@@ -1077,6 +1077,7 @@ const updated = {
|
|
|
1077
1077
|
};
|
|
1078
1078
|
|
|
1079
1079
|
/**
|
|
1080
|
+
* Creates the HTML response.
|
|
1080
1081
|
* @param {{
|
|
1081
1082
|
* branch: Array<import('./types').Loaded>;
|
|
1082
1083
|
* options: import('types').SSROptions;
|
|
@@ -2027,6 +2028,7 @@ function path_matches(path, constraint) {
|
|
|
2027
2028
|
}
|
|
2028
2029
|
|
|
2029
2030
|
/**
|
|
2031
|
+
* Calls the user's `load` function.
|
|
2030
2032
|
* @param {{
|
|
2031
2033
|
* event: import('types').RequestEvent;
|
|
2032
2034
|
* options: import('types').SSROptions;
|
|
@@ -2661,6 +2663,7 @@ async function respond_with_error({
|
|
|
2661
2663
|
*/
|
|
2662
2664
|
|
|
2663
2665
|
/**
|
|
2666
|
+
* Gets the nodes, calls `load` for each of them, and then calls render to build the HTML response.
|
|
2664
2667
|
* @param {{
|
|
2665
2668
|
* event: import('types').RequestEvent;
|
|
2666
2669
|
* options: SSROptions;
|
|
@@ -3093,8 +3096,9 @@ async function respond(request, options, state) {
|
|
|
3093
3096
|
const is_data_request = decoded.endsWith(DATA_SUFFIX);
|
|
3094
3097
|
|
|
3095
3098
|
if (is_data_request) {
|
|
3096
|
-
|
|
3097
|
-
|
|
3099
|
+
const data_suffix_length = DATA_SUFFIX.length - (options.trailing_slash === 'always' ? 1 : 0);
|
|
3100
|
+
decoded = decoded.slice(0, -data_suffix_length) || '/';
|
|
3101
|
+
url = new URL(url.origin + url.pathname.slice(0, -data_suffix_length) + url.search);
|
|
3098
3102
|
}
|
|
3099
3103
|
|
|
3100
3104
|
if (!state.prerendering?.fallback) {
|
|
@@ -3113,19 +3117,26 @@ async function respond(request, options, state) {
|
|
|
3113
3117
|
}
|
|
3114
3118
|
}
|
|
3115
3119
|
|
|
3116
|
-
if (route
|
|
3117
|
-
|
|
3120
|
+
if (route) {
|
|
3121
|
+
if (route.type === 'page') {
|
|
3122
|
+
const normalized = normalize_path(url.pathname, options.trailing_slash);
|
|
3118
3123
|
|
|
3119
|
-
|
|
3124
|
+
if (normalized !== url.pathname && !state.prerendering?.fallback) {
|
|
3125
|
+
return new Response(undefined, {
|
|
3126
|
+
status: 301,
|
|
3127
|
+
headers: {
|
|
3128
|
+
'x-sveltekit-normalize': '1',
|
|
3129
|
+
location:
|
|
3130
|
+
// ensure paths starting with '//' are not treated as protocol-relative
|
|
3131
|
+
(normalized.startsWith('//') ? url.origin + normalized : normalized) +
|
|
3132
|
+
(url.search === '?' ? '' : url.search)
|
|
3133
|
+
}
|
|
3134
|
+
});
|
|
3135
|
+
}
|
|
3136
|
+
} else if (is_data_request) {
|
|
3137
|
+
// requesting /__data.json should fail for a standalone endpoint
|
|
3120
3138
|
return new Response(undefined, {
|
|
3121
|
-
status:
|
|
3122
|
-
headers: {
|
|
3123
|
-
'x-sveltekit-normalize': '1',
|
|
3124
|
-
location:
|
|
3125
|
-
// ensure paths starting with '//' are not treated as protocol-relative
|
|
3126
|
-
(normalized.startsWith('//') ? url.origin + normalized : normalized) +
|
|
3127
|
-
(url.search === '?' ? '' : url.search)
|
|
3128
|
-
}
|
|
3139
|
+
status: 404
|
|
3129
3140
|
});
|
|
3130
3141
|
}
|
|
3131
3142
|
}
|
package/dist/chunks/constants.js
CHANGED
package/dist/chunks/index.js
CHANGED
|
@@ -12,16 +12,18 @@ import { pathToFileURL, URL as URL$1 } from 'url';
|
|
|
12
12
|
import { installPolyfills } from '../node/polyfills.js';
|
|
13
13
|
import './write_tsconfig.js';
|
|
14
14
|
import 'chokidar';
|
|
15
|
-
import 'child_process';
|
|
16
|
-
import 'net';
|
|
17
15
|
import 'sade';
|
|
18
16
|
import 'os';
|
|
19
17
|
import 'node:http';
|
|
20
18
|
import 'node:https';
|
|
21
19
|
import 'node:zlib';
|
|
22
20
|
import 'node:stream';
|
|
21
|
+
import 'node:buffer';
|
|
23
22
|
import 'node:util';
|
|
24
23
|
import 'node:url';
|
|
24
|
+
import 'node:net';
|
|
25
|
+
import 'node:fs';
|
|
26
|
+
import 'node:path';
|
|
25
27
|
import 'crypto';
|
|
26
28
|
|
|
27
29
|
const absolute = /^([a-z]+:)?\/?\//;
|
|
@@ -85,7 +87,10 @@ function normalize_path(path, trailing_slash) {
|
|
|
85
87
|
* @typedef {import('rollup').OutputAsset} OutputAsset
|
|
86
88
|
*/
|
|
87
89
|
|
|
88
|
-
/**
|
|
90
|
+
/**
|
|
91
|
+
* Invokes Vite.
|
|
92
|
+
* @param {import('vite').UserConfig} config
|
|
93
|
+
*/
|
|
89
94
|
async function create_build(config) {
|
|
90
95
|
const { output } = /** @type {RollupOutput} */ (await vite.build(config));
|
|
91
96
|
|
|
@@ -101,6 +106,7 @@ async function create_build(config) {
|
|
|
101
106
|
}
|
|
102
107
|
|
|
103
108
|
/**
|
|
109
|
+
* Adds transitive JS and CSS dependencies to the js and css inputs.
|
|
104
110
|
* @param {string} file
|
|
105
111
|
* @param {import('vite').Manifest} manifest
|
|
106
112
|
* @param {Set<string>} css
|
|
@@ -122,6 +128,7 @@ function find_deps(file, manifest, js, css) {
|
|
|
122
128
|
}
|
|
123
129
|
|
|
124
130
|
/**
|
|
131
|
+
* The Vite configuration that we use by default.
|
|
125
132
|
* @param {{
|
|
126
133
|
* client_out_dir?: string;
|
|
127
134
|
* config: import('types').ValidatedConfig;
|
|
@@ -133,7 +140,7 @@ function find_deps(file, manifest, js, css) {
|
|
|
133
140
|
*/
|
|
134
141
|
const get_default_config = function ({ client_out_dir, config, input, output_dir, ssr }) {
|
|
135
142
|
return {
|
|
136
|
-
base: assets_base(config),
|
|
143
|
+
base: assets_base(config.kit),
|
|
137
144
|
build: {
|
|
138
145
|
cssCodeSplit: true,
|
|
139
146
|
manifest: true,
|
|
@@ -154,10 +161,6 @@ const get_default_config = function ({ client_out_dir, config, input, output_dir
|
|
|
154
161
|
plugins: [
|
|
155
162
|
svelte({
|
|
156
163
|
...config,
|
|
157
|
-
compilerOptions: {
|
|
158
|
-
...config.compilerOptions,
|
|
159
|
-
hydratable: !!config.kit.browser.hydrate
|
|
160
|
-
},
|
|
161
164
|
configFile: false
|
|
162
165
|
})
|
|
163
166
|
],
|
|
@@ -165,21 +168,21 @@ const get_default_config = function ({ client_out_dir, config, input, output_dir
|
|
|
165
168
|
// if it happens to be 'public' instead of 'static'
|
|
166
169
|
publicDir: false,
|
|
167
170
|
resolve: {
|
|
168
|
-
alias: get_aliases(config)
|
|
171
|
+
alias: get_aliases(config.kit)
|
|
169
172
|
}
|
|
170
173
|
};
|
|
171
174
|
};
|
|
172
175
|
|
|
173
176
|
/**
|
|
174
|
-
* @param {import('types').
|
|
177
|
+
* @param {import('types').ValidatedKitConfig} config
|
|
175
178
|
* @returns {string}
|
|
176
179
|
*/
|
|
177
180
|
function assets_base(config) {
|
|
178
181
|
// TODO this is so that Vite's preloading works. Unfortunately, it fails
|
|
179
182
|
// during `svelte-kit preview`, because we use a local asset path. This
|
|
180
183
|
// may be fixed in Vite 3: https://github.com/vitejs/vite/issues/2009
|
|
181
|
-
const { base, assets } = config.
|
|
182
|
-
return `${assets || base}/${config.
|
|
184
|
+
const { base, assets } = config.paths;
|
|
185
|
+
return `${assets || base}/${config.appDir}/immutable/`;
|
|
183
186
|
}
|
|
184
187
|
|
|
185
188
|
/**
|
|
@@ -244,7 +247,7 @@ async function build_service_worker(
|
|
|
244
247
|
|
|
245
248
|
/** @type {[any, string[]]} */
|
|
246
249
|
const [merged_config, conflicts] = deep_merge(await config.kit.vite(), {
|
|
247
|
-
base: assets_base(config),
|
|
250
|
+
base: assets_base(config.kit),
|
|
248
251
|
build: {
|
|
249
252
|
lib: {
|
|
250
253
|
entry: service_worker_entry_file,
|
|
@@ -402,7 +405,7 @@ export class Server {
|
|
|
402
405
|
error.stack = this.options.get_stack(error);
|
|
403
406
|
},
|
|
404
407
|
hooks: null,
|
|
405
|
-
hydrate: ${s(config.
|
|
408
|
+
hydrate: ${s(config.compilerOptions.hydratable)},
|
|
406
409
|
manifest,
|
|
407
410
|
method_override: ${s(config.kit.methodOverride)},
|
|
408
411
|
paths: { base, assets },
|
|
@@ -507,7 +510,7 @@ async function build_server(options, client) {
|
|
|
507
510
|
config,
|
|
508
511
|
hooks: app_relative(hooks_file),
|
|
509
512
|
has_service_worker: config.kit.serviceWorker.register && !!service_worker_entry_file,
|
|
510
|
-
runtime: get_runtime_path(config),
|
|
513
|
+
runtime: get_runtime_path(config.kit),
|
|
511
514
|
template: load_template(cwd, config)
|
|
512
515
|
})
|
|
513
516
|
);
|
|
@@ -1027,7 +1030,7 @@ const REDIRECT = 3;
|
|
|
1027
1030
|
|
|
1028
1031
|
/**
|
|
1029
1032
|
* @param {{
|
|
1030
|
-
* config: import('types').
|
|
1033
|
+
* config: import('types').ValidatedKitConfig;
|
|
1031
1034
|
* entries: string[];
|
|
1032
1035
|
* files: Set<string>;
|
|
1033
1036
|
* log: Logger;
|
|
@@ -1042,36 +1045,36 @@ async function prerender({ config, entries, files, log }) {
|
|
|
1042
1045
|
paths: []
|
|
1043
1046
|
};
|
|
1044
1047
|
|
|
1045
|
-
if (!config.
|
|
1048
|
+
if (!config.prerender.enabled) {
|
|
1046
1049
|
return prerendered;
|
|
1047
1050
|
}
|
|
1048
1051
|
|
|
1049
1052
|
installPolyfills();
|
|
1050
1053
|
|
|
1051
|
-
const server_root = join(config.
|
|
1054
|
+
const server_root = join(config.outDir, 'output');
|
|
1052
1055
|
|
|
1053
1056
|
/** @type {import('types').ServerModule} */
|
|
1054
1057
|
const { Server, override } = await import(pathToFileURL(`${server_root}/server/index.js`).href);
|
|
1055
1058
|
const { manifest } = await import(pathToFileURL(`${server_root}/server/manifest.js`).href);
|
|
1056
1059
|
|
|
1057
1060
|
override({
|
|
1058
|
-
paths: config.
|
|
1061
|
+
paths: config.paths,
|
|
1059
1062
|
prerendering: true,
|
|
1060
|
-
read: (file) => readFileSync(join(config.
|
|
1063
|
+
read: (file) => readFileSync(join(config.files.assets, file))
|
|
1061
1064
|
});
|
|
1062
1065
|
|
|
1063
1066
|
const server = new Server(manifest);
|
|
1064
1067
|
|
|
1065
|
-
const error = normalise_error_handler(log, config.
|
|
1068
|
+
const error = normalise_error_handler(log, config.prerender.onError);
|
|
1066
1069
|
|
|
1067
|
-
const q = queue(config.
|
|
1070
|
+
const q = queue(config.prerender.concurrency);
|
|
1068
1071
|
|
|
1069
1072
|
/**
|
|
1070
1073
|
* @param {string} path
|
|
1071
1074
|
* @param {boolean} is_html
|
|
1072
1075
|
*/
|
|
1073
1076
|
function output_filename(path, is_html) {
|
|
1074
|
-
const file = path.slice(config.
|
|
1077
|
+
const file = path.slice(config.paths.base.length + 1);
|
|
1075
1078
|
|
|
1076
1079
|
if (file === '') {
|
|
1077
1080
|
return 'index.html';
|
|
@@ -1096,7 +1099,7 @@ async function prerender({ config, entries, files, log }) {
|
|
|
1096
1099
|
if (seen.has(decoded)) return;
|
|
1097
1100
|
seen.add(decoded);
|
|
1098
1101
|
|
|
1099
|
-
const file = decoded.slice(config.
|
|
1102
|
+
const file = decoded.slice(config.paths.base.length + 1);
|
|
1100
1103
|
if (files.has(file)) return;
|
|
1101
1104
|
|
|
1102
1105
|
return q.add(() => visit(decoded, encoded || encodeURI(decoded), referrer));
|
|
@@ -1108,7 +1111,7 @@ async function prerender({ config, entries, files, log }) {
|
|
|
1108
1111
|
* @param {string?} referrer
|
|
1109
1112
|
*/
|
|
1110
1113
|
async function visit(decoded, encoded, referrer) {
|
|
1111
|
-
if (!decoded.startsWith(config.
|
|
1114
|
+
if (!decoded.startsWith(config.paths.base)) {
|
|
1112
1115
|
error({ status: 404, path: decoded, referrer, referenceType: 'linked' });
|
|
1113
1116
|
return;
|
|
1114
1117
|
}
|
|
@@ -1145,7 +1148,7 @@ async function prerender({ config, entries, files, log }) {
|
|
|
1145
1148
|
);
|
|
1146
1149
|
}
|
|
1147
1150
|
|
|
1148
|
-
if (config.
|
|
1151
|
+
if (config.prerender.crawl && response.headers.get('content-type') === 'text/html') {
|
|
1149
1152
|
for (const href of crawl(text)) {
|
|
1150
1153
|
if (href.startsWith('data:') || href.startsWith('#')) continue;
|
|
1151
1154
|
|
|
@@ -1174,7 +1177,7 @@ async function prerender({ config, entries, files, log }) {
|
|
|
1174
1177
|
const is_html = response_type === REDIRECT || type === 'text/html';
|
|
1175
1178
|
|
|
1176
1179
|
const file = output_filename(decoded, is_html);
|
|
1177
|
-
const dest = `${config.
|
|
1180
|
+
const dest = `${config.outDir}/output/prerendered/${category}/${file}`;
|
|
1178
1181
|
|
|
1179
1182
|
if (written.has(file)) return;
|
|
1180
1183
|
|
|
@@ -1238,14 +1241,14 @@ async function prerender({ config, entries, files, log }) {
|
|
|
1238
1241
|
}
|
|
1239
1242
|
}
|
|
1240
1243
|
|
|
1241
|
-
if (config.
|
|
1242
|
-
for (const entry of config.
|
|
1244
|
+
if (config.prerender.enabled) {
|
|
1245
|
+
for (const entry of config.prerender.entries) {
|
|
1243
1246
|
if (entry === '*') {
|
|
1244
1247
|
for (const entry of entries) {
|
|
1245
|
-
enqueue(null, config.
|
|
1248
|
+
enqueue(null, config.paths.base + entry); // TODO can we pre-normalize these?
|
|
1246
1249
|
}
|
|
1247
1250
|
} else {
|
|
1248
|
-
enqueue(null, config.
|
|
1251
|
+
enqueue(null, config.paths.base + entry);
|
|
1249
1252
|
}
|
|
1250
1253
|
}
|
|
1251
1254
|
|
|
@@ -1260,7 +1263,7 @@ async function prerender({ config, entries, files, log }) {
|
|
|
1260
1263
|
}
|
|
1261
1264
|
});
|
|
1262
1265
|
|
|
1263
|
-
const file = `${config.
|
|
1266
|
+
const file = `${config.outDir}/output/prerendered/fallback.html`;
|
|
1264
1267
|
mkdirp(dirname(file));
|
|
1265
1268
|
writeFileSync(file, await rendered.text());
|
|
1266
1269
|
|
|
@@ -1295,7 +1298,7 @@ async function build(config, { log }) {
|
|
|
1295
1298
|
build_dir,
|
|
1296
1299
|
manifest_data,
|
|
1297
1300
|
output_dir,
|
|
1298
|
-
client_entry_file: path__default.relative(cwd, `${get_runtime_path(config)}/client/start.js`),
|
|
1301
|
+
client_entry_file: path__default.relative(cwd, `${get_runtime_path(config.kit)}/client/start.js`),
|
|
1299
1302
|
service_worker_entry_file: resolve_entry(config.kit.files.serviceWorker)
|
|
1300
1303
|
};
|
|
1301
1304
|
|
|
@@ -1334,7 +1337,7 @@ async function build(config, { log }) {
|
|
|
1334
1337
|
});
|
|
1335
1338
|
|
|
1336
1339
|
const prerendered = await prerender({
|
|
1337
|
-
config,
|
|
1340
|
+
config: config.kit,
|
|
1338
1341
|
entries: options.manifest_data.routes
|
|
1339
1342
|
.map((route) => (route.type === 'page' ? route.path : ''))
|
|
1340
1343
|
.filter(Boolean),
|
package/dist/chunks/index2.js
CHANGED
|
@@ -2,6 +2,8 @@ import { s, p as parse_route_id } from './misc.js';
|
|
|
2
2
|
import { b as get_mime_lookup } from '../cli.js';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
|
+
* Generates the data used to write the server-side manifest.js file. This data is used in the Vite
|
|
6
|
+
* build process, to power routing, etc.
|
|
5
7
|
* @param {{
|
|
6
8
|
* build_data: import('types').BuildData;
|
|
7
9
|
* relative_path: string;
|
package/dist/chunks/index3.js
CHANGED
|
@@ -4,8 +4,6 @@ import { g as generate_manifest } from './index2.js';
|
|
|
4
4
|
import 'chokidar';
|
|
5
5
|
import 'fs';
|
|
6
6
|
import 'path';
|
|
7
|
-
import 'child_process';
|
|
8
|
-
import 'net';
|
|
9
7
|
import 'sade';
|
|
10
8
|
import 'vite';
|
|
11
9
|
import 'url';
|
|
@@ -13,6 +11,7 @@ import 'os';
|
|
|
13
11
|
import './misc.js';
|
|
14
12
|
|
|
15
13
|
/**
|
|
14
|
+
* Creates the Builder which is passed to adapters for building the application.
|
|
16
15
|
* @param {{
|
|
17
16
|
* config: import('types').ValidatedConfig;
|
|
18
17
|
* build_data: import('types').BuildData;
|