From a445fae6f49f1cf84f4da41399e122d861d85f64 Mon Sep 17 00:00:00 2001 From: Keigo Nakao <54620036+kspace-trk@users.noreply.github.com> Date: Sun, 10 Mar 2024 08:03:22 +0900 Subject: [PATCH 1/3] docs: fix typo --- docs/1.guide/9.plugins.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/1.guide/9.plugins.md b/docs/1.guide/9.plugins.md index 67f073d695..fe5462ff26 100644 --- a/docs/1.guide/9.plugins.md +++ b/docs/1.guide/9.plugins.md @@ -40,7 +40,7 @@ export default defineNuxtConfig({ ## Nitro runtime hooks -You can use Nitro [hooks]("https://github.com/unjs/hookable) to extend the default runtime behaviour of Nitro by registering custom (async or asnc) functions to the lifecycle events within plugins. +You can use Nitro [hooks](https://github.com/unjs/hookable) to extend the default runtime behaviour of Nitro by registering custom (async or asnc) functions to the lifecycle events within plugins. **Example:** From 52b65c7e96b6dd946a5fe36ba2e75387db32dd38 Mon Sep 17 00:00:00 2001 From: Pooya Parsa Date: Sun, 10 Mar 2024 11:12:43 +0100 Subject: [PATCH 2/3] fix(raw): use mime to chck binary types and exclude `.json` (#2239) --- src/rollup/plugins/raw.ts | 18 ++++++++++++------ test/fixture/assets/test.json | 3 +++ test/fixture/routes/assets/all.ts | 25 +++++++++++++++++++++++++ 3 files changed, 40 insertions(+), 6 deletions(-) create mode 100644 test/fixture/assets/test.json create mode 100644 test/fixture/routes/assets/all.ts diff --git a/src/rollup/plugins/raw.ts b/src/rollup/plugins/raw.ts index e32c90ef01..778f4f9015 100644 --- a/src/rollup/plugins/raw.ts +++ b/src/rollup/plugins/raw.ts @@ -1,5 +1,6 @@ import { promises as fsp } from "node:fs"; import { extname } from "pathe"; +import mime from "mime"; import type { Plugin } from "rollup"; export interface RawOptions { @@ -18,15 +19,9 @@ export function raw(opts: RawOptions = {}): Plugin { ".css", ".htm", ".html", - ".json", - ".json5", - ".csv", ...(opts.extensions || []), ]); - // TODO: use ext=>mime - const isBinary = (id) => !extensions.has(extname(id)); - return { name: "raw", resolveId(id) { @@ -79,6 +74,17 @@ export function raw(opts: RawOptions = {}): Plugin { }; } +function isBinary(id: string) { + const idMime = mime.getType(id) || ""; + if (idMime.startsWith("text/")) { + return false; + } + if (/application\/(json|xml|yaml)/.test(idMime)) { + return false; + } + return true; +} + function getHelpers() { const js = String.raw; return js` diff --git a/test/fixture/assets/test.json b/test/fixture/assets/test.json new file mode 100644 index 0000000000..c8c4105eb5 --- /dev/null +++ b/test/fixture/assets/test.json @@ -0,0 +1,3 @@ +{ + "foo": "bar" +} diff --git a/test/fixture/routes/assets/all.ts b/test/fixture/routes/assets/all.ts new file mode 100644 index 0000000000..58b16b9843 --- /dev/null +++ b/test/fixture/routes/assets/all.ts @@ -0,0 +1,25 @@ +export default eventHandler(async (event) => { + const serverAssets = useStorage("assets/server"); + + const keys = await serverAssets.getKeys(); + const items = await Promise.all( + keys.map(async (key) => { + return { + key, + meta: await serverAssets.getMeta(key), + data: await serverAssets.getItem(key).then((r) => + // prettier-ignore + typeof r === "string" ? r.slice(0, 32) : (isPureObject(r) ? r : ``) + ), + }; + }) + ); + + return items; +}); + +function isPureObject(value) { + return ( + value !== null && typeof value === "object" && value.constructor === Object + ); +} From 7e13a51fe6cf005109fd5ab60015cb1b38380be9 Mon Sep 17 00:00:00 2001 From: Pooya Parsa Date: Sun, 10 Mar 2024 11:15:12 +0100 Subject: [PATCH 3/3] chore(release): v2.9.3 --- CHANGELOG.md | 17 +++++++++++++++++ package.json | 2 +- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3472853177..5f79572e23 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,23 @@ All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines. +## v2.9.3 + +[compare changes](https://github.com/unjs/nitro/compare/v2.9.2...v2.9.3) + +### 🩹 Fixes + +- **raw:** Use mime to chck binary types and exclude `.json` ([#2239](https://github.com/unjs/nitro/pull/2239)) + +### 📖 Documentation + +- Fix typo ([a445fae6](https://github.com/unjs/nitro/commit/a445fae6)) + +### ❤️ Contributors + +- Pooya Parsa +- Keigo Nakao ([@kspace-trk](http://github.com/kspace-trk)) + ## v2.9.2 [compare changes](https://github.com/unjs/nitro/compare/v2.9.1...v2.9.2) diff --git a/package.json b/package.json index 673d484d5d..ae55a83548 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "nitropack", - "version": "2.9.2", + "version": "2.9.3", "description": "Build and Deploy Universal JavaScript Servers", "repository": "unjs/nitro", "license": "MIT",