From d1e89a8637005e1b9033a14db730876bb39816d0 Mon Sep 17 00:00:00 2001 From: Anton Golub Date: Fri, 6 Dec 2024 18:28:08 +0300 Subject: [PATCH] chore: shrink extra bytes --- src/main/ts/spawn.ts | 4 ---- src/main/ts/zurk.ts | 12 +++++------- target/cjs/index.cjs | 10 ++++++++++ target/cjs/spawn.cjs | 3 --- target/cjs/zurk.cjs | 13 +++++-------- target/dts/spawn.d.ts | 1 - target/dts/zurk.d.ts | 2 +- target/esm/index.mjs | 10 ++++++++++ target/esm/spawn.mjs | 3 --- target/esm/zurk.mjs | 13 +++++-------- 10 files changed, 36 insertions(+), 35 deletions(-) diff --git a/src/main/ts/spawn.ts b/src/main/ts/spawn.ts index 4726c52..e4582b5 100644 --- a/src/main/ts/spawn.ts +++ b/src/main/ts/spawn.ts @@ -33,7 +33,6 @@ export type TSpawnResult = { ctx: TSpawnCtxNormalized error?: TSpawnError, child?: TChild - stack: string } export type TSpawnListeners = { @@ -187,7 +186,6 @@ export const invoke = (c: TSpawnCtxNormalized): TSpawnCtxNormalized => { get stdall() { return c.store.stdall.join('') }, stdio, duration: Date.now() - now, - stack: c.stack, ctx: c }) c.ee.emit('end', c.fulfilled, c) @@ -242,7 +240,6 @@ export const invoke = (c: TSpawnCtxNormalized): TSpawnCtxNormalized => { get stdall() { return c.store.stdall.join('') }, stdio, duration: Date.now() - now, - stack: c.stack, ctx: c } opts.signal?.removeEventListener('abort', onAbort) @@ -263,7 +260,6 @@ export const invoke = (c: TSpawnCtxNormalized): TSpawnCtxNormalized => { stdall: '', stdio, duration: Date.now() - now, - stack: c.stack, ctx: c } ) diff --git a/src/main/ts/zurk.ts b/src/main/ts/zurk.ts index 4f145b0..d9ea9e4 100644 --- a/src/main/ts/zurk.ts +++ b/src/main/ts/zurk.ts @@ -95,7 +95,6 @@ export const zurkifyPromise = (target: Promise | TZurkPromise, ctx: TSpaw if (p === 'stdio') return ctx.stdio if (p === 'ctx') return ctx if (p === 'child') return ctx.child - if (p === 'stack') return ctx.stack if (p === 'on') return function (name: string, cb: VoidFunction){ ctx.ee.on(name, cb); return proxy } if (p in target) return Reflect.get(target, p, receiver) @@ -107,11 +106,11 @@ export const zurkifyPromise = (target: Promise | TZurkPromise, ctx: TSpaw return proxy } -export const getError = (data: TSpawnResult): Error | null => { - if (data.error) - return new Error(formatErrorMessage(data.error, data.stack)) - if (data.status || data.signal) - return new Error(formatExitMessage(data.status, data.signal, data.stderr, data.stack)) +export const getError = (spawnResult: TSpawnResult): Error | null => { + if (spawnResult.error) + return new Error(formatErrorMessage(spawnResult.error, spawnResult.ctx.stack)) + if (spawnResult.status || spawnResult.signal) + return new Error(formatExitMessage(spawnResult.status, spawnResult.signal, spawnResult.stderr, spawnResult.ctx.stack)) return null } @@ -142,7 +141,6 @@ class Zurk implements TZurk { this.ctx.stdout, this.ctx.stderr ]} - get stack() { return this.ctx.stack } get duration() { return this.ctx.fulfilled?.duration ?? 0 } toString(){ return this.stdall.trim() } valueOf(){ return this.stdall.trim() } diff --git a/target/cjs/index.cjs b/target/cjs/index.cjs index acab54b..a020ba2 100644 --- a/target/cjs/index.cjs +++ b/target/cjs/index.cjs @@ -23,6 +23,15 @@ var import_spawn2 = require("./spawn.cjs"); var import_zurk4 = require("./zurk.cjs"); var import_util4 = require("./util.cjs"); +// src/main/ts/error.ts +function getCallerLocation(err = new Error("zurk error")) { + return getCallerLocationFromString(err.stack); +} +function getCallerLocationFromString(stackString = "unknown") { + var _a; + return ((_a = stackString.split(/^\s*(at\s)?/m).filter((s) => s == null ? void 0 : s.includes(":"))[2]) == null ? void 0 : _a.trim()) || stackString; +} + // src/main/ts/mixin/pipe.ts var import_node_stream = require("stream"); var import_util = require("./util.cjs"); @@ -126,6 +135,7 @@ var timeoutMixin = ($2, result, ctx) => { var $ = function(pieces, ...args) { const self = this !== import_util4.g && this; const preset = self || {}; + preset.stack = preset.stack || getCallerLocation(); if (pieces === void 0) return applyMixins($, preset); if ((0, import_util4.isStringLiteral)(pieces, ...args)) return ignite(preset, pieces, ...args); return (...args2) => $.apply(self ? (0, import_util4.assign)(self, pieces) : pieces, args2); diff --git a/target/cjs/spawn.cjs b/target/cjs/spawn.cjs index 759f090..f6ab523 100644 --- a/target/cjs/spawn.cjs +++ b/target/cjs/spawn.cjs @@ -155,7 +155,6 @@ var invoke = (c) => { }, stdio, duration: Date.now() - now, - stack: c.stack, ctx: c })); c.ee.emit("end", c.fulfilled, c); @@ -210,7 +209,6 @@ var invoke = (c) => { }, stdio, duration: Date.now() - now, - stack: c.stack, ctx: c }; (_a3 = opts.signal) == null ? void 0 : _a3.removeEventListener("abort", onAbort); @@ -231,7 +229,6 @@ var invoke = (c) => { stdall: "", stdio, duration: Date.now() - now, - stack: c.stack, ctx: c } ); diff --git a/target/cjs/zurk.cjs b/target/cjs/zurk.cjs index 29aec18..0454caf 100644 --- a/target/cjs/zurk.cjs +++ b/target/cjs/zurk.cjs @@ -260,11 +260,11 @@ var zurkifyPromise = (target, ctx) => { }); return proxy; }; -var getError = (data) => { - if (data.error) - return new Error(formatErrorMessage(data.error, data.stack)); - if (data.status || data.signal) - return new Error(formatExitMessage(data.status, data.signal, data.stderr, data.stack)); +var getError = (spawnResult) => { + if (spawnResult.error) + return new Error(formatErrorMessage(spawnResult.error, spawnResult.ctx.stack)); + if (spawnResult.status || spawnResult.signal) + return new Error(formatExitMessage(spawnResult.status, spawnResult.signal, spawnResult.stderr, spawnResult.ctx.stack)); return null; }; var isZurkAny = (o) => (o == null ? void 0 : o[ZURK]) === ZURK; @@ -317,9 +317,6 @@ var Zurk = class { this.ctx.stderr ]; } - get stack() { - return this.ctx.stack; - } get duration() { var _a2, _b; return (_b = (_a2 = this.ctx.fulfilled) == null ? void 0 : _a2.duration) != null ? _b : 0; diff --git a/target/dts/spawn.d.ts b/target/dts/spawn.d.ts index 3116c42..1b25c0d 100644 --- a/target/dts/spawn.d.ts +++ b/target/dts/spawn.d.ts @@ -30,7 +30,6 @@ export type TSpawnResult = { ctx: TSpawnCtxNormalized; error?: TSpawnError; child?: TChild; - stack: string; }; export type TSpawnListeners = { start: (data: TChild, ctx: TSpawnCtxNormalized) => void; diff --git a/target/dts/zurk.d.ts b/target/dts/zurk.d.ts index ab627bb..c5476fe 100644 --- a/target/dts/zurk.d.ts +++ b/target/dts/zurk.d.ts @@ -29,7 +29,7 @@ export declare const zurk: TZurkPromise; export declare const zurkSync: (opts: TZurkOptions) => TZurk; export declare const zurkifyPromise: (target: Promise | TZurkPromise, ctx: TSpawnCtxNormalized) => TZurkPromise; -export declare const getError: (data: TSpawnResult) => Error | null; +export declare const getError: (spawnResult: TSpawnResult) => Error | null; export declare const isZurkAny: (o: any) => o is TZurk | TZurkPromise; export declare const isZurk: (o: any) => o is TZurk; export declare const isZurkPromise: (o: any) => o is TZurkPromise; diff --git a/target/esm/index.mjs b/target/esm/index.mjs index 7480c6b..1ec42f9 100644 --- a/target/esm/index.mjs +++ b/target/esm/index.mjs @@ -18,6 +18,15 @@ import { immediate } from "./util.mjs"; +// src/main/ts/error.ts +function getCallerLocation(err = new Error("zurk error")) { + return getCallerLocationFromString(err.stack); +} +function getCallerLocationFromString(stackString = "unknown") { + var _a; + return ((_a = stackString.split(/^\s*(at\s)?/m).filter((s) => s == null ? void 0 : s.includes(":"))[2]) == null ? void 0 : _a.trim()) || stackString; +} + // src/main/ts/mixin/pipe.ts import { Writable } from "node:stream"; import { assign, isStringLiteral } from "./util.mjs"; @@ -121,6 +130,7 @@ var timeoutMixin = ($2, result, ctx) => { var $ = function(pieces, ...args) { const self = this !== g && this; const preset = self || {}; + preset.stack = preset.stack || getCallerLocation(); if (pieces === void 0) return applyMixins($, preset); if (isStringLiteral2(pieces, ...args)) return ignite(preset, pieces, ...args); return (...args2) => $.apply(self ? assign4(self, pieces) : pieces, args2); diff --git a/target/esm/spawn.mjs b/target/esm/spawn.mjs index 6e4a17a..62f7f7e 100644 --- a/target/esm/spawn.mjs +++ b/target/esm/spawn.mjs @@ -134,7 +134,6 @@ var invoke = (c) => { }, stdio, duration: Date.now() - now, - stack: c.stack, ctx: c }); c.ee.emit("end", c.fulfilled, c); @@ -189,7 +188,6 @@ var invoke = (c) => { }, stdio, duration: Date.now() - now, - stack: c.stack, ctx: c }; (_a3 = opts.signal) == null ? void 0 : _a3.removeEventListener("abort", onAbort); @@ -210,7 +208,6 @@ var invoke = (c) => { stdall: "", stdio, duration: Date.now() - now, - stack: c.stack, ctx: c } ); diff --git a/target/esm/zurk.mjs b/target/esm/zurk.mjs index ae0ec43..0d74f7e 100644 --- a/target/esm/zurk.mjs +++ b/target/esm/zurk.mjs @@ -247,11 +247,11 @@ var zurkifyPromise = (target, ctx) => { }); return proxy; }; -var getError = (data) => { - if (data.error) - return new Error(formatErrorMessage(data.error, data.stack)); - if (data.status || data.signal) - return new Error(formatExitMessage(data.status, data.signal, data.stderr, data.stack)); +var getError = (spawnResult) => { + if (spawnResult.error) + return new Error(formatErrorMessage(spawnResult.error, spawnResult.ctx.stack)); + if (spawnResult.status || spawnResult.signal) + return new Error(formatExitMessage(spawnResult.status, spawnResult.signal, spawnResult.stderr, spawnResult.ctx.stack)); return null; }; var isZurkAny = (o) => (o == null ? void 0 : o[ZURK]) === ZURK; @@ -304,9 +304,6 @@ var Zurk = class { this.ctx.stderr ]; } - get stack() { - return this.ctx.stack; - } get duration() { var _a2, _b; return (_b = (_a2 = this.ctx.fulfilled) == null ? void 0 : _a2.duration) != null ? _b : 0;