Skip to content

Commit

Permalink
refactor: upgrade to ohash v2 (#3114)
Browse files Browse the repository at this point in the history
  • Loading branch information
pi0 authored Feb 21, 2025
1 parent a7feefa commit f7e0e88
Show file tree
Hide file tree
Showing 7 changed files with 307 additions and 11 deletions.
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@
"@types/http-proxy": "^1.17.16",
"@vercel/nft": "^0.29.2",
"archiver": "^7.0.1",
"c12": "^2.0.2",
"c12": "^2.0.4",
"chokidar": "^4.0.3",
"citty": "^0.1.6",
"compatx": "^0.1.8",
Expand Down Expand Up @@ -142,7 +142,7 @@
"node-fetch-native": "^1.6.6",
"node-mock-http": "^1.0.0",
"ofetch": "^1.4.1",
"ohash": "^1.1.4",
"ohash": "^2.0.4",
"openapi-typescript": "^7.6.1",
"pathe": "^2.0.3",
"perfect-debounce": "^1.0.0",
Expand Down Expand Up @@ -199,6 +199,7 @@
"firebase-functions": "^4.9.0",
"get-port-please": "^3.1.2",
"miniflare": "^3.20250214.0",
"ohash-v1": "npm:ohash@^1.1.4",
"prettier": "^3.5.1",
"typescript": "^5.7.3",
"unbuild": "^3.3.1",
Expand Down
55 changes: 51 additions & 4 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions src/rollup/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -370,11 +370,13 @@ export const getRollupConfig = (nitro: Nitro): RollupConfig => {
{
"#nitro-internal-virtual/plugins": `
${nitroPlugins
.map((plugin) => `import _${hash(plugin)} from '${plugin}';`)
.map(
(plugin) => `import _${hash(plugin).replace(/-/g, "")} from '${plugin}';`
)
.join("\n")}
export const plugins = [
${nitroPlugins.map((plugin) => `_${hash(plugin)}`).join(",\n")}
${nitroPlugins.map((plugin) => `_${hash(plugin).replace(/-/g, "")}`).join(",\n")}
]
`,
},
Expand Down
2 changes: 1 addition & 1 deletion src/rollup/plugins/handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ function unique(arr: any[]) {
}

function getImportId(p: string, lazy?: boolean) {
return (lazy ? "_lazy_" : "_") + hash(p).slice(0, 6);
return (lazy ? "_lazy_" : "_") + hash(p).replace(/-/g, "").slice(0, 6);
}

const WILDCARD_PATH_RE = /\/\*\*.*$/;
Expand Down
4 changes: 2 additions & 2 deletions src/runtime/internal/cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ import type {
NitroFetchRequest,
ResponseCacheEntry,
} from "nitropack/types";
import { hash } from "ohash";
import { parseURL } from "ufo";
import { useNitroApp } from "./app";
import { useStorage } from "./storage";
import { hash } from "./hash";
import type { TransactionOptions } from "unstorage";

function defaultCacheOptions() {
Expand Down Expand Up @@ -185,7 +185,7 @@ export function cachedFunction<T, ArgsT extends unknown[] = any[]>(
}

function getKey(...args: unknown[]) {
return args.length > 0 ? hash(args, {}) : "";
return args.length > 0 ? hash(args) : "";
}

function escapeKey(key: string | string[]) {
Expand Down
Loading

0 comments on commit f7e0e88

Please sign in to comment.