giget 3.1.0 → 3.1.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
@@ -190,9 +190,7 @@ You can define additional [custom registry](#custom-registry) providers using `r
190
190
  ```ts
191
191
  import { registryProvider } from "giget";
192
192
 
193
- const themes = registryProvider(
194
- "https://raw.githubusercontent.com/unjs/giget/main/templates",
195
- );
193
+ const themes = registryProvider("https://raw.githubusercontent.com/unjs/giget/main/templates");
196
194
 
197
195
  const { source, dir } = await downloadTemplate("themes:test", {
198
196
  providers: { themes },
@@ -5,8 +5,6 @@ import { pipeline } from "node:stream";
5
5
  import { spawnSync } from "node:child_process";
6
6
  import { homedir, tmpdir } from "node:os";
7
7
  import { promisify } from "node:util";
8
-
9
- //#region src/_utils.ts
10
8
  async function download(url, filePath, options = {}) {
11
9
  const infoPath = filePath + ".json";
12
10
  const info = JSON.parse(await readFile(infoPath, "utf8").catch(() => "{}"));
@@ -79,9 +77,6 @@ function startShell(cwd) {
79
77
  stdio: "inherit"
80
78
  });
81
79
  }
82
-
83
- //#endregion
84
- //#region src/providers.ts
85
80
  const http = async (input, options) => {
86
81
  if (input.endsWith(".json")) return await _httpJSON(input, options);
87
82
  const url = new URL(input);
@@ -177,9 +172,6 @@ const providers = {
177
172
  bitbucket,
178
173
  sourcehut
179
174
  };
180
-
181
- //#endregion
182
- //#region src/registry.ts
183
175
  const DEFAULT_REGISTRY = "https://raw.githubusercontent.com/unjs/giget/main/templates";
184
176
  const registryProvider = (registryEndpoint = DEFAULT_REGISTRY, options = {}) => {
185
177
  return (async (input) => {
@@ -193,9 +185,6 @@ const registryProvider = (registryEndpoint = DEFAULT_REGISTRY, options = {}) =>
193
185
  return info;
194
186
  });
195
187
  };
196
-
197
- //#endregion
198
- //#region src/giget.ts
199
188
  const sourceProtoRe = /^([\w-.]+):/;
200
189
  async function downloadTemplate(input, options = {}) {
201
190
  options.registry = process.env.GIGET_REGISTRY ?? options.registry;
@@ -221,7 +210,7 @@ async function downloadTemplate(input, options = {}) {
221
210
  if (options.preferOffline && existsSync(tarPath)) options.offline = true;
222
211
  if (!options.offline) {
223
212
  await mkdir(dirname(tarPath), { recursive: true });
224
- const s$1 = Date.now();
213
+ const s = Date.now();
225
214
  await download(template.tar, tarPath, { headers: {
226
215
  Authorization: options.auth ? `Bearer ${options.auth}` : void 0,
227
216
  ...normalizeHeaders(template.headers)
@@ -230,7 +219,7 @@ async function downloadTemplate(input, options = {}) {
230
219
  debug("Download error. Using cached version:", error);
231
220
  options.offline = true;
232
221
  });
233
- debug(`Downloaded ${template.tar} to ${tarPath} in ${Date.now() - s$1}ms`);
222
+ debug(`Downloaded ${template.tar} to ${tarPath} in ${Date.now() - s}ms`);
234
223
  }
235
224
  if (!existsSync(tarPath)) throw new Error(`Tarball not found: ${tarPath} (offline: ${options.offline})`);
236
225
  const extractPath = resolve(resolve(options.cwd || "."), options.dir || template.defaultDir);
@@ -268,6 +257,4 @@ async function downloadTemplate(input, options = {}) {
268
257
  dir: extractPath
269
258
  };
270
259
  }
271
-
272
- //#endregion
273
- export { registryProvider as n, startShell as r, downloadTemplate as t };
260
+ export { registryProvider as n, startShell as r, downloadTemplate as t };
@@ -1 +1,527 @@
1
- import Stream from"node:stream";import EE from"events";import fs from"fs";import{EventEmitter as EventEmitter$1}from"node:events";import{StringDecoder}from"node:string_decoder";const proc=typeof process==`object`&&process?process:{stdout:null,stderr:null},isStream=K=>!!K&&typeof K==`object`&&(K instanceof Minipass||K instanceof Stream||isReadable(K)||isWritable(K)),isReadable=K=>!!K&&typeof K==`object`&&K instanceof EventEmitter$1&&typeof K.pipe==`function`&&K.pipe!==Stream.Writable.prototype.pipe,isWritable=_=>!!_&&typeof _==`object`&&_ instanceof EventEmitter$1&&typeof _.write==`function`&&typeof _.end==`function`,EOF=Symbol(`EOF`),MAYBE_EMIT_END=Symbol(`maybeEmitEnd`),EMITTED_END=Symbol(`emittedEnd`),EMITTING_END=Symbol(`emittingEnd`),EMITTED_ERROR=Symbol(`emittedError`),CLOSED=Symbol(`closed`),READ=Symbol(`read`),FLUSH=Symbol(`flush`),FLUSHCHUNK=Symbol(`flushChunk`),ENCODING=Symbol(`encoding`),DECODER=Symbol(`decoder`),FLOWING=Symbol(`flowing`),PAUSED=Symbol(`paused`),RESUME=Symbol(`resume`),BUFFER=Symbol(`buffer`),PIPES=Symbol(`pipes`),BUFFERLENGTH=Symbol(`bufferLength`),BUFFERPUSH=Symbol(`bufferPush`),BUFFERSHIFT=Symbol(`bufferShift`),OBJECTMODE=Symbol(`objectMode`),DESTROYED=Symbol(`destroyed`),ERROR=Symbol(`error`),EMITDATA=Symbol(`emitData`),EMITEND=Symbol(`emitEnd`),EMITEND2=Symbol(`emitEnd2`),ASYNC=Symbol(`async`),ABORT=Symbol(`abort`),ABORTED=Symbol(`aborted`),SIGNAL=Symbol(`signal`),DATALISTENERS=Symbol(`dataListeners`),DISCARDED=Symbol(`discarded`),defer=_=>Promise.resolve().then(_),nodefer=_=>_(),isEndish=_=>_===`end`||_===`finish`||_===`prefinish`,isArrayBufferLike=_=>_ instanceof ArrayBuffer||!!_&&typeof _==`object`&&_.constructor&&_.constructor.name===`ArrayBuffer`&&_.byteLength>=0,isArrayBufferView=_=>!Buffer.isBuffer(_)&&ArrayBuffer.isView(_);var Pipe=class{src;dest;opts;ondrain;constructor(_,K,q){this.src=_,this.dest=K,this.opts=q,this.ondrain=()=>_[RESUME](),this.dest.on(`drain`,this.ondrain)}unpipe(){this.dest.removeListener(`drain`,this.ondrain)}proxyErrors(_){}end(){this.unpipe(),this.opts.end&&this.dest.end()}},PipeProxyErrors=class extends Pipe{unpipe(){this.src.removeListener(`error`,this.proxyErrors),super.unpipe()}constructor(_,K,q){super(_,K,q),this.proxyErrors=_=>K.emit(`error`,_),_.on(`error`,this.proxyErrors)}};const isObjectModeOptions=_=>!!_.objectMode,isEncodingOptions=_=>!_.objectMode&&!!_.encoding&&_.encoding!==`buffer`;var Minipass=class extends EventEmitter$1{[FLOWING]=!1;[PAUSED]=!1;[PIPES]=[];[BUFFER]=[];[OBJECTMODE];[ENCODING];[ASYNC];[DECODER];[EOF]=!1;[EMITTED_END]=!1;[EMITTING_END]=!1;[CLOSED]=!1;[EMITTED_ERROR]=null;[BUFFERLENGTH]=0;[DESTROYED]=!1;[SIGNAL];[ABORTED]=!1;[DATALISTENERS]=0;[DISCARDED]=!1;writable=!0;readable=!0;constructor(..._){let K=_[0]||{};if(super(),K.objectMode&&typeof K.encoding==`string`)throw TypeError(`Encoding and objectMode may not be used together`);isObjectModeOptions(K)?(this[OBJECTMODE]=!0,this[ENCODING]=null):isEncodingOptions(K)?(this[ENCODING]=K.encoding,this[OBJECTMODE]=!1):(this[OBJECTMODE]=!1,this[ENCODING]=null),this[ASYNC]=!!K.async,this[DECODER]=this[ENCODING]?new StringDecoder(this[ENCODING]):null,K&&K.debugExposeBuffer===!0&&Object.defineProperty(this,`buffer`,{get:()=>this[BUFFER]}),K&&K.debugExposePipes===!0&&Object.defineProperty(this,`pipes`,{get:()=>this[PIPES]});let{signal:q}=K;q&&(this[SIGNAL]=q,q.aborted?this[ABORT]():q.addEventListener(`abort`,()=>this[ABORT]()))}get bufferLength(){return this[BUFFERLENGTH]}get encoding(){return this[ENCODING]}set encoding(_){throw Error(`Encoding must be set at instantiation time`)}setEncoding(_){throw Error(`Encoding must be set at instantiation time`)}get objectMode(){return this[OBJECTMODE]}set objectMode(_){throw Error(`objectMode must be set at instantiation time`)}get async(){return this[ASYNC]}set async(_){this[ASYNC]=this[ASYNC]||!!_}[ABORT](){this[ABORTED]=!0,this.emit(`abort`,this[SIGNAL]?.reason),this.destroy(this[SIGNAL]?.reason)}get aborted(){return this[ABORTED]}set aborted(_){}write(_,K,q){if(this[ABORTED])return!1;if(this[EOF])throw Error(`write after end`);if(this[DESTROYED])return this.emit(`error`,Object.assign(Error(`Cannot call write after a stream was destroyed`),{code:`ERR_STREAM_DESTROYED`})),!0;typeof K==`function`&&(q=K,K=`utf8`),K||=`utf8`;let J=this[ASYNC]?defer:nodefer;if(!this[OBJECTMODE]&&!Buffer.isBuffer(_)){if(isArrayBufferView(_))_=Buffer.from(_.buffer,_.byteOffset,_.byteLength);else if(isArrayBufferLike(_))_=Buffer.from(_);else if(typeof _!=`string`)throw Error(`Non-contiguous data written to non-objectMode stream`)}return this[OBJECTMODE]?(this[FLOWING]&&this[BUFFERLENGTH]!==0&&this[FLUSH](!0),this[FLOWING]?this.emit(`data`,_):this[BUFFERPUSH](_),this[BUFFERLENGTH]!==0&&this.emit(`readable`),q&&J(q),this[FLOWING]):_.length?(typeof _==`string`&&!(K===this[ENCODING]&&!this[DECODER]?.lastNeed)&&(_=Buffer.from(_,K)),Buffer.isBuffer(_)&&this[ENCODING]&&(_=this[DECODER].write(_)),this[FLOWING]&&this[BUFFERLENGTH]!==0&&this[FLUSH](!0),this[FLOWING]?this.emit(`data`,_):this[BUFFERPUSH](_),this[BUFFERLENGTH]!==0&&this.emit(`readable`),q&&J(q),this[FLOWING]):(this[BUFFERLENGTH]!==0&&this.emit(`readable`),q&&J(q),this[FLOWING])}read(_){if(this[DESTROYED])return null;if(this[DISCARDED]=!1,this[BUFFERLENGTH]===0||_===0||_&&_>this[BUFFERLENGTH])return this[MAYBE_EMIT_END](),null;this[OBJECTMODE]&&(_=null),this[BUFFER].length>1&&!this[OBJECTMODE]&&(this[BUFFER]=[this[ENCODING]?this[BUFFER].join(``):Buffer.concat(this[BUFFER],this[BUFFERLENGTH])]);let K=this[READ](_||null,this[BUFFER][0]);return this[MAYBE_EMIT_END](),K}[READ](_,K){if(this[OBJECTMODE])this[BUFFERSHIFT]();else{let q=K;_===q.length||_===null?this[BUFFERSHIFT]():typeof q==`string`?(this[BUFFER][0]=q.slice(_),K=q.slice(0,_),this[BUFFERLENGTH]-=_):(this[BUFFER][0]=q.subarray(_),K=q.subarray(0,_),this[BUFFERLENGTH]-=_)}return this.emit(`data`,K),!this[BUFFER].length&&!this[EOF]&&this.emit(`drain`),K}end(_,K,q){return typeof _==`function`&&(q=_,_=void 0),typeof K==`function`&&(q=K,K=`utf8`),_!==void 0&&this.write(_,K),q&&this.once(`end`,q),this[EOF]=!0,this.writable=!1,(this[FLOWING]||!this[PAUSED])&&this[MAYBE_EMIT_END](),this}[RESUME](){this[DESTROYED]||(!this[DATALISTENERS]&&!this[PIPES].length&&(this[DISCARDED]=!0),this[PAUSED]=!1,this[FLOWING]=!0,this.emit(`resume`),this[BUFFER].length?this[FLUSH]():this[EOF]?this[MAYBE_EMIT_END]():this.emit(`drain`))}resume(){return this[RESUME]()}pause(){this[FLOWING]=!1,this[PAUSED]=!0,this[DISCARDED]=!1}get destroyed(){return this[DESTROYED]}get flowing(){return this[FLOWING]}get paused(){return this[PAUSED]}[BUFFERPUSH](_){this[OBJECTMODE]?this[BUFFERLENGTH]+=1:this[BUFFERLENGTH]+=_.length,this[BUFFER].push(_)}[BUFFERSHIFT](){return this[OBJECTMODE]?--this[BUFFERLENGTH]:this[BUFFERLENGTH]-=this[BUFFER][0].length,this[BUFFER].shift()}[FLUSH](_=!1){do;while(this[FLUSHCHUNK](this[BUFFERSHIFT]())&&this[BUFFER].length);!_&&!this[BUFFER].length&&!this[EOF]&&this.emit(`drain`)}[FLUSHCHUNK](_){return this.emit(`data`,_),this[FLOWING]}pipe(_,K){if(this[DESTROYED])return _;this[DISCARDED]=!1;let q=this[EMITTED_END];return K||={},_===proc.stdout||_===proc.stderr?K.end=!1:K.end=K.end!==!1,K.proxyErrors=!!K.proxyErrors,q?K.end&&_.end():(this[PIPES].push(K.proxyErrors?new PipeProxyErrors(this,_,K):new Pipe(this,_,K)),this[ASYNC]?defer(()=>this[RESUME]()):this[RESUME]()),_}unpipe(_){let K=this[PIPES].find(K=>K.dest===_);K&&(this[PIPES].length===1?(this[FLOWING]&&this[DATALISTENERS]===0&&(this[FLOWING]=!1),this[PIPES]=[]):this[PIPES].splice(this[PIPES].indexOf(K),1),K.unpipe())}addListener(_,K){return this.on(_,K)}on(_,K){let q=super.on(_,K);if(_===`data`)this[DISCARDED]=!1,this[DATALISTENERS]++,!this[PIPES].length&&!this[FLOWING]&&this[RESUME]();else if(_===`readable`&&this[BUFFERLENGTH]!==0)super.emit(`readable`);else if(isEndish(_)&&this[EMITTED_END])super.emit(_),this.removeAllListeners(_);else if(_===`error`&&this[EMITTED_ERROR]){let _=K;this[ASYNC]?defer(()=>_.call(this,this[EMITTED_ERROR])):_.call(this,this[EMITTED_ERROR])}return q}removeListener(_,K){return this.off(_,K)}off(_,K){let q=super.off(_,K);return _===`data`&&(this[DATALISTENERS]=this.listeners(`data`).length,this[DATALISTENERS]===0&&!this[DISCARDED]&&!this[PIPES].length&&(this[FLOWING]=!1)),q}removeAllListeners(_){let K=super.removeAllListeners(_);return(_===`data`||_===void 0)&&(this[DATALISTENERS]=0,!this[DISCARDED]&&!this[PIPES].length&&(this[FLOWING]=!1)),K}get emittedEnd(){return this[EMITTED_END]}[MAYBE_EMIT_END](){!this[EMITTING_END]&&!this[EMITTED_END]&&!this[DESTROYED]&&this[BUFFER].length===0&&this[EOF]&&(this[EMITTING_END]=!0,this.emit(`end`),this.emit(`prefinish`),this.emit(`finish`),this[CLOSED]&&this.emit(`close`),this[EMITTING_END]=!1)}emit(_,...K){let q=K[0];if(_!==`error`&&_!==`close`&&_!==DESTROYED&&this[DESTROYED])return!1;if(_===`data`)return!this[OBJECTMODE]&&!q?!1:this[ASYNC]?(defer(()=>this[EMITDATA](q)),!0):this[EMITDATA](q);if(_===`end`)return this[EMITEND]();if(_===`close`){if(this[CLOSED]=!0,!this[EMITTED_END]&&!this[DESTROYED])return!1;let _=super.emit(`close`);return this.removeAllListeners(`close`),_}else if(_===`error`){this[EMITTED_ERROR]=q,super.emit(ERROR,q);let _=!this[SIGNAL]||this.listeners(`error`).length?super.emit(`error`,q):!1;return this[MAYBE_EMIT_END](),_}else if(_===`resume`){let _=super.emit(`resume`);return this[MAYBE_EMIT_END](),_}else if(_===`finish`||_===`prefinish`){let K=super.emit(_);return this.removeAllListeners(_),K}let J=super.emit(_,...K);return this[MAYBE_EMIT_END](),J}[EMITDATA](_){for(let K of this[PIPES])K.dest.write(_)===!1&&this.pause();let K=this[DISCARDED]?!1:super.emit(`data`,_);return this[MAYBE_EMIT_END](),K}[EMITEND](){return this[EMITTED_END]?!1:(this[EMITTED_END]=!0,this.readable=!1,this[ASYNC]?(defer(()=>this[EMITEND2]()),!0):this[EMITEND2]())}[EMITEND2](){if(this[DECODER]){let _=this[DECODER].end();if(_){for(let K of this[PIPES])K.dest.write(_);this[DISCARDED]||super.emit(`data`,_)}}for(let _ of this[PIPES])_.end();let _=super.emit(`end`);return this.removeAllListeners(`end`),_}async collect(){let _=Object.assign([],{dataLength:0});this[OBJECTMODE]||(_.dataLength=0);let K=this.promise();return this.on(`data`,K=>{_.push(K),this[OBJECTMODE]||(_.dataLength+=K.length)}),await K,_}async concat(){if(this[OBJECTMODE])throw Error(`cannot concat in objectMode`);let _=await this.collect();return this[ENCODING]?_.join(``):Buffer.concat(_,_.dataLength)}async promise(){return new Promise((_,K)=>{this.on(DESTROYED,()=>K(Error(`stream destroyed`))),this.on(`error`,_=>K(_)),this.on(`end`,()=>_())})}[Symbol.asyncIterator](){this[DISCARDED]=!1;let _=!1,K=async()=>(this.pause(),_=!0,{value:void 0,done:!0});return{next:()=>{if(_)return K();let q=this.read();if(q!==null)return Promise.resolve({done:!1,value:q});if(this[EOF])return K();let J,Y,X=_=>{this.off(`data`,Z),this.off(`end`,Q),this.off(DESTROYED,$),K(),Y(_)},Z=_=>{this.off(`error`,X),this.off(`end`,Q),this.off(DESTROYED,$),this.pause(),J({value:_,done:!!this[EOF]})},Q=()=>{this.off(`error`,X),this.off(`data`,Z),this.off(DESTROYED,$),K(),J({done:!0,value:void 0})},$=()=>X(Error(`stream destroyed`));return new Promise((_,K)=>{Y=K,J=_,this.once(DESTROYED,$),this.once(`error`,X),this.once(`end`,Q),this.once(`data`,Z)})},throw:K,return:K,[Symbol.asyncIterator](){return this}}}[Symbol.iterator](){this[DISCARDED]=!1;let _=!1,K=()=>(this.pause(),this.off(ERROR,K),this.off(DESTROYED,K),this.off(`end`,K),_=!0,{done:!0,value:void 0});return this.once(`end`,K),this.once(ERROR,K),this.once(DESTROYED,K),{next:()=>{if(_)return K();let q=this.read();return q===null?K():{done:!1,value:q}},throw:K,return:K,[Symbol.iterator](){return this}}}destroy(_){if(this[DESTROYED])return _?this.emit(`error`,_):this.emit(DESTROYED),this;this[DESTROYED]=!0,this[DISCARDED]=!0,this[BUFFER].length=0,this[BUFFERLENGTH]=0;let K=this;return typeof K.close==`function`&&!this[CLOSED]&&K.close(),_?this.emit(`error`,_):this.emit(DESTROYED),this}static get isStream(){return isStream}};const writev=fs.writev,_autoClose=Symbol(`_autoClose`),_close=Symbol(`_close`),_ended=Symbol(`_ended`),_fd=Symbol(`_fd`),_finished=Symbol(`_finished`),_flags=Symbol(`_flags`),_flush=Symbol(`_flush`),_handleChunk=Symbol(`_handleChunk`),_makeBuf=Symbol(`_makeBuf`),_mode=Symbol(`_mode`),_needDrain=Symbol(`_needDrain`),_onerror=Symbol(`_onerror`),_onopen=Symbol(`_onopen`),_onread=Symbol(`_onread`),_onwrite=Symbol(`_onwrite`),_open=Symbol(`_open`),_path=Symbol(`_path`),_pos=Symbol(`_pos`),_queue=Symbol(`_queue`),_read=Symbol(`_read`),_readSize=Symbol(`_readSize`),_reading=Symbol(`_reading`),_remain=Symbol(`_remain`),_size=Symbol(`_size`),_write=Symbol(`_write`),_writing=Symbol(`_writing`),_defaultFlag=Symbol(`_defaultFlag`),_errored=Symbol(`_errored`);var ReadStream=class extends Minipass{[_errored]=!1;[_fd];[_path];[_readSize];[_reading]=!1;[_size];[_remain];[_autoClose];constructor(_,K){if(K||={},super(K),this.readable=!0,this.writable=!1,typeof _!=`string`)throw TypeError(`path must be a string`);this[_errored]=!1,this[_fd]=typeof K.fd==`number`?K.fd:void 0,this[_path]=_,this[_readSize]=K.readSize||16*1024*1024,this[_reading]=!1,this[_size]=typeof K.size==`number`?K.size:1/0,this[_remain]=this[_size],this[_autoClose]=typeof K.autoClose==`boolean`?K.autoClose:!0,typeof this[_fd]==`number`?this[_read]():this[_open]()}get fd(){return this[_fd]}get path(){return this[_path]}write(){throw TypeError(`this is a readable stream`)}end(){throw TypeError(`this is a readable stream`)}[_open](){fs.open(this[_path],`r`,(_,K)=>this[_onopen](_,K))}[_onopen](_,K){_?this[_onerror](_):(this[_fd]=K,this.emit(`open`,K),this[_read]())}[_makeBuf](){return Buffer.allocUnsafe(Math.min(this[_readSize],this[_remain]))}[_read](){if(!this[_reading]){this[_reading]=!0;let _=this[_makeBuf]();if(_.length===0)return process.nextTick(()=>this[_onread](null,0,_));fs.read(this[_fd],_,0,_.length,null,(_,K,q)=>this[_onread](_,K,q))}}[_onread](_,K,q){this[_reading]=!1,_?this[_onerror](_):this[_handleChunk](K,q)&&this[_read]()}[_close](){if(this[_autoClose]&&typeof this[_fd]==`number`){let _=this[_fd];this[_fd]=void 0,fs.close(_,_=>_?this.emit(`error`,_):this.emit(`close`))}}[_onerror](_){this[_reading]=!0,this[_close](),this.emit(`error`,_)}[_handleChunk](_,K){let q=!1;return this[_remain]-=_,_>0&&(q=super.write(_<K.length?K.subarray(0,_):K)),(_===0||this[_remain]<=0)&&(q=!1,this[_close](),super.end()),q}emit(_,...K){switch(_){case`prefinish`:case`finish`:return!1;case`drain`:return typeof this[_fd]==`number`&&this[_read](),!1;case`error`:return this[_errored]?!1:(this[_errored]=!0,super.emit(_,...K));default:return super.emit(_,...K)}}},ReadStreamSync=class extends ReadStream{[_open](){let _=!0;try{this[_onopen](null,fs.openSync(this[_path],`r`)),_=!1}finally{_&&this[_close]()}}[_read](){let _=!0;try{if(!this[_reading]){this[_reading]=!0;do{let _=this[_makeBuf](),K=_.length===0?0:fs.readSync(this[_fd],_,0,_.length,null);if(!this[_handleChunk](K,_))break}while(!0);this[_reading]=!1}_=!1}finally{_&&this[_close]()}}[_close](){if(this[_autoClose]&&typeof this[_fd]==`number`){let _=this[_fd];this[_fd]=void 0,fs.closeSync(_),this.emit(`close`)}}},WriteStream=class extends EE{readable=!1;writable=!0;[_errored]=!1;[_writing]=!1;[_ended]=!1;[_queue]=[];[_needDrain]=!1;[_path];[_mode];[_autoClose];[_fd];[_defaultFlag];[_flags];[_finished]=!1;[_pos];constructor(_,K){K||={},super(K),this[_path]=_,this[_fd]=typeof K.fd==`number`?K.fd:void 0,this[_mode]=K.mode===void 0?438:K.mode,this[_pos]=typeof K.start==`number`?K.start:void 0,this[_autoClose]=typeof K.autoClose==`boolean`?K.autoClose:!0;let q=this[_pos]===void 0?`w`:`r+`;this[_defaultFlag]=K.flags===void 0,this[_flags]=K.flags===void 0?q:K.flags,this[_fd]===void 0&&this[_open]()}emit(_,...K){if(_===`error`){if(this[_errored])return!1;this[_errored]=!0}return super.emit(_,...K)}get fd(){return this[_fd]}get path(){return this[_path]}[_onerror](_){this[_close](),this[_writing]=!0,this.emit(`error`,_)}[_open](){fs.open(this[_path],this[_flags],this[_mode],(_,K)=>this[_onopen](_,K))}[_onopen](_,K){this[_defaultFlag]&&this[_flags]===`r+`&&_&&_.code===`ENOENT`?(this[_flags]=`w`,this[_open]()):_?this[_onerror](_):(this[_fd]=K,this.emit(`open`,K),this[_writing]||this[_flush]())}end(_,K){return _&&this.write(_,K),this[_ended]=!0,!this[_writing]&&!this[_queue].length&&typeof this[_fd]==`number`&&this[_onwrite](null,0),this}write(_,K){return typeof _==`string`&&(_=Buffer.from(_,K)),this[_ended]?(this.emit(`error`,Error(`write() after end()`)),!1):this[_fd]===void 0||this[_writing]||this[_queue].length?(this[_queue].push(_),this[_needDrain]=!0,!1):(this[_writing]=!0,this[_write](_),!0)}[_write](_){fs.write(this[_fd],_,0,_.length,this[_pos],(_,K)=>this[_onwrite](_,K))}[_onwrite](_,K){_?this[_onerror](_):(this[_pos]!==void 0&&typeof K==`number`&&(this[_pos]+=K),this[_queue].length?this[_flush]():(this[_writing]=!1,this[_ended]&&!this[_finished]?(this[_finished]=!0,this[_close](),this.emit(`finish`)):this[_needDrain]&&(this[_needDrain]=!1,this.emit(`drain`))))}[_flush](){if(this[_queue].length===0)this[_ended]&&this[_onwrite](null,0);else if(this[_queue].length===1)this[_write](this[_queue].pop());else{let _=this[_queue];this[_queue]=[],writev(this[_fd],_,this[_pos],(_,K)=>this[_onwrite](_,K))}}[_close](){if(this[_autoClose]&&typeof this[_fd]==`number`){let _=this[_fd];this[_fd]=void 0,fs.close(_,_=>_?this.emit(`error`,_):this.emit(`close`))}}},WriteStreamSync=class extends WriteStream{[_open](){let _;if(this[_defaultFlag]&&this[_flags]===`r+`)try{_=fs.openSync(this[_path],this[_flags],this[_mode])}catch(_){if(_?.code===`ENOENT`)return this[_flags]=`w`,this[_open]();throw _}else _=fs.openSync(this[_path],this[_flags],this[_mode]);this[_onopen](null,_)}[_close](){if(this[_autoClose]&&typeof this[_fd]==`number`){let _=this[_fd];this[_fd]=void 0,fs.closeSync(_),this.emit(`close`)}}[_write](_){let K=!0;try{this[_onwrite](null,fs.writeSync(this[_fd],_,0,_.length,this[_pos])),K=!1}finally{if(K)try{this[_close]()}catch{}}}};export{Minipass as a,WriteStreamSync as i,ReadStreamSync as n,WriteStream as r,ReadStream as t};
1
+ import Stream from "node:stream";
2
+ import EE from "events";
3
+ import fs from "fs";
4
+ import { EventEmitter as EventEmitter$1 } from "node:events";
5
+ import { StringDecoder } from "node:string_decoder";
6
+ const proc = typeof process == `object` && process ? process : {
7
+ stdout: null,
8
+ stderr: null
9
+ }, isStream = (t) => !!t && typeof t == `object` && (t instanceof Minipass || t instanceof Stream || isReadable(t) || isWritable(t)), isReadable = (t) => !!t && typeof t == `object` && t instanceof EventEmitter$1 && typeof t.pipe == `function` && t.pipe !== Stream.Writable.prototype.pipe, isWritable = (e) => !!e && typeof e == `object` && e instanceof EventEmitter$1 && typeof e.write == `function` && typeof e.end == `function`, EOF = Symbol(`EOF`), MAYBE_EMIT_END = Symbol(`maybeEmitEnd`), EMITTED_END = Symbol(`emittedEnd`), EMITTING_END = Symbol(`emittingEnd`), EMITTED_ERROR = Symbol(`emittedError`), CLOSED = Symbol(`closed`), READ = Symbol(`read`), FLUSH = Symbol(`flush`), FLUSHCHUNK = Symbol(`flushChunk`), ENCODING = Symbol(`encoding`), DECODER = Symbol(`decoder`), FLOWING = Symbol(`flowing`), PAUSED = Symbol(`paused`), RESUME = Symbol(`resume`), BUFFER = Symbol(`buffer`), PIPES = Symbol(`pipes`), BUFFERLENGTH = Symbol(`bufferLength`), BUFFERPUSH = Symbol(`bufferPush`), BUFFERSHIFT = Symbol(`bufferShift`), OBJECTMODE = Symbol(`objectMode`), DESTROYED = Symbol(`destroyed`), ERROR = Symbol(`error`), EMITDATA = Symbol(`emitData`), EMITEND = Symbol(`emitEnd`), EMITEND2 = Symbol(`emitEnd2`), ASYNC = Symbol(`async`), ABORT = Symbol(`abort`), ABORTED = Symbol(`aborted`), SIGNAL = Symbol(`signal`), DATALISTENERS = Symbol(`dataListeners`), DISCARDED = Symbol(`discarded`), defer = (e) => Promise.resolve().then(e), nodefer = (e) => e(), isEndish = (e) => e === `end` || e === `finish` || e === `prefinish`, isArrayBufferLike = (e) => e instanceof ArrayBuffer || !!e && typeof e == `object` && e.constructor && e.constructor.name === `ArrayBuffer` && e.byteLength >= 0, isArrayBufferView = (e) => !Buffer.isBuffer(e) && ArrayBuffer.isView(e);
10
+ var Pipe = class {
11
+ src;
12
+ dest;
13
+ opts;
14
+ ondrain;
15
+ constructor(e, t, n) {
16
+ this.src = e, this.dest = t, this.opts = n, this.ondrain = () => e[RESUME](), this.dest.on(`drain`, this.ondrain);
17
+ }
18
+ unpipe() {
19
+ this.dest.removeListener(`drain`, this.ondrain);
20
+ }
21
+ proxyErrors(e) {}
22
+ end() {
23
+ this.unpipe(), this.opts.end && this.dest.end();
24
+ }
25
+ }, PipeProxyErrors = class extends Pipe {
26
+ unpipe() {
27
+ this.src.removeListener(`error`, this.proxyErrors), super.unpipe();
28
+ }
29
+ constructor(e, t, n) {
30
+ super(e, t, n), this.proxyErrors = (e) => t.emit(`error`, e), e.on(`error`, this.proxyErrors);
31
+ }
32
+ };
33
+ const isObjectModeOptions = (e) => !!e.objectMode, isEncodingOptions = (e) => !e.objectMode && !!e.encoding && e.encoding !== `buffer`;
34
+ var Minipass = class extends EventEmitter$1 {
35
+ [FLOWING] = !1;
36
+ [PAUSED] = !1;
37
+ [PIPES] = [];
38
+ [BUFFER] = [];
39
+ [OBJECTMODE];
40
+ [ENCODING];
41
+ [ASYNC];
42
+ [DECODER];
43
+ [EOF] = !1;
44
+ [EMITTED_END] = !1;
45
+ [EMITTING_END] = !1;
46
+ [CLOSED] = !1;
47
+ [EMITTED_ERROR] = null;
48
+ [BUFFERLENGTH] = 0;
49
+ [DESTROYED] = !1;
50
+ [SIGNAL];
51
+ [ABORTED] = !1;
52
+ [DATALISTENERS] = 0;
53
+ [DISCARDED] = !1;
54
+ writable = !0;
55
+ readable = !0;
56
+ constructor(...e) {
57
+ let t = e[0] || {};
58
+ if (super(), t.objectMode && typeof t.encoding == `string`) throw TypeError(`Encoding and objectMode may not be used together`);
59
+ isObjectModeOptions(t) ? (this[OBJECTMODE] = !0, this[ENCODING] = null) : isEncodingOptions(t) ? (this[ENCODING] = t.encoding, this[OBJECTMODE] = !1) : (this[OBJECTMODE] = !1, this[ENCODING] = null), this[ASYNC] = !!t.async, this[DECODER] = this[ENCODING] ? new StringDecoder(this[ENCODING]) : null, t && t.debugExposeBuffer === !0 && Object.defineProperty(this, `buffer`, { get: () => this[BUFFER] }), t && t.debugExposePipes === !0 && Object.defineProperty(this, `pipes`, { get: () => this[PIPES] });
60
+ let { signal: n } = t;
61
+ n && (this[SIGNAL] = n, n.aborted ? this[ABORT]() : n.addEventListener(`abort`, () => this[ABORT]()));
62
+ }
63
+ get bufferLength() {
64
+ return this[BUFFERLENGTH];
65
+ }
66
+ get encoding() {
67
+ return this[ENCODING];
68
+ }
69
+ set encoding(e) {
70
+ throw Error(`Encoding must be set at instantiation time`);
71
+ }
72
+ setEncoding(e) {
73
+ throw Error(`Encoding must be set at instantiation time`);
74
+ }
75
+ get objectMode() {
76
+ return this[OBJECTMODE];
77
+ }
78
+ set objectMode(e) {
79
+ throw Error(`objectMode must be set at instantiation time`);
80
+ }
81
+ get async() {
82
+ return this[ASYNC];
83
+ }
84
+ set async(e) {
85
+ this[ASYNC] = this[ASYNC] || !!e;
86
+ }
87
+ [ABORT]() {
88
+ this[ABORTED] = !0, this.emit(`abort`, this[SIGNAL]?.reason), this.destroy(this[SIGNAL]?.reason);
89
+ }
90
+ get aborted() {
91
+ return this[ABORTED];
92
+ }
93
+ set aborted(e) {}
94
+ write(e, t, n) {
95
+ if (this[ABORTED]) return !1;
96
+ if (this[EOF]) throw Error(`write after end`);
97
+ if (this[DESTROYED]) return this.emit(`error`, Object.assign(Error(`Cannot call write after a stream was destroyed`), { code: `ERR_STREAM_DESTROYED` })), !0;
98
+ typeof t == `function` && (n = t, t = `utf8`), t ||= `utf8`;
99
+ let r = this[ASYNC] ? defer : nodefer;
100
+ if (!this[OBJECTMODE] && !Buffer.isBuffer(e)) {
101
+ if (isArrayBufferView(e)) e = Buffer.from(e.buffer, e.byteOffset, e.byteLength);
102
+ else if (isArrayBufferLike(e)) e = Buffer.from(e);
103
+ else if (typeof e != `string`) throw Error(`Non-contiguous data written to non-objectMode stream`);
104
+ }
105
+ return this[OBJECTMODE] ? (this[FLOWING] && this[BUFFERLENGTH] !== 0 && this[FLUSH](!0), this[FLOWING] ? this.emit(`data`, e) : this[BUFFERPUSH](e), this[BUFFERLENGTH] !== 0 && this.emit(`readable`), n && r(n), this[FLOWING]) : e.length ? (typeof e == `string` && !(t === this[ENCODING] && !this[DECODER]?.lastNeed) && (e = Buffer.from(e, t)), Buffer.isBuffer(e) && this[ENCODING] && (e = this[DECODER].write(e)), this[FLOWING] && this[BUFFERLENGTH] !== 0 && this[FLUSH](!0), this[FLOWING] ? this.emit(`data`, e) : this[BUFFERPUSH](e), this[BUFFERLENGTH] !== 0 && this.emit(`readable`), n && r(n), this[FLOWING]) : (this[BUFFERLENGTH] !== 0 && this.emit(`readable`), n && r(n), this[FLOWING]);
106
+ }
107
+ read(e) {
108
+ if (this[DESTROYED]) return null;
109
+ if (this[DISCARDED] = !1, this[BUFFERLENGTH] === 0 || e === 0 || e && e > this[BUFFERLENGTH]) return this[MAYBE_EMIT_END](), null;
110
+ this[OBJECTMODE] && (e = null), this[BUFFER].length > 1 && !this[OBJECTMODE] && (this[BUFFER] = [this[ENCODING] ? this[BUFFER].join(``) : Buffer.concat(this[BUFFER], this[BUFFERLENGTH])]);
111
+ let t = this[READ](e || null, this[BUFFER][0]);
112
+ return this[MAYBE_EMIT_END](), t;
113
+ }
114
+ [READ](e, t) {
115
+ if (this[OBJECTMODE]) this[BUFFERSHIFT]();
116
+ else {
117
+ let n = t;
118
+ e === n.length || e === null ? this[BUFFERSHIFT]() : typeof n == `string` ? (this[BUFFER][0] = n.slice(e), t = n.slice(0, e), this[BUFFERLENGTH] -= e) : (this[BUFFER][0] = n.subarray(e), t = n.subarray(0, e), this[BUFFERLENGTH] -= e);
119
+ }
120
+ return this.emit(`data`, t), !this[BUFFER].length && !this[EOF] && this.emit(`drain`), t;
121
+ }
122
+ end(e, t, n) {
123
+ return typeof e == `function` && (n = e, e = void 0), typeof t == `function` && (n = t, t = `utf8`), e !== void 0 && this.write(e, t), n && this.once(`end`, n), this[EOF] = !0, this.writable = !1, (this[FLOWING] || !this[PAUSED]) && this[MAYBE_EMIT_END](), this;
124
+ }
125
+ [RESUME]() {
126
+ this[DESTROYED] || (!this[DATALISTENERS] && !this[PIPES].length && (this[DISCARDED] = !0), this[PAUSED] = !1, this[FLOWING] = !0, this.emit(`resume`), this[BUFFER].length ? this[FLUSH]() : this[EOF] ? this[MAYBE_EMIT_END]() : this.emit(`drain`));
127
+ }
128
+ resume() {
129
+ return this[RESUME]();
130
+ }
131
+ pause() {
132
+ this[FLOWING] = !1, this[PAUSED] = !0, this[DISCARDED] = !1;
133
+ }
134
+ get destroyed() {
135
+ return this[DESTROYED];
136
+ }
137
+ get flowing() {
138
+ return this[FLOWING];
139
+ }
140
+ get paused() {
141
+ return this[PAUSED];
142
+ }
143
+ [BUFFERPUSH](e) {
144
+ this[OBJECTMODE] ? this[BUFFERLENGTH] += 1 : this[BUFFERLENGTH] += e.length, this[BUFFER].push(e);
145
+ }
146
+ [BUFFERSHIFT]() {
147
+ return this[OBJECTMODE] ? --this[BUFFERLENGTH] : this[BUFFERLENGTH] -= this[BUFFER][0].length, this[BUFFER].shift();
148
+ }
149
+ [FLUSH](e = !1) {
150
+ do ;
151
+ while (this[FLUSHCHUNK](this[BUFFERSHIFT]()) && this[BUFFER].length);
152
+ !e && !this[BUFFER].length && !this[EOF] && this.emit(`drain`);
153
+ }
154
+ [FLUSHCHUNK](e) {
155
+ return this.emit(`data`, e), this[FLOWING];
156
+ }
157
+ pipe(e, t) {
158
+ if (this[DESTROYED]) return e;
159
+ this[DISCARDED] = !1;
160
+ let n = this[EMITTED_END];
161
+ return t ||= {}, e === proc.stdout || e === proc.stderr ? t.end = !1 : t.end = t.end !== !1, t.proxyErrors = !!t.proxyErrors, n ? t.end && e.end() : (this[PIPES].push(t.proxyErrors ? new PipeProxyErrors(this, e, t) : new Pipe(this, e, t)), this[ASYNC] ? defer(() => this[RESUME]()) : this[RESUME]()), e;
162
+ }
163
+ unpipe(e) {
164
+ let t = this[PIPES].find((t) => t.dest === e);
165
+ t && (this[PIPES].length === 1 ? (this[FLOWING] && this[DATALISTENERS] === 0 && (this[FLOWING] = !1), this[PIPES] = []) : this[PIPES].splice(this[PIPES].indexOf(t), 1), t.unpipe());
166
+ }
167
+ addListener(e, t) {
168
+ return this.on(e, t);
169
+ }
170
+ on(e, t) {
171
+ let n = super.on(e, t);
172
+ if (e === `data`) this[DISCARDED] = !1, this[DATALISTENERS]++, !this[PIPES].length && !this[FLOWING] && this[RESUME]();
173
+ else if (e === `readable` && this[BUFFERLENGTH] !== 0) super.emit(`readable`);
174
+ else if (isEndish(e) && this[EMITTED_END]) super.emit(e), this.removeAllListeners(e);
175
+ else if (e === `error` && this[EMITTED_ERROR]) {
176
+ let e = t;
177
+ this[ASYNC] ? defer(() => e.call(this, this[EMITTED_ERROR])) : e.call(this, this[EMITTED_ERROR]);
178
+ }
179
+ return n;
180
+ }
181
+ removeListener(e, t) {
182
+ return this.off(e, t);
183
+ }
184
+ off(e, t) {
185
+ let n = super.off(e, t);
186
+ return e === `data` && (this[DATALISTENERS] = this.listeners(`data`).length, this[DATALISTENERS] === 0 && !this[DISCARDED] && !this[PIPES].length && (this[FLOWING] = !1)), n;
187
+ }
188
+ removeAllListeners(e) {
189
+ let t = super.removeAllListeners(e);
190
+ return (e === `data` || e === void 0) && (this[DATALISTENERS] = 0, !this[DISCARDED] && !this[PIPES].length && (this[FLOWING] = !1)), t;
191
+ }
192
+ get emittedEnd() {
193
+ return this[EMITTED_END];
194
+ }
195
+ [MAYBE_EMIT_END]() {
196
+ !this[EMITTING_END] && !this[EMITTED_END] && !this[DESTROYED] && this[BUFFER].length === 0 && this[EOF] && (this[EMITTING_END] = !0, this.emit(`end`), this.emit(`prefinish`), this.emit(`finish`), this[CLOSED] && this.emit(`close`), this[EMITTING_END] = !1);
197
+ }
198
+ emit(e, ...t) {
199
+ let n = t[0];
200
+ if (e !== `error` && e !== `close` && e !== DESTROYED && this[DESTROYED]) return !1;
201
+ if (e === `data`) return !this[OBJECTMODE] && !n ? !1 : this[ASYNC] ? (defer(() => this[EMITDATA](n)), !0) : this[EMITDATA](n);
202
+ if (e === `end`) return this[EMITEND]();
203
+ if (e === `close`) {
204
+ if (this[CLOSED] = !0, !this[EMITTED_END] && !this[DESTROYED]) return !1;
205
+ let e = super.emit(`close`);
206
+ return this.removeAllListeners(`close`), e;
207
+ } else if (e === `error`) {
208
+ this[EMITTED_ERROR] = n, super.emit(ERROR, n);
209
+ let e = !this[SIGNAL] || this.listeners(`error`).length ? super.emit(`error`, n) : !1;
210
+ return this[MAYBE_EMIT_END](), e;
211
+ } else if (e === `resume`) {
212
+ let e = super.emit(`resume`);
213
+ return this[MAYBE_EMIT_END](), e;
214
+ } else if (e === `finish` || e === `prefinish`) {
215
+ let t = super.emit(e);
216
+ return this.removeAllListeners(e), t;
217
+ }
218
+ let r = super.emit(e, ...t);
219
+ return this[MAYBE_EMIT_END](), r;
220
+ }
221
+ [EMITDATA](e) {
222
+ for (let t of this[PIPES]) t.dest.write(e) === !1 && this.pause();
223
+ let t = this[DISCARDED] ? !1 : super.emit(`data`, e);
224
+ return this[MAYBE_EMIT_END](), t;
225
+ }
226
+ [EMITEND]() {
227
+ return this[EMITTED_END] ? !1 : (this[EMITTED_END] = !0, this.readable = !1, this[ASYNC] ? (defer(() => this[EMITEND2]()), !0) : this[EMITEND2]());
228
+ }
229
+ [EMITEND2]() {
230
+ if (this[DECODER]) {
231
+ let e = this[DECODER].end();
232
+ if (e) {
233
+ for (let t of this[PIPES]) t.dest.write(e);
234
+ this[DISCARDED] || super.emit(`data`, e);
235
+ }
236
+ }
237
+ for (let e of this[PIPES]) e.end();
238
+ let e = super.emit(`end`);
239
+ return this.removeAllListeners(`end`), e;
240
+ }
241
+ async collect() {
242
+ let e = Object.assign([], { dataLength: 0 });
243
+ this[OBJECTMODE] || (e.dataLength = 0);
244
+ let t = this.promise();
245
+ return this.on(`data`, (t) => {
246
+ e.push(t), this[OBJECTMODE] || (e.dataLength += t.length);
247
+ }), await t, e;
248
+ }
249
+ async concat() {
250
+ if (this[OBJECTMODE]) throw Error(`cannot concat in objectMode`);
251
+ let e = await this.collect();
252
+ return this[ENCODING] ? e.join(``) : Buffer.concat(e, e.dataLength);
253
+ }
254
+ async promise() {
255
+ return new Promise((e, t) => {
256
+ this.on(DESTROYED, () => t(Error(`stream destroyed`))), this.on(`error`, (e) => t(e)), this.on(`end`, () => e());
257
+ });
258
+ }
259
+ [Symbol.asyncIterator]() {
260
+ this[DISCARDED] = !1;
261
+ let e = !1, t = async () => (this.pause(), e = !0, {
262
+ value: void 0,
263
+ done: !0
264
+ });
265
+ return {
266
+ next: () => {
267
+ if (e) return t();
268
+ let n = this.read();
269
+ if (n !== null) return Promise.resolve({
270
+ done: !1,
271
+ value: n
272
+ });
273
+ if (this[EOF]) return t();
274
+ let r, i, a = (e) => {
275
+ this.off(`data`, o), this.off(`end`, s), this.off(DESTROYED, c), t(), i(e);
276
+ }, o = (e) => {
277
+ this.off(`error`, a), this.off(`end`, s), this.off(DESTROYED, c), this.pause(), r({
278
+ value: e,
279
+ done: !!this[EOF]
280
+ });
281
+ }, s = () => {
282
+ this.off(`error`, a), this.off(`data`, o), this.off(DESTROYED, c), t(), r({
283
+ done: !0,
284
+ value: void 0
285
+ });
286
+ }, c = () => a(Error(`stream destroyed`));
287
+ return new Promise((e, t) => {
288
+ i = t, r = e, this.once(DESTROYED, c), this.once(`error`, a), this.once(`end`, s), this.once(`data`, o);
289
+ });
290
+ },
291
+ throw: t,
292
+ return: t,
293
+ [Symbol.asyncIterator]() {
294
+ return this;
295
+ }
296
+ };
297
+ }
298
+ [Symbol.iterator]() {
299
+ this[DISCARDED] = !1;
300
+ let e = !1, t = () => (this.pause(), this.off(ERROR, t), this.off(DESTROYED, t), this.off(`end`, t), e = !0, {
301
+ done: !0,
302
+ value: void 0
303
+ });
304
+ return this.once(`end`, t), this.once(ERROR, t), this.once(DESTROYED, t), {
305
+ next: () => {
306
+ if (e) return t();
307
+ let n = this.read();
308
+ return n === null ? t() : {
309
+ done: !1,
310
+ value: n
311
+ };
312
+ },
313
+ throw: t,
314
+ return: t,
315
+ [Symbol.iterator]() {
316
+ return this;
317
+ }
318
+ };
319
+ }
320
+ destroy(e) {
321
+ if (this[DESTROYED]) return e ? this.emit(`error`, e) : this.emit(DESTROYED), this;
322
+ this[DESTROYED] = !0, this[DISCARDED] = !0, this[BUFFER].length = 0, this[BUFFERLENGTH] = 0;
323
+ let t = this;
324
+ return typeof t.close == `function` && !this[CLOSED] && t.close(), e ? this.emit(`error`, e) : this.emit(DESTROYED), this;
325
+ }
326
+ static get isStream() {
327
+ return isStream;
328
+ }
329
+ };
330
+ const writev = fs.writev, _autoClose = Symbol(`_autoClose`), _close = Symbol(`_close`), _ended = Symbol(`_ended`), _fd = Symbol(`_fd`), _finished = Symbol(`_finished`), _flags = Symbol(`_flags`), _flush = Symbol(`_flush`), _handleChunk = Symbol(`_handleChunk`), _makeBuf = Symbol(`_makeBuf`), _mode = Symbol(`_mode`), _needDrain = Symbol(`_needDrain`), _onerror = Symbol(`_onerror`), _onopen = Symbol(`_onopen`), _onread = Symbol(`_onread`), _onwrite = Symbol(`_onwrite`), _open = Symbol(`_open`), _path = Symbol(`_path`), _pos = Symbol(`_pos`), _queue = Symbol(`_queue`), _read = Symbol(`_read`), _readSize = Symbol(`_readSize`), _reading = Symbol(`_reading`), _remain = Symbol(`_remain`), _size = Symbol(`_size`), _write = Symbol(`_write`), _writing = Symbol(`_writing`), _defaultFlag = Symbol(`_defaultFlag`), _errored = Symbol(`_errored`);
331
+ var ReadStream = class extends Minipass {
332
+ [_errored] = !1;
333
+ [_fd];
334
+ [_path];
335
+ [_readSize];
336
+ [_reading] = !1;
337
+ [_size];
338
+ [_remain];
339
+ [_autoClose];
340
+ constructor(e, t) {
341
+ if (t ||= {}, super(t), this.readable = !0, this.writable = !1, typeof e != `string`) throw TypeError(`path must be a string`);
342
+ this[_errored] = !1, this[_fd] = typeof t.fd == `number` ? t.fd : void 0, this[_path] = e, this[_readSize] = t.readSize || 16 * 1024 * 1024, this[_reading] = !1, this[_size] = typeof t.size == `number` ? t.size : Infinity, this[_remain] = this[_size], this[_autoClose] = typeof t.autoClose == `boolean` ? t.autoClose : !0, typeof this[_fd] == `number` ? this[_read]() : this[_open]();
343
+ }
344
+ get fd() {
345
+ return this[_fd];
346
+ }
347
+ get path() {
348
+ return this[_path];
349
+ }
350
+ write() {
351
+ throw TypeError(`this is a readable stream`);
352
+ }
353
+ end() {
354
+ throw TypeError(`this is a readable stream`);
355
+ }
356
+ [_open]() {
357
+ fs.open(this[_path], `r`, (e, t) => this[_onopen](e, t));
358
+ }
359
+ [_onopen](e, t) {
360
+ e ? this[_onerror](e) : (this[_fd] = t, this.emit(`open`, t), this[_read]());
361
+ }
362
+ [_makeBuf]() {
363
+ return Buffer.allocUnsafe(Math.min(this[_readSize], this[_remain]));
364
+ }
365
+ [_read]() {
366
+ if (!this[_reading]) {
367
+ this[_reading] = !0;
368
+ let e = this[_makeBuf]();
369
+ if (e.length === 0) return process.nextTick(() => this[_onread](null, 0, e));
370
+ fs.read(this[_fd], e, 0, e.length, null, (e, t, n) => this[_onread](e, t, n));
371
+ }
372
+ }
373
+ [_onread](e, t, n) {
374
+ this[_reading] = !1, e ? this[_onerror](e) : this[_handleChunk](t, n) && this[_read]();
375
+ }
376
+ [_close]() {
377
+ if (this[_autoClose] && typeof this[_fd] == `number`) {
378
+ let e = this[_fd];
379
+ this[_fd] = void 0, fs.close(e, (e) => e ? this.emit(`error`, e) : this.emit(`close`));
380
+ }
381
+ }
382
+ [_onerror](e) {
383
+ this[_reading] = !0, this[_close](), this.emit(`error`, e);
384
+ }
385
+ [_handleChunk](e, t) {
386
+ let n = !1;
387
+ return this[_remain] -= e, e > 0 && (n = super.write(e < t.length ? t.subarray(0, e) : t)), (e === 0 || this[_remain] <= 0) && (n = !1, this[_close](), super.end()), n;
388
+ }
389
+ emit(e, ...t) {
390
+ switch (e) {
391
+ case `prefinish`:
392
+ case `finish`: return !1;
393
+ case `drain`: return typeof this[_fd] == `number` && this[_read](), !1;
394
+ case `error`: return this[_errored] ? !1 : (this[_errored] = !0, super.emit(e, ...t));
395
+ default: return super.emit(e, ...t);
396
+ }
397
+ }
398
+ }, ReadStreamSync = class extends ReadStream {
399
+ [_open]() {
400
+ let e = !0;
401
+ try {
402
+ this[_onopen](null, fs.openSync(this[_path], `r`)), e = !1;
403
+ } finally {
404
+ e && this[_close]();
405
+ }
406
+ }
407
+ [_read]() {
408
+ let e = !0;
409
+ try {
410
+ if (!this[_reading]) {
411
+ this[_reading] = !0;
412
+ do {
413
+ let e = this[_makeBuf](), t = e.length === 0 ? 0 : fs.readSync(this[_fd], e, 0, e.length, null);
414
+ if (!this[_handleChunk](t, e)) break;
415
+ } while (!0);
416
+ this[_reading] = !1;
417
+ }
418
+ e = !1;
419
+ } finally {
420
+ e && this[_close]();
421
+ }
422
+ }
423
+ [_close]() {
424
+ if (this[_autoClose] && typeof this[_fd] == `number`) {
425
+ let e = this[_fd];
426
+ this[_fd] = void 0, fs.closeSync(e), this.emit(`close`);
427
+ }
428
+ }
429
+ }, WriteStream = class extends EE {
430
+ readable = !1;
431
+ writable = !0;
432
+ [_errored] = !1;
433
+ [_writing] = !1;
434
+ [_ended] = !1;
435
+ [_queue] = [];
436
+ [_needDrain] = !1;
437
+ [_path];
438
+ [_mode];
439
+ [_autoClose];
440
+ [_fd];
441
+ [_defaultFlag];
442
+ [_flags];
443
+ [_finished] = !1;
444
+ [_pos];
445
+ constructor(e, t) {
446
+ t ||= {}, super(t), this[_path] = e, this[_fd] = typeof t.fd == `number` ? t.fd : void 0, this[_mode] = t.mode === void 0 ? 438 : t.mode, this[_pos] = typeof t.start == `number` ? t.start : void 0, this[_autoClose] = typeof t.autoClose == `boolean` ? t.autoClose : !0;
447
+ let n = this[_pos] === void 0 ? `w` : `r+`;
448
+ this[_defaultFlag] = t.flags === void 0, this[_flags] = t.flags === void 0 ? n : t.flags, this[_fd] === void 0 && this[_open]();
449
+ }
450
+ emit(e, ...t) {
451
+ if (e === `error`) {
452
+ if (this[_errored]) return !1;
453
+ this[_errored] = !0;
454
+ }
455
+ return super.emit(e, ...t);
456
+ }
457
+ get fd() {
458
+ return this[_fd];
459
+ }
460
+ get path() {
461
+ return this[_path];
462
+ }
463
+ [_onerror](e) {
464
+ this[_close](), this[_writing] = !0, this.emit(`error`, e);
465
+ }
466
+ [_open]() {
467
+ fs.open(this[_path], this[_flags], this[_mode], (e, t) => this[_onopen](e, t));
468
+ }
469
+ [_onopen](e, t) {
470
+ this[_defaultFlag] && this[_flags] === `r+` && e && e.code === `ENOENT` ? (this[_flags] = `w`, this[_open]()) : e ? this[_onerror](e) : (this[_fd] = t, this.emit(`open`, t), this[_writing] || this[_flush]());
471
+ }
472
+ end(e, t) {
473
+ return e && this.write(e, t), this[_ended] = !0, !this[_writing] && !this[_queue].length && typeof this[_fd] == `number` && this[_onwrite](null, 0), this;
474
+ }
475
+ write(e, t) {
476
+ return typeof e == `string` && (e = Buffer.from(e, t)), this[_ended] ? (this.emit(`error`, Error(`write() after end()`)), !1) : this[_fd] === void 0 || this[_writing] || this[_queue].length ? (this[_queue].push(e), this[_needDrain] = !0, !1) : (this[_writing] = !0, this[_write](e), !0);
477
+ }
478
+ [_write](e) {
479
+ fs.write(this[_fd], e, 0, e.length, this[_pos], (e, t) => this[_onwrite](e, t));
480
+ }
481
+ [_onwrite](e, t) {
482
+ e ? this[_onerror](e) : (this[_pos] !== void 0 && typeof t == `number` && (this[_pos] += t), this[_queue].length ? this[_flush]() : (this[_writing] = !1, this[_ended] && !this[_finished] ? (this[_finished] = !0, this[_close](), this.emit(`finish`)) : this[_needDrain] && (this[_needDrain] = !1, this.emit(`drain`))));
483
+ }
484
+ [_flush]() {
485
+ if (this[_queue].length === 0) this[_ended] && this[_onwrite](null, 0);
486
+ else if (this[_queue].length === 1) this[_write](this[_queue].pop());
487
+ else {
488
+ let e = this[_queue];
489
+ this[_queue] = [], writev(this[_fd], e, this[_pos], (e, t) => this[_onwrite](e, t));
490
+ }
491
+ }
492
+ [_close]() {
493
+ if (this[_autoClose] && typeof this[_fd] == `number`) {
494
+ let e = this[_fd];
495
+ this[_fd] = void 0, fs.close(e, (e) => e ? this.emit(`error`, e) : this.emit(`close`));
496
+ }
497
+ }
498
+ }, WriteStreamSync = class extends WriteStream {
499
+ [_open]() {
500
+ let e;
501
+ if (this[_defaultFlag] && this[_flags] === `r+`) try {
502
+ e = fs.openSync(this[_path], this[_flags], this[_mode]);
503
+ } catch (e) {
504
+ if (e?.code === `ENOENT`) return this[_flags] = `w`, this[_open]();
505
+ throw e;
506
+ }
507
+ else e = fs.openSync(this[_path], this[_flags], this[_mode]);
508
+ this[_onopen](null, e);
509
+ }
510
+ [_close]() {
511
+ if (this[_autoClose] && typeof this[_fd] == `number`) {
512
+ let e = this[_fd];
513
+ this[_fd] = void 0, fs.closeSync(e), this.emit(`close`);
514
+ }
515
+ }
516
+ [_write](e) {
517
+ let t = !0;
518
+ try {
519
+ this[_onwrite](null, fs.writeSync(this[_fd], e, 0, e.length, this[_pos])), t = !1;
520
+ } finally {
521
+ if (t) try {
522
+ this[_close]();
523
+ } catch {}
524
+ }
525
+ }
526
+ };
527
+ export { Minipass as a, WriteStreamSync as i, ReadStreamSync as n, WriteStream as r, ReadStream as t };