@sveltejs/kit 3.0.0-next.7 → 3.0.0-next.8

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 (44) hide show
  1. package/package.json +2 -2
  2. package/src/core/config/options.js +1 -1
  3. package/src/core/env.js +1 -0
  4. package/src/core/sync/create_manifest_data/index.js +1 -1
  5. package/src/core/sync/sync.js +0 -2
  6. package/src/core/sync/write_client_manifest.js +0 -7
  7. package/src/core/sync/write_non_ambient.js +2 -2
  8. package/src/core/sync/write_server.js +0 -3
  9. package/src/core/sync/write_types/index.js +17 -14
  10. package/src/core/utils.js +2 -2
  11. package/src/exports/node/index.js +4 -8
  12. package/src/exports/public.d.ts +21 -14
  13. package/src/exports/vite/dev/index.js +3 -3
  14. package/src/exports/vite/index.js +64 -44
  15. package/src/exports/vite/preview/index.js +13 -14
  16. package/src/exports/vite/utils.js +5 -5
  17. package/src/runtime/app/env/internal.js +4 -4
  18. package/src/runtime/app/forms.js +2 -2
  19. package/src/runtime/app/paths/internal/client.js +4 -2
  20. package/src/runtime/app/paths/internal/server.js +2 -23
  21. package/src/runtime/app/paths/server.js +2 -2
  22. package/src/runtime/client/bundle.js +1 -1
  23. package/src/runtime/client/client-entry.js +3 -0
  24. package/src/runtime/client/client.js +216 -171
  25. package/src/runtime/client/entry.js +24 -3
  26. package/src/runtime/client/payload.js +17 -0
  27. package/src/runtime/client/remote-functions/form.svelte.js +6 -6
  28. package/src/runtime/client/types.d.ts +2 -6
  29. package/src/runtime/components/root.svelte +66 -0
  30. package/src/runtime/form-utils.js +1 -4
  31. package/src/runtime/server/cookie.js +17 -7
  32. package/src/runtime/server/page/index.js +7 -14
  33. package/src/runtime/server/page/render.js +71 -78
  34. package/src/runtime/server/remote.js +2 -1
  35. package/src/runtime/server/utils.js +28 -5
  36. package/src/runtime/types.d.ts +8 -0
  37. package/src/types/global-private.d.ts +10 -17
  38. package/src/types/internal.d.ts +21 -25
  39. package/src/utils/import.js +6 -1
  40. package/src/utils/routing.js +6 -6
  41. package/src/version.js +1 -1
  42. package/types/index.d.ts +34 -43
  43. package/types/index.d.ts.map +3 -2
  44. package/src/core/sync/write_root.js +0 -127
@@ -1,3 +1,6 @@
1
+ /** @import { NextHandleFunction } from 'connect' */
2
+ /** @import { PreviewServer, ResolvedConfig } from 'vite' */
3
+ /** @import { ValidatedConfig, ServerInternalModule, ServerModule } from 'types' */
1
4
  import fs from 'node:fs';
2
5
  import { join } from 'node:path';
3
6
  import { pathToFileURL } from 'node:url';
@@ -8,14 +11,10 @@ import { createReadableStream, getRequest, setResponse } from '../../../exports/
8
11
  import { SVELTE_KIT_ASSETS } from '../../../constants.js';
9
12
  import { is_chrome_devtools_request, not_found } from '../utils.js';
10
13
 
11
- /** @typedef {import('http').IncomingMessage} Req */
12
- /** @typedef {import('http').ServerResponse} Res */
13
- /** @typedef {(req: Req, res: Res, next: () => void) => void} Handler */
14
-
15
14
  /**
16
- * @param {import('vite').PreviewServer} vite
17
- * @param {import('vite').ResolvedConfig} vite_config
18
- * @param {import('types').ValidatedConfig} svelte_config
15
+ * @param {PreviewServer} vite
16
+ * @param {ResolvedConfig} vite_config
17
+ * @param {ValidatedConfig} svelte_config
19
18
  */
20
19
  export async function preview(vite, vite_config, svelte_config) {
21
20
  const { paths } = svelte_config.kit;
@@ -37,10 +36,10 @@ export async function preview(vite, vite_config, svelte_config) {
37
36
  await import(pathToFileURL(instrumentation).href);
38
37
  }
39
38
 
40
- /** @type {import('types').ServerInternalModule} */
39
+ /** @type {ServerInternalModule} */
41
40
  const { set_assets } = await import(pathToFileURL(join(dir, 'internal.js')).href);
42
41
 
43
- /** @type {import('types').ServerModule} */
42
+ /** @type {ServerModule} */
44
43
  const { Server } = await import(pathToFileURL(join(dir, 'index.js')).href);
45
44
 
46
45
  const { manifest } = await import(pathToFileURL(join(dir, 'manifest.js')).href);
@@ -204,12 +203,12 @@ export async function preview(vite, vite_config, svelte_config) {
204
203
  vite.middlewares.use(async (req, res) => {
205
204
  const host = req.headers[':authority'] || req.headers.host;
206
205
 
207
- const request = await getRequest({
206
+ const request = getRequest({
208
207
  base: `${protocol}://${host}`,
209
208
  request: req
210
209
  });
211
210
 
212
- await setResponse(
211
+ setResponse(
213
212
  res,
214
213
  await server.respond(request, {
215
214
  getClientAddress: () => {
@@ -233,7 +232,7 @@ export async function preview(vite, vite_config, svelte_config) {
233
232
 
234
233
  /**
235
234
  * @param {string} dir
236
- * @returns {Handler}
235
+ * @returns {NextHandleFunction}
237
236
  */
238
237
  const mutable = (dir) =>
239
238
  fs.existsSync(dir)
@@ -245,8 +244,8 @@ const mutable = (dir) =>
245
244
 
246
245
  /**
247
246
  * @param {string} scope
248
- * @param {Handler} handler
249
- * @returns {Handler}
247
+ * @param {NextHandleFunction} handler
248
+ * @returns {NextHandleFunction}
250
249
  */
251
250
  function scoped(scope, handler) {
252
251
  if (scope === '') return handler;
@@ -18,13 +18,13 @@ import {
18
18
  *
19
19
  * @param {import('types').ValidatedKitConfig} config
20
20
  * @param {string} root
21
- * */
21
+ */
22
22
  export function get_config_aliases(config, root) {
23
23
  /** @type {import('vite').Alias[]} */
24
24
  const alias = [
25
25
  // For now, we handle `$lib` specially here rather than make it a default value for
26
26
  // `config.alias` since it has special meaning for packaging, etc.
27
- { find: '$lib', replacement: config.files.lib }
27
+ { find: '$lib', replacement: posixify(config.files.lib) }
28
28
  ];
29
29
 
30
30
  for (let [key, value] of Object.entries(config.alias)) {
@@ -36,16 +36,16 @@ export function get_config_aliases(config, root) {
36
36
  // Doing just `{ find: key.slice(0, -2) ,..}` would mean `import .. from "key"` would also be matched, which we don't want
37
37
  alias.push({
38
38
  find: new RegExp(`^${escape_for_regexp(key.slice(0, -2))}\\/(.+)$`),
39
- replacement: `${path.resolve(root, value)}/$1`
39
+ replacement: `${posixify(path.resolve(root, value))}/$1`
40
40
  });
41
41
  } else if (key + '/*' in config.alias) {
42
42
  // key and key/* both exist -> the replacement for key needs to happen _only_ on import .. from "key"
43
43
  alias.push({
44
44
  find: new RegExp(`^${escape_for_regexp(key)}$`),
45
- replacement: path.resolve(root, value)
45
+ replacement: posixify(path.resolve(root, value))
46
46
  });
47
47
  } else {
48
- alias.push({ find: key, replacement: path.resolve(root, value) });
48
+ alias.push({ find: key, replacement: posixify(path.resolve(root, value)) });
49
49
  }
50
50
  }
51
51
 
@@ -1,4 +1,7 @@
1
- export const version = __SVELTEKIT_APP_VERSION__;
1
+ import { BROWSER } from 'esm-env';
2
+ import { payload } from '../../client/payload.js';
3
+
4
+ export const version = BROWSER ? payload.version : __SVELTEKIT_APP_VERSION__;
2
5
  export let building = false;
3
6
  export let prerendering = false;
4
7
 
@@ -9,6 +12,3 @@ export function set_building() {
9
12
  export function set_prerendering() {
10
13
  prerendering = true;
11
14
  }
12
-
13
- // force /@vite/client to be injected
14
- import.meta.hot;
@@ -1,7 +1,7 @@
1
1
  import * as devalue from 'devalue';
2
2
  import { BROWSER, DEV } from 'esm-env';
3
3
  import { noop } from '../../utils/functions.js';
4
- import { invalidateAll } from './navigation.js';
4
+ import { refreshAll } from './navigation.js';
5
5
  import { app as client_app, applyAction, handle_error } from '../client/client.js';
6
6
  import { app as server_app } from '../server/app.js';
7
7
 
@@ -106,7 +106,7 @@ export function enhance(form_element, submit = noop) {
106
106
  HTMLFormElement.prototype.reset.call(form_element);
107
107
  }
108
108
  if (shouldInvalidateAll) {
109
- await invalidateAll();
109
+ await refreshAll();
110
110
  }
111
111
  }
112
112
 
@@ -1,4 +1,6 @@
1
- export const base = __SVELTEKIT_PAYLOAD__?.base ?? __SVELTEKIT_PATHS_BASE__;
2
- export const assets = __SVELTEKIT_PAYLOAD__?.assets ?? base ?? __SVELTEKIT_PATHS_ASSETS__;
1
+ import { payload } from '../../../client/payload.js';
2
+
3
+ export const base = payload.base ?? __SVELTEKIT_PATHS_BASE__;
4
+ export const assets = payload.assets ?? base ?? __SVELTEKIT_PATHS_ASSETS__;
3
5
  export const app_dir = __SVELTEKIT_APP_DIR__;
4
6
  export const hash_routing = __SVELTEKIT_HASH_ROUTING__;
@@ -1,30 +1,9 @@
1
- export let base = __SVELTEKIT_PATHS_BASE__;
1
+ export const base = __SVELTEKIT_PATHS_BASE__;
2
2
  export let assets = __SVELTEKIT_PATHS_ASSETS__ || base;
3
3
  export const app_dir = __SVELTEKIT_APP_DIR__;
4
4
  export const relative = __SVELTEKIT_PATHS_RELATIVE__;
5
5
 
6
- const initial = { base, assets };
7
-
8
- /**
9
- * `base` could be overridden during rendering to be relative;
10
- * this one's the original non-relative base path
11
- */
12
- export const initial_base = initial.base;
13
-
14
- /**
15
- * @param {{ base: string, assets: string }} paths
16
- */
17
- export function override(paths) {
18
- base = paths.base;
19
- assets = paths.assets;
20
- }
21
-
22
- export function reset() {
23
- base = initial.base;
24
- assets = initial.assets;
25
- }
26
-
27
6
  /** @param {string} path */
28
7
  export function set_assets(path) {
29
- assets = initial.assets = path;
8
+ assets = path;
30
9
  }
@@ -1,4 +1,4 @@
1
- import { base, assets, relative, initial_base } from './internal/server.js';
1
+ import { base, assets, relative } from './internal/server.js';
2
2
  import { resolve_route, find_route } from '../../../utils/routing.js';
3
3
  import { decode_pathname } from '../../../utils/url.js';
4
4
  import { add_data_suffix } from '../../pathname.js';
@@ -32,7 +32,7 @@ export function resolve(id, params) {
32
32
  const pathname = store.event.isDataRequest
33
33
  ? add_data_suffix(store.event.url.pathname)
34
34
  : store.event.url.pathname;
35
- const after_base = pathname.slice(initial_base.length);
35
+ const after_base = pathname.slice(base.length);
36
36
  const segments = after_base.split('/').slice(2);
37
37
  const prefix = segments.map(() => '..').join('/') || '.';
38
38
 
@@ -1,6 +1,6 @@
1
1
  /* if `bundleStrategy` is 'single' or 'inline', this file is used as the entry point */
2
2
 
3
- import * as kit from './entry.js';
3
+ import * as kit from './client-entry.js';
4
4
 
5
5
  // @ts-expect-error
6
6
  import * as app from '__sveltekit/manifest';
@@ -0,0 +1,3 @@
1
+ // we expose this as a separate entry point (rather than treating client.js as the entry point)
2
+ // so that everything other than `start`/`load_css` can be treeshaken
3
+ export { start, load_css } from './client.js';