mirror of
https://github.com/Start9Labs/start-os.git
synced 2026-03-26 10:21:52 +00:00
* fix lockup when stop during init * Fix incorrect description for registry package remove command * alpha.5 * beta.25 --------- Co-authored-by: Mariusz Kogen <k0gen@pm.me>
52 lines
1.3 KiB
TypeScript
52 lines
1.3 KiB
TypeScript
import { ExtendedVersion, VersionRange } from "../../../base/lib/exver"
|
|
import * as T from "../../../base/lib/types"
|
|
|
|
export type UninitFn = (
|
|
effects: T.Effects,
|
|
/**
|
|
* @description the target version to prepare for
|
|
*
|
|
* on update: the canMigrateFrom of the new package
|
|
* on uninstall: null
|
|
* on shutdown: the current version
|
|
*/
|
|
target: VersionRange | ExtendedVersion | null,
|
|
) => Promise<void | null | undefined>
|
|
|
|
export interface UninitScript {
|
|
uninit(
|
|
effects: T.Effects,
|
|
/**
|
|
* @description the target version to prepare for
|
|
*
|
|
* on update: the canMigrateFrom of the new package
|
|
* on uninstall: null
|
|
* on shutdown: the current version
|
|
*/
|
|
target: VersionRange | ExtendedVersion | null,
|
|
): Promise<void>
|
|
}
|
|
|
|
export type UninitScriptOrFn = UninitScript | UninitFn
|
|
|
|
export function setupUninit(
|
|
...uninits: UninitScriptOrFn[]
|
|
): T.ExpectedExports.uninit {
|
|
return async (opts) => {
|
|
for (const uninit of uninits) {
|
|
if ("uninit" in uninit) await uninit.uninit(opts.effects, opts.target)
|
|
else await uninit(opts.effects, opts.target)
|
|
}
|
|
}
|
|
}
|
|
|
|
export function setupOnUninit(onUninit: UninitScriptOrFn): UninitScript {
|
|
return "uninit" in onUninit
|
|
? onUninit
|
|
: {
|
|
uninit: async (effects, target) => {
|
|
await onUninit(effects, target)
|
|
},
|
|
}
|
|
}
|