Skip to content

Commit

Permalink
refactor: use md5 instead of crc32 for version hash computing
Browse files Browse the repository at this point in the history
  • Loading branch information
Julien-R44 committed Jan 4, 2025
1 parent ffd0c06 commit c9459c4
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 4 deletions.
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@
"dependencies": {
"@poppinss/utils": "^6.9.2",
"@tuyau/utils": "^0.0.6",
"crc-32": "^1.2.2",
"edge-error": "^4.0.1",
"html-entities": "^2.5.2",
"locate-path": "^7.2.0",
Expand Down
6 changes: 3 additions & 3 deletions src/version_cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
* file that was distributed with this source code.
*/

import { createHash } from 'node:crypto'
import { readFile } from 'node:fs/promises'

import type { AssetsVersion } from './types.js'

/**
Expand All @@ -33,10 +33,10 @@ export class VersionCache {
*/
async #getManifestHash(): Promise<AssetsVersion> {
try {
const crc32 = await import('crc-32')
const manifestPath = new URL('public/assets/.vite/manifest.json', this.appRoot)
const manifestFile = await readFile(manifestPath, 'utf-8')
this.#cachedVersion = crc32.default.str(manifestFile)
this.#cachedVersion = createHash('md5').update(manifestFile).digest('hex')

return this.#cachedVersion
} catch {
/**
Expand Down

0 comments on commit c9459c4

Please sign in to comment.