@sveltejs/kit 1.0.11 → 1.0.13

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.
Files changed (45) hide show
  1. package/package.json +3 -3
  2. package/src/core/adapt/builder.js +1 -1
  3. package/src/core/{prerender → postbuild}/crawl.js +0 -0
  4. package/src/core/{prerender → postbuild}/entities.js +0 -0
  5. package/src/core/{prerender → postbuild}/fallback.js +10 -7
  6. package/src/core/postbuild/index.js +104 -0
  7. package/src/core/{prerender → postbuild}/prerender.js +32 -106
  8. package/src/core/{prerender → postbuild}/queue.js +0 -0
  9. package/src/core/sync/sync.js +10 -0
  10. package/src/core/sync/write_client_manifest.js +1 -1
  11. package/src/core/sync/write_server.js +89 -0
  12. package/src/core/utils.js +0 -9
  13. package/src/exports/vite/build/build_server.js +11 -163
  14. package/src/exports/vite/build/build_service_worker.js +3 -2
  15. package/src/exports/vite/build/utils.js +1 -0
  16. package/src/exports/vite/dev/index.js +72 -114
  17. package/src/exports/vite/index.js +26 -27
  18. package/src/exports/vite/preview/index.js +11 -12
  19. package/src/runtime/app/environment.js +1 -1
  20. package/src/runtime/app/paths.js +1 -1
  21. package/src/runtime/client/client.js +8 -2
  22. package/src/runtime/client/fetcher.js +12 -4
  23. package/src/runtime/client/start.js +1 -2
  24. package/src/runtime/client/types.d.ts +1 -1
  25. package/src/runtime/client/utils.js +1 -2
  26. package/src/runtime/control.js +23 -5
  27. package/src/runtime/server/ambient.d.ts +8 -0
  28. package/src/runtime/server/cookie.js +4 -5
  29. package/src/runtime/server/data/index.js +5 -2
  30. package/src/runtime/server/endpoint.js +5 -5
  31. package/src/runtime/server/fetch.js +11 -9
  32. package/src/runtime/server/index.js +54 -395
  33. package/src/runtime/server/page/csp.js +9 -11
  34. package/src/runtime/server/page/index.js +13 -8
  35. package/src/runtime/server/page/load_data.js +2 -3
  36. package/src/runtime/server/page/render.js +28 -25
  37. package/src/runtime/server/page/respond_with_error.js +20 -13
  38. package/src/runtime/server/page/types.d.ts +0 -1
  39. package/src/runtime/server/respond.js +419 -0
  40. package/src/runtime/server/utils.js +21 -4
  41. package/src/runtime/shared.js +28 -0
  42. package/types/index.d.ts +10 -5
  43. package/types/internal.d.ts +22 -39
  44. package/src/runtime/env.js +0 -12
  45. package/src/runtime/paths.js +0 -11
@@ -12,7 +12,7 @@ import { SVELTE_KIT_ASSETS } from '../../constants.js';
12
12
  import { create_static_module, create_dynamic_module } from '../../core/env.js';
13
13
  import * as sync from '../../core/sync/sync.js';
14
14
  import { create_assets } from '../../core/sync/create_manifest_data/index.js';
15
- import { runtime_base, runtime_directory, runtime_prefix, logger } from '../../core/utils.js';
15
+ import { runtime_base, runtime_directory, logger } from '../../core/utils.js';
16
16
  import { load_config } from '../../core/config/index.js';
17
17
  import { generate_manifest } from '../../core/generate_manifest/index.js';
18
18
  import { build_server } from './build/build_server.js';
@@ -128,7 +128,6 @@ function kit({ svelte_config }) {
128
128
 
129
129
  /**
130
130
  * @type {{
131
- * build_dir: string;
132
131
  * output_dir: string;
133
132
  * client_out_dir: string;
134
133
  * }}
@@ -147,7 +146,7 @@ function kit({ svelte_config }) {
147
146
 
148
147
  manifest_data.nodes.forEach((node) => {
149
148
  if (node.component) {
150
- const resolved = path.resolve(cwd, node.component);
149
+ const resolved = path.resolve(node.component);
151
150
  const relative = decodeURIComponent(
152
151
  path.relative(svelte_config.kit.files.routes, resolved)
153
152
  );
@@ -159,7 +158,7 @@ function kit({ svelte_config }) {
159
158
  }
160
159
 
161
160
  if (node.universal) {
162
- const resolved = path.resolve(cwd, node.universal);
161
+ const resolved = path.resolve(node.universal);
163
162
  const relative = decodeURIComponent(
164
163
  path.relative(svelte_config.kit.files.routes, resolved)
165
164
  );
@@ -189,7 +188,7 @@ function kit({ svelte_config }) {
189
188
  fs.readFileSync(`${paths.client_out_dir}/${vite_config.build.manifest}`, 'utf-8')
190
189
  );
191
190
 
192
- const entry_id = posixify(path.relative(cwd, `${runtime_directory}/client/start.js`));
191
+ const entry_id = posixify(path.relative('.', `${runtime_directory}/client/start.js`));
193
192
 
194
193
  return {
195
194
  assets,
@@ -218,7 +217,6 @@ function kit({ svelte_config }) {
218
217
  is_build = config_env.command === 'build';
219
218
 
220
219
  paths = {
221
- build_dir: `${svelte_config.kit.outDir}/build`,
222
220
  output_dir: `${svelte_config.kit.outDir}/output`,
223
221
  client_out_dir: `${svelte_config.kit.outDir}/output/client`
224
222
  };
@@ -238,8 +236,8 @@ function kit({ svelte_config }) {
238
236
  svelte_config.kit.files.lib,
239
237
  svelte_config.kit.files.routes,
240
238
  svelte_config.kit.outDir,
241
- path.resolve(cwd, 'src'), // TODO this isn't correct if user changed all his files to sth else than src (like in test/options)
242
- path.resolve(cwd, 'node_modules'),
239
+ path.resolve('src'), // TODO this isn't correct if user changed all his files to sth else than src (like in test/options)
240
+ path.resolve('node_modules'),
243
241
  path.resolve(vite.searchForWorkspaceRoot(cwd), 'node_modules')
244
242
  ]);
245
243
  // We can only add directories to the allow list, so we find out
@@ -254,6 +252,7 @@ function kit({ svelte_config }) {
254
252
  const result = {
255
253
  define: {
256
254
  __SVELTEKIT_APP_VERSION_POLL_INTERVAL__: '0',
255
+ __SVELTEKIT_DEV__: config_env.command === 'serve',
257
256
  __SVELTEKIT_EMBEDDED__: svelte_config.kit.embedded ? 'true' : 'false'
258
257
  },
259
258
  resolve: {
@@ -276,7 +275,7 @@ function kit({ svelte_config }) {
276
275
  // a linked dependency, and that causes modules to be imported twice
277
276
  // under different IDs, which breaks a bunch of stuff
278
277
  // https://github.com/vitejs/vite/pull/9296
279
- external: ['@sveltejs/kit']
278
+ external: ['@sveltejs/kit', 'cookie', 'set-cookie-parser']
280
279
  },
281
280
  optimizeDeps: {
282
281
  exclude: [
@@ -307,7 +306,7 @@ function kit({ svelte_config }) {
307
306
  if (
308
307
  is_illegal(id, {
309
308
  cwd: normalized_cwd,
310
- node_modules: vite.normalizePath(path.join(cwd, 'node_modules')),
309
+ node_modules: vite.normalizePath(path.resolve('node_modules')),
311
310
  server: vite.normalizePath(path.join(normalized_lib, 'server'))
312
311
  })
313
312
  ) {
@@ -358,10 +357,8 @@ function kit({ svelte_config }) {
358
357
 
359
358
  if (is_build) {
360
359
  if (!vite_config.build.watch) {
361
- rimraf(paths.build_dir);
362
360
  rimraf(paths.output_dir);
363
361
  }
364
- mkdirp(paths.build_dir);
365
362
  mkdirp(paths.output_dir);
366
363
  }
367
364
  },
@@ -380,18 +377,18 @@ function kit({ svelte_config }) {
380
377
  * @see https://vitejs.dev/guide/api-plugin.html#configureserver
381
378
  */
382
379
  async configureServer(vite) {
383
- // set `import { version } from '$app/environment'`
384
- (await vite.ssrLoadModule(`${runtime_prefix}/env.js`)).set_version(
385
- svelte_config.kit.version.name
386
- );
380
+ const { set_paths, set_version } = await vite.ssrLoadModule(`${runtime_base}/shared.js`);
387
381
 
388
382
  // set `import { base, assets } from '$app/paths'`
389
383
  const { base, assets } = svelte_config.kit.paths;
390
384
 
391
- (await vite.ssrLoadModule(`${runtime_base}/paths.js`)).set_paths({
385
+ set_paths({
392
386
  base,
393
387
  assets: assets ? SVELTE_KIT_ASSETS : base
394
388
  });
389
+
390
+ // set `import { version } from '$app/environment'`
391
+ set_version(svelte_config.kit.version.name);
395
392
  }
396
393
  };
397
394
 
@@ -489,18 +486,17 @@ function kit({ svelte_config }) {
489
486
  log.info('Building server');
490
487
 
491
488
  const options = {
492
- cwd,
493
489
  config: svelte_config,
494
490
  vite_config,
495
491
  vite_config_env,
496
- build_dir: paths.build_dir, // TODO just pass `paths`
497
492
  manifest_data,
498
- output_dir: paths.output_dir,
499
- service_worker_entry_file: resolve_entry(svelte_config.kit.files.serviceWorker)
493
+ output_dir: paths.output_dir
500
494
  };
501
495
  const client = client_build_info(assets, chunks);
502
496
  const server = await build_server(options, client);
503
497
 
498
+ const service_worker_entry_file = resolve_entry(svelte_config.kit.files.serviceWorker);
499
+
504
500
  /** @type {import('types').BuildData} */
505
501
  build_data = {
506
502
  app_dir: svelte_config.kit.appDir,
@@ -508,7 +504,7 @@ function kit({ svelte_config }) {
508
504
  svelte_config.kit.paths.base ? '/' : ''
509
505
  }${svelte_config.kit.appDir}`,
510
506
  manifest_data,
511
- service_worker: options.service_worker_entry_file ? 'service-worker.js' : null, // TODO make file configurable?
507
+ service_worker: !!service_worker_entry_file ? 'service-worker.js' : null, // TODO make file configurable?
512
508
  client,
513
509
  server
514
510
  };
@@ -528,9 +524,7 @@ function kit({ svelte_config }) {
528
524
  const results_path = `${svelte_config.kit.outDir}/generated/prerendered.json`;
529
525
 
530
526
  // do prerendering in a subprocess so any dangling stuff gets killed upon completion
531
- const script = fileURLToPath(
532
- new URL('../../core/prerender/prerender.js', import.meta.url)
533
- );
527
+ const script = fileURLToPath(new URL('../../core/postbuild/index.js', import.meta.url));
534
528
 
535
529
  const child = fork(
536
530
  script,
@@ -575,14 +569,19 @@ function kit({ svelte_config }) {
575
569
  })};\n`
576
570
  );
577
571
 
578
- if (options.service_worker_entry_file) {
572
+ if (service_worker_entry_file) {
579
573
  if (svelte_config.kit.paths.assets) {
580
574
  throw new Error('Cannot use service worker alongside config.kit.paths.assets');
581
575
  }
582
576
 
583
577
  log.info('Building service worker');
584
578
 
585
- await build_service_worker(options, prerendered, client.vite_manifest);
579
+ await build_service_worker(
580
+ options,
581
+ service_worker_entry_file,
582
+ prerendered,
583
+ client.vite_manifest
584
+ );
586
585
  }
587
586
 
588
587
  console.log(
@@ -34,19 +34,17 @@ export async function preview(vite, vite_config, svelte_config) {
34
34
 
35
35
  const etag = `"${Date.now()}"`;
36
36
 
37
- const index_file = join(svelte_config.kit.outDir, 'output/server/index.js');
38
- const manifest_file = join(svelte_config.kit.outDir, 'output/server/manifest.js');
37
+ const dir = join(svelte_config.kit.outDir, 'output/server');
38
+
39
+ /** @type {import('types').ServerInternalModule} */
40
+ const { set_paths } = await import(pathToFileURL(join(dir, 'internal.js')).href);
39
41
 
40
42
  /** @type {import('types').ServerModule} */
41
- const { Server, override } = await import(pathToFileURL(index_file).href);
42
- const { manifest } = await import(pathToFileURL(manifest_file).href);
43
-
44
- override({
45
- paths: { base, assets },
46
- building: false,
47
- protocol,
48
- read: (file) => fs.readFileSync(join(svelte_config.kit.files.assets, file))
49
- });
43
+ const { Server } = await import(pathToFileURL(join(dir, 'index.js')).href);
44
+
45
+ const { manifest } = await import(pathToFileURL(join(dir, 'manifest.js')).href);
46
+
47
+ set_paths({ base, assets });
50
48
 
51
49
  const server = new Server(manifest);
52
50
  await server.init({
@@ -150,7 +148,8 @@ export async function preview(vite, vite_config, svelte_config) {
150
148
  const { remoteAddress } = req.socket;
151
149
  if (remoteAddress) return remoteAddress;
152
150
  throw new Error('Could not determine clientAddress');
153
- }
151
+ },
152
+ read: (file) => fs.readFileSync(join(svelte_config.kit.files.assets, file))
154
153
  })
155
154
  );
156
155
  });
@@ -10,4 +10,4 @@ export const browser = BROWSER;
10
10
  */
11
11
  export const dev = DEV;
12
12
 
13
- export { building, version } from '../env.js';
13
+ export { building, version } from '../shared.js';
@@ -1 +1 @@
1
- export { base, assets } from '../paths.js';
1
+ export { base, assets } from '../shared.js';
@@ -467,7 +467,7 @@ export function create_client({ target, base }) {
467
467
  !current.url ||
468
468
  url.href !== current.url.href ||
469
469
  current.error !== error ||
470
- form !== undefined ||
470
+ (form !== undefined && form !== page.form) ||
471
471
  data_changed;
472
472
 
473
473
  if (page_changed) {
@@ -824,6 +824,12 @@ export function create_client({ target, base }) {
824
824
  status = err.status;
825
825
  error = err.body;
826
826
  } else {
827
+ // Referenced node could have been removed due to redeploy, check
828
+ const updated = await stores.updated.check();
829
+ if (updated) {
830
+ return await native_navigation(url);
831
+ }
832
+
827
833
  error = await handle_error(err, { params, url, route: { id: route.id } });
828
834
  }
829
835
 
@@ -909,7 +915,7 @@ export function create_client({ target, base }) {
909
915
  /** @type {import('types').ServerDataNode | null} */
910
916
  let server_data_node = null;
911
917
 
912
- if (node.server) {
918
+ if (node.has_server_load) {
913
919
  // TODO post-https://github.com/sveltejs/kit/discussions/6124 we can use
914
920
  // existing root layout data
915
921
  try {
@@ -24,12 +24,20 @@ if (DEV) {
24
24
  check_stack_trace();
25
25
 
26
26
  window.fetch = (input, init) => {
27
+ // Check if fetch was called via load_node. the lock method only checks if it was called at the
28
+ // same time, but not necessarily if it was called from `load`.
29
+ // We use just the filename as the method name sometimes does not appear on the CI.
27
30
  const url = input instanceof Request ? input.url : input.toString();
28
- const stack = /** @type {string} */ (new Error().stack);
31
+ const stack_array = /** @type {string} */ (new Error().stack).split('\n');
32
+ // We need to do some Firefox-specific cutoff because it (impressively) maintains the stack
33
+ // across events and for example traces a `fetch` call triggered from a button back
34
+ // to the creation of the event listener and the element creation itself,
35
+ // where at some point client.js will show up, leading to false positives.
36
+ const firefox_cutoff = stack_array.findIndex((a) => a.includes('*listen@'));
37
+ const stack = stack_array
38
+ .slice(0, firefox_cutoff !== -1 ? firefox_cutoff : undefined)
39
+ .join('\n');
29
40
 
30
- // check if fetch was called via load_node. the lock method only checks if it was called at the
31
- // same time, but not necessarily if it was called from `load`
32
- // we use just the filename as the method name sometimes does not appear on the CI
33
41
  const heuristic = can_inspect_stack_trace
34
42
  ? stack.includes('src/runtime/client/client.js')
35
43
  : loading;
@@ -1,9 +1,8 @@
1
1
  import { DEV } from 'esm-env';
2
2
  import { create_client } from './client.js';
3
3
  import { init } from './singletons.js';
4
- import { set_paths } from '../paths.js';
4
+ import { set_paths, set_version } from '../shared.js';
5
5
  import { set_public_env } from '../env-public.js';
6
- import { set_version } from '../env.js';
7
6
 
8
7
  /**
9
8
  * @param {{
@@ -26,7 +26,7 @@ export interface Client {
26
26
  // private API
27
27
  _hydrate(opts: {
28
28
  status: number;
29
- error: App.Error;
29
+ error: App.Error | null;
30
30
  node_ids: number[];
31
31
  params: Record<string, string>;
32
32
  route: { id: string | null };
@@ -1,7 +1,6 @@
1
1
  import { BROWSER, DEV } from 'esm-env';
2
2
  import { writable } from 'svelte/store';
3
- import { assets } from '../paths.js';
4
- import { version } from '../env.js';
3
+ import { assets, version } from '../shared.js';
5
4
  import { PRELOAD_PRIORITIES } from './constants.js';
6
5
 
7
6
  /* global __SVELTEKIT_APP_VERSION_FILE__, __SVELTEKIT_APP_VERSION_POLL_INTERVAL__ */
@@ -1,4 +1,4 @@
1
- export class HttpError {
1
+ export let HttpError = class HttpError {
2
2
  /**
3
3
  * @param {number} status
4
4
  * @param {{message: string} extends App.Error ? (App.Error | string | undefined) : App.Error} body
@@ -17,9 +17,9 @@ export class HttpError {
17
17
  toString() {
18
18
  return JSON.stringify(this.body);
19
19
  }
20
- }
20
+ };
21
21
 
22
- export class Redirect {
22
+ export let Redirect = class Redirect {
23
23
  /**
24
24
  * @param {300 | 301 | 302 | 303 | 304 | 305 | 306 | 307 | 308} status
25
25
  * @param {string} location
@@ -28,12 +28,12 @@ export class Redirect {
28
28
  this.status = status;
29
29
  this.location = location;
30
30
  }
31
- }
31
+ };
32
32
 
33
33
  /**
34
34
  * @template {Record<string, unknown> | undefined} [T=undefined]
35
35
  */
36
- export class ActionFailure {
36
+ export let ActionFailure = class ActionFailure {
37
37
  /**
38
38
  * @param {number} status
39
39
  * @param {T} [data]
@@ -42,4 +42,22 @@ export class ActionFailure {
42
42
  this.status = status;
43
43
  this.data = data;
44
44
  }
45
+ };
46
+
47
+ /**
48
+ * This is a grotesque hack that, in dev, allows us to replace the implementations
49
+ * of these classes that you'd get by importing them from `@sveltejs/kit` with the
50
+ * ones that are imported via Vite and loaded internally, so that instanceof
51
+ * checks work even though SvelteKit imports this module via Vite and consumers
52
+ * import it via Node
53
+ * @param {{
54
+ * ActionFailure: typeof ActionFailure;
55
+ * HttpError: typeof HttpError;
56
+ * Redirect: typeof Redirect;
57
+ * }} implementations
58
+ */
59
+ export function replace_implementations(implementations) {
60
+ ActionFailure = implementations.ActionFailure;
61
+ HttpError = implementations.HttpError;
62
+ Redirect = implementations.Redirect;
45
63
  }
@@ -0,0 +1,8 @@
1
+ declare module '__GENERATED__/server-internal.js' {
2
+ export const options: import('types').SSROptions;
3
+ export const get_hooks: () => Promise<{
4
+ handle?: import('types').Handle;
5
+ handleError?: import('types').HandleServerError;
6
+ handleFetch?: import('types').HandleFetch;
7
+ }>;
8
+ }
@@ -11,10 +11,9 @@ const cookie_paths = {};
11
11
  /**
12
12
  * @param {Request} request
13
13
  * @param {URL} url
14
- * @param {boolean} dev
15
14
  * @param {import('types').TrailingSlash} trailing_slash
16
15
  */
17
- export function get_cookies(request, url, dev, trailing_slash) {
16
+ export function get_cookies(request, url, trailing_slash) {
18
17
  const header = request.headers.get('cookie') ?? '';
19
18
  const initial_cookies = parse(header, { decode: (value) => value });
20
19
 
@@ -22,7 +21,7 @@ export function get_cookies(request, url, dev, trailing_slash) {
22
21
  // Emulate browser-behavior: if the cookie is set at '/foo/bar', its path is '/foo'
23
22
  const default_path = normalized_url.split('/').slice(0, -1).join('/') || '/';
24
23
 
25
- if (dev) {
24
+ if (__SVELTEKIT_DEV__) {
26
25
  // TODO this could theoretically be wrong if the cookie was set unencoded?
27
26
  const initial_decoded_cookies = parse(header, { decode: decodeURIComponent });
28
27
  // Remove all cookies that no longer exist according to the request
@@ -77,7 +76,7 @@ export function get_cookies(request, url, dev, trailing_slash) {
77
76
  const req_cookies = parse(header, { decode: decoder });
78
77
  const cookie = req_cookies[name]; // the decoded string or undefined
79
78
 
80
- if (!dev || cookie) {
79
+ if (!__SVELTEKIT_DEV__ || cookie) {
81
80
  return cookie;
82
81
  }
83
82
 
@@ -111,7 +110,7 @@ export function get_cookies(request, url, dev, trailing_slash) {
111
110
  }
112
111
  };
113
112
 
114
- if (dev) {
113
+ if (__SVELTEKIT_DEV__) {
115
114
  cookie_paths[name] = cookie_paths[name] ?? new Set();
116
115
  if (!value) {
117
116
  if (!cookie_paths[name].has(path) && cookie_paths[name].size > 0) {
@@ -11,6 +11,7 @@ export const INVALIDATED_PARAM = 'x-sveltekit-invalidated';
11
11
  * @param {import('types').RequestEvent} event
12
12
  * @param {import('types').SSRRoute} route
13
13
  * @param {import('types').SSROptions} options
14
+ * @param {import('types').SSRManifest} manifest
14
15
  * @param {import('types').SSRState} state
15
16
  * @param {boolean[] | undefined} invalidated_data_nodes
16
17
  * @param {import('types').TrailingSlash} trailing_slash
@@ -20,6 +21,7 @@ export async function render_data(
20
21
  event,
21
22
  route,
22
23
  options,
24
+ manifest,
23
25
  state,
24
26
  invalidated_data_nodes,
25
27
  trailing_slash
@@ -31,6 +33,8 @@ export async function render_data(
31
33
  });
32
34
  }
33
35
 
36
+ state.initiator = route;
37
+
34
38
  try {
35
39
  const node_ids = [...route.page.layouts, route.page.leaf];
36
40
  const invalidated = invalidated_data_nodes ?? node_ids.map(() => true);
@@ -52,10 +56,9 @@ export async function render_data(
52
56
  }
53
57
 
54
58
  // == because it could be undefined (in dev) or null (in build, because of JSON.stringify)
55
- const node = n == undefined ? n : await options.manifest._.nodes[n]();
59
+ const node = n == undefined ? n : await manifest._.nodes[n]();
56
60
  return load_server_data({
57
61
  event: new_event,
58
- options,
59
62
  state,
60
63
  node,
61
64
  parent: async () => {
@@ -54,15 +54,15 @@ export async function render_endpoint(event, mod, state) {
54
54
  }
55
55
 
56
56
  return response;
57
- } catch (error) {
58
- if (error instanceof Redirect) {
57
+ } catch (e) {
58
+ if (e instanceof Redirect) {
59
59
  return new Response(undefined, {
60
- status: error.status,
61
- headers: { location: error.location }
60
+ status: e.status,
61
+ headers: { location: e.location }
62
62
  });
63
63
  }
64
64
 
65
- throw error;
65
+ throw e;
66
66
  }
67
67
  }
68
68
 
@@ -1,16 +1,18 @@
1
1
  import * as set_cookie_parser from 'set-cookie-parser';
2
- import { respond } from './index.js';
2
+ import { respond } from './respond.js';
3
+ import * as paths from '../shared.js';
3
4
 
4
5
  /**
5
6
  * @param {{
6
7
  * event: import('types').RequestEvent;
7
8
  * options: import('types').SSROptions;
9
+ * manifest: import('types').SSRManifest;
8
10
  * state: import('types').SSRState;
9
11
  * get_cookie_header: (url: URL, header: string | null) => string;
10
12
  * }} opts
11
13
  * @returns {typeof fetch}
12
14
  */
13
- export function create_fetch({ event, options, state, get_cookie_header }) {
15
+ export function create_fetch({ event, options, manifest, state, get_cookie_header }) {
14
16
  return async (info, init) => {
15
17
  const original_request = normalize_fetch_input(info, init, event.url);
16
18
 
@@ -71,25 +73,25 @@ export function create_fetch({ event, options, state, get_cookie_header }) {
71
73
 
72
74
  // handle fetch requests for static assets. e.g. prebaked data, etc.
73
75
  // we need to support everything the browser's fetch supports
74
- const prefix = options.paths.assets || options.paths.base;
76
+ const prefix = paths.assets || paths.base;
75
77
  const decoded = decodeURIComponent(url.pathname);
76
78
  const filename = (
77
79
  decoded.startsWith(prefix) ? decoded.slice(prefix.length) : decoded
78
80
  ).slice(1);
79
81
  const filename_html = `${filename}/index.html`; // path may also match path/index.html
80
82
 
81
- const is_asset = options.manifest.assets.has(filename);
82
- const is_asset_html = options.manifest.assets.has(filename_html);
83
+ const is_asset = manifest.assets.has(filename);
84
+ const is_asset_html = manifest.assets.has(filename_html);
83
85
 
84
86
  if (is_asset || is_asset_html) {
85
87
  const file = is_asset ? filename : filename_html;
86
88
 
87
- if (options.read) {
89
+ if (state.read) {
88
90
  const type = is_asset
89
- ? options.manifest.mimeTypes[filename.slice(filename.lastIndexOf('.'))]
91
+ ? manifest.mimeTypes[filename.slice(filename.lastIndexOf('.'))]
90
92
  : 'text/html';
91
93
 
92
- return new Response(options.read(file), {
94
+ return new Response(state.read(file), {
93
95
  headers: type ? { 'content-type': type } : {}
94
96
  });
95
97
  }
@@ -129,7 +131,7 @@ export function create_fetch({ event, options, state, get_cookie_header }) {
129
131
  );
130
132
  }
131
133
 
132
- response = await respond(request, options, state);
134
+ response = await respond(request, options, manifest, state);
133
135
 
134
136
  const set_cookie = response.headers.get('set-cookie');
135
137
  if (set_cookie) {