Skip to content

Commit 2bc1cd5

Browse files
committed
generate stable db version hash
1 parent b58036b commit 2bc1cd5

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

src/builder/index.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,14 @@ export class Database extends Hookable {
4545
}
4646
}
4747

48+
async toJSON() {
49+
const omit = (key, val) => this.omitKeys.includes(key) ? undefined : val
50+
const sort = (a, b) => a.path.localeCompare(b.path)
51+
const data = (await this.db.find({}).toArray()).sort(sort)
52+
53+
return JSON.stringify(data, omit)
54+
}
55+
4856
async init() {
4957
const startTime = process.hrtime()
5058

@@ -71,9 +79,7 @@ export class Database extends Hookable {
7179
filename = filename || this.name
7280

7381
const path = join(dir, filename)
74-
const data = await this.db.find({}).toArray()
75-
const omit = (key, val) => this.omitKeys.includes(key) ? undefined : val
76-
const json = JSON.stringify(data, omit)
82+
const json = await this.toJSON()
7783

7884
await fs.mkdir(dir, { recursive: true })
7985
await fs.writeFile(path, json, 'utf-8')

src/module.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ export default defineNuxtModule({
5656

5757
await database.init()
5858

59-
const dbHash = hash(database.db)
59+
const dbHash = hash(await database.toJSON())
6060
const dbName = `db-${dbHash}.json`
6161
const dbUrl = joinURL(baseURL, dbFolder, dbName)
6262
const dbPath = resolve(pubDir, dbName)

0 commit comments

Comments
 (0)