@lowlighter/run 2.0.4 → 3.0.0
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 +40 -0
- package/command.mjs +1 -1
- package/command.ts +10 -1
- package/command_test.ts +11 -11
- package/deno.jsonc +8 -8
- package/deno.lock +84 -66
- package/mod.mjs +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -9,6 +9,42 @@
|
|
|
9
9
|
> [!WARNING]
|
|
10
10
|
> Deno exclusive!
|
|
11
11
|
|
|
12
|
+
## 📑 Examples
|
|
13
|
+
|
|
14
|
+
### Run a command
|
|
15
|
+
|
|
16
|
+
```ts
|
|
17
|
+
import { command } from "./command.ts"
|
|
18
|
+
|
|
19
|
+
// Commands are run asynchronously, and support Deno.command options alongside additional options
|
|
20
|
+
// For example, stdio can also be set to a Logger level too or you can automatically append an extension when running on Windows
|
|
21
|
+
await command("deno", ["version"], { stdout: "debug", stderr: "piped", winext: ".exe" })
|
|
22
|
+
|
|
23
|
+
// Commands can be run synchronously too, and can also throw an error automatically when the process exits with a non-zero code
|
|
24
|
+
command("deno", ["version"], { sync: true, throw: true })
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
### Writing to stdin
|
|
28
|
+
|
|
29
|
+
```ts
|
|
30
|
+
import { command } from "./command.ts"
|
|
31
|
+
|
|
32
|
+
const { stdout } = await command("deno", ["repl"], {
|
|
33
|
+
env: { NO_COLOR: "true" },
|
|
34
|
+
// Passing a callback will automatically set `stdin` to `"piped"`
|
|
35
|
+
// You can then write to the process using utility functions
|
|
36
|
+
callback: async ({ i, stdio, write, close, wait }) => {
|
|
37
|
+
if ((!stdio.stdout.includes("exit using")) || i) {
|
|
38
|
+
return
|
|
39
|
+
}
|
|
40
|
+
await write("console.log('hello')")
|
|
41
|
+
await wait(1000)
|
|
42
|
+
close()
|
|
43
|
+
},
|
|
44
|
+
})
|
|
45
|
+
console.assert(stdout.includes("hello"))
|
|
46
|
+
```
|
|
47
|
+
|
|
12
48
|
## ✨ Features
|
|
13
49
|
|
|
14
50
|
- Supports `stdin` interactivity through callbacks.
|
|
@@ -18,6 +54,10 @@
|
|
|
18
54
|
- Optionally decide to throw an error when the process exits with a non-zero code.
|
|
19
55
|
- Generates a `stdio` history that contains timestamped entries with configurable buffering
|
|
20
56
|
|
|
57
|
+
## 🕊️ Migrating from `2.x.x` to `3.x.x`
|
|
58
|
+
|
|
59
|
+
Version `3.x.x` and onwards require Deno `2.x.x` or later.
|
|
60
|
+
|
|
21
61
|
## 📜 Licenses
|
|
22
62
|
|
|
23
63
|
```plaintext
|
package/command.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
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};
|
|
1
|
+
var e=class e{constructor({level:t,format:r,output:n,tags:o,...s}={}){"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(s),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}#o=new Map;#s=new Map;censor({values:e=[],keys:t=[],replace:r="[[redacted]]"}){return e.forEach((e=>this.#o.set(e,r))),t.forEach((e=>this.#s.set(e,r))),this}#i(e){return"string"==typeof e?this.#l(e):"object"==typeof e&&e?this.#a(e):e}#l(e){for(const[t,r]of this.#o)e=e.replaceAll(t instanceof RegExp&&!t.flags.includes("g")?new RegExp(t.source,"g"):t,r);return e}#a(e,t={}){for(const[r,n]of Object.entries(e))if(t[r]=n,"object"==typeof n&&n)t[r]=this.#a(n);else if("string"==typeof n){t[r]=this.#l(n);for(const[e,n]of this.#s)r===e&&(t[r]=n),e.test?.(r)&&(t[r]=n)}return t}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={}){const r=new e({level:this.#t,format:this.#r,output:this.#e,...this.#n,tags:{...this.tags,...t}});return this.#o.forEach(((e,t)=>r.#o.set(t,e))),this.#s.forEach(((e,t)=>r.#s.set(t,e))),r}#c(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]}#u(e){return e=this.#i(e),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(e,{level:t,content:r,options:n}){const o={error:"red",warn:"orange",info:"cyan",ok:"green",log:"white",debug:"gray",wdebug:"yellow",trace:"gray",probe:"magenta"}[t],s=[`%c ${t.replace("wdebug","debug").toLocaleUpperCase().padEnd(5)} │%c`],i=[`color: black; background-color: ${o}`,""];if(n.date||n.time||n.delta){const e=(new Date).toISOString(),t=[];if(n.delta){const e=performance.now()/1e3;let r=e.toPrecision(4);e<1&&(r=e.toPrecision(2)),t.push(`+${r}`)}n.date&&n.time?t.push(e):n.date?t.push(e.slice(0,e.indexOf("T"))):n.time&&t.push(e.slice(e.indexOf("T")+1,-1)),s.push(`%c ${t.join(" ¦ ").trim()} %c`),i.push(`color: black; background-color: ${o}`,"")}if(n.caller.file||n.caller.name||n.caller.line){const t=e.#c();if(t){const e=[];if(n.caller.file){let r=`${t.file}`;Array.isArray(n.caller.fileformat)&&(r=r.replace(n.caller.fileformat[0],n.caller.fileformat[1])),e.push(r)}n.caller.name&&t.name&&e.push(t.name),n.caller.line&&e.push(t.line,t.column),s.push(`%c ${e.join(":").trim()} %c`),i.push("color: black; background-color: gray","")}}const l=[];for(const[t,r]of Object.entries(e.tags))l.push(`${t}:${e.#u(r)}`);return s.push(`%c ${l.join(" ").trim()} %c`),i.push("background-color: black",""),[s.join(""),...i,...r.map((t=>e.#u(t)))]},json(e,{level:t,content:r,options:n}){const o={level:t,timestamp:Date.now(),tags:Object.fromEntries(Object.entries(e.tags).map((([t,r])=>[t,e.#i(r)]))),content:r.map((t=>e.#i(t)))},s={};if(n.date||n.time){const e=new Date(o.timestamp).toISOString();n.date&&(s.date=e.slice(0,e.indexOf("T"))),n.time&&(s.time=e.slice(e.indexOf("T")+1,-1))}if(n.delta&&(s.delta=performance.now()/1e3),n.caller.file||n.caller.name||n.caller.line){const t=e.#c();if(t){if(s.caller={},n.caller.file){let e=`${t.file}`;Array.isArray(n.caller.fileformat)&&(e=e.replace(n.caller.fileformat[0],n.caller.fileformat[1])),s.caller.file=e}n.caller.name&&t.name&&(s.caller.name=t.name),n.caller.line&&(s.caller.line=[t.line,t.column])}}return[JSON.stringify({...o,...s})]}}};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;var n=class extends TransformStream{#d="";constructor(e={allowCR:!1}){super({transform:(t,r)=>{for(t=this.#d+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 s="\r"===t[n-1]?n-1:n;r.enqueue(t.slice(0,s)),t=t.slice(n+1)}this.#d=t},flush:t=>{if(""===this.#d)return;const r=e.allowCR&&this.#d.endsWith("\r")?this.#d.slice(0,-1):this.#d;t.enqueue(r)}})}};var o=new TextEncoder,s=new TextDecoder;function i(t,r,{logger:i=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}`),i=i.with({bin:t}),p&&"piped"!==l(a)&&(a="piped");const k=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){i.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:i}){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)?s.decode(c.stdout):"",stderr:"piped"===l(i)?s.decode(c.stderr):""};for(const{channel:e,mode:t}of[{channel:"stdout",mode:o},{channel:"stderr",mode:i}])"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}}(k,{bin:t,log:i,throw:w,stdout:c,stderr:u}):async function(e,{bin:t,log:r,callback:s=({close:e})=>e?.(),buffering:i=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=(...s)=>{o.clear(),n=()=>{o.clear(),e.call(o,...s)},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 s({stdio:h,i:h.stdin.length,...f})}),i);if("piped"===l(c.stdin)){const e=u.stdin.getWriter();Object.assign(f,{async write(t,n=!0){const s=Date.now()-d;c.stdin&&r.with({t:s,channel:"stdin"})[c.stdin]?.(t),h.stdio.push([s,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 s=()=>{clearTimeout(i),o(r?.reason)},i=setTimeout((()=>{r?.removeEventListener("abort",s),t()}),e);if(r?.addEventListener("abort",s,{once:!0}),!1===n)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 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}}(k,{bin:t,log:i,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{i as command};
|
package/command.ts
CHANGED
|
@@ -161,9 +161,18 @@ export function command(bin: string, args: string[], options?: options & { sync:
|
|
|
161
161
|
* @example
|
|
162
162
|
* ```ts
|
|
163
163
|
* import { command } from "./command.ts"
|
|
164
|
+
*
|
|
164
165
|
* const { stdout } = await command("deno", ["repl"], {
|
|
165
166
|
* env: { NO_COLOR: "true" },
|
|
166
|
-
*
|
|
167
|
+
* // Passing a callback will automatically set `stdin` to `"piped"`
|
|
168
|
+
* // You can then write to the process using utility functions
|
|
169
|
+
* callback: async ({ i, stdio, write, close, wait }) => {
|
|
170
|
+
* if ((!stdio.stdout.includes("exit using")) || (i))
|
|
171
|
+
* return
|
|
172
|
+
* await write("console.log('hello')")
|
|
173
|
+
* await wait(1000)
|
|
174
|
+
* close()
|
|
175
|
+
* },
|
|
167
176
|
* })
|
|
168
177
|
* console.assert(stdout.includes("hello"))
|
|
169
178
|
* ```
|
package/command_test.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { Logger } from "@libs/logger"
|
|
|
2
2
|
import { command } from "./command.ts"
|
|
3
3
|
import { expect, test, type testing } from "@libs/testing"
|
|
4
4
|
|
|
5
|
-
test("deno")("command() can spawn subprocesses asynchronously", async () => {
|
|
5
|
+
test("deno")("`command()` can spawn subprocesses asynchronously", async () => {
|
|
6
6
|
let result = command("deno", ["--version"], { env: { NO_COLOR: "true" } }) as testing
|
|
7
7
|
expect(result).toBeInstanceOf(Promise)
|
|
8
8
|
result = await result
|
|
@@ -11,7 +11,7 @@ test("deno")("command() can spawn subprocesses asynchronously", async () => {
|
|
|
11
11
|
expect(result.stdout).toMatch(/deno/)
|
|
12
12
|
}, { permissions: { run: ["deno"] } })
|
|
13
13
|
|
|
14
|
-
test("deno")("command() can spawn subprocesses synchronously", () => {
|
|
14
|
+
test("deno")("`command()` can spawn subprocesses synchronously", () => {
|
|
15
15
|
const result = command("deno", ["--version"], { env: { NO_COLOR: "true" }, sync: true })
|
|
16
16
|
expect(result).not.toBeInstanceOf(Promise)
|
|
17
17
|
expect(result).toMatchObject({ success: true, code: 0, stdin: "", stderr: "" })
|
|
@@ -19,13 +19,13 @@ test("deno")("command() can spawn subprocesses synchronously", () => {
|
|
|
19
19
|
expect(result.stdout).toMatch(/deno/)
|
|
20
20
|
}, { permissions: { run: ["deno"] } })
|
|
21
21
|
|
|
22
|
-
test("deno")("command() handles callback<write()
|
|
22
|
+
test("deno")("`command()` handles `callback<write()>` and `callback<close()>` calls", async () => {
|
|
23
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"] } })
|
|
27
27
|
|
|
28
|
-
test("deno")("command() handles multiple callback<close()
|
|
28
|
+
test("deno")("`command()` handles multiple `callback<close()>` calls", async () => {
|
|
29
29
|
const result = await command("deno", ["repl"], {
|
|
30
30
|
env: { NO_COLOR: "true" },
|
|
31
31
|
callback: async ({ close }) => {
|
|
@@ -36,7 +36,7 @@ test("deno")("command() handles multiple callback<close()> calls", async () => {
|
|
|
36
36
|
expect(result).toMatchObject({ success: true, code: 0 })
|
|
37
37
|
}, { permissions: { run: ["deno"] } })
|
|
38
38
|
|
|
39
|
-
test("deno")("command() handles callback<wait()
|
|
39
|
+
test("deno")("`command()` handles `callback<wait()>` calls", async () => {
|
|
40
40
|
let waited = false
|
|
41
41
|
const result = await command("deno", ["repl"], {
|
|
42
42
|
env: { NO_COLOR: "true" },
|
|
@@ -47,7 +47,7 @@ test("deno")("command() handles callback<wait()> calls", async () => {
|
|
|
47
47
|
|
|
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
|
-
test("deno")(
|
|
50
|
+
test("deno")(`\`command()\` supports stdio set to \`"${mode}"\` in ${sync ? "sync" : "async"} mode`, async () => {
|
|
51
51
|
const result = await command("deno", ["eval", "null"], {
|
|
52
52
|
logger: new Logger({ level: "disabled" }),
|
|
53
53
|
env: { NO_COLOR: "true" },
|
|
@@ -61,7 +61,7 @@ for (const sync of [false, true]) {
|
|
|
61
61
|
}
|
|
62
62
|
}
|
|
63
63
|
|
|
64
|
-
test("deno")("command() handles both stdout and stderr channels", async () => {
|
|
64
|
+
test("deno")("`command()` handles both stdout and stderr channels", async () => {
|
|
65
65
|
const result = await command("deno", ["eval", "await Deno.stdout.write(new TextEncoder().encode(`foo\n`));await Deno.stderr.write(new TextEncoder().encode(`bar\n`))"], {
|
|
66
66
|
env: { NO_COLOR: "true" },
|
|
67
67
|
stdout: "piped",
|
|
@@ -70,7 +70,7 @@ test("deno")("command() handles both stdout and stderr channels", async () => {
|
|
|
70
70
|
expect(result).toMatchObject({ success: true, code: 0, stdout: "foo", stderr: "bar" })
|
|
71
71
|
}, { permissions: { run: ["deno"] } })
|
|
72
72
|
|
|
73
|
-
test("deno")("command() supports buffering", async () => {
|
|
73
|
+
test("deno")("`command()` supports buffering", async () => {
|
|
74
74
|
// Combined entries if buffering is greater than the time between writes
|
|
75
75
|
{
|
|
76
76
|
const result = await command("deno", ["eval", "console.log(`foo`);await new Promise(resolve => setTimeout(resolve, 100));console.log(`bar`)"], {
|
|
@@ -112,16 +112,16 @@ test("deno")("command() supports buffering", async () => {
|
|
|
112
112
|
}
|
|
113
113
|
}, { permissions: { run: ["deno"] } })
|
|
114
114
|
|
|
115
|
-
test("deno")("command() throws an error when
|
|
115
|
+
test("deno")("`command()` throws an error when throw option is enabled and exit code is non-zero", async () => {
|
|
116
116
|
expect(() => command("deno", ["eval", "Deno.exit(1)"], { env: { NO_COLOR: "true" }, throw: true, sync: true })).toThrow(EvalError)
|
|
117
117
|
await expect(command("deno", ["eval", "Deno.exit(1)"], { env: { NO_COLOR: "true" }, throw: true })).rejects.toThrow(EvalError)
|
|
118
118
|
}, { permissions: { run: ["deno"] } })
|
|
119
119
|
|
|
120
|
-
test("deno")("command() does nothing in dryrun", async () => {
|
|
120
|
+
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
124
|
|
|
125
|
-
test("deno")("command() appends windows extension when os platform is windows", () => {
|
|
125
|
+
test("deno")("`command()` appends windows extension when os platform is windows", () => {
|
|
126
126
|
expect(command("", ["--version"], { logger: new Logger({ level: "disabled" }), sync: true, winext: "deno", os: "windows" })).toMatchObject({ success: true, code: 0 })
|
|
127
127
|
}, { permissions: { run: ["deno"] } })
|
package/deno.jsonc
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"icon": "⏯️",
|
|
3
3
|
"name": "@libs/run",
|
|
4
|
-
"version": "
|
|
4
|
+
"version": "3.0.0",
|
|
5
5
|
"description": "Utilities to run subprocess.",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"subprocess",
|
|
@@ -28,9 +28,9 @@
|
|
|
28
28
|
"@std/async/delay": "jsr:@std/async@1/delay",
|
|
29
29
|
"@std/async/debounce": "jsr:@std/async@1/debounce",
|
|
30
30
|
"@std/streams": "jsr:@std/streams@1",
|
|
31
|
-
"@libs/logger": "jsr:@libs/logger@
|
|
32
|
-
"@libs/testing": "jsr:@libs/testing@
|
|
33
|
-
"@libs/typing": "jsr:@libs/typing@
|
|
31
|
+
"@libs/logger": "jsr:@libs/logger@3",
|
|
32
|
+
"@libs/testing": "jsr:@libs/testing@3",
|
|
33
|
+
"@libs/typing": "jsr:@libs/typing@3"
|
|
34
34
|
},
|
|
35
35
|
"test:permissions": {
|
|
36
36
|
"run": [
|
|
@@ -42,11 +42,11 @@
|
|
|
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='
|
|
46
|
-
"test:deno": "deno task clean:deno && deno fmt --check && deno task test --filter='
|
|
45
|
+
"dev": "deno fmt && deno task test --filter='/DENO/' && deno coverage --exclude=.js --detailed && deno task lint",
|
|
46
|
+
"test:deno": "deno task clean:deno && deno fmt --check && deno task test --filter='/DENO/' --quiet && deno coverage --exclude=.js && deno lint",
|
|
47
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='
|
|
49
|
-
"coverage:html": "deno task test --filter='
|
|
48
|
+
"test:others": "deno task clean:others && deno fmt --check && deno task test --filter='/NODE|BUN/' --quiet && deno coverage --exclude=.js && deno lint",
|
|
49
|
+
"coverage:html": "deno task test --filter='/DENO/' --quiet && deno coverage --exclude=.js --html && sleep 1",
|
|
50
50
|
"lint": "deno fmt --check && deno lint && deno doc --lint mod.ts && deno publish --dry-run --quiet --allow-dirty",
|
|
51
51
|
"clean:deno": "rm -rf node_modules .npmrc deno.lock",
|
|
52
52
|
"clean:others": "rm -rf node_modules .npmrc deno.lock package.json package-lock.json bun.lockb"
|
package/deno.lock
CHANGED
|
@@ -1,75 +1,93 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "
|
|
3
|
-
"
|
|
4
|
-
"
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
2
|
+
"version": "4",
|
|
3
|
+
"specifiers": {
|
|
4
|
+
"jsr:@libs/logger@*": "3.0.0",
|
|
5
|
+
"jsr:@libs/logger@3": "3.0.0",
|
|
6
|
+
"jsr:@libs/testing@3": "3.0.0",
|
|
7
|
+
"jsr:@libs/typing@2": "2.9.0",
|
|
8
|
+
"jsr:@libs/typing@3": "3.0.0",
|
|
9
|
+
"jsr:@std/assert@1": "1.0.6",
|
|
10
|
+
"jsr:@std/assert@^1.0.6": "1.0.6",
|
|
11
|
+
"jsr:@std/async@1": "1.0.5",
|
|
12
|
+
"jsr:@std/bytes@^1.0.2": "1.0.2",
|
|
13
|
+
"jsr:@std/expect@1": "1.0.4",
|
|
14
|
+
"jsr:@std/fmt@1": "1.0.2",
|
|
15
|
+
"jsr:@std/html@1": "1.0.3",
|
|
16
|
+
"jsr:@std/http@1": "1.0.7",
|
|
17
|
+
"jsr:@std/internal@^1.0.4": "1.0.4",
|
|
18
|
+
"jsr:@std/streams@1": "1.0.6",
|
|
19
|
+
"npm:highlight.js@11": "11.10.0"
|
|
20
|
+
},
|
|
21
|
+
"jsr": {
|
|
22
|
+
"@libs/logger@3.0.0": {
|
|
23
|
+
"integrity": "c3372ddc9f057ab39248ba51c404984be779fe9d5d9a54ef548714fc2d5512ff"
|
|
24
|
+
},
|
|
25
|
+
"@libs/testing@3.0.0": {
|
|
26
|
+
"integrity": "514547988fadac36890692ccafc932546d9e27680df1b736dd7674ad2e7c9625",
|
|
27
|
+
"dependencies": [
|
|
28
|
+
"jsr:@libs/typing@2",
|
|
29
|
+
"jsr:@std/assert@1",
|
|
30
|
+
"jsr:@std/expect",
|
|
31
|
+
"jsr:@std/fmt",
|
|
32
|
+
"jsr:@std/html",
|
|
33
|
+
"jsr:@std/http",
|
|
34
|
+
"npm:highlight.js"
|
|
35
|
+
]
|
|
36
|
+
},
|
|
37
|
+
"@libs/typing@2.9.0": {
|
|
38
|
+
"integrity": "ddf35ea652b807cd9b19b4f3f163fb5d76d57299053753fbd01ba8b02d9306ad"
|
|
39
|
+
},
|
|
40
|
+
"@libs/typing@3.0.0": {
|
|
41
|
+
"integrity": "f84ffbbdcbb6a02e6a527911b1399dc79f6ad213aec4ad0a86c95df4b353738f"
|
|
42
|
+
},
|
|
43
|
+
"@std/assert@1.0.6": {
|
|
44
|
+
"integrity": "1904c05806a25d94fe791d6d883b685c9e2dcd60e4f9fc30f4fc5cf010c72207",
|
|
45
|
+
"dependencies": [
|
|
46
|
+
"jsr:@std/internal"
|
|
47
|
+
]
|
|
48
|
+
},
|
|
49
|
+
"@std/async@1.0.5": {
|
|
50
|
+
"integrity": "31d68214bfbb31bd4c6022401d484e3964147c76c9220098baa703a39b6c2da6"
|
|
51
|
+
},
|
|
52
|
+
"@std/bytes@1.0.2": {
|
|
53
|
+
"integrity": "fbdee322bbd8c599a6af186a1603b3355e59a5fb1baa139f8f4c3c9a1b3e3d57"
|
|
17
54
|
},
|
|
18
|
-
"
|
|
19
|
-
"
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
"
|
|
47
|
-
"integrity": "44075d9c2cb701ddfc4d5a260da2fb26ba3cfd94c45d3a0359f63cabbf85a058",
|
|
48
|
-
"dependencies": [
|
|
49
|
-
"jsr:@std/assert@^1.0.3",
|
|
50
|
-
"jsr:@std/internal@^1.0.2"
|
|
51
|
-
]
|
|
52
|
-
},
|
|
53
|
-
"@std/http@1.0.4": {
|
|
54
|
-
"integrity": "1a8142217907d49c4687f90ef3d257e7df2baf344c5122c322d7316df09df453"
|
|
55
|
-
},
|
|
56
|
-
"@std/internal@1.0.2": {
|
|
57
|
-
"integrity": "f4cabe2021352e8bfc24e6569700df87bf070914fc38d4b23eddd20108ac4495"
|
|
58
|
-
},
|
|
59
|
-
"@std/streams@1.0.3": {
|
|
60
|
-
"integrity": "d62e645ab981cee2c3d03040eb03cf387fc6bceef6d4564f3ed485a43741a81f",
|
|
61
|
-
"dependencies": [
|
|
62
|
-
"jsr:@std/bytes@^1.0.2"
|
|
63
|
-
]
|
|
64
|
-
}
|
|
55
|
+
"@std/expect@1.0.4": {
|
|
56
|
+
"integrity": "97f68a445a9de0d9670200d2b7a19a7505a01b2cb390a983ba8d97d90ce30c4f",
|
|
57
|
+
"dependencies": [
|
|
58
|
+
"jsr:@std/assert@^1.0.6",
|
|
59
|
+
"jsr:@std/internal"
|
|
60
|
+
]
|
|
61
|
+
},
|
|
62
|
+
"@std/fmt@1.0.2": {
|
|
63
|
+
"integrity": "87e9dfcdd3ca7c066e0c3c657c1f987c82888eb8103a3a3baa62684ffeb0f7a7"
|
|
64
|
+
},
|
|
65
|
+
"@std/html@1.0.3": {
|
|
66
|
+
"integrity": "7a0ac35e050431fb49d44e61c8b8aac1ebd55937e0dc9ec6409aa4bab39a7988"
|
|
67
|
+
},
|
|
68
|
+
"@std/http@1.0.7": {
|
|
69
|
+
"integrity": "9b904fc256678a5c9759f1a53a24a3fdcc59d83dc62099bb472683b6f819194c"
|
|
70
|
+
},
|
|
71
|
+
"@std/internal@1.0.4": {
|
|
72
|
+
"integrity": "62e8e4911527e5e4f307741a795c0b0a9e6958d0b3790716ae71ce085f755422"
|
|
73
|
+
},
|
|
74
|
+
"@std/streams@1.0.6": {
|
|
75
|
+
"integrity": "022ed94e380d06b4d91c49eb70241b7289ab78b8c2b4c4bbb7eb265e4997c25c",
|
|
76
|
+
"dependencies": [
|
|
77
|
+
"jsr:@std/bytes"
|
|
78
|
+
]
|
|
79
|
+
}
|
|
80
|
+
},
|
|
81
|
+
"npm": {
|
|
82
|
+
"highlight.js@11.10.0": {
|
|
83
|
+
"integrity": "sha512-SYVnVFswQER+zu1laSya563s+F8VDGt7o35d4utbamowvUNLLMovFqwCLSocpZTz3MgaSRA1IbqRWZv97dtErQ=="
|
|
65
84
|
}
|
|
66
85
|
},
|
|
67
|
-
"remote": {},
|
|
68
86
|
"workspace": {
|
|
69
87
|
"dependencies": [
|
|
70
|
-
"jsr:@libs/logger@
|
|
71
|
-
"jsr:@libs/testing@
|
|
72
|
-
"jsr:@libs/typing@
|
|
88
|
+
"jsr:@libs/logger@3",
|
|
89
|
+
"jsr:@libs/testing@3",
|
|
90
|
+
"jsr:@libs/typing@3",
|
|
73
91
|
"jsr:@std/async@1",
|
|
74
92
|
"jsr:@std/streams@1"
|
|
75
93
|
]
|
package/mod.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
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};
|
|
1
|
+
var e=class e{constructor({level:t,format:r,output:n,tags:o,...s}={}){"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(s),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}#o=new Map;#s=new Map;censor({values:e=[],keys:t=[],replace:r="[[redacted]]"}){return e.forEach((e=>this.#o.set(e,r))),t.forEach((e=>this.#s.set(e,r))),this}#i(e){return"string"==typeof e?this.#l(e):"object"==typeof e&&e?this.#a(e):e}#l(e){for(const[t,r]of this.#o)e=e.replaceAll(t instanceof RegExp&&!t.flags.includes("g")?new RegExp(t.source,"g"):t,r);return e}#a(e,t={}){for(const[r,n]of Object.entries(e))if(t[r]=n,"object"==typeof n&&n)t[r]=this.#a(n);else if("string"==typeof n){t[r]=this.#l(n);for(const[e,n]of this.#s)r===e&&(t[r]=n),e.test?.(r)&&(t[r]=n)}return t}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={}){const r=new e({level:this.#t,format:this.#r,output:this.#e,...this.#n,tags:{...this.tags,...t}});return this.#o.forEach(((e,t)=>r.#o.set(t,e))),this.#s.forEach(((e,t)=>r.#s.set(t,e))),r}#c(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]}#u(e){return e=this.#i(e),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(e,{level:t,content:r,options:n}){const o={error:"red",warn:"orange",info:"cyan",ok:"green",log:"white",debug:"gray",wdebug:"yellow",trace:"gray",probe:"magenta"}[t],s=[`%c ${t.replace("wdebug","debug").toLocaleUpperCase().padEnd(5)} │%c`],i=[`color: black; background-color: ${o}`,""];if(n.date||n.time||n.delta){const e=(new Date).toISOString(),t=[];if(n.delta){const e=performance.now()/1e3;let r=e.toPrecision(4);e<1&&(r=e.toPrecision(2)),t.push(`+${r}`)}n.date&&n.time?t.push(e):n.date?t.push(e.slice(0,e.indexOf("T"))):n.time&&t.push(e.slice(e.indexOf("T")+1,-1)),s.push(`%c ${t.join(" ¦ ").trim()} %c`),i.push(`color: black; background-color: ${o}`,"")}if(n.caller.file||n.caller.name||n.caller.line){const t=e.#c();if(t){const e=[];if(n.caller.file){let r=`${t.file}`;Array.isArray(n.caller.fileformat)&&(r=r.replace(n.caller.fileformat[0],n.caller.fileformat[1])),e.push(r)}n.caller.name&&t.name&&e.push(t.name),n.caller.line&&e.push(t.line,t.column),s.push(`%c ${e.join(":").trim()} %c`),i.push("color: black; background-color: gray","")}}const l=[];for(const[t,r]of Object.entries(e.tags))l.push(`${t}:${e.#u(r)}`);return s.push(`%c ${l.join(" ").trim()} %c`),i.push("background-color: black",""),[s.join(""),...i,...r.map((t=>e.#u(t)))]},json(e,{level:t,content:r,options:n}){const o={level:t,timestamp:Date.now(),tags:Object.fromEntries(Object.entries(e.tags).map((([t,r])=>[t,e.#i(r)]))),content:r.map((t=>e.#i(t)))},s={};if(n.date||n.time){const e=new Date(o.timestamp).toISOString();n.date&&(s.date=e.slice(0,e.indexOf("T"))),n.time&&(s.time=e.slice(e.indexOf("T")+1,-1))}if(n.delta&&(s.delta=performance.now()/1e3),n.caller.file||n.caller.name||n.caller.line){const t=e.#c();if(t){if(s.caller={},n.caller.file){let e=`${t.file}`;Array.isArray(n.caller.fileformat)&&(e=e.replace(n.caller.fileformat[0],n.caller.fileformat[1])),s.caller.file=e}n.caller.name&&t.name&&(s.caller.name=t.name),n.caller.line&&(s.caller.line=[t.line,t.column])}}return[JSON.stringify({...o,...s})]}}};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;var n=class extends TransformStream{#d="";constructor(e={allowCR:!1}){super({transform:(t,r)=>{for(t=this.#d+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 s="\r"===t[n-1]?n-1:n;r.enqueue(t.slice(0,s)),t=t.slice(n+1)}this.#d=t},flush:t=>{if(""===this.#d)return;const r=e.allowCR&&this.#d.endsWith("\r")?this.#d.slice(0,-1):this.#d;t.enqueue(r)}})}};var o=new TextEncoder,s=new TextDecoder;function i(t,r,{logger:i=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}`),i=i.with({bin:t}),p&&"piped"!==l(a)&&(a="piped");const k=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){i.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:i}){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)?s.decode(c.stdout):"",stderr:"piped"===l(i)?s.decode(c.stderr):""};for(const{channel:e,mode:t}of[{channel:"stdout",mode:o},{channel:"stderr",mode:i}])"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}}(k,{bin:t,log:i,throw:w,stdout:c,stderr:u}):async function(e,{bin:t,log:r,callback:s=({close:e})=>e?.(),buffering:i=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=(...s)=>{o.clear(),n=()=>{o.clear(),e.call(o,...s)},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 s({stdio:h,i:h.stdin.length,...f})}),i);if("piped"===l(c.stdin)){const e=u.stdin.getWriter();Object.assign(f,{async write(t,n=!0){const s=Date.now()-d;c.stdin&&r.with({t:s,channel:"stdin"})[c.stdin]?.(t),h.stdio.push([s,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 s=()=>{clearTimeout(i),o(r?.reason)},i=setTimeout((()=>{r?.removeEventListener("abort",s),t()}),e);if(r?.addEventListener("abort",s,{once:!0}),!1===n)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 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}}(k,{bin:t,log:i,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{i as command};
|