@lowlighter/run 0.2.0 → 1.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -6,9 +6,12 @@
6
6
  - [`🦕 Playground`](https://libs.lecoq.io/run)
7
7
  - [`📚 Documentation`](https://jsr.io/@libs/run/doc)
8
8
 
9
+ > [!WARNING]
10
+ > Deno exclusive!
11
+
9
12
  ## 📜 Licenses
10
13
 
11
- ```
12
- Copyright (c) Lecoq Simon <@lowlighter>. (MIT License)
14
+ ```plaintext
15
+ Copyright (c) Simon Lecoq <@lowlighter>. (MIT License)
13
16
  https://github.com/lowlighter/libs/blob/main/LICENSE
14
17
  ```
package/command.mjs CHANGED
@@ -1,4 +1,4 @@
1
- var e=class e{constructor({level:t,format:n,output:o,tags:r,options:s}={}){if("granted"===globalThis.Deno?.permissions.querySync?.({name:"env",variable:"LOG_LEVEL"}).state){const n=globalThis.Deno?.env.get("LOG_LEVEL")??"";n in e.level&&(t??=e.level[n]),Number.isNaN(Number.parseInt(n))||(t??=Number.parseInt(n))}this.level=t??e.level.log,this.#e=o||null===o?o:console,this.#t=n??e.format.text,this.tags=r??{},this.options={date:!1,time:!1,delta:!0,...s,caller:!1!==s?.caller&&{file:!1,name:!1,line:!1,...s?.caller}}}level;#t;#e;tags;options;error(...t){return this.level>=e.level.error&&this.#e?.error(...this.#t(this,{level:e.level.error,content:t})),this}warn(...t){return this.level>=e.level.warn&&this.#e?.warn(...this.#t(this,{level:e.level.warn,content:t})),this}info(...t){return this.level>=e.level.info&&this.#e?.info(...this.#t(this,{level:e.level.info,content:t})),this}log(...t){return this.level>=e.level.log&&this.#e?.log(...this.#t(this,{level:e.level.log,content:t})),this}debug(...t){return this.level>=e.level.debug&&this.#e?.debug(...this.#t(this,{level:e.level.debug,content:t})),this}with(t={}){return new e({level:this.level,format:this.#t,output:this.#e,options:{...this.options},tags:{...this.tags,...t}})}#n(e=3){const t=Error,n=t.prepareStackTrace;t.prepareStackTrace=(e,t)=>t;const{stack:o}=new Error;t.prepareStackTrace=n;const r=o[e];return{file:r.getFileName(),name:r.getFunctionName(),line:r.getLineNumber(),column:r.getColumnNumber()}}static level=Object.freeze({disabled:NaN,error:0,warn:1,info:2,log:3,debug:4});static format={text(t,{level:n=0,content:o}){const r=["red","orange","cyan","white","gray"][n],s=[`%c ${Object.keys(e.level).find((t=>e.level[t]===n)).toLocaleUpperCase().padEnd(5)} │%c`],i=[`color: black; background-color: ${r}`,""];if(t.options.date||t.options.time||t.options.delta){const e=(new Date).toISOString(),n=[];if(t.options.delta){const e=performance.now()/1e3;let t=e.toPrecision(4);e<1&&(t=e.toPrecision(2)),n.push(`+${t}`)}t.options.date&&t.options.time?n.push(e):t.options.date?n.push(e.slice(0,e.indexOf("T"))):t.options.time&&n.push(e.slice(e.indexOf("T")+1,-1)),s.push(`%c ${n.join(" ¦ ").trim()} %c`),i.push(`color: black; background-color: ${r}`,"")}if(t.options.caller){const e=t.#n();if(e){const n=[];t.options.caller.file&&n.push(`${e.file.replace(t.options.caller.fileformat,"$<file>")}`),t.options.caller.name&&e.name&&n.push(e.name),t.options.caller.line&&n.push(e.line,e.column),s.push(`%c ${n.join(":").trim()} %c`),i.push("color: black; background-color: gray","")}}{const n=[];for(const[o,r]of Object.entries(t.tags))n.push(`${o}:${e.inspect(r)}`);s.push(`%c ${n.join(" ").trim()} %c`),i.push("background-color: black","")}return[s.join(""),...i,...o.map(e.inspect)]},json(t,{level:n=0,content:o}){const r={level:Object.keys(e.level).find((t=>e.level[t]===n)),timestamp:Date.now(),tags:t.tags,content:o},s={};if(t.options.date||t.options.time){const e=new Date(r.timestamp).toISOString();t.options.date&&(s.date=e.slice(0,e.indexOf("T"))),t.options.time&&(s.time=e.slice(e.indexOf("T")+1,-1))}if(t.options.delta&&(s.delta=performance.now()/1e3),t.options.caller){const e=t.#n();e&&(s.caller={},t.options.caller.file&&(s.caller.file=`${e.file.replace(t.options.caller.fileformat,"$<file>")}`),t.options.caller.name&&e.name&&(s.caller.name=e.name),t.options.caller.line&&(s.caller.line=[e.line,e.column]))}return[JSON.stringify({...r,...s})]}};static inspect(e){return globalThis.Deno?.inspect(e,{colors:!0,depth:1/0})??e}},t=class extends Error{constructor(e){super(e),this.name="AssertionError"}};TransformStream;function n(e){let t=0;for(const n of e)t+=n.length;const n=new Uint8Array(t);let o=0;for(const t of e)n.set(t,o),o+=t.length;return n}function o(e){const t=e.length,n=new Uint8Array(t);n[0]=0;let o=0,r=1;for(;r<t;)e[r]===e[o]?(o++,n[r]=o,r++):0===o?(n[r]=0,r++):o=n[o-1];return n}TransformStream,TransformStream,TransformStream,TransformStream;var r=class extends TransformStream{#o="";constructor(e={allowCR:!1}){super({transform:(t,n)=>{for(t=this.#o+t;;){const o=t.indexOf("\n"),r=e.allowCR?t.indexOf("\r"):-1;if(-1!==r&&r!==t.length-1&&(-1===o||o-1>r)){n.enqueue(t.slice(0,r)),t=t.slice(r+1);continue}if(-1===o)break;const s="\r"===t[o-1]?o-1:o;n.enqueue(t.slice(0,s)),t=t.slice(o+1)}this.#o=t},flush:t=>{if(""===this.#o)return;const n=e.allowCR&&this.#o.endsWith("\r")?this.#o.slice(0,-1):this.#o;t.enqueue(n)}})}};new TextDecoder;var s=new TextEncoder,i=new TextDecoder;function l(t,n,{log:o=new e,stdin:l=null,stdout:c="debug",stderr:u="error",env:d,cwd:p,raw:h,callback:f,buffering:m,sync:w,throw:g,winext:b="",os:v=Deno.build.os}={}){"windows"===v&&(t=`${t}${b}`),o=o.with({bin:t}),f&&"piped"!==a(l)&&(l="piped");const T=new Deno.Command(t,{args:n,stdin:w?"null":a(l),stdout:a(c),stderr:a(u),env:d,cwd:p,windowsRawArguments:h});return w?function(e,{bin:t,log:n,throw:o,stdout:r,stderr:s}){const l=Date.now(),c=e.outputSync(),{success:u,code:d}=c,p=Date.now()-l,h={get stdio(){return[[p,1,this.stdout],[p,2,this.stderr]]},stdin:"",stdout:"piped"===a(r)?i.decode(c.stdout):"",stderr:"piped"===a(s)?i.decode(c.stderr):""};for(const{channel:e,mode:t}of[{channel:"stdout",mode:r},{channel:"stderr",mode:s}])"piped"===a(t)&&h[e]&&n.with({t:p,channel:e})[t]?.(h[e]);if(!u&&o)throw new EvalError(`${t} exited with non-zero code ${d}:\n${h.stdout}\n${h.stderr}`);return{success:u,code:d,...h}}(T,{bin:t,log:o,throw:g,stdout:c,stderr:u}):async function(e,{bin:t,log:n,callback:o=(({close:e})=>e?.()),buffering:i=250,throw:l,...c}){const u=e.spawn(),d=Date.now(),p={stdio:[],get stdin(){return this.stdio.filter((([e,t])=>0===t)).map((([e,t,n])=>n)).join("\n")},get stdout(){return this.stdio.filter((([e,t])=>1===t)).map((([e,t,n])=>n)).join("\n")},get stderr(){return this.stdio.filter((([e,t])=>2===t)).map((([e,t,n])=>n)).join("\n")}},h={};let f="";const m=function(e,t){let n=null,o=null;const r=(...s)=>{r.clear(),o=()=>{r.clear(),e.call(r,...s)},n=setTimeout(o,t)};return r.clear=()=>{"number"==typeof n&&(clearTimeout(n),n=null,o=null)},r.flush=()=>{o?.()},Object.defineProperty(r,"pending",{get:()=>"number"==typeof n}),r}((async e=>{n.with({t:e}).debug("debounced"),f="",await o({stdio:p,i:p.stdin.length,...h})}),i);if("piped"===a(c.stdin)){const e=u.stdin.getWriter();Object.assign(h,{async write(t,o=!0){const r=Date.now()-d;c.stdin&&n.with({t:r,channel:"stdin"})[c.stdin]?.(t),p.stdio.push([r,0,t]),o&&!t.endsWith("\n")&&(t+="\n"),await e.write(s.encode(t)),f="stdin",e.releaseLock()},async close(){try{e.releaseLock(),await u.stdin.close(),n.with({t:Date.now()-d,closed:"stdin"}).debug()}catch{}},async wait(e=1e3){const t=Date.now()-d;n.with({t:t,waiting:e}).debug(),await function(e,t={}){const{signal:n,persistent:o=!0}=t;return n?.aborted?Promise.reject(n.reason):new Promise(((t,r)=>{const s=()=>{clearTimeout(i),r(n?.reason)},i=setTimeout((()=>{n?.removeEventListener("abort",s),t()}),e);if(n?.addEventListener("abort",s,{once:!0}),!1===o)try{Deno.unrefTimer(i)}catch(e){if(!(e instanceof ReferenceError))throw e;console.error("`persistent` option is only available in Deno")}}))}(e),m(t)}}),m(Date.now()-d)}await Promise.all(["stdout","stderr"].filter((e=>"piped"===a(c[e]))).map((async e=>{for await(const t of u[e].pipeThrough(new TextDecoderStream).pipeThrough(new r)){const o=Date.now()-d,r={stdout:1,stderr:2}[e];if(c[e]&&n.with({t:o,channel:e})[c[e]]?.(t),p.stdio.length&&f===e){const e=p.stdio.at(-1);e[1]===r&&(e[2]+=`\n${t}`)}else p.stdio.push([o,r,t]);f=e,m(o)}}))),m.flush();const{success:w,code:g}=await u.status;if(!w&&l)throw new EvalError(`${t} exited with non-zero code ${g}:\n${p.stdout}\n${p.stderr}`);return{success:w,code:g,...p}}(T,{bin:t,log:o,callback:f,buffering:m,throw:g,stdin:"piped"===a(l)?l:null,stdout:"piped"===a(c)?c:null,stderr:"piped"===a(u)?u:null})}function a(e){return["inherit","null"].includes(`${e}`)?`${e}`:"piped"}export{l as command};
1
+ var e=class e{constructor({level:t,format:n,output:o,tags:r,options:s}={}){if("granted"===globalThis.Deno?.permissions.querySync?.({name:"env",variable:"LOG_LEVEL"}).state){const n=globalThis.Deno?.env.get("LOG_LEVEL")??"";n in e.level&&(t??=e.level[n]),Number.isNaN(Number.parseInt(n))||(t??=Number.parseInt(n))}this.level=t??e.level.log,this.#e=o||null===o?o:console,this.#t=n??e.format.text,this.tags=r??{},this.options={date:!1,time:!1,delta:!0,...s,caller:!1!==s?.caller&&{file:!1,name:!1,line:!1,...s?.caller}}}level;#t;#e;tags;options;error(...t){return this.level>=e.level.error&&this.#e?.error(...this.#t(this,{level:e.level.error,content:t})),this}warn(...t){return this.level>=e.level.warn&&this.#e?.warn(...this.#t(this,{level:e.level.warn,content:t})),this}info(...t){return this.level>=e.level.info&&this.#e?.info(...this.#t(this,{level:e.level.info,content:t})),this}log(...t){return this.level>=e.level.log&&this.#e?.log(...this.#t(this,{level:e.level.log,content:t})),this}debug(...t){return this.level>=e.level.debug&&this.#e?.debug(...this.#t(this,{level:e.level.debug,content:t})),this}with(t={}){return new e({level:this.level,format:this.#t,output:this.#e,options:{...this.options},tags:{...this.tags,...t}})}#n(e=3){const t=Error,n=t.prepareStackTrace;t.prepareStackTrace=(e,t)=>t;const{stack:o}=new Error;t.prepareStackTrace=n;const r=o[e];return{file:r.getFileName(),name:r.getFunctionName(),line:r.getLineNumber(),column:r.getColumnNumber()}}static level=Object.freeze({disabled:NaN,error:0,warn:1,info:2,log:3,debug:4});static format={text(t,{level:n=0,content:o}){const r=["red","orange","cyan","white","gray"][n],s=[`%c ${Object.keys(e.level).find((t=>e.level[t]===n)).toLocaleUpperCase().padEnd(5)} │%c`],i=[`color: black; background-color: ${r}`,""];if(t.options.date||t.options.time||t.options.delta){const e=(new Date).toISOString(),n=[];if(t.options.delta){const e=performance.now()/1e3;let t=e.toPrecision(4);e<1&&(t=e.toPrecision(2)),n.push(`+${t}`)}t.options.date&&t.options.time?n.push(e):t.options.date?n.push(e.slice(0,e.indexOf("T"))):t.options.time&&n.push(e.slice(e.indexOf("T")+1,-1)),s.push(`%c ${n.join(" ¦ ").trim()} %c`),i.push(`color: black; background-color: ${r}`,"")}if(t.options.caller){const e=t.#n();if(e){const n=[];t.options.caller.file&&n.push(`${e.file.replace(t.options.caller.fileformat,"$<file>")}`),t.options.caller.name&&e.name&&n.push(e.name),t.options.caller.line&&n.push(e.line,e.column),s.push(`%c ${n.join(":").trim()} %c`),i.push("color: black; background-color: gray","")}}{const n=[];for(const[o,r]of Object.entries(t.tags))n.push(`${o}:${e.inspect(r)}`);s.push(`%c ${n.join(" ").trim()} %c`),i.push("background-color: black","")}return[s.join(""),...i,...o.map(e.inspect)]},json(t,{level:n=0,content:o}){const r={level:Object.keys(e.level).find((t=>e.level[t]===n)),timestamp:Date.now(),tags:t.tags,content:o},s={};if(t.options.date||t.options.time){const e=new Date(r.timestamp).toISOString();t.options.date&&(s.date=e.slice(0,e.indexOf("T"))),t.options.time&&(s.time=e.slice(e.indexOf("T")+1,-1))}if(t.options.delta&&(s.delta=performance.now()/1e3),t.options.caller){const e=t.#n();e&&(s.caller={},t.options.caller.file&&(s.caller.file=`${e.file.replace(t.options.caller.fileformat,"$<file>")}`),t.options.caller.name&&e.name&&(s.caller.name=e.name),t.options.caller.line&&(s.caller.line=[e.line,e.column]))}return[JSON.stringify({...r,...s})]}};static inspect(e){return globalThis.Deno?.inspect(e,{colors:!0,depth:1/0,strAbbreviateSize:1/0})??e}};TransformStream;function t(e){let t=0;for(const n of e)t+=n.length;const n=new Uint8Array(t);let o=0;for(const t of e)n.set(t,o),o+=t.length;return n}function n(e){const t=e.length,n=new Uint8Array(t);n[0]=0;let o=0,r=1;for(;r<t;)e[r]===e[o]?(o++,n[r]=o,r++):0===o?(n[r]=0,r++):o=n[o-1];return n}TransformStream,TransformStream,TransformStream,TransformStream;var o=class extends TransformStream{#o="";constructor(e={allowCR:!1}){super({transform:(t,n)=>{for(t=this.#o+t;;){const o=t.indexOf("\n"),r=e.allowCR?t.indexOf("\r"):-1;if(-1!==r&&r!==t.length-1&&(-1===o||o-1>r)){n.enqueue(t.slice(0,r)),t=t.slice(r+1);continue}if(-1===o)break;const s="\r"===t[o-1]?o-1:o;n.enqueue(t.slice(0,s)),t=t.slice(o+1)}this.#o=t},flush:t=>{if(""===this.#o)return;const n=e.allowCR&&this.#o.endsWith("\r")?this.#o.slice(0,-1):this.#o;t.enqueue(n)}})}};new TextDecoder;var r=new TextEncoder,s=new TextDecoder;function i(t,n,{log:i=new e,stdin:a=null,stdout:c="debug",stderr:u="error",env:d,cwd:p,raw:h,callback:f,buffering:m,sync:w,throw:g,dryrun:b,winext:v="",os:T=Deno.build.os}={}){"windows"===T&&(t=`${t}${v}`),i=i.with({bin:t}),f&&"piped"!==l(a)&&(a="piped");const $=new Deno.Command(t,{args:n,stdin:w?"null":l(a),stdout:l(c),stderr:l(u),env:d,cwd:p,windowsRawArguments:h});if(b){i.debug(`dryrun: ${t} not executed`);const e={success:!0,code:0,stdio:[],stdin:"",stdout:"",stderr:""};return w?e:Promise.resolve(e)}return w?function(e,{bin:t,log:n,throw:o,stdout:r,stderr:i}){const a=Date.now(),c=e.outputSync(),{success:u,code:d}=c,p=Date.now()-a,h={get stdio(){return[[p,1,this.stdout],[p,2,this.stderr]]},stdin:"",stdout:"piped"===l(r)?s.decode(c.stdout):"",stderr:"piped"===l(i)?s.decode(c.stderr):""};for(const{channel:e,mode:t}of[{channel:"stdout",mode:r},{channel:"stderr",mode:i}])"piped"===l(t)&&h[e]&&n.with({t:p,channel:e})[t]?.(h[e]);if(!u&&o)throw new EvalError(`${t} exited with non-zero code ${d}:\n${h.stdout}\n${h.stderr}`);return{success:u,code:d,...h}}($,{bin:t,log:i,throw:g,stdout:c,stderr:u}):async function(e,{bin:t,log:n,callback:s=(({close:e})=>e?.()),buffering:i=250,throw:a,...c}){const u=e.spawn(),d=Date.now(),p={stdio:[],get stdin(){return this.stdio.filter((([e,t])=>0===t)).map((([e,t,n])=>n)).join("\n")},get stdout(){return this.stdio.filter((([e,t])=>1===t)).map((([e,t,n])=>n)).join("\n")},get stderr(){return this.stdio.filter((([e,t])=>2===t)).map((([e,t,n])=>n)).join("\n")}},h={};let f="";const m=function(e,t){let n=null,o=null;const r=(...s)=>{r.clear(),o=()=>{r.clear(),e.call(r,...s)},n=setTimeout(o,t)};return r.clear=()=>{"number"==typeof n&&(clearTimeout(n),n=null,o=null)},r.flush=()=>{o?.()},Object.defineProperty(r,"pending",{get:()=>"number"==typeof n}),r}((async e=>{n.with({t:e}).debug("debounced"),f="",await s({stdio:p,i:p.stdin.length,...h})}),i);if("piped"===l(c.stdin)){const e=u.stdin.getWriter();Object.assign(h,{async write(t,o=!0){const s=Date.now()-d;c.stdin&&n.with({t:s,channel:"stdin"})[c.stdin]?.(t),p.stdio.push([s,0,t]),o&&!t.endsWith("\n")&&(t+="\n"),await e.write(r.encode(t)),f="stdin",e.releaseLock()},async close(){try{e.releaseLock(),await u.stdin.close(),n.with({t:Date.now()-d,closed:"stdin"}).debug()}catch{}},async wait(e=1e3){const t=Date.now()-d;n.with({t:t,waiting:e}).debug(),await function(e,t={}){const{signal:n,persistent:o=!0}=t;return n?.aborted?Promise.reject(n.reason):new Promise(((t,r)=>{const s=()=>{clearTimeout(i),r(n?.reason)},i=setTimeout((()=>{n?.removeEventListener("abort",s),t()}),e);if(n?.addEventListener("abort",s,{once:!0}),!1===o)try{Deno.unrefTimer(i)}catch(e){if(!(e instanceof ReferenceError))throw e;console.error("`persistent` option is only available in Deno")}}))}(e),m(t)}}),m(Date.now()-d)}await Promise.all(["stdout","stderr"].filter((e=>"piped"===l(c[e]))).map((async e=>{for await(const t of u[e].pipeThrough(new TextDecoderStream).pipeThrough(new o)){const o=Date.now()-d,r={stdout:1,stderr:2}[e];if(c[e]&&n.with({t:o,channel:e})[c[e]]?.(t),p.stdio.length&&f===e){const e=p.stdio.at(-1);e[1]===r&&(e[2]+=`\n${t}`)}else p.stdio.push([o,r,t]);f=e,m(o)}}))),m.flush();const{success:w,code:g}=await u.status;if(!w&&a)throw new EvalError(`${t} exited with non-zero code ${g}:\n${p.stdout}\n${p.stderr}`);return{success:w,code:g,...p}}($,{bin:t,log:i,callback:f,buffering:m,throw:g,stdin:"piped"===l(a)?a:null,stdout:"piped"===l(c)?c:null,stderr:"piped"===l(u)?u:null})}function l(e){return["inherit","null"].includes(`${e}`)?`${e}`:"piped"}export{i as command};
2
2
  /**
3
3
  * Logger library
4
4
  *
package/command.ts CHANGED
@@ -45,6 +45,11 @@ export type options = {
45
45
  os?: typeof Deno.build.os
46
46
  /** Throw an error if exit code is non-zero rather than returning a result. */
47
47
  throw?: boolean
48
+ /**
49
+ * Do not actually execute the command.
50
+ * In this case you will instead receive an empty successful result object.
51
+ */
52
+ dryrun?: boolean
48
53
  }
49
54
 
50
55
  /** Run result. */
@@ -131,7 +136,7 @@ export function command(bin: string, args: string[], options?: options & { sync:
131
136
  * command("deno", ["eval", "Deno.exit(1)"], { throw: true, sync: true })
132
137
  * ```
133
138
  */
134
- export function command(bin: string, args: string[], { log = new Logger(), stdin = null, stdout = "debug", stderr = "error", env, cwd, raw, callback, buffering, sync, throw: _throw, winext = "", os = Deno.build.os } = {} as options): Promisable<result> {
139
+ export function command(bin: string, args: string[], { log = new Logger(), stdin = null, stdout = "debug", stderr = "error", env, cwd, raw, callback, buffering, sync, throw: _throw, dryrun, winext = "", os = Deno.build.os } = {} as options): Promisable<result> {
135
140
  if (os === "windows") {
136
141
  bin = `${bin}${winext}`
137
142
  }
@@ -140,6 +145,11 @@ export function command(bin: string, args: string[], { log = new Logger(), stdin
140
145
  stdin = "piped"
141
146
  }
142
147
  const command = new Deno.Command(bin, { args, stdin: !sync ? handle(stdin) : "null", stdout: handle(stdout), stderr: handle(stderr), env, cwd, windowsRawArguments: raw })
148
+ if (dryrun) {
149
+ log.debug(`dryrun: ${bin} not executed`)
150
+ const result = { success: true, code: 0, stdio: [], stdin: "", stdout: "", stderr: "" }
151
+ return sync ? result : Promise.resolve(result)
152
+ }
143
153
  if (sync) {
144
154
  return exec(command, { bin, log, throw: _throw, stdout, stderr })
145
155
  }
package/command_test.ts CHANGED
@@ -116,3 +116,8 @@ test("deno")("command() throws an error when `throw` option is enabled and exit
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
+
120
+ test("deno")("command() does nothing in dryrun", async () => {
121
+ expect(command("deno", ["--version"], { dryrun: true, sync: true })).toMatchObject({ success: true, code: 0, stdio: [], stdin: "", stderr: "", stdout: "" })
122
+ await expect(command("deno", ["--version"], { dryrun: true })).resolves.toMatchObject({ success: true, code: 0, stdio: [], stdin: "", stderr: "", stdout: "" })
123
+ }, { permissions: { run: ["deno"] } })
package/deno.jsonc CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "icon": "⏯️",
3
3
  "name": "@libs/run",
4
- "version": "0.2.0",
4
+ "version": "1.0.2",
5
5
  "description": "Utilities to run subprocess.",
6
6
  "keywords": [
7
7
  "subprocess",
8
8
  "esm"
9
9
  ],
10
- "license": "MIT License",
10
+ "license": "MIT",
11
11
  "author": "lowlighter (Simon Lecoq)",
12
12
  "funding": "https://github.com/sponsors/lowlighter",
13
13
  "homepage": "https://github.com/lowlighter/libs",
@@ -25,9 +25,9 @@
25
25
  "./command": "./command.ts"
26
26
  },
27
27
  "imports": {
28
- "@std/async/delay": "jsr:@std/async@0.224.1/delay",
29
- "@std/async/debounce": "jsr:@std/async@0.224.1/debounce",
30
- "@std/streams": "jsr:@std/streams@0.224.2",
28
+ "@std/async/delay": "jsr:@std/async@0.224.2/delay",
29
+ "@std/async/debounce": "jsr:@std/async@0.224.2/debounce",
30
+ "@std/streams": "jsr:@std/streams@0.224.5",
31
31
  "@libs/logger": "jsr:@libs/logger@1",
32
32
  "@libs/testing": "jsr:@libs/testing@1",
33
33
  "@libs/typing": "jsr:@libs/typing@2"
@@ -73,6 +73,7 @@
73
73
  "**/package-lock.json",
74
74
  "**/wasm_*",
75
75
  "**/*.mjs"
76
- ]
76
+ ],
77
+ "proseWrap": "preserve"
77
78
  }
78
79
  }
package/deno.lock CHANGED
@@ -2,89 +2,72 @@
2
2
  "version": "3",
3
3
  "packages": {
4
4
  "specifiers": {
5
- "jsr:@libs/logger@1": "jsr:@libs/logger@1.1.1",
6
- "jsr:@libs/testing@1": "jsr:@libs/testing@1.0.7",
7
- "jsr:@libs/typing@2": "jsr:@libs/typing@2.1.0",
8
- "jsr:@std/assert@^0.224.0": "jsr:@std/assert@0.224.0",
5
+ "jsr:@libs/logger@1": "jsr:@libs/logger@1.1.2",
6
+ "jsr:@libs/testing@1": "jsr:@libs/testing@1.1.0",
7
+ "jsr:@libs/typing@2": "jsr:@libs/typing@2.3.0",
9
8
  "jsr:@std/assert@^0.225.3": "jsr:@std/assert@0.225.3",
10
- "jsr:@std/async@0.224.1": "jsr:@std/async@0.224.1",
11
- "jsr:@std/bytes@^0.224.0": "jsr:@std/bytes@0.224.0",
12
- "jsr:@std/bytes@^1.0.0-rc.3": "jsr:@std/bytes@1.0.0-rc.3",
13
- "jsr:@std/expect@0.224.0": "jsr:@std/expect@0.224.0",
14
- "jsr:@std/fmt@^0.224.0": "jsr:@std/fmt@0.224.0",
15
- "jsr:@std/internal@^0.224.0": "jsr:@std/internal@0.224.0",
16
- "jsr:@std/io@^0.224.0": "jsr:@std/io@0.224.0",
9
+ "jsr:@std/async@0.224.2": "jsr:@std/async@0.224.2",
10
+ "jsr:@std/bytes@^1.0.0-rc.3": "jsr:@std/bytes@1.0.1",
11
+ "jsr:@std/bytes@^1.0.1-rc.3": "jsr:@std/bytes@1.0.1",
12
+ "jsr:@std/expect@0.224.3": "jsr:@std/expect@0.224.3",
13
+ "jsr:@std/internal@^1.0.0": "jsr:@std/internal@1.0.1",
14
+ "jsr:@std/io@^0.224.1": "jsr:@std/io@0.224.3",
17
15
  "jsr:@std/path@0.225.1": "jsr:@std/path@0.225.1",
18
- "jsr:@std/streams@0.224.2": "jsr:@std/streams@0.224.2",
19
- "npm:@types/node": "npm:@types/node@18.16.19"
16
+ "jsr:@std/streams@0.224.5": "jsr:@std/streams@0.224.5"
20
17
  },
21
18
  "jsr": {
22
- "@libs/logger@1.1.1": {
23
- "integrity": "7b74ca947062b955e8d63299f77a41fc4f2cf0a663a6ad836b703d601f622ccf"
19
+ "@libs/logger@1.1.2": {
20
+ "integrity": "7d718f54c9a5d1c00f570051bee0217e3b282e8c2131144ec55c794a8ebd5d4f"
24
21
  },
25
- "@libs/testing@1.0.7": {
26
- "integrity": "b1a7caa9d2e00569f90b9753eb768ec6b16ff5c859f104b73a6ef4611968892e",
22
+ "@libs/testing@1.1.0": {
23
+ "integrity": "961fed690ee11a6f0f2cf8ed759b9b3a5c40ca24d319ba6c18cbbdaf73f1b29b",
27
24
  "dependencies": [
28
- "jsr:@std/expect@0.224.0",
25
+ "jsr:@libs/run@1",
26
+ "jsr:@std/expect@0.224.3",
29
27
  "jsr:@std/path@0.225.1"
30
28
  ]
31
29
  },
32
- "@libs/typing@2.1.0": {
33
- "integrity": "3c3b93e1da1e4bb45a22dde168fdfd1cc765edbdb371b46bf4ca7873ee79e15d"
34
- },
35
- "@std/assert@0.224.0": {
36
- "integrity": "8643233ec7aec38a940a8264a6e3eed9bfa44e7a71cc6b3c8874213ff401967f"
30
+ "@libs/typing@2.3.0": {
31
+ "integrity": "8a03098b2d63763bc3b45b58f6e847d9c085405db83330c588aecb6b670587d0"
37
32
  },
38
33
  "@std/assert@0.225.3": {
39
- "integrity": "b3c2847aecf6955b50644cdb9cf072004ea3d1998dd7579fc0acb99dbb23bd4f"
40
- },
41
- "@std/async@0.224.1": {
42
- "integrity": "2fda2c8151cc5811a6ca37fe825f1f71c95e02a374abb6ef868e0e19eca814a5"
34
+ "integrity": "b3c2847aecf6955b50644cdb9cf072004ea3d1998dd7579fc0acb99dbb23bd4f",
35
+ "dependencies": [
36
+ "jsr:@std/internal@^1.0.0"
37
+ ]
43
38
  },
44
- "@std/bytes@0.224.0": {
45
- "integrity": "a2250e1d0eb7d1c5a426f21267ab9bdeac2447fa87a3d0d1a467d3f7a6058e49"
39
+ "@std/async@0.224.2": {
40
+ "integrity": "4d277d6e165df43d5e061ba0ef3edfddb8e8d558f5b920e3e6b1d2614b44d074"
46
41
  },
47
- "@std/bytes@1.0.0-rc.3": {
48
- "integrity": "b3e93f73f1ccf167124f695596d2d026b0030930c38bd0ddec81d7f75ab41948"
42
+ "@std/bytes@1.0.1": {
43
+ "integrity": "e57c9b243932b95a4c3672f8a038cdadea7492efeeb6b8a774844fee70426815"
49
44
  },
50
- "@std/expect@0.224.0": {
51
- "integrity": "54bc071f7edcbd7bb4531f913e466e5ec3642f401dc3771fe5975f0693f25969",
45
+ "@std/expect@0.224.3": {
46
+ "integrity": "eacd71aaa426472bf04ddde7e0765b0b360d3ffa33ad2ca05a96fd7052caea41",
52
47
  "dependencies": [
53
- "jsr:@std/assert@^0.224.0",
54
- "jsr:@std/fmt@^0.224.0",
55
- "jsr:@std/internal@^0.224.0"
48
+ "jsr:@std/assert@^0.225.3",
49
+ "jsr:@std/internal@^1.0.0"
56
50
  ]
57
51
  },
58
- "@std/fmt@0.224.0": {
59
- "integrity": "e20e9a2312a8b5393272c26191c0a68eda8d2c4b08b046bad1673148f1d69851"
52
+ "@std/internal@1.0.1": {
53
+ "integrity": "6f8c7544d06a11dd256c8d6ba54b11ed870aac6c5aeafff499892662c57673e6"
60
54
  },
61
- "@std/internal@0.224.0": {
62
- "integrity": "afc50644f9cdf4495eeb80523a8f6d27226b4b36c45c7c195dfccad4b8509291"
63
- },
64
- "@std/io@0.224.0": {
65
- "integrity": "0aff885d21d829c050b8a08b1d71b54aed5841aecf227f8d77e99ec529a11e8e",
55
+ "@std/io@0.224.3": {
56
+ "integrity": "b402edeb99c6b3778d9ae3e9927bc9085b170b41e5a09bbb7064ab2ee394ae2f",
66
57
  "dependencies": [
67
- "jsr:@std/assert@^0.224.0",
68
- "jsr:@std/bytes@^0.224.0"
58
+ "jsr:@std/bytes@^1.0.1-rc.3"
69
59
  ]
70
60
  },
71
61
  "@std/path@0.225.1": {
72
62
  "integrity": "8c3220635a73730eb51fe43de9e10b79e2724a5bb8638b9355d35ae012fd9429"
73
63
  },
74
- "@std/streams@0.224.2": {
75
- "integrity": "5d437af1423e4f616111b986ea783c15e0bc998b53e23e93b623de7ef0b14c2b",
64
+ "@std/streams@0.224.5": {
65
+ "integrity": "bcde7818dd5460d474cdbd674b15f6638b9cd73cd64e52bd852fba2bd4d8ec91",
76
66
  "dependencies": [
77
- "jsr:@std/assert@^0.225.3",
78
67
  "jsr:@std/bytes@^1.0.0-rc.3",
79
- "jsr:@std/io@^0.224.0"
68
+ "jsr:@std/io@^0.224.1"
80
69
  ]
81
70
  }
82
- },
83
- "npm": {
84
- "@types/node@18.16.19": {
85
- "integrity": "sha512-IXl7o+R9iti9eBW4Wg2hx1xQDig183jj7YLn8F7udNceyfkbn1ZxmzZXuak20gR40D7pIkIY1kYGx5VIGbaHKA==",
86
- "dependencies": {}
87
- }
88
71
  }
89
72
  },
90
73
  "remote": {},
@@ -93,8 +76,8 @@
93
76
  "jsr:@libs/logger@1",
94
77
  "jsr:@libs/testing@1",
95
78
  "jsr:@libs/typing@2",
96
- "jsr:@std/async@0.224.1",
97
- "jsr:@std/streams@0.224.2"
79
+ "jsr:@std/async@0.224.2",
80
+ "jsr:@std/streams@0.224.5"
98
81
  ]
99
82
  }
100
83
  }
package/mod.mjs CHANGED
@@ -1,4 +1,4 @@
1
- var e=class e{constructor({level:t,format:n,output:o,tags:r,options:s}={}){if("granted"===globalThis.Deno?.permissions.querySync?.({name:"env",variable:"LOG_LEVEL"}).state){const n=globalThis.Deno?.env.get("LOG_LEVEL")??"";n in e.level&&(t??=e.level[n]),Number.isNaN(Number.parseInt(n))||(t??=Number.parseInt(n))}this.level=t??e.level.log,this.#e=o||null===o?o:console,this.#t=n??e.format.text,this.tags=r??{},this.options={date:!1,time:!1,delta:!0,...s,caller:!1!==s?.caller&&{file:!1,name:!1,line:!1,...s?.caller}}}level;#t;#e;tags;options;error(...t){return this.level>=e.level.error&&this.#e?.error(...this.#t(this,{level:e.level.error,content:t})),this}warn(...t){return this.level>=e.level.warn&&this.#e?.warn(...this.#t(this,{level:e.level.warn,content:t})),this}info(...t){return this.level>=e.level.info&&this.#e?.info(...this.#t(this,{level:e.level.info,content:t})),this}log(...t){return this.level>=e.level.log&&this.#e?.log(...this.#t(this,{level:e.level.log,content:t})),this}debug(...t){return this.level>=e.level.debug&&this.#e?.debug(...this.#t(this,{level:e.level.debug,content:t})),this}with(t={}){return new e({level:this.level,format:this.#t,output:this.#e,options:{...this.options},tags:{...this.tags,...t}})}#n(e=3){const t=Error,n=t.prepareStackTrace;t.prepareStackTrace=(e,t)=>t;const{stack:o}=new Error;t.prepareStackTrace=n;const r=o[e];return{file:r.getFileName(),name:r.getFunctionName(),line:r.getLineNumber(),column:r.getColumnNumber()}}static level=Object.freeze({disabled:NaN,error:0,warn:1,info:2,log:3,debug:4});static format={text(t,{level:n=0,content:o}){const r=["red","orange","cyan","white","gray"][n],s=[`%c ${Object.keys(e.level).find((t=>e.level[t]===n)).toLocaleUpperCase().padEnd(5)} │%c`],i=[`color: black; background-color: ${r}`,""];if(t.options.date||t.options.time||t.options.delta){const e=(new Date).toISOString(),n=[];if(t.options.delta){const e=performance.now()/1e3;let t=e.toPrecision(4);e<1&&(t=e.toPrecision(2)),n.push(`+${t}`)}t.options.date&&t.options.time?n.push(e):t.options.date?n.push(e.slice(0,e.indexOf("T"))):t.options.time&&n.push(e.slice(e.indexOf("T")+1,-1)),s.push(`%c ${n.join(" ¦ ").trim()} %c`),i.push(`color: black; background-color: ${r}`,"")}if(t.options.caller){const e=t.#n();if(e){const n=[];t.options.caller.file&&n.push(`${e.file.replace(t.options.caller.fileformat,"$<file>")}`),t.options.caller.name&&e.name&&n.push(e.name),t.options.caller.line&&n.push(e.line,e.column),s.push(`%c ${n.join(":").trim()} %c`),i.push("color: black; background-color: gray","")}}{const n=[];for(const[o,r]of Object.entries(t.tags))n.push(`${o}:${e.inspect(r)}`);s.push(`%c ${n.join(" ").trim()} %c`),i.push("background-color: black","")}return[s.join(""),...i,...o.map(e.inspect)]},json(t,{level:n=0,content:o}){const r={level:Object.keys(e.level).find((t=>e.level[t]===n)),timestamp:Date.now(),tags:t.tags,content:o},s={};if(t.options.date||t.options.time){const e=new Date(r.timestamp).toISOString();t.options.date&&(s.date=e.slice(0,e.indexOf("T"))),t.options.time&&(s.time=e.slice(e.indexOf("T")+1,-1))}if(t.options.delta&&(s.delta=performance.now()/1e3),t.options.caller){const e=t.#n();e&&(s.caller={},t.options.caller.file&&(s.caller.file=`${e.file.replace(t.options.caller.fileformat,"$<file>")}`),t.options.caller.name&&e.name&&(s.caller.name=e.name),t.options.caller.line&&(s.caller.line=[e.line,e.column]))}return[JSON.stringify({...r,...s})]}};static inspect(e){return globalThis.Deno?.inspect(e,{colors:!0,depth:1/0})??e}},t=class extends Error{constructor(e){super(e),this.name="AssertionError"}};TransformStream;function n(e){let t=0;for(const n of e)t+=n.length;const n=new Uint8Array(t);let o=0;for(const t of e)n.set(t,o),o+=t.length;return n}function o(e){const t=e.length,n=new Uint8Array(t);n[0]=0;let o=0,r=1;for(;r<t;)e[r]===e[o]?(o++,n[r]=o,r++):0===o?(n[r]=0,r++):o=n[o-1];return n}TransformStream,TransformStream,TransformStream,TransformStream;var r=class extends TransformStream{#o="";constructor(e={allowCR:!1}){super({transform:(t,n)=>{for(t=this.#o+t;;){const o=t.indexOf("\n"),r=e.allowCR?t.indexOf("\r"):-1;if(-1!==r&&r!==t.length-1&&(-1===o||o-1>r)){n.enqueue(t.slice(0,r)),t=t.slice(r+1);continue}if(-1===o)break;const s="\r"===t[o-1]?o-1:o;n.enqueue(t.slice(0,s)),t=t.slice(o+1)}this.#o=t},flush:t=>{if(""===this.#o)return;const n=e.allowCR&&this.#o.endsWith("\r")?this.#o.slice(0,-1):this.#o;t.enqueue(n)}})}};new TextDecoder;var s=new TextEncoder,i=new TextDecoder;function l(t,n,{log:o=new e,stdin:l=null,stdout:c="debug",stderr:u="error",env:d,cwd:p,raw:h,callback:f,buffering:m,sync:w,throw:g,winext:b="",os:v=Deno.build.os}={}){"windows"===v&&(t=`${t}${b}`),o=o.with({bin:t}),f&&"piped"!==a(l)&&(l="piped");const T=new Deno.Command(t,{args:n,stdin:w?"null":a(l),stdout:a(c),stderr:a(u),env:d,cwd:p,windowsRawArguments:h});return w?function(e,{bin:t,log:n,throw:o,stdout:r,stderr:s}){const l=Date.now(),c=e.outputSync(),{success:u,code:d}=c,p=Date.now()-l,h={get stdio(){return[[p,1,this.stdout],[p,2,this.stderr]]},stdin:"",stdout:"piped"===a(r)?i.decode(c.stdout):"",stderr:"piped"===a(s)?i.decode(c.stderr):""};for(const{channel:e,mode:t}of[{channel:"stdout",mode:r},{channel:"stderr",mode:s}])"piped"===a(t)&&h[e]&&n.with({t:p,channel:e})[t]?.(h[e]);if(!u&&o)throw new EvalError(`${t} exited with non-zero code ${d}:\n${h.stdout}\n${h.stderr}`);return{success:u,code:d,...h}}(T,{bin:t,log:o,throw:g,stdout:c,stderr:u}):async function(e,{bin:t,log:n,callback:o=(({close:e})=>e?.()),buffering:i=250,throw:l,...c}){const u=e.spawn(),d=Date.now(),p={stdio:[],get stdin(){return this.stdio.filter((([e,t])=>0===t)).map((([e,t,n])=>n)).join("\n")},get stdout(){return this.stdio.filter((([e,t])=>1===t)).map((([e,t,n])=>n)).join("\n")},get stderr(){return this.stdio.filter((([e,t])=>2===t)).map((([e,t,n])=>n)).join("\n")}},h={};let f="";const m=function(e,t){let n=null,o=null;const r=(...s)=>{r.clear(),o=()=>{r.clear(),e.call(r,...s)},n=setTimeout(o,t)};return r.clear=()=>{"number"==typeof n&&(clearTimeout(n),n=null,o=null)},r.flush=()=>{o?.()},Object.defineProperty(r,"pending",{get:()=>"number"==typeof n}),r}((async e=>{n.with({t:e}).debug("debounced"),f="",await o({stdio:p,i:p.stdin.length,...h})}),i);if("piped"===a(c.stdin)){const e=u.stdin.getWriter();Object.assign(h,{async write(t,o=!0){const r=Date.now()-d;c.stdin&&n.with({t:r,channel:"stdin"})[c.stdin]?.(t),p.stdio.push([r,0,t]),o&&!t.endsWith("\n")&&(t+="\n"),await e.write(s.encode(t)),f="stdin",e.releaseLock()},async close(){try{e.releaseLock(),await u.stdin.close(),n.with({t:Date.now()-d,closed:"stdin"}).debug()}catch{}},async wait(e=1e3){const t=Date.now()-d;n.with({t:t,waiting:e}).debug(),await function(e,t={}){const{signal:n,persistent:o=!0}=t;return n?.aborted?Promise.reject(n.reason):new Promise(((t,r)=>{const s=()=>{clearTimeout(i),r(n?.reason)},i=setTimeout((()=>{n?.removeEventListener("abort",s),t()}),e);if(n?.addEventListener("abort",s,{once:!0}),!1===o)try{Deno.unrefTimer(i)}catch(e){if(!(e instanceof ReferenceError))throw e;console.error("`persistent` option is only available in Deno")}}))}(e),m(t)}}),m(Date.now()-d)}await Promise.all(["stdout","stderr"].filter((e=>"piped"===a(c[e]))).map((async e=>{for await(const t of u[e].pipeThrough(new TextDecoderStream).pipeThrough(new r)){const o=Date.now()-d,r={stdout:1,stderr:2}[e];if(c[e]&&n.with({t:o,channel:e})[c[e]]?.(t),p.stdio.length&&f===e){const e=p.stdio.at(-1);e[1]===r&&(e[2]+=`\n${t}`)}else p.stdio.push([o,r,t]);f=e,m(o)}}))),m.flush();const{success:w,code:g}=await u.status;if(!w&&l)throw new EvalError(`${t} exited with non-zero code ${g}:\n${p.stdout}\n${p.stderr}`);return{success:w,code:g,...p}}(T,{bin:t,log:o,callback:f,buffering:m,throw:g,stdin:"piped"===a(l)?l:null,stdout:"piped"===a(c)?c:null,stderr:"piped"===a(u)?u:null})}function a(e){return["inherit","null"].includes(`${e}`)?`${e}`:"piped"}export{l as command};
1
+ var e=class e{constructor({level:t,format:n,output:o,tags:r,options:s}={}){if("granted"===globalThis.Deno?.permissions.querySync?.({name:"env",variable:"LOG_LEVEL"}).state){const n=globalThis.Deno?.env.get("LOG_LEVEL")??"";n in e.level&&(t??=e.level[n]),Number.isNaN(Number.parseInt(n))||(t??=Number.parseInt(n))}this.level=t??e.level.log,this.#e=o||null===o?o:console,this.#t=n??e.format.text,this.tags=r??{},this.options={date:!1,time:!1,delta:!0,...s,caller:!1!==s?.caller&&{file:!1,name:!1,line:!1,...s?.caller}}}level;#t;#e;tags;options;error(...t){return this.level>=e.level.error&&this.#e?.error(...this.#t(this,{level:e.level.error,content:t})),this}warn(...t){return this.level>=e.level.warn&&this.#e?.warn(...this.#t(this,{level:e.level.warn,content:t})),this}info(...t){return this.level>=e.level.info&&this.#e?.info(...this.#t(this,{level:e.level.info,content:t})),this}log(...t){return this.level>=e.level.log&&this.#e?.log(...this.#t(this,{level:e.level.log,content:t})),this}debug(...t){return this.level>=e.level.debug&&this.#e?.debug(...this.#t(this,{level:e.level.debug,content:t})),this}with(t={}){return new e({level:this.level,format:this.#t,output:this.#e,options:{...this.options},tags:{...this.tags,...t}})}#n(e=3){const t=Error,n=t.prepareStackTrace;t.prepareStackTrace=(e,t)=>t;const{stack:o}=new Error;t.prepareStackTrace=n;const r=o[e];return{file:r.getFileName(),name:r.getFunctionName(),line:r.getLineNumber(),column:r.getColumnNumber()}}static level=Object.freeze({disabled:NaN,error:0,warn:1,info:2,log:3,debug:4});static format={text(t,{level:n=0,content:o}){const r=["red","orange","cyan","white","gray"][n],s=[`%c ${Object.keys(e.level).find((t=>e.level[t]===n)).toLocaleUpperCase().padEnd(5)} │%c`],i=[`color: black; background-color: ${r}`,""];if(t.options.date||t.options.time||t.options.delta){const e=(new Date).toISOString(),n=[];if(t.options.delta){const e=performance.now()/1e3;let t=e.toPrecision(4);e<1&&(t=e.toPrecision(2)),n.push(`+${t}`)}t.options.date&&t.options.time?n.push(e):t.options.date?n.push(e.slice(0,e.indexOf("T"))):t.options.time&&n.push(e.slice(e.indexOf("T")+1,-1)),s.push(`%c ${n.join(" ¦ ").trim()} %c`),i.push(`color: black; background-color: ${r}`,"")}if(t.options.caller){const e=t.#n();if(e){const n=[];t.options.caller.file&&n.push(`${e.file.replace(t.options.caller.fileformat,"$<file>")}`),t.options.caller.name&&e.name&&n.push(e.name),t.options.caller.line&&n.push(e.line,e.column),s.push(`%c ${n.join(":").trim()} %c`),i.push("color: black; background-color: gray","")}}{const n=[];for(const[o,r]of Object.entries(t.tags))n.push(`${o}:${e.inspect(r)}`);s.push(`%c ${n.join(" ").trim()} %c`),i.push("background-color: black","")}return[s.join(""),...i,...o.map(e.inspect)]},json(t,{level:n=0,content:o}){const r={level:Object.keys(e.level).find((t=>e.level[t]===n)),timestamp:Date.now(),tags:t.tags,content:o},s={};if(t.options.date||t.options.time){const e=new Date(r.timestamp).toISOString();t.options.date&&(s.date=e.slice(0,e.indexOf("T"))),t.options.time&&(s.time=e.slice(e.indexOf("T")+1,-1))}if(t.options.delta&&(s.delta=performance.now()/1e3),t.options.caller){const e=t.#n();e&&(s.caller={},t.options.caller.file&&(s.caller.file=`${e.file.replace(t.options.caller.fileformat,"$<file>")}`),t.options.caller.name&&e.name&&(s.caller.name=e.name),t.options.caller.line&&(s.caller.line=[e.line,e.column]))}return[JSON.stringify({...r,...s})]}};static inspect(e){return globalThis.Deno?.inspect(e,{colors:!0,depth:1/0,strAbbreviateSize:1/0})??e}};TransformStream;function t(e){let t=0;for(const n of e)t+=n.length;const n=new Uint8Array(t);let o=0;for(const t of e)n.set(t,o),o+=t.length;return n}function n(e){const t=e.length,n=new Uint8Array(t);n[0]=0;let o=0,r=1;for(;r<t;)e[r]===e[o]?(o++,n[r]=o,r++):0===o?(n[r]=0,r++):o=n[o-1];return n}TransformStream,TransformStream,TransformStream,TransformStream;var o=class extends TransformStream{#o="";constructor(e={allowCR:!1}){super({transform:(t,n)=>{for(t=this.#o+t;;){const o=t.indexOf("\n"),r=e.allowCR?t.indexOf("\r"):-1;if(-1!==r&&r!==t.length-1&&(-1===o||o-1>r)){n.enqueue(t.slice(0,r)),t=t.slice(r+1);continue}if(-1===o)break;const s="\r"===t[o-1]?o-1:o;n.enqueue(t.slice(0,s)),t=t.slice(o+1)}this.#o=t},flush:t=>{if(""===this.#o)return;const n=e.allowCR&&this.#o.endsWith("\r")?this.#o.slice(0,-1):this.#o;t.enqueue(n)}})}};new TextDecoder;var r=new TextEncoder,s=new TextDecoder;function i(t,n,{log:i=new e,stdin:a=null,stdout:c="debug",stderr:u="error",env:d,cwd:p,raw:h,callback:f,buffering:m,sync:w,throw:g,dryrun:b,winext:v="",os:T=Deno.build.os}={}){"windows"===T&&(t=`${t}${v}`),i=i.with({bin:t}),f&&"piped"!==l(a)&&(a="piped");const $=new Deno.Command(t,{args:n,stdin:w?"null":l(a),stdout:l(c),stderr:l(u),env:d,cwd:p,windowsRawArguments:h});if(b){i.debug(`dryrun: ${t} not executed`);const e={success:!0,code:0,stdio:[],stdin:"",stdout:"",stderr:""};return w?e:Promise.resolve(e)}return w?function(e,{bin:t,log:n,throw:o,stdout:r,stderr:i}){const a=Date.now(),c=e.outputSync(),{success:u,code:d}=c,p=Date.now()-a,h={get stdio(){return[[p,1,this.stdout],[p,2,this.stderr]]},stdin:"",stdout:"piped"===l(r)?s.decode(c.stdout):"",stderr:"piped"===l(i)?s.decode(c.stderr):""};for(const{channel:e,mode:t}of[{channel:"stdout",mode:r},{channel:"stderr",mode:i}])"piped"===l(t)&&h[e]&&n.with({t:p,channel:e})[t]?.(h[e]);if(!u&&o)throw new EvalError(`${t} exited with non-zero code ${d}:\n${h.stdout}\n${h.stderr}`);return{success:u,code:d,...h}}($,{bin:t,log:i,throw:g,stdout:c,stderr:u}):async function(e,{bin:t,log:n,callback:s=(({close:e})=>e?.()),buffering:i=250,throw:a,...c}){const u=e.spawn(),d=Date.now(),p={stdio:[],get stdin(){return this.stdio.filter((([e,t])=>0===t)).map((([e,t,n])=>n)).join("\n")},get stdout(){return this.stdio.filter((([e,t])=>1===t)).map((([e,t,n])=>n)).join("\n")},get stderr(){return this.stdio.filter((([e,t])=>2===t)).map((([e,t,n])=>n)).join("\n")}},h={};let f="";const m=function(e,t){let n=null,o=null;const r=(...s)=>{r.clear(),o=()=>{r.clear(),e.call(r,...s)},n=setTimeout(o,t)};return r.clear=()=>{"number"==typeof n&&(clearTimeout(n),n=null,o=null)},r.flush=()=>{o?.()},Object.defineProperty(r,"pending",{get:()=>"number"==typeof n}),r}((async e=>{n.with({t:e}).debug("debounced"),f="",await s({stdio:p,i:p.stdin.length,...h})}),i);if("piped"===l(c.stdin)){const e=u.stdin.getWriter();Object.assign(h,{async write(t,o=!0){const s=Date.now()-d;c.stdin&&n.with({t:s,channel:"stdin"})[c.stdin]?.(t),p.stdio.push([s,0,t]),o&&!t.endsWith("\n")&&(t+="\n"),await e.write(r.encode(t)),f="stdin",e.releaseLock()},async close(){try{e.releaseLock(),await u.stdin.close(),n.with({t:Date.now()-d,closed:"stdin"}).debug()}catch{}},async wait(e=1e3){const t=Date.now()-d;n.with({t:t,waiting:e}).debug(),await function(e,t={}){const{signal:n,persistent:o=!0}=t;return n?.aborted?Promise.reject(n.reason):new Promise(((t,r)=>{const s=()=>{clearTimeout(i),r(n?.reason)},i=setTimeout((()=>{n?.removeEventListener("abort",s),t()}),e);if(n?.addEventListener("abort",s,{once:!0}),!1===o)try{Deno.unrefTimer(i)}catch(e){if(!(e instanceof ReferenceError))throw e;console.error("`persistent` option is only available in Deno")}}))}(e),m(t)}}),m(Date.now()-d)}await Promise.all(["stdout","stderr"].filter((e=>"piped"===l(c[e]))).map((async e=>{for await(const t of u[e].pipeThrough(new TextDecoderStream).pipeThrough(new o)){const o=Date.now()-d,r={stdout:1,stderr:2}[e];if(c[e]&&n.with({t:o,channel:e})[c[e]]?.(t),p.stdio.length&&f===e){const e=p.stdio.at(-1);e[1]===r&&(e[2]+=`\n${t}`)}else p.stdio.push([o,r,t]);f=e,m(o)}}))),m.flush();const{success:w,code:g}=await u.status;if(!w&&a)throw new EvalError(`${t} exited with non-zero code ${g}:\n${p.stdout}\n${p.stderr}`);return{success:w,code:g,...p}}($,{bin:t,log:i,callback:f,buffering:m,throw:g,stdin:"piped"===l(a)?a:null,stdout:"piped"===l(c)?c:null,stderr:"piped"===l(u)?u:null})}function l(e){return["inherit","null"].includes(`${e}`)?`${e}`:"piped"}export{i as command};
2
2
  /**
3
3
  * Logger library
4
4
  *
package/package.json CHANGED
@@ -1,14 +1,16 @@
1
1
  {
2
2
  "name": "@lowlighter/run",
3
- "version": "0.2.0",
3
+ "version": "1.0.2",
4
4
  "type": "module",
5
5
  "scripts": {},
6
+ "dependencies": {},
7
+ "devDependencies": {},
6
8
  "description": "Utilities to run subprocess.",
7
9
  "keywords": [
8
10
  "subprocess",
9
11
  "esm"
10
12
  ],
11
- "license": "MIT License",
13
+ "license": "MIT",
12
14
  "author": "lowlighter (Simon Lecoq)",
13
15
  "homepage": "https://github.com/lowlighter/libs",
14
16
  "repository": {