diff --git a/.changeset/brave-parrots-sleep.md b/.changeset/brave-parrots-sleep.md new file mode 100644 index 000000000000..25f2bf51b394 --- /dev/null +++ b/.changeset/brave-parrots-sleep.md @@ -0,0 +1,5 @@ +--- +'@sveltejs/kit': patch +--- + +fix: basic mime type handling for prerendered pages in preview diff --git a/.changeset/clean-garlics-deny.md b/.changeset/clean-garlics-deny.md new file mode 100644 index 000000000000..0ff1a36d68e9 --- /dev/null +++ b/.changeset/clean-garlics-deny.md @@ -0,0 +1,5 @@ +--- +'@sveltejs/kit': patch +--- + +chore: use just a single library (mrmime) for mime type handling diff --git a/packages/kit/package.json b/packages/kit/package.json index 9adf66907765..78717c31a611 100644 --- a/packages/kit/package.json +++ b/packages/kit/package.json @@ -18,7 +18,7 @@ "esm-env": "^1.0.0", "kleur": "^4.1.5", "magic-string": "^0.30.0", - "mime": "^3.0.0", + "mrmime": "^1.0.1", "sade": "^1.8.1", "set-cookie-parser": "^2.6.0", "sirv": "^2.0.2", @@ -28,7 +28,6 @@ "devDependencies": { "@playwright/test": "1.30.0", "@types/connect": "^3.4.35", - "@types/mime": "^3.0.1", "@types/node": "^16.18.6", "@types/sade": "^1.7.4", "@types/set-cookie-parser": "^2.4.2", diff --git a/packages/kit/src/core/sync/create_manifest_data/index.js b/packages/kit/src/core/sync/create_manifest_data/index.js index d5f8dd1cde6a..9ca662b78f58 100644 --- a/packages/kit/src/core/sync/create_manifest_data/index.js +++ b/packages/kit/src/core/sync/create_manifest_data/index.js @@ -1,7 +1,7 @@ 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'; import { posixify } from '../../../utils/filesystem.js'; import { parse_route_id } from '../../../utils/routing.js'; @@ -48,7 +48,7 @@ export function create_assets(config) { return list_files(config.kit.files.assets).map((file) => ({ file, size: fs.statSync(path.resolve(config.kit.files.assets, file)).size, - type: mime.getType(file) + type: lookup(file) || null })); } diff --git a/packages/kit/src/exports/vite/preview/index.js b/packages/kit/src/exports/vite/preview/index.js index 1e5045dd3bda..445334635d2c 100644 --- a/packages/kit/src/exports/vite/preview/index.js +++ b/packages/kit/src/exports/vite/preview/index.js @@ -1,6 +1,7 @@ import fs from 'node:fs'; import { join } from 'node:path'; import { pathToFileURL } from 'node:url'; +import { lookup } from 'mrmime'; import sirv from 'sirv'; import { loadEnv, normalizePath } from 'vite'; import { getRequest, setResponse } from '../../../exports/node/index.js'; @@ -141,7 +142,7 @@ export async function preview(vite, vite_config, svelte_config) { if (prerendered) { res.writeHead(200, { - 'content-type': 'text/html', + 'content-type': lookup(pathname) || 'text/html', etag }); diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 166b9ce7e090..d18b5d8786e2 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -385,9 +385,9 @@ importers: magic-string: specifier: ^0.30.0 version: 0.30.2 - mime: - specifier: ^3.0.0 - version: 3.0.0 + mrmime: + specifier: ^1.0.1 + version: 1.0.1 sade: specifier: ^1.8.1 version: 1.8.1 @@ -410,9 +410,6 @@ importers: '@types/connect': specifier: ^3.4.35 version: 3.4.35 - '@types/mime': - specifier: ^3.0.1 - version: 3.0.1 '@types/node': specifier: ^16.18.6 version: 16.18.6 @@ -2141,10 +2138,6 @@ packages: resolution: {integrity: sha512-Hr5Jfhc9eYOQNPYO5WLDq/n4jqijdHNlDXjuAQkkt+mWdQR+XJToOHrsD4cPaMXpn6KO7y2+wM8AZEs8VpBLVA==} dev: true - /@types/mime@3.0.1: - resolution: {integrity: sha512-Y4XFY5VJAuw0FgAqPNd6NNoV44jbq9Bz2L7Rh/J6jLTiHBSBJa9fxqQIvkIld4GsoDOcCbvzOUAbLPsSKKg+uA==} - dev: true - /@types/minimist@1.2.2: resolution: {integrity: sha512-jhuKLIRrhvCPLqwPcx6INqmKeiA5EWrsCOPhrlFSrbrmU4ZMPjj5Ul/oLCMDO98XRUIwVm78xICz4EPCektzeQ==} dev: true @@ -4592,6 +4585,7 @@ packages: resolution: {integrity: sha512-jSCU7/VB1loIWBZe14aEYHU/+1UMEHoaO7qxCOVJOw9GgH72VAWppxNcjU+x9a2k3GSIBXNKxXQFqRvvZ7vr3A==} engines: {node: '>=10.0.0'} hasBin: true + dev: true /mimic-response@3.1.0: resolution: {integrity: sha512-z0yWI+4FDrrweS8Zmt4Ej5HdJmky15+L2e6Wgn3+iK5fWzb6T3fhNFq2+MeTRb064c6Wr4N/wv0DzQTjNzHNGQ==}