Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into fix/expose-grrfp
Browse files Browse the repository at this point in the history
  • Loading branch information
danielroe committed Mar 10, 2024
2 parents ce25779 + 7e13a51 commit 35331f1
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 8 deletions.
17 changes: 17 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <[email protected]>
- 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)
Expand Down
2 changes: 1 addition & 1 deletion docs/1.guide/9.plugins.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:**

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
18 changes: 12 additions & 6 deletions src/rollup/plugins/raw.ts
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -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) {
Expand Down Expand Up @@ -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`
Expand Down
3 changes: 3 additions & 0 deletions test/fixture/assets/test.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"foo": "bar"
}
25 changes: 25 additions & 0 deletions test/fixture/routes/assets/all.ts
Original file line number Diff line number Diff line change
@@ -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 : `<data>`)
),
};
})
);

return items;
});

function isPureObject(value) {
return (
value !== null && typeof value === "object" && value.constructor === Object
);
}

0 comments on commit 35331f1

Please sign in to comment.