Skip to content

Commit 227a428

Browse files
committed
exclude timestamps from db hash generation
1 parent 44ca258 commit 227a428

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

src/builder/index.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { join, extname } from 'pathe'
2+
import { hash } from 'ohash'
23
import { promises as fs } from 'fs'
34

45
import fsDriver from 'unstorage/drivers/fs'
@@ -52,6 +53,16 @@ export class Database extends Hookable {
5253
return JSON.stringify(data, omit)
5354
}
5455

56+
async toHash() {
57+
const keys = ['createdAt', 'updatedAt', ...this.omitKeys]
58+
const omit = (key, val) => keys.includes(key) ? undefined : val
59+
60+
const sort = (a, b) => a.path.localeCompare(b.path)
61+
const data = (await this.db.find({}).toArray()).sort(sort)
62+
63+
return hash(JSON.stringify(data, omit))
64+
}
65+
5566
async init() {
5667
const startTime = process.hrtime()
5768

src/module.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { fileURLToPath } from 'url'
22
import { resolve, join } from 'pathe'
33
import { joinURL } from 'ufo'
4-
import { hash } from 'ohash'
54
import { defineNuxtModule, extendViteConfig, updateTemplates } from '@nuxt/kit'
65
import { addPlugin, addImports, addComponent, addTemplate } from '@nuxt/kit'
76
import { Database } from './builder'
@@ -56,7 +55,7 @@ export default defineNuxtModule({
5655

5756
await database.init()
5857

59-
const dbHash = hash(await database.toJSON())
58+
const dbHash = await database.toHash()
6059
const dbName = `db-${dbHash}.json`
6160
const dbUrl = joinURL(baseURL, dbFolder, dbName)
6261
const dbPath = resolve(pubDir, dbName)

0 commit comments

Comments
 (0)