Skip to content

Commit

Permalink
fix: node presets with url
Browse files Browse the repository at this point in the history
  • Loading branch information
typicode committed Oct 23, 2023
1 parent d4482a5 commit 7166e2e
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 14 deletions.
14 changes: 7 additions & 7 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
"prepare": "husky install"
},
"dependencies": {
"steno": "^3.1.0"
"steno": "^3.1.1"
},
"devDependencies": {
"@commitlint/cli": "^17.7.2",
Expand Down
12 changes: 6 additions & 6 deletions src/presets/node.ts
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
import fs from 'node:fs'

import { Memory, MemorySync } from '../adapters/Memory.js'
import { JSONFile, JSONFileSync } from '../adapters/node/JSONFile.js'
import { Low, LowSync } from '../core/Low.js'

export async function JSONPreset<Data>(
filename: string | URL,
filename: fs.PathLike,
defaultData: Data,
dir?: string | URL,
): Promise<Low<Data>> {
const adapter =
process.env.NODE_ENV === 'test'
? new Memory<Data>()
: new JSONFile<Data>(new URL(filename, dir))
: new JSONFile<Data>(filename)
const db = new Low<Data>(adapter, defaultData)
await db.read()
return db
}

export function JSONSyncPreset<Data>(
filename: string | URL,
filename: fs.PathLike,
defaultData: Data,
dir?: string | URL,
): LowSync<Data> {
const adapter =
process.env.NODE_ENV === 'test'
? new MemorySync<Data>()
: new JSONFileSync<Data>(new URL(filename, dir))
: new JSONFileSync<Data>(filename)
const db = new LowSync<Data>(adapter, defaultData)
db.read()
return db
Expand Down

0 comments on commit 7166e2e

Please sign in to comment.