surrge 0.4.1 → 0.4.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/cli.js CHANGED
@@ -2,8 +2,8 @@
2
2
 
3
3
  // src/cli.ts
4
4
  import { spawn, spawnSync } from "node:child_process";
5
- import { fileURLToPath } from "node:url";
6
5
  import { dirname, resolve } from "node:path";
6
+ import { fileURLToPath } from "node:url";
7
7
  var args = process.argv.slice(2);
8
8
  if (args.length === 0) {
9
9
  console.log("Usage: surrge [options] <script> [args...]");
@@ -1 +1 @@
1
- {"version":3,"file":"hooks.d.ts","sourceRoot":"","sources":["../src/hooks.ts"],"names":[],"mappings":"AAyJA,eAAO,MAAM,OAAO,GAClB,WAAW,MAAM,EACjB,SAAS,OAAO,EAChB,aAAa,QAAQ,iBAGtB,CAAC;AAEF,eAAO,MAAM,IAAI,GACf,KAAK,MAAM,EACX,SAAS,OAAO,EAChB,UAAU,QAAQ,iBAGnB,CAAC"}
1
+ {"version":3,"file":"hooks.d.ts","sourceRoot":"","sources":["../src/hooks.ts"],"names":[],"mappings":"AA6KA,eAAO,MAAM,OAAO,GAClB,WAAW,MAAM,EACjB,SAAS,OAAO,EAChB,aAAa,QAAQ,iBAGtB,CAAC;AAEF,eAAO,MAAM,IAAI,GACf,KAAK,MAAM,EACX,SAAS,OAAO,EAChB,UAAU,QAAQ,iBAGnB,CAAC"}
package/dist/hooks.js CHANGED
@@ -57,7 +57,7 @@ var normalizeLevel = (level) => {
57
57
  return "info";
58
58
  };
59
59
  var captureOutput = (chunk) => {
60
- const text = typeof chunk === "string" ? chunk : chunk.toString();
60
+ const text = typeof chunk === "string" ? chunk : Buffer.isBuffer(chunk) ? chunk.toString() : new TextDecoder().decode(chunk);
61
61
  buffer += text;
62
62
  const lines = buffer.split(`
63
63
  `);
@@ -108,7 +108,7 @@ cjsFs.write = (fd, data, ...args) => {
108
108
  };
109
109
  var originalStdoutWrite = process.stdout.write.bind(process.stdout);
110
110
  process.stdout.write = (chunk, encodingOrCallback, callback) => {
111
- if (typeof chunk === "string" || Buffer.isBuffer(chunk)) {
111
+ if (typeof chunk === "string" || chunk instanceof Uint8Array) {
112
112
  captureOutput(chunk);
113
113
  }
114
114
  if (typeof encodingOrCallback === "function") {
@@ -122,12 +122,20 @@ if (Bun?.write) {
122
122
  const originalBunWrite = Bun.write;
123
123
  Bun.write = (dest, data, ...args) => {
124
124
  const isStdout = dest === STDOUT_FD || dest === process.stdout || dest === BunStdout;
125
- if (isStdout && (typeof data === "string" || Buffer.isBuffer(data))) {
125
+ if (isStdout && (typeof data === "string" || data instanceof Uint8Array)) {
126
126
  captureOutput(data);
127
127
  }
128
128
  return originalBunWrite(dest, data, ...args);
129
129
  };
130
130
  }
131
+ var bunStdout = BunStdout;
132
+ if (bunStdout?.write) {
133
+ const originalBunStdoutWrite = bunStdout.write.bind(bunStdout);
134
+ bunStdout.write = (data) => {
135
+ captureOutput(data);
136
+ return originalBunStdoutWrite(data);
137
+ };
138
+ }
131
139
  var resolve = async (specifier, context, nextResolve) => {
132
140
  return nextResolve(specifier, context);
133
141
  };
package/dist/index.js CHANGED
@@ -3595,6 +3595,95 @@ var require_promise_limit = __commonJS((exports, module) => {
3595
3595
  }
3596
3596
  };
3597
3597
  });
3598
+ // package.json
3599
+ var package_default = {
3600
+ name: "surrge",
3601
+ version: "0.4.6",
3602
+ description: "One-line observability + analytics for Node.js/Bun",
3603
+ type: "module",
3604
+ exports: {
3605
+ ".": {
3606
+ types: "./dist/index.d.ts",
3607
+ import: "./dist/index.js"
3608
+ },
3609
+ "./register": {
3610
+ types: "./dist/register.d.ts",
3611
+ import: "./dist/register.js"
3612
+ },
3613
+ "./loader": {
3614
+ types: "./dist/loader.d.ts",
3615
+ import: "./dist/loader.js"
3616
+ }
3617
+ },
3618
+ bin: {
3619
+ surrge: "./dist/cli.js"
3620
+ },
3621
+ files: [
3622
+ "dist",
3623
+ "!dist/**/*.test.*",
3624
+ "README.md",
3625
+ "LICENSE"
3626
+ ],
3627
+ scripts: {
3628
+ preuninstall: "echo '[surrge] Your data in surrge.db has been preserved. To remove it: rm surrge.db'",
3629
+ build: "bun run build:dashboard && bun run build:bundle && bun run build:types",
3630
+ "build:bundle": "bun build ./src/index.ts ./src/register.ts ./src/loader.ts ./src/hooks.ts ./src/cli.ts --outdir=./dist --target=node",
3631
+ "build:types": "tsc --emitDeclarationOnly",
3632
+ "build:dashboard": "cd src/dashboard/ui && bun run build.ts",
3633
+ "dev:dashboard": "cd src/dashboard/ui && bun run dev",
3634
+ dev: "bun --watch src/index.ts",
3635
+ test: "bun test",
3636
+ check: "tsc --noEmit",
3637
+ lint: "biome check --write .",
3638
+ prepublishOnly: "bun run check && bun test && bun run build",
3639
+ push: "npm publish",
3640
+ db: "./bin/db.sh"
3641
+ },
3642
+ dependencies: {
3643
+ "@libsql/client": "^0.14.0",
3644
+ hono: "^4.6.0"
3645
+ },
3646
+ devDependencies: {
3647
+ "@biomejs/biome": "^2.3.10",
3648
+ "@types/node": "^22.0.0",
3649
+ "bun-types": "^1.3.5",
3650
+ elysia: "^1.4.19",
3651
+ express: "^5.2.1",
3652
+ pino: "^10.1.0",
3653
+ typescript: "^5.7.0",
3654
+ winston: "^3.19.0"
3655
+ },
3656
+ keywords: [
3657
+ "observability",
3658
+ "analytics",
3659
+ "logging",
3660
+ "monitoring",
3661
+ "metrics",
3662
+ "tracing",
3663
+ "sqlite",
3664
+ "embedded",
3665
+ "bun",
3666
+ "nodejs"
3667
+ ],
3668
+ license: "MIT",
3669
+ engines: {
3670
+ node: ">=18.0.0"
3671
+ },
3672
+ repository: {
3673
+ type: "git",
3674
+ url: "git+https://github.com/blakbelt78/surrge.git"
3675
+ },
3676
+ homepage: "https://github.com/blakbelt78/surrge#readme",
3677
+ bugs: {
3678
+ url: "https://github.com/blakbelt78/surrge/issues"
3679
+ },
3680
+ author: "blakbelt78",
3681
+ sideEffects: [
3682
+ "./dist/register.js",
3683
+ "./dist/loader.js",
3684
+ "./dist/hooks.js"
3685
+ ]
3686
+ };
3598
3687
 
3599
3688
  // src/collector.ts
3600
3689
  var exports_collector = {};
@@ -8898,10 +8987,8 @@ var patchProcessStdout = () => {
8898
8987
  };
8899
8988
  var patchFsWriteSync = () => {
8900
8989
  const originalWriteSync = fs.writeSync;
8901
- console.log("[surrge] Patching fs.writeSync");
8902
8990
  fs.writeSync = (fd, buffer2, ...args) => {
8903
8991
  if (fd === STDOUT_FD) {
8904
- console.log("[surrge] fs.writeSync intercepted for stdout");
8905
8992
  captureOutput(buffer2);
8906
8993
  }
8907
8994
  return originalWriteSync(fd, buffer2, ...args);
@@ -8918,20 +9005,30 @@ var patchFsWrite = () => {
8918
9005
  };
8919
9006
  var patchBunWrite = () => {
8920
9007
  const Bun2 = globalThis.Bun;
8921
- if (!Bun2?.write)
9008
+ if (!Bun2)
8922
9009
  return;
8923
- const originalWrite = Bun2.write;
8924
- Bun2.write = (dest, data, ...args) => {
8925
- if (dest === STDOUT_FD || dest === process.stdout) {
8926
- if (typeof data === "string" || data instanceof Uint8Array) {
9010
+ const BunStdout = Bun2.stdout;
9011
+ if (Bun2.write) {
9012
+ const originalWrite = Bun2.write;
9013
+ Bun2.write = (dest, data, ...args) => {
9014
+ const isStdout = dest === STDOUT_FD || dest === process.stdout || dest === BunStdout;
9015
+ if (isStdout && (typeof data === "string" || data instanceof Uint8Array)) {
8927
9016
  captureOutput(data);
8928
9017
  }
8929
- }
8930
- return originalWrite(dest, data, ...args);
8931
- };
9018
+ return originalWrite(dest, data, ...args);
9019
+ };
9020
+ }
9021
+ const bunStdout = BunStdout;
9022
+ if (bunStdout?.write) {
9023
+ const originalBunStdoutWrite = bunStdout.write.bind(bunStdout);
9024
+ bunStdout.write = (data) => {
9025
+ captureOutput(data);
9026
+ return originalBunStdoutWrite(data);
9027
+ };
9028
+ }
8932
9029
  };
8933
9030
  var captureOutput = (chunk) => {
8934
- const text = typeof chunk === "string" ? chunk : Buffer.from(chunk.buffer).toString();
9031
+ const text = typeof chunk === "string" ? chunk : Buffer.isBuffer(chunk) ? chunk.toString() : new TextDecoder().decode(chunk);
8935
9032
  buffer += text;
8936
9033
  const lines = buffer.split(`
8937
9034
  `);
@@ -10766,91 +10863,6 @@ var handleDashboard = async (req, res) => {
10766
10863
  response.headers.forEach((value, key) => res.setHeader(key, value));
10767
10864
  res.end(await response.text());
10768
10865
  };
10769
- // package.json
10770
- var package_default = {
10771
- name: "surrge",
10772
- version: "0.4.1",
10773
- description: "One-line observability + analytics for Node.js/Bun",
10774
- type: "module",
10775
- exports: {
10776
- ".": {
10777
- types: "./dist/index.d.ts",
10778
- import: "./dist/index.js"
10779
- },
10780
- "./register": {
10781
- types: "./dist/register.d.ts",
10782
- import: "./dist/register.js"
10783
- },
10784
- "./loader": {
10785
- types: "./dist/loader.d.ts",
10786
- import: "./dist/loader.js"
10787
- }
10788
- },
10789
- bin: {
10790
- surrge: "./dist/cli.js"
10791
- },
10792
- files: [
10793
- "dist",
10794
- "README.md",
10795
- "LICENSE"
10796
- ],
10797
- scripts: {
10798
- preuninstall: "echo '[surrge] Your data in surrge.db has been preserved. To remove it: rm surrge.db'",
10799
- build: "bun run build:dashboard && bun run build:bundle && bun run build:types",
10800
- "build:bundle": "bun build ./src/index.ts ./src/register.ts ./src/loader.ts ./src/hooks.ts ./src/cli.ts --outdir=./dist --target=node",
10801
- "build:types": "tsc --emitDeclarationOnly",
10802
- "build:dashboard": "cd src/dashboard/ui && bun run build.ts",
10803
- "dev:dashboard": "cd src/dashboard/ui && bun run dev",
10804
- dev: "bun --watch src/index.ts",
10805
- test: "bun test",
10806
- check: "tsc --noEmit",
10807
- lint: "biome check --write .",
10808
- prepublishOnly: "bun run check && bun test && bun run build",
10809
- push: "npm publish",
10810
- db: "./bin/db.sh"
10811
- },
10812
- dependencies: {
10813
- "@libsql/client": "^0.14.0",
10814
- hono: "^4.6.0"
10815
- },
10816
- devDependencies: {
10817
- "@biomejs/biome": "^2.3.10",
10818
- "@types/node": "^22.0.0",
10819
- "bun-types": "^1.3.5",
10820
- express: "^5.2.1",
10821
- typescript: "^5.7.0"
10822
- },
10823
- keywords: [
10824
- "observability",
10825
- "analytics",
10826
- "logging",
10827
- "monitoring",
10828
- "metrics",
10829
- "tracing",
10830
- "sqlite",
10831
- "embedded",
10832
- "bun",
10833
- "nodejs"
10834
- ],
10835
- license: "MIT",
10836
- engines: {
10837
- node: ">=18.0.0"
10838
- },
10839
- repository: {
10840
- type: "git",
10841
- url: "git+https://github.com/blakbelt78/surrge.git"
10842
- },
10843
- homepage: "https://github.com/blakbelt78/surrge#readme",
10844
- bugs: {
10845
- url: "https://github.com/blakbelt78/surrge/issues"
10846
- },
10847
- author: "blakbelt78",
10848
- sideEffects: [
10849
- "./dist/register.js",
10850
- "./dist/loader.js",
10851
- "./dist/hooks.js"
10852
- ]
10853
- };
10854
10866
 
10855
10867
  // src/register.ts
10856
10868
  init();
@@ -10860,12 +10872,19 @@ start3();
10860
10872
  var isBun = typeof globalThis.Bun !== "undefined";
10861
10873
  if (isBun) {
10862
10874
  patch5();
10875
+ patch6();
10863
10876
  } else {
10864
10877
  patch6();
10865
10878
  }
10866
10879
  setInterval(() => {
10867
10880
  cleanup();
10868
10881
  }, 24 * 60 * 60 * 1000).unref();
10882
+ process.on("beforeExit", () => {
10883
+ stop();
10884
+ });
10885
+ process.on("exit", () => {
10886
+ stop();
10887
+ });
10869
10888
  console.log(`[surrge] v${package_default.version} → /surrge`);
10870
10889
  export {
10871
10890
  exports_db as db,
package/dist/loader.js CHANGED
@@ -3595,6 +3595,95 @@ var require_promise_limit = __commonJS((exports, module) => {
3595
3595
  }
3596
3596
  };
3597
3597
  });
3598
+ // package.json
3599
+ var package_default = {
3600
+ name: "surrge",
3601
+ version: "0.4.6",
3602
+ description: "One-line observability + analytics for Node.js/Bun",
3603
+ type: "module",
3604
+ exports: {
3605
+ ".": {
3606
+ types: "./dist/index.d.ts",
3607
+ import: "./dist/index.js"
3608
+ },
3609
+ "./register": {
3610
+ types: "./dist/register.d.ts",
3611
+ import: "./dist/register.js"
3612
+ },
3613
+ "./loader": {
3614
+ types: "./dist/loader.d.ts",
3615
+ import: "./dist/loader.js"
3616
+ }
3617
+ },
3618
+ bin: {
3619
+ surrge: "./dist/cli.js"
3620
+ },
3621
+ files: [
3622
+ "dist",
3623
+ "!dist/**/*.test.*",
3624
+ "README.md",
3625
+ "LICENSE"
3626
+ ],
3627
+ scripts: {
3628
+ preuninstall: "echo '[surrge] Your data in surrge.db has been preserved. To remove it: rm surrge.db'",
3629
+ build: "bun run build:dashboard && bun run build:bundle && bun run build:types",
3630
+ "build:bundle": "bun build ./src/index.ts ./src/register.ts ./src/loader.ts ./src/hooks.ts ./src/cli.ts --outdir=./dist --target=node",
3631
+ "build:types": "tsc --emitDeclarationOnly",
3632
+ "build:dashboard": "cd src/dashboard/ui && bun run build.ts",
3633
+ "dev:dashboard": "cd src/dashboard/ui && bun run dev",
3634
+ dev: "bun --watch src/index.ts",
3635
+ test: "bun test",
3636
+ check: "tsc --noEmit",
3637
+ lint: "biome check --write .",
3638
+ prepublishOnly: "bun run check && bun test && bun run build",
3639
+ push: "npm publish",
3640
+ db: "./bin/db.sh"
3641
+ },
3642
+ dependencies: {
3643
+ "@libsql/client": "^0.14.0",
3644
+ hono: "^4.6.0"
3645
+ },
3646
+ devDependencies: {
3647
+ "@biomejs/biome": "^2.3.10",
3648
+ "@types/node": "^22.0.0",
3649
+ "bun-types": "^1.3.5",
3650
+ elysia: "^1.4.19",
3651
+ express: "^5.2.1",
3652
+ pino: "^10.1.0",
3653
+ typescript: "^5.7.0",
3654
+ winston: "^3.19.0"
3655
+ },
3656
+ keywords: [
3657
+ "observability",
3658
+ "analytics",
3659
+ "logging",
3660
+ "monitoring",
3661
+ "metrics",
3662
+ "tracing",
3663
+ "sqlite",
3664
+ "embedded",
3665
+ "bun",
3666
+ "nodejs"
3667
+ ],
3668
+ license: "MIT",
3669
+ engines: {
3670
+ node: ">=18.0.0"
3671
+ },
3672
+ repository: {
3673
+ type: "git",
3674
+ url: "git+https://github.com/blakbelt78/surrge.git"
3675
+ },
3676
+ homepage: "https://github.com/blakbelt78/surrge#readme",
3677
+ bugs: {
3678
+ url: "https://github.com/blakbelt78/surrge/issues"
3679
+ },
3680
+ author: "blakbelt78",
3681
+ sideEffects: [
3682
+ "./dist/register.js",
3683
+ "./dist/loader.js",
3684
+ "./dist/hooks.js"
3685
+ ]
3686
+ };
3598
3687
 
3599
3688
  // src/collector.ts
3600
3689
  var exports_collector = {};
@@ -8898,10 +8987,8 @@ var patchProcessStdout = () => {
8898
8987
  };
8899
8988
  var patchFsWriteSync = () => {
8900
8989
  const originalWriteSync = fs.writeSync;
8901
- console.log("[surrge] Patching fs.writeSync");
8902
8990
  fs.writeSync = (fd, buffer2, ...args) => {
8903
8991
  if (fd === STDOUT_FD) {
8904
- console.log("[surrge] fs.writeSync intercepted for stdout");
8905
8992
  captureOutput(buffer2);
8906
8993
  }
8907
8994
  return originalWriteSync(fd, buffer2, ...args);
@@ -8918,20 +9005,30 @@ var patchFsWrite = () => {
8918
9005
  };
8919
9006
  var patchBunWrite = () => {
8920
9007
  const Bun2 = globalThis.Bun;
8921
- if (!Bun2?.write)
9008
+ if (!Bun2)
8922
9009
  return;
8923
- const originalWrite = Bun2.write;
8924
- Bun2.write = (dest, data, ...args) => {
8925
- if (dest === STDOUT_FD || dest === process.stdout) {
8926
- if (typeof data === "string" || data instanceof Uint8Array) {
9010
+ const BunStdout = Bun2.stdout;
9011
+ if (Bun2.write) {
9012
+ const originalWrite = Bun2.write;
9013
+ Bun2.write = (dest, data, ...args) => {
9014
+ const isStdout = dest === STDOUT_FD || dest === process.stdout || dest === BunStdout;
9015
+ if (isStdout && (typeof data === "string" || data instanceof Uint8Array)) {
8927
9016
  captureOutput(data);
8928
9017
  }
8929
- }
8930
- return originalWrite(dest, data, ...args);
8931
- };
9018
+ return originalWrite(dest, data, ...args);
9019
+ };
9020
+ }
9021
+ const bunStdout = BunStdout;
9022
+ if (bunStdout?.write) {
9023
+ const originalBunStdoutWrite = bunStdout.write.bind(bunStdout);
9024
+ bunStdout.write = (data) => {
9025
+ captureOutput(data);
9026
+ return originalBunStdoutWrite(data);
9027
+ };
9028
+ }
8932
9029
  };
8933
9030
  var captureOutput = (chunk) => {
8934
- const text = typeof chunk === "string" ? chunk : Buffer.from(chunk.buffer).toString();
9031
+ const text = typeof chunk === "string" ? chunk : Buffer.isBuffer(chunk) ? chunk.toString() : new TextDecoder().decode(chunk);
8935
9032
  buffer += text;
8936
9033
  const lines = buffer.split(`
8937
9034
  `);
@@ -10766,91 +10863,6 @@ var handleDashboard = async (req, res) => {
10766
10863
  response.headers.forEach((value, key) => res.setHeader(key, value));
10767
10864
  res.end(await response.text());
10768
10865
  };
10769
- // package.json
10770
- var package_default = {
10771
- name: "surrge",
10772
- version: "0.4.1",
10773
- description: "One-line observability + analytics for Node.js/Bun",
10774
- type: "module",
10775
- exports: {
10776
- ".": {
10777
- types: "./dist/index.d.ts",
10778
- import: "./dist/index.js"
10779
- },
10780
- "./register": {
10781
- types: "./dist/register.d.ts",
10782
- import: "./dist/register.js"
10783
- },
10784
- "./loader": {
10785
- types: "./dist/loader.d.ts",
10786
- import: "./dist/loader.js"
10787
- }
10788
- },
10789
- bin: {
10790
- surrge: "./dist/cli.js"
10791
- },
10792
- files: [
10793
- "dist",
10794
- "README.md",
10795
- "LICENSE"
10796
- ],
10797
- scripts: {
10798
- preuninstall: "echo '[surrge] Your data in surrge.db has been preserved. To remove it: rm surrge.db'",
10799
- build: "bun run build:dashboard && bun run build:bundle && bun run build:types",
10800
- "build:bundle": "bun build ./src/index.ts ./src/register.ts ./src/loader.ts ./src/hooks.ts ./src/cli.ts --outdir=./dist --target=node",
10801
- "build:types": "tsc --emitDeclarationOnly",
10802
- "build:dashboard": "cd src/dashboard/ui && bun run build.ts",
10803
- "dev:dashboard": "cd src/dashboard/ui && bun run dev",
10804
- dev: "bun --watch src/index.ts",
10805
- test: "bun test",
10806
- check: "tsc --noEmit",
10807
- lint: "biome check --write .",
10808
- prepublishOnly: "bun run check && bun test && bun run build",
10809
- push: "npm publish",
10810
- db: "./bin/db.sh"
10811
- },
10812
- dependencies: {
10813
- "@libsql/client": "^0.14.0",
10814
- hono: "^4.6.0"
10815
- },
10816
- devDependencies: {
10817
- "@biomejs/biome": "^2.3.10",
10818
- "@types/node": "^22.0.0",
10819
- "bun-types": "^1.3.5",
10820
- express: "^5.2.1",
10821
- typescript: "^5.7.0"
10822
- },
10823
- keywords: [
10824
- "observability",
10825
- "analytics",
10826
- "logging",
10827
- "monitoring",
10828
- "metrics",
10829
- "tracing",
10830
- "sqlite",
10831
- "embedded",
10832
- "bun",
10833
- "nodejs"
10834
- ],
10835
- license: "MIT",
10836
- engines: {
10837
- node: ">=18.0.0"
10838
- },
10839
- repository: {
10840
- type: "git",
10841
- url: "git+https://github.com/blakbelt78/surrge.git"
10842
- },
10843
- homepage: "https://github.com/blakbelt78/surrge#readme",
10844
- bugs: {
10845
- url: "https://github.com/blakbelt78/surrge/issues"
10846
- },
10847
- author: "blakbelt78",
10848
- sideEffects: [
10849
- "./dist/register.js",
10850
- "./dist/loader.js",
10851
- "./dist/hooks.js"
10852
- ]
10853
- };
10854
10866
 
10855
10867
  // src/register.ts
10856
10868
  init();
@@ -10860,12 +10872,19 @@ start3();
10860
10872
  var isBun = typeof globalThis.Bun !== "undefined";
10861
10873
  if (isBun) {
10862
10874
  patch5();
10875
+ patch6();
10863
10876
  } else {
10864
10877
  patch6();
10865
10878
  }
10866
10879
  setInterval(() => {
10867
10880
  cleanup();
10868
10881
  }, 24 * 60 * 60 * 1000).unref();
10882
+ process.on("beforeExit", () => {
10883
+ stop();
10884
+ });
10885
+ process.on("exit", () => {
10886
+ stop();
10887
+ });
10869
10888
  console.log(`[surrge] v${package_default.version} → /surrge`);
10870
10889
 
10871
10890
  // src/hooks.ts
@@ -10898,7 +10917,7 @@ var normalizeLevel2 = (level) => {
10898
10917
  return "info";
10899
10918
  };
10900
10919
  var captureOutput2 = (chunk) => {
10901
- const text = typeof chunk === "string" ? chunk : chunk.toString();
10920
+ const text = typeof chunk === "string" ? chunk : Buffer.isBuffer(chunk) ? chunk.toString() : new TextDecoder().decode(chunk);
10902
10921
  buffer2 += text;
10903
10922
  const lines = buffer2.split(`
10904
10923
  `);
@@ -10949,7 +10968,7 @@ cjsFs.write = (fd, data, ...args) => {
10949
10968
  };
10950
10969
  var originalStdoutWrite = process.stdout.write.bind(process.stdout);
10951
10970
  process.stdout.write = (chunk, encodingOrCallback, callback) => {
10952
- if (typeof chunk === "string" || Buffer.isBuffer(chunk)) {
10971
+ if (typeof chunk === "string" || chunk instanceof Uint8Array) {
10953
10972
  captureOutput2(chunk);
10954
10973
  }
10955
10974
  if (typeof encodingOrCallback === "function") {
@@ -10963,12 +10982,20 @@ if (Bun2?.write) {
10963
10982
  const originalBunWrite = Bun2.write;
10964
10983
  Bun2.write = (dest, data, ...args) => {
10965
10984
  const isStdout = dest === STDOUT_FD2 || dest === process.stdout || dest === BunStdout;
10966
- if (isStdout && (typeof data === "string" || Buffer.isBuffer(data))) {
10985
+ if (isStdout && (typeof data === "string" || data instanceof Uint8Array)) {
10967
10986
  captureOutput2(data);
10968
10987
  }
10969
10988
  return originalBunWrite(dest, data, ...args);
10970
10989
  };
10971
10990
  }
10991
+ var bunStdout = BunStdout;
10992
+ if (bunStdout?.write) {
10993
+ const originalBunStdoutWrite = bunStdout.write.bind(bunStdout);
10994
+ bunStdout.write = (data) => {
10995
+ captureOutput2(data);
10996
+ return originalBunStdoutWrite(data);
10997
+ };
10998
+ }
10972
10999
  var resolve = async (specifier, context, nextResolve) => {
10973
11000
  return nextResolve(specifier, context);
10974
11001
  };
package/dist/register.js CHANGED
@@ -3595,6 +3595,95 @@ var require_promise_limit = __commonJS((exports, module) => {
3595
3595
  }
3596
3596
  };
3597
3597
  });
3598
+ // package.json
3599
+ var package_default = {
3600
+ name: "surrge",
3601
+ version: "0.4.6",
3602
+ description: "One-line observability + analytics for Node.js/Bun",
3603
+ type: "module",
3604
+ exports: {
3605
+ ".": {
3606
+ types: "./dist/index.d.ts",
3607
+ import: "./dist/index.js"
3608
+ },
3609
+ "./register": {
3610
+ types: "./dist/register.d.ts",
3611
+ import: "./dist/register.js"
3612
+ },
3613
+ "./loader": {
3614
+ types: "./dist/loader.d.ts",
3615
+ import: "./dist/loader.js"
3616
+ }
3617
+ },
3618
+ bin: {
3619
+ surrge: "./dist/cli.js"
3620
+ },
3621
+ files: [
3622
+ "dist",
3623
+ "!dist/**/*.test.*",
3624
+ "README.md",
3625
+ "LICENSE"
3626
+ ],
3627
+ scripts: {
3628
+ preuninstall: "echo '[surrge] Your data in surrge.db has been preserved. To remove it: rm surrge.db'",
3629
+ build: "bun run build:dashboard && bun run build:bundle && bun run build:types",
3630
+ "build:bundle": "bun build ./src/index.ts ./src/register.ts ./src/loader.ts ./src/hooks.ts ./src/cli.ts --outdir=./dist --target=node",
3631
+ "build:types": "tsc --emitDeclarationOnly",
3632
+ "build:dashboard": "cd src/dashboard/ui && bun run build.ts",
3633
+ "dev:dashboard": "cd src/dashboard/ui && bun run dev",
3634
+ dev: "bun --watch src/index.ts",
3635
+ test: "bun test",
3636
+ check: "tsc --noEmit",
3637
+ lint: "biome check --write .",
3638
+ prepublishOnly: "bun run check && bun test && bun run build",
3639
+ push: "npm publish",
3640
+ db: "./bin/db.sh"
3641
+ },
3642
+ dependencies: {
3643
+ "@libsql/client": "^0.14.0",
3644
+ hono: "^4.6.0"
3645
+ },
3646
+ devDependencies: {
3647
+ "@biomejs/biome": "^2.3.10",
3648
+ "@types/node": "^22.0.0",
3649
+ "bun-types": "^1.3.5",
3650
+ elysia: "^1.4.19",
3651
+ express: "^5.2.1",
3652
+ pino: "^10.1.0",
3653
+ typescript: "^5.7.0",
3654
+ winston: "^3.19.0"
3655
+ },
3656
+ keywords: [
3657
+ "observability",
3658
+ "analytics",
3659
+ "logging",
3660
+ "monitoring",
3661
+ "metrics",
3662
+ "tracing",
3663
+ "sqlite",
3664
+ "embedded",
3665
+ "bun",
3666
+ "nodejs"
3667
+ ],
3668
+ license: "MIT",
3669
+ engines: {
3670
+ node: ">=18.0.0"
3671
+ },
3672
+ repository: {
3673
+ type: "git",
3674
+ url: "git+https://github.com/blakbelt78/surrge.git"
3675
+ },
3676
+ homepage: "https://github.com/blakbelt78/surrge#readme",
3677
+ bugs: {
3678
+ url: "https://github.com/blakbelt78/surrge/issues"
3679
+ },
3680
+ author: "blakbelt78",
3681
+ sideEffects: [
3682
+ "./dist/register.js",
3683
+ "./dist/loader.js",
3684
+ "./dist/hooks.js"
3685
+ ]
3686
+ };
3598
3687
 
3599
3688
  // src/collector.ts
3600
3689
  var exports_collector = {};
@@ -8898,10 +8987,8 @@ var patchProcessStdout = () => {
8898
8987
  };
8899
8988
  var patchFsWriteSync = () => {
8900
8989
  const originalWriteSync = fs.writeSync;
8901
- console.log("[surrge] Patching fs.writeSync");
8902
8990
  fs.writeSync = (fd, buffer2, ...args) => {
8903
8991
  if (fd === STDOUT_FD) {
8904
- console.log("[surrge] fs.writeSync intercepted for stdout");
8905
8992
  captureOutput(buffer2);
8906
8993
  }
8907
8994
  return originalWriteSync(fd, buffer2, ...args);
@@ -8918,20 +9005,30 @@ var patchFsWrite = () => {
8918
9005
  };
8919
9006
  var patchBunWrite = () => {
8920
9007
  const Bun2 = globalThis.Bun;
8921
- if (!Bun2?.write)
9008
+ if (!Bun2)
8922
9009
  return;
8923
- const originalWrite = Bun2.write;
8924
- Bun2.write = (dest, data, ...args) => {
8925
- if (dest === STDOUT_FD || dest === process.stdout) {
8926
- if (typeof data === "string" || data instanceof Uint8Array) {
9010
+ const BunStdout = Bun2.stdout;
9011
+ if (Bun2.write) {
9012
+ const originalWrite = Bun2.write;
9013
+ Bun2.write = (dest, data, ...args) => {
9014
+ const isStdout = dest === STDOUT_FD || dest === process.stdout || dest === BunStdout;
9015
+ if (isStdout && (typeof data === "string" || data instanceof Uint8Array)) {
8927
9016
  captureOutput(data);
8928
9017
  }
8929
- }
8930
- return originalWrite(dest, data, ...args);
8931
- };
9018
+ return originalWrite(dest, data, ...args);
9019
+ };
9020
+ }
9021
+ const bunStdout = BunStdout;
9022
+ if (bunStdout?.write) {
9023
+ const originalBunStdoutWrite = bunStdout.write.bind(bunStdout);
9024
+ bunStdout.write = (data) => {
9025
+ captureOutput(data);
9026
+ return originalBunStdoutWrite(data);
9027
+ };
9028
+ }
8932
9029
  };
8933
9030
  var captureOutput = (chunk) => {
8934
- const text = typeof chunk === "string" ? chunk : Buffer.from(chunk.buffer).toString();
9031
+ const text = typeof chunk === "string" ? chunk : Buffer.isBuffer(chunk) ? chunk.toString() : new TextDecoder().decode(chunk);
8935
9032
  buffer += text;
8936
9033
  const lines = buffer.split(`
8937
9034
  `);
@@ -10766,91 +10863,6 @@ var handleDashboard = async (req, res) => {
10766
10863
  response.headers.forEach((value, key) => res.setHeader(key, value));
10767
10864
  res.end(await response.text());
10768
10865
  };
10769
- // package.json
10770
- var package_default = {
10771
- name: "surrge",
10772
- version: "0.4.1",
10773
- description: "One-line observability + analytics for Node.js/Bun",
10774
- type: "module",
10775
- exports: {
10776
- ".": {
10777
- types: "./dist/index.d.ts",
10778
- import: "./dist/index.js"
10779
- },
10780
- "./register": {
10781
- types: "./dist/register.d.ts",
10782
- import: "./dist/register.js"
10783
- },
10784
- "./loader": {
10785
- types: "./dist/loader.d.ts",
10786
- import: "./dist/loader.js"
10787
- }
10788
- },
10789
- bin: {
10790
- surrge: "./dist/cli.js"
10791
- },
10792
- files: [
10793
- "dist",
10794
- "README.md",
10795
- "LICENSE"
10796
- ],
10797
- scripts: {
10798
- preuninstall: "echo '[surrge] Your data in surrge.db has been preserved. To remove it: rm surrge.db'",
10799
- build: "bun run build:dashboard && bun run build:bundle && bun run build:types",
10800
- "build:bundle": "bun build ./src/index.ts ./src/register.ts ./src/loader.ts ./src/hooks.ts ./src/cli.ts --outdir=./dist --target=node",
10801
- "build:types": "tsc --emitDeclarationOnly",
10802
- "build:dashboard": "cd src/dashboard/ui && bun run build.ts",
10803
- "dev:dashboard": "cd src/dashboard/ui && bun run dev",
10804
- dev: "bun --watch src/index.ts",
10805
- test: "bun test",
10806
- check: "tsc --noEmit",
10807
- lint: "biome check --write .",
10808
- prepublishOnly: "bun run check && bun test && bun run build",
10809
- push: "npm publish",
10810
- db: "./bin/db.sh"
10811
- },
10812
- dependencies: {
10813
- "@libsql/client": "^0.14.0",
10814
- hono: "^4.6.0"
10815
- },
10816
- devDependencies: {
10817
- "@biomejs/biome": "^2.3.10",
10818
- "@types/node": "^22.0.0",
10819
- "bun-types": "^1.3.5",
10820
- express: "^5.2.1",
10821
- typescript: "^5.7.0"
10822
- },
10823
- keywords: [
10824
- "observability",
10825
- "analytics",
10826
- "logging",
10827
- "monitoring",
10828
- "metrics",
10829
- "tracing",
10830
- "sqlite",
10831
- "embedded",
10832
- "bun",
10833
- "nodejs"
10834
- ],
10835
- license: "MIT",
10836
- engines: {
10837
- node: ">=18.0.0"
10838
- },
10839
- repository: {
10840
- type: "git",
10841
- url: "git+https://github.com/blakbelt78/surrge.git"
10842
- },
10843
- homepage: "https://github.com/blakbelt78/surrge#readme",
10844
- bugs: {
10845
- url: "https://github.com/blakbelt78/surrge/issues"
10846
- },
10847
- author: "blakbelt78",
10848
- sideEffects: [
10849
- "./dist/register.js",
10850
- "./dist/loader.js",
10851
- "./dist/hooks.js"
10852
- ]
10853
- };
10854
10866
 
10855
10867
  // src/register.ts
10856
10868
  init();
@@ -10860,10 +10872,17 @@ start3();
10860
10872
  var isBun = typeof globalThis.Bun !== "undefined";
10861
10873
  if (isBun) {
10862
10874
  patch5();
10875
+ patch6();
10863
10876
  } else {
10864
10877
  patch6();
10865
10878
  }
10866
10879
  setInterval(() => {
10867
10880
  cleanup();
10868
10881
  }, 24 * 60 * 60 * 1000).unref();
10882
+ process.on("beforeExit", () => {
10883
+ stop();
10884
+ });
10885
+ process.on("exit", () => {
10886
+ stop();
10887
+ });
10869
10888
  console.log(`[surrge] v${package_default.version} → /surrge`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "surrge",
3
- "version": "0.4.1",
3
+ "version": "0.4.6",
4
4
  "description": "One-line observability + analytics for Node.js/Bun",
5
5
  "type": "module",
6
6
  "exports": {
@@ -22,6 +22,7 @@
22
22
  },
23
23
  "files": [
24
24
  "dist",
25
+ "!dist/**/*.test.*",
25
26
  "README.md",
26
27
  "LICENSE"
27
28
  ],
@@ -48,8 +49,11 @@
48
49
  "@biomejs/biome": "^2.3.10",
49
50
  "@types/node": "^22.0.0",
50
51
  "bun-types": "^1.3.5",
52
+ "elysia": "^1.4.19",
51
53
  "express": "^5.2.1",
52
- "typescript": "^5.7.0"
54
+ "pino": "^10.1.0",
55
+ "typescript": "^5.7.0",
56
+ "winston": "^3.19.0"
53
57
  },
54
58
  "keywords": [
55
59
  "observability",