From 65cde3ba74a86a327fc4b0b962e485a71be4b8ae Mon Sep 17 00:00:00 2001 From: Shigma Date: Mon, 10 Feb 2025 03:35:50 +0800 Subject: [PATCH] chore: adjustments for typing --- packages/registry/src/index.ts | 6 +----- plugins/config/src/shared/writer.ts | 2 +- plugins/console/src/node/index.ts | 3 ++- plugins/logger/src/index.ts | 2 +- plugins/notifier/src/index.ts | 2 ++ 5 files changed, 7 insertions(+), 8 deletions(-) diff --git a/packages/registry/src/index.ts b/packages/registry/src/index.ts index 80b023da..0140e741 100644 --- a/packages/registry/src/index.ts +++ b/packages/registry/src/index.ts @@ -1,5 +1,5 @@ import { compare, intersects } from 'semver' -import { Awaitable, defineProperty, Dict, Time } from 'cosmokit' +import { Awaitable, defineProperty, Dict, isNonNullable, Time } from 'cosmokit' import { Registry, RemotePackage, SearchObject, SearchResult } from './types' import { conclude } from './utils' import pMap from 'p-map' @@ -157,7 +157,3 @@ export default class Scanner { return result.filter(isNonNullable) } } - -function isNonNullable(value: T): value is Exclude { - return value !== null && value !== undefined -} diff --git a/plugins/config/src/shared/writer.ts b/plugins/config/src/shared/writer.ts index da6e847f..1e23bba1 100644 --- a/plugins/config/src/shared/writer.ts +++ b/plugins/config/src/shared/writer.ts @@ -182,7 +182,7 @@ export class ConfigWriter extends DataService { fork.parent = parentT.ctx Object.setPrototypeOf(fork.ctx, parentT.ctx) fork.ctx.emit('internal/fork', fork) - if (fork.runtime.using.some(name => parentS[name] !== parentT[name])) { + if (Object.keys(fork.runtime.inject).some(name => parentS[name] !== parentT[name])) { fork.restart() } } diff --git a/plugins/console/src/node/index.ts b/plugins/console/src/node/index.ts index 7353a26d..3ae79402 100644 --- a/plugins/console/src/node/index.ts +++ b/plugins/console/src/node/index.ts @@ -32,7 +32,8 @@ interface HeartbeatConfig { } class NodeConsole extends Console { - static inject = ['server'] + static inject = { required: ['server'], optional: ['console'] } + // static inject = ['server'] // workaround for edge case (collision with @koishijs/plugin-config) private _config: NodeConsole.Config diff --git a/plugins/logger/src/index.ts b/plugins/logger/src/index.ts index dafe5818..5e899f9a 100644 --- a/plugins/logger/src/index.ts +++ b/plugins/logger/src/index.ts @@ -102,7 +102,7 @@ export async function apply(ctx: Context, config: Config) { record.meta ||= {} const scope = record.meta[Context.current]?.scope if (loader && scope) { - record.meta.paths = loader.paths(scope) + record.meta['paths'] = loader.paths(scope) } const date = new Date(record.timestamp).toISOString().slice(0, 10) if (writer.date !== date) { diff --git a/plugins/notifier/src/index.ts b/plugins/notifier/src/index.ts index 0b4725f0..9d2d23bf 100644 --- a/plugins/notifier/src/index.ts +++ b/plugins/notifier/src/index.ts @@ -93,6 +93,8 @@ export namespace Notifier { } class NotifierService extends Service { + static inject = { optional: ['notifier'] } + public store: Notifier[] = [] public actions: Dict<() => void> = Object.create(null) public entry?: Entry