@lowlighter/run 2.0.2 → 2.0.4

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/command.mjs CHANGED
@@ -1 +1 @@
1
- var e=class e{constructor({level:t,format:n,output:r,tags:o,...i}={}){"granted"===globalThis.Deno?.permissions.querySync?.({name:"env",variable:"LOG_LEVEL"}).state&&(t??=globalThis.Deno?.env.get("LOG_LEVEL")),this.#e=r||null===r?r:console,this.#t=e.level.log,this.#n=e.format.text,this.#r={date:!1,time:!1,delta:!0,caller:{file:!1,name:!1,line:!1,fileformat:null}},this.level(t).format(n).options(i),this.tags=o??{}}#e;#r;options(e){if(!e)return structuredClone(this.#r);if("date"in e&&(this.#r.date=e.date),"time"in e&&(this.#r.time=e.time),"delta"in e&&(this.#r.delta=e.delta),"caller"in e)switch(!0){case!0===e.caller:this.#r.caller={file:!0,name:!0,line:!0,fileformat:this.#r.caller.fileformat};break;case!1===e.caller:this.#r.caller={file:!1,name:!1,line:!1,fileformat:this.#r.caller.fileformat};break;case"object"==typeof e.caller:"file"in e.caller&&(this.#r.caller.file=e.caller.file),"name"in e.caller&&(this.#r.caller.name=e.caller.name),"line"in e.caller&&(this.#r.caller.line=e.caller.line),"fileformat"in e.caller&&void 0!==e.caller.fileformat&&(this.#r.caller.fileformat=e.caller.fileformat)}return this}#t;level(t){return arguments.length?(Number.isNaN(Number.parseInt(`${t}`))||(t=Number.parseInt(`${t}`)),"string"==typeof t&&t in e.level&&(t=e.level[t]),"number"==typeof t&&(this.#t=!Number.isNaN(t)&&t>=0?t:-1),this):this.#t>=0?this.#t:NaN}static level=Object.freeze({disabled:NaN,error:0,warn:1,info:2,ok:2,log:3,debug:4,wdebug:4,trace:5,probe:NaN,always:1/0});error(...t){return this.#t>=e.level.error&&this.#e?.error(...this.#n(this,{level:"error",content:t,options:this.#r})),this}warn(...t){return this.#t>=e.level.warn&&this.#e?.warn(...this.#n(this,{level:"warn",content:t,options:this.#r})),this}info(...t){return this.#t>=e.level.info&&this.#e?.info(...this.#n(this,{level:"info",content:t,options:this.#r})),this}ok(...t){return this.#t>=e.level.info&&this.#e?.info(...this.#n(this,{level:"ok",content:t,options:this.#r})),this}log(...t){return this.#t>=e.level.log&&this.#e?.log(...this.#n(this,{level:"log",content:t,options:this.#r})),this}debug(...t){return this.#t>=e.level.debug&&this.#e?.debug(...this.#n(this,{level:"debug",content:t,options:this.#r})),this}wdebug(...t){return this.#t>=e.level.debug&&this.#e?.debug(...this.#n(this,{level:"wdebug",content:t,options:this.#r})),this}trace(...t){return this.#t>=e.level.trace&&this.#e?.debug(...this.#n(this,{level:"trace",content:t,options:this.#r})),this}probe(...e){return this.#e?.debug(...this.#n(this,{level:"probe",content:e,options:this.#r})),this}tags;with(t={}){return new e({level:this.#t,format:this.#n,output:this.#e,...this.#r,tags:{...this.tags,...t}})}#o(e=3){const t=Error,n=t.prepareStackTrace;t.prepareStackTrace=(e,t)=>t;const{stack:r}=new Error;t.prepareStackTrace=n;return r.map((e=>({file:e.getFileName(),name:e.getFunctionName(),line:e.getLineNumber(),column:e.getColumnNumber()})))[e]}static inspect(e){return globalThis.Deno?.inspect(e,{colors:!0,depth:1/0,strAbbreviateSize:1/0})??e}#n;format(t){return this.#n=("string"==typeof t?e.format[t]:t)??e.format.text,this}static format={text(t,{level:n,content:r,options:o}){const i={error:"red",warn:"orange",info:"cyan",ok:"green",log:"white",debug:"gray",wdebug:"yellow",trace:"gray",probe:"magenta"}[n],s=[`%c ${n.replace("wdebug","debug").toLocaleUpperCase().padEnd(5)} │%c`],l=[`color: black; background-color: ${i}`,""];if(o.date||o.time||o.delta){const e=(new Date).toISOString(),t=[];if(o.delta){const e=performance.now()/1e3;let n=e.toPrecision(4);e<1&&(n=e.toPrecision(2)),t.push(`+${n}`)}o.date&&o.time?t.push(e):o.date?t.push(e.slice(0,e.indexOf("T"))):o.time&&t.push(e.slice(e.indexOf("T")+1,-1)),s.push(`%c ${t.join(" ¦ ").trim()} %c`),l.push(`color: black; background-color: ${i}`,"")}if(o.caller.file||o.caller.name||o.caller.line){const e=t.#o();if(e){const t=[];if(o.caller.file){let n=`${e.file}`;Array.isArray(o.caller.fileformat)&&(n=n.replace(o.caller.fileformat[0],o.caller.fileformat[1])),t.push(n)}o.caller.name&&e.name&&t.push(e.name),o.caller.line&&t.push(e.line,e.column),s.push(`%c ${t.join(":").trim()} %c`),l.push("color: black; background-color: gray","")}}const a=[];for(const[n,r]of Object.entries(t.tags))a.push(`${n}:${e.inspect(r)}`);return s.push(`%c ${a.join(" ").trim()} %c`),l.push("background-color: black",""),[s.join(""),...l,...r.map(e.inspect)]},json(e,{level:t,content:n,options:r}){const o={level:t,timestamp:Date.now(),tags:e.tags,content:n},i={};if(r.date||r.time){const e=new Date(o.timestamp).toISOString();r.date&&(i.date=e.slice(0,e.indexOf("T"))),r.time&&(i.time=e.slice(e.indexOf("T")+1,-1))}if(r.delta&&(i.delta=performance.now()/1e3),r.caller.file||r.caller.name||r.caller.line){const t=e.#o();if(t){if(i.caller={},r.caller.file){let e=`${t.file}`;Array.isArray(r.caller.fileformat)&&(e=e.replace(r.caller.fileformat[0],r.caller.fileformat[1])),i.caller.file=e}r.caller.name&&t.name&&(i.caller.name=t.name),r.caller.line&&(i.caller.line=[t.line,t.column])}}return[JSON.stringify({...o,...i})]}}};TransformStream;function t(e){let t=0;for(const n of e)t+=n.length;const n=new Uint8Array(t);let r=0;for(const t of e)n.set(t,r),r+=t.length;return n}function n(e){const t=e.length,n=new Uint8Array(t);n[0]=0;let r=0,o=1;for(;o<t;)e[o]===e[r]?(r++,n[o]=r,o++):0===r?(n[o]=0,o++):r=n[r-1];return n}TransformStream,TransformStream,TransformStream,TransformStream;var r=class extends TransformStream{#i="";constructor(e={allowCR:!1}){super({transform:(t,n)=>{for(t=this.#i+t;;){const r=t.indexOf("\n"),o=e.allowCR?t.indexOf("\r"):-1;if(-1!==o&&o!==t.length-1&&(-1===r||r-1>o)){n.enqueue(t.slice(0,o)),t=t.slice(o+1);continue}if(-1===r)break;const i="\r"===t[r-1]?r-1:r;n.enqueue(t.slice(0,i)),t=t.slice(r+1)}this.#i=t},flush:t=>{if(""===this.#i)return;const n=e.allowCR&&this.#i.endsWith("\r")?this.#i.slice(0,-1):this.#i;t.enqueue(n)}})}};var o=new TextEncoder,i=new TextDecoder;function s(t,n,{logger:s=new e,stdin:a=null,stdout:c="debug",stderr:u="error",env:d,cwd:h,raw:f,callback:p,buffering:m,sync:g,throw:w,dryrun:b,winext:v="",os:y=Deno.build.os}={}){"windows"===y&&(t=`${t}${v}`),s=s.with({bin:t}),p&&"piped"!==l(a)&&(a="piped");const $=new Deno.Command(t,{args:n,stdin:g?"null":l(a),stdout:l(c),stderr:l(u),env:d,cwd:h,windowsRawArguments:f});if(b){s.wdebug(`dryrun: ${t} not executed`);const e={success:!0,code:0,stdio:[],stdin:"",stdout:"",stderr:""};return g?e:Promise.resolve(e)}return g?function(e,{bin:t,log:n,throw:r,stdout:o,stderr:s}){const a=Date.now(),c=e.outputSync(),{success:u,code:d}=c,h=Date.now()-a,f={get stdio(){return[[h,1,this.stdout],[h,2,this.stderr]]},stdin:"",stdout:"piped"===l(o)?i.decode(c.stdout):"",stderr:"piped"===l(s)?i.decode(c.stderr):""};for(const{channel:e,mode:t}of[{channel:"stdout",mode:o},{channel:"stderr",mode:s}])"piped"===l(t)&&f[e]&&n.with({t:h,channel:e})[t]?.(f[e]);if(!u&&r)throw new EvalError(`${t} exited with non-zero code ${d}:\n${f.stdout}\n${f.stderr}`);return{success:u,code:d,...f}}($,{bin:t,log:s,throw:w,stdout:c,stderr:u}):async function(e,{bin:t,log:n,callback:i=({close:e})=>e?.(),buffering:s=250,throw:a,...c}){const u=e.spawn(),d=Date.now(),h={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")}},f={};let p="";const m=function(e,t){let n=null,r=null;const o=(...i)=>{o.clear(),r=()=>{o.clear(),e.call(o,...i)},n=Number(setTimeout(r,t))};return o.clear=()=>{"number"==typeof n&&(clearTimeout(n),n=null,r=null)},o.flush=()=>{r?.()},Object.defineProperty(o,"pending",{get:()=>"number"==typeof n}),o}((async e=>{n.with({t:e}).trace("debounced"),p="",await i({stdio:h,i:h.stdin.length,...f})}),s);if("piped"===l(c.stdin)){const e=u.stdin.getWriter();Object.assign(f,{async write(t,r=!0){const i=Date.now()-d;c.stdin&&n.with({t:i,channel:"stdin"})[c.stdin]?.(t),h.stdio.push([i,0,t]),r&&!t.endsWith("\n")&&(t+="\n"),await e.write(o.encode(t)),p="stdin",e.releaseLock()},async close(){try{e.releaseLock(),await u.stdin.close(),n.with({t:Date.now()-d,closed:"stdin"}).trace()}catch{}},async wait(e=1e3){const t=Date.now()-d;n.with({t:t,waiting:e}).trace(),await function(e,t={}){const{signal:n,persistent:r=!0}=t;return n?.aborted?Promise.reject(n.reason):new Promise(((t,o)=>{const i=()=>{clearTimeout(s),o(n?.reason)},s=setTimeout((()=>{n?.removeEventListener("abort",i),t()}),e);if(n?.addEventListener("abort",i,{once:!0}),!1===r)try{Deno.unrefTimer(s)}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 r)){const r=Date.now()-d,o={stdout:1,stderr:2}[e];if(c[e]&&n.with({t:r,channel:e})[c[e]]?.(t),h.stdio.length&&p===e){const e=h.stdio.at(-1);e[1]===o&&(e[2]+=`\n${t}`)}else h.stdio.push([r,o,t]);p=e,m(r)}}))),m.flush();const{success:g,code:w}=await u.status;if(!g&&a)throw new EvalError(`${t} exited with non-zero code ${w}:\n${h.stdout}\n${h.stderr}`);return{success:g,code:w,...h}}($,{bin:t,log:s,callback:p,buffering:m,throw:w,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{s as command};
1
+ var e=class e{constructor({level:t,format:r,output:n,tags:o,...i}={}){"granted"===globalThis.Deno?.permissions.querySync?.({name:"env",variable:"LOG_LEVEL"}).state&&(t??=globalThis.Deno?.env.get("LOG_LEVEL")),this.#e=n||null===n?n:console,this.#t=e.level.log,this.#r=e.format.text,this.#n={date:!1,time:!1,delta:!0,caller:{file:!1,name:!1,line:!1,fileformat:null}},this.level(t).format(r).options(i),this.tags=o??{}}#e;#n;options(e){if(!e)return structuredClone(this.#n);if("date"in e&&(this.#n.date=e.date),"time"in e&&(this.#n.time=e.time),"delta"in e&&(this.#n.delta=e.delta),"caller"in e)switch(!0){case!0===e.caller:this.#n.caller={file:!0,name:!0,line:!0,fileformat:this.#n.caller.fileformat};break;case!1===e.caller:this.#n.caller={file:!1,name:!1,line:!1,fileformat:this.#n.caller.fileformat};break;case"object"==typeof e.caller:"file"in e.caller&&(this.#n.caller.file=e.caller.file),"name"in e.caller&&(this.#n.caller.name=e.caller.name),"line"in e.caller&&(this.#n.caller.line=e.caller.line),"fileformat"in e.caller&&void 0!==e.caller.fileformat&&(this.#n.caller.fileformat=e.caller.fileformat)}return this}#t;level(t){return arguments.length?(Number.isNaN(Number.parseInt(`${t}`))||(t=Number.parseInt(`${t}`)),"string"==typeof t&&t in e.level&&(t=e.level[t]),"number"==typeof t&&(this.#t=!Number.isNaN(t)&&t>=0?t:-1),this):this.#t>=0?this.#t:NaN}static level=Object.freeze({disabled:NaN,error:0,warn:1,info:2,ok:2,log:3,debug:4,wdebug:4,trace:5,probe:NaN,always:1/0});error(...t){return this.#t>=e.level.error&&this.#e?.error(...this.#r(this,{level:"error",content:t,options:this.#n})),this}warn(...t){return this.#t>=e.level.warn&&this.#e?.warn(...this.#r(this,{level:"warn",content:t,options:this.#n})),this}info(...t){return this.#t>=e.level.info&&this.#e?.info(...this.#r(this,{level:"info",content:t,options:this.#n})),this}ok(...t){return this.#t>=e.level.info&&this.#e?.info(...this.#r(this,{level:"ok",content:t,options:this.#n})),this}log(...t){return this.#t>=e.level.log&&this.#e?.log(...this.#r(this,{level:"log",content:t,options:this.#n})),this}debug(...t){return this.#t>=e.level.debug&&this.#e?.debug(...this.#r(this,{level:"debug",content:t,options:this.#n})),this}wdebug(...t){return this.#t>=e.level.debug&&this.#e?.debug(...this.#r(this,{level:"wdebug",content:t,options:this.#n})),this}trace(...t){return this.#t>=e.level.trace&&this.#e?.debug(...this.#r(this,{level:"trace",content:t,options:this.#n})),this}probe(...e){return this.#e?.debug(...this.#r(this,{level:"probe",content:e,options:this.#n})),this}tags;with(t={}){return new e({level:this.#t,format:this.#r,output:this.#e,...this.#n,tags:{...this.tags,...t}})}#o(e=3){const t=Error,r=t.prepareStackTrace;t.prepareStackTrace=(e,t)=>t;const{stack:n}=new Error;t.prepareStackTrace=r;return n.map((e=>({file:e.getFileName(),name:e.getFunctionName(),line:e.getLineNumber(),column:e.getColumnNumber()})))[e]}static inspect(e){return globalThis.Deno?.inspect(e,{colors:!0,depth:1/0,strAbbreviateSize:1/0})??e}#r;format(t){return this.#r=("string"==typeof t?e.format[t]:t)??e.format.text,this}static format={text(t,{level:r,content:n,options:o}){const i={error:"red",warn:"orange",info:"cyan",ok:"green",log:"white",debug:"gray",wdebug:"yellow",trace:"gray",probe:"magenta"}[r],s=[`%c ${r.replace("wdebug","debug").toLocaleUpperCase().padEnd(5)} │%c`],l=[`color: black; background-color: ${i}`,""];if(o.date||o.time||o.delta){const e=(new Date).toISOString(),t=[];if(o.delta){const e=performance.now()/1e3;let r=e.toPrecision(4);e<1&&(r=e.toPrecision(2)),t.push(`+${r}`)}o.date&&o.time?t.push(e):o.date?t.push(e.slice(0,e.indexOf("T"))):o.time&&t.push(e.slice(e.indexOf("T")+1,-1)),s.push(`%c ${t.join(" ¦ ").trim()} %c`),l.push(`color: black; background-color: ${i}`,"")}if(o.caller.file||o.caller.name||o.caller.line){const e=t.#o();if(e){const t=[];if(o.caller.file){let r=`${e.file}`;Array.isArray(o.caller.fileformat)&&(r=r.replace(o.caller.fileformat[0],o.caller.fileformat[1])),t.push(r)}o.caller.name&&e.name&&t.push(e.name),o.caller.line&&t.push(e.line,e.column),s.push(`%c ${t.join(":").trim()} %c`),l.push("color: black; background-color: gray","")}}const a=[];for(const[r,n]of Object.entries(t.tags))a.push(`${r}:${e.inspect(n)}`);return s.push(`%c ${a.join(" ").trim()} %c`),l.push("background-color: black",""),[s.join(""),...l,...n.map(e.inspect)]},json(e,{level:t,content:r,options:n}){const o={level:t,timestamp:Date.now(),tags:e.tags,content:r},i={};if(n.date||n.time){const e=new Date(o.timestamp).toISOString();n.date&&(i.date=e.slice(0,e.indexOf("T"))),n.time&&(i.time=e.slice(e.indexOf("T")+1,-1))}if(n.delta&&(i.delta=performance.now()/1e3),n.caller.file||n.caller.name||n.caller.line){const t=e.#o();if(t){if(i.caller={},n.caller.file){let e=`${t.file}`;Array.isArray(n.caller.fileformat)&&(e=e.replace(n.caller.fileformat[0],n.caller.fileformat[1])),i.caller.file=e}n.caller.name&&t.name&&(i.caller.name=t.name),n.caller.line&&(i.caller.line=[t.line,t.column])}}return[JSON.stringify({...o,...i})]}}};TransformStream;function t(e){let t=0;for(const r of e)t+=r.length;const r=new Uint8Array(t);let n=0;for(const t of e)r.set(t,n),n+=t.length;return r}function r(e){const t=e.length,r=new Uint8Array(t);r[0]=0;let n=0,o=1;for(;o<t;)e[o]===e[n]?(n++,r[o]=n,o++):0===n?(r[o]=0,o++):n=r[n-1];return r}TransformStream,TransformStream,TransformStream,TransformStream,TransformStream;var n=class extends TransformStream{#i="";constructor(e={allowCR:!1}){super({transform:(t,r)=>{for(t=this.#i+t;;){const n=t.indexOf("\n"),o=e.allowCR?t.indexOf("\r"):-1;if(-1!==o&&o!==t.length-1&&(-1===n||n-1>o)){r.enqueue(t.slice(0,o)),t=t.slice(o+1);continue}if(-1===n)break;const i="\r"===t[n-1]?n-1:n;r.enqueue(t.slice(0,i)),t=t.slice(n+1)}this.#i=t},flush:t=>{if(""===this.#i)return;const r=e.allowCR&&this.#i.endsWith("\r")?this.#i.slice(0,-1):this.#i;t.enqueue(r)}})}};var o=new TextEncoder,i=new TextDecoder;function s(t,r,{logger:s=new e,stdin:a=null,stdout:c="debug",stderr:u="error",env:d,cwd:h,raw:f,callback:p,buffering:m,sync:g,throw:w,dryrun:b,winext:v="",os:y=Deno.build.os}={}){"windows"===y&&(t=`${t}${v}`),s=s.with({bin:t}),p&&"piped"!==l(a)&&(a="piped");const T=new Deno.Command(t,{args:r,stdin:g?"null":l(a),stdout:l(c),stderr:l(u),env:d,cwd:h,windowsRawArguments:f});if(b){s.wdebug(`dryrun: ${t} not executed`);const e={success:!0,code:0,stdio:[],stdin:"",stdout:"",stderr:""};return g?e:Promise.resolve(e)}return g?function(e,{bin:t,log:r,throw:n,stdout:o,stderr:s}){const a=Date.now(),c=e.outputSync(),{success:u,code:d}=c,h=Date.now()-a,f={get stdio(){return[[h,1,this.stdout],[h,2,this.stderr]]},stdin:"",stdout:"piped"===l(o)?i.decode(c.stdout):"",stderr:"piped"===l(s)?i.decode(c.stderr):""};for(const{channel:e,mode:t}of[{channel:"stdout",mode:o},{channel:"stderr",mode:s}])"piped"===l(t)&&f[e]&&r.with({t:h,channel:e})[t]?.(f[e]);if(!u&&n)throw new EvalError(`${t} exited with non-zero code ${d}:\n${f.stdout}\n${f.stderr}`);return{success:u,code:d,...f}}(T,{bin:t,log:s,throw:w,stdout:c,stderr:u}):async function(e,{bin:t,log:r,callback:i=({close:e})=>e?.(),buffering:s=250,throw:a,...c}){const u=e.spawn(),d=Date.now(),h={stdio:[],get stdin(){return this.stdio.filter((([e,t])=>0===t)).map((([e,t,r])=>r)).join("\n")},get stdout(){return this.stdio.filter((([e,t])=>1===t)).map((([e,t,r])=>r)).join("\n")},get stderr(){return this.stdio.filter((([e,t])=>2===t)).map((([e,t,r])=>r)).join("\n")}},f={};let p="";const m=function(e,t){let r=null,n=null;const o=(...i)=>{o.clear(),n=()=>{o.clear(),e.call(o,...i)},r=Number(setTimeout(n,t))};return o.clear=()=>{"number"==typeof r&&(clearTimeout(r),r=null,n=null)},o.flush=()=>{n?.()},Object.defineProperty(o,"pending",{get:()=>"number"==typeof r}),o}((async e=>{r.with({t:e}).trace("debounced"),p="",await i({stdio:h,i:h.stdin.length,...f})}),s);if("piped"===l(c.stdin)){const e=u.stdin.getWriter();Object.assign(f,{async write(t,n=!0){const i=Date.now()-d;c.stdin&&r.with({t:i,channel:"stdin"})[c.stdin]?.(t),h.stdio.push([i,0,t]),n&&!t.endsWith("\n")&&(t+="\n"),await e.write(o.encode(t)),p="stdin",e.releaseLock()},async close(){try{e.releaseLock(),await u.stdin.close(),r.with({t:Date.now()-d,closed:"stdin"}).trace()}catch{}},async wait(e=1e3){const t=Date.now()-d;r.with({t:t,waiting:e}).trace(),await function(e,t={}){const{signal:r,persistent:n=!0}=t;return r?.aborted?Promise.reject(r.reason):new Promise(((t,o)=>{const i=()=>{clearTimeout(s),o(r?.reason)},s=setTimeout((()=>{r?.removeEventListener("abort",i),t()}),e);if(r?.addEventListener("abort",i,{once:!0}),!1===n)try{Deno.unrefTimer(s)}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 n)){const n=Date.now()-d,o={stdout:1,stderr:2}[e];if(c[e]&&r.with({t:n,channel:e})[c[e]]?.(t),h.stdio.length&&p===e){const e=h.stdio.at(-1);e[1]===o&&(e[2]+=`\n${t}`)}else h.stdio.push([n,o,t]);p=e,m(n)}}))),m.flush();const{success:g,code:w}=await u.status;if(!g&&a)throw new EvalError(`${t} exited with non-zero code ${w}:\n${h.stdout}\n${h.stderr}`);return{success:g,code:w,...h}}(T,{bin:t,log:s,callback:p,buffering:m,throw:w,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{s as command};
package/command_test.ts CHANGED
@@ -20,7 +20,7 @@ test("deno")("command() can spawn subprocesses synchronously", () => {
20
20
  }, { permissions: { run: ["deno"] } })
21
21
 
22
22
  test("deno")("command() handles callback<write()> and callback<close()> calls", async () => {
23
- const result = await command("deno", ["repl"], { env: { NO_COLOR: "true" }, callback: ({ i, write, close }) => i === 0 ? write("console.log('hello')") : close() })
23
+ const result = await command("deno", ["repl"], { stdin: "debug", env: { NO_COLOR: "true" }, callback: ({ i, write, close }) => i === 0 ? write("console.log('hello')") : close() })
24
24
  expect(result).toMatchObject({ success: true, code: 0, stdin: "console.log('hello')" })
25
25
  expect(result.stdout).toMatch(/hello/)
26
26
  }, { permissions: { run: ["deno"] } })
@@ -48,7 +48,7 @@ test("deno")("command() handles callback<wait()> calls", async () => {
48
48
  for (const sync of [false, true]) {
49
49
  for (const mode of ["inherit", "piped", null, "debug", "log", "info", "warn", "error"] as const) {
50
50
  test("deno")(`command() supports stdio set to "${mode}" in "${sync ? "sync" : "async"}" mode`, async () => {
51
- const result = await command("deno", ["--version"], {
51
+ const result = await command("deno", ["eval", "null"], {
52
52
  logger: new Logger({ level: "disabled" }),
53
53
  env: { NO_COLOR: "true" },
54
54
  stdin: mode,
@@ -121,3 +121,7 @@ test("deno")("command() does nothing in dryrun", async () => {
121
121
  expect(command("deno", ["--version"], { dryrun: true, sync: true })).toMatchObject({ success: true, code: 0, stdio: [], stdin: "", stderr: "", stdout: "" })
122
122
  await expect(command("deno", ["--version"], { dryrun: true })).resolves.toMatchObject({ success: true, code: 0, stdio: [], stdin: "", stderr: "", stdout: "" })
123
123
  }, { permissions: { run: ["deno"] } })
124
+
125
+ test("deno")("command() appends windows extension when os platform is windows", () => {
126
+ expect(command("", ["--version"], { logger: new Logger({ level: "disabled" }), sync: true, winext: "deno", os: "windows" })).toMatchObject({ success: true, code: 0 })
127
+ }, { permissions: { run: ["deno"] } })
package/deno.jsonc CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "icon": "⏯️",
3
3
  "name": "@libs/run",
4
- "version": "2.0.2",
4
+ "version": "2.0.4",
5
5
  "description": "Utilities to run subprocess.",
6
6
  "keywords": [
7
7
  "subprocess",
@@ -43,11 +43,13 @@
43
43
  "tasks": {
44
44
  "test": "deno test --allow-run=deno,node,bun,npx --no-prompt --coverage --clean --trace-leaks --doc",
45
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",
46
+ "test:deno": "deno task clean:deno && deno fmt --check && deno task test --filter='/^\\[deno\\]/' --quiet && deno coverage --exclude=.js && deno lint",
47
+ "test:deno-future": "deno task clean:deno && DENO_FUTURE=1 && deno task test:deno",
48
+ "test:others": "deno task clean:others && deno fmt --check && deno task test --filter='/^\\[node|bun \\]/' --quiet && deno coverage --exclude=.js && deno lint",
49
49
  "coverage:html": "deno task test --filter='/^\\[deno\\]/' --quiet && deno coverage --exclude=.js --html && sleep 1",
50
- "lint": "deno fmt --check && deno lint && deno doc --lint mod.ts && deno publish --dry-run --quiet --allow-dirty"
50
+ "lint": "deno fmt --check && deno lint && deno doc --lint mod.ts && deno publish --dry-run --quiet --allow-dirty",
51
+ "clean:deno": "rm -rf node_modules .npmrc deno.lock",
52
+ "clean:others": "rm -rf node_modules .npmrc deno.lock package.json package-lock.json bun.lockb"
51
53
  },
52
54
  "lint": {
53
55
  "rules": {
package/deno.lock CHANGED
@@ -2,65 +2,64 @@
2
2
  "version": "3",
3
3
  "packages": {
4
4
  "specifiers": {
5
- "jsr:@libs/logger": "jsr:@libs/logger@2.1.0",
6
- "jsr:@libs/logger@2": "jsr:@libs/logger@2.1.0",
7
- "jsr:@libs/testing@2": "jsr:@libs/testing@2.2.3",
8
- "jsr:@libs/typing@2": "jsr:@libs/typing@2.8.0",
9
- "jsr:@std/assert@1": "jsr:@std/assert@1.0.2",
10
- "jsr:@std/assert@^1.0.1": "jsr:@std/assert@1.0.2",
11
- "jsr:@std/async@1": "jsr:@std/async@1.0.2",
12
- "jsr:@std/bytes@^1.0.2-rc.3": "jsr:@std/bytes@1.0.2",
13
- "jsr:@std/expect@1": "jsr:@std/expect@1.0.0",
14
- "jsr:@std/http@1": "jsr:@std/http@1.0.0",
15
- "jsr:@std/internal@^1.0.1": "jsr:@std/internal@1.0.1",
16
- "jsr:@std/streams@1": "jsr:@std/streams@1.0.0"
5
+ "jsr:@libs/logger": "jsr:@libs/logger@2.1.2",
6
+ "jsr:@libs/logger@2": "jsr:@libs/logger@2.1.2",
7
+ "jsr:@libs/testing@2": "jsr:@libs/testing@2.2.4",
8
+ "jsr:@libs/typing@2": "jsr:@libs/typing@2.8.2",
9
+ "jsr:@std/assert@1": "jsr:@std/assert@1.0.3",
10
+ "jsr:@std/assert@^1.0.3": "jsr:@std/assert@1.0.3",
11
+ "jsr:@std/async@1": "jsr:@std/async@1.0.4",
12
+ "jsr:@std/bytes@^1.0.2": "jsr:@std/bytes@1.0.2",
13
+ "jsr:@std/expect@1": "jsr:@std/expect@1.0.1",
14
+ "jsr:@std/http@1": "jsr:@std/http@1.0.4",
15
+ "jsr:@std/internal@^1.0.2": "jsr:@std/internal@1.0.2",
16
+ "jsr:@std/streams@1": "jsr:@std/streams@1.0.3"
17
17
  },
18
18
  "jsr": {
19
- "@libs/logger@2.1.0": {
20
- "integrity": "2cd144c758044f34902360b0ae3705d022db19b3e183260f6f504f43c9869a4f"
19
+ "@libs/logger@2.1.2": {
20
+ "integrity": "2a5f4b148fd8d6b1221ff89cff73367ca0511137f4d6548c532b6e220ed22bcc"
21
21
  },
22
- "@libs/testing@2.2.3": {
23
- "integrity": "1041b2db2979ce40a3f5e116a907eb6a4fc8acc5430ce0c137e29480a7111c3b",
22
+ "@libs/testing@2.2.4": {
23
+ "integrity": "3ef407b62cf18424b3e2e604eef5df81d3c07cf8adb4b78ab4cf40db2a029f2c",
24
24
  "dependencies": [
25
- "jsr:@libs/run@2",
26
25
  "jsr:@libs/typing@2",
27
26
  "jsr:@std/assert@1",
28
27
  "jsr:@std/expect@1",
29
28
  "jsr:@std/http@1"
30
29
  ]
31
30
  },
32
- "@libs/typing@2.8.0": {
33
- "integrity": "92cb68fe9798fee525e810423c2346ee42a11b3d9955432c6a1d8e93a262aa39"
31
+ "@libs/typing@2.8.2": {
32
+ "integrity": "c53f8aad9b01621de893aeac5d6cd592ec2ce783f8e89b677dcd81490a3be0a0"
34
33
  },
35
- "@std/assert@1.0.2": {
36
- "integrity": "ccacec332958126deaceb5c63ff8b4eaf9f5ed0eac9feccf124110435e59e49c",
34
+ "@std/assert@1.0.3": {
35
+ "integrity": "b0d03ce1ced880df67132eea140623010d415848df66f6aa5df76507ca7c26d8",
37
36
  "dependencies": [
38
- "jsr:@std/internal@^1.0.1"
37
+ "jsr:@std/internal@^1.0.2"
39
38
  ]
40
39
  },
41
- "@std/async@1.0.2": {
42
- "integrity": "36e7f0f922c843b45df546857d269f01ed4d0406aced2a6639eac325b2435e43"
40
+ "@std/async@1.0.4": {
41
+ "integrity": "373f5168a01b46ecaabc785d4e0f9ef18a010ab867af069fb905d93a9129ae5b"
43
42
  },
44
43
  "@std/bytes@1.0.2": {
45
44
  "integrity": "fbdee322bbd8c599a6af186a1603b3355e59a5fb1baa139f8f4c3c9a1b3e3d57"
46
45
  },
47
- "@std/expect@1.0.0": {
48
- "integrity": "030275683c23d6708878c5439a3ffd99285948d708e00835fd38fcef9a0bb921",
46
+ "@std/expect@1.0.1": {
47
+ "integrity": "44075d9c2cb701ddfc4d5a260da2fb26ba3cfd94c45d3a0359f63cabbf85a058",
49
48
  "dependencies": [
50
- "jsr:@std/assert@^1.0.1",
51
- "jsr:@std/internal@^1.0.1"
49
+ "jsr:@std/assert@^1.0.3",
50
+ "jsr:@std/internal@^1.0.2"
52
51
  ]
53
52
  },
54
- "@std/http@1.0.0": {
55
- "integrity": "001812606b471c2d64799f14e5677bd26bfd029c35046eba0bddac1a49109789"
53
+ "@std/http@1.0.4": {
54
+ "integrity": "1a8142217907d49c4687f90ef3d257e7df2baf344c5122c322d7316df09df453"
56
55
  },
57
- "@std/internal@1.0.1": {
58
- "integrity": "6f8c7544d06a11dd256c8d6ba54b11ed870aac6c5aeafff499892662c57673e6"
56
+ "@std/internal@1.0.2": {
57
+ "integrity": "f4cabe2021352e8bfc24e6569700df87bf070914fc38d4b23eddd20108ac4495"
59
58
  },
60
- "@std/streams@1.0.0": {
61
- "integrity": "350242b8fad9874ed45f3c42df3d132bd0a958f8a8bae9bbfa1ff039716aa6fb",
59
+ "@std/streams@1.0.3": {
60
+ "integrity": "d62e645ab981cee2c3d03040eb03cf387fc6bceef6d4564f3ed485a43741a81f",
62
61
  "dependencies": [
63
- "jsr:@std/bytes@^1.0.2-rc.3"
62
+ "jsr:@std/bytes@^1.0.2"
64
63
  ]
65
64
  }
66
65
  }
package/mod.mjs CHANGED
@@ -1 +1 @@
1
- var e=class e{constructor({level:t,format:n,output:r,tags:o,...i}={}){"granted"===globalThis.Deno?.permissions.querySync?.({name:"env",variable:"LOG_LEVEL"}).state&&(t??=globalThis.Deno?.env.get("LOG_LEVEL")),this.#e=r||null===r?r:console,this.#t=e.level.log,this.#n=e.format.text,this.#r={date:!1,time:!1,delta:!0,caller:{file:!1,name:!1,line:!1,fileformat:null}},this.level(t).format(n).options(i),this.tags=o??{}}#e;#r;options(e){if(!e)return structuredClone(this.#r);if("date"in e&&(this.#r.date=e.date),"time"in e&&(this.#r.time=e.time),"delta"in e&&(this.#r.delta=e.delta),"caller"in e)switch(!0){case!0===e.caller:this.#r.caller={file:!0,name:!0,line:!0,fileformat:this.#r.caller.fileformat};break;case!1===e.caller:this.#r.caller={file:!1,name:!1,line:!1,fileformat:this.#r.caller.fileformat};break;case"object"==typeof e.caller:"file"in e.caller&&(this.#r.caller.file=e.caller.file),"name"in e.caller&&(this.#r.caller.name=e.caller.name),"line"in e.caller&&(this.#r.caller.line=e.caller.line),"fileformat"in e.caller&&void 0!==e.caller.fileformat&&(this.#r.caller.fileformat=e.caller.fileformat)}return this}#t;level(t){return arguments.length?(Number.isNaN(Number.parseInt(`${t}`))||(t=Number.parseInt(`${t}`)),"string"==typeof t&&t in e.level&&(t=e.level[t]),"number"==typeof t&&(this.#t=!Number.isNaN(t)&&t>=0?t:-1),this):this.#t>=0?this.#t:NaN}static level=Object.freeze({disabled:NaN,error:0,warn:1,info:2,ok:2,log:3,debug:4,wdebug:4,trace:5,probe:NaN,always:1/0});error(...t){return this.#t>=e.level.error&&this.#e?.error(...this.#n(this,{level:"error",content:t,options:this.#r})),this}warn(...t){return this.#t>=e.level.warn&&this.#e?.warn(...this.#n(this,{level:"warn",content:t,options:this.#r})),this}info(...t){return this.#t>=e.level.info&&this.#e?.info(...this.#n(this,{level:"info",content:t,options:this.#r})),this}ok(...t){return this.#t>=e.level.info&&this.#e?.info(...this.#n(this,{level:"ok",content:t,options:this.#r})),this}log(...t){return this.#t>=e.level.log&&this.#e?.log(...this.#n(this,{level:"log",content:t,options:this.#r})),this}debug(...t){return this.#t>=e.level.debug&&this.#e?.debug(...this.#n(this,{level:"debug",content:t,options:this.#r})),this}wdebug(...t){return this.#t>=e.level.debug&&this.#e?.debug(...this.#n(this,{level:"wdebug",content:t,options:this.#r})),this}trace(...t){return this.#t>=e.level.trace&&this.#e?.debug(...this.#n(this,{level:"trace",content:t,options:this.#r})),this}probe(...e){return this.#e?.debug(...this.#n(this,{level:"probe",content:e,options:this.#r})),this}tags;with(t={}){return new e({level:this.#t,format:this.#n,output:this.#e,...this.#r,tags:{...this.tags,...t}})}#o(e=3){const t=Error,n=t.prepareStackTrace;t.prepareStackTrace=(e,t)=>t;const{stack:r}=new Error;t.prepareStackTrace=n;return r.map((e=>({file:e.getFileName(),name:e.getFunctionName(),line:e.getLineNumber(),column:e.getColumnNumber()})))[e]}static inspect(e){return globalThis.Deno?.inspect(e,{colors:!0,depth:1/0,strAbbreviateSize:1/0})??e}#n;format(t){return this.#n=("string"==typeof t?e.format[t]:t)??e.format.text,this}static format={text(t,{level:n,content:r,options:o}){const i={error:"red",warn:"orange",info:"cyan",ok:"green",log:"white",debug:"gray",wdebug:"yellow",trace:"gray",probe:"magenta"}[n],s=[`%c ${n.replace("wdebug","debug").toLocaleUpperCase().padEnd(5)} │%c`],l=[`color: black; background-color: ${i}`,""];if(o.date||o.time||o.delta){const e=(new Date).toISOString(),t=[];if(o.delta){const e=performance.now()/1e3;let n=e.toPrecision(4);e<1&&(n=e.toPrecision(2)),t.push(`+${n}`)}o.date&&o.time?t.push(e):o.date?t.push(e.slice(0,e.indexOf("T"))):o.time&&t.push(e.slice(e.indexOf("T")+1,-1)),s.push(`%c ${t.join(" ¦ ").trim()} %c`),l.push(`color: black; background-color: ${i}`,"")}if(o.caller.file||o.caller.name||o.caller.line){const e=t.#o();if(e){const t=[];if(o.caller.file){let n=`${e.file}`;Array.isArray(o.caller.fileformat)&&(n=n.replace(o.caller.fileformat[0],o.caller.fileformat[1])),t.push(n)}o.caller.name&&e.name&&t.push(e.name),o.caller.line&&t.push(e.line,e.column),s.push(`%c ${t.join(":").trim()} %c`),l.push("color: black; background-color: gray","")}}const a=[];for(const[n,r]of Object.entries(t.tags))a.push(`${n}:${e.inspect(r)}`);return s.push(`%c ${a.join(" ").trim()} %c`),l.push("background-color: black",""),[s.join(""),...l,...r.map(e.inspect)]},json(e,{level:t,content:n,options:r}){const o={level:t,timestamp:Date.now(),tags:e.tags,content:n},i={};if(r.date||r.time){const e=new Date(o.timestamp).toISOString();r.date&&(i.date=e.slice(0,e.indexOf("T"))),r.time&&(i.time=e.slice(e.indexOf("T")+1,-1))}if(r.delta&&(i.delta=performance.now()/1e3),r.caller.file||r.caller.name||r.caller.line){const t=e.#o();if(t){if(i.caller={},r.caller.file){let e=`${t.file}`;Array.isArray(r.caller.fileformat)&&(e=e.replace(r.caller.fileformat[0],r.caller.fileformat[1])),i.caller.file=e}r.caller.name&&t.name&&(i.caller.name=t.name),r.caller.line&&(i.caller.line=[t.line,t.column])}}return[JSON.stringify({...o,...i})]}}};TransformStream;function t(e){let t=0;for(const n of e)t+=n.length;const n=new Uint8Array(t);let r=0;for(const t of e)n.set(t,r),r+=t.length;return n}function n(e){const t=e.length,n=new Uint8Array(t);n[0]=0;let r=0,o=1;for(;o<t;)e[o]===e[r]?(r++,n[o]=r,o++):0===r?(n[o]=0,o++):r=n[r-1];return n}TransformStream,TransformStream,TransformStream,TransformStream;var r=class extends TransformStream{#i="";constructor(e={allowCR:!1}){super({transform:(t,n)=>{for(t=this.#i+t;;){const r=t.indexOf("\n"),o=e.allowCR?t.indexOf("\r"):-1;if(-1!==o&&o!==t.length-1&&(-1===r||r-1>o)){n.enqueue(t.slice(0,o)),t=t.slice(o+1);continue}if(-1===r)break;const i="\r"===t[r-1]?r-1:r;n.enqueue(t.slice(0,i)),t=t.slice(r+1)}this.#i=t},flush:t=>{if(""===this.#i)return;const n=e.allowCR&&this.#i.endsWith("\r")?this.#i.slice(0,-1):this.#i;t.enqueue(n)}})}};var o=new TextEncoder,i=new TextDecoder;function s(t,n,{logger:s=new e,stdin:a=null,stdout:c="debug",stderr:u="error",env:d,cwd:h,raw:f,callback:p,buffering:m,sync:g,throw:w,dryrun:b,winext:v="",os:y=Deno.build.os}={}){"windows"===y&&(t=`${t}${v}`),s=s.with({bin:t}),p&&"piped"!==l(a)&&(a="piped");const $=new Deno.Command(t,{args:n,stdin:g?"null":l(a),stdout:l(c),stderr:l(u),env:d,cwd:h,windowsRawArguments:f});if(b){s.wdebug(`dryrun: ${t} not executed`);const e={success:!0,code:0,stdio:[],stdin:"",stdout:"",stderr:""};return g?e:Promise.resolve(e)}return g?function(e,{bin:t,log:n,throw:r,stdout:o,stderr:s}){const a=Date.now(),c=e.outputSync(),{success:u,code:d}=c,h=Date.now()-a,f={get stdio(){return[[h,1,this.stdout],[h,2,this.stderr]]},stdin:"",stdout:"piped"===l(o)?i.decode(c.stdout):"",stderr:"piped"===l(s)?i.decode(c.stderr):""};for(const{channel:e,mode:t}of[{channel:"stdout",mode:o},{channel:"stderr",mode:s}])"piped"===l(t)&&f[e]&&n.with({t:h,channel:e})[t]?.(f[e]);if(!u&&r)throw new EvalError(`${t} exited with non-zero code ${d}:\n${f.stdout}\n${f.stderr}`);return{success:u,code:d,...f}}($,{bin:t,log:s,throw:w,stdout:c,stderr:u}):async function(e,{bin:t,log:n,callback:i=({close:e})=>e?.(),buffering:s=250,throw:a,...c}){const u=e.spawn(),d=Date.now(),h={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")}},f={};let p="";const m=function(e,t){let n=null,r=null;const o=(...i)=>{o.clear(),r=()=>{o.clear(),e.call(o,...i)},n=Number(setTimeout(r,t))};return o.clear=()=>{"number"==typeof n&&(clearTimeout(n),n=null,r=null)},o.flush=()=>{r?.()},Object.defineProperty(o,"pending",{get:()=>"number"==typeof n}),o}((async e=>{n.with({t:e}).trace("debounced"),p="",await i({stdio:h,i:h.stdin.length,...f})}),s);if("piped"===l(c.stdin)){const e=u.stdin.getWriter();Object.assign(f,{async write(t,r=!0){const i=Date.now()-d;c.stdin&&n.with({t:i,channel:"stdin"})[c.stdin]?.(t),h.stdio.push([i,0,t]),r&&!t.endsWith("\n")&&(t+="\n"),await e.write(o.encode(t)),p="stdin",e.releaseLock()},async close(){try{e.releaseLock(),await u.stdin.close(),n.with({t:Date.now()-d,closed:"stdin"}).trace()}catch{}},async wait(e=1e3){const t=Date.now()-d;n.with({t:t,waiting:e}).trace(),await function(e,t={}){const{signal:n,persistent:r=!0}=t;return n?.aborted?Promise.reject(n.reason):new Promise(((t,o)=>{const i=()=>{clearTimeout(s),o(n?.reason)},s=setTimeout((()=>{n?.removeEventListener("abort",i),t()}),e);if(n?.addEventListener("abort",i,{once:!0}),!1===r)try{Deno.unrefTimer(s)}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 r)){const r=Date.now()-d,o={stdout:1,stderr:2}[e];if(c[e]&&n.with({t:r,channel:e})[c[e]]?.(t),h.stdio.length&&p===e){const e=h.stdio.at(-1);e[1]===o&&(e[2]+=`\n${t}`)}else h.stdio.push([r,o,t]);p=e,m(r)}}))),m.flush();const{success:g,code:w}=await u.status;if(!g&&a)throw new EvalError(`${t} exited with non-zero code ${w}:\n${h.stdout}\n${h.stderr}`);return{success:g,code:w,...h}}($,{bin:t,log:s,callback:p,buffering:m,throw:w,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{s as command};
1
+ var e=class e{constructor({level:t,format:r,output:n,tags:o,...i}={}){"granted"===globalThis.Deno?.permissions.querySync?.({name:"env",variable:"LOG_LEVEL"}).state&&(t??=globalThis.Deno?.env.get("LOG_LEVEL")),this.#e=n||null===n?n:console,this.#t=e.level.log,this.#r=e.format.text,this.#n={date:!1,time:!1,delta:!0,caller:{file:!1,name:!1,line:!1,fileformat:null}},this.level(t).format(r).options(i),this.tags=o??{}}#e;#n;options(e){if(!e)return structuredClone(this.#n);if("date"in e&&(this.#n.date=e.date),"time"in e&&(this.#n.time=e.time),"delta"in e&&(this.#n.delta=e.delta),"caller"in e)switch(!0){case!0===e.caller:this.#n.caller={file:!0,name:!0,line:!0,fileformat:this.#n.caller.fileformat};break;case!1===e.caller:this.#n.caller={file:!1,name:!1,line:!1,fileformat:this.#n.caller.fileformat};break;case"object"==typeof e.caller:"file"in e.caller&&(this.#n.caller.file=e.caller.file),"name"in e.caller&&(this.#n.caller.name=e.caller.name),"line"in e.caller&&(this.#n.caller.line=e.caller.line),"fileformat"in e.caller&&void 0!==e.caller.fileformat&&(this.#n.caller.fileformat=e.caller.fileformat)}return this}#t;level(t){return arguments.length?(Number.isNaN(Number.parseInt(`${t}`))||(t=Number.parseInt(`${t}`)),"string"==typeof t&&t in e.level&&(t=e.level[t]),"number"==typeof t&&(this.#t=!Number.isNaN(t)&&t>=0?t:-1),this):this.#t>=0?this.#t:NaN}static level=Object.freeze({disabled:NaN,error:0,warn:1,info:2,ok:2,log:3,debug:4,wdebug:4,trace:5,probe:NaN,always:1/0});error(...t){return this.#t>=e.level.error&&this.#e?.error(...this.#r(this,{level:"error",content:t,options:this.#n})),this}warn(...t){return this.#t>=e.level.warn&&this.#e?.warn(...this.#r(this,{level:"warn",content:t,options:this.#n})),this}info(...t){return this.#t>=e.level.info&&this.#e?.info(...this.#r(this,{level:"info",content:t,options:this.#n})),this}ok(...t){return this.#t>=e.level.info&&this.#e?.info(...this.#r(this,{level:"ok",content:t,options:this.#n})),this}log(...t){return this.#t>=e.level.log&&this.#e?.log(...this.#r(this,{level:"log",content:t,options:this.#n})),this}debug(...t){return this.#t>=e.level.debug&&this.#e?.debug(...this.#r(this,{level:"debug",content:t,options:this.#n})),this}wdebug(...t){return this.#t>=e.level.debug&&this.#e?.debug(...this.#r(this,{level:"wdebug",content:t,options:this.#n})),this}trace(...t){return this.#t>=e.level.trace&&this.#e?.debug(...this.#r(this,{level:"trace",content:t,options:this.#n})),this}probe(...e){return this.#e?.debug(...this.#r(this,{level:"probe",content:e,options:this.#n})),this}tags;with(t={}){return new e({level:this.#t,format:this.#r,output:this.#e,...this.#n,tags:{...this.tags,...t}})}#o(e=3){const t=Error,r=t.prepareStackTrace;t.prepareStackTrace=(e,t)=>t;const{stack:n}=new Error;t.prepareStackTrace=r;return n.map((e=>({file:e.getFileName(),name:e.getFunctionName(),line:e.getLineNumber(),column:e.getColumnNumber()})))[e]}static inspect(e){return globalThis.Deno?.inspect(e,{colors:!0,depth:1/0,strAbbreviateSize:1/0})??e}#r;format(t){return this.#r=("string"==typeof t?e.format[t]:t)??e.format.text,this}static format={text(t,{level:r,content:n,options:o}){const i={error:"red",warn:"orange",info:"cyan",ok:"green",log:"white",debug:"gray",wdebug:"yellow",trace:"gray",probe:"magenta"}[r],s=[`%c ${r.replace("wdebug","debug").toLocaleUpperCase().padEnd(5)} │%c`],l=[`color: black; background-color: ${i}`,""];if(o.date||o.time||o.delta){const e=(new Date).toISOString(),t=[];if(o.delta){const e=performance.now()/1e3;let r=e.toPrecision(4);e<1&&(r=e.toPrecision(2)),t.push(`+${r}`)}o.date&&o.time?t.push(e):o.date?t.push(e.slice(0,e.indexOf("T"))):o.time&&t.push(e.slice(e.indexOf("T")+1,-1)),s.push(`%c ${t.join(" ¦ ").trim()} %c`),l.push(`color: black; background-color: ${i}`,"")}if(o.caller.file||o.caller.name||o.caller.line){const e=t.#o();if(e){const t=[];if(o.caller.file){let r=`${e.file}`;Array.isArray(o.caller.fileformat)&&(r=r.replace(o.caller.fileformat[0],o.caller.fileformat[1])),t.push(r)}o.caller.name&&e.name&&t.push(e.name),o.caller.line&&t.push(e.line,e.column),s.push(`%c ${t.join(":").trim()} %c`),l.push("color: black; background-color: gray","")}}const a=[];for(const[r,n]of Object.entries(t.tags))a.push(`${r}:${e.inspect(n)}`);return s.push(`%c ${a.join(" ").trim()} %c`),l.push("background-color: black",""),[s.join(""),...l,...n.map(e.inspect)]},json(e,{level:t,content:r,options:n}){const o={level:t,timestamp:Date.now(),tags:e.tags,content:r},i={};if(n.date||n.time){const e=new Date(o.timestamp).toISOString();n.date&&(i.date=e.slice(0,e.indexOf("T"))),n.time&&(i.time=e.slice(e.indexOf("T")+1,-1))}if(n.delta&&(i.delta=performance.now()/1e3),n.caller.file||n.caller.name||n.caller.line){const t=e.#o();if(t){if(i.caller={},n.caller.file){let e=`${t.file}`;Array.isArray(n.caller.fileformat)&&(e=e.replace(n.caller.fileformat[0],n.caller.fileformat[1])),i.caller.file=e}n.caller.name&&t.name&&(i.caller.name=t.name),n.caller.line&&(i.caller.line=[t.line,t.column])}}return[JSON.stringify({...o,...i})]}}};TransformStream;function t(e){let t=0;for(const r of e)t+=r.length;const r=new Uint8Array(t);let n=0;for(const t of e)r.set(t,n),n+=t.length;return r}function r(e){const t=e.length,r=new Uint8Array(t);r[0]=0;let n=0,o=1;for(;o<t;)e[o]===e[n]?(n++,r[o]=n,o++):0===n?(r[o]=0,o++):n=r[n-1];return r}TransformStream,TransformStream,TransformStream,TransformStream,TransformStream;var n=class extends TransformStream{#i="";constructor(e={allowCR:!1}){super({transform:(t,r)=>{for(t=this.#i+t;;){const n=t.indexOf("\n"),o=e.allowCR?t.indexOf("\r"):-1;if(-1!==o&&o!==t.length-1&&(-1===n||n-1>o)){r.enqueue(t.slice(0,o)),t=t.slice(o+1);continue}if(-1===n)break;const i="\r"===t[n-1]?n-1:n;r.enqueue(t.slice(0,i)),t=t.slice(n+1)}this.#i=t},flush:t=>{if(""===this.#i)return;const r=e.allowCR&&this.#i.endsWith("\r")?this.#i.slice(0,-1):this.#i;t.enqueue(r)}})}};var o=new TextEncoder,i=new TextDecoder;function s(t,r,{logger:s=new e,stdin:a=null,stdout:c="debug",stderr:u="error",env:d,cwd:h,raw:f,callback:p,buffering:m,sync:g,throw:w,dryrun:b,winext:v="",os:y=Deno.build.os}={}){"windows"===y&&(t=`${t}${v}`),s=s.with({bin:t}),p&&"piped"!==l(a)&&(a="piped");const T=new Deno.Command(t,{args:r,stdin:g?"null":l(a),stdout:l(c),stderr:l(u),env:d,cwd:h,windowsRawArguments:f});if(b){s.wdebug(`dryrun: ${t} not executed`);const e={success:!0,code:0,stdio:[],stdin:"",stdout:"",stderr:""};return g?e:Promise.resolve(e)}return g?function(e,{bin:t,log:r,throw:n,stdout:o,stderr:s}){const a=Date.now(),c=e.outputSync(),{success:u,code:d}=c,h=Date.now()-a,f={get stdio(){return[[h,1,this.stdout],[h,2,this.stderr]]},stdin:"",stdout:"piped"===l(o)?i.decode(c.stdout):"",stderr:"piped"===l(s)?i.decode(c.stderr):""};for(const{channel:e,mode:t}of[{channel:"stdout",mode:o},{channel:"stderr",mode:s}])"piped"===l(t)&&f[e]&&r.with({t:h,channel:e})[t]?.(f[e]);if(!u&&n)throw new EvalError(`${t} exited with non-zero code ${d}:\n${f.stdout}\n${f.stderr}`);return{success:u,code:d,...f}}(T,{bin:t,log:s,throw:w,stdout:c,stderr:u}):async function(e,{bin:t,log:r,callback:i=({close:e})=>e?.(),buffering:s=250,throw:a,...c}){const u=e.spawn(),d=Date.now(),h={stdio:[],get stdin(){return this.stdio.filter((([e,t])=>0===t)).map((([e,t,r])=>r)).join("\n")},get stdout(){return this.stdio.filter((([e,t])=>1===t)).map((([e,t,r])=>r)).join("\n")},get stderr(){return this.stdio.filter((([e,t])=>2===t)).map((([e,t,r])=>r)).join("\n")}},f={};let p="";const m=function(e,t){let r=null,n=null;const o=(...i)=>{o.clear(),n=()=>{o.clear(),e.call(o,...i)},r=Number(setTimeout(n,t))};return o.clear=()=>{"number"==typeof r&&(clearTimeout(r),r=null,n=null)},o.flush=()=>{n?.()},Object.defineProperty(o,"pending",{get:()=>"number"==typeof r}),o}((async e=>{r.with({t:e}).trace("debounced"),p="",await i({stdio:h,i:h.stdin.length,...f})}),s);if("piped"===l(c.stdin)){const e=u.stdin.getWriter();Object.assign(f,{async write(t,n=!0){const i=Date.now()-d;c.stdin&&r.with({t:i,channel:"stdin"})[c.stdin]?.(t),h.stdio.push([i,0,t]),n&&!t.endsWith("\n")&&(t+="\n"),await e.write(o.encode(t)),p="stdin",e.releaseLock()},async close(){try{e.releaseLock(),await u.stdin.close(),r.with({t:Date.now()-d,closed:"stdin"}).trace()}catch{}},async wait(e=1e3){const t=Date.now()-d;r.with({t:t,waiting:e}).trace(),await function(e,t={}){const{signal:r,persistent:n=!0}=t;return r?.aborted?Promise.reject(r.reason):new Promise(((t,o)=>{const i=()=>{clearTimeout(s),o(r?.reason)},s=setTimeout((()=>{r?.removeEventListener("abort",i),t()}),e);if(r?.addEventListener("abort",i,{once:!0}),!1===n)try{Deno.unrefTimer(s)}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 n)){const n=Date.now()-d,o={stdout:1,stderr:2}[e];if(c[e]&&r.with({t:n,channel:e})[c[e]]?.(t),h.stdio.length&&p===e){const e=h.stdio.at(-1);e[1]===o&&(e[2]+=`\n${t}`)}else h.stdio.push([n,o,t]);p=e,m(n)}}))),m.flush();const{success:g,code:w}=await u.status;if(!g&&a)throw new EvalError(`${t} exited with non-zero code ${w}:\n${h.stdout}\n${h.stderr}`);return{success:g,code:w,...h}}(T,{bin:t,log:s,callback:p,buffering:m,throw:w,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{s as command};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lowlighter/run",
3
- "version": "2.0.2",
3
+ "version": "2.0.4",
4
4
  "type": "module",
5
5
  "scripts": {},
6
6
  "dependencies": {},