fix(plugins/api.json-storage): remove entire dir when clearing and only update storage when needed

This commit is contained in:
PalmDevs 2026-07-19 20:19:19 +07:00
parent f97c273bef
commit fb35d7af95
No known key found for this signature in database
GPG key ID: 6FAE8F8677ACA8BA

View file

@ -6,6 +6,7 @@ import {
PluginFlags,
registerPlugin,
} from '@revenge-mod/plugins/_'
import { pluginStorageDirFor } from '@revenge-mod/plugins/constants'
import { defineLazyProperty } from '@revenge-mod/utils/object'
import type { JsonStorage, JsonStorageOptions } from '@revenge-mod/json-storage'
import type { InitPluginApi, Plugin } from '@revenge-mod/plugins/types'
@ -66,16 +67,16 @@ registerPlugin(
)
export async function deleteJsonStorageForPlugin(plugin: Plugin<any, any>) {
const opts = storageOptions.get(plugin)!
const path = jsonStorage.pluginStoragePathFor(plugin.manifest.id, opts.file)
const path = pluginStorageDirFor(plugin.manifest.id)
if (await exists(path)) await rm(path)
const api = plugin.api as
| InitPluginApi<{ jsonStorage: AnyObject }>
| undefined
const storage = api?.jsonStorage as JsonStorage<AnyObject> | undefined
// Only update already initialized storages
const storage = Object.getOwnPropertyDescriptor(api, 'jsonStorage')
?.value as JsonStorage<AnyObject> | undefined
await storage?.get()
}