From 3c218a4a7728da96b0676fe3ecc3b3cbdd66ed26 Mon Sep 17 00:00:00 2001 From: gornostay25 Date: Tue, 12 Jul 2022 17:36:31 +0200 Subject: [PATCH] add Range headers support for static files Many small bug fixes https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Range https://github.com/oven-sh/bun/issues/616 --- README.md | 6 + index.js | 2 +- package-lock.json | 478 +++++++++++++++++++++++++--------------------- package.json | 9 +- rollup.config.js | 5 +- src/handler.js | 9 +- src/sirv.js | 93 ++++----- 7 files changed, 328 insertions(+), 274 deletions(-) diff --git a/README.md b/README.md index 1d7a5f6..672b0e4 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,10 @@ [Adapter](https://kit.svelte.dev/docs/adapters) for SvelteKit apps that generates a standalone [Bun](https://github.com/oven-sh/bun) server. +> **Warning** +> **This is experimental module!** Bun does not support many things like [`FormData`](https://github.com/oven-sh/bun/issues/621) +> So I can't promise it will work + ## Usage Install with `bun add -d svelte-adapter-bun` or `npm i -D svelte-adapter-bun`, then add the adapter to your `svelte.config.js`: @@ -62,6 +66,8 @@ The directory to build the server to. It defaults to `build` — i.e. `bun run s Browse a static assets. Default: `true` + - [X] Support [HTTP range requests](https://developer.mozilla.org/en-US/docs/Web/HTTP/Range_requests) + ### precompress Enables precompressing using gzip and brotli for assets and prerendered pages. It defaults to `false`. diff --git a/index.js b/index.js index dc22b2a..69fe492 100644 --- a/index.js +++ b/index.js @@ -78,7 +78,7 @@ export default function (opts = {}) { JSON.stringify(package_data, null, "\t") ); - builder.log.success("Start server with: bun /build/index.js") + builder.log.success("Start server with: bun ./build/index.js") } }; } diff --git a/package-lock.json b/package-lock.json index c7a50f8..3d467cf 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "svelte-adapter-bun", - "version": "0.2.2-2", + "version": "0.2.2-3", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "svelte-adapter-bun", - "version": "0.2.2-2", + "version": "0.2.2-3", "license": "MIT", "dependencies": { "tiny-glob": "^0.2.9" @@ -15,11 +15,12 @@ "@rollup/plugin-commonjs": "^22.0.1", "@rollup/plugin-json": "^4.1.0", "@rollup/plugin-node-resolve": "^13.3.0", - "@sveltejs/kit": "^1.0.0-next.367", - "bun-types": "^0.1.2", + "@sveltejs/kit": "next", + "bun-types": "latest", "mrmime": "^1.0.1", "rimraf": "^3.0.2", "rollup": "^2.76.0", + "rollup-plugin-cleanup": "^3.2.1", "rollup-plugin-copy": "^3.4.0", "totalist": "^3.0.0" } @@ -80,38 +81,6 @@ "rollup": "^2.68.0" } }, - "node_modules/@rollup/plugin-commonjs/node_modules/@rollup/pluginutils": { - "version": "3.1.0", - "resolved": "https://registry.npmjs.org/@rollup/pluginutils/-/pluginutils-3.1.0.tgz", - "integrity": "sha512-GksZ6pr6TpIjHm8h9lSQ8pi8BE9VeubNT0OMJ3B5uZJ8pz73NPiqOtCog/x2/QzM1ENChPKxMDhiQuRHsqc+lg==", - "dev": true, - "dependencies": { - "@types/estree": "0.0.39", - "estree-walker": "^1.0.1", - "picomatch": "^2.2.2" - }, - "engines": { - "node": ">= 8.0.0" - }, - "peerDependencies": { - "rollup": "^1.20.0||^2.0.0" - } - }, - "node_modules/@rollup/plugin-commonjs/node_modules/@rollup/pluginutils/node_modules/estree-walker": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/estree-walker/-/estree-walker-1.0.1.tgz", - "integrity": "sha512-1fMXF3YP4pZZVozF8j/ZLfvnR8NSIljt56UhbZ5PeeDmmGHpgpdwQt7ITlGvYaQukCvuBRMLEiKiYC+oeIg4cg==", - "dev": true - }, - "node_modules/@rollup/plugin-commonjs/node_modules/magic-string": { - "version": "0.25.9", - "resolved": "https://registry.npmjs.org/magic-string/-/magic-string-0.25.9.tgz", - "integrity": "sha512-RmF0AsMzgt25qzqqLc1+MbHmhdx0ojF2Fvs4XnOqz2ZOBXzzkEwc/dJQZCYHAn7v1jbVOjAZfK8msRn4BxO4VQ==", - "dev": true, - "dependencies": { - "sourcemap-codec": "^1.4.8" - } - }, "node_modules/@rollup/plugin-json": { "version": "4.1.0", "resolved": "https://registry.npmjs.org/@rollup/plugin-json/-/plugin-json-4.1.0.tgz", @@ -124,29 +93,6 @@ "rollup": "^1.20.0 || ^2.0.0" } }, - "node_modules/@rollup/plugin-json/node_modules/@rollup/pluginutils": { - "version": "3.1.0", - "resolved": "https://registry.npmjs.org/@rollup/pluginutils/-/pluginutils-3.1.0.tgz", - "integrity": "sha512-GksZ6pr6TpIjHm8h9lSQ8pi8BE9VeubNT0OMJ3B5uZJ8pz73NPiqOtCog/x2/QzM1ENChPKxMDhiQuRHsqc+lg==", - "dev": true, - "dependencies": { - "@types/estree": "0.0.39", - "estree-walker": "^1.0.1", - "picomatch": "^2.2.2" - }, - "engines": { - "node": ">= 8.0.0" - }, - "peerDependencies": { - "rollup": "^1.20.0||^2.0.0" - } - }, - "node_modules/@rollup/plugin-json/node_modules/estree-walker": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/estree-walker/-/estree-walker-1.0.1.tgz", - "integrity": "sha512-1fMXF3YP4pZZVozF8j/ZLfvnR8NSIljt56UhbZ5PeeDmmGHpgpdwQt7ITlGvYaQukCvuBRMLEiKiYC+oeIg4cg==", - "dev": true - }, "node_modules/@rollup/plugin-node-resolve": { "version": "13.3.0", "resolved": "https://registry.npmjs.org/@rollup/plugin-node-resolve/-/plugin-node-resolve-13.3.0.tgz", @@ -167,7 +113,7 @@ "rollup": "^2.42.0" } }, - "node_modules/@rollup/plugin-node-resolve/node_modules/@rollup/pluginutils": { + "node_modules/@rollup/pluginutils": { "version": "3.1.0", "resolved": "https://registry.npmjs.org/@rollup/pluginutils/-/pluginutils-3.1.0.tgz", "integrity": "sha512-GksZ6pr6TpIjHm8h9lSQ8pi8BE9VeubNT0OMJ3B5uZJ8pz73NPiqOtCog/x2/QzM1ENChPKxMDhiQuRHsqc+lg==", @@ -184,29 +130,16 @@ "rollup": "^1.20.0||^2.0.0" } }, - "node_modules/@rollup/plugin-node-resolve/node_modules/estree-walker": { + "node_modules/@rollup/pluginutils/node_modules/estree-walker": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/estree-walker/-/estree-walker-1.0.1.tgz", "integrity": "sha512-1fMXF3YP4pZZVozF8j/ZLfvnR8NSIljt56UhbZ5PeeDmmGHpgpdwQt7ITlGvYaQukCvuBRMLEiKiYC+oeIg4cg==", "dev": true }, - "node_modules/@rollup/pluginutils": { - "version": "4.2.1", - "resolved": "https://registry.npmjs.org/@rollup/pluginutils/-/pluginutils-4.2.1.tgz", - "integrity": "sha512-iKnFXr7NkdZAIHiIWE+BX5ULi/ucVFYWD6TbAV+rZctiRTY2PL6tsIKhoIOaoskiWAkgu+VsbXgUVDNLHf+InQ==", - "dev": true, - "dependencies": { - "estree-walker": "^2.0.1", - "picomatch": "^2.2.2" - }, - "engines": { - "node": ">= 8.0.0" - } - }, "node_modules/@sveltejs/kit": { - "version": "1.0.0-next.367", - "resolved": "https://registry.npmjs.org/@sveltejs/kit/-/kit-1.0.0-next.367.tgz", - "integrity": "sha512-glilWol6iJEf8esQpH0HOzdI4n/xgZtoLa9U9sbg+BZelQXFRRglaGyw+ahjEreBH5MH3/bpIYAPPObQN8Pgbg==", + "version": "1.0.0-next.370", + "resolved": "https://registry.npmjs.org/@sveltejs/kit/-/kit-1.0.0-next.370.tgz", + "integrity": "sha512-HAQtw8IjXs9yOPWKpuwpGgDT8x6Dgqm14NmFx0emF52vo5wn3tQzu0cBx299Po2RdRgfSDFKrNqVSlL1hVTHcA==", "dev": true, "dependencies": { "@sveltejs/vite-plugin-svelte": "^1.0.0-next.48", @@ -251,6 +184,31 @@ } } }, + "node_modules/@sveltejs/vite-plugin-svelte/node_modules/@rollup/pluginutils": { + "version": "4.2.1", + "resolved": "https://registry.npmjs.org/@rollup/pluginutils/-/pluginutils-4.2.1.tgz", + "integrity": "sha512-iKnFXr7NkdZAIHiIWE+BX5ULi/ucVFYWD6TbAV+rZctiRTY2PL6tsIKhoIOaoskiWAkgu+VsbXgUVDNLHf+InQ==", + "dev": true, + "dependencies": { + "estree-walker": "^2.0.1", + "picomatch": "^2.2.2" + }, + "engines": { + "node": ">= 8.0.0" + } + }, + "node_modules/@sveltejs/vite-plugin-svelte/node_modules/magic-string": { + "version": "0.26.2", + "resolved": "https://registry.npmjs.org/magic-string/-/magic-string-0.26.2.tgz", + "integrity": "sha512-NzzlXpclt5zAbmo6h6jNc8zl2gNRGHvmsZW4IvZhTC4W7k4OlLP+S5YLussa/r3ixNT66KOQfNORlXHSOy/X4A==", + "dev": true, + "dependencies": { + "sourcemap-codec": "^1.4.8" + }, + "engines": { + "node": ">=12" + } + }, "node_modules/@types/estree": { "version": "0.0.39", "resolved": "https://registry.npmjs.org/@types/estree/-/estree-0.0.39.tgz", @@ -369,9 +327,9 @@ } }, "node_modules/bun-types": { - "version": "0.1.2", - "resolved": "https://registry.npmjs.org/bun-types/-/bun-types-0.1.2.tgz", - "integrity": "sha512-7R0rl/rvVVsw5DSywjjI3u1Ai2RM2TPnUbMPwfoVr1R3pt/92E4jZD7ZqQIn25ZKucD6z5nVyux4pfXU4hcJnw==", + "version": "0.1.3", + "resolved": "https://registry.npmjs.org/bun-types/-/bun-types-0.1.3.tgz", + "integrity": "sha512-mbqjiQNw5O0Id0KT5Oar1VgeK5tLoNA7KBLc8KFz1EbjU3jUjdlbQWKz39K4Ea0T68Orsg/B6EWP30W+M+VANw==", "dev": true }, "node_modules/chokidar": { @@ -458,9 +416,9 @@ } }, "node_modules/esbuild": { - "version": "0.14.48", - "resolved": "https://registry.npmjs.org/esbuild/-/esbuild-0.14.48.tgz", - "integrity": "sha512-w6N1Yn5MtqK2U1/WZTX9ZqUVb8IOLZkZ5AdHkT6x3cHDMVsYWC7WPdiLmx19w3i4Rwzy5LqsEMtVihG3e4rFzA==", + "version": "0.14.49", + "resolved": "https://registry.npmjs.org/esbuild/-/esbuild-0.14.49.tgz", + "integrity": "sha512-/TlVHhOaq7Yz8N1OJrjqM3Auzo5wjvHFLk+T8pIue+fhnhIMpfAzsG6PLVMbFveVxqD2WOp3QHei+52IMUNmCw==", "dev": true, "hasInstallScript": true, "peer": true, @@ -471,32 +429,32 @@ "node": ">=12" }, "optionalDependencies": { - "esbuild-android-64": "0.14.48", - "esbuild-android-arm64": "0.14.48", - "esbuild-darwin-64": "0.14.48", - "esbuild-darwin-arm64": "0.14.48", - "esbuild-freebsd-64": "0.14.48", - "esbuild-freebsd-arm64": "0.14.48", - "esbuild-linux-32": "0.14.48", - "esbuild-linux-64": "0.14.48", - "esbuild-linux-arm": "0.14.48", - "esbuild-linux-arm64": "0.14.48", - "esbuild-linux-mips64le": "0.14.48", - "esbuild-linux-ppc64le": "0.14.48", - "esbuild-linux-riscv64": "0.14.48", - "esbuild-linux-s390x": "0.14.48", - "esbuild-netbsd-64": "0.14.48", - "esbuild-openbsd-64": "0.14.48", - "esbuild-sunos-64": "0.14.48", - "esbuild-windows-32": "0.14.48", - "esbuild-windows-64": "0.14.48", - "esbuild-windows-arm64": "0.14.48" + "esbuild-android-64": "0.14.49", + "esbuild-android-arm64": "0.14.49", + "esbuild-darwin-64": "0.14.49", + "esbuild-darwin-arm64": "0.14.49", + "esbuild-freebsd-64": "0.14.49", + "esbuild-freebsd-arm64": "0.14.49", + "esbuild-linux-32": "0.14.49", + "esbuild-linux-64": "0.14.49", + "esbuild-linux-arm": "0.14.49", + "esbuild-linux-arm64": "0.14.49", + "esbuild-linux-mips64le": "0.14.49", + "esbuild-linux-ppc64le": "0.14.49", + "esbuild-linux-riscv64": "0.14.49", + "esbuild-linux-s390x": "0.14.49", + "esbuild-netbsd-64": "0.14.49", + "esbuild-openbsd-64": "0.14.49", + "esbuild-sunos-64": "0.14.49", + "esbuild-windows-32": "0.14.49", + "esbuild-windows-64": "0.14.49", + "esbuild-windows-arm64": "0.14.49" } }, "node_modules/esbuild-windows-64": { - "version": "0.14.48", - "resolved": "https://registry.npmjs.org/esbuild-windows-64/-/esbuild-windows-64-0.14.48.tgz", - "integrity": "sha512-YmpXjdT1q0b8ictSdGwH3M8VCoqPpK1/UArze3X199w6u8hUx3V8BhAi1WjbsfDYRBanVVtduAhh2sirImtAvA==", + "version": "0.14.49", + "resolved": "https://registry.npmjs.org/esbuild-windows-64/-/esbuild-windows-64-0.14.49.tgz", + "integrity": "sha512-+Cme7Ongv0UIUTniPqfTX6mJ8Deo7VXw9xN0yJEN1lQMHDppTNmKwAM3oGbD/Vqff+07K2gN0WfNkMohmG+dVw==", "cpu": [ "x64" ], @@ -773,6 +731,20 @@ "@types/estree": "*" } }, + "node_modules/js-cleanup": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/js-cleanup/-/js-cleanup-1.2.0.tgz", + "integrity": "sha512-JeDD0yiiSt80fXzAVa/crrS0JDPQljyBG/RpOtaSbyDq03VHa9szJWMaWOYU/bcTn412uMN2MxApXq8v79cUiQ==", + "dev": true, + "dependencies": { + "magic-string": "^0.25.7", + "perf-regexes": "^1.0.1", + "skip-regex": "^1.0.2" + }, + "engines": { + "node": "^10.14.2 || >=12.0.0" + } + }, "node_modules/jsonfile": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/jsonfile/-/jsonfile-4.0.0.tgz", @@ -792,15 +764,12 @@ } }, "node_modules/magic-string": { - "version": "0.26.2", - "resolved": "https://registry.npmjs.org/magic-string/-/magic-string-0.26.2.tgz", - "integrity": "sha512-NzzlXpclt5zAbmo6h6jNc8zl2gNRGHvmsZW4IvZhTC4W7k4OlLP+S5YLussa/r3ixNT66KOQfNORlXHSOy/X4A==", + "version": "0.25.9", + "resolved": "https://registry.npmjs.org/magic-string/-/magic-string-0.25.9.tgz", + "integrity": "sha512-RmF0AsMzgt25qzqqLc1+MbHmhdx0ojF2Fvs4XnOqz2ZOBXzzkEwc/dJQZCYHAn7v1jbVOjAZfK8msRn4BxO4VQ==", "dev": true, "dependencies": { "sourcemap-codec": "^1.4.8" - }, - "engines": { - "node": ">=12" } }, "node_modules/merge2": { @@ -916,6 +885,15 @@ "node": ">=8" } }, + "node_modules/perf-regexes": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/perf-regexes/-/perf-regexes-1.0.1.tgz", + "integrity": "sha512-L7MXxUDtqr4PUaLFCDCXBfGV/6KLIuSEccizDI7JxT+c9x1G1v04BQ4+4oag84SHaCdrBgQAIs/Cqn+flwFPng==", + "dev": true, + "engines": { + "node": ">=6.14" + } + }, "node_modules/picocolors": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/picocolors/-/picocolors-1.0.0.tgz", @@ -1049,6 +1027,22 @@ "fsevents": "~2.3.2" } }, + "node_modules/rollup-plugin-cleanup": { + "version": "3.2.1", + "resolved": "https://registry.npmjs.org/rollup-plugin-cleanup/-/rollup-plugin-cleanup-3.2.1.tgz", + "integrity": "sha512-zuv8EhoO3TpnrU8MX8W7YxSbO4gmOR0ny06Lm3nkFfq0IVKdBUtHwhVzY1OAJyNCIAdLiyPnOrU0KnO0Fri1GQ==", + "dev": true, + "dependencies": { + "js-cleanup": "^1.2.0", + "rollup-pluginutils": "^2.8.2" + }, + "engines": { + "node": "^10.14.2 || >=12.0.0" + }, + "peerDependencies": { + "rollup": ">=2.0" + } + }, "node_modules/rollup-plugin-copy": { "version": "3.4.0", "resolved": "https://registry.npmjs.org/rollup-plugin-copy/-/rollup-plugin-copy-3.4.0.tgz", @@ -1065,6 +1059,21 @@ "node": ">=8.3" } }, + "node_modules/rollup-pluginutils": { + "version": "2.8.2", + "resolved": "https://registry.npmjs.org/rollup-pluginutils/-/rollup-pluginutils-2.8.2.tgz", + "integrity": "sha512-EEp9NhnUkwY8aif6bxgovPHMoMoNr2FulJziTndpt5H9RdwC47GSGuII9XxpSdzVGM0GWrNPHV6ie1LTNJPaLQ==", + "dev": true, + "dependencies": { + "estree-walker": "^0.6.1" + } + }, + "node_modules/rollup-pluginutils/node_modules/estree-walker": { + "version": "0.6.1", + "resolved": "https://registry.npmjs.org/estree-walker/-/estree-walker-0.6.1.tgz", + "integrity": "sha512-SqmZANLWS0mnatqbSfRP5g8OXZC12Fgg1IwNtLsyHDzJizORW4khDfjPqJZsemPWBB2uqykUah5YpQ6epsqC/w==", + "dev": true + }, "node_modules/run-parallel": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/run-parallel/-/run-parallel-1.2.0.tgz", @@ -1100,6 +1109,15 @@ "node": ">=6" } }, + "node_modules/skip-regex": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/skip-regex/-/skip-regex-1.0.2.tgz", + "integrity": "sha512-pEjMUbwJ5Pl/6Vn6FsamXHXItJXSRftcibixDmNCWbWhic0hzHrwkMZo0IZ7fMRH9KxcWDFSkzhccB4285PutA==", + "dev": true, + "engines": { + "node": ">=4.2" + } + }, "node_modules/slash": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/slash/-/slash-3.0.0.tgz", @@ -1189,6 +1207,15 @@ "node": ">=6" } }, + "node_modules/undici": { + "version": "5.7.0", + "resolved": "https://registry.npmjs.org/undici/-/undici-5.7.0.tgz", + "integrity": "sha512-ORgxwDkiPS+gK2VxE7iyVeR7JliVn5DqhZ4LgQqYLBXsuK+lwOEmnJ66dhvlpLM0tC3fC7eYF1Bti2frbw2eAA==", + "dev": true, + "engines": { + "node": ">=12.18" + } + }, "node_modules/universalify": { "version": "0.1.2", "resolved": "https://registry.npmjs.org/universalify/-/universalify-0.1.2.tgz", @@ -1283,36 +1310,6 @@ "is-reference": "^1.2.1", "magic-string": "^0.25.7", "resolve": "^1.17.0" - }, - "dependencies": { - "@rollup/pluginutils": { - "version": "3.1.0", - "resolved": "https://registry.npmjs.org/@rollup/pluginutils/-/pluginutils-3.1.0.tgz", - "integrity": "sha512-GksZ6pr6TpIjHm8h9lSQ8pi8BE9VeubNT0OMJ3B5uZJ8pz73NPiqOtCog/x2/QzM1ENChPKxMDhiQuRHsqc+lg==", - "dev": true, - "requires": { - "@types/estree": "0.0.39", - "estree-walker": "^1.0.1", - "picomatch": "^2.2.2" - }, - "dependencies": { - "estree-walker": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/estree-walker/-/estree-walker-1.0.1.tgz", - "integrity": "sha512-1fMXF3YP4pZZVozF8j/ZLfvnR8NSIljt56UhbZ5PeeDmmGHpgpdwQt7ITlGvYaQukCvuBRMLEiKiYC+oeIg4cg==", - "dev": true - } - } - }, - "magic-string": { - "version": "0.25.9", - "resolved": "https://registry.npmjs.org/magic-string/-/magic-string-0.25.9.tgz", - "integrity": "sha512-RmF0AsMzgt25qzqqLc1+MbHmhdx0ojF2Fvs4XnOqz2ZOBXzzkEwc/dJQZCYHAn7v1jbVOjAZfK8msRn4BxO4VQ==", - "dev": true, - "requires": { - "sourcemap-codec": "^1.4.8" - } - } } }, "@rollup/plugin-json": { @@ -1322,25 +1319,6 @@ "dev": true, "requires": { "@rollup/pluginutils": "^3.0.8" - }, - "dependencies": { - "@rollup/pluginutils": { - "version": "3.1.0", - "resolved": "https://registry.npmjs.org/@rollup/pluginutils/-/pluginutils-3.1.0.tgz", - "integrity": "sha512-GksZ6pr6TpIjHm8h9lSQ8pi8BE9VeubNT0OMJ3B5uZJ8pz73NPiqOtCog/x2/QzM1ENChPKxMDhiQuRHsqc+lg==", - "dev": true, - "requires": { - "@types/estree": "0.0.39", - "estree-walker": "^1.0.1", - "picomatch": "^2.2.2" - } - }, - "estree-walker": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/estree-walker/-/estree-walker-1.0.1.tgz", - "integrity": "sha512-1fMXF3YP4pZZVozF8j/ZLfvnR8NSIljt56UhbZ5PeeDmmGHpgpdwQt7ITlGvYaQukCvuBRMLEiKiYC+oeIg4cg==", - "dev": true - } } }, "@rollup/plugin-node-resolve": { @@ -1355,19 +1333,19 @@ "is-builtin-module": "^3.1.0", "is-module": "^1.0.0", "resolve": "^1.19.0" + } + }, + "@rollup/pluginutils": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/@rollup/pluginutils/-/pluginutils-3.1.0.tgz", + "integrity": "sha512-GksZ6pr6TpIjHm8h9lSQ8pi8BE9VeubNT0OMJ3B5uZJ8pz73NPiqOtCog/x2/QzM1ENChPKxMDhiQuRHsqc+lg==", + "dev": true, + "requires": { + "@types/estree": "0.0.39", + "estree-walker": "^1.0.1", + "picomatch": "^2.2.2" }, "dependencies": { - "@rollup/pluginutils": { - "version": "3.1.0", - "resolved": "https://registry.npmjs.org/@rollup/pluginutils/-/pluginutils-3.1.0.tgz", - "integrity": "sha512-GksZ6pr6TpIjHm8h9lSQ8pi8BE9VeubNT0OMJ3B5uZJ8pz73NPiqOtCog/x2/QzM1ENChPKxMDhiQuRHsqc+lg==", - "dev": true, - "requires": { - "@types/estree": "0.0.39", - "estree-walker": "^1.0.1", - "picomatch": "^2.2.2" - } - }, "estree-walker": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/estree-walker/-/estree-walker-1.0.1.tgz", @@ -1376,20 +1354,10 @@ } } }, - "@rollup/pluginutils": { - "version": "4.2.1", - "resolved": "https://registry.npmjs.org/@rollup/pluginutils/-/pluginutils-4.2.1.tgz", - "integrity": "sha512-iKnFXr7NkdZAIHiIWE+BX5ULi/ucVFYWD6TbAV+rZctiRTY2PL6tsIKhoIOaoskiWAkgu+VsbXgUVDNLHf+InQ==", - "dev": true, - "requires": { - "estree-walker": "^2.0.1", - "picomatch": "^2.2.2" - } - }, "@sveltejs/kit": { - "version": "1.0.0-next.367", - "resolved": "https://registry.npmjs.org/@sveltejs/kit/-/kit-1.0.0-next.367.tgz", - "integrity": "sha512-glilWol6iJEf8esQpH0HOzdI4n/xgZtoLa9U9sbg+BZelQXFRRglaGyw+ahjEreBH5MH3/bpIYAPPObQN8Pgbg==", + "version": "1.0.0-next.370", + "resolved": "https://registry.npmjs.org/@sveltejs/kit/-/kit-1.0.0-next.370.tgz", + "integrity": "sha512-HAQtw8IjXs9yOPWKpuwpGgDT8x6Dgqm14NmFx0emF52vo5wn3tQzu0cBx299Po2RdRgfSDFKrNqVSlL1hVTHcA==", "dev": true, "requires": { "@sveltejs/vite-plugin-svelte": "^1.0.0-next.48", @@ -1409,6 +1377,27 @@ "kleur": "^4.1.4", "magic-string": "^0.26.2", "svelte-hmr": "^0.14.12" + }, + "dependencies": { + "@rollup/pluginutils": { + "version": "4.2.1", + "resolved": "https://registry.npmjs.org/@rollup/pluginutils/-/pluginutils-4.2.1.tgz", + "integrity": "sha512-iKnFXr7NkdZAIHiIWE+BX5ULi/ucVFYWD6TbAV+rZctiRTY2PL6tsIKhoIOaoskiWAkgu+VsbXgUVDNLHf+InQ==", + "dev": true, + "requires": { + "estree-walker": "^2.0.1", + "picomatch": "^2.2.2" + } + }, + "magic-string": { + "version": "0.26.2", + "resolved": "https://registry.npmjs.org/magic-string/-/magic-string-0.26.2.tgz", + "integrity": "sha512-NzzlXpclt5zAbmo6h6jNc8zl2gNRGHvmsZW4IvZhTC4W7k4OlLP+S5YLussa/r3ixNT66KOQfNORlXHSOy/X4A==", + "dev": true, + "requires": { + "sourcemap-codec": "^1.4.8" + } + } } }, "@types/estree": { @@ -1511,9 +1500,9 @@ "dev": true }, "bun-types": { - "version": "0.1.2", - "resolved": "https://registry.npmjs.org/bun-types/-/bun-types-0.1.2.tgz", - "integrity": "sha512-7R0rl/rvVVsw5DSywjjI3u1Ai2RM2TPnUbMPwfoVr1R3pt/92E4jZD7ZqQIn25ZKucD6z5nVyux4pfXU4hcJnw==", + "version": "0.1.3", + "resolved": "https://registry.npmjs.org/bun-types/-/bun-types-0.1.3.tgz", + "integrity": "sha512-mbqjiQNw5O0Id0KT5Oar1VgeK5tLoNA7KBLc8KFz1EbjU3jUjdlbQWKz39K4Ea0T68Orsg/B6EWP30W+M+VANw==", "dev": true }, "chokidar": { @@ -1575,38 +1564,38 @@ } }, "esbuild": { - "version": "0.14.48", - "resolved": "https://registry.npmjs.org/esbuild/-/esbuild-0.14.48.tgz", - "integrity": "sha512-w6N1Yn5MtqK2U1/WZTX9ZqUVb8IOLZkZ5AdHkT6x3cHDMVsYWC7WPdiLmx19w3i4Rwzy5LqsEMtVihG3e4rFzA==", + "version": "0.14.49", + "resolved": "https://registry.npmjs.org/esbuild/-/esbuild-0.14.49.tgz", + "integrity": "sha512-/TlVHhOaq7Yz8N1OJrjqM3Auzo5wjvHFLk+T8pIue+fhnhIMpfAzsG6PLVMbFveVxqD2WOp3QHei+52IMUNmCw==", "dev": true, "peer": true, "requires": { - "esbuild-android-64": "0.14.48", - "esbuild-android-arm64": "0.14.48", - "esbuild-darwin-64": "0.14.48", - "esbuild-darwin-arm64": "0.14.48", - "esbuild-freebsd-64": "0.14.48", - "esbuild-freebsd-arm64": "0.14.48", - "esbuild-linux-32": "0.14.48", - "esbuild-linux-64": "0.14.48", - "esbuild-linux-arm": "0.14.48", - "esbuild-linux-arm64": "0.14.48", - "esbuild-linux-mips64le": "0.14.48", - "esbuild-linux-ppc64le": "0.14.48", - "esbuild-linux-riscv64": "0.14.48", - "esbuild-linux-s390x": "0.14.48", - "esbuild-netbsd-64": "0.14.48", - "esbuild-openbsd-64": "0.14.48", - "esbuild-sunos-64": "0.14.48", - "esbuild-windows-32": "0.14.48", - "esbuild-windows-64": "0.14.48", - "esbuild-windows-arm64": "0.14.48" + "esbuild-android-64": "0.14.49", + "esbuild-android-arm64": "0.14.49", + "esbuild-darwin-64": "0.14.49", + "esbuild-darwin-arm64": "0.14.49", + "esbuild-freebsd-64": "0.14.49", + "esbuild-freebsd-arm64": "0.14.49", + "esbuild-linux-32": "0.14.49", + "esbuild-linux-64": "0.14.49", + "esbuild-linux-arm": "0.14.49", + "esbuild-linux-arm64": "0.14.49", + "esbuild-linux-mips64le": "0.14.49", + "esbuild-linux-ppc64le": "0.14.49", + "esbuild-linux-riscv64": "0.14.49", + "esbuild-linux-s390x": "0.14.49", + "esbuild-netbsd-64": "0.14.49", + "esbuild-openbsd-64": "0.14.49", + "esbuild-sunos-64": "0.14.49", + "esbuild-windows-32": "0.14.49", + "esbuild-windows-64": "0.14.49", + "esbuild-windows-arm64": "0.14.49" } }, "esbuild-windows-64": { - "version": "0.14.48", - "resolved": "https://registry.npmjs.org/esbuild-windows-64/-/esbuild-windows-64-0.14.48.tgz", - "integrity": "sha512-YmpXjdT1q0b8ictSdGwH3M8VCoqPpK1/UArze3X199w6u8hUx3V8BhAi1WjbsfDYRBanVVtduAhh2sirImtAvA==", + "version": "0.14.49", + "resolved": "https://registry.npmjs.org/esbuild-windows-64/-/esbuild-windows-64-0.14.49.tgz", + "integrity": "sha512-+Cme7Ongv0UIUTniPqfTX6mJ8Deo7VXw9xN0yJEN1lQMHDppTNmKwAM3oGbD/Vqff+07K2gN0WfNkMohmG+dVw==", "dev": true, "optional": true, "peer": true @@ -1826,6 +1815,17 @@ "@types/estree": "*" } }, + "js-cleanup": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/js-cleanup/-/js-cleanup-1.2.0.tgz", + "integrity": "sha512-JeDD0yiiSt80fXzAVa/crrS0JDPQljyBG/RpOtaSbyDq03VHa9szJWMaWOYU/bcTn412uMN2MxApXq8v79cUiQ==", + "dev": true, + "requires": { + "magic-string": "^0.25.7", + "perf-regexes": "^1.0.1", + "skip-regex": "^1.0.2" + } + }, "jsonfile": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/jsonfile/-/jsonfile-4.0.0.tgz", @@ -1842,9 +1842,9 @@ "dev": true }, "magic-string": { - "version": "0.26.2", - "resolved": "https://registry.npmjs.org/magic-string/-/magic-string-0.26.2.tgz", - "integrity": "sha512-NzzlXpclt5zAbmo6h6jNc8zl2gNRGHvmsZW4IvZhTC4W7k4OlLP+S5YLussa/r3ixNT66KOQfNORlXHSOy/X4A==", + "version": "0.25.9", + "resolved": "https://registry.npmjs.org/magic-string/-/magic-string-0.25.9.tgz", + "integrity": "sha512-RmF0AsMzgt25qzqqLc1+MbHmhdx0ojF2Fvs4XnOqz2ZOBXzzkEwc/dJQZCYHAn7v1jbVOjAZfK8msRn4BxO4VQ==", "dev": true, "requires": { "sourcemap-codec": "^1.4.8" @@ -1933,6 +1933,12 @@ "integrity": "sha512-gDKb8aZMDeD/tZWs9P6+q0J9Mwkdl6xMV8TjnGP3qJVJ06bdMgkbBlLU8IdfOsIsFz2BW1rNVT3XuNEl8zPAvw==", "dev": true }, + "perf-regexes": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/perf-regexes/-/perf-regexes-1.0.1.tgz", + "integrity": "sha512-L7MXxUDtqr4PUaLFCDCXBfGV/6KLIuSEccizDI7JxT+c9x1G1v04BQ4+4oag84SHaCdrBgQAIs/Cqn+flwFPng==", + "dev": true + }, "picocolors": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/picocolors/-/picocolors-1.0.0.tgz", @@ -2008,6 +2014,16 @@ "fsevents": "~2.3.2" } }, + "rollup-plugin-cleanup": { + "version": "3.2.1", + "resolved": "https://registry.npmjs.org/rollup-plugin-cleanup/-/rollup-plugin-cleanup-3.2.1.tgz", + "integrity": "sha512-zuv8EhoO3TpnrU8MX8W7YxSbO4gmOR0ny06Lm3nkFfq0IVKdBUtHwhVzY1OAJyNCIAdLiyPnOrU0KnO0Fri1GQ==", + "dev": true, + "requires": { + "js-cleanup": "^1.2.0", + "rollup-pluginutils": "^2.8.2" + } + }, "rollup-plugin-copy": { "version": "3.4.0", "resolved": "https://registry.npmjs.org/rollup-plugin-copy/-/rollup-plugin-copy-3.4.0.tgz", @@ -2021,6 +2037,23 @@ "is-plain-object": "^3.0.0" } }, + "rollup-pluginutils": { + "version": "2.8.2", + "resolved": "https://registry.npmjs.org/rollup-pluginutils/-/rollup-pluginutils-2.8.2.tgz", + "integrity": "sha512-EEp9NhnUkwY8aif6bxgovPHMoMoNr2FulJziTndpt5H9RdwC47GSGuII9XxpSdzVGM0GWrNPHV6ie1LTNJPaLQ==", + "dev": true, + "requires": { + "estree-walker": "^0.6.1" + }, + "dependencies": { + "estree-walker": { + "version": "0.6.1", + "resolved": "https://registry.npmjs.org/estree-walker/-/estree-walker-0.6.1.tgz", + "integrity": "sha512-SqmZANLWS0mnatqbSfRP5g8OXZC12Fgg1IwNtLsyHDzJizORW4khDfjPqJZsemPWBB2uqykUah5YpQ6epsqC/w==", + "dev": true + } + } + }, "run-parallel": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/run-parallel/-/run-parallel-1.2.0.tgz", @@ -2039,6 +2072,12 @@ "mri": "^1.1.0" } }, + "skip-regex": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/skip-regex/-/skip-regex-1.0.2.tgz", + "integrity": "sha512-pEjMUbwJ5Pl/6Vn6FsamXHXItJXSRftcibixDmNCWbWhic0hzHrwkMZo0IZ7fMRH9KxcWDFSkzhccB4285PutA==", + "dev": true + }, "slash": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/slash/-/slash-3.0.0.tgz", @@ -2102,6 +2141,11 @@ "integrity": "sha512-eM+pCBxXO/njtF7vdFsHuqb+ElbxqtI4r5EAvk6grfAFyJ6IvWlSkfZ5T9ozC6xWw3Fj1fGoSmrl0gUs46JVIw==", "dev": true }, + "undici": { + "version": "https://registry.npmjs.org/undici/-/undici-5.7.0.tgz", + "integrity": "sha512-ORgxwDkiPS+gK2VxE7iyVeR7JliVn5DqhZ4LgQqYLBXsuK+lwOEmnJ66dhvlpLM0tC3fC7eYF1Bti2frbw2eAA==", + "dev": true + }, "universalify": { "version": "0.1.2", "resolved": "https://registry.npmjs.org/universalify/-/universalify-0.1.2.tgz", diff --git a/package.json b/package.json index 6ac7e5b..efead81 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "svelte-adapter-bun", - "version": "0.2.2-2", + "version": "0.2.2-3", "description": "Adapter for SvelteKit apps that generates a standalone Bun.js server.", "main": "index.js", "types": "index.d.ts", @@ -40,15 +40,16 @@ "@rollup/plugin-commonjs": "^22.0.1", "@rollup/plugin-json": "^4.1.0", "@rollup/plugin-node-resolve": "^13.3.0", - "@sveltejs/kit": "^1.0.0-next.367", - "bun-types": "^0.1.2", + "@sveltejs/kit": "next", + "bun-types": "latest", "mrmime": "^1.0.1", "rimraf": "^3.0.2", "rollup": "^2.76.0", + "rollup-plugin-cleanup": "^3.2.1", "rollup-plugin-copy": "^3.4.0", "totalist": "^3.0.0" }, "dependencies": { "tiny-glob": "^0.2.9" } -} \ No newline at end of file +} diff --git a/rollup.config.js b/rollup.config.js index 3d1bb55..8ca4439 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -2,7 +2,7 @@ import { nodeResolve } from '@rollup/plugin-node-resolve'; import commonjs from '@rollup/plugin-commonjs'; import json from '@rollup/plugin-json'; import copy from 'rollup-plugin-copy'; - +import cleanup from 'rollup-plugin-cleanup'; export default [{ input: { @@ -23,7 +23,8 @@ export default [{ targets: [ { src: "src/.env.example", dest: "files/" } ] - }) + }), + cleanup() ], external: ['bun', 'SERVER', 'MANIFEST', ...require('module').builtinModules] }] \ No newline at end of file diff --git a/src/handler.js b/src/handler.js index 4459520..38e1f91 100644 --- a/src/handler.js +++ b/src/handler.js @@ -37,9 +37,7 @@ export default function (assets) { if (i < handlers.length) { return handle(i + 1) } else { - return Response(404, { - status: 404 - }) + return new Response(404, { status: 404 }) } }); } @@ -54,13 +52,14 @@ function serve(path, client = false) { brotli: true, setHeaders: client && ((headers, pathname) => { if (pathname.startsWith(`/${manifest.appDir}/immutable/`)) { - headers.set('cache-control', 'public,max-age=31536000,immutable') - return headers + headers.set('cache-control', 'public,max-age=31536000,immutable'); } + return headers }) }) } +/**@param {Request} req */ function ssr(req) { let request = req; if (build_options.dynamic_origin ?? false) { diff --git a/src/sirv.js b/src/sirv.js index f58cdc7..e7b9177 100644 --- a/src/sirv.js +++ b/src/sirv.js @@ -5,11 +5,11 @@ import { mimes, lookup as getExt } from "mrmime"; import { totalist } from "totalist/sync"; import exmimes from "./mime.conf"; -function isMatch(uri, arr) { - for (let i = 0; i < arr.length; i++) { - if (arr[i].test(uri)) return true; - } -} +// function isMatch(uri, arr) { +// for (let i = 0; i < arr.length; i++) { +// if (arr[i].test(uri)) return true; +// } +// } function toAssume(uri, extns) { let i = 0, x, len = uri.length - 1; @@ -60,44 +60,46 @@ function is404(req) { * @param {Request} req * @param {import('../sirv').SirvData} data */ -function send(req, data) {//file, stats, headers) { - let code = 200 - // , opts = {}; - - - // if (req.headers.has("range")) { - // code = 206; - // let [x, y] = req.headers.get("range").replace('bytes=', '').split('-'); - // let end = opts.end = parseInt(y, 10) || stats.size - 1; - // let start = opts.start = parseInt(x, 10) || 0; - - // if (start >= stats.size || end >= stats.size) { - // headers.set('Content-Range', `bytes */${stats.size}`); - // return new Response(null, { - // headers, - // status: 416 - // }) - // } - - // headers.set('Content-Range', `bytes ${start}-${end}/${stats.size}`); - // headers.set('Content-Length', (end - start + 1)); - // headers.set('Accept-Ranges', 'bytes'); - // } +function send(req, data) { + let code = 200, opts = {}; + + + if (req.headers.has("range")) { + code = 206; + let [x, y] = req.headers.get("range").replace('bytes=', '').split('-'); + let end = opts.end = parseInt(y, 10) || data.stats.size - 1; + let start = opts.start = parseInt(x, 10) || 0; + + if (start >= data.stats.size || end >= data.stats.size) { + data.headers.set('Content-Range', `bytes */${data.stats.size}`); + return new Response(null, { + headers: data.headers, + status: 416 + }) + } + + data.headers.set('Content-Range', `bytes ${start}-${end}/${data.stats.size}`); + data.headers.set('Content-Length', (end - start + 1)); + data.headers.set('Accept-Ranges', 'bytes'); + opts.range = true + } + + if (opts.range) { + return new Promise((rs) => { + // https://github.com/oven-sh/bun/issues/616 + Bun.file(data.abs).slice(opts.start, opts.end).arrayBuffer().then(arbf => { + return new Response(arbf, { + headers: data.headers, + status: code + }) + }).then(rs).catch(e => (console.error(e), rs(new Response(null, 500)))) + }) + } - // if (opts.start) { - // console.log("Readable string",opts) - // // let rsReadableStream = - // return new Response(Bun.readableStreamToBlob(fs.createReadStream(file, opts)), { - // headers, - // status: code - // }) - // } else { return new Response(Bun.file(data.abs), { headers: data.headers, status: code }) - // } - } const ENCODING = { @@ -152,14 +154,14 @@ export default function (dir, opts = {}) { /** @type {import('../sirv').SirvFiles} */ const FILES = {}; - let fallback = '/'; + // let fallback = '/'; let isEtag = !!opts.etag; - let isSPA = !!opts.single; + // let isSPA = !!opts.single; - if (typeof opts.single === 'string') { - let idx = opts.single.lastIndexOf('.'); - fallback += !!~idx ? opts.single.substring(0, idx) : opts.single; - } + // if (typeof opts.single === 'string') { + // let idx = opts.single.lastIndexOf('.'); + // fallback += !!~idx ? opts.single.substring(0, idx) : opts.single; + // } let ignores = []; if (opts.ignores !== false) { @@ -216,7 +218,8 @@ export default function (dir, opts = {}) { // tmp = lookup(fallback, extns) // } // } - let data = lookup(pathname, extns) || isSPA && !isMatch(pathname, ignores) && lookup(fallback, extns); + let data = lookup(pathname, extns) + // || isSPA && !isMatch(pathname, ignores) && lookup(fallback, extns); if (!data) return next ? next() : isNotFound(req);