From bac9472a2373bd03b49997664a3f5693d8ebd0d2 Mon Sep 17 00:00:00 2001 From: Vojtech Szocs Date: Wed, 1 Jul 2026 13:45:54 +0000 Subject: [PATCH] Add PluginStore.copyFrom method --- packages/lib-core/src/runtime/PluginStore.ts | 31 ++++++++++++++++++++ reports/lib-core.api.md | 1 + 2 files changed, 32 insertions(+) diff --git a/packages/lib-core/src/runtime/PluginStore.ts b/packages/lib-core/src/runtime/PluginStore.ts index ed97631a..ce5411de 100644 --- a/packages/lib-core/src/runtime/PluginStore.ts +++ b/packages/lib-core/src/runtime/PluginStore.ts @@ -375,4 +375,35 @@ export class PluginStore implements PluginStoreInterface { return referencedModule; } + + /** + * Create new `PluginStore` with state copied from the source `PluginStore`. + * + * @remarks + * + * Does not copy subscribed event {@link listeners} and {@link pendingPromises}. + */ + static copyFrom(source: PluginStore): PluginStore { + const target = new PluginStore({ + autoEnableLoadedPlugins: source.options.autoEnableLoadedPlugins, + loader: source.loader, + }); + + source.pendingPlugins.forEach((plugin, name) => { + target.pendingPlugins.set(name, { ...plugin }); + }); + + source.loadedPlugins.forEach((plugin, name) => { + target.loadedPlugins.set(name, { ...plugin }); + }); + + source.failedPlugins.forEach((plugin, name) => { + target.failedPlugins.set(name, { ...plugin }); + }); + + target.extensions = [...source.extensions]; + target.featureFlags = { ...source.featureFlags }; + + return target; + } } diff --git a/reports/lib-core.api.md b/reports/lib-core.api.md index 02fcdcb7..3233c151 100644 --- a/reports/lib-core.api.md +++ b/reports/lib-core.api.md @@ -254,6 +254,7 @@ export class PluginStore implements PluginStoreInterface { protected addLoadedPlugin(manifest: PluginManifest, loadedExtensions: LoadedExtension[], entryModule?: PluginEntryModule): void; // (undocumented) protected addPendingPlugin(manifest: PluginManifest): void; + static copyFrom(source: PluginStore): PluginStore; // (undocumented) disablePlugins(pluginNames: string[], disableReason?: string): void; // (undocumented)