Skip to content

Commit

Permalink
chore: shrink extra bytes
Browse files Browse the repository at this point in the history
  • Loading branch information
antongolub committed Dec 6, 2024
1 parent 6b1eb65 commit d1e89a8
Show file tree
Hide file tree
Showing 10 changed files with 36 additions and 35 deletions.
4 changes: 0 additions & 4 deletions src/main/ts/spawn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ export type TSpawnResult = {
ctx: TSpawnCtxNormalized
error?: TSpawnError,
child?: TChild
stack: string
}

export type TSpawnListeners = {
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -263,7 +260,6 @@ export const invoke = (c: TSpawnCtxNormalized): TSpawnCtxNormalized => {
stdall: '',
stdio,
duration: Date.now() - now,
stack: c.stack,
ctx: c
}
)
Expand Down
12 changes: 5 additions & 7 deletions src/main/ts/zurk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@ export const zurkifyPromise = (target: Promise<TZurk> | 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)
Expand All @@ -107,11 +106,11 @@ export const zurkifyPromise = (target: Promise<TZurk> | 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
}
Expand Down Expand Up @@ -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() }
Expand Down
10 changes: 10 additions & 0 deletions target/cjs/index.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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);
Expand Down
3 changes: 0 additions & 3 deletions target/cjs/spawn.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,6 @@ var invoke = (c) => {
},
stdio,
duration: Date.now() - now,
stack: c.stack,
ctx: c
}));
c.ee.emit("end", c.fulfilled, c);
Expand Down Expand Up @@ -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);
Expand All @@ -231,7 +229,6 @@ var invoke = (c) => {
stdall: "",
stdio,
duration: Date.now() - now,
stack: c.stack,
ctx: c
}
);
Expand Down
13 changes: 5 additions & 8 deletions target/cjs/zurk.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
1 change: 0 additions & 1 deletion target/dts/spawn.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ export type TSpawnResult = {
ctx: TSpawnCtxNormalized;
error?: TSpawnError;
child?: TChild;
stack: string;
};
export type TSpawnListeners = {
start: (data: TChild, ctx: TSpawnCtxNormalized) => void;
Expand Down
2 changes: 1 addition & 1 deletion target/dts/zurk.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export declare const zurk: <T extends TZurkOptions = Partial<Omit<TZurkCtx, "cal
export declare const zurkAsync: (opts: TZurkOptions) => TZurkPromise;
export declare const zurkSync: (opts: TZurkOptions) => TZurk;
export declare const zurkifyPromise: (target: Promise<TZurk> | 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;
Expand Down
10 changes: 10 additions & 0 deletions target/esm/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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);
Expand Down
3 changes: 0 additions & 3 deletions target/esm/spawn.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,6 @@ var invoke = (c) => {
},
stdio,
duration: Date.now() - now,
stack: c.stack,
ctx: c
});
c.ee.emit("end", c.fulfilled, c);
Expand Down Expand Up @@ -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);
Expand All @@ -210,7 +208,6 @@ var invoke = (c) => {
stdall: "",
stdio,
duration: Date.now() - now,
stack: c.stack,
ctx: c
}
);
Expand Down
13 changes: 5 additions & 8 deletions target/esm/zurk.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit d1e89a8

Please sign in to comment.