Просмотр исходного кода

@uppy/core: fix plugin detection (#4951)

Using `instanceof` is problematic as it won't detect plugins from
different Uppy distributions.
Antoine du Hamel 1 год назад
Родитель
Сommit
2cac7c7db6
1 измененных файлов с 11 добавлено и 2 удалено
  1. 11 2
      packages/@uppy/core/src/UIPlugin.ts

+ 11 - 2
packages/@uppy/core/src/UIPlugin.ts

@@ -59,9 +59,18 @@ class UIPlugin<
     target: PluginTarget<Me, Bo>, // eslint-disable-line no-use-before-define
   ): UIPlugin<any, Me, Bo> | undefined {
     let targetPlugin
-    if (typeof target === 'object' && target instanceof UIPlugin) {
+    if (typeof (target as UIPlugin<any, any, any>)?.addTarget === 'function') {
       // Targeting a plugin *instance*
-      targetPlugin = target
+      targetPlugin = target as UIPlugin<any, any, any>
+      if (!(targetPlugin instanceof UIPlugin)) {
+        // eslint-disable-next-line no-console
+        console.warn(
+          new Error(
+            'The provided plugin is not an instance of UIPlugin. This is an indication of a bug with the way Uppy is bundled.',
+            { cause: { targetPlugin, UIPlugin } },
+          ),
+        )
+      }
     } else if (typeof target === 'function') {
       // Targeting a plugin type
       const Target = target