@lowlighter/run 1.0.1 → 1.0.3

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/README.md CHANGED
@@ -6,9 +6,12 @@
6
6
  - [`🦕 Playground`](https://libs.lecoq.io/run)
7
7
  - [`📚 Documentation`](https://jsr.io/@libs/run/doc)
8
8
 
9
+ > [!WARNING]
10
+ > Deno exclusive!
11
+
9
12
  ## 📜 Licenses
10
13
 
11
- ```
12
- Copyright (c) Lecoq Simon <@lowlighter>. (MIT License)
14
+ ```plaintext
15
+ Copyright (c) Simon Lecoq <@lowlighter>. (MIT License)
13
16
  https://github.com/lowlighter/libs/blob/main/LICENSE
14
17
  ```
package/command.mjs CHANGED
@@ -1,4 +1,4 @@
1
- var e=class e{constructor({level:t,format:n,output:o,tags:r,options:s}={}){if("granted"===globalThis.Deno?.permissions.querySync?.({name:"env",variable:"LOG_LEVEL"}).state){const n=globalThis.Deno?.env.get("LOG_LEVEL")??"";n in e.level&&(t??=e.level[n]),Number.isNaN(Number.parseInt(n))||(t??=Number.parseInt(n))}this.level=t??e.level.log,this.#e=o||null===o?o:console,this.#t=n??e.format.text,this.tags=r??{},this.options={date:!1,time:!1,delta:!0,...s,caller:!1!==s?.caller&&{file:!1,name:!1,line:!1,...s?.caller}}}level;#t;#e;tags;options;error(...t){return this.level>=e.level.error&&this.#e?.error(...this.#t(this,{level:e.level.error,content:t})),this}warn(...t){return this.level>=e.level.warn&&this.#e?.warn(...this.#t(this,{level:e.level.warn,content:t})),this}info(...t){return this.level>=e.level.info&&this.#e?.info(...this.#t(this,{level:e.level.info,content:t})),this}log(...t){return this.level>=e.level.log&&this.#e?.log(...this.#t(this,{level:e.level.log,content:t})),this}debug(...t){return this.level>=e.level.debug&&this.#e?.debug(...this.#t(this,{level:e.level.debug,content:t})),this}with(t={}){return new e({level:this.level,format:this.#t,output:this.#e,options:{...this.options},tags:{...this.tags,...t}})}#n(e=3){const t=Error,n=t.prepareStackTrace;t.prepareStackTrace=(e,t)=>t;const{stack:o}=new Error;t.prepareStackTrace=n;const r=o[e];return{file:r.getFileName(),name:r.getFunctionName(),line:r.getLineNumber(),column:r.getColumnNumber()}}static level=Object.freeze({disabled:NaN,error:0,warn:1,info:2,log:3,debug:4});static format={text(t,{level:n=0,content:o}){const r=["red","orange","cyan","white","gray"][n],s=[`%c ${Object.keys(e.level).find((t=>e.level[t]===n)).toLocaleUpperCase().padEnd(5)} │%c`],i=[`color: black; background-color: ${r}`,""];if(t.options.date||t.options.time||t.options.delta){const e=(new Date).toISOString(),n=[];if(t.options.delta){const e=performance.now()/1e3;let t=e.toPrecision(4);e<1&&(t=e.toPrecision(2)),n.push(`+${t}`)}t.options.date&&t.options.time?n.push(e):t.options.date?n.push(e.slice(0,e.indexOf("T"))):t.options.time&&n.push(e.slice(e.indexOf("T")+1,-1)),s.push(`%c ${n.join(" ¦ ").trim()} %c`),i.push(`color: black; background-color: ${r}`,"")}if(t.options.caller){const e=t.#n();if(e){const n=[];t.options.caller.file&&n.push(`${e.file.replace(t.options.caller.fileformat,"$<file>")}`),t.options.caller.name&&e.name&&n.push(e.name),t.options.caller.line&&n.push(e.line,e.column),s.push(`%c ${n.join(":").trim()} %c`),i.push("color: black; background-color: gray","")}}{const n=[];for(const[o,r]of Object.entries(t.tags))n.push(`${o}:${e.inspect(r)}`);s.push(`%c ${n.join(" ").trim()} %c`),i.push("background-color: black","")}return[s.join(""),...i,...o.map(e.inspect)]},json(t,{level:n=0,content:o}){const r={level:Object.keys(e.level).find((t=>e.level[t]===n)),timestamp:Date.now(),tags:t.tags,content:o},s={};if(t.options.date||t.options.time){const e=new Date(r.timestamp).toISOString();t.options.date&&(s.date=e.slice(0,e.indexOf("T"))),t.options.time&&(s.time=e.slice(e.indexOf("T")+1,-1))}if(t.options.delta&&(s.delta=performance.now()/1e3),t.options.caller){const e=t.#n();e&&(s.caller={},t.options.caller.file&&(s.caller.file=`${e.file.replace(t.options.caller.fileformat,"$<file>")}`),t.options.caller.name&&e.name&&(s.caller.name=e.name),t.options.caller.line&&(s.caller.line=[e.line,e.column]))}return[JSON.stringify({...r,...s})]}};static inspect(e){return globalThis.Deno?.inspect(e,{colors:!0,depth:1/0})??e}},t=class extends Error{constructor(e){super(e),this.name="AssertionError"}};TransformStream;function n(e){let t=0;for(const n of e)t+=n.length;const n=new Uint8Array(t);let o=0;for(const t of e)n.set(t,o),o+=t.length;return n}function o(e){const t=e.length,n=new Uint8Array(t);n[0]=0;let o=0,r=1;for(;r<t;)e[r]===e[o]?(o++,n[r]=o,r++):0===o?(n[r]=0,r++):o=n[o-1];return n}TransformStream,TransformStream,TransformStream,TransformStream;var r=class extends TransformStream{#o="";constructor(e={allowCR:!1}){super({transform:(t,n)=>{for(t=this.#o+t;;){const o=t.indexOf("\n"),r=e.allowCR?t.indexOf("\r"):-1;if(-1!==r&&r!==t.length-1&&(-1===o||o-1>r)){n.enqueue(t.slice(0,r)),t=t.slice(r+1);continue}if(-1===o)break;const s="\r"===t[o-1]?o-1:o;n.enqueue(t.slice(0,s)),t=t.slice(o+1)}this.#o=t},flush:t=>{if(""===this.#o)return;const n=e.allowCR&&this.#o.endsWith("\r")?this.#o.slice(0,-1):this.#o;t.enqueue(n)}})}};new TextDecoder;var s=new TextEncoder,i=new TextDecoder;function l(t,n,{log:o=new e,stdin:l=null,stdout:a="debug",stderr:u="error",env:d,cwd:p,raw:h,callback:f,buffering:m,sync:w,throw:g,dryrun:b,winext:v="",os:T=Deno.build.os}={}){"windows"===T&&(t=`${t}${v}`),o=o.with({bin:t}),f&&"piped"!==c(l)&&(l="piped");const $=new Deno.Command(t,{args:n,stdin:w?"null":c(l),stdout:c(a),stderr:c(u),env:d,cwd:p,windowsRawArguments:h});if(b){o.debug(`dryrun: ${t} not executed`);const e={success:!0,code:0,stdio:[],stdin:"",stdout:"",stderr:""};return w?e:Promise.resolve(e)}return w?function(e,{bin:t,log:n,throw:o,stdout:r,stderr:s}){const l=Date.now(),a=e.outputSync(),{success:u,code:d}=a,p=Date.now()-l,h={get stdio(){return[[p,1,this.stdout],[p,2,this.stderr]]},stdin:"",stdout:"piped"===c(r)?i.decode(a.stdout):"",stderr:"piped"===c(s)?i.decode(a.stderr):""};for(const{channel:e,mode:t}of[{channel:"stdout",mode:r},{channel:"stderr",mode:s}])"piped"===c(t)&&h[e]&&n.with({t:p,channel:e})[t]?.(h[e]);if(!u&&o)throw new EvalError(`${t} exited with non-zero code ${d}:\n${h.stdout}\n${h.stderr}`);return{success:u,code:d,...h}}($,{bin:t,log:o,throw:g,stdout:a,stderr:u}):async function(e,{bin:t,log:n,callback:o=(({close:e})=>e?.()),buffering:i=250,throw:l,...a}){const u=e.spawn(),d=Date.now(),p={stdio:[],get stdin(){return this.stdio.filter((([e,t])=>0===t)).map((([e,t,n])=>n)).join("\n")},get stdout(){return this.stdio.filter((([e,t])=>1===t)).map((([e,t,n])=>n)).join("\n")},get stderr(){return this.stdio.filter((([e,t])=>2===t)).map((([e,t,n])=>n)).join("\n")}},h={};let f="";const m=function(e,t){let n=null,o=null;const r=(...s)=>{r.clear(),o=()=>{r.clear(),e.call(r,...s)},n=setTimeout(o,t)};return r.clear=()=>{"number"==typeof n&&(clearTimeout(n),n=null,o=null)},r.flush=()=>{o?.()},Object.defineProperty(r,"pending",{get:()=>"number"==typeof n}),r}((async e=>{n.with({t:e}).debug("debounced"),f="",await o({stdio:p,i:p.stdin.length,...h})}),i);if("piped"===c(a.stdin)){const e=u.stdin.getWriter();Object.assign(h,{async write(t,o=!0){const r=Date.now()-d;a.stdin&&n.with({t:r,channel:"stdin"})[a.stdin]?.(t),p.stdio.push([r,0,t]),o&&!t.endsWith("\n")&&(t+="\n"),await e.write(s.encode(t)),f="stdin",e.releaseLock()},async close(){try{e.releaseLock(),await u.stdin.close(),n.with({t:Date.now()-d,closed:"stdin"}).debug()}catch{}},async wait(e=1e3){const t=Date.now()-d;n.with({t:t,waiting:e}).debug(),await function(e,t={}){const{signal:n,persistent:o=!0}=t;return n?.aborted?Promise.reject(n.reason):new Promise(((t,r)=>{const s=()=>{clearTimeout(i),r(n?.reason)},i=setTimeout((()=>{n?.removeEventListener("abort",s),t()}),e);if(n?.addEventListener("abort",s,{once:!0}),!1===o)try{Deno.unrefTimer(i)}catch(e){if(!(e instanceof ReferenceError))throw e;console.error("`persistent` option is only available in Deno")}}))}(e),m(t)}}),m(Date.now()-d)}await Promise.all(["stdout","stderr"].filter((e=>"piped"===c(a[e]))).map((async e=>{for await(const t of u[e].pipeThrough(new TextDecoderStream).pipeThrough(new r)){const o=Date.now()-d,r={stdout:1,stderr:2}[e];if(a[e]&&n.with({t:o,channel:e})[a[e]]?.(t),p.stdio.length&&f===e){const e=p.stdio.at(-1);e[1]===r&&(e[2]+=`\n${t}`)}else p.stdio.push([o,r,t]);f=e,m(o)}}))),m.flush();const{success:w,code:g}=await u.status;if(!w&&l)throw new EvalError(`${t} exited with non-zero code ${g}:\n${p.stdout}\n${p.stderr}`);return{success:w,code:g,...p}}($,{bin:t,log:o,callback:f,buffering:m,throw:g,stdin:"piped"===c(l)?l:null,stdout:"piped"===c(a)?a:null,stderr:"piped"===c(u)?u:null})}function c(e){return["inherit","null"].includes(`${e}`)?`${e}`:"piped"}export{l as command};
1
+ var e=class e{constructor({level:t,format:n,output:o,tags:r,options:s}={}){if("granted"===globalThis.Deno?.permissions.querySync?.({name:"env",variable:"LOG_LEVEL"}).state){const n=globalThis.Deno?.env.get("LOG_LEVEL")??"";n in e.level&&(t??=e.level[n]),Number.isNaN(Number.parseInt(n))||(t??=Number.parseInt(n))}this.level=t??e.level.log,this.#e=o||null===o?o:console,this.#t=n??e.format.text,this.tags=r??{},this.options={date:!1,time:!1,delta:!0,...s,caller:!1!==s?.caller&&{file:!1,name:!1,line:!1,...s?.caller}}}level;#t;#e;tags;options;error(...t){return this.level>=e.level.error&&this.#e?.error(...this.#t(this,{level:e.level.error,content:t})),this}warn(...t){return this.level>=e.level.warn&&this.#e?.warn(...this.#t(this,{level:e.level.warn,content:t})),this}info(...t){return this.level>=e.level.info&&this.#e?.info(...this.#t(this,{level:e.level.info,content:t})),this}log(...t){return this.level>=e.level.log&&this.#e?.log(...this.#t(this,{level:e.level.log,content:t})),this}debug(...t){return this.level>=e.level.debug&&this.#e?.debug(...this.#t(this,{level:e.level.debug,content:t})),this}with(t={}){return new e({level:this.level,format:this.#t,output:this.#e,options:{...this.options},tags:{...this.tags,...t}})}#n(e=3){const t=Error,n=t.prepareStackTrace;t.prepareStackTrace=(e,t)=>t;const{stack:o}=new Error;t.prepareStackTrace=n;const r=o[e];return{file:r.getFileName(),name:r.getFunctionName(),line:r.getLineNumber(),column:r.getColumnNumber()}}static level=Object.freeze({disabled:NaN,error:0,warn:1,info:2,log:3,debug:4});static format={text(t,{level:n=0,content:o}){const r=["red","orange","cyan","white","gray"][n],s=[`%c ${Object.keys(e.level).find((t=>e.level[t]===n)).toLocaleUpperCase().padEnd(5)} │%c`],i=[`color: black; background-color: ${r}`,""];if(t.options.date||t.options.time||t.options.delta){const e=(new Date).toISOString(),n=[];if(t.options.delta){const e=performance.now()/1e3;let t=e.toPrecision(4);e<1&&(t=e.toPrecision(2)),n.push(`+${t}`)}t.options.date&&t.options.time?n.push(e):t.options.date?n.push(e.slice(0,e.indexOf("T"))):t.options.time&&n.push(e.slice(e.indexOf("T")+1,-1)),s.push(`%c ${n.join(" ¦ ").trim()} %c`),i.push(`color: black; background-color: ${r}`,"")}if(t.options.caller){const e=t.#n();if(e){const n=[];t.options.caller.file&&n.push(`${e.file.replace(t.options.caller.fileformat,"$<file>")}`),t.options.caller.name&&e.name&&n.push(e.name),t.options.caller.line&&n.push(e.line,e.column),s.push(`%c ${n.join(":").trim()} %c`),i.push("color: black; background-color: gray","")}}{const n=[];for(const[o,r]of Object.entries(t.tags))n.push(`${o}:${e.inspect(r)}`);s.push(`%c ${n.join(" ").trim()} %c`),i.push("background-color: black","")}return[s.join(""),...i,...o.map(e.inspect)]},json(t,{level:n=0,content:o}){const r={level:Object.keys(e.level).find((t=>e.level[t]===n)),timestamp:Date.now(),tags:t.tags,content:o},s={};if(t.options.date||t.options.time){const e=new Date(r.timestamp).toISOString();t.options.date&&(s.date=e.slice(0,e.indexOf("T"))),t.options.time&&(s.time=e.slice(e.indexOf("T")+1,-1))}if(t.options.delta&&(s.delta=performance.now()/1e3),t.options.caller){const e=t.#n();e&&(s.caller={},t.options.caller.file&&(s.caller.file=`${e.file.replace(t.options.caller.fileformat,"$<file>")}`),t.options.caller.name&&e.name&&(s.caller.name=e.name),t.options.caller.line&&(s.caller.line=[e.line,e.column]))}return[JSON.stringify({...r,...s})]}};static inspect(e){return globalThis.Deno?.inspect(e,{colors:!0,depth:1/0,strAbbreviateSize:1/0})??e}};TransformStream;function t(e){let t=0;for(const n of e)t+=n.length;const n=new Uint8Array(t);let o=0;for(const t of e)n.set(t,o),o+=t.length;return n}function n(e){const t=e.length,n=new Uint8Array(t);n[0]=0;let o=0,r=1;for(;r<t;)e[r]===e[o]?(o++,n[r]=o,r++):0===o?(n[r]=0,r++):o=n[o-1];return n}TransformStream,TransformStream,TransformStream,TransformStream;var o=class extends TransformStream{#o="";constructor(e={allowCR:!1}){super({transform:(t,n)=>{for(t=this.#o+t;;){const o=t.indexOf("\n"),r=e.allowCR?t.indexOf("\r"):-1;if(-1!==r&&r!==t.length-1&&(-1===o||o-1>r)){n.enqueue(t.slice(0,r)),t=t.slice(r+1);continue}if(-1===o)break;const s="\r"===t[o-1]?o-1:o;n.enqueue(t.slice(0,s)),t=t.slice(o+1)}this.#o=t},flush:t=>{if(""===this.#o)return;const n=e.allowCR&&this.#o.endsWith("\r")?this.#o.slice(0,-1):this.#o;t.enqueue(n)}})}};new TextDecoder;var r=new TextEncoder,s=new TextDecoder;function i(t,n,{log:i=new e,stdin:a=null,stdout:c="debug",stderr:u="error",env:d,cwd:p,raw:h,callback:f,buffering:m,sync:w,throw:g,dryrun:b,winext:v="",os:T=Deno.build.os}={}){"windows"===T&&(t=`${t}${v}`),i=i.with({bin:t}),f&&"piped"!==l(a)&&(a="piped");const $=new Deno.Command(t,{args:n,stdin:w?"null":l(a),stdout:l(c),stderr:l(u),env:d,cwd:p,windowsRawArguments:h});if(b){i.debug(`dryrun: ${t} not executed`);const e={success:!0,code:0,stdio:[],stdin:"",stdout:"",stderr:""};return w?e:Promise.resolve(e)}return w?function(e,{bin:t,log:n,throw:o,stdout:r,stderr:i}){const a=Date.now(),c=e.outputSync(),{success:u,code:d}=c,p=Date.now()-a,h={get stdio(){return[[p,1,this.stdout],[p,2,this.stderr]]},stdin:"",stdout:"piped"===l(r)?s.decode(c.stdout):"",stderr:"piped"===l(i)?s.decode(c.stderr):""};for(const{channel:e,mode:t}of[{channel:"stdout",mode:r},{channel:"stderr",mode:i}])"piped"===l(t)&&h[e]&&n.with({t:p,channel:e})[t]?.(h[e]);if(!u&&o)throw new EvalError(`${t} exited with non-zero code ${d}:\n${h.stdout}\n${h.stderr}`);return{success:u,code:d,...h}}($,{bin:t,log:i,throw:g,stdout:c,stderr:u}):async function(e,{bin:t,log:n,callback:s=(({close:e})=>e?.()),buffering:i=250,throw:a,...c}){const u=e.spawn(),d=Date.now(),p={stdio:[],get stdin(){return this.stdio.filter((([e,t])=>0===t)).map((([e,t,n])=>n)).join("\n")},get stdout(){return this.stdio.filter((([e,t])=>1===t)).map((([e,t,n])=>n)).join("\n")},get stderr(){return this.stdio.filter((([e,t])=>2===t)).map((([e,t,n])=>n)).join("\n")}},h={};let f="";const m=function(e,t){let n=null,o=null;const r=(...s)=>{r.clear(),o=()=>{r.clear(),e.call(r,...s)},n=setTimeout(o,t)};return r.clear=()=>{"number"==typeof n&&(clearTimeout(n),n=null,o=null)},r.flush=()=>{o?.()},Object.defineProperty(r,"pending",{get:()=>"number"==typeof n}),r}((async e=>{n.with({t:e}).debug("debounced"),f="",await s({stdio:p,i:p.stdin.length,...h})}),i);if("piped"===l(c.stdin)){const e=u.stdin.getWriter();Object.assign(h,{async write(t,o=!0){const s=Date.now()-d;c.stdin&&n.with({t:s,channel:"stdin"})[c.stdin]?.(t),p.stdio.push([s,0,t]),o&&!t.endsWith("\n")&&(t+="\n"),await e.write(r.encode(t)),f="stdin",e.releaseLock()},async close(){try{e.releaseLock(),await u.stdin.close(),n.with({t:Date.now()-d,closed:"stdin"}).debug()}catch{}},async wait(e=1e3){const t=Date.now()-d;n.with({t:t,waiting:e}).debug(),await function(e,t={}){const{signal:n,persistent:o=!0}=t;return n?.aborted?Promise.reject(n.reason):new Promise(((t,r)=>{const s=()=>{clearTimeout(i),r(n?.reason)},i=setTimeout((()=>{n?.removeEventListener("abort",s),t()}),e);if(n?.addEventListener("abort",s,{once:!0}),!1===o)try{Deno.unrefTimer(i)}catch(e){if(!(e instanceof ReferenceError))throw e;console.error("`persistent` option is only available in Deno")}}))}(e),m(t)}}),m(Date.now()-d)}await Promise.all(["stdout","stderr"].filter((e=>"piped"===l(c[e]))).map((async e=>{for await(const t of u[e].pipeThrough(new TextDecoderStream).pipeThrough(new o)){const o=Date.now()-d,r={stdout:1,stderr:2}[e];if(c[e]&&n.with({t:o,channel:e})[c[e]]?.(t),p.stdio.length&&f===e){const e=p.stdio.at(-1);e[1]===r&&(e[2]+=`\n${t}`)}else p.stdio.push([o,r,t]);f=e,m(o)}}))),m.flush();const{success:w,code:g}=await u.status;if(!w&&a)throw new EvalError(`${t} exited with non-zero code ${g}:\n${p.stdout}\n${p.stderr}`);return{success:w,code:g,...p}}($,{bin:t,log:i,callback:f,buffering:m,throw:g,stdin:"piped"===l(a)?a:null,stdout:"piped"===l(c)?c:null,stderr:"piped"===l(u)?u:null})}function l(e){return["inherit","null"].includes(`${e}`)?`${e}`:"piped"}export{i as command};
2
2
  /**
3
3
  * Logger library
4
4
  *
package/command.ts CHANGED
@@ -1,9 +1,15 @@
1
+ /**
2
+ * @module
3
+ * A wrapper around `Deno.command` that provides a better handling of stdio for interactive processes.
4
+ */
5
+
1
6
  // Imports
2
7
  import type { Arg, Nullable, Promisable } from "@libs/typing"
3
8
  import { Logger, type loglevel } from "@libs/logger"
4
9
  import { TextLineStream } from "@std/streams"
5
10
  import { debounce } from "@std/async/debounce"
6
11
  import { delay } from "@std/async/delay"
12
+ export type { Logger, loglevel, Promisable }
7
13
 
8
14
  /** Run options. */
9
15
  export type options = {
@@ -80,7 +86,9 @@ const encoder = new TextEncoder()
80
86
  /** Text decoder */
81
87
  const decoder = new TextDecoder()
82
88
 
89
+ /** Asynchronous version of {@link command}. */
83
90
  export function command(bin: string, args: string[], options?: options & { sync?: false }): Promise<result>
91
+ /** Synchronous version of {@link command}. */
84
92
  export function command(bin: string, args: string[], options?: options & { sync: true }): result
85
93
  /**
86
94
  * Run a command.
package/deno.jsonc CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "icon": "⏯️",
3
3
  "name": "@libs/run",
4
- "version": "1.0.1",
4
+ "version": "1.0.3",
5
5
  "description": "Utilities to run subprocess.",
6
6
  "keywords": [
7
7
  "subprocess",
@@ -25,11 +25,11 @@
25
25
  "./command": "./command.ts"
26
26
  },
27
27
  "imports": {
28
- "@std/async/delay": "jsr:@std/async@0.224.1/delay",
29
- "@std/async/debounce": "jsr:@std/async@0.224.1/debounce",
30
- "@std/streams": "jsr:@std/streams@0.224.2",
31
- "@libs/logger": "jsr:@libs/logger@1",
32
- "@libs/testing": "jsr:@libs/testing@1",
28
+ "@std/async/delay": "jsr:@std/async@0.224.2/delay",
29
+ "@std/async/debounce": "jsr:@std/async@0.224.2/debounce",
30
+ "@std/streams": "jsr:@std/streams@0.224.5",
31
+ "@libs/logger": "jsr:@libs/logger@1.1.3",
32
+ "@libs/testing": "jsr:@libs/testing@2",
33
33
  "@libs/typing": "jsr:@libs/typing@2"
34
34
  },
35
35
  "test:permissions": {
@@ -42,11 +42,12 @@
42
42
  },
43
43
  "tasks": {
44
44
  "test": "deno test --allow-run=deno,node,bun,npx --no-prompt --coverage --clean --trace-leaks --doc",
45
- "dev": "deno fmt && deno task test --filter='/^\\[deno\\]/' && deno coverage --exclude=.js --detailed && deno lint && deno publish --dry-run --quiet --allow-dirty",
46
- "dev:future": "DENO_FUTURE=1 && deno task dev",
47
- "coverage": "deno task test --filter='/^\\[deno\\]/' --quiet && deno coverage --exclude=.js",
48
- "ci": "deno fmt --check && deno task test --filter='/^\\[node|bun \\]/' --quiet && deno coverage --exclude=.js && deno lint",
49
- "ci:coverage": "deno task coverage --html && sleep 1 && mkdir -p ../coverage && rm -rf ../coverage/run && mv coverage/html ../coverage/run"
45
+ "dev": "deno fmt && deno task test --filter='/^\\[deno\\]/' && deno coverage --exclude=.js --detailed && deno task lint",
46
+ "test:deno": "deno fmt --check && deno task test --filter='/^\\[deno\\]/' --quiet && deno coverage --exclude=.js && deno lint",
47
+ "test:deno-future": "DENO_FUTURE=1 && deno task test:deno",
48
+ "test:others": "deno fmt --check && deno task test --filter='/^\\[node|bun \\]/' --quiet && deno coverage --exclude=.js && deno lint",
49
+ "coverage:html": "deno fmt --check && deno task test --filter='/^\\[deno\\]/' --quiet && deno coverage --exclude=.js && deno lint",
50
+ "lint": "deno fmt --check && deno lint && deno doc --lint mod.ts && deno publish --dry-run --quiet --allow-dirty"
50
51
  },
51
52
  "lint": {
52
53
  "rules": {
@@ -73,6 +74,7 @@
73
74
  "**/package-lock.json",
74
75
  "**/wasm_*",
75
76
  "**/*.mjs"
76
- ]
77
+ ],
78
+ "proseWrap": "preserve"
77
79
  }
78
80
  }
package/deno.lock CHANGED
@@ -2,99 +2,94 @@
2
2
  "version": "3",
3
3
  "packages": {
4
4
  "specifiers": {
5
- "jsr:@libs/logger@1": "jsr:@libs/logger@1.1.1",
6
- "jsr:@libs/testing@1": "jsr:@libs/testing@1.0.7",
7
- "jsr:@libs/typing@2": "jsr:@libs/typing@2.1.0",
8
- "jsr:@std/assert@^0.224.0": "jsr:@std/assert@0.224.0",
9
- "jsr:@std/assert@^0.225.3": "jsr:@std/assert@0.225.3",
10
- "jsr:@std/async@0.224.1": "jsr:@std/async@0.224.1",
11
- "jsr:@std/bytes@^0.224.0": "jsr:@std/bytes@0.224.0",
12
- "jsr:@std/bytes@^1.0.0-rc.3": "jsr:@std/bytes@1.0.0-rc.3",
13
- "jsr:@std/expect@0.224.0": "jsr:@std/expect@0.224.0",
14
- "jsr:@std/fmt@^0.224.0": "jsr:@std/fmt@0.224.0",
15
- "jsr:@std/internal@^0.224.0": "jsr:@std/internal@0.224.0",
16
- "jsr:@std/io@^0.224.0": "jsr:@std/io@0.224.0",
17
- "jsr:@std/path@0.225.1": "jsr:@std/path@0.225.1",
18
- "jsr:@std/streams@0.224.2": "jsr:@std/streams@0.224.2",
19
- "npm:@types/node": "npm:@types/node@18.16.19"
5
+ "jsr:@libs/logger@1.1.3": "jsr:@libs/logger@1.1.3",
6
+ "jsr:@libs/testing@2": "jsr:@libs/testing@2.0.0",
7
+ "jsr:@libs/typing@2": "jsr:@libs/typing@2.6.0",
8
+ "jsr:@libs/typing@2.6": "jsr:@libs/typing@2.6.0",
9
+ "jsr:@std/assert@0.226.0": "jsr:@std/assert@0.226.0",
10
+ "jsr:@std/assert@1.0.0-rc.2": "jsr:@std/assert@1.0.0-rc.2",
11
+ "jsr:@std/async@0.224.2": "jsr:@std/async@0.224.2",
12
+ "jsr:@std/bytes@^1.0.0-rc.3": "jsr:@std/bytes@1.0.1",
13
+ "jsr:@std/bytes@^1.0.1-rc.3": "jsr:@std/bytes@1.0.1",
14
+ "jsr:@std/expect@0.224.5": "jsr:@std/expect@0.224.5",
15
+ "jsr:@std/http@0.224.5": "jsr:@std/http@0.224.5",
16
+ "jsr:@std/internal@^1.0.0": "jsr:@std/internal@1.0.1",
17
+ "jsr:@std/io@^0.224.1": "jsr:@std/io@0.224.3",
18
+ "jsr:@std/path@0.225.2": "jsr:@std/path@0.225.2",
19
+ "jsr:@std/streams@0.224.5": "jsr:@std/streams@0.224.5"
20
20
  },
21
21
  "jsr": {
22
- "@libs/logger@1.1.1": {
23
- "integrity": "7b74ca947062b955e8d63299f77a41fc4f2cf0a663a6ad836b703d601f622ccf"
22
+ "@libs/logger@1.1.3": {
23
+ "integrity": "a359d5ce4aa9f2508b1515ad6f48f41e9dfbc2250ebaa1fd9059930b3a9bab3a"
24
24
  },
25
- "@libs/testing@1.0.7": {
26
- "integrity": "b1a7caa9d2e00569f90b9753eb768ec6b16ff5c859f104b73a6ef4611968892e",
25
+ "@libs/testing@2.0.0": {
26
+ "integrity": "a1cb40f127ec8ab3a37814beb13ff604b5aacbf9da633b413b243b7fcbd2309a",
27
27
  "dependencies": [
28
- "jsr:@std/expect@0.224.0",
29
- "jsr:@std/path@0.225.1"
28
+ "jsr:@libs/run@1",
29
+ "jsr:@libs/typing@2",
30
+ "jsr:@std/assert@0.226.0",
31
+ "jsr:@std/expect@0.224.5",
32
+ "jsr:@std/http@0.224.5",
33
+ "jsr:@std/path@0.225.2"
30
34
  ]
31
35
  },
32
- "@libs/typing@2.1.0": {
33
- "integrity": "3c3b93e1da1e4bb45a22dde168fdfd1cc765edbdb371b46bf4ca7873ee79e15d"
36
+ "@libs/typing@2.6.0": {
37
+ "integrity": "07a1ee52fa6d769d68d95d7310bac7dd608932c91760a0bc8a95ce6de3630603"
34
38
  },
35
- "@std/assert@0.224.0": {
36
- "integrity": "8643233ec7aec38a940a8264a6e3eed9bfa44e7a71cc6b3c8874213ff401967f"
37
- },
38
- "@std/assert@0.225.3": {
39
- "integrity": "b3c2847aecf6955b50644cdb9cf072004ea3d1998dd7579fc0acb99dbb23bd4f"
39
+ "@std/assert@0.226.0": {
40
+ "integrity": "0dfb5f7c7723c18cec118e080fec76ce15b4c31154b15ad2bd74822603ef75b3",
41
+ "dependencies": [
42
+ "jsr:@std/internal@^1.0.0"
43
+ ]
40
44
  },
41
- "@std/async@0.224.1": {
42
- "integrity": "2fda2c8151cc5811a6ca37fe825f1f71c95e02a374abb6ef868e0e19eca814a5"
45
+ "@std/assert@1.0.0-rc.2": {
46
+ "integrity": "0484eab1d76b55fca1c3beaff485a274e67dd3b9f065edcbe70030dfc0b964d3"
43
47
  },
44
- "@std/bytes@0.224.0": {
45
- "integrity": "a2250e1d0eb7d1c5a426f21267ab9bdeac2447fa87a3d0d1a467d3f7a6058e49"
48
+ "@std/async@0.224.2": {
49
+ "integrity": "4d277d6e165df43d5e061ba0ef3edfddb8e8d558f5b920e3e6b1d2614b44d074"
46
50
  },
47
- "@std/bytes@1.0.0-rc.3": {
48
- "integrity": "b3e93f73f1ccf167124f695596d2d026b0030930c38bd0ddec81d7f75ab41948"
51
+ "@std/bytes@1.0.1": {
52
+ "integrity": "e57c9b243932b95a4c3672f8a038cdadea7492efeeb6b8a774844fee70426815"
49
53
  },
50
- "@std/expect@0.224.0": {
51
- "integrity": "54bc071f7edcbd7bb4531f913e466e5ec3642f401dc3771fe5975f0693f25969",
54
+ "@std/expect@0.224.5": {
55
+ "integrity": "ae6e57ee6f23a2fd5ae130cb84448eef182354cb902e1a2a98d64c72ac3a5a1c",
52
56
  "dependencies": [
53
- "jsr:@std/assert@^0.224.0",
54
- "jsr:@std/fmt@^0.224.0",
55
- "jsr:@std/internal@^0.224.0"
57
+ "jsr:@std/assert@1.0.0-rc.2",
58
+ "jsr:@std/internal@^1.0.0"
56
59
  ]
57
60
  },
58
- "@std/fmt@0.224.0": {
59
- "integrity": "e20e9a2312a8b5393272c26191c0a68eda8d2c4b08b046bad1673148f1d69851"
61
+ "@std/http@0.224.5": {
62
+ "integrity": "b03b5d1529f6c423badfb82f6640f9f2557b4034cd7c30655ba5bb447ff750a4"
60
63
  },
61
- "@std/internal@0.224.0": {
62
- "integrity": "afc50644f9cdf4495eeb80523a8f6d27226b4b36c45c7c195dfccad4b8509291"
64
+ "@std/internal@1.0.1": {
65
+ "integrity": "6f8c7544d06a11dd256c8d6ba54b11ed870aac6c5aeafff499892662c57673e6"
63
66
  },
64
- "@std/io@0.224.0": {
65
- "integrity": "0aff885d21d829c050b8a08b1d71b54aed5841aecf227f8d77e99ec529a11e8e",
67
+ "@std/io@0.224.3": {
68
+ "integrity": "b402edeb99c6b3778d9ae3e9927bc9085b170b41e5a09bbb7064ab2ee394ae2f",
66
69
  "dependencies": [
67
- "jsr:@std/assert@^0.224.0",
68
- "jsr:@std/bytes@^0.224.0"
70
+ "jsr:@std/bytes@^1.0.1-rc.3"
69
71
  ]
70
72
  },
71
- "@std/path@0.225.1": {
72
- "integrity": "8c3220635a73730eb51fe43de9e10b79e2724a5bb8638b9355d35ae012fd9429"
73
+ "@std/path@0.225.2": {
74
+ "integrity": "0f2db41d36b50ef048dcb0399aac720a5348638dd3cb5bf80685bf2a745aa506"
73
75
  },
74
- "@std/streams@0.224.2": {
75
- "integrity": "5d437af1423e4f616111b986ea783c15e0bc998b53e23e93b623de7ef0b14c2b",
76
+ "@std/streams@0.224.5": {
77
+ "integrity": "bcde7818dd5460d474cdbd674b15f6638b9cd73cd64e52bd852fba2bd4d8ec91",
76
78
  "dependencies": [
77
- "jsr:@std/assert@^0.225.3",
78
79
  "jsr:@std/bytes@^1.0.0-rc.3",
79
- "jsr:@std/io@^0.224.0"
80
+ "jsr:@std/io@^0.224.1"
80
81
  ]
81
82
  }
82
- },
83
- "npm": {
84
- "@types/node@18.16.19": {
85
- "integrity": "sha512-IXl7o+R9iti9eBW4Wg2hx1xQDig183jj7YLn8F7udNceyfkbn1ZxmzZXuak20gR40D7pIkIY1kYGx5VIGbaHKA==",
86
- "dependencies": {}
87
- }
88
83
  }
89
84
  },
90
85
  "remote": {},
91
86
  "workspace": {
92
87
  "dependencies": [
93
- "jsr:@libs/logger@1",
94
- "jsr:@libs/testing@1",
88
+ "jsr:@libs/logger@1.1.3",
89
+ "jsr:@libs/testing@2",
95
90
  "jsr:@libs/typing@2",
96
- "jsr:@std/async@0.224.1",
97
- "jsr:@std/streams@0.224.2"
91
+ "jsr:@std/async@0.224.2",
92
+ "jsr:@std/streams@0.224.5"
98
93
  ]
99
94
  }
100
95
  }
package/mod.mjs CHANGED
@@ -1,4 +1,4 @@
1
- var e=class e{constructor({level:t,format:n,output:o,tags:r,options:s}={}){if("granted"===globalThis.Deno?.permissions.querySync?.({name:"env",variable:"LOG_LEVEL"}).state){const n=globalThis.Deno?.env.get("LOG_LEVEL")??"";n in e.level&&(t??=e.level[n]),Number.isNaN(Number.parseInt(n))||(t??=Number.parseInt(n))}this.level=t??e.level.log,this.#e=o||null===o?o:console,this.#t=n??e.format.text,this.tags=r??{},this.options={date:!1,time:!1,delta:!0,...s,caller:!1!==s?.caller&&{file:!1,name:!1,line:!1,...s?.caller}}}level;#t;#e;tags;options;error(...t){return this.level>=e.level.error&&this.#e?.error(...this.#t(this,{level:e.level.error,content:t})),this}warn(...t){return this.level>=e.level.warn&&this.#e?.warn(...this.#t(this,{level:e.level.warn,content:t})),this}info(...t){return this.level>=e.level.info&&this.#e?.info(...this.#t(this,{level:e.level.info,content:t})),this}log(...t){return this.level>=e.level.log&&this.#e?.log(...this.#t(this,{level:e.level.log,content:t})),this}debug(...t){return this.level>=e.level.debug&&this.#e?.debug(...this.#t(this,{level:e.level.debug,content:t})),this}with(t={}){return new e({level:this.level,format:this.#t,output:this.#e,options:{...this.options},tags:{...this.tags,...t}})}#n(e=3){const t=Error,n=t.prepareStackTrace;t.prepareStackTrace=(e,t)=>t;const{stack:o}=new Error;t.prepareStackTrace=n;const r=o[e];return{file:r.getFileName(),name:r.getFunctionName(),line:r.getLineNumber(),column:r.getColumnNumber()}}static level=Object.freeze({disabled:NaN,error:0,warn:1,info:2,log:3,debug:4});static format={text(t,{level:n=0,content:o}){const r=["red","orange","cyan","white","gray"][n],s=[`%c ${Object.keys(e.level).find((t=>e.level[t]===n)).toLocaleUpperCase().padEnd(5)} │%c`],i=[`color: black; background-color: ${r}`,""];if(t.options.date||t.options.time||t.options.delta){const e=(new Date).toISOString(),n=[];if(t.options.delta){const e=performance.now()/1e3;let t=e.toPrecision(4);e<1&&(t=e.toPrecision(2)),n.push(`+${t}`)}t.options.date&&t.options.time?n.push(e):t.options.date?n.push(e.slice(0,e.indexOf("T"))):t.options.time&&n.push(e.slice(e.indexOf("T")+1,-1)),s.push(`%c ${n.join(" ¦ ").trim()} %c`),i.push(`color: black; background-color: ${r}`,"")}if(t.options.caller){const e=t.#n();if(e){const n=[];t.options.caller.file&&n.push(`${e.file.replace(t.options.caller.fileformat,"$<file>")}`),t.options.caller.name&&e.name&&n.push(e.name),t.options.caller.line&&n.push(e.line,e.column),s.push(`%c ${n.join(":").trim()} %c`),i.push("color: black; background-color: gray","")}}{const n=[];for(const[o,r]of Object.entries(t.tags))n.push(`${o}:${e.inspect(r)}`);s.push(`%c ${n.join(" ").trim()} %c`),i.push("background-color: black","")}return[s.join(""),...i,...o.map(e.inspect)]},json(t,{level:n=0,content:o}){const r={level:Object.keys(e.level).find((t=>e.level[t]===n)),timestamp:Date.now(),tags:t.tags,content:o},s={};if(t.options.date||t.options.time){const e=new Date(r.timestamp).toISOString();t.options.date&&(s.date=e.slice(0,e.indexOf("T"))),t.options.time&&(s.time=e.slice(e.indexOf("T")+1,-1))}if(t.options.delta&&(s.delta=performance.now()/1e3),t.options.caller){const e=t.#n();e&&(s.caller={},t.options.caller.file&&(s.caller.file=`${e.file.replace(t.options.caller.fileformat,"$<file>")}`),t.options.caller.name&&e.name&&(s.caller.name=e.name),t.options.caller.line&&(s.caller.line=[e.line,e.column]))}return[JSON.stringify({...r,...s})]}};static inspect(e){return globalThis.Deno?.inspect(e,{colors:!0,depth:1/0})??e}},t=class extends Error{constructor(e){super(e),this.name="AssertionError"}};TransformStream;function n(e){let t=0;for(const n of e)t+=n.length;const n=new Uint8Array(t);let o=0;for(const t of e)n.set(t,o),o+=t.length;return n}function o(e){const t=e.length,n=new Uint8Array(t);n[0]=0;let o=0,r=1;for(;r<t;)e[r]===e[o]?(o++,n[r]=o,r++):0===o?(n[r]=0,r++):o=n[o-1];return n}TransformStream,TransformStream,TransformStream,TransformStream;var r=class extends TransformStream{#o="";constructor(e={allowCR:!1}){super({transform:(t,n)=>{for(t=this.#o+t;;){const o=t.indexOf("\n"),r=e.allowCR?t.indexOf("\r"):-1;if(-1!==r&&r!==t.length-1&&(-1===o||o-1>r)){n.enqueue(t.slice(0,r)),t=t.slice(r+1);continue}if(-1===o)break;const s="\r"===t[o-1]?o-1:o;n.enqueue(t.slice(0,s)),t=t.slice(o+1)}this.#o=t},flush:t=>{if(""===this.#o)return;const n=e.allowCR&&this.#o.endsWith("\r")?this.#o.slice(0,-1):this.#o;t.enqueue(n)}})}};new TextDecoder;var s=new TextEncoder,i=new TextDecoder;function l(t,n,{log:o=new e,stdin:l=null,stdout:a="debug",stderr:u="error",env:d,cwd:p,raw:h,callback:f,buffering:m,sync:w,throw:g,dryrun:b,winext:v="",os:T=Deno.build.os}={}){"windows"===T&&(t=`${t}${v}`),o=o.with({bin:t}),f&&"piped"!==c(l)&&(l="piped");const $=new Deno.Command(t,{args:n,stdin:w?"null":c(l),stdout:c(a),stderr:c(u),env:d,cwd:p,windowsRawArguments:h});if(b){o.debug(`dryrun: ${t} not executed`);const e={success:!0,code:0,stdio:[],stdin:"",stdout:"",stderr:""};return w?e:Promise.resolve(e)}return w?function(e,{bin:t,log:n,throw:o,stdout:r,stderr:s}){const l=Date.now(),a=e.outputSync(),{success:u,code:d}=a,p=Date.now()-l,h={get stdio(){return[[p,1,this.stdout],[p,2,this.stderr]]},stdin:"",stdout:"piped"===c(r)?i.decode(a.stdout):"",stderr:"piped"===c(s)?i.decode(a.stderr):""};for(const{channel:e,mode:t}of[{channel:"stdout",mode:r},{channel:"stderr",mode:s}])"piped"===c(t)&&h[e]&&n.with({t:p,channel:e})[t]?.(h[e]);if(!u&&o)throw new EvalError(`${t} exited with non-zero code ${d}:\n${h.stdout}\n${h.stderr}`);return{success:u,code:d,...h}}($,{bin:t,log:o,throw:g,stdout:a,stderr:u}):async function(e,{bin:t,log:n,callback:o=(({close:e})=>e?.()),buffering:i=250,throw:l,...a}){const u=e.spawn(),d=Date.now(),p={stdio:[],get stdin(){return this.stdio.filter((([e,t])=>0===t)).map((([e,t,n])=>n)).join("\n")},get stdout(){return this.stdio.filter((([e,t])=>1===t)).map((([e,t,n])=>n)).join("\n")},get stderr(){return this.stdio.filter((([e,t])=>2===t)).map((([e,t,n])=>n)).join("\n")}},h={};let f="";const m=function(e,t){let n=null,o=null;const r=(...s)=>{r.clear(),o=()=>{r.clear(),e.call(r,...s)},n=setTimeout(o,t)};return r.clear=()=>{"number"==typeof n&&(clearTimeout(n),n=null,o=null)},r.flush=()=>{o?.()},Object.defineProperty(r,"pending",{get:()=>"number"==typeof n}),r}((async e=>{n.with({t:e}).debug("debounced"),f="",await o({stdio:p,i:p.stdin.length,...h})}),i);if("piped"===c(a.stdin)){const e=u.stdin.getWriter();Object.assign(h,{async write(t,o=!0){const r=Date.now()-d;a.stdin&&n.with({t:r,channel:"stdin"})[a.stdin]?.(t),p.stdio.push([r,0,t]),o&&!t.endsWith("\n")&&(t+="\n"),await e.write(s.encode(t)),f="stdin",e.releaseLock()},async close(){try{e.releaseLock(),await u.stdin.close(),n.with({t:Date.now()-d,closed:"stdin"}).debug()}catch{}},async wait(e=1e3){const t=Date.now()-d;n.with({t:t,waiting:e}).debug(),await function(e,t={}){const{signal:n,persistent:o=!0}=t;return n?.aborted?Promise.reject(n.reason):new Promise(((t,r)=>{const s=()=>{clearTimeout(i),r(n?.reason)},i=setTimeout((()=>{n?.removeEventListener("abort",s),t()}),e);if(n?.addEventListener("abort",s,{once:!0}),!1===o)try{Deno.unrefTimer(i)}catch(e){if(!(e instanceof ReferenceError))throw e;console.error("`persistent` option is only available in Deno")}}))}(e),m(t)}}),m(Date.now()-d)}await Promise.all(["stdout","stderr"].filter((e=>"piped"===c(a[e]))).map((async e=>{for await(const t of u[e].pipeThrough(new TextDecoderStream).pipeThrough(new r)){const o=Date.now()-d,r={stdout:1,stderr:2}[e];if(a[e]&&n.with({t:o,channel:e})[a[e]]?.(t),p.stdio.length&&f===e){const e=p.stdio.at(-1);e[1]===r&&(e[2]+=`\n${t}`)}else p.stdio.push([o,r,t]);f=e,m(o)}}))),m.flush();const{success:w,code:g}=await u.status;if(!w&&l)throw new EvalError(`${t} exited with non-zero code ${g}:\n${p.stdout}\n${p.stderr}`);return{success:w,code:g,...p}}($,{bin:t,log:o,callback:f,buffering:m,throw:g,stdin:"piped"===c(l)?l:null,stdout:"piped"===c(a)?a:null,stderr:"piped"===c(u)?u:null})}function c(e){return["inherit","null"].includes(`${e}`)?`${e}`:"piped"}export{l as command};
1
+ var e=class e{constructor({level:t,format:n,output:o,tags:r,options:s}={}){if("granted"===globalThis.Deno?.permissions.querySync?.({name:"env",variable:"LOG_LEVEL"}).state){const n=globalThis.Deno?.env.get("LOG_LEVEL")??"";n in e.level&&(t??=e.level[n]),Number.isNaN(Number.parseInt(n))||(t??=Number.parseInt(n))}this.level=t??e.level.log,this.#e=o||null===o?o:console,this.#t=n??e.format.text,this.tags=r??{},this.options={date:!1,time:!1,delta:!0,...s,caller:!1!==s?.caller&&{file:!1,name:!1,line:!1,...s?.caller}}}level;#t;#e;tags;options;error(...t){return this.level>=e.level.error&&this.#e?.error(...this.#t(this,{level:e.level.error,content:t})),this}warn(...t){return this.level>=e.level.warn&&this.#e?.warn(...this.#t(this,{level:e.level.warn,content:t})),this}info(...t){return this.level>=e.level.info&&this.#e?.info(...this.#t(this,{level:e.level.info,content:t})),this}log(...t){return this.level>=e.level.log&&this.#e?.log(...this.#t(this,{level:e.level.log,content:t})),this}debug(...t){return this.level>=e.level.debug&&this.#e?.debug(...this.#t(this,{level:e.level.debug,content:t})),this}with(t={}){return new e({level:this.level,format:this.#t,output:this.#e,options:{...this.options},tags:{...this.tags,...t}})}#n(e=3){const t=Error,n=t.prepareStackTrace;t.prepareStackTrace=(e,t)=>t;const{stack:o}=new Error;t.prepareStackTrace=n;const r=o[e];return{file:r.getFileName(),name:r.getFunctionName(),line:r.getLineNumber(),column:r.getColumnNumber()}}static level=Object.freeze({disabled:NaN,error:0,warn:1,info:2,log:3,debug:4});static format={text(t,{level:n=0,content:o}){const r=["red","orange","cyan","white","gray"][n],s=[`%c ${Object.keys(e.level).find((t=>e.level[t]===n)).toLocaleUpperCase().padEnd(5)} │%c`],i=[`color: black; background-color: ${r}`,""];if(t.options.date||t.options.time||t.options.delta){const e=(new Date).toISOString(),n=[];if(t.options.delta){const e=performance.now()/1e3;let t=e.toPrecision(4);e<1&&(t=e.toPrecision(2)),n.push(`+${t}`)}t.options.date&&t.options.time?n.push(e):t.options.date?n.push(e.slice(0,e.indexOf("T"))):t.options.time&&n.push(e.slice(e.indexOf("T")+1,-1)),s.push(`%c ${n.join(" ¦ ").trim()} %c`),i.push(`color: black; background-color: ${r}`,"")}if(t.options.caller){const e=t.#n();if(e){const n=[];t.options.caller.file&&n.push(`${e.file.replace(t.options.caller.fileformat,"$<file>")}`),t.options.caller.name&&e.name&&n.push(e.name),t.options.caller.line&&n.push(e.line,e.column),s.push(`%c ${n.join(":").trim()} %c`),i.push("color: black; background-color: gray","")}}{const n=[];for(const[o,r]of Object.entries(t.tags))n.push(`${o}:${e.inspect(r)}`);s.push(`%c ${n.join(" ").trim()} %c`),i.push("background-color: black","")}return[s.join(""),...i,...o.map(e.inspect)]},json(t,{level:n=0,content:o}){const r={level:Object.keys(e.level).find((t=>e.level[t]===n)),timestamp:Date.now(),tags:t.tags,content:o},s={};if(t.options.date||t.options.time){const e=new Date(r.timestamp).toISOString();t.options.date&&(s.date=e.slice(0,e.indexOf("T"))),t.options.time&&(s.time=e.slice(e.indexOf("T")+1,-1))}if(t.options.delta&&(s.delta=performance.now()/1e3),t.options.caller){const e=t.#n();e&&(s.caller={},t.options.caller.file&&(s.caller.file=`${e.file.replace(t.options.caller.fileformat,"$<file>")}`),t.options.caller.name&&e.name&&(s.caller.name=e.name),t.options.caller.line&&(s.caller.line=[e.line,e.column]))}return[JSON.stringify({...r,...s})]}};static inspect(e){return globalThis.Deno?.inspect(e,{colors:!0,depth:1/0,strAbbreviateSize:1/0})??e}};TransformStream;function t(e){let t=0;for(const n of e)t+=n.length;const n=new Uint8Array(t);let o=0;for(const t of e)n.set(t,o),o+=t.length;return n}function n(e){const t=e.length,n=new Uint8Array(t);n[0]=0;let o=0,r=1;for(;r<t;)e[r]===e[o]?(o++,n[r]=o,r++):0===o?(n[r]=0,r++):o=n[o-1];return n}TransformStream,TransformStream,TransformStream,TransformStream;var o=class extends TransformStream{#o="";constructor(e={allowCR:!1}){super({transform:(t,n)=>{for(t=this.#o+t;;){const o=t.indexOf("\n"),r=e.allowCR?t.indexOf("\r"):-1;if(-1!==r&&r!==t.length-1&&(-1===o||o-1>r)){n.enqueue(t.slice(0,r)),t=t.slice(r+1);continue}if(-1===o)break;const s="\r"===t[o-1]?o-1:o;n.enqueue(t.slice(0,s)),t=t.slice(o+1)}this.#o=t},flush:t=>{if(""===this.#o)return;const n=e.allowCR&&this.#o.endsWith("\r")?this.#o.slice(0,-1):this.#o;t.enqueue(n)}})}};new TextDecoder;var r=new TextEncoder,s=new TextDecoder;function i(t,n,{log:i=new e,stdin:a=null,stdout:c="debug",stderr:u="error",env:d,cwd:p,raw:h,callback:f,buffering:m,sync:w,throw:g,dryrun:b,winext:v="",os:T=Deno.build.os}={}){"windows"===T&&(t=`${t}${v}`),i=i.with({bin:t}),f&&"piped"!==l(a)&&(a="piped");const $=new Deno.Command(t,{args:n,stdin:w?"null":l(a),stdout:l(c),stderr:l(u),env:d,cwd:p,windowsRawArguments:h});if(b){i.debug(`dryrun: ${t} not executed`);const e={success:!0,code:0,stdio:[],stdin:"",stdout:"",stderr:""};return w?e:Promise.resolve(e)}return w?function(e,{bin:t,log:n,throw:o,stdout:r,stderr:i}){const a=Date.now(),c=e.outputSync(),{success:u,code:d}=c,p=Date.now()-a,h={get stdio(){return[[p,1,this.stdout],[p,2,this.stderr]]},stdin:"",stdout:"piped"===l(r)?s.decode(c.stdout):"",stderr:"piped"===l(i)?s.decode(c.stderr):""};for(const{channel:e,mode:t}of[{channel:"stdout",mode:r},{channel:"stderr",mode:i}])"piped"===l(t)&&h[e]&&n.with({t:p,channel:e})[t]?.(h[e]);if(!u&&o)throw new EvalError(`${t} exited with non-zero code ${d}:\n${h.stdout}\n${h.stderr}`);return{success:u,code:d,...h}}($,{bin:t,log:i,throw:g,stdout:c,stderr:u}):async function(e,{bin:t,log:n,callback:s=(({close:e})=>e?.()),buffering:i=250,throw:a,...c}){const u=e.spawn(),d=Date.now(),p={stdio:[],get stdin(){return this.stdio.filter((([e,t])=>0===t)).map((([e,t,n])=>n)).join("\n")},get stdout(){return this.stdio.filter((([e,t])=>1===t)).map((([e,t,n])=>n)).join("\n")},get stderr(){return this.stdio.filter((([e,t])=>2===t)).map((([e,t,n])=>n)).join("\n")}},h={};let f="";const m=function(e,t){let n=null,o=null;const r=(...s)=>{r.clear(),o=()=>{r.clear(),e.call(r,...s)},n=setTimeout(o,t)};return r.clear=()=>{"number"==typeof n&&(clearTimeout(n),n=null,o=null)},r.flush=()=>{o?.()},Object.defineProperty(r,"pending",{get:()=>"number"==typeof n}),r}((async e=>{n.with({t:e}).debug("debounced"),f="",await s({stdio:p,i:p.stdin.length,...h})}),i);if("piped"===l(c.stdin)){const e=u.stdin.getWriter();Object.assign(h,{async write(t,o=!0){const s=Date.now()-d;c.stdin&&n.with({t:s,channel:"stdin"})[c.stdin]?.(t),p.stdio.push([s,0,t]),o&&!t.endsWith("\n")&&(t+="\n"),await e.write(r.encode(t)),f="stdin",e.releaseLock()},async close(){try{e.releaseLock(),await u.stdin.close(),n.with({t:Date.now()-d,closed:"stdin"}).debug()}catch{}},async wait(e=1e3){const t=Date.now()-d;n.with({t:t,waiting:e}).debug(),await function(e,t={}){const{signal:n,persistent:o=!0}=t;return n?.aborted?Promise.reject(n.reason):new Promise(((t,r)=>{const s=()=>{clearTimeout(i),r(n?.reason)},i=setTimeout((()=>{n?.removeEventListener("abort",s),t()}),e);if(n?.addEventListener("abort",s,{once:!0}),!1===o)try{Deno.unrefTimer(i)}catch(e){if(!(e instanceof ReferenceError))throw e;console.error("`persistent` option is only available in Deno")}}))}(e),m(t)}}),m(Date.now()-d)}await Promise.all(["stdout","stderr"].filter((e=>"piped"===l(c[e]))).map((async e=>{for await(const t of u[e].pipeThrough(new TextDecoderStream).pipeThrough(new o)){const o=Date.now()-d,r={stdout:1,stderr:2}[e];if(c[e]&&n.with({t:o,channel:e})[c[e]]?.(t),p.stdio.length&&f===e){const e=p.stdio.at(-1);e[1]===r&&(e[2]+=`\n${t}`)}else p.stdio.push([o,r,t]);f=e,m(o)}}))),m.flush();const{success:w,code:g}=await u.status;if(!w&&a)throw new EvalError(`${t} exited with non-zero code ${g}:\n${p.stdout}\n${p.stderr}`);return{success:w,code:g,...p}}($,{bin:t,log:i,callback:f,buffering:m,throw:g,stdin:"piped"===l(a)?a:null,stdout:"piped"===l(c)?c:null,stderr:"piped"===l(u)?u:null})}function l(e){return["inherit","null"].includes(`${e}`)?`${e}`:"piped"}export{i as command};
2
2
  /**
3
3
  * Logger library
4
4
  *
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lowlighter/run",
3
- "version": "1.0.1",
3
+ "version": "1.0.3",
4
4
  "type": "module",
5
5
  "scripts": {},
6
6
  "dependencies": {},