Skip to content

Commit

Permalink
chore: validate plugin dependency type (#4646)
Browse files Browse the repository at this point in the history
  • Loading branch information
wzhudev authored Feb 15, 2025
1 parent a1ee27f commit c8fcab8
Showing 1 changed file with 16 additions and 9 deletions.
25 changes: 16 additions & 9 deletions packages/core/src/services/plugin/plugin.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -250,18 +250,25 @@ export class PluginHolder extends Disposable {
const dependents = plugin[DependentOnSymbol];
if (dependents) {
const exhaustUnregisteredDependents = () => {
const NotRegistered = dependents.find((d) => !this._checkPluginRegistered(d));
if (NotRegistered) {
this._logService.debug(
'[PluginService]',
`Plugin "${plugin.pluginName}" depends on "${NotRegistered.pluginName}" which is not registered. Univer will automatically register it with default configuration.`
);
const notRegisteredPlugin = dependents.find((d) => !this._checkPluginRegistered(d));
if (!notRegisteredPlugin) {
return false;
}

this._registerPlugin(NotRegistered, undefined);
return true;
// TODO: plugin with Univer type cannot dependent on types other than Univer.
if (plugin.type === UniverInstanceType.UNIVER_UNKNOWN && notRegisteredPlugin.type !== UniverInstanceType.UNIVER_UNKNOWN) {
throw new Error('[PluginService]: cannot register a plugin with Univer type that depends on a plugin with other type. '
+ `The dependent is ${plugin.pluginName} and the dependency is ${notRegisteredPlugin.pluginName}.`
);
}

return false;
this._logService.debug(
'[PluginService]',
`Plugin "${plugin.pluginName}" depends on "${notRegisteredPlugin.pluginName}" which is not registered. Univer will automatically register it with default configuration.`
);

this._registerPlugin(notRegisteredPlugin, undefined);
return true;
};

while (exhaustUnregisteredDependents()) {
Expand Down

0 comments on commit c8fcab8

Please sign in to comment.