findPlugin function retrieves a previously registered plugin by name and optionally by type. Use it when you need to access plugin configuration or call a plugin directly.
Signature
Parameters
The unique identifier of the plugin to find. This should match the name used when registering the plugin.
The plugin type to search within. If omitted, searches all plugin types. Must be one of:
'router''render'or'postProcessByHtml''postProcessByDom''fileHandler''routeProcess''allDone''beforeAll''routeDiscoveryDone''enterprise''scullySystem'
Whether to exit the process if the plugin is not found. When
true, the process exits with code 15. When false, returns undefined.Return Value
Returns the plugin function if found, orundefined if not found (when errorOnNotfound is false).
Basic Usage
Using with Plugin Configuration
Combine withgetConfig to retrieve plugin configuration:
Accessing Plugins Directly
Plugins are wrapped when registered. To access the original plugin function:Error Handling
Plugin Not Found
By default, if a plugin is not found, Scully exits with an error:Multiple Plugins with Same Name
If a plugin name exists in multiple types and you don’t specify a type:Use Cases
Calling Plugins Programmatically
Checking Plugin Availability
Dynamic Plugin Selection
Working with the Render System
TherenderRoute system uses findPlugin internally to find and execute plugins:
Best Practices
Always specify the plugin type when possible
Always specify the plugin type when possible
Specifying the type avoids ambiguity and makes your code more maintainable:
Handle missing plugins gracefully in optional features
Handle missing plugins gracefully in optional features
When a plugin is optional, use
errorOnNotfound: false:Cache plugin references for better performance
Cache plugin references for better performance
If you’re calling
findPlugin frequently, cache the result:Implementation Details
The function searches for plugins using the following logic:- If a type is specified, searches only within that plugin type
- If no type is specified, searches all plugin types
- The deprecated
'render'type is automatically mapped to'postProcessByHtml' - Returns the first matching plugin found
- Logs an error and exits if multiple matches are found without a type specified
Plugins are stored in a wrapped form. The wrapper tracks plugin execution and handles errors. Use the
accessPluginDirectly property to access the original unwrapped function if needed.Source Reference
Source:libs/scully/src/lib/pluginManagement/pluginConfig.ts:56
Related
registerPlugin
Register a new plugin with Scully
getConfig
Get configuration data for a plugin
Plugin Types
Learn about different plugin types
Plugin System
Understanding Scully’s plugin architecture

