@sveltejs/kit 1.0.0-next.288 → 1.0.0-next.290
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/client/start.js +10 -11
- package/assets/server/index.js +0 -1
- package/dist/chunks/amp_hook.js +1 -1
- package/dist/chunks/{build.js → constants.js} +6 -1
- package/dist/chunks/index.js +22 -10
- package/dist/chunks/index2.js +545 -728
- package/dist/chunks/index3.js +99 -622
- package/dist/chunks/index4.js +868 -96
- package/dist/chunks/index5.js +107 -842
- package/dist/chunks/index6.js +15546 -132
- package/dist/chunks/index7.js +3746 -15123
- package/dist/chunks/tsconfig.js +1032 -0
- package/dist/cli.js +15 -17
- package/package.json +10 -2
- package/types/index.d.ts +22 -7
- package/types/internal.d.ts +7 -3
- package/types/private.d.ts +12 -14
- package/dist/chunks/index8.js +0 -4207
package/dist/chunks/index3.js
CHANGED
|
@@ -1,643 +1,120 @@
|
|
|
1
|
-
import fs__default from 'fs';
|
|
2
|
-
import path__default from 'path';
|
|
3
|
-
import { p as print_config_conflicts, b as SVELTE_KIT, d as copy_assets, f as posixify, e as get_aliases, a as resolve_entry, l as load_template, r as runtime, m as mkdirp, h as rimraf } from '../cli.js';
|
|
4
|
-
import { d as deep_merge, a as create_app, c as create_manifest_data } from './index2.js';
|
|
5
|
-
import { g as generate_manifest } from './index4.js';
|
|
6
|
-
import vite from 'vite';
|
|
7
1
|
import { s } from './misc.js';
|
|
8
|
-
import {
|
|
9
|
-
import 'sade';
|
|
10
|
-
import 'child_process';
|
|
11
|
-
import 'net';
|
|
12
|
-
import 'url';
|
|
13
|
-
import 'os';
|
|
2
|
+
import { a as get_mime_lookup } from '../cli.js';
|
|
14
3
|
|
|
15
4
|
/**
|
|
16
|
-
* @param {
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
* manifest_data: import('types').ManifestData
|
|
21
|
-
* output_dir: string;
|
|
22
|
-
* service_worker_entry_file: string | null;
|
|
23
|
-
* }} options
|
|
24
|
-
* @param {import('vite').Manifest} client_manifest
|
|
5
|
+
* @param {import('types').BuildData} build_data;
|
|
6
|
+
* @param {string} relative_path;
|
|
7
|
+
* @param {import('types').RouteData[]} routes;
|
|
8
|
+
* @param {'esm' | 'cjs'} format
|
|
25
9
|
*/
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
10
|
+
function generate_manifest(
|
|
11
|
+
build_data,
|
|
12
|
+
relative_path,
|
|
13
|
+
routes = build_data.manifest_data.routes,
|
|
14
|
+
format = 'esm'
|
|
29
15
|
) {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
});
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
const service_worker = `${cwd}/${SVELTE_KIT}/generated/service-worker.js`;
|
|
43
|
-
|
|
44
|
-
fs__default.writeFileSync(
|
|
45
|
-
service_worker,
|
|
46
|
-
`
|
|
47
|
-
export const timestamp = ${Date.now()};
|
|
48
|
-
|
|
49
|
-
export const build = [
|
|
50
|
-
${Array.from(app_files)
|
|
51
|
-
.map((file) => `${s(`${config.kit.paths.base}/${config.kit.appDir}/${file}`)}`)
|
|
52
|
-
.join(',\n\t\t\t\t')}
|
|
53
|
-
];
|
|
54
|
-
|
|
55
|
-
export const files = [
|
|
56
|
-
${manifest_data.assets
|
|
57
|
-
.map((asset) => `${s(`${config.kit.paths.base}/${asset.file}`)}`)
|
|
58
|
-
.join(',\n\t\t\t\t')}
|
|
59
|
-
];
|
|
60
|
-
`
|
|
61
|
-
.replace(/^\t{3}/gm, '')
|
|
62
|
-
.trim()
|
|
63
|
-
);
|
|
64
|
-
|
|
65
|
-
/** @type {[any, string[]]} */
|
|
66
|
-
const [merged_config, conflicts] = deep_merge(await config.kit.vite(), {
|
|
67
|
-
configFile: false,
|
|
68
|
-
root: cwd,
|
|
69
|
-
base: assets_base,
|
|
70
|
-
build: {
|
|
71
|
-
lib: {
|
|
72
|
-
entry: service_worker_entry_file,
|
|
73
|
-
name: 'app',
|
|
74
|
-
formats: ['es']
|
|
75
|
-
},
|
|
76
|
-
rollupOptions: {
|
|
77
|
-
output: {
|
|
78
|
-
entryFileNames: 'service-worker.js'
|
|
79
|
-
}
|
|
80
|
-
},
|
|
81
|
-
outDir: `${output_dir}/client`,
|
|
82
|
-
emptyOutDir: false
|
|
83
|
-
},
|
|
84
|
-
resolve: {
|
|
85
|
-
alias: {
|
|
86
|
-
'$service-worker': service_worker,
|
|
87
|
-
$lib: config.kit.files.lib
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
});
|
|
91
|
-
|
|
92
|
-
print_config_conflicts(conflicts, 'kit.vite.', 'build_service_worker');
|
|
93
|
-
|
|
94
|
-
await vite.build(merged_config);
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
/** @param {import('vite').UserConfig} config */
|
|
98
|
-
async function create_build(config) {
|
|
99
|
-
const { output } = /** @type {import('rollup').RollupOutput} */ (await vite.build(config));
|
|
100
|
-
|
|
101
|
-
const chunks = /** @type {import('rollup').OutputChunk[]} */ (
|
|
102
|
-
output.filter((output) => output.type === 'chunk')
|
|
103
|
-
);
|
|
104
|
-
|
|
105
|
-
const assets = /** @type {import('rollup').OutputAsset[]} */ (
|
|
106
|
-
output.filter((output) => output.type === 'asset')
|
|
107
|
-
);
|
|
108
|
-
|
|
109
|
-
return { chunks, assets };
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
/**
|
|
113
|
-
* @param {string} file
|
|
114
|
-
* @param {import('vite').Manifest} manifest
|
|
115
|
-
* @param {Set<string>} css
|
|
116
|
-
* @param {Set<string>} js
|
|
117
|
-
* @returns
|
|
118
|
-
*/
|
|
119
|
-
function find_deps(file, manifest, js, css) {
|
|
120
|
-
const chunk = manifest[file];
|
|
121
|
-
|
|
122
|
-
if (js.has(chunk.file)) return;
|
|
123
|
-
js.add(chunk.file);
|
|
124
|
-
|
|
125
|
-
if (chunk.css) {
|
|
126
|
-
chunk.css.forEach((file) => css.add(file));
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
if (chunk.imports) {
|
|
130
|
-
chunk.imports.forEach((file) => find_deps(file, manifest, js, css));
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
/**
|
|
135
|
-
* @param {{
|
|
136
|
-
* cwd: string;
|
|
137
|
-
* assets_base: string;
|
|
138
|
-
* config: import('types').ValidatedConfig
|
|
139
|
-
* manifest_data: import('types').ManifestData
|
|
140
|
-
* output_dir: string;
|
|
141
|
-
* client_entry_file: string;
|
|
142
|
-
* service_worker_entry_file: string | null;
|
|
143
|
-
* service_worker_register: boolean;
|
|
144
|
-
* }} options
|
|
145
|
-
*/
|
|
146
|
-
async function build_client({
|
|
147
|
-
cwd,
|
|
148
|
-
assets_base,
|
|
149
|
-
config,
|
|
150
|
-
manifest_data,
|
|
151
|
-
output_dir,
|
|
152
|
-
client_entry_file
|
|
153
|
-
}) {
|
|
154
|
-
process.env.VITE_SVELTEKIT_APP_VERSION = config.kit.version.name;
|
|
155
|
-
process.env.VITE_SVELTEKIT_APP_VERSION_FILE = `${config.kit.appDir}/version.json`;
|
|
156
|
-
process.env.VITE_SVELTEKIT_APP_VERSION_POLL_INTERVAL = `${config.kit.version.pollInterval}`;
|
|
157
|
-
|
|
158
|
-
create_app({
|
|
159
|
-
manifest_data,
|
|
160
|
-
output: `${SVELTE_KIT}/generated`,
|
|
161
|
-
cwd
|
|
162
|
-
});
|
|
163
|
-
|
|
164
|
-
copy_assets(`${SVELTE_KIT}/runtime`);
|
|
165
|
-
|
|
166
|
-
process.env.VITE_SVELTEKIT_AMP = config.kit.amp ? 'true' : '';
|
|
167
|
-
|
|
168
|
-
const client_out_dir = `${output_dir}/client/${config.kit.appDir}`;
|
|
169
|
-
|
|
170
|
-
/** @type {Record<string, string>} */
|
|
171
|
-
const input = {
|
|
172
|
-
start: path__default.resolve(cwd, client_entry_file)
|
|
173
|
-
};
|
|
174
|
-
|
|
175
|
-
// This step is optional — Vite/Rollup will create the necessary chunks
|
|
176
|
-
// for everything regardless — but it means that entry chunks reflect
|
|
177
|
-
// their location in the source code, which is helpful for debugging
|
|
178
|
-
manifest_data.components.forEach((file) => {
|
|
179
|
-
const resolved = path__default.resolve(cwd, file);
|
|
180
|
-
const relative = path__default.relative(config.kit.files.routes, resolved);
|
|
181
|
-
|
|
182
|
-
const name = relative.startsWith('..')
|
|
183
|
-
? path__default.basename(file)
|
|
184
|
-
: posixify(path__default.join('pages', relative));
|
|
185
|
-
input[name] = resolved;
|
|
186
|
-
});
|
|
187
|
-
|
|
188
|
-
/** @type {[any, string[]]} */
|
|
189
|
-
const [merged_config, conflicts] = deep_merge(await config.kit.vite(), {
|
|
190
|
-
configFile: false,
|
|
191
|
-
root: cwd,
|
|
192
|
-
base: assets_base,
|
|
193
|
-
build: {
|
|
194
|
-
cssCodeSplit: true,
|
|
195
|
-
manifest: true,
|
|
196
|
-
outDir: client_out_dir,
|
|
197
|
-
polyfillDynamicImport: false,
|
|
198
|
-
rollupOptions: {
|
|
199
|
-
input,
|
|
200
|
-
output: {
|
|
201
|
-
entryFileNames: '[name]-[hash].js',
|
|
202
|
-
chunkFileNames: 'chunks/[name]-[hash].js',
|
|
203
|
-
assetFileNames: 'assets/[name]-[hash][extname]'
|
|
204
|
-
},
|
|
205
|
-
preserveEntrySignatures: 'strict'
|
|
206
|
-
}
|
|
207
|
-
},
|
|
208
|
-
resolve: {
|
|
209
|
-
alias: get_aliases(config)
|
|
210
|
-
},
|
|
211
|
-
plugins: [
|
|
212
|
-
svelte({
|
|
213
|
-
extensions: config.extensions,
|
|
214
|
-
// In AMP mode, we know that there are no conditional component imports. In that case, we
|
|
215
|
-
// don't need to include CSS for components that are imported but unused, so we can just
|
|
216
|
-
// include rendered CSS.
|
|
217
|
-
// This would also apply if hydrate and router are both false, but we don't know if one
|
|
218
|
-
// has been enabled at the page level, so we don't do anything there.
|
|
219
|
-
emitCss: !config.kit.amp,
|
|
220
|
-
compilerOptions: {
|
|
221
|
-
hydratable: !!config.kit.browser.hydrate
|
|
222
|
-
}
|
|
223
|
-
})
|
|
224
|
-
]
|
|
225
|
-
});
|
|
226
|
-
|
|
227
|
-
print_config_conflicts(conflicts, 'kit.vite.', 'build_client');
|
|
228
|
-
|
|
229
|
-
const { chunks, assets } = await create_build(merged_config);
|
|
230
|
-
|
|
231
|
-
/** @type {import('vite').Manifest} */
|
|
232
|
-
const vite_manifest = JSON.parse(fs__default.readFileSync(`${client_out_dir}/manifest.json`, 'utf-8'));
|
|
233
|
-
|
|
234
|
-
const entry = posixify(client_entry_file);
|
|
235
|
-
const entry_js = new Set();
|
|
236
|
-
const entry_css = new Set();
|
|
237
|
-
find_deps(entry, vite_manifest, entry_js, entry_css);
|
|
238
|
-
|
|
239
|
-
fs__default.writeFileSync(
|
|
240
|
-
`${client_out_dir}/version.json`,
|
|
241
|
-
JSON.stringify({ version: process.env.VITE_SVELTEKIT_APP_VERSION })
|
|
242
|
-
);
|
|
243
|
-
|
|
244
|
-
return {
|
|
245
|
-
assets,
|
|
246
|
-
chunks,
|
|
247
|
-
entry: {
|
|
248
|
-
file: vite_manifest[entry].file,
|
|
249
|
-
js: Array.from(entry_js),
|
|
250
|
-
css: Array.from(entry_css)
|
|
251
|
-
},
|
|
252
|
-
vite_manifest
|
|
253
|
-
};
|
|
254
|
-
}
|
|
255
|
-
|
|
256
|
-
/**
|
|
257
|
-
* @param {{
|
|
258
|
-
* hooks: string;
|
|
259
|
-
* config: import('types').ValidatedConfig;
|
|
260
|
-
* has_service_worker: boolean;
|
|
261
|
-
* template: string;
|
|
262
|
-
* }} opts
|
|
263
|
-
* @returns
|
|
264
|
-
*/
|
|
265
|
-
const server_template = ({ config, hooks, has_service_worker, template }) => `
|
|
266
|
-
import root from '__GENERATED__/root.svelte';
|
|
267
|
-
import { respond } from '${runtime}/server/index.js';
|
|
268
|
-
import { set_paths, assets, base } from '${runtime}/paths.js';
|
|
269
|
-
import { set_prerendering } from '${runtime}/env.js';
|
|
270
|
-
import * as user_hooks from ${s(hooks)};
|
|
271
|
-
|
|
272
|
-
const template = ({ head, body, assets, nonce }) => ${s(template)
|
|
273
|
-
.replace('%svelte.head%', '" + head + "')
|
|
274
|
-
.replace('%svelte.body%', '" + body + "')
|
|
275
|
-
.replace(/%svelte\.assets%/g, '" + assets + "')
|
|
276
|
-
.replace(/%svelte\.nonce%/g, '" + nonce + "')};
|
|
277
|
-
|
|
278
|
-
let read = null;
|
|
279
|
-
|
|
280
|
-
set_paths(${s(config.kit.paths)});
|
|
281
|
-
|
|
282
|
-
// this looks redundant, but the indirection allows us to access
|
|
283
|
-
// named imports without triggering Rollup's missing import detection
|
|
284
|
-
const get_hooks = hooks => ({
|
|
285
|
-
getSession: hooks.getSession || (() => ({})),
|
|
286
|
-
handle: hooks.handle || (({ event, resolve }) => resolve(event)),
|
|
287
|
-
handleError: hooks.handleError || (({ error }) => console.error(error.stack)),
|
|
288
|
-
externalFetch: hooks.externalFetch || fetch
|
|
289
|
-
});
|
|
290
|
-
|
|
291
|
-
let default_protocol = 'https';
|
|
292
|
-
|
|
293
|
-
// allow paths to be globally overridden
|
|
294
|
-
// in svelte-kit preview and in prerendering
|
|
295
|
-
export function override(settings) {
|
|
296
|
-
default_protocol = settings.protocol || default_protocol;
|
|
297
|
-
set_paths(settings.paths);
|
|
298
|
-
set_prerendering(settings.prerendering);
|
|
299
|
-
read = settings.read;
|
|
300
|
-
}
|
|
301
|
-
|
|
302
|
-
export class Server {
|
|
303
|
-
constructor(manifest) {
|
|
304
|
-
const hooks = get_hooks(user_hooks);
|
|
305
|
-
|
|
306
|
-
this.options = {
|
|
307
|
-
amp: ${config.kit.amp},
|
|
308
|
-
csp: ${s(config.kit.csp)},
|
|
309
|
-
dev: false,
|
|
310
|
-
floc: ${config.kit.floc},
|
|
311
|
-
get_stack: error => String(error), // for security
|
|
312
|
-
handle_error: (error, event) => {
|
|
313
|
-
hooks.handleError({
|
|
314
|
-
error,
|
|
315
|
-
event,
|
|
316
|
-
|
|
317
|
-
// TODO remove for 1.0
|
|
318
|
-
// @ts-expect-error
|
|
319
|
-
get request() {
|
|
320
|
-
throw new Error('request in handleError has been replaced with event. See https://github.com/sveltejs/kit/pull/3384 for details');
|
|
321
|
-
}
|
|
322
|
-
});
|
|
323
|
-
error.stack = this.options.get_stack(error);
|
|
324
|
-
},
|
|
325
|
-
hooks,
|
|
326
|
-
hydrate: ${s(config.kit.browser.hydrate)},
|
|
327
|
-
manifest,
|
|
328
|
-
method_override: ${s(config.kit.methodOverride)},
|
|
329
|
-
paths: { base, assets },
|
|
330
|
-
prefix: assets + '/${config.kit.appDir}/',
|
|
331
|
-
prerender: ${config.kit.prerender.enabled},
|
|
332
|
-
read,
|
|
333
|
-
root,
|
|
334
|
-
service_worker: ${has_service_worker ? "base + '/service-worker.js'" : 'null'},
|
|
335
|
-
router: ${s(config.kit.browser.router)},
|
|
336
|
-
template,
|
|
337
|
-
template_contains_nonce: ${template.includes('%svelte.nonce%')},
|
|
338
|
-
trailing_slash: ${s(config.kit.trailingSlash)}
|
|
339
|
-
};
|
|
340
|
-
}
|
|
341
|
-
|
|
342
|
-
respond(request, options = {}) {
|
|
343
|
-
if (!(request instanceof Request)) {
|
|
344
|
-
throw new Error('The first argument to app.render must be a Request object. See https://github.com/sveltejs/kit/pull/3384 for details');
|
|
345
|
-
}
|
|
346
|
-
|
|
347
|
-
return respond(request, this.options, options);
|
|
348
|
-
}
|
|
349
|
-
}
|
|
350
|
-
`;
|
|
351
|
-
|
|
352
|
-
/**
|
|
353
|
-
* @param {{
|
|
354
|
-
* cwd: string;
|
|
355
|
-
* assets_base: string;
|
|
356
|
-
* config: import('types').ValidatedConfig
|
|
357
|
-
* manifest_data: import('types').ManifestData
|
|
358
|
-
* build_dir: string;
|
|
359
|
-
* output_dir: string;
|
|
360
|
-
* service_worker_entry_file: string | null;
|
|
361
|
-
* service_worker_register: boolean;
|
|
362
|
-
* }} options
|
|
363
|
-
* @param {{ vite_manifest: import('vite').Manifest, assets: import('rollup').OutputAsset[] }} client
|
|
364
|
-
*/
|
|
365
|
-
async function build_server(
|
|
366
|
-
{
|
|
367
|
-
cwd,
|
|
368
|
-
assets_base,
|
|
369
|
-
config,
|
|
370
|
-
manifest_data,
|
|
371
|
-
build_dir,
|
|
372
|
-
output_dir,
|
|
373
|
-
service_worker_entry_file,
|
|
374
|
-
service_worker_register
|
|
375
|
-
},
|
|
376
|
-
client
|
|
377
|
-
) {
|
|
378
|
-
let hooks_file = resolve_entry(config.kit.files.hooks);
|
|
379
|
-
if (!hooks_file || !fs__default.existsSync(hooks_file)) {
|
|
380
|
-
hooks_file = path__default.resolve(cwd, `${SVELTE_KIT}/build/hooks.js`);
|
|
381
|
-
fs__default.writeFileSync(hooks_file, '');
|
|
382
|
-
}
|
|
383
|
-
|
|
384
|
-
/** @type {Record<string, string>} */
|
|
385
|
-
const input = {
|
|
386
|
-
index: `${build_dir}/index.js`
|
|
387
|
-
};
|
|
388
|
-
|
|
389
|
-
// add entry points for every endpoint...
|
|
390
|
-
manifest_data.routes.forEach((route) => {
|
|
391
|
-
const file = route.type === 'endpoint' ? route.file : route.shadow;
|
|
392
|
-
|
|
393
|
-
if (file) {
|
|
394
|
-
const resolved = path__default.resolve(cwd, file);
|
|
395
|
-
const relative = path__default.relative(config.kit.files.routes, resolved);
|
|
396
|
-
const name = posixify(path__default.join('entries/endpoints', relative.replace(/\.js$/, '')));
|
|
397
|
-
input[name] = resolved;
|
|
398
|
-
}
|
|
16
|
+
/** @typedef {{ index: number, path: string }} LookupEntry */
|
|
17
|
+
/** @type {Map<string, LookupEntry>} */
|
|
18
|
+
const bundled_nodes = new Map();
|
|
19
|
+
|
|
20
|
+
// 0 and 1 are special, they correspond to the root layout and root error nodes
|
|
21
|
+
bundled_nodes.set(build_data.manifest_data.components[0], {
|
|
22
|
+
path: `${relative_path}/nodes/0.js`,
|
|
23
|
+
index: 0
|
|
399
24
|
});
|
|
400
25
|
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
const relative = path__default.relative(config.kit.files.routes, resolved);
|
|
405
|
-
|
|
406
|
-
const name = relative.startsWith('..')
|
|
407
|
-
? posixify(path__default.join('entries/pages', path__default.basename(file)))
|
|
408
|
-
: posixify(path__default.join('entries/pages', relative));
|
|
409
|
-
input[name] = resolved;
|
|
26
|
+
bundled_nodes.set(build_data.manifest_data.components[1], {
|
|
27
|
+
path: `${relative_path}/nodes/1.js`,
|
|
28
|
+
index: 1
|
|
410
29
|
});
|
|
411
30
|
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
31
|
+
routes.forEach((route) => {
|
|
32
|
+
if (route.type === 'page') {
|
|
33
|
+
[...route.a, ...route.b].forEach((component) => {
|
|
34
|
+
if (component && !bundled_nodes.has(component)) {
|
|
35
|
+
const i = build_data.manifest_data.components.indexOf(component);
|
|
417
36
|
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
hooks: app_relative(hooks_file),
|
|
423
|
-
has_service_worker: service_worker_register && !!service_worker_entry_file,
|
|
424
|
-
template: load_template(cwd, config)
|
|
425
|
-
})
|
|
426
|
-
);
|
|
427
|
-
|
|
428
|
-
/** @type {import('vite').UserConfig} */
|
|
429
|
-
const vite_config = await config.kit.vite();
|
|
430
|
-
|
|
431
|
-
const default_config = {
|
|
432
|
-
build: {
|
|
433
|
-
target: 'es2020'
|
|
434
|
-
}
|
|
435
|
-
};
|
|
436
|
-
|
|
437
|
-
// don't warn on overriding defaults
|
|
438
|
-
const [modified_vite_config] = deep_merge(default_config, vite_config);
|
|
439
|
-
|
|
440
|
-
/** @type {[any, string[]]} */
|
|
441
|
-
const [merged_config, conflicts] = deep_merge(modified_vite_config, {
|
|
442
|
-
configFile: false,
|
|
443
|
-
root: cwd,
|
|
444
|
-
base: assets_base,
|
|
445
|
-
build: {
|
|
446
|
-
ssr: true,
|
|
447
|
-
outDir: `${output_dir}/server`,
|
|
448
|
-
manifest: true,
|
|
449
|
-
polyfillDynamicImport: false,
|
|
450
|
-
rollupOptions: {
|
|
451
|
-
input,
|
|
452
|
-
output: {
|
|
453
|
-
format: 'esm',
|
|
454
|
-
entryFileNames: '[name].js',
|
|
455
|
-
chunkFileNames: 'chunks/[name]-[hash].js',
|
|
456
|
-
assetFileNames: 'assets/[name]-[hash][extname]'
|
|
457
|
-
},
|
|
458
|
-
preserveEntrySignatures: 'strict'
|
|
459
|
-
}
|
|
460
|
-
},
|
|
461
|
-
plugins: [
|
|
462
|
-
svelte({
|
|
463
|
-
extensions: config.extensions,
|
|
464
|
-
compilerOptions: {
|
|
465
|
-
hydratable: !!config.kit.browser.hydrate
|
|
37
|
+
bundled_nodes.set(component, {
|
|
38
|
+
path: `${relative_path}/nodes/${i}.js`,
|
|
39
|
+
index: bundled_nodes.size
|
|
40
|
+
});
|
|
466
41
|
}
|
|
467
|
-
})
|
|
468
|
-
],
|
|
469
|
-
resolve: {
|
|
470
|
-
alias: get_aliases(config)
|
|
471
|
-
}
|
|
472
|
-
});
|
|
473
|
-
|
|
474
|
-
print_config_conflicts(conflicts, 'kit.vite.', 'build_server');
|
|
475
|
-
|
|
476
|
-
const { chunks } = await create_build(merged_config);
|
|
477
|
-
|
|
478
|
-
/** @type {import('vite').Manifest} */
|
|
479
|
-
const vite_manifest = JSON.parse(fs__default.readFileSync(`${output_dir}/server/manifest.json`, 'utf-8'));
|
|
480
|
-
|
|
481
|
-
mkdirp(`${output_dir}/server/nodes`);
|
|
482
|
-
mkdirp(`${output_dir}/server/stylesheets`);
|
|
483
|
-
|
|
484
|
-
const stylesheet_lookup = new Map();
|
|
485
|
-
|
|
486
|
-
client.assets.forEach((asset) => {
|
|
487
|
-
if (asset.fileName.endsWith('.css')) {
|
|
488
|
-
if (config.kit.amp || asset.source.length < config.kit.inlineStyleThreshold) {
|
|
489
|
-
const index = stylesheet_lookup.size;
|
|
490
|
-
const file = `${output_dir}/server/stylesheets/${index}.js`;
|
|
491
|
-
|
|
492
|
-
fs__default.writeFileSync(file, `// ${asset.fileName}\nexport default ${s(asset.source)};`);
|
|
493
|
-
stylesheet_lookup.set(asset.fileName, index);
|
|
494
|
-
}
|
|
495
|
-
}
|
|
496
|
-
});
|
|
497
|
-
|
|
498
|
-
manifest_data.components.forEach((component, i) => {
|
|
499
|
-
const file = `${output_dir}/server/nodes/${i}.js`;
|
|
500
|
-
|
|
501
|
-
const js = new Set();
|
|
502
|
-
const css = new Set();
|
|
503
|
-
find_deps(component, client.vite_manifest, js, css);
|
|
504
|
-
|
|
505
|
-
const imports = [`import * as module from '../${vite_manifest[component].file}';`];
|
|
506
|
-
|
|
507
|
-
const exports = [
|
|
508
|
-
'export { module };',
|
|
509
|
-
`export const entry = '${client.vite_manifest[component].file}';`,
|
|
510
|
-
`export const js = ${s(Array.from(js))};`,
|
|
511
|
-
`export const css = ${s(Array.from(css))};`
|
|
512
|
-
];
|
|
513
|
-
|
|
514
|
-
/** @type {string[]} */
|
|
515
|
-
const styles = [];
|
|
516
|
-
|
|
517
|
-
css.forEach((file) => {
|
|
518
|
-
if (stylesheet_lookup.has(file)) {
|
|
519
|
-
const index = stylesheet_lookup.get(file);
|
|
520
|
-
const name = `stylesheet_${index}`;
|
|
521
|
-
imports.push(`import ${name} from '../stylesheets/${index}.js';`);
|
|
522
|
-
styles.push(`\t${s(file)}: ${name}`);
|
|
523
|
-
}
|
|
524
|
-
});
|
|
525
|
-
|
|
526
|
-
if (styles.length > 0) {
|
|
527
|
-
exports.push(`export const styles = {\n${styles.join(',\n')}\n};`);
|
|
42
|
+
});
|
|
528
43
|
}
|
|
529
|
-
|
|
530
|
-
fs__default.writeFileSync(file, `${imports.join('\n')}\n\n${exports.join('\n')}\n`);
|
|
531
44
|
});
|
|
532
45
|
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
}
|
|
539
|
-
|
|
540
|
-
/** @type {Record<string, string>} */
|
|
541
|
-
const method_names = {
|
|
542
|
-
get: 'get',
|
|
543
|
-
head: 'head',
|
|
544
|
-
post: 'post',
|
|
545
|
-
put: 'put',
|
|
546
|
-
del: 'delete',
|
|
547
|
-
patch: 'patch'
|
|
548
|
-
};
|
|
549
|
-
|
|
550
|
-
/**
|
|
551
|
-
*
|
|
552
|
-
* @param {string} cwd
|
|
553
|
-
* @param {import('rollup').OutputChunk[]} output
|
|
554
|
-
* @param {import('types').ManifestData} manifest_data
|
|
555
|
-
*/
|
|
556
|
-
function get_methods(cwd, output, manifest_data) {
|
|
557
|
-
/** @type {Record<string, string[]>} */
|
|
558
|
-
const lookup = {};
|
|
559
|
-
output.forEach((chunk) => {
|
|
560
|
-
if (!chunk.facadeModuleId) return;
|
|
561
|
-
const id = chunk.facadeModuleId.slice(cwd.length + 1);
|
|
562
|
-
lookup[id] = chunk.exports;
|
|
563
|
-
});
|
|
46
|
+
/** @type {(path: string) => string} */
|
|
47
|
+
const importer =
|
|
48
|
+
format === 'esm'
|
|
49
|
+
? (path) => `() => import('${path}')`
|
|
50
|
+
: (path) => `() => Promise.resolve().then(() => require('${path}'))`;
|
|
564
51
|
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
52
|
+
const assets = build_data.manifest_data.assets.map((asset) => asset.file);
|
|
53
|
+
if (build_data.service_worker) {
|
|
54
|
+
assets.push(build_data.service_worker);
|
|
55
|
+
}
|
|
569
56
|
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
57
|
+
/** @param {string} id */
|
|
58
|
+
const get_index = (id) => id && /** @type {LookupEntry} */ (bundled_nodes.get(id)).index;
|
|
59
|
+
|
|
60
|
+
// prettier-ignore
|
|
61
|
+
return `{
|
|
62
|
+
appDir: ${s(build_data.app_dir)},
|
|
63
|
+
assets: new Set(${s(assets)}),
|
|
64
|
+
_: {
|
|
65
|
+
mime: ${s(get_mime_lookup(build_data.manifest_data))},
|
|
66
|
+
entry: ${s(build_data.client.entry)},
|
|
67
|
+
nodes: [
|
|
68
|
+
${Array.from(bundled_nodes.values()).map(node => importer(node.path)).join(',\n\t\t\t\t')}
|
|
69
|
+
],
|
|
70
|
+
routes: [
|
|
71
|
+
${routes.map(route => {
|
|
72
|
+
if (route.type === 'page') {
|
|
73
|
+
return `{
|
|
74
|
+
type: 'page',
|
|
75
|
+
pattern: ${route.pattern},
|
|
76
|
+
params: ${get_params(route.params)},
|
|
77
|
+
path: ${route.path ? s(route.path) : null},
|
|
78
|
+
shadow: ${route.shadow ? importer(`${relative_path}/${build_data.server.vite_manifest[route.shadow].file}`) : null},
|
|
79
|
+
a: ${s(route.a.map(get_index))},
|
|
80
|
+
b: ${s(route.b.map(get_index))}
|
|
81
|
+
}`.replace(/^\t\t/gm, '');
|
|
82
|
+
} else {
|
|
83
|
+
if (!build_data.server.vite_manifest[route.file]) {
|
|
84
|
+
// this is necessary in cases where a .css file snuck in —
|
|
85
|
+
// perhaps it would be better to disallow these (and others?)
|
|
86
|
+
return null;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
return `{
|
|
90
|
+
type: 'endpoint',
|
|
91
|
+
pattern: ${route.pattern},
|
|
92
|
+
params: ${get_params(route.params)},
|
|
93
|
+
load: ${importer(`${relative_path}/${build_data.server.vite_manifest[route.file].file}`)}
|
|
94
|
+
}`.replace(/^\t\t/gm, '');
|
|
95
|
+
}
|
|
96
|
+
}).filter(Boolean).join(',\n\t\t\t\t')}
|
|
97
|
+
]
|
|
574
98
|
}
|
|
575
|
-
});
|
|
576
|
-
|
|
577
|
-
return methods;
|
|
99
|
+
}`.replace(/^\t/gm, '');
|
|
578
100
|
}
|
|
579
101
|
|
|
580
|
-
/**
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
cwd,
|
|
597
|
-
config,
|
|
598
|
-
build_dir,
|
|
599
|
-
// TODO this is so that Vite's preloading works. Unfortunately, it fails
|
|
600
|
-
// during `svelte-kit preview`, because we use a local asset path. If Vite
|
|
601
|
-
// used relative paths, I _think_ this could get fixed. Issue here:
|
|
602
|
-
// https://github.com/vitejs/vite/issues/2009
|
|
603
|
-
assets_base: `${config.kit.paths.assets || config.kit.paths.base}/${config.kit.appDir}/`,
|
|
604
|
-
manifest_data: create_manifest_data({
|
|
605
|
-
config,
|
|
606
|
-
cwd
|
|
607
|
-
}),
|
|
608
|
-
output_dir,
|
|
609
|
-
client_entry_file: path__default.relative(cwd, `${runtime}/client/start.js`),
|
|
610
|
-
service_worker_entry_file: resolve_entry(config.kit.files.serviceWorker),
|
|
611
|
-
service_worker_register: config.kit.serviceWorker.register
|
|
612
|
-
};
|
|
613
|
-
|
|
614
|
-
const client = await build_client(options);
|
|
615
|
-
const server = await build_server(options, client);
|
|
616
|
-
|
|
617
|
-
if (options.service_worker_entry_file) {
|
|
618
|
-
if (config.kit.paths.assets) {
|
|
619
|
-
throw new Error('Cannot use service worker alongside config.kit.paths.assets');
|
|
620
|
-
}
|
|
621
|
-
|
|
622
|
-
await build_service_worker(options, client.vite_manifest);
|
|
623
|
-
}
|
|
624
|
-
|
|
625
|
-
const build_data = {
|
|
626
|
-
app_dir: config.kit.appDir,
|
|
627
|
-
manifest_data: options.manifest_data,
|
|
628
|
-
service_worker: options.service_worker_entry_file ? 'service-worker.js' : null, // TODO make file configurable?
|
|
629
|
-
client,
|
|
630
|
-
server,
|
|
631
|
-
static: options.manifest_data.assets.map((asset) => posixify(asset.file)),
|
|
632
|
-
entries: options.manifest_data.routes
|
|
633
|
-
.map((route) => (route.type === 'page' ? route.path : ''))
|
|
634
|
-
.filter(Boolean)
|
|
635
|
-
};
|
|
636
|
-
|
|
637
|
-
const manifest = `export const manifest = ${generate_manifest(build_data, '.')};\n`;
|
|
638
|
-
fs__default.writeFileSync(`${output_dir}/server/manifest.js`, manifest);
|
|
639
|
-
|
|
640
|
-
return build_data;
|
|
102
|
+
/** @param {string[]} array */
|
|
103
|
+
function get_params(array) {
|
|
104
|
+
// given an array of params like `['x', 'y', 'z']` for
|
|
105
|
+
// src/routes/[x]/[y]/[z]/svelte, create a function
|
|
106
|
+
// that turns a RexExpMatchArray into ({ x, y, z })
|
|
107
|
+
return array.length
|
|
108
|
+
? '(m) => ({ ' +
|
|
109
|
+
array
|
|
110
|
+
.map((param, i) => {
|
|
111
|
+
return param.startsWith('...')
|
|
112
|
+
? `${param.slice(3)}: m[${i + 1}] || ''`
|
|
113
|
+
: `${param}: m[${i + 1}]`;
|
|
114
|
+
})
|
|
115
|
+
.join(', ') +
|
|
116
|
+
'})'
|
|
117
|
+
: 'null';
|
|
641
118
|
}
|
|
642
119
|
|
|
643
|
-
export {
|
|
120
|
+
export { generate_manifest as g };
|