From f709e5730bbbdb05128b88aff1b1aca2aec0568a Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Mon, 24 Feb 2025 23:21:48 +0000 Subject: [PATCH] chore(deps): update dependency ohash to v2 (3.x) (#31051) --- package.json | 1 - packages/kit/package.json | 2 +- packages/nuxt/package.json | 2 +- .../nuxt/src/app/components/nuxt-island.ts | 2 +- packages/nuxt/src/app/composables/cookie.ts | 8 ++--- packages/nuxt/src/core/cache.ts | 8 ++--- .../nuxt/src/core/plugins/composable-keys.ts | 2 +- packages/nuxt/src/core/plugins/prehydrate.ts | 2 +- packages/nuxt/src/core/templates.ts | 4 +-- packages/nuxt/test/composable-keys.test.ts | 2 +- packages/nuxt/test/page-metadata.test.ts | 20 +++++------ packages/nuxt/test/prehydrate.test.ts | 2 +- packages/rspack/package.json | 2 +- packages/vite/package.json | 2 +- packages/webpack/package.json | 2 +- pnpm-lock.yaml | 34 +++++++++++-------- test/bundle.test.ts | 2 +- 17 files changed, 50 insertions(+), 47 deletions(-) diff --git a/package.json b/package.json index d0fd014c06..b962d011ff 100644 --- a/package.json +++ b/package.json @@ -57,7 +57,6 @@ "magic-string": "^0.30.17", "memfs": "4.14.1", "nuxt": "workspace:*", - "ohash": "1.1.4", "postcss": "8.5.3", "rollup": "4.34.8", "send": ">=1.1.0", diff --git a/packages/kit/package.json b/packages/kit/package.json index ddec72e9c0..06df98498d 100644 --- a/packages/kit/package.json +++ b/packages/kit/package.json @@ -37,7 +37,7 @@ "klona": "^2.0.6", "knitwork": "^1.2.0", "mlly": "^1.7.4", - "ohash": "^1.1.4", + "ohash": "^2.0.4", "pathe": "^2.0.3", "pkg-types": "^1.3.1", "scule": "^1.3.0", diff --git a/packages/nuxt/package.json b/packages/nuxt/package.json index b2f25c1b98..e6f3a904d7 100644 --- a/packages/nuxt/package.json +++ b/packages/nuxt/package.json @@ -108,7 +108,7 @@ "nitropack": "^2.10.4", "nypm": "^0.5.4", "ofetch": "^1.4.1", - "ohash": "^1.1.4", + "ohash": "^2.0.4", "on-change": "^5.0.1", "pathe": "^2.0.3", "perfect-debounce": "^1.0.0", diff --git a/packages/nuxt/src/app/components/nuxt-island.ts b/packages/nuxt/src/app/components/nuxt-island.ts index 18b1b99433..cd3d9cbac5 100644 --- a/packages/nuxt/src/app/components/nuxt-island.ts +++ b/packages/nuxt/src/app/components/nuxt-island.ts @@ -86,7 +86,7 @@ export default defineComponent({ const config = useRuntimeConfig() const nuxtApp = useNuxtApp() const filteredProps = computed(() => props.props ? Object.fromEntries(Object.entries(props.props).filter(([key]) => !key.startsWith('data-v-'))) : {}) - const hashId = computed(() => hash([props.name, filteredProps.value, props.context, props.source])) + const hashId = computed(() => hash([props.name, filteredProps.value, props.context, props.source]).replace(/[-_]/g, '')) const instance = getCurrentInstance()! const event = useRequestEvent() diff --git a/packages/nuxt/src/app/composables/cookie.ts b/packages/nuxt/src/app/composables/cookie.ts index 47a9299673..913b8b87e9 100644 --- a/packages/nuxt/src/app/composables/cookie.ts +++ b/packages/nuxt/src/app/composables/cookie.ts @@ -5,7 +5,7 @@ import { parse, serialize } from 'cookie-es' import { deleteCookie, getCookie, getRequestHeader, setCookie } from 'h3' import type { H3Event } from 'h3' import destr from 'destr' -import { isEqual } from 'ohash' +import { hash } from 'ohash' import { klona } from 'klona' import { useNuxtApp } from '../nuxt' import { useRequestEvent } from './ssr' @@ -75,7 +75,7 @@ export function useCookie (name: string, _opts?: // or running in an iframe: see https://github.com/nuxt/nuxt/issues/26338 } const callback = () => { - if (opts.readonly || isEqual(cookie.value, cookies[name])) { return } + if (opts.readonly || hash(cookie.value) === hash(cookies[name])) { return } writeClientCookie(name, cookie.value, opts as CookieSerializeOptions) cookies[name] = klona(cookie.value) @@ -136,11 +136,11 @@ export function useCookie (name: string, _opts?: } else if (import.meta.server) { const nuxtApp = useNuxtApp() const writeFinalCookieValue = () => { - if (opts.readonly || isEqual(cookie.value, cookies[name])) { return } + if (opts.readonly || hash(cookie.value) === hash(cookies[name])) { return } nuxtApp._cookies ||= {} if (name in nuxtApp._cookies) { // do not append a second `set-cookie` header - if (isEqual(cookie.value, nuxtApp._cookies[name])) { return } + if (hash(cookie.value) === hash(nuxtApp._cookies[name])) { return } // warn in dev mode if (import.meta.dev) { console.warn(`[nuxt] cookie \`${name}\` was previously set to \`${opts.encode(nuxtApp._cookies[name] as any)}\` and is being overridden to \`${opts.encode(cookie.value as any)}\`. This may cause unexpected issues.`) diff --git a/packages/nuxt/src/core/cache.ts b/packages/nuxt/src/core/cache.ts index 5c24dab590..8dfb110efb 100644 --- a/packages/nuxt/src/core/cache.ts +++ b/packages/nuxt/src/core/cache.ts @@ -4,7 +4,7 @@ import { resolve } from 'node:path' import { existsSync } from 'node:fs' import { createIsIgnored } from '@nuxt/kit' import type { Nuxt, NuxtConfig, NuxtConfigLayer } from '@nuxt/schema' -import { hash, murmurHash, objectHash } from 'ohash' +import { hash, serialize } from 'ohash' import { glob } from 'tinyglobby' import { consola } from 'consola' import { dirname, join, relative } from 'pathe' @@ -107,7 +107,7 @@ async function getHashes (nuxt: Nuxt, options: GetHashOptions): Promise const layerName = `layer#${layerCtr++}` hashSources.push({ name: `${layerName}:config`, - data: objectHash({ + data: serialize({ ...layer.config, ...options.configOverrides || {}, }), @@ -115,8 +115,8 @@ async function getHashes (nuxt: Nuxt, options: GetHashOptions): Promise const normalizeFiles = (files: Awaited>) => files.map(f => ({ name: f.name, - size: (f.attrs as any)?.size, - data: murmurHash(f.data as any /* ArrayBuffer */), + size: f.attrs?.size, + data: hash(f.data), })) const isIgnored = createIsIgnored(nuxt) diff --git a/packages/nuxt/src/core/plugins/composable-keys.ts b/packages/nuxt/src/core/plugins/composable-keys.ts index df099bef40..7b7ac8d0d0 100644 --- a/packages/nuxt/src/core/plugins/composable-keys.ts +++ b/packages/nuxt/src/core/plugins/composable-keys.ts @@ -108,7 +108,7 @@ export const ComposableKeysPlugin = (options: ComposableKeysOptions) => createUn s.appendLeft( codeIndex + (node as any).end - 1, - (node.arguments.length && !endsWithComma ? ', ' : '') + '\'$' + hash(`${relativeID}-${++count}`) + '\'', + (node.arguments.length && !endsWithComma ? ', ' : '') + '\'$' + hash(`${relativeID}-${++count}`).slice(0, 10) + '\'', ) }, }) diff --git a/packages/nuxt/src/core/plugins/prehydrate.ts b/packages/nuxt/src/core/plugins/prehydrate.ts index 24bc2e2407..bfe419442c 100644 --- a/packages/nuxt/src/core/plugins/prehydrate.ts +++ b/packages/nuxt/src/core/plugins/prehydrate.ts @@ -33,7 +33,7 @@ export function PrehydrateTransformPlugin (options: { sourcemap?: boolean } = {} const cleaned = result.slice('forEach'.length).replace(/;\s+$/, '') const args = [JSON.stringify(cleaned)] if (needsAttr) { - args.push(JSON.stringify(hash(result))) + args.push(JSON.stringify(hash(result).slice(0, 10))) } s.overwrite(callback.start, callback.end, args.join(', ')) })) diff --git a/packages/nuxt/src/core/templates.ts b/packages/nuxt/src/core/templates.ts index 15da3975cd..ca31933a8c 100644 --- a/packages/nuxt/src/core/templates.ts +++ b/packages/nuxt/src/core/templates.ts @@ -68,7 +68,7 @@ export const clientPluginTemplate: NuxtTemplate = { const imports: string[] = [] for (const plugin of clientPlugins) { const path = relative(ctx.nuxt.options.rootDir, plugin.src) - const variable = genSafeVariableName(filename(plugin.src) || path).replace(PLUGIN_TEMPLATE_RE, '_') + '_' + hash(path) + const variable = genSafeVariableName(filename(plugin.src) || path).replace(PLUGIN_TEMPLATE_RE, '_') + '_' + hash(path).replace(/-/g, '_') exports.push(variable) imports.push(genImport(plugin.src, variable)) } @@ -88,7 +88,7 @@ export const serverPluginTemplate: NuxtTemplate = { const imports: string[] = [] for (const plugin of serverPlugins) { const path = relative(ctx.nuxt.options.rootDir, plugin.src) - const variable = genSafeVariableName(filename(plugin.src) || path).replace(PLUGIN_TEMPLATE_RE, '_') + '_' + hash(path) + const variable = genSafeVariableName(filename(plugin.src) || path).replace(PLUGIN_TEMPLATE_RE, '_') + '_' + hash(path).replace(/-/g, '_') exports.push(variable) imports.push(genImport(plugin.src, variable)) } diff --git a/packages/nuxt/test/composable-keys.test.ts b/packages/nuxt/test/composable-keys.test.ts index 38893a0bab..13bbcbed96 100644 --- a/packages/nuxt/test/composable-keys.test.ts +++ b/packages/nuxt/test/composable-keys.test.ts @@ -49,7 +49,7 @@ useAsyncData(() => {}) }), }, code, 'plugin.ts')?.code.trim()).toMatchInlineSnapshot(` "import { useAsyncData } from '#app' - useAsyncData(() => {}, '$yXewDLZblH')" + useAsyncData(() => {}, '$HJiaryoL2y')" `) }) diff --git a/packages/nuxt/test/page-metadata.test.ts b/packages/nuxt/test/page-metadata.test.ts index 61010a42c8..33c94adbea 100644 --- a/packages/nuxt/test/page-metadata.test.ts +++ b/packages/nuxt/test/page-metadata.test.ts @@ -280,13 +280,13 @@ describe('normalizeRoutes', () => { expect({ routes, imports }).toMatchInlineSnapshot(` { "imports": Set { - "import { default as indexN6pT4Un8hYMeta } from "/app/pages/index.vue?macro=true";", + "import { default as indexndqPXFtP262szLmLJV4PriPTgAg5k_457f05QyTfosBXQMeta } from "/app/pages/index.vue?macro=true";", }, "routes": "[ { name: "some-custom-name", - path: indexN6pT4Un8hYMeta?.path ?? "/", - meta: { ...(indexN6pT4Un8hYMeta || {}), ...{"layout":"test","foo":"bar"} }, + path: indexndqPXFtP262szLmLJV4PriPTgAg5k_457f05QyTfosBXQMeta?.path ?? "/", + meta: { ...(indexndqPXFtP262szLmLJV4PriPTgAg5k_457f05QyTfosBXQMeta || {}), ...{"layout":"test","foo":"bar"} }, redirect: "/", component: () => import("/app/pages/index.vue") } @@ -309,16 +309,16 @@ describe('normalizeRoutes', () => { expect({ routes, imports }).toMatchInlineSnapshot(` { "imports": Set { - "import { default as indexN6pT4Un8hYMeta } from "/app/pages/index.vue?macro=true";", + "import { default as indexndqPXFtP262szLmLJV4PriPTgAg5k_457f05QyTfosBXQMeta } from "/app/pages/index.vue?macro=true";", }, "routes": "[ { - name: indexN6pT4Un8hYMeta?.name ?? undefined, - path: indexN6pT4Un8hYMeta?.path ?? "/", - props: indexN6pT4Un8hYMeta?.props ?? false, - meta: { ...(indexN6pT4Un8hYMeta || {}), ...{"layout":"test","foo":"bar"} }, - alias: indexN6pT4Un8hYMeta?.alias || [], - redirect: indexN6pT4Un8hYMeta?.redirect, + name: indexndqPXFtP262szLmLJV4PriPTgAg5k_457f05QyTfosBXQMeta?.name ?? undefined, + path: indexndqPXFtP262szLmLJV4PriPTgAg5k_457f05QyTfosBXQMeta?.path ?? "/", + props: indexndqPXFtP262szLmLJV4PriPTgAg5k_457f05QyTfosBXQMeta?.props ?? false, + meta: { ...(indexndqPXFtP262szLmLJV4PriPTgAg5k_457f05QyTfosBXQMeta || {}), ...{"layout":"test","foo":"bar"} }, + alias: indexndqPXFtP262szLmLJV4PriPTgAg5k_457f05QyTfosBXQMeta?.alias || [], + redirect: indexndqPXFtP262szLmLJV4PriPTgAg5k_457f05QyTfosBXQMeta?.redirect, component: () => import("/app/pages/index.vue") } ]", diff --git a/packages/nuxt/test/prehydrate.test.ts b/packages/nuxt/test/prehydrate.test.ts index 664e988bb6..d73bdab30b 100644 --- a/packages/nuxt/test/prehydrate.test.ts +++ b/packages/nuxt/test/prehydrate.test.ts @@ -35,6 +35,6 @@ onPrehydrate((attr) => { ` const { code } = await transformPlugin.transform(snippet, 'test.ts') ?? {} - expect(code?.trim()).toMatchInlineSnapshot(`"onPrehydrate("(o=>{console.log(\\"hello world\\")})", "rifMBArY0d")"`) + expect(code?.trim()).toMatchInlineSnapshot(`"onPrehydrate("(o=>{console.log(\\"hello world\\")})", "mcDYwfgR1x")"`) }) }) diff --git a/packages/rspack/package.json b/packages/rspack/package.json index 6489bb1a3b..97614de244 100644 --- a/packages/rspack/package.json +++ b/packages/rspack/package.json @@ -48,7 +48,7 @@ "knitwork": "^1.2.0", "magic-string": "^0.30.17", "memfs": "^4.14.1", - "ohash": "^1.1.4", + "ohash": "^2.0.4", "pathe": "^2.0.3", "pify": "^6.1.0", "postcss": "^8.5.3", diff --git a/packages/vite/package.json b/packages/vite/package.json index 00a06b15df..ae5abb28df 100644 --- a/packages/vite/package.json +++ b/packages/vite/package.json @@ -48,7 +48,7 @@ "knitwork": "^1.2.0", "magic-string": "^0.30.17", "mlly": "^1.7.4", - "ohash": "^1.1.4", + "ohash": "^2.0.4", "pathe": "^2.0.3", "perfect-debounce": "^1.0.0", "pkg-types": "^1.3.1", diff --git a/packages/webpack/package.json b/packages/webpack/package.json index 23bcdc1cac..d801836aef 100644 --- a/packages/webpack/package.json +++ b/packages/webpack/package.json @@ -46,7 +46,7 @@ "magic-string": "^0.30.17", "memfs": "^4.14.1", "mini-css-extract-plugin": "^2.9.2", - "ohash": "^1.1.4", + "ohash": "^2.0.4", "pathe": "^2.0.3", "pify": "^6.1.0", "postcss": "^8.5.3", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 9f613eb905..688b06695c 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -25,7 +25,6 @@ overrides: magic-string: ^0.30.17 memfs: 4.14.1 nuxt: workspace:* - ohash: 1.1.4 postcss: 8.5.3 rollup: 4.34.8 send: '>=1.1.0' @@ -261,8 +260,8 @@ importers: specifier: ^1.7.4 version: 1.7.4 ohash: - specifier: 1.1.4 - version: 1.1.4 + specifier: ^2.0.4 + version: 2.0.4 pathe: specifier: ^2.0.3 version: 2.0.3 @@ -445,8 +444,8 @@ importers: specifier: ^1.4.1 version: 1.4.1 ohash: - specifier: 1.1.4 - version: 1.1.4 + specifier: ^2.0.4 + version: 2.0.4 on-change: specifier: ^5.0.1 version: 5.0.1 @@ -605,8 +604,8 @@ importers: specifier: 4.14.1 version: 4.14.1 ohash: - specifier: 1.1.4 - version: 1.1.4 + specifier: ^2.0.4 + version: 2.0.4 pathe: specifier: ^2.0.3 version: 2.0.3 @@ -925,8 +924,8 @@ importers: specifier: ^1.7.4 version: 1.7.4 ohash: - specifier: 1.1.4 - version: 1.1.4 + specifier: ^2.0.4 + version: 2.0.4 pathe: specifier: ^2.0.3 version: 2.0.3 @@ -959,7 +958,7 @@ importers: version: 6.1.1(@types/node@22.13.5)(jiti@2.4.2)(sass@1.78.0)(terser@5.37.0)(tsx@4.19.2)(yaml@2.7.0) vite-node: specifier: ^3.0.6 - version: 3.0.6(@types/node@22.13.5)(jiti@2.4.2)(terser@5.37.0)(tsx@4.19.2)(yaml@2.7.0) + version: 3.0.7(@types/node@22.13.5)(jiti@2.4.2)(sass@1.78.0)(terser@5.37.0)(tsx@4.19.2)(yaml@2.7.0) vite-plugin-checker: specifier: ^0.9.0 version: 0.9.0(eslint@9.21.0(jiti@2.4.2))(optionator@0.9.4)(typescript@5.7.3)(vite@6.1.1(@types/node@22.13.5)(jiti@2.4.2)(terser@5.37.0)(tsx@4.19.2)(yaml@2.7.0))(vue-tsc@2.2.4(typescript@5.7.3)) @@ -1031,8 +1030,8 @@ importers: specifier: ^2.9.2 version: 2.9.2(webpack@5.96.1) ohash: - specifier: 1.1.4 - version: 1.1.4 + specifier: ^2.0.4 + version: 2.0.4 pathe: specifier: ^2.0.3 version: 2.0.3 @@ -5881,6 +5880,9 @@ packages: ohash@1.1.4: resolution: {integrity: sha512-FlDryZAahJmEF3VR3w1KogSEdWX3WhA5GPakFx4J81kEAiHyLMpdLLElS8n8dfNadMgAne/MywcvmogzscVt4g==} + ohash@2.0.4: + resolution: {integrity: sha512-ac+SFwzhdHb0hp48/dbR7Jta39qfbuj7t3hApd9uyHS8bisHTfVzSEvjOVgV0L3zG7VR2/7JjkSGimP75D+hOQ==} + on-change@5.0.1: resolution: {integrity: sha512-n7THCP7RkyReRSLkJb8kUWoNsxUIBxTkIp3JKno+sEz6o/9AJ3w3P9fzQkITEkMwyTKJjZciF3v/pVoouxZZMg==} engines: {node: '>=18'} @@ -8698,7 +8700,7 @@ snapshots: listhen: 1.9.0 nypm: 0.5.4 ofetch: 1.4.1 - ohash: 1.1.4 + ohash: 2.0.4 pathe: 2.0.3 perfect-debounce: 1.0.0 pkg-types: 1.3.1 @@ -10618,7 +10620,7 @@ snapshots: giget: 1.2.4 jiti: 2.4.2 mlly: 1.7.4 - ohash: 1.1.4 + ohash: 2.0.4 pathe: 2.0.3 perfect-debounce: 1.0.0 pkg-types: 1.3.1 @@ -13481,6 +13483,8 @@ snapshots: ohash@1.1.4: {} + ohash@2.0.4: {} + on-change@5.0.1: {} on-finished@2.4.1: @@ -15384,7 +15388,7 @@ snapshots: dependencies: '@vitest/expect': 3.0.6 '@vitest/mocker': 3.0.6(vite@6.1.1(@types/node@22.13.5)(jiti@2.4.2)(terser@5.37.0)(tsx@4.19.2)(yaml@2.7.0)) - '@vitest/pretty-format': 3.0.6 + '@vitest/pretty-format': 3.0.7 '@vitest/runner': 3.0.6 '@vitest/snapshot': 3.0.6 '@vitest/spy': 3.0.6 diff --git a/test/bundle.test.ts b/test/bundle.test.ts index 5fab3908cf..00fb2bab38 100644 --- a/test/bundle.test.ts +++ b/test/bundle.test.ts @@ -79,7 +79,7 @@ describe.skipIf(process.env.SKIP_BUNDLE_SIZE === 'true' || process.env.ECOSYSTEM const serverDir = join(rootDir, '.output-inline/server') const serverStats = await analyzeSizes(['**/*.mjs', '!node_modules'], serverDir) - expect.soft(roundToKilobytes(serverStats.totalBytes)).toMatchInlineSnapshot(`"566k"`) + expect.soft(roundToKilobytes(serverStats.totalBytes)).toMatchInlineSnapshot(`"567k"`) const modules = await analyzeSizes(['node_modules/**/*'], serverDir) expect.soft(roundToKilobytes(modules.totalBytes)).toMatchInlineSnapshot(`"101k"`)