Browse Source

chore: updates esbuild config

e22m4u 1 year ago
parent
commit
85079f5224
3 changed files with 16 additions and 2 deletions
  1. 6 0
      build-cjs.js
  2. 8 1
      dist/cjs/index.cjs
  3. 2 1
      package.json

+ 6 - 0
build-cjs.js

@@ -1,4 +1,5 @@
 import * as esbuild from 'esbuild';
+import packageJson from './package.json' with {type: 'json'};
 
 await esbuild.build({
   entryPoints: ['src/index.js'],
@@ -7,4 +8,9 @@ await esbuild.build({
   platform: 'node',
   target: ['node12'],
   bundle: true,
+  keepNames: true,
+  external: [
+    ...Object.keys(packageJson.peerDependencies || {}),
+    ...Object.keys(packageJson.dependencies || {}),
+  ],
 });

+ 8 - 1
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");
 
 // 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");
 
 // 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");
 
 // src/format.js
 function format(pattern) {
@@ -101,9 +105,10 @@ function format(pattern) {
   pattern = pattern.replace(/%{2}/g, "%");
   return "" + pattern;
 }
+__name(format, "format");
 
 // src/errorf.js
-var Errorf = class extends Error {
+var _Errorf = class _Errorf extends Error {
   /**
    * Constructor.
    *
@@ -115,6 +120,8 @@ var Errorf = class extends Error {
     super(message);
   }
 };
+__name(_Errorf, "Errorf");
+var Errorf = _Errorf;
 // Annotate the CommonJS export names for ESM import in node:
 0 && (module.exports = {
   Errorf,

+ 2 - 1
package.json

@@ -20,7 +20,7 @@
     "format": "prettier --write \"./src/**/*.js\"",
     "test": "npm run lint && c8 --reporter=text-summary mocha",
     "test:coverage": "npm run lint && c8 --reporter=text mocha",
-    "build:cjs": "node build-cjs.js",
+    "build:cjs": "rimraf ./dist/cjs && node --no-warnings=ExperimentalWarning build-cjs.js",
     "prepare": "husky"
   },
   "repository": {
@@ -50,6 +50,7 @@
     "husky": "~9.1.6",
     "mocha": "~10.8.2",
     "prettier": "~3.3.3",
+    "rimraf": "^6.0.1",
     "typescript": "~5.6.2"
   }
 }