@sveltejs/kit 1.8.6 → 1.8.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sveltejs/kit",
3
- "version": "1.8.6",
3
+ "version": "1.8.8",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/sveltejs/kit",
@@ -43,14 +43,15 @@ export function create_builder({
43
43
  * we expose a stable type that adapters can use to group/filter routes
44
44
  */
45
45
  const routes = route_data.map((route) => {
46
- const methods =
47
- /** @type {import('types').HttpMethod[]} */
48
- (server_metadata.routes.get(route.id)?.methods);
49
- const config = server_metadata.routes.get(route.id)?.config;
46
+ const { config, methods, page, api } = /** @type {import('types').ServerMetadataRoute} */ (
47
+ server_metadata.routes.get(route.id)
48
+ );
50
49
 
51
50
  /** @type {import('types').RouteDefinition} */
52
51
  const facade = {
53
52
  id: route.id,
53
+ api,
54
+ page,
54
55
  segments: get_route_segments(route.id).map((segment) => ({
55
56
  dynamic: segment.includes('['),
56
57
  rest: segment.includes('[...'),
@@ -62,8 +62,11 @@ async function analyse({ manifest_path, env }) {
62
62
 
63
63
  // analyse routes
64
64
  for (const route of manifest._.routes) {
65
- /** @type {Set<import('types').HttpMethod>} */
66
- const methods = new Set();
65
+ /** @type {Array<'GET' | 'POST'>} */
66
+ const page_methods = [];
67
+
68
+ /** @type {import('types').HttpMethod[]} */
69
+ const api_methods = [];
67
70
 
68
71
  /** @type {import('types').PrerenderOption | undefined} */
69
72
  let prerender = undefined;
@@ -84,12 +87,12 @@ async function analyse({ manifest_path, env }) {
84
87
  prerender = mod.prerender;
85
88
  }
86
89
 
87
- if (mod.GET) methods.add('GET');
88
- if (mod.POST) methods.add('POST');
89
- if (mod.PUT) methods.add('PUT');
90
- if (mod.PATCH) methods.add('PATCH');
91
- if (mod.DELETE) methods.add('DELETE');
92
- if (mod.OPTIONS) methods.add('OPTIONS');
90
+ if (mod.GET) api_methods.push('GET');
91
+ if (mod.POST) api_methods.push('POST');
92
+ if (mod.PUT) api_methods.push('PUT');
93
+ if (mod.PATCH) api_methods.push('PATCH');
94
+ if (mod.DELETE) api_methods.push('DELETE');
95
+ if (mod.OPTIONS) api_methods.push('OPTIONS');
93
96
 
94
97
  config = mod.config;
95
98
  }
@@ -112,8 +115,8 @@ async function analyse({ manifest_path, env }) {
112
115
  }
113
116
 
114
117
  if (page) {
115
- methods.add('GET');
116
- if (page.server?.actions) methods.add('POST');
118
+ page_methods.push('GET');
119
+ if (page.server?.actions) page_methods.push('POST');
117
120
 
118
121
  validate_page_server_exports(page.server, page.server_id);
119
122
  validate_common_exports(page.universal, page.universal_id);
@@ -133,9 +136,15 @@ async function analyse({ manifest_path, env }) {
133
136
  }
134
137
 
135
138
  metadata.routes.set(route.id, {
136
- prerender,
137
139
  config,
138
- methods: Array.from(methods)
140
+ methods: Array.from(new Set([...page_methods, ...api_methods])),
141
+ page: {
142
+ methods: page_methods
143
+ },
144
+ api: {
145
+ methods: api_methods
146
+ },
147
+ prerender
139
148
  });
140
149
  }
141
150
 
@@ -218,21 +218,6 @@ function kit({ svelte_config }) {
218
218
 
219
219
  const generated = path.posix.join(kit.outDir, 'generated');
220
220
 
221
- // This ensures that esm-env is inlined into the server output with the
222
- // export conditions resolved correctly through Vite. This prevents adapters
223
- // that bundle later on from resolving the export conditions incorrectly
224
- // and for example include browser-only code in the server output
225
- // because they for example use esbuild.build with `platform: 'browser'`
226
- const noExternal = ['esm-env'];
227
-
228
- // Vitest bypasses Vite when loading external modules, so we bundle
229
- // when it is detected to keep our virtual modules working.
230
- // See https://github.com/sveltejs/kit/pull/9172
231
- // and https://vitest.dev/config/#deps-registernodeloader
232
- if (process.env.TEST) {
233
- noExternal.push('@sveltejs/kit');
234
- }
235
-
236
221
  // dev and preview config can be shared
237
222
  /** @type {import('vite').UserConfig} */
238
223
  const new_config = {
@@ -269,7 +254,23 @@ function kit({ svelte_config }) {
269
254
  ]
270
255
  },
271
256
  ssr: {
272
- noExternal
257
+ noExternal: [
258
+ // This ensures that esm-env is inlined into the server output with the
259
+ // export conditions resolved correctly through Vite. This prevents adapters
260
+ // that bundle later on from resolving the export conditions incorrectly
261
+ // and for example include browser-only code in the server output
262
+ // because they for example use esbuild.build with `platform: 'browser'`
263
+ 'esm-env',
264
+ // We need this for two reasons:
265
+ // 1. Without this, `@sveltejs/kit` imports are kept as-is in the server output,
266
+ // and that causes modules and therefore classes like `Redirect` to be imported twice
267
+ // under different IDs, which breaks a bunch of stuff because of failing instanceof checks.
268
+ // 2. Vitest bypasses Vite when loading external modules, so we bundle
269
+ // when it is detected to keep our virtual modules working.
270
+ // See https://github.com/sveltejs/kit/pull/9172
271
+ // and https://vitest.dev/config/#deps-registernodeloader
272
+ '@sveltejs/kit'
273
+ ]
273
274
  }
274
275
  };
275
276
 
@@ -87,11 +87,11 @@ export function not_found(req, res, base) {
87
87
  if (type === 'text/html') {
88
88
  res.setHeader('Content-Type', 'text/html');
89
89
  res.end(
90
- `The server is configured with a public base URL of /path-base - did you mean to visit <a href="${prefixed}">${prefixed}</a> instead?`
90
+ `The server is configured with a public base URL of ${base} - did you mean to visit <a href="${prefixed}">${prefixed}</a> instead?`
91
91
  );
92
92
  } else {
93
93
  res.end(
94
- `The server is configured with a public base URL of /path-base - did you mean to visit ${prefixed} instead?`
94
+ `The server is configured with a public base URL of ${base} - did you mean to visit ${prefixed} instead?`
95
95
  );
96
96
  }
97
97
  }
package/types/index.d.ts CHANGED
@@ -906,7 +906,7 @@ export interface RequestEvent<
906
906
  */
907
907
  locals: App.Locals;
908
908
  /**
909
- * The parameters of the current page or endpoint - e.g. for a route like `/blog/[slug]`, a `{ slug: string }` object
909
+ * The parameters of the current route - e.g. for a route like `/blog/[slug]`, a `{ slug: string }` object
910
910
  */
911
911
  params: Params;
912
912
  /**
@@ -950,7 +950,7 @@ export interface RequestEvent<
950
950
  */
951
951
  setHeaders(headers: Record<string, string>): void;
952
952
  /**
953
- * The URL of the current page or endpoint.
953
+ * The requested URL.
954
954
  */
955
955
  url: URL;
956
956
  /**
@@ -997,6 +997,12 @@ export interface ResolveOptions {
997
997
 
998
998
  export interface RouteDefinition<Config = any> {
999
999
  id: string;
1000
+ api: {
1001
+ methods: HttpMethod[];
1002
+ };
1003
+ page: {
1004
+ methods: Extract<HttpMethod, 'GET' | 'POST'>[];
1005
+ };
1000
1006
  pattern: RegExp;
1001
1007
  prerender: PrerenderOption;
1002
1008
  segments: RouteSegment[];
@@ -254,16 +254,21 @@ export interface ServerErrorNode {
254
254
  status?: number;
255
255
  }
256
256
 
257
+ export interface ServerMetadataRoute {
258
+ config: any;
259
+ api: {
260
+ methods: HttpMethod[];
261
+ };
262
+ page: {
263
+ methods: Array<'GET' | 'POST'>;
264
+ };
265
+ methods: HttpMethod[];
266
+ prerender: PrerenderOption | undefined;
267
+ }
268
+
257
269
  export interface ServerMetadata {
258
270
  nodes: Array<{ has_server_load: boolean }>;
259
- routes: Map<
260
- string,
261
- {
262
- prerender: PrerenderOption | undefined;
263
- methods: HttpMethod[];
264
- config: any;
265
- }
266
- >;
271
+ routes: Map<string, ServerMetadataRoute>;
267
272
  }
268
273
 
269
274
  export interface SSRComponent {