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

fix: container inheritance in cjs mode

e22m4u 1 год назад
Родитель
Сommit
7120121616
2 измененных файлов с 20 добавлено и 6 удалено
  1. 2 1
      build-cjs.js
  2. 18 5
      dist/cjs/index.cjs

+ 2 - 1
build-cjs.js

@@ -7,4 +7,5 @@ await esbuild.build({
   platform: 'node',
   target: ['node12'],
   bundle: true,
-});
+  keepNames: true,
+});

+ 18 - 5
dist/cjs/index.cjs

@@ -2,6 +2,7 @@ var __defProp = Object.defineProperty;
 var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
 var __getOwnPropNames = Object.getOwnPropertyNames;
 var __hasOwnProp = Object.prototype.hasOwnProperty;
+var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
 var __export = (target, all) => {
   for (var name in all)
     __defProp(target, name, { get: all[name], enumerable: true });
@@ -29,6 +30,7 @@ function isClass(value) {
   if (!value) return false;
   return typeof value === "function" && /^class\s/.test(Function.prototype.toString.call(value));
 }
+__name(isClass, "isClass");
 
 // node_modules/@e22m4u/js-format/src/value-to-string.js
 var BASE_CTOR_NAMES = [
@@ -54,6 +56,7 @@ function valueToString(input) {
   if (typeof input === "object" && input.constructor == null) return "Object";
   return String(input);
 }
+__name(valueToString, "valueToString");
 
 // node_modules/@e22m4u/js-format/src/array-to-list.js
 var SEPARATOR = ", ";
@@ -62,6 +65,7 @@ function arrayToList(input) {
     return input.map(valueToString).join(SEPARATOR);
   return valueToString(input);
 }
+__name(arrayToList, "arrayToList");
 
 // node_modules/@e22m4u/js-format/src/format.js
 function format(pattern) {
@@ -101,9 +105,10 @@ function format(pattern) {
   pattern = pattern.replace(/%{2}/g, "%");
   return "" + pattern;
 }
+__name(format, "format");
 
 // node_modules/@e22m4u/js-format/src/errorf.js
-var Errorf = class extends Error {
+var _Errorf = class _Errorf extends Error {
   /**
    * Constructor.
    *
@@ -115,13 +120,17 @@ var Errorf = class extends Error {
     super(message);
   }
 };
+__name(_Errorf, "Errorf");
+var Errorf = _Errorf;
 
 // src/errors/invalid-argument-error.js
-var InvalidArgumentError = class extends Errorf {
+var _InvalidArgumentError = class _InvalidArgumentError extends Errorf {
 };
+__name(_InvalidArgumentError, "InvalidArgumentError");
+var InvalidArgumentError = _InvalidArgumentError;
 
 // src/service-container.js
-var ServiceContainer = class _ServiceContainer {
+var _ServiceContainer = class _ServiceContainer {
   /**
    * Services map.
    *
@@ -201,7 +210,7 @@ var ServiceContainer = class _ServiceContainer {
         "The first argument of ServicesContainer.add must be a class constructor, but %v given.",
         ctor
       );
-    const factory = () => ctor.prototype instanceof Service ? new ctor(this, ...args) : new ctor(...args);
+    const factory = /* @__PURE__ */ __name(() => ctor.prototype instanceof Service ? new ctor(this, ...args) : new ctor(...args), "factory");
     this._services.set(ctor, factory);
     return this;
   }
@@ -244,9 +253,11 @@ var ServiceContainer = class _ServiceContainer {
     return this;
   }
 };
+__name(_ServiceContainer, "ServiceContainer");
+var ServiceContainer = _ServiceContainer;
 
 // src/service.js
-var Service = class {
+var _Service = class _Service {
   /**
    * Container.
    *
@@ -314,6 +325,8 @@ var Service = class {
     return this;
   }
 };
+__name(_Service, "Service");
+var Service = _Service;
 // Annotate the CommonJS export names for ESM import in node:
 0 && (module.exports = {
   Service,