@sveltejs/kit 1.24.1 → 1.25.0

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.24.1",
3
+ "version": "1.25.0",
4
4
  "description": "The fastest way to build Svelte apps",
5
5
  "repository": {
6
6
  "type": "git",
@@ -33,7 +33,7 @@
33
33
  "@types/sade": "^1.7.4",
34
34
  "@types/set-cookie-parser": "^2.4.2",
35
35
  "dts-buddy": "^0.2.4",
36
- "marked": "^7.0.0",
36
+ "marked": "^9.0.0",
37
37
  "rollup": "^3.7.0",
38
38
  "svelte": "^4.0.5",
39
39
  "svelte-preprocess": "^5.0.4",
@@ -69,7 +69,7 @@ async function analyse({ manifest_path, env }) {
69
69
  /** @type {Array<'GET' | 'POST'>} */
70
70
  const page_methods = [];
71
71
 
72
- /** @type {import('types').HttpMethod[]} */
72
+ /** @type {(import('types').HttpMethod | '*')[]} */
73
73
  const api_methods = [];
74
74
 
75
75
  /** @type {import('types').PrerenderOption | undefined} */
@@ -96,6 +96,8 @@ async function analyse({ manifest_path, env }) {
96
96
  Object.values(mod).forEach((/** @type {import('types').HttpMethod} */ method) => {
97
97
  if (mod[method] && ENDPOINT_METHODS.has(method)) {
98
98
  api_methods.push(method);
99
+ } else if (mod.fallback) {
100
+ api_methods.push('*');
99
101
  }
100
102
  });
101
103
 
@@ -1084,7 +1084,7 @@ export interface ResolveOptions {
1084
1084
  export interface RouteDefinition<Config = any> {
1085
1085
  id: string;
1086
1086
  api: {
1087
- methods: HttpMethod[];
1087
+ methods: Array<HttpMethod | '*'>;
1088
1088
  };
1089
1089
  page: {
1090
1090
  methods: Array<Extract<HttpMethod, 'GET' | 'POST'>>;
@@ -1092,7 +1092,7 @@ export interface RouteDefinition<Config = any> {
1092
1092
  pattern: RegExp;
1093
1093
  prerender: PrerenderOption;
1094
1094
  segments: RouteSegment[];
1095
- methods: HttpMethod[];
1095
+ methods: Array<HttpMethod | '*'>;
1096
1096
  config: Config;
1097
1097
  }
1098
1098
 
@@ -15,6 +15,7 @@ import * as sync from '../../../core/sync/sync.js';
15
15
  import { get_mime_lookup, runtime_base } from '../../../core/utils.js';
16
16
  import { compact } from '../../../utils/array.js';
17
17
  import { not_found } from '../utils.js';
18
+ import { SCHEME } from '../../../utils/url.js';
18
19
 
19
20
  const cwd = process.cwd();
20
21
 
@@ -31,7 +32,7 @@ export async function dev(vite, vite_config, svelte_config) {
31
32
 
32
33
  const fetch = globalThis.fetch;
33
34
  globalThis.fetch = (info, init) => {
34
- if (typeof info === 'string' && !/^\w+:\/\//.test(info)) {
35
+ if (typeof info === 'string' && !SCHEME.test(info)) {
35
36
  throw new Error(
36
37
  `Cannot use relative URL (${info}) with global fetch — use \`event.fetch\` instead: https://kit.svelte.dev/docs/web-standards#fetch-apis`
37
38
  );
@@ -12,9 +12,9 @@ import { method_not_allowed } from './utils.js';
12
12
  export async function render_endpoint(event, mod, state) {
13
13
  const method = /** @type {import('types').HttpMethod} */ (event.request.method);
14
14
 
15
- let handler = mod[method];
15
+ let handler = mod[method] || mod.fallback;
16
16
 
17
- if (!handler && method === 'HEAD') {
17
+ if (method === 'HEAD' && mod.GET && !mod.HEAD) {
18
18
  handler = mod.GET;
19
19
  }
20
20
 
@@ -12,6 +12,7 @@ import { public_env } from '../../shared-server.js';
12
12
  import { text } from '../../../exports/index.js';
13
13
  import { create_async_iterator } from '../../../utils/streaming.js';
14
14
  import { SVELTE_KIT_ASSETS } from '../../../constants.js';
15
+ import { SCHEME } from '../../../utils/url.js';
15
16
 
16
17
  // TODO rename this function/module
17
18
 
@@ -151,7 +152,7 @@ export async function render_response({
151
152
  const fetch = globalThis.fetch;
152
153
  let warned = false;
153
154
  globalThis.fetch = (info, init) => {
154
- if (typeof info === 'string' && !/^\w+:\/\//.test(info)) {
155
+ if (typeof info === 'string' && !SCHEME.test(info)) {
155
156
  throw new Error(
156
157
  `Cannot call \`fetch\` eagerly during server side rendering with relative URL (${info}) — put your \`fetch\` calls inside \`onMount\` or a \`load\` function instead`
157
158
  );
@@ -259,12 +259,12 @@ export interface ServerErrorNode {
259
259
  export interface ServerMetadataRoute {
260
260
  config: any;
261
261
  api: {
262
- methods: HttpMethod[];
262
+ methods: Array<HttpMethod | '*'>;
263
263
  };
264
264
  page: {
265
265
  methods: Array<'GET' | 'POST'>;
266
266
  };
267
- methods: HttpMethod[];
267
+ methods: Array<HttpMethod | '*'>;
268
268
  prerender: PrerenderOption | undefined;
269
269
  entries: string[] | undefined;
270
270
  }
@@ -367,6 +367,7 @@ export type SSREndpoint = Partial<Record<HttpMethod, RequestHandler>> & {
367
367
  trailingSlash?: TrailingSlash;
368
368
  config?: any;
369
369
  entries?: PrerenderEntryGenerator;
370
+ fallback?: RequestHandler;
370
371
  };
371
372
 
372
373
  export interface SSRRoute {
@@ -79,6 +79,7 @@ const valid_server_exports = new Set([
79
79
  'DELETE',
80
80
  'OPTIONS',
81
81
  'HEAD',
82
+ 'fallback',
82
83
  'prerender',
83
84
  'trailingSlash',
84
85
  'config',
package/src/utils/url.js CHANGED
@@ -1,14 +1,19 @@
1
1
  import { BROWSER } from 'esm-env';
2
2
 
3
+ /**
4
+ * Matches a URI scheme. See https://www.rfc-editor.org/rfc/rfc3986#section-3.1
5
+ * @type {RegExp}
6
+ */
7
+ export const SCHEME = /^[a-z][a-z\d+\-.]+:/i;
8
+
3
9
  const absolute = /^([a-z]+:)?\/?\//;
4
- const scheme = /^[a-z]+:/;
5
10
 
6
11
  /**
7
12
  * @param {string} base
8
13
  * @param {string} path
9
14
  */
10
15
  export function resolve(base, path) {
11
- if (scheme.test(path)) return path;
16
+ if (SCHEME.test(path)) return path;
12
17
  if (path[0] === '#') return base + path;
13
18
 
14
19
  const base_match = absolute.exec(base);
package/src/version.js CHANGED
@@ -1,4 +1,4 @@
1
1
  // generated during release, do not modify
2
2
 
3
3
  /** @type {string} */
4
- export const VERSION = '1.24.1';
4
+ export const VERSION = '1.25.0';
package/types/index.d.ts CHANGED
@@ -1064,7 +1064,7 @@ declare module '@sveltejs/kit' {
1064
1064
  export interface RouteDefinition<Config = any> {
1065
1065
  id: string;
1066
1066
  api: {
1067
- methods: HttpMethod[];
1067
+ methods: Array<HttpMethod | '*'>;
1068
1068
  };
1069
1069
  page: {
1070
1070
  methods: Array<Extract<HttpMethod, 'GET' | 'POST'>>;
@@ -1072,7 +1072,7 @@ declare module '@sveltejs/kit' {
1072
1072
  pattern: RegExp;
1073
1073
  prerender: PrerenderOption;
1074
1074
  segments: RouteSegment[];
1075
- methods: HttpMethod[];
1075
+ methods: Array<HttpMethod | '*'>;
1076
1076
  config: Config;
1077
1077
  }
1078
1078
 
@@ -1676,6 +1676,7 @@ declare module '@sveltejs/kit' {
1676
1676
  trailingSlash?: TrailingSlash;
1677
1677
  config?: any;
1678
1678
  entries?: PrerenderEntryGenerator;
1679
+ fallback?: RequestHandler;
1679
1680
  };
1680
1681
 
1681
1682
  interface SSRRoute {
@@ -136,5 +136,5 @@
136
136
  null,
137
137
  null
138
138
  ],
139
- "mappings": ";;;;;;;;;kBA6BiBA,OAAOA;;;;;;;;;;;;;;;;;;;;;;aAsBZC,iBAAiBA;;;;;aAKjBC,cAAcA;;;;;;;;;;;;;;;;;;;;;;;kBAuBTC,OAAOA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;kBAuFPC,MAAMA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;kBA6BNC,OAAOA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;kBAiDPC,SAASA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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