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

fix: adapter import in cjs mode

e22m4u 1 год назад
Родитель
Сommit
a99c61f55e
4 измененных файлов с 28 добавлено и 4 удалено
  1. 10 1
      dist/cjs/index.cjs
  2. 2 2
      package.json
  3. 7 1
      src/adapter/adapter-loader.js
  4. 9 0
      src/adapter/adapter.js

+ 10 - 1
dist/cjs/index.cjs

@@ -5713,6 +5713,14 @@ var init_adapter = __esm({
     init_decorator();
     init_decorator();
     _Adapter = class _Adapter extends Service {
+      /**
+       * Class name.
+       *
+       * @type {string}
+       */
+      get className() {
+        return _Adapter.name;
+      }
       /**
        * Settings.
        *
@@ -6300,7 +6308,8 @@ function findAdapterCtorInModule(module2) {
   let adapterCtor;
   if (!module2 || typeof module2 !== "object" || Array.isArray(module2)) return;
   for (const ctor of Object.values(module2)) {
-    if (typeof ctor === "function" && ctor.prototype instanceof Adapter) {
+    console.log(ctor);
+    if (typeof ctor === "function" && ctor.prototype && typeof ctor.prototype === "object" && ctor.prototype.className === Adapter.name) {
       adapterCtor = ctor;
       break;
     }

+ 2 - 2
package.json

@@ -18,8 +18,8 @@
     "lint": "tsc && eslint ./src",
     "lint:fix": "tsc && eslint ./src --fix",
     "format": "prettier --write \"./src/**/*.js\"",
-    "test": "npm run lint && c8 --reporter=text-summary mocha",
-    "test:coverage": "npm run lint && c8 --reporter=text mocha",
+    "test": "npm run lint && c8 --reporter=text-summary mocha --bail",
+    "test:coverage": "npm run lint && c8 --reporter=text mocha --bail",
     "build:cjs": "node build-cjs.js",
     "prepare": "husky"
   },

+ 7 - 1
src/adapter/adapter-loader.js

@@ -54,7 +54,13 @@ function findAdapterCtorInModule(module) {
   let adapterCtor;
   if (!module || typeof module !== 'object' || Array.isArray(module)) return;
   for (const ctor of Object.values(module)) {
-    if (typeof ctor === 'function' && ctor.prototype instanceof Adapter) {
+    console.log(ctor);
+    if (
+      typeof ctor === 'function' &&
+      ctor.prototype &&
+      typeof ctor.prototype === 'object' &&
+      ctor.prototype.className === Adapter.name
+    ) {
       adapterCtor = ctor;
       break;
     }

+ 9 - 0
src/adapter/adapter.js

@@ -14,6 +14,15 @@ import {PropertyUniquenessDecorator} from './decorator/index.js';
  * Adapter.
  */
 export class Adapter extends Service {
+  /**
+   * Class name.
+   *
+   * @type {string}
+   */
+  get className() {
+    return Adapter.name;
+  }
+
   /**
    * Settings.
    *