@sveltejs/kit
Advanced tools
Comparing version 1.25.2 to 1.26.0
{ | ||
"name": "@sveltejs/kit", | ||
"version": "1.25.2", | ||
"version": "1.26.0", | ||
"description": "The fastest way to build Svelte apps", | ||
@@ -21,3 +21,3 @@ "repository": { | ||
"magic-string": "^0.30.0", | ||
"mime": "^3.0.0", | ||
"mrmime": "^1.0.1", | ||
"sade": "^1.8.1", | ||
@@ -27,3 +27,3 @@ "set-cookie-parser": "^2.6.0", | ||
"tiny-glob": "^0.2.9", | ||
"undici": "~5.25.0" | ||
"undici": "~5.26.2" | ||
}, | ||
@@ -33,3 +33,2 @@ "devDependencies": { | ||
"@types/connect": "^3.4.35", | ||
"@types/mime": "^3.0.1", | ||
"@types/node": "^16.18.6", | ||
@@ -36,0 +35,0 @@ "@types/sade": "^1.7.4", |
import fs from 'node:fs'; | ||
import path from 'node:path'; | ||
import colors from 'kleur'; | ||
import mime from 'mime'; | ||
import { lookup } from 'mrmime'; | ||
import { list_files, runtime_directory } from '../../utils.js'; | ||
@@ -51,3 +51,3 @@ import { posixify } from '../../../utils/filesystem.js'; | ||
size: fs.statSync(path.resolve(config.kit.files.assets, file)).size, | ||
type: mime.getType(file) | ||
type: lookup(file) || null | ||
})); | ||
@@ -54,0 +54,0 @@ } |
@@ -191,8 +191,16 @@ import fs from 'node:fs'; | ||
declarations.push('type Expand<T> = T extends infer O ? { [K in keyof O]: O[K] } : never;'); | ||
// returns the predicate of a matcher's type guard - or string if there is no type guard | ||
declarations.push( | ||
`type RouteParams = { ${route.params | ||
.map((param) => `${param.name}${param.optional ? '?' : ''}: string`) | ||
.join('; ')} }` | ||
// TS complains on infer U, which seems weird, therefore ts-ignore it | ||
[ | ||
'// @ts-ignore', | ||
'type MatcherParam<M> = M extends (param : string) => param is infer U ? U extends string ? U : string : string;' | ||
].join('\n') | ||
); | ||
declarations.push( | ||
'type RouteParams = ' + generate_params_type(route.params, outdir, config) + ';' | ||
); | ||
if (route.params.length > 0) { | ||
@@ -269,3 +277,4 @@ exports.push( | ||
let all_pages_have_load = true; | ||
const layout_params = new Set(); | ||
/** @type {import('types').RouteParam[]} */ | ||
const layout_params = []; | ||
const ids = ['RouteId']; | ||
@@ -279,3 +288,5 @@ | ||
for (const param of leaf.route.params) { | ||
layout_params.add(param.name); | ||
// skip if already added | ||
if (layout_params.some((p) => p.name === param.name)) continue; | ||
layout_params.push({ ...param, optional: true }); | ||
} | ||
@@ -307,5 +318,3 @@ | ||
declarations.push( | ||
`type LayoutParams = RouteParams & { ${Array.from(layout_params).map( | ||
(param) => `${param}?: string` | ||
)} }` | ||
'type LayoutParams = RouteParams & ' + generate_params_type(layout_params, outdir, config) | ||
); | ||
@@ -575,2 +584,24 @@ | ||
/** | ||
* @param {import('types').RouteParam[]} params | ||
* @param {string} outdir | ||
* @param {import('types').ValidatedConfig} config | ||
*/ | ||
function generate_params_type(params, outdir, config) { | ||
/** @param {string} matcher */ | ||
const path_to_matcher = (matcher) => | ||
posixify(path.relative(outdir, path.join(config.kit.files.params, matcher))); | ||
return `{ ${params | ||
.map( | ||
(param) => | ||
`${param.name}${param.optional ? '?' : ''}: ${ | ||
param.matcher | ||
? `MatcherParam<typeof import('${path_to_matcher(param.matcher)}').match>` | ||
: 'string' | ||
}` | ||
) | ||
.join('; ')} }`; | ||
} | ||
/** | ||
* @param {string} content | ||
@@ -577,0 +608,0 @@ * @param {boolean} is_server |
import fs from 'node:fs'; | ||
import { join } from 'node:path'; | ||
import { pathToFileURL } from 'node:url'; | ||
import { lookup } from 'mrmime'; | ||
import sirv from 'sirv'; | ||
@@ -144,3 +145,3 @@ import { loadEnv, normalizePath } from 'vite'; | ||
res.writeHead(200, { | ||
'content-type': 'text/html', | ||
'content-type': lookup(pathname) || 'text/html', | ||
etag | ||
@@ -147,0 +148,0 @@ }); |
@@ -176,3 +176,3 @@ import { DEV } from 'esm-env'; | ||
if (navigation_result.type === 'redirect') { | ||
return goto(new URL(navigation_result.location, url).href, {}, [url.pathname], nav_token); | ||
return goto(new URL(navigation_result.location, url).href, {}, 1, nav_token); | ||
} else { | ||
@@ -212,3 +212,3 @@ if (navigation_result.props.page !== undefined) { | ||
* @param {{ noScroll?: boolean; replaceState?: boolean; keepFocus?: boolean; state?: any; invalidateAll?: boolean }} opts | ||
* @param {string[]} redirect_chain | ||
* @param {number} redirect_count | ||
* @param {{}} [nav_token] | ||
@@ -225,3 +225,3 @@ */ | ||
}, | ||
redirect_chain, | ||
redirect_count, | ||
nav_token | ||
@@ -237,3 +237,3 @@ ) { | ||
keepfocus: keepFocus, | ||
redirect_chain, | ||
redirect_count, | ||
details: { | ||
@@ -948,3 +948,3 @@ state, | ||
* keepfocus: boolean; | ||
* redirect_chain: string[]; | ||
* redirect_count: number; | ||
* details: { | ||
@@ -965,3 +965,3 @@ * replaceState: boolean; | ||
keepfocus, | ||
redirect_chain, | ||
redirect_count, | ||
details, | ||
@@ -1023,3 +1023,4 @@ type, | ||
if (navigation_result.type === 'redirect') { | ||
if (redirect_chain.length > 10 || redirect_chain.includes(url.pathname)) { | ||
// whatwg fetch spec https://fetch.spec.whatwg.org/#http-redirect-fetch says to error after 20 redirects | ||
if (redirect_count >= 20) { | ||
navigation_result = await load_root_error_page({ | ||
@@ -1036,8 +1037,3 @@ status: 500, | ||
} else { | ||
goto( | ||
new URL(navigation_result.location, url).href, | ||
{}, | ||
[...redirect_chain, url.pathname], | ||
nav_token | ||
); | ||
goto(new URL(navigation_result.location, url).href, {}, redirect_count + 1, nav_token); | ||
return false; | ||
@@ -1390,3 +1386,3 @@ } | ||
goto: (href, opts = {}) => { | ||
return goto(href, opts, []); | ||
return goto(href, opts, 0); | ||
}, | ||
@@ -1452,3 +1448,3 @@ | ||
} else if (result.type === 'redirect') { | ||
goto(result.location, { invalidateAll: true }, []); | ||
goto(result.location, { invalidateAll: true }, 0); | ||
} else { | ||
@@ -1608,3 +1604,3 @@ /** @type {Record<string, any>} */ | ||
keepfocus: options.keep_focus ?? false, | ||
redirect_chain: [], | ||
redirect_count: 0, | ||
details: { | ||
@@ -1663,3 +1659,3 @@ state: {}, | ||
keepfocus: keep_focus ?? false, | ||
redirect_chain: [], | ||
redirect_count: 0, | ||
details: { | ||
@@ -1702,3 +1698,3 @@ state: {}, | ||
keepfocus: false, | ||
redirect_chain: [], | ||
redirect_count: 0, | ||
details: null, | ||
@@ -1705,0 +1701,0 @@ accepted: () => { |
@@ -26,2 +26,6 @@ import { DEV } from 'esm-env'; | ||
/** | ||
* @param {RequestInfo | URL} input | ||
* @param {RequestInit & Record<string, any> | undefined} init | ||
*/ | ||
window.fetch = (input, init) => { | ||
@@ -40,6 +44,10 @@ // Check if fetch was called via load_node. the lock method only checks if it was called at the | ||
const heuristic = can_inspect_stack_trace | ||
const in_load_heuristic = can_inspect_stack_trace | ||
? stack.includes('src/runtime/client/client.js') | ||
: loading; | ||
if (heuristic) { | ||
// This flag is set in initial_fetch and subsequent_fetch | ||
const used_kit_fetch = init?.__sveltekit_fetch__; | ||
if (in_load_heuristic && !used_kit_fetch) { | ||
console.warn( | ||
@@ -91,3 +99,3 @@ `Loading ${url} using \`window.fetch\`. For best results, use the \`fetch\` that is passed to your \`load\` function: https://kit.svelte.dev/docs/load#making-fetch-requests` | ||
return native_fetch(resource, opts); | ||
return DEV ? dev_fetch(resource, opts) : window.fetch(resource, opts); | ||
} | ||
@@ -118,6 +126,21 @@ | ||
return native_fetch(resolved, opts); | ||
return DEV ? dev_fetch(resolved, opts) : window.fetch(resolved, opts); | ||
} | ||
/** | ||
* @param {RequestInfo | URL} resource | ||
* @param {RequestInit & Record<string, any> | undefined} opts | ||
*/ | ||
function dev_fetch(resource, opts) { | ||
const patched_opts = { ...opts }; | ||
// This assigns the __sveltekit_fetch__ flag and makes it non-enumerable | ||
Object.defineProperty(patched_opts, '__sveltekit_fetch__', { | ||
value: true, | ||
writable: true, | ||
configurable: true | ||
}); | ||
return window.fetch(resource, patched_opts); | ||
} | ||
/** | ||
* Build the cache key for a given request | ||
@@ -124,0 +147,0 @@ * @param {URL | RequestInfo} resource |
// generated during release, do not modify | ||
/** @type {string} */ | ||
export const VERSION = '1.25.2'; | ||
export const VERSION = '1.26.0'; |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
672241
13
19760
+ Addedmrmime@^1.0.1
+ Addedmrmime@1.0.1(transitive)
+ Addedundici@5.26.5(transitive)
- Removedmime@^3.0.0
- Removedmime@3.0.0(transitive)
- Removedundici@5.25.4(transitive)
Updatedundici@~5.26.2