Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions packages/lib-core/src/runtime/PluginStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
1 change: 1 addition & 0 deletions reports/lib-core.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down