fix: avoid command registry init cycle in CI
This commit is contained in:
parent
e9bf234eb7
commit
e2c2dcdc77
@ -1,5 +1,4 @@
|
|||||||
import { listChannelDocks } from "../channels/dock.js";
|
import { listChannelDocks } from "../channels/dock.js";
|
||||||
import { getActivePluginRegistry } from "../plugins/runtime.js";
|
|
||||||
import { COMMAND_ARG_FORMATTERS } from "./commands-args.js";
|
import { COMMAND_ARG_FORMATTERS } from "./commands-args.js";
|
||||||
import type {
|
import type {
|
||||||
ChatCommandDefinition,
|
ChatCommandDefinition,
|
||||||
@ -124,9 +123,7 @@ function assertCommandRegistry(commands: ChatCommandDefinition[]): void {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let cachedCommands: ChatCommandDefinition[] | null = null;
|
let cachedCommands: ChatCommandDefinition[] | null = null;
|
||||||
let cachedRegistry: ReturnType<typeof getActivePluginRegistry> | null = null;
|
|
||||||
let cachedNativeCommandSurfaces: Set<string> | null = null;
|
let cachedNativeCommandSurfaces: Set<string> | null = null;
|
||||||
let cachedNativeRegistry: ReturnType<typeof getActivePluginRegistry> | null = null;
|
|
||||||
|
|
||||||
function buildChatCommands(): ChatCommandDefinition[] {
|
function buildChatCommands(): ChatCommandDefinition[] {
|
||||||
const commands: ChatCommandDefinition[] = [
|
const commands: ChatCommandDefinition[] = [
|
||||||
@ -759,20 +756,17 @@ function buildChatCommands(): ChatCommandDefinition[] {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function getChatCommands(): ChatCommandDefinition[] {
|
export function getChatCommands(): ChatCommandDefinition[] {
|
||||||
const registry = getActivePluginRegistry();
|
if (cachedCommands) {
|
||||||
if (cachedCommands && registry === cachedRegistry) {
|
|
||||||
return cachedCommands;
|
return cachedCommands;
|
||||||
}
|
}
|
||||||
const commands = buildChatCommands();
|
const commands = buildChatCommands();
|
||||||
cachedCommands = commands;
|
cachedCommands = commands;
|
||||||
cachedRegistry = registry;
|
|
||||||
cachedNativeCommandSurfaces = null;
|
cachedNativeCommandSurfaces = null;
|
||||||
return commands;
|
return commands;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getNativeCommandSurfaces(): Set<string> {
|
export function getNativeCommandSurfaces(): Set<string> {
|
||||||
const registry = getActivePluginRegistry();
|
if (cachedNativeCommandSurfaces) {
|
||||||
if (cachedNativeCommandSurfaces && registry === cachedNativeRegistry) {
|
|
||||||
return cachedNativeCommandSurfaces;
|
return cachedNativeCommandSurfaces;
|
||||||
}
|
}
|
||||||
cachedNativeCommandSurfaces = new Set(
|
cachedNativeCommandSurfaces = new Set(
|
||||||
@ -780,6 +774,5 @@ export function getNativeCommandSurfaces(): Set<string> {
|
|||||||
.filter((dock) => dock.capabilities.nativeCommands)
|
.filter((dock) => dock.capabilities.nativeCommands)
|
||||||
.map((dock) => dock.id),
|
.map((dock) => dock.id),
|
||||||
);
|
);
|
||||||
cachedNativeRegistry = registry;
|
|
||||||
return cachedNativeCommandSurfaces;
|
return cachedNativeCommandSurfaces;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user