@sveltejs/kit 1.15.4 → 1.15.5

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.15.4",
3
+ "version": "1.15.5",
4
4
  "description": "The fastest way to build Svelte apps",
5
5
  "repository": {
6
6
  "type": "git",
@@ -227,6 +227,18 @@ function create_routes_and_nodes(cwd, config, fallback) {
227
227
  config.kit.moduleExtensions
228
228
  );
229
229
 
230
+ /**
231
+ * @param {string} type
232
+ * @param {string} existing_file
233
+ */
234
+ function duplicate_files_error(type, existing_file) {
235
+ return new Error(
236
+ `Multiple ${type} files found in ${routes_base}${route.id} : ${path.basename(
237
+ existing_file
238
+ )} and ${file.name}`
239
+ );
240
+ }
241
+
230
242
  if (item.kind === 'component') {
231
243
  if (item.is_error) {
232
244
  route.error = {
@@ -234,21 +246,51 @@ function create_routes_and_nodes(cwd, config, fallback) {
234
246
  component: project_relative
235
247
  };
236
248
  } else if (item.is_layout) {
237
- if (!route.layout) route.layout = { depth, child_pages: [] };
249
+ if (!route.layout) {
250
+ route.layout = { depth, child_pages: [] };
251
+ } else if (route.layout.component) {
252
+ throw duplicate_files_error('layout component', route.layout.component);
253
+ }
254
+
238
255
  route.layout.component = project_relative;
239
256
  if (item.uses_layout !== undefined) route.layout.parent_id = item.uses_layout;
240
257
  } else {
241
- if (!route.leaf) route.leaf = { depth };
258
+ if (!route.leaf) {
259
+ route.leaf = { depth };
260
+ } else if (route.leaf.component) {
261
+ throw duplicate_files_error('page component', route.leaf.component);
262
+ }
263
+
242
264
  route.leaf.component = project_relative;
243
265
  if (item.uses_layout !== undefined) route.leaf.parent_id = item.uses_layout;
244
266
  }
245
267
  } else if (item.is_layout) {
246
- if (!route.layout) route.layout = { depth, child_pages: [] };
268
+ if (!route.layout) {
269
+ route.layout = { depth, child_pages: [] };
270
+ } else if (route.layout[item.kind]) {
271
+ throw duplicate_files_error(
272
+ item.kind + ' layout module',
273
+ /** @type {string} */ (route.layout[item.kind])
274
+ );
275
+ }
276
+
247
277
  route.layout[item.kind] = project_relative;
248
278
  } else if (item.is_page) {
249
- if (!route.leaf) route.leaf = { depth };
279
+ if (!route.leaf) {
280
+ route.leaf = { depth };
281
+ } else if (route.leaf[item.kind]) {
282
+ throw duplicate_files_error(
283
+ item.kind + ' page module',
284
+ /** @type {string} */ (route.leaf[item.kind])
285
+ );
286
+ }
287
+
250
288
  route.leaf[item.kind] = project_relative;
251
289
  } else {
290
+ if (route.endpoint) {
291
+ throw duplicate_files_error('endpoint', route.endpoint.file);
292
+ }
293
+
252
294
  route.endpoint = {
253
295
  file: project_relative
254
296
  };
@@ -105,17 +105,25 @@ export async function getRequest({ request, base, bodySizeLimit }) {
105
105
 
106
106
  /** @type {import('@sveltejs/kit/node').setResponse} */
107
107
  export async function setResponse(res, response) {
108
- const headers = Object.fromEntries(response.headers);
109
-
110
- if (response.headers.has('set-cookie')) {
111
- const header = /** @type {string} */ (response.headers.get('set-cookie'));
112
- const split = set_cookie_parser.splitCookiesString(header);
113
-
114
- // @ts-expect-error
115
- headers['set-cookie'] = split;
108
+ for (const [key, value] of response.headers) {
109
+ try {
110
+ res.setHeader(
111
+ key,
112
+ key === 'set-cookie'
113
+ ? set_cookie_parser.splitCookiesString(
114
+ // This is absurd but necessary, TODO: investigate why
115
+ /** @type {string}*/ (response.headers.get(key))
116
+ )
117
+ : value
118
+ );
119
+ } catch (error) {
120
+ res.getHeaderNames().forEach((name) => res.removeHeader(name));
121
+ res.writeHead(500).end(String(error));
122
+ return;
123
+ }
116
124
  }
117
125
 
118
- res.writeHead(response.status, headers);
126
+ res.writeHead(response.status);
119
127
 
120
128
  if (!response.body) {
121
129
  res.end();
@@ -123,11 +131,10 @@ export async function setResponse(res, response) {
123
131
  }
124
132
 
125
133
  if (response.body.locked) {
126
- res.write(
134
+ res.end(
127
135
  'Fatal error: Response body is locked. ' +
128
136
  `This can happen when the response was already read (for example through 'response.json()' or 'response.text()').`
129
137
  );
130
- res.end();
131
138
  return;
132
139
  }
133
140
 
@@ -34,13 +34,11 @@ export function method_not_allowed(mod, method) {
34
34
 
35
35
  /** @param {Partial<Record<import('types').HttpMethod, any>>} mod */
36
36
  export function allowed_methods(mod) {
37
- const allowed = [];
37
+ const allowed = ['GET', 'POST', 'PUT', 'PATCH', 'DELETE', 'OPTIONS'].filter(
38
+ (method) => method in mod
39
+ );
38
40
 
39
- for (const method in ['GET', 'POST', 'PUT', 'PATCH', 'DELETE', 'OPTIONS']) {
40
- if (method in mod) allowed.push(method);
41
- }
42
-
43
- if (mod.GET || mod.HEAD) allowed.push('HEAD');
41
+ if ('GET' in mod || 'HEAD' in mod) allowed.push('HEAD');
44
42
 
45
43
  return allowed;
46
44
  }
@@ -281,11 +281,13 @@ declare module '$app/paths' {
281
281
  }
282
282
 
283
283
  /**
284
- * Stores on the server are _contextual_ — they are added to the [context](https://svelte.dev/tutorial/context-api) of your root component. This means that `page` is unique to each request, rather than shared between multiple requests handled by the same server simultaneously.
284
+ * These stores are _contextual_ on the server — they are added to the [context](https://svelte.dev/tutorial/context-api) of your root component. This means that `page` is unique to each request, rather than shared between multiple requests handled by the same server simultaneously.
285
285
  *
286
286
  * Because of that, you must subscribe to the stores during component initialization (which happens automatically if you reference the store value, e.g. as `$page`, in a component) before you can use them.
287
287
  *
288
288
  * In the browser, we don't need to worry about this, and stores can be accessed from anywhere. Code that will only ever run on the browser can refer to (or subscribe to) any of these stores at any time.
289
+ *
290
+ * You can read more about client/server differences in the [state management](https://kit.svelte.dev/docs/state-management#using-stores-with-context) documentation.
289
291
  */
290
292
  declare module '$app/stores' {
291
293
  import { Readable } from 'svelte/store';