@@ -108,33 +108,30 @@ interface PluginDetails {
108108 */
109109export async function loadPlugin ( url :string , packageName :string | null ) :Promise < string > {
110110try {
111- const res = await loadPluginImpl ( url , packageName ) ;
111+ if ( DEBUG ) {
112+ if ( registeredPluginUrls . has ( url ) ) throw new Error ( "This plugin has already been registered" ) ;
113+ registeredPluginUrls . add ( url ) ;
114+ }
115+
116+ const plugin = ( await import ( url ) ) . default as Plugin ;
117+ const res = registerPlugin ( plugin , packageName ) ;
112118return JSON . stringify ( { Success :res } ) ;
113119} catch ( err ) {
114120return JSON . stringify ( { Failure :getErrorMessage ( err ) } ) ;
115121}
116122}
117123
118124/**
119- *Load a plugin.
125+ *Register a plugin.
120126 *
121- *@param url -Absolute path of plugin file as a `file://...` URL
127+ *@param plugin -Plugin
122128 *@param packageName - Optional package name from `package.json` (fallback if `plugin.meta.name` is not defined)
123129 *@returns - Plugin details
124- *@throws {* } If plugin throws during import
125130 *@throws {Error } If `plugin.meta.name` is `null` / `undefined` and `packageName` not provided
126131 *@throws {TypeError } If one of plugin's rules is malformed, or its `createOnce` method returns invalid visitor
127132 *@throws {TypeError } If `plugin.meta.name` is not a string
128- *@throws {Error } In debug build if plugin has already been registered
129133 */
130- async function loadPluginImpl ( url :string , packageName :string | null ) :Promise < PluginDetails > {
131- if ( DEBUG ) {
132- if ( registeredPluginUrls . has ( url ) ) throw new Error ( "This plugin has already been registered" ) ;
133- registeredPluginUrls . add ( url ) ;
134- }
135-
136- const { default :plugin } = ( await import ( url ) ) as { default :Plugin } ;
137-
134+ function registerPlugin ( plugin :Plugin , packageName :string | null ) :PluginDetails {
138135// TODO: Use a validation library to assert the shape of the plugin, and of rules
139136
140137const pluginName = getPluginName ( plugin , packageName ) ;