@stackone/cli 1.8.0 → 1.9.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/CLAUDE_TEMPLATE.md +634 -0
- package/README.md +83 -8
- package/dist/cli.cjs +1 -1
- package/dist/cli.js +1 -1
- package/dist/cliCore-BJMMc7zt.cjs +139 -0
- package/dist/cliCore-DObMBAP8.js +139 -0
- package/dist/{esm-BrK-ICga.cjs → esm-BSZWAx0q.cjs} +1 -1
- package/dist/esm-Wey0v-fi.js +1 -0
- package/dist/index.cjs +1 -1
- package/dist/index.js +1 -1
- package/package.json +2 -1
- package/dist/cliCore-BOwdDcP4.cjs +0 -7
- package/dist/cliCore-CYhcPSJT.js +0 -7
- package/dist/esm-D_hUWJ1V.js +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{lstat as e,readdir as t,realpath as n,stat as r}from"node:fs/promises";import{join as i,relative as a,resolve as o,sep as s}from"node:path";import{stat as c,unwatchFile as l,watch as u,watchFile as d}from"fs";import{type as f}from"os";import*as p from"path";import{lstat as ee,open as te,readdir as ne,realpath as m,stat as h}from"fs/promises";import{EventEmitter as re}from"events";import{Readable as g}from"node:stream";const _={FILE_TYPE:`files`,DIR_TYPE:`directories`,FILE_DIR_TYPE:`files_directories`,EVERYTHING_TYPE:`all`},v={root:`.`,fileFilter:e=>!0,directoryFilter:e=>!0,type:_.FILE_TYPE,lstat:!1,depth:2147483648,alwaysStat:!1,highWaterMark:4096};Object.freeze(v);const y=`READDIRP_RECURSIVE_ERROR`,ie=new Set([`ENOENT`,`EPERM`,`EACCES`,`ELOOP`,y]),b=[_.DIR_TYPE,_.EVERYTHING_TYPE,_.FILE_DIR_TYPE,_.FILE_TYPE],ae=new Set([_.DIR_TYPE,_.EVERYTHING_TYPE,_.FILE_DIR_TYPE]),oe=new Set([_.EVERYTHING_TYPE,_.FILE_DIR_TYPE,_.FILE_TYPE]),se=e=>ie.has(e.code),ce=process.platform===`win32`,x=e=>!0,S=e=>{if(e===void 0)return x;if(typeof e==`function`)return e;if(typeof e==`string`){let t=e.trim();return e=>e.basename===t}if(Array.isArray(e)){let t=e.map(e=>e.trim());return e=>t.some(t=>e.basename===t)}return x};var le=class extends g{constructor(t={}){super({objectMode:!0,autoDestroy:!0,highWaterMark:t.highWaterMark});let n={...v,...t},{root:i,type:a}=n;this._fileFilter=S(n.fileFilter),this._directoryFilter=S(n.directoryFilter);let s=n.lstat?e:r;ce?this._stat=e=>s(e,{bigint:!0}):this._stat=s,this._maxDepth=n.depth??v.depth,this._wantsDir=a?ae.has(a):!1,this._wantsFile=a?oe.has(a):!1,this._wantsEverything=a===_.EVERYTHING_TYPE,this._root=o(i),this._isDirent=!n.alwaysStat,this._statsProp=this._isDirent?`dirent`:`stats`,this._rdOptions={encoding:`utf8`,withFileTypes:this._isDirent},this.parents=[this._exploreDir(i,1)],this.reading=!1,this.parent=void 0}async _read(e){if(!this.reading){this.reading=!0;try{for(;!this.destroyed&&e>0;){let t=this.parent,n=t&&t.files;if(n&&n.length>0){let{path:r,depth:i}=t,a=n.splice(0,e).map(e=>this._formatEntry(e,r)),o=await Promise.all(a);for(let t of o){if(!t)continue;if(this.destroyed)return;let n=await this._getEntryType(t);n===`directory`&&this._directoryFilter(t)?(i<=this._maxDepth&&this.parents.push(this._exploreDir(t.fullPath,i+1)),this._wantsDir&&(this.push(t),e--)):(n===`file`||this._includeAsFile(t))&&this._fileFilter(t)&&this._wantsFile&&(this.push(t),e--)}}else{let e=this.parents.pop();if(!e){this.push(null);break}if(this.parent=await e,this.destroyed)return}}}catch(e){this.destroy(e)}finally{this.reading=!1}}}async _exploreDir(e,n){let r;try{r=await t(e,this._rdOptions)}catch(e){this._onError(e)}return{files:r,depth:n,path:e}}async _formatEntry(e,t){let n,r=this._isDirent?e.name:e;try{let s=o(i(t,r));n={path:a(this._root,s),fullPath:s,basename:r},n[this._statsProp]=this._isDirent?e:await this._stat(s)}catch(e){this._onError(e);return}return n}_onError(e){se(e)&&!this.destroyed?this.emit(`warn`,e):this.destroy(e)}async _getEntryType(t){if(!t&&this._statsProp in t)return``;let r=t[this._statsProp];if(r.isFile())return`file`;if(r.isDirectory())return`directory`;if(r&&r.isSymbolicLink()){let r=t.fullPath;try{let t=await n(r),i=await e(t);if(i.isFile())return`file`;if(i.isDirectory()){let e=t.length;if(r.startsWith(t)&&r.substr(e,1)===s){let e=Error(`Circular symlink detected: "${r}" points to "${t}"`);return e.code=y,this._onError(e)}return`directory`}}catch(e){return this._onError(e),``}}}_includeAsFile(e){let t=e&&e[this._statsProp];return t&&this._wantsEverything&&!t.isDirectory()}};function ue(e,t={}){let n=t.entryType||t.type;if(n===`both`&&(n=_.FILE_DIR_TYPE),n&&(t.type=n),e){if(typeof e!=`string`)throw TypeError(`readdirp: root argument must be a string. Usage: readdirp(root, options)`);if(n&&!b.includes(n))throw Error(`readdirp: Invalid type passed. Use one of ${b.join(`, `)}`)}else throw Error(`readdirp: root argument is required. Usage: readdirp(root, options)`);return t.root=e,new le(t)}const de=`data`,C=`end`,fe=`close`,w=()=>{},T=process.platform,E=T===`win32`,pe=T===`darwin`,me=T===`linux`,he=T===`freebsd`,ge=f()===`OS400`,D={ALL:`all`,READY:`ready`,ADD:`add`,CHANGE:`change`,ADD_DIR:`addDir`,UNLINK:`unlink`,UNLINK_DIR:`unlinkDir`,RAW:`raw`,ERROR:`error`},O=D,_e=`watch`,ve={lstat:ee,stat:h},k=`listeners`,A=`errHandlers`,j=`rawEmitters`,M=[k,A,j],N=new Set(`3dm.3ds.3g2.3gp.7z.a.aac.adp.afdesign.afphoto.afpub.ai.aif.aiff.alz.ape.apk.appimage.ar.arj.asf.au.avi.bak.baml.bh.bin.bk.bmp.btif.bz2.bzip2.cab.caf.cgm.class.cmx.cpio.cr2.cur.dat.dcm.deb.dex.djvu.dll.dmg.dng.doc.docm.docx.dot.dotm.dra.DS_Store.dsk.dts.dtshd.dvb.dwg.dxf.ecelp4800.ecelp7470.ecelp9600.egg.eol.eot.epub.exe.f4v.fbs.fh.fla.flac.flatpak.fli.flv.fpx.fst.fvt.g3.gh.gif.graffle.gz.gzip.h261.h263.h264.icns.ico.ief.img.ipa.iso.jar.jpeg.jpg.jpgv.jpm.jxr.key.ktx.lha.lib.lvp.lz.lzh.lzma.lzo.m3u.m4a.m4v.mar.mdi.mht.mid.midi.mj2.mka.mkv.mmr.mng.mobi.mov.movie.mp3.mp4.mp4a.mpeg.mpg.mpga.mxu.nef.npx.numbers.nupkg.o.odp.ods.odt.oga.ogg.ogv.otf.ott.pages.pbm.pcx.pdb.pdf.pea.pgm.pic.png.pnm.pot.potm.potx.ppa.ppam.ppm.pps.ppsm.ppsx.ppt.pptm.pptx.psd.pya.pyc.pyo.pyv.qt.rar.ras.raw.resources.rgb.rip.rlc.rmf.rmvb.rpm.rtf.rz.s3m.s7z.scpt.sgi.shar.snap.sil.sketch.slk.smv.snk.so.stl.suo.sub.swf.tar.tbz.tbz2.tga.tgz.thmx.tif.tiff.tlz.ttc.ttf.txz.udf.uvh.uvi.uvm.uvp.uvs.uvu.viv.vob.war.wav.wax.wbmp.wdp.weba.webm.webp.whl.wim.wm.wma.wmv.wmx.woff.woff2.wrm.wvx.xbm.xif.xla.xlam.xls.xlsb.xlsm.xlsx.xlt.xltm.xltx.xm.xmind.xpi.xpm.xwd.xz.z.zip.zipx`.split(`.`)),P=e=>N.has(p.extname(e).slice(1).toLowerCase()),F=(e,t)=>{e instanceof Set?e.forEach(t):t(e)},I=(e,t,n)=>{let r=e[t];r instanceof Set||(e[t]=r=new Set([r])),r.add(n)},ye=e=>t=>{let n=e[t];n instanceof Set?n.clear():delete e[t]},L=(e,t,n)=>{let r=e[t];r instanceof Set?r.delete(n):r===n&&delete e[t]},R=e=>e instanceof Set?e.size===0:!e,z=new Map;function B(e,t,n,r,i){let a=(t,r)=>{n(e),i(t,r,{watchedPath:e}),r&&e!==r&&V(p.resolve(e,r),k,p.join(e,r))};try{return u(e,{persistent:t.persistent},a)}catch(e){r(e);return}}const V=(e,t,n,r,i)=>{let a=z.get(e);a&&F(a[t],e=>{e(n,r,i)})},H=(e,t,n,r)=>{let{listener:i,errHandler:a,rawEmitter:o}=r,s=z.get(t),c;if(!n.persistent)return c=B(e,n,i,a,o),c?c.close.bind(c):void 0;if(s)I(s,k,i),I(s,A,a),I(s,j,o);else{if(c=B(e,n,V.bind(null,t,k),a,V.bind(null,t,j)),!c)return;c.on(O.ERROR,async n=>{let r=V.bind(null,t,A);if(s&&(s.watcherUnusable=!0),E&&n.code===`EPERM`)try{let t=await te(e,`r`);await t.close(),r(n)}catch{}else r(n)}),s={listeners:i,errHandlers:a,rawEmitters:o,watcher:c},z.set(t,s)}return()=>{L(s,k,i),L(s,A,a),L(s,j,o),R(s.listeners)&&(s.watcher.close(),z.delete(t),M.forEach(ye(s)),s.watcher=void 0,Object.freeze(s))}},U=new Map,be=(e,t,n,r)=>{let{listener:i,rawEmitter:a}=r,o=U.get(t),s=o&&o.options;return s&&(s.persistent<n.persistent||s.interval>n.interval)&&(l(t),o=void 0),o?(I(o,k,i),I(o,j,a)):(o={listeners:i,rawEmitters:a,options:n,watcher:d(t,n,(n,r)=>{F(o.rawEmitters,e=>{e(O.CHANGE,t,{curr:n,prev:r})});let i=n.mtimeMs;(n.size!==r.size||i>r.mtimeMs||i===0)&&F(o.listeners,t=>t(e,n))})},U.set(t,o)),()=>{L(o,k,i),L(o,j,a),R(o.listeners)&&(U.delete(t),l(t),o.options=o.watcher=void 0,Object.freeze(o))}};var xe=class{constructor(e){this.fsw=e,this._boundHandleError=t=>e._handleError(t)}_watchWithNodeFs(e,t){let n=this.fsw.options,r=p.dirname(e),i=p.basename(e),a=this.fsw._getWatchedDir(r);a.add(i);let o=p.resolve(e),s={persistent:n.persistent};t||=w;let c;if(n.usePolling){let r=n.interval!==n.binaryInterval;s.interval=r&&P(i)?n.binaryInterval:n.interval,c=be(e,o,s,{listener:t,rawEmitter:this.fsw._emitRaw})}else c=H(e,o,s,{listener:t,errHandler:this._boundHandleError,rawEmitter:this.fsw._emitRaw});return c}_handleFile(e,t,n){if(this.fsw.closed)return;let r=p.dirname(e),i=p.basename(e),a=this.fsw._getWatchedDir(r),o=t;if(a.has(i))return;let s=async(t,n)=>{if(this.fsw._throttle(_e,e,5)){if(!n||n.mtimeMs===0)try{let n=await h(e);if(this.fsw.closed)return;let r=n.atimeMs,i=n.mtimeMs;if((!r||r<=i||i!==o.mtimeMs)&&this.fsw._emit(O.CHANGE,e,n),(pe||me||he)&&o.ino!==n.ino){this.fsw._closeFile(t),o=n;let r=this._watchWithNodeFs(e,s);r&&this.fsw._addPathCloser(t,r)}else o=n}catch{this.fsw._remove(r,i)}else if(a.has(i)){let t=n.atimeMs,r=n.mtimeMs;(!t||t<=r||r!==o.mtimeMs)&&this.fsw._emit(O.CHANGE,e,n),o=n}}},c=this._watchWithNodeFs(e,s);if(!(n&&this.fsw.options.ignoreInitial)&&this.fsw._isntIgnored(e)){if(!this.fsw._throttle(O.ADD,e,0))return;this.fsw._emit(O.ADD,e,t)}return c}async _handleSymlink(e,t,n,r){if(this.fsw.closed)return;let i=e.fullPath,a=this.fsw._getWatchedDir(t);if(!this.fsw.options.followSymlinks){this.fsw._incrReadyCount();let t;try{t=await m(n)}catch{return this.fsw._emitReady(),!0}return this.fsw.closed?void 0:(a.has(r)?this.fsw._symlinkPaths.get(i)!==t&&(this.fsw._symlinkPaths.set(i,t),this.fsw._emit(O.CHANGE,n,e.stats)):(a.add(r),this.fsw._symlinkPaths.set(i,t),this.fsw._emit(O.ADD,n,e.stats)),this.fsw._emitReady(),!0)}if(this.fsw._symlinkPaths.has(i))return!0;this.fsw._symlinkPaths.set(i,!0)}_handleRead(e,t,n,r,i,a,o){if(e=p.join(e,``),o=this.fsw._throttle(`readdir`,e,1e3),!o)return;let s=this.fsw._getWatchedDir(n.path),c=new Set,l=this.fsw._readdirp(e,{fileFilter:e=>n.filterPath(e),directoryFilter:e=>n.filterDir(e)});if(l)return l.on(de,async o=>{if(this.fsw.closed){l=void 0;return}let u=o.path,d=p.join(e,u);if(c.add(u),!(o.stats.isSymbolicLink()&&await this._handleSymlink(o,e,d,u))){if(this.fsw.closed){l=void 0;return}(u===r||!r&&!s.has(u))&&(this.fsw._incrReadyCount(),d=p.join(i,p.relative(i,d)),this._addToNodeFs(d,t,n,a+1))}}).on(O.ERROR,this._boundHandleError),new Promise((t,u)=>{if(!l)return u();l.once(C,()=>{if(this.fsw.closed){l=void 0;return}let u=o?o.clear():!1;t(void 0),s.getChildren().filter(t=>t!==e&&!c.has(t)).forEach(t=>{this.fsw._remove(e,t)}),l=void 0,u&&this._handleRead(e,!1,n,r,i,a,o)})})}async _handleDir(e,t,n,r,i,a,o){let s=this.fsw._getWatchedDir(p.dirname(e)),c=s.has(p.basename(e));!(n&&this.fsw.options.ignoreInitial)&&!i&&!c&&this.fsw._emit(O.ADD_DIR,e,t),s.add(p.basename(e)),this.fsw._getWatchedDir(e);let l,u,d=this.fsw.options.depth;if((d==null||r<=d)&&!this.fsw._symlinkPaths.has(o)){if(!i&&(await this._handleRead(e,n,a,i,e,r,l),this.fsw.closed))return;u=this._watchWithNodeFs(e,(t,n)=>{n&&n.mtimeMs===0||this._handleRead(t,!1,a,i,e,r,l)})}return u}async _addToNodeFs(e,t,n,r,i){let a=this.fsw._emitReady;if(this.fsw._isIgnored(e)||this.fsw.closed)return a(),!1;let o=this.fsw._getWatchHelpers(e);n&&(o.filterPath=e=>n.filterPath(e),o.filterDir=e=>n.filterDir(e));try{let n=await ve[o.statMethod](o.watchPath);if(this.fsw.closed)return;if(this.fsw._isIgnored(o.watchPath,n))return a(),!1;let s=this.fsw.options.followSymlinks,c;if(n.isDirectory()){let a=p.resolve(e),l=s?await m(e):e;if(this.fsw.closed||(c=await this._handleDir(o.watchPath,n,t,r,i,o,l),this.fsw.closed))return;a!==l&&l!==void 0&&this.fsw._symlinkPaths.set(a,l)}else if(n.isSymbolicLink()){let i=s?await m(e):e;if(this.fsw.closed)return;let a=p.dirname(o.watchPath);if(this.fsw._getWatchedDir(a).add(o.watchPath),this.fsw._emit(O.ADD,o.watchPath,n),c=await this._handleDir(a,n,t,r,e,o,i),this.fsw.closed)return;i!==void 0&&this.fsw._symlinkPaths.set(p.resolve(e),i)}else c=this._handleFile(o.watchPath,n,t);return a(),c&&this.fsw._addPathCloser(e,c),!1}catch(t){if(this.fsw._handleError(t))return a(),e}}};const W=`/`,Se=`//`,G=`.`,Ce=`..`,we=`string`,Te=/\\/g,K=/\/\//,Ee=/\..*\.(sw[px])$|~$|\.subl.*\.tmp/,De=/^\.[/\\]/;function q(e){return Array.isArray(e)?e:[e]}const J=e=>typeof e==`object`&&!!e&&!(e instanceof RegExp);function Oe(e){return typeof e==`function`?e:typeof e==`string`?t=>e===t:e instanceof RegExp?t=>e.test(t):typeof e==`object`&&e?t=>{if(e.path===t)return!0;if(e.recursive){let n=p.relative(e.path,t);return n?!n.startsWith(`..`)&&!p.isAbsolute(n):!1}return!1}:()=>!1}function ke(e){if(typeof e!=`string`)throw Error(`string expected`);e=p.normalize(e),e=e.replace(/\\/g,`/`);let t=!1;e.startsWith(`//`)&&(t=!0);let n=/\/\//;for(;e.match(n);)e=e.replace(n,`/`);return t&&(e=`/`+e),e}function Y(e,t,n){let r=ke(t);for(let t=0;t<e.length;t++){let i=e[t];if(i(r,n))return!0}return!1}function Ae(e,t){if(e==null)throw TypeError(`anymatch: specify first argument`);let n=q(e),r=n.map(e=>Oe(e));return t==null?(e,t)=>Y(r,e,t):Y(r,t)}const X=e=>{let t=q(e).flat();if(!t.every(e=>typeof e===we))throw TypeError(`Non-string provided as watch path: ${t}`);return t.map(Q)},Z=e=>{let t=e.replace(Te,W),n=!1;for(t.startsWith(Se)&&(n=!0);t.match(K);)t=t.replace(K,W);return n&&(t=W+t),t},Q=e=>Z(p.normalize(Z(e))),$=(e=``)=>t=>typeof t==`string`?Q(p.isAbsolute(t)?t:p.join(e,t)):t,je=(e,t)=>p.isAbsolute(e)?e:p.join(t,e),Me=Object.freeze(new Set);var Ne=class{constructor(e,t){this.path=e,this._removeWatcher=t,this.items=new Set}add(e){let{items:t}=this;t&&e!==G&&e!==Ce&&t.add(e)}async remove(e){let{items:t}=this;if(!t||(t.delete(e),t.size>0))return;let n=this.path;try{await ne(n)}catch{this._removeWatcher&&this._removeWatcher(p.dirname(n),p.basename(n))}}has(e){let{items:t}=this;if(t)return t.has(e)}getChildren(){let{items:e}=this;return e?[...e.values()]:[]}dispose(){this.items.clear(),this.path=``,this._removeWatcher=w,this.items=Me,Object.freeze(this)}};const Pe=`stat`,Fe=`lstat`;var Ie=class{constructor(e,t,n){this.fsw=n;let r=e;this.path=e=e.replace(De,``),this.watchPath=r,this.fullWatchPath=p.resolve(r),this.dirParts=[],this.dirParts.forEach(e=>{e.length>1&&e.pop()}),this.followSymlinks=t,this.statMethod=t?Pe:Fe}entryPath(e){return p.join(this.watchPath,p.relative(this.watchPath,e.fullPath))}filterPath(e){let{stats:t}=e;if(t&&t.isSymbolicLink())return this.filterDir(e);let n=this.entryPath(e);return this.fsw._isntIgnored(n,t)&&this.fsw._hasReadPermissions(t)}filterDir(e){return this.fsw._isntIgnored(this.entryPath(e),e.stats)}},Le=class extends re{constructor(e={}){super(),this.closed=!1,this._closers=new Map,this._ignoredPaths=new Set,this._throttled=new Map,this._streams=new Set,this._symlinkPaths=new Map,this._watched=new Map,this._pendingWrites=new Map,this._pendingUnlinks=new Map,this._readyCount=0,this._readyEmitted=!1;let t=e.awaitWriteFinish,n={stabilityThreshold:2e3,pollInterval:100},r={persistent:!0,ignoreInitial:!1,ignorePermissionErrors:!1,interval:100,binaryInterval:300,followSymlinks:!0,usePolling:!1,atomic:!0,...e,ignored:e.ignored?q(e.ignored):q([]),awaitWriteFinish:t===!0?n:typeof t==`object`?{...n,...t}:!1};ge&&(r.usePolling=!0),r.atomic===void 0&&(r.atomic=!r.usePolling);let i=process.env.CHOKIDAR_USEPOLLING;if(i!==void 0){let e=i.toLowerCase();e===`false`||e===`0`?r.usePolling=!1:e===`true`||e===`1`?r.usePolling=!0:r.usePolling=!!e}let a=process.env.CHOKIDAR_INTERVAL;a&&(r.interval=Number.parseInt(a,10));let o=0;this._emitReady=()=>{o++,o>=this._readyCount&&(this._emitReady=w,this._readyEmitted=!0,process.nextTick(()=>this.emit(D.READY)))},this._emitRaw=(...e)=>this.emit(D.RAW,...e),this._boundRemove=this._remove.bind(this),this.options=r,this._nodeFsHandler=new xe(this),Object.freeze(r)}_addIgnoredPath(e){if(J(e)){for(let t of this._ignoredPaths)if(J(t)&&t.path===e.path&&t.recursive===e.recursive)return}this._ignoredPaths.add(e)}_removeIgnoredPath(e){if(this._ignoredPaths.delete(e),typeof e==`string`)for(let t of this._ignoredPaths)J(t)&&t.path===e&&this._ignoredPaths.delete(t)}add(e,t,n){let{cwd:r}=this.options;this.closed=!1,this._closePromise=void 0;let i=X(e);return r&&(i=i.map(e=>{let t=je(e,r);return t})),i.forEach(e=>{this._removeIgnoredPath(e)}),this._userIgnored=void 0,this._readyCount||=0,this._readyCount+=i.length,Promise.all(i.map(async e=>{let r=await this._nodeFsHandler._addToNodeFs(e,!n,void 0,0,t);return r&&this._emitReady(),r})).then(e=>{this.closed||e.forEach(e=>{e&&this.add(p.dirname(e),p.basename(t||e))})}),this}unwatch(e){if(this.closed)return this;let t=X(e),{cwd:n}=this.options;return t.forEach(e=>{!p.isAbsolute(e)&&!this._closers.has(e)&&(n&&(e=p.join(n,e)),e=p.resolve(e)),this._closePath(e),this._addIgnoredPath(e),this._watched.has(e)&&this._addIgnoredPath({path:e,recursive:!0}),this._userIgnored=void 0}),this}close(){if(this._closePromise)return this._closePromise;this.closed=!0,this.removeAllListeners();let e=[];return this._closers.forEach(t=>t.forEach(t=>{let n=t();n instanceof Promise&&e.push(n)})),this._streams.forEach(e=>e.destroy()),this._userIgnored=void 0,this._readyCount=0,this._readyEmitted=!1,this._watched.forEach(e=>e.dispose()),this._closers.clear(),this._watched.clear(),this._streams.clear(),this._symlinkPaths.clear(),this._throttled.clear(),this._closePromise=e.length?Promise.all(e).then(()=>void 0):Promise.resolve(),this._closePromise}getWatched(){let e={};return this._watched.forEach((t,n)=>{let r=this.options.cwd?p.relative(this.options.cwd,n):n,i=r||G;e[i]=t.getChildren().sort()}),e}emitWithAll(e,t){this.emit(e,...t),e!==D.ERROR&&this.emit(D.ALL,e,...t)}async _emit(e,t,n){if(this.closed)return;let r=this.options;E&&(t=p.normalize(t)),r.cwd&&(t=p.relative(r.cwd,t));let i=[t];n!=null&&i.push(n);let a=r.awaitWriteFinish,o;if(a&&(o=this._pendingWrites.get(t)))return o.lastChange=new Date,this;if(r.atomic){if(e===D.UNLINK)return this._pendingUnlinks.set(t,[e,...i]),setTimeout(()=>{this._pendingUnlinks.forEach((e,t)=>{this.emit(...e),this.emit(D.ALL,...e),this._pendingUnlinks.delete(t)})},typeof r.atomic==`number`?r.atomic:100),this;e===D.ADD&&this._pendingUnlinks.has(t)&&(e=D.CHANGE,this._pendingUnlinks.delete(t))}if(a&&(e===D.ADD||e===D.CHANGE)&&this._readyEmitted){let n=(t,n)=>{t?(e=D.ERROR,i[0]=t,this.emitWithAll(e,i)):n&&(i.length>1?i[1]=n:i.push(n),this.emitWithAll(e,i))};return this._awaitWriteFinish(t,a.stabilityThreshold,e,n),this}if(e===D.CHANGE){let e=!this._throttle(D.CHANGE,t,50);if(e)return this}if(r.alwaysStat&&n===void 0&&(e===D.ADD||e===D.ADD_DIR||e===D.CHANGE)){let e=r.cwd?p.join(r.cwd,t):t,n;try{n=await h(e)}catch{}if(!n||this.closed)return;i.push(n)}return this.emitWithAll(e,i),this}_handleError(e){let t=e&&e.code;return e&&t!==`ENOENT`&&t!==`ENOTDIR`&&(!this.options.ignorePermissionErrors||t!==`EPERM`&&t!==`EACCES`)&&this.emit(D.ERROR,e),e||this.closed}_throttle(e,t,n){this._throttled.has(e)||this._throttled.set(e,new Map);let r=this._throttled.get(e);if(!r)throw Error(`invalid throttle`);let i=r.get(t);if(i)return i.count++,!1;let a,o=()=>{let e=r.get(t),n=e?e.count:0;return r.delete(t),clearTimeout(a),e&&clearTimeout(e.timeoutObject),n};a=setTimeout(o,n);let s={timeoutObject:a,clear:o,count:0};return r.set(t,s),s}_incrReadyCount(){return this._readyCount++}_awaitWriteFinish(e,t,n,r){let i=this.options.awaitWriteFinish;if(typeof i!=`object`)return;let a=i.pollInterval,o,s=e;this.options.cwd&&!p.isAbsolute(e)&&(s=p.join(this.options.cwd,e));let l=new Date,u=this._pendingWrites;function d(n){c(s,(i,s)=>{if(i||!u.has(e)){i&&i.code!==`ENOENT`&&r(i);return}let c=Number(new Date);n&&s.size!==n.size&&(u.get(e).lastChange=c);let l=u.get(e),f=c-l.lastChange;f>=t?(u.delete(e),r(void 0,s)):o=setTimeout(d,a,s)})}u.has(e)||(u.set(e,{lastChange:l,cancelWait:()=>(u.delete(e),clearTimeout(o),n)}),o=setTimeout(d,a))}_isIgnored(e,t){if(this.options.atomic&&Ee.test(e))return!0;if(!this._userIgnored){let{cwd:e}=this.options,t=this.options.ignored,n=(t||[]).map($(e)),r=[...this._ignoredPaths],i=[...r.map($(e)),...n];this._userIgnored=Ae(i,void 0)}return this._userIgnored(e,t)}_isntIgnored(e,t){return!this._isIgnored(e,t)}_getWatchHelpers(e){return new Ie(e,this.options.followSymlinks,this)}_getWatchedDir(e){let t=p.resolve(e);return this._watched.has(t)||this._watched.set(t,new Ne(t,this._boundRemove)),this._watched.get(t)}_hasReadPermissions(e){return this.options.ignorePermissionErrors?!0:!!(Number(e.mode)&256)}_remove(e,t,n){let r=p.join(e,t),i=p.resolve(r);if(n??=this._watched.has(r)||this._watched.has(i),!this._throttle(`remove`,r,100))return;!n&&this._watched.size===1&&this.add(e,t,!0);let a=this._getWatchedDir(r),o=a.getChildren();o.forEach(e=>this._remove(r,e));let s=this._getWatchedDir(e),c=s.has(t);s.remove(t),this._symlinkPaths.has(i)&&this._symlinkPaths.delete(i);let l=r;if(this.options.cwd&&(l=p.relative(this.options.cwd,r)),this.options.awaitWriteFinish&&this._pendingWrites.has(l)){let e=this._pendingWrites.get(l).cancelWait();if(e===D.ADD)return}this._watched.delete(r),this._watched.delete(i);let u=n?D.UNLINK_DIR:D.UNLINK;c&&!this._isIgnored(r)&&this._emit(u,r),this._closePath(r)}_closePath(e){this._closeFile(e);let t=p.dirname(e);this._getWatchedDir(t).remove(p.basename(e))}_closeFile(e){let t=this._closers.get(e);t&&(t.forEach(e=>e()),this._closers.delete(e))}_addPathCloser(e,t){if(!t)return;let n=this._closers.get(e);n||(n=[],this._closers.set(e,n)),n.push(t)}_readdirp(e,t){if(this.closed)return;let n={type:D.ALL,alwaysStat:!0,lstat:!0,...t,depth:0},r=ue(e,n);return this._streams.add(r),r.once(fe,()=>{r=void 0}),r.once(C,()=>{r&&(this._streams.delete(r),r=void 0)}),r}};function Re(e,t={}){let n=new Le(t);return n.add(e),n}export{Re as watch};
|
package/dist/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
const e=require(`./cliCore-
|
|
1
|
+
const e=require(`./cliCore-BJMMc7zt.cjs`);exports.CLI=e.CLI;
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{CLI as e}from"./cliCore-
|
|
1
|
+
import{CLI as e}from"./cliCore-DObMBAP8.js";export{e as CLI};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stackone/cli",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.9.0",
|
|
4
4
|
"description": "StackOne Connect CLI tool",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -11,6 +11,7 @@
|
|
|
11
11
|
},
|
|
12
12
|
"files": [
|
|
13
13
|
"dist",
|
|
14
|
+
"CLAUDE_TEMPLATE.md",
|
|
14
15
|
"package.json",
|
|
15
16
|
"README.md"
|
|
16
17
|
],
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
const e=require(`./chunk-CUT6urMc.cjs`),t=e.__toESM(require(`chalk`)),n=e.__toESM(require(`commander`)),r=e.__toESM(require(`inquirer`)),i=e.__toESM(require(`fs`)),a=e.__toESM(require(`os`)),o=e.__toESM(require(`path`)),s=e.__toESM(require(`@stackone/connect-sdk`)),c=e.__toESM(require(`ora`)),l=e.__toESM(require(`url`)),u=(0,o.join)((0,a.homedir)(),`.stackone`),d={profiles:{}},f=()=>{if(!(0,i.existsSync)(u))return d;try{let e=(0,i.readFileSync)(u,`utf-8`);return JSON.parse(e)}catch{return d}},p=e=>{let t=f();return t.profiles[e]},m=e=>{let t=f();return!!t.profiles[e]},h=(e,t)=>{let n=f();n.profiles[e]=t;let r=(0,o.join)((0,a.homedir)());(0,i.existsSync)(r)||(0,i.mkdirSync)(r,{recursive:!0}),(0,i.writeFileSync)(u,JSON.stringify(n,null,2),`utf-8`)},g=()=>{let e=f();return Object.keys(e.profiles)};var _=class{static info(e){console.info(t.default.blue(`ℹ`),e)}static warn(e){console.info(t.default.yellow(`⚠`),e)}static error(e){console.info(t.default.red(`✗`),e)}static success(e){console.info(t.default.green(`✓`),e)}};const v=`https://api.stackone.com`,y=`https://api.stackone-dev.com`,b=`http://localhost:4000`;var x=class{async execute(){try{let{label:e}=await r.default.prompt([{type:`input`,name:`label`,message:`Profile label:`,validate:e=>!e||e.trim().length===0?`The profile label is required`:e.includes(` `)?`The profile label cannot contain spaces`:!0}]);if(m(e)){let{overwrite:t}=await r.default.prompt([{type:`confirm`,name:`overwrite`,message:`Configuration profile with name "${e}" already exists. Do you want to overwrite it?`,default:!1}]);t||(_.info(`Configuration profile initialization cancelled`),process.exit(0))}let{environment:n}=await r.default.prompt([{type:`list`,name:`environment`,message:`Environment:`,choices:[`production`,`staging`,`local`]}]),i;if(n===`production`)i=v;else if(n===`staging`)i=y;else{let{customUrl:e}=await r.default.prompt([{type:`input`,name:`customUrl`,message:`API URL:`,default:b,validate:e=>{if(!e||e.trim().length===0)return`API URL is required`;try{return new URL(e),!0}catch{return`Please enter a valid URL`}}}]);i=e}let{apiKey:a}=await r.default.prompt([{type:`password`,name:`apiKey`,message:`API Key:`,validate:e=>!e||e.trim().length===0?`API Key is required`:!0}]),o={label:e,environment:n,apiUrl:i,apiKey:a};h(e,o),console.info(t.default.green(`\n✓ Configuration profile "${e}" saved successfully`)),process.exit(0)}catch(e){e.isTtyError?_.error(`Prompt couldn't be rendered in the current environment`):_.error(`Failed to initialize configuration profile: ${e}`),process.exit(1)}}},S=class{async execute(e){let{profile:t,fileOrDir:n}=e;if(t||(_.error(`Profile is required. Use --profile <label> to specify a configuration.`),_.info(`Run "stackone init" to create a new configuration profile.`),process.exit(1)),!m(t)){_.error(`Configuration profile "${t}" not found.`),_.info(`Run "stackone init" to create a new configuration profile.`);let e=g();_.info(`Available profiles: ${e.join(`, `)||`none`}`),process.exit(1)}let r=p(t);r||(_.error(`Failed to load configuration profile "${t}".`),process.exit(1)),n||(_.error(`File or directory path is required.`),process.exit(1));try{(0,i.statSync)(n)}catch{_.error(`File or directory not found: ${n}`),process.exit(1)}let a=(0,i.statSync)(n);if(a.isDirectory()){let e=w(n),t=0;e.length===0?(_.error(`No .s1.yaml connector files found in the directory: ${n}.`),process.exit(1)):_.info(`Found ${e.length} connector(s) file(s). Processing...`);for(let n of e){console.info(`
|
|
2
|
-
`);let e=await this.uploadFile(n,r.apiUrl,r.apiKey);e&&t++}console.info(`
|
|
3
|
-
`),_.info(`Upload completed: ${t} of ${e.length} file(s) uploaded successfully.`),process.exit(t>0?0:1)}else n.endsWith(`.s1.yaml`)||(_.error(`Only .s1.yaml files are supported for upload.`),process.exit(1));let o=await this.uploadFile(n,r.apiUrl,r.apiKey);process.exit(o?0:1)}async uploadFile(e,n,r){try{console.info(t.default.blue(`📤 Uploading ${(0,o.basename)(e)}...`));let i=C(e);if(!i)return!1;let a=(0,o.basename)(e),s=new FormData,c=new Blob([i],{type:`application/x-yaml`});s.append(`file`,c,a);let l=Buffer.from(r).toString(`base64`),u=await fetch(`${n}/registry/connectors`,{method:`POST`,headers:{Authorization:`Basic ${l}`},body:s});if(!u.ok){let e=await u.text();return _.error(`Upload failed: ${u.status} - ${u.statusText}`),e&&console.error(t.default.red(e)),!1}let d=await u.json();return console.info(t.default.green(`✓ Successfully uploaded ${a} with connector "${d.provider}@${d.version}"`)),!0}catch(e){return _.error(`Failed to upload file: ${e}`),!1}}};const C=e=>{let n=(0,s.loadConnector)(e),r=(0,s.validateYamlConnector)(n),i=r?.errors??[];if(r.success){let t=e.split(`/`).pop()||e;return _.success(`Connector ${t} is valid!`),n}else i.length>0?(_.error(`Connector ${e} is not valid. Please fix the following errors:\n`),i.forEach(e=>{console.info(t.default.red(`- L${e.line}: ${e.message}`))})):_.error(`Connector ${e} is not valid. Please check the file for errors.`)},w=e=>{let t=[],n=(0,i.readdirSync)(e,{withFileTypes:!0});for(let r of n){let n=(0,o.join)(e,r.name);r.isDirectory()?t.push(...w(n)):r.name.endsWith(`.s1.yaml`)&&t.push(n)}return t};var T=class{async execute(e){let{watchMode:n,fileOrDir:r}=e,a=(0,c.default)(`Watching for changes...`),o=()=>{console.clear(),console.info(t.default.yellow(`Watch mode enabled. Press "q" to quit.
|
|
4
|
-
`))};if(r){try{(0,i.statSync)(r)}catch{_.error(`File or directory not found: ${r}`),process.exit(1)}if(n){let{watch:e}=await Promise.resolve().then(()=>require(`./esm-BrK-ICga.cjs`)),n=await import(`readline`),i=n.createInterface({input:process.stdin,output:process.stdout});process.stdin.setRawMode(!0),process.stdin.resume(),process.stdin.setEncoding(`utf8`);let s=()=>{console.info(t.default.grey(`
|
|
5
|
-
|
|
6
|
-
Exiting watch mode...`)),c.close(),a.stop(),i.close(),process.exit(0)};o(),console.info(t.default.blue(`Running connector(s) validations...`)),await E(r),a.start();let c=e(r||`.`,{ignored:/(^|[/\\])\../,persistent:!0});c.on(`change`,async e=>{o(),a.stop(),console.info(t.default.blue(`File change detected. Running connector(s) validations...`)),await E(r),a.start()}),process.stdin.on(`data`,e=>{e.toString()===`q`&&s()}),process.on(`SIGINT`,()=>{s()})}else await E(r),process.exit(0)}}};const E=async e=>{let t=(0,i.statSync)(e);if(t.isDirectory()){let t=(0,i.readdirSync)(e),n=t.filter(e=>e.endsWith(`.s1.yaml`));if(n.length===0){_.error(`No StackOne connectors found in directory: ${e}. Connector files need to have the extension .s1.yaml.\n`);return}let r=0,a=0;for(let t of n){let n=`${e}/${t}`,o=(0,i.statSync)(n);if(o.isFile()){let e=await D(n);e?r++:a++}}_.info(`Validation completed: ${r} valid, ${a} invalid connectors.\n`)}else t.isFile()&&e.endsWith(`s1.yaml`)?await D(e):_.error(`No StackOne connector found: ${e}. Connector files need to have the extension .s1.yaml.\n`)},D=async e=>{let n=(0,s.loadConnector)(e),r=(0,s.validateYamlConnector)(n),i=r?.errors??[];if(r.success){let t=e.split(`/`).pop()||e;return _.success(`Connector ${t} is valid!\n`),!0}else if(i.length>0)return _.error(`Connector ${e} is not valid. Please fix the following errors:\n`),i.forEach(e=>{console.info(t.default.red(`- L${e.line}: ${e.message}`))}),console.info(`
|
|
7
|
-
`),!1;else return _.error(`Connector ${e} is not valid. Please check the file for errors.`),!1},O=()=>{try{let e=(0,l.fileURLToPath)(require(`url`).pathToFileURL(__filename).href),t=(0,o.dirname)(e),n=(0,o.join)(t,`..`,`package.json`),r=JSON.parse((0,i.readFileSync)(n,`utf8`));return r.version}catch{return`unknown`}};var k=class{constructor(e=new n.Command,t=O()){this.program=e,this.version=t,this.setupProgram(),this.registerCommands()}setupProgram(){this.program.name(`stackone`).description(`StackOne CLI`).version(this.version)}registerCommands(){let e=new x,r=new S,i=new T;this.program.configureOutput({writeOut:e=>process.stdout.write(e),writeErr:e=>process.stderr.write(e),outputError:(e,n)=>{n(t.default.red(e))}}),this.program.command(`init`).description(`Initialize & create a StackOne CLI configuration profile`).action(()=>{e.execute()}),this.program.command(`push`).option(`-p, --profile <label>`,`Configuration profile to use`).addArgument(new n.Argument(`<path>`,`Connector file or directory to push`)).description(`Push a connector to the StackOne registry`).action((e,t)=>{r.execute({profile:t.profile,fileOrDir:e})}),this.program.command(`validate`).option(`-w, --watch`,`Run in watch mode`).addArgument(new n.Argument(`<path>`,`Connector file or directory with connectors to validate`)).description(`Validate a StackOne connector`).action((e,t)=>{i.execute({watchMode:t.watch,fileOrDir:e})}),this.program.command(`version`).description(`Show version information`).action(()=>{console.info(`${t.default.greenBright(`StackOne`)} ${t.default.grey(`CLI`)} ${t.default.whiteBright(this.version)}`),process.exit(0)})}run(){this.program.parse(process.argv)}};Object.defineProperty(exports,`CLI`,{enumerable:!0,get:function(){return k}});
|
package/dist/cliCore-CYhcPSJT.js
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import e from"chalk";import{Argument as t,Command as n}from"commander";import r from"inquirer";import{existsSync as i,mkdirSync as a,readFileSync as o,readdirSync as s,statSync as c,writeFileSync as l}from"fs";import{homedir as u}from"os";import{basename as d,dirname as f,join as p}from"path";import{loadConnector as m,validateYamlConnector as h}from"@stackone/connect-sdk";import g from"ora";import{fileURLToPath as _}from"url";const v=p(u(),`.stackone`),y={profiles:{}},b=()=>{if(!i(v))return y;try{let e=o(v,`utf-8`);return JSON.parse(e)}catch{return y}},x=e=>{let t=b();return t.profiles[e]},S=e=>{let t=b();return!!t.profiles[e]},C=(e,t)=>{let n=b();n.profiles[e]=t;let r=p(u());i(r)||a(r,{recursive:!0}),l(v,JSON.stringify(n,null,2),`utf-8`)},w=()=>{let e=b();return Object.keys(e.profiles)};var T=class{static info(t){console.info(e.blue(`ℹ`),t)}static warn(t){console.info(e.yellow(`⚠`),t)}static error(t){console.info(e.red(`✗`),t)}static success(t){console.info(e.green(`✓`),t)}};const E=`https://api.stackone.com`,D=`https://api.stackone-dev.com`,O=`http://localhost:4000`;var k=class{async execute(){try{let{label:t}=await r.prompt([{type:`input`,name:`label`,message:`Profile label:`,validate:e=>!e||e.trim().length===0?`The profile label is required`:e.includes(` `)?`The profile label cannot contain spaces`:!0}]);if(S(t)){let{overwrite:e}=await r.prompt([{type:`confirm`,name:`overwrite`,message:`Configuration profile with name "${t}" already exists. Do you want to overwrite it?`,default:!1}]);e||(T.info(`Configuration profile initialization cancelled`),process.exit(0))}let{environment:n}=await r.prompt([{type:`list`,name:`environment`,message:`Environment:`,choices:[`production`,`staging`,`local`]}]),i;if(n===`production`)i=E;else if(n===`staging`)i=D;else{let{customUrl:e}=await r.prompt([{type:`input`,name:`customUrl`,message:`API URL:`,default:O,validate:e=>{if(!e||e.trim().length===0)return`API URL is required`;try{return new URL(e),!0}catch{return`Please enter a valid URL`}}}]);i=e}let{apiKey:a}=await r.prompt([{type:`password`,name:`apiKey`,message:`API Key:`,validate:e=>!e||e.trim().length===0?`API Key is required`:!0}]),o={label:t,environment:n,apiUrl:i,apiKey:a};C(t,o),console.info(e.green(`\n✓ Configuration profile "${t}" saved successfully`)),process.exit(0)}catch(e){e.isTtyError?T.error(`Prompt couldn't be rendered in the current environment`):T.error(`Failed to initialize configuration profile: ${e}`),process.exit(1)}}},A=class{async execute(e){let{profile:t,fileOrDir:n}=e;if(t||(T.error(`Profile is required. Use --profile <label> to specify a configuration.`),T.info(`Run "stackone init" to create a new configuration profile.`),process.exit(1)),!S(t)){T.error(`Configuration profile "${t}" not found.`),T.info(`Run "stackone init" to create a new configuration profile.`);let e=w();T.info(`Available profiles: ${e.join(`, `)||`none`}`),process.exit(1)}let r=x(t);r||(T.error(`Failed to load configuration profile "${t}".`),process.exit(1)),n||(T.error(`File or directory path is required.`),process.exit(1));try{c(n)}catch{T.error(`File or directory not found: ${n}`),process.exit(1)}let i=c(n);if(i.isDirectory()){let e=M(n),t=0;e.length===0?(T.error(`No .s1.yaml connector files found in the directory: ${n}.`),process.exit(1)):T.info(`Found ${e.length} connector(s) file(s). Processing...`);for(let n of e){console.info(`
|
|
2
|
-
`);let e=await this.uploadFile(n,r.apiUrl,r.apiKey);e&&t++}console.info(`
|
|
3
|
-
`),T.info(`Upload completed: ${t} of ${e.length} file(s) uploaded successfully.`),process.exit(t>0?0:1)}else n.endsWith(`.s1.yaml`)||(T.error(`Only .s1.yaml files are supported for upload.`),process.exit(1));let a=await this.uploadFile(n,r.apiUrl,r.apiKey);process.exit(a?0:1)}async uploadFile(t,n,r){try{console.info(e.blue(`📤 Uploading ${d(t)}...`));let i=j(t);if(!i)return!1;let a=d(t),o=new FormData,s=new Blob([i],{type:`application/x-yaml`});o.append(`file`,s,a);let c=Buffer.from(r).toString(`base64`),l=await fetch(`${n}/registry/connectors`,{method:`POST`,headers:{Authorization:`Basic ${c}`},body:o});if(!l.ok){let t=await l.text();return T.error(`Upload failed: ${l.status} - ${l.statusText}`),t&&console.error(e.red(t)),!1}let u=await l.json();return console.info(e.green(`✓ Successfully uploaded ${a} with connector "${u.provider}@${u.version}"`)),!0}catch(e){return T.error(`Failed to upload file: ${e}`),!1}}};const j=t=>{let n=m(t),r=h(n),i=r?.errors??[];if(r.success){let e=t.split(`/`).pop()||t;return T.success(`Connector ${e} is valid!`),n}else i.length>0?(T.error(`Connector ${t} is not valid. Please fix the following errors:\n`),i.forEach(t=>{console.info(e.red(`- L${t.line}: ${t.message}`))})):T.error(`Connector ${t} is not valid. Please check the file for errors.`)},M=e=>{let t=[],n=s(e,{withFileTypes:!0});for(let r of n){let n=p(e,r.name);r.isDirectory()?t.push(...M(n)):r.name.endsWith(`.s1.yaml`)&&t.push(n)}return t};var N=class{async execute(t){let{watchMode:n,fileOrDir:r}=t,i=g(`Watching for changes...`),a=()=>{console.clear(),console.info(e.yellow(`Watch mode enabled. Press "q" to quit.
|
|
4
|
-
`))};if(r){try{c(r)}catch{T.error(`File or directory not found: ${r}`),process.exit(1)}if(n){let{watch:t}=await import(`./esm-D_hUWJ1V.js`),n=await import(`readline`),o=n.createInterface({input:process.stdin,output:process.stdout});process.stdin.setRawMode(!0),process.stdin.resume(),process.stdin.setEncoding(`utf8`);let s=()=>{console.info(e.grey(`
|
|
5
|
-
|
|
6
|
-
Exiting watch mode...`)),c.close(),i.stop(),o.close(),process.exit(0)};a(),console.info(e.blue(`Running connector(s) validations...`)),await P(r),i.start();let c=t(r||`.`,{ignored:/(^|[/\\])\../,persistent:!0});c.on(`change`,async t=>{a(),i.stop(),console.info(e.blue(`File change detected. Running connector(s) validations...`)),await P(r),i.start()}),process.stdin.on(`data`,e=>{e.toString()===`q`&&s()}),process.on(`SIGINT`,()=>{s()})}else await P(r),process.exit(0)}}};const P=async e=>{let t=c(e);if(t.isDirectory()){let t=s(e),n=t.filter(e=>e.endsWith(`.s1.yaml`));if(n.length===0){T.error(`No StackOne connectors found in directory: ${e}. Connector files need to have the extension .s1.yaml.\n`);return}let r=0,i=0;for(let t of n){let n=`${e}/${t}`,a=c(n);if(a.isFile()){let e=await F(n);e?r++:i++}}T.info(`Validation completed: ${r} valid, ${i} invalid connectors.\n`)}else t.isFile()&&e.endsWith(`s1.yaml`)?await F(e):T.error(`No StackOne connector found: ${e}. Connector files need to have the extension .s1.yaml.\n`)},F=async t=>{let n=m(t),r=h(n),i=r?.errors??[];if(r.success){let e=t.split(`/`).pop()||t;return T.success(`Connector ${e} is valid!\n`),!0}else if(i.length>0)return T.error(`Connector ${t} is not valid. Please fix the following errors:\n`),i.forEach(t=>{console.info(e.red(`- L${t.line}: ${t.message}`))}),console.info(`
|
|
7
|
-
`),!1;else return T.error(`Connector ${t} is not valid. Please check the file for errors.`),!1},I=()=>{try{let e=_(import.meta.url),t=f(e),n=p(t,`..`,`package.json`),r=JSON.parse(o(n,`utf8`));return r.version}catch{return`unknown`}};var L=class{constructor(e=new n,t=I()){this.program=e,this.version=t,this.setupProgram(),this.registerCommands()}setupProgram(){this.program.name(`stackone`).description(`StackOne CLI`).version(this.version)}registerCommands(){let n=new k,r=new A,i=new N;this.program.configureOutput({writeOut:e=>process.stdout.write(e),writeErr:e=>process.stderr.write(e),outputError:(t,n)=>{n(e.red(t))}}),this.program.command(`init`).description(`Initialize & create a StackOne CLI configuration profile`).action(()=>{n.execute()}),this.program.command(`push`).option(`-p, --profile <label>`,`Configuration profile to use`).addArgument(new t(`<path>`,`Connector file or directory to push`)).description(`Push a connector to the StackOne registry`).action((e,t)=>{r.execute({profile:t.profile,fileOrDir:e})}),this.program.command(`validate`).option(`-w, --watch`,`Run in watch mode`).addArgument(new t(`<path>`,`Connector file or directory with connectors to validate`)).description(`Validate a StackOne connector`).action((e,t)=>{i.execute({watchMode:t.watch,fileOrDir:e})}),this.program.command(`version`).description(`Show version information`).action(()=>{console.info(`${e.greenBright(`StackOne`)} ${e.grey(`CLI`)} ${e.whiteBright(this.version)}`),process.exit(0)})}run(){this.program.parse(process.argv)}};export{L as CLI};
|
package/dist/esm-D_hUWJ1V.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{stat as e,unwatchFile as t,watch as n,watchFile as r}from"fs";import{type as i}from"os";import*as a from"path";import{lstat as o,open as s,readdir as c,realpath as l,stat as u}from"fs/promises";import{EventEmitter as d}from"events";import{lstat as f,readdir as p,realpath as ee,stat as te}from"node:fs/promises";import{Readable as ne}from"node:stream";import{join as re,relative as ie,resolve as m,sep as ae}from"node:path";const h={FILE_TYPE:`files`,DIR_TYPE:`directories`,FILE_DIR_TYPE:`files_directories`,EVERYTHING_TYPE:`all`},g={root:`.`,fileFilter:e=>!0,directoryFilter:e=>!0,type:h.FILE_TYPE,lstat:!1,depth:2147483648,alwaysStat:!1,highWaterMark:4096};Object.freeze(g);const _=`READDIRP_RECURSIVE_ERROR`,v=new Set([`ENOENT`,`EPERM`,`EACCES`,`ELOOP`,_]),y=[h.DIR_TYPE,h.EVERYTHING_TYPE,h.FILE_DIR_TYPE,h.FILE_TYPE],oe=new Set([h.DIR_TYPE,h.EVERYTHING_TYPE,h.FILE_DIR_TYPE]),se=new Set([h.EVERYTHING_TYPE,h.FILE_DIR_TYPE,h.FILE_TYPE]),ce=e=>v.has(e.code),b=process.platform===`win32`,x=e=>!0,S=e=>{if(e===void 0)return x;if(typeof e==`function`)return e;if(typeof e==`string`){let t=e.trim();return e=>e.basename===t}if(Array.isArray(e)){let t=e.map(e=>e.trim());return e=>t.some(t=>e.basename===t)}return x};var le=class extends ne{constructor(e={}){super({objectMode:!0,autoDestroy:!0,highWaterMark:e.highWaterMark});let t={...g,...e},{root:n,type:r}=t;this._fileFilter=S(t.fileFilter),this._directoryFilter=S(t.directoryFilter);let i=t.lstat?f:te;b?this._stat=e=>i(e,{bigint:!0}):this._stat=i,this._maxDepth=t.depth??g.depth,this._wantsDir=r?oe.has(r):!1,this._wantsFile=r?se.has(r):!1,this._wantsEverything=r===h.EVERYTHING_TYPE,this._root=m(n),this._isDirent=!t.alwaysStat,this._statsProp=this._isDirent?`dirent`:`stats`,this._rdOptions={encoding:`utf8`,withFileTypes:this._isDirent},this.parents=[this._exploreDir(n,1)],this.reading=!1,this.parent=void 0}async _read(e){if(!this.reading){this.reading=!0;try{for(;!this.destroyed&&e>0;){let t=this.parent,n=t&&t.files;if(n&&n.length>0){let{path:r,depth:i}=t,a=n.splice(0,e).map(e=>this._formatEntry(e,r)),o=await Promise.all(a);for(let t of o){if(!t)continue;if(this.destroyed)return;let n=await this._getEntryType(t);n===`directory`&&this._directoryFilter(t)?(i<=this._maxDepth&&this.parents.push(this._exploreDir(t.fullPath,i+1)),this._wantsDir&&(this.push(t),e--)):(n===`file`||this._includeAsFile(t))&&this._fileFilter(t)&&this._wantsFile&&(this.push(t),e--)}}else{let e=this.parents.pop();if(!e){this.push(null);break}if(this.parent=await e,this.destroyed)return}}}catch(e){this.destroy(e)}finally{this.reading=!1}}}async _exploreDir(e,t){let n;try{n=await p(e,this._rdOptions)}catch(e){this._onError(e)}return{files:n,depth:t,path:e}}async _formatEntry(e,t){let n,r=this._isDirent?e.name:e;try{let i=m(re(t,r));n={path:ie(this._root,i),fullPath:i,basename:r},n[this._statsProp]=this._isDirent?e:await this._stat(i)}catch(e){this._onError(e);return}return n}_onError(e){ce(e)&&!this.destroyed?this.emit(`warn`,e):this.destroy(e)}async _getEntryType(e){if(!e&&this._statsProp in e)return``;let t=e[this._statsProp];if(t.isFile())return`file`;if(t.isDirectory())return`directory`;if(t&&t.isSymbolicLink()){let t=e.fullPath;try{let e=await ee(t),n=await f(e);if(n.isFile())return`file`;if(n.isDirectory()){let n=e.length;if(t.startsWith(e)&&t.substr(n,1)===ae){let n=Error(`Circular symlink detected: "${t}" points to "${e}"`);return n.code=_,this._onError(n)}return`directory`}}catch(e){return this._onError(e),``}}}_includeAsFile(e){let t=e&&e[this._statsProp];return t&&this._wantsEverything&&!t.isDirectory()}};function ue(e,t={}){let n=t.entryType||t.type;if(n===`both`&&(n=h.FILE_DIR_TYPE),n&&(t.type=n),e){if(typeof e!=`string`)throw TypeError(`readdirp: root argument must be a string. Usage: readdirp(root, options)`);if(n&&!y.includes(n))throw Error(`readdirp: Invalid type passed. Use one of ${y.join(`, `)}`)}else throw Error(`readdirp: root argument is required. Usage: readdirp(root, options)`);return t.root=e,new le(t)}const de=`data`,C=`end`,fe=`close`,w=()=>{},T=process.platform,E=T===`win32`,pe=T===`darwin`,me=T===`linux`,he=T===`freebsd`,ge=i()===`OS400`,D={ALL:`all`,READY:`ready`,ADD:`add`,CHANGE:`change`,ADD_DIR:`addDir`,UNLINK:`unlink`,UNLINK_DIR:`unlinkDir`,RAW:`raw`,ERROR:`error`},O=D,_e=`watch`,ve={lstat:o,stat:u},k=`listeners`,A=`errHandlers`,j=`rawEmitters`,M=[k,A,j],N=new Set(`3dm.3ds.3g2.3gp.7z.a.aac.adp.afdesign.afphoto.afpub.ai.aif.aiff.alz.ape.apk.appimage.ar.arj.asf.au.avi.bak.baml.bh.bin.bk.bmp.btif.bz2.bzip2.cab.caf.cgm.class.cmx.cpio.cr2.cur.dat.dcm.deb.dex.djvu.dll.dmg.dng.doc.docm.docx.dot.dotm.dra.DS_Store.dsk.dts.dtshd.dvb.dwg.dxf.ecelp4800.ecelp7470.ecelp9600.egg.eol.eot.epub.exe.f4v.fbs.fh.fla.flac.flatpak.fli.flv.fpx.fst.fvt.g3.gh.gif.graffle.gz.gzip.h261.h263.h264.icns.ico.ief.img.ipa.iso.jar.jpeg.jpg.jpgv.jpm.jxr.key.ktx.lha.lib.lvp.lz.lzh.lzma.lzo.m3u.m4a.m4v.mar.mdi.mht.mid.midi.mj2.mka.mkv.mmr.mng.mobi.mov.movie.mp3.mp4.mp4a.mpeg.mpg.mpga.mxu.nef.npx.numbers.nupkg.o.odp.ods.odt.oga.ogg.ogv.otf.ott.pages.pbm.pcx.pdb.pdf.pea.pgm.pic.png.pnm.pot.potm.potx.ppa.ppam.ppm.pps.ppsm.ppsx.ppt.pptm.pptx.psd.pya.pyc.pyo.pyv.qt.rar.ras.raw.resources.rgb.rip.rlc.rmf.rmvb.rpm.rtf.rz.s3m.s7z.scpt.sgi.shar.snap.sil.sketch.slk.smv.snk.so.stl.suo.sub.swf.tar.tbz.tbz2.tga.tgz.thmx.tif.tiff.tlz.ttc.ttf.txz.udf.uvh.uvi.uvm.uvp.uvs.uvu.viv.vob.war.wav.wax.wbmp.wdp.weba.webm.webp.whl.wim.wm.wma.wmv.wmx.woff.woff2.wrm.wvx.xbm.xif.xla.xlam.xls.xlsb.xlsm.xlsx.xlt.xltm.xltx.xm.xmind.xpi.xpm.xwd.xz.z.zip.zipx`.split(`.`)),P=e=>N.has(a.extname(e).slice(1).toLowerCase()),F=(e,t)=>{e instanceof Set?e.forEach(t):t(e)},I=(e,t,n)=>{let r=e[t];r instanceof Set||(e[t]=r=new Set([r])),r.add(n)},ye=e=>t=>{let n=e[t];n instanceof Set?n.clear():delete e[t]},L=(e,t,n)=>{let r=e[t];r instanceof Set?r.delete(n):r===n&&delete e[t]},R=e=>e instanceof Set?e.size===0:!e,z=new Map;function B(e,t,r,i,o){let s=(t,n)=>{r(e),o(t,n,{watchedPath:e}),n&&e!==n&&V(a.resolve(e,n),k,a.join(e,n))};try{return n(e,{persistent:t.persistent},s)}catch(e){i(e);return}}const V=(e,t,n,r,i)=>{let a=z.get(e);a&&F(a[t],e=>{e(n,r,i)})},be=(e,t,n,r)=>{let{listener:i,errHandler:a,rawEmitter:o}=r,c=z.get(t),l;if(!n.persistent)return l=B(e,n,i,a,o),l?l.close.bind(l):void 0;if(c)I(c,k,i),I(c,A,a),I(c,j,o);else{if(l=B(e,n,V.bind(null,t,k),a,V.bind(null,t,j)),!l)return;l.on(O.ERROR,async n=>{let r=V.bind(null,t,A);if(c&&(c.watcherUnusable=!0),E&&n.code===`EPERM`)try{let t=await s(e,`r`);await t.close(),r(n)}catch{}else r(n)}),c={listeners:i,errHandlers:a,rawEmitters:o,watcher:l},z.set(t,c)}return()=>{L(c,k,i),L(c,A,a),L(c,j,o),R(c.listeners)&&(c.watcher.close(),z.delete(t),M.forEach(ye(c)),c.watcher=void 0,Object.freeze(c))}},H=new Map,xe=(e,n,i,a)=>{let{listener:o,rawEmitter:s}=a,c=H.get(n),l=c&&c.options;return l&&(l.persistent<i.persistent||l.interval>i.interval)&&(t(n),c=void 0),c?(I(c,k,o),I(c,j,s)):(c={listeners:o,rawEmitters:s,options:i,watcher:r(n,i,(t,r)=>{F(c.rawEmitters,e=>{e(O.CHANGE,n,{curr:t,prev:r})});let i=t.mtimeMs;(t.size!==r.size||i>r.mtimeMs||i===0)&&F(c.listeners,n=>n(e,t))})},H.set(n,c)),()=>{L(c,k,o),L(c,j,s),R(c.listeners)&&(H.delete(n),t(n),c.options=c.watcher=void 0,Object.freeze(c))}};var Se=class{constructor(e){this.fsw=e,this._boundHandleError=t=>e._handleError(t)}_watchWithNodeFs(e,t){let n=this.fsw.options,r=a.dirname(e),i=a.basename(e),o=this.fsw._getWatchedDir(r);o.add(i);let s=a.resolve(e),c={persistent:n.persistent};t||=w;let l;if(n.usePolling){let r=n.interval!==n.binaryInterval;c.interval=r&&P(i)?n.binaryInterval:n.interval,l=xe(e,s,c,{listener:t,rawEmitter:this.fsw._emitRaw})}else l=be(e,s,c,{listener:t,errHandler:this._boundHandleError,rawEmitter:this.fsw._emitRaw});return l}_handleFile(e,t,n){if(this.fsw.closed)return;let r=a.dirname(e),i=a.basename(e),o=this.fsw._getWatchedDir(r),s=t;if(o.has(i))return;let c=async(t,n)=>{if(this.fsw._throttle(_e,e,5)){if(!n||n.mtimeMs===0)try{let n=await u(e);if(this.fsw.closed)return;let r=n.atimeMs,i=n.mtimeMs;if((!r||r<=i||i!==s.mtimeMs)&&this.fsw._emit(O.CHANGE,e,n),(pe||me||he)&&s.ino!==n.ino){this.fsw._closeFile(t),s=n;let r=this._watchWithNodeFs(e,c);r&&this.fsw._addPathCloser(t,r)}else s=n}catch{this.fsw._remove(r,i)}else if(o.has(i)){let t=n.atimeMs,r=n.mtimeMs;(!t||t<=r||r!==s.mtimeMs)&&this.fsw._emit(O.CHANGE,e,n),s=n}}},l=this._watchWithNodeFs(e,c);if(!(n&&this.fsw.options.ignoreInitial)&&this.fsw._isntIgnored(e)){if(!this.fsw._throttle(O.ADD,e,0))return;this.fsw._emit(O.ADD,e,t)}return l}async _handleSymlink(e,t,n,r){if(this.fsw.closed)return;let i=e.fullPath,a=this.fsw._getWatchedDir(t);if(!this.fsw.options.followSymlinks){this.fsw._incrReadyCount();let t;try{t=await l(n)}catch{return this.fsw._emitReady(),!0}return this.fsw.closed?void 0:(a.has(r)?this.fsw._symlinkPaths.get(i)!==t&&(this.fsw._symlinkPaths.set(i,t),this.fsw._emit(O.CHANGE,n,e.stats)):(a.add(r),this.fsw._symlinkPaths.set(i,t),this.fsw._emit(O.ADD,n,e.stats)),this.fsw._emitReady(),!0)}if(this.fsw._symlinkPaths.has(i))return!0;this.fsw._symlinkPaths.set(i,!0)}_handleRead(e,t,n,r,i,o,s){if(e=a.join(e,``),s=this.fsw._throttle(`readdir`,e,1e3),!s)return;let c=this.fsw._getWatchedDir(n.path),l=new Set,u=this.fsw._readdirp(e,{fileFilter:e=>n.filterPath(e),directoryFilter:e=>n.filterDir(e)});if(u)return u.on(de,async s=>{if(this.fsw.closed){u=void 0;return}let d=s.path,f=a.join(e,d);if(l.add(d),!(s.stats.isSymbolicLink()&&await this._handleSymlink(s,e,f,d))){if(this.fsw.closed){u=void 0;return}(d===r||!r&&!c.has(d))&&(this.fsw._incrReadyCount(),f=a.join(i,a.relative(i,f)),this._addToNodeFs(f,t,n,o+1))}}).on(O.ERROR,this._boundHandleError),new Promise((t,a)=>{if(!u)return a();u.once(C,()=>{if(this.fsw.closed){u=void 0;return}let a=s?s.clear():!1;t(void 0),c.getChildren().filter(t=>t!==e&&!l.has(t)).forEach(t=>{this.fsw._remove(e,t)}),u=void 0,a&&this._handleRead(e,!1,n,r,i,o,s)})})}async _handleDir(e,t,n,r,i,o,s){let c=this.fsw._getWatchedDir(a.dirname(e)),l=c.has(a.basename(e));!(n&&this.fsw.options.ignoreInitial)&&!i&&!l&&this.fsw._emit(O.ADD_DIR,e,t),c.add(a.basename(e)),this.fsw._getWatchedDir(e);let u,d,f=this.fsw.options.depth;if((f==null||r<=f)&&!this.fsw._symlinkPaths.has(s)){if(!i&&(await this._handleRead(e,n,o,i,e,r,u),this.fsw.closed))return;d=this._watchWithNodeFs(e,(t,n)=>{n&&n.mtimeMs===0||this._handleRead(t,!1,o,i,e,r,u)})}return d}async _addToNodeFs(e,t,n,r,i){let o=this.fsw._emitReady;if(this.fsw._isIgnored(e)||this.fsw.closed)return o(),!1;let s=this.fsw._getWatchHelpers(e);n&&(s.filterPath=e=>n.filterPath(e),s.filterDir=e=>n.filterDir(e));try{let n=await ve[s.statMethod](s.watchPath);if(this.fsw.closed)return;if(this.fsw._isIgnored(s.watchPath,n))return o(),!1;let c=this.fsw.options.followSymlinks,u;if(n.isDirectory()){let o=a.resolve(e),d=c?await l(e):e;if(this.fsw.closed||(u=await this._handleDir(s.watchPath,n,t,r,i,s,d),this.fsw.closed))return;o!==d&&d!==void 0&&this.fsw._symlinkPaths.set(o,d)}else if(n.isSymbolicLink()){let i=c?await l(e):e;if(this.fsw.closed)return;let o=a.dirname(s.watchPath);if(this.fsw._getWatchedDir(o).add(s.watchPath),this.fsw._emit(O.ADD,s.watchPath,n),u=await this._handleDir(o,n,t,r,e,s,i),this.fsw.closed)return;i!==void 0&&this.fsw._symlinkPaths.set(a.resolve(e),i)}else u=this._handleFile(s.watchPath,n,t);return o(),u&&this.fsw._addPathCloser(e,u),!1}catch(t){if(this.fsw._handleError(t))return o(),e}}};const U=`/`,Ce=`//`,W=`.`,we=`..`,Te=`string`,Ee=/\\/g,G=/\/\//,De=/\..*\.(sw[px])$|~$|\.subl.*\.tmp/,Oe=/^\.[/\\]/;function K(e){return Array.isArray(e)?e:[e]}const q=e=>typeof e==`object`&&!!e&&!(e instanceof RegExp);function ke(e){return typeof e==`function`?e:typeof e==`string`?t=>e===t:e instanceof RegExp?t=>e.test(t):typeof e==`object`&&e?t=>{if(e.path===t)return!0;if(e.recursive){let n=a.relative(e.path,t);return n?!n.startsWith(`..`)&&!a.isAbsolute(n):!1}return!1}:()=>!1}function Ae(e){if(typeof e!=`string`)throw Error(`string expected`);e=a.normalize(e),e=e.replace(/\\/g,`/`);let t=!1;e.startsWith(`//`)&&(t=!0);let n=/\/\//;for(;e.match(n);)e=e.replace(n,`/`);return t&&(e=`/`+e),e}function J(e,t,n){let r=Ae(t);for(let t=0;t<e.length;t++){let i=e[t];if(i(r,n))return!0}return!1}function je(e,t){if(e==null)throw TypeError(`anymatch: specify first argument`);let n=K(e),r=n.map(e=>ke(e));return t==null?(e,t)=>J(r,e,t):J(r,t)}const Y=e=>{let t=K(e).flat();if(!t.every(e=>typeof e===Te))throw TypeError(`Non-string provided as watch path: ${t}`);return t.map(Z)},X=e=>{let t=e.replace(Ee,U),n=!1;for(t.startsWith(Ce)&&(n=!0);t.match(G);)t=t.replace(G,U);return n&&(t=U+t),t},Z=e=>X(a.normalize(X(e))),Q=(e=``)=>t=>typeof t==`string`?Z(a.isAbsolute(t)?t:a.join(e,t)):t,Me=(e,t)=>a.isAbsolute(e)?e:a.join(t,e),Ne=Object.freeze(new Set);var $=class{constructor(e,t){this.path=e,this._removeWatcher=t,this.items=new Set}add(e){let{items:t}=this;t&&e!==W&&e!==we&&t.add(e)}async remove(e){let{items:t}=this;if(!t||(t.delete(e),t.size>0))return;let n=this.path;try{await c(n)}catch{this._removeWatcher&&this._removeWatcher(a.dirname(n),a.basename(n))}}has(e){let{items:t}=this;if(t)return t.has(e)}getChildren(){let{items:e}=this;return e?[...e.values()]:[]}dispose(){this.items.clear(),this.path=``,this._removeWatcher=w,this.items=Ne,Object.freeze(this)}};const Pe=`stat`,Fe=`lstat`;var Ie=class{constructor(e,t,n){this.fsw=n;let r=e;this.path=e=e.replace(Oe,``),this.watchPath=r,this.fullWatchPath=a.resolve(r),this.dirParts=[],this.dirParts.forEach(e=>{e.length>1&&e.pop()}),this.followSymlinks=t,this.statMethod=t?Pe:Fe}entryPath(e){return a.join(this.watchPath,a.relative(this.watchPath,e.fullPath))}filterPath(e){let{stats:t}=e;if(t&&t.isSymbolicLink())return this.filterDir(e);let n=this.entryPath(e);return this.fsw._isntIgnored(n,t)&&this.fsw._hasReadPermissions(t)}filterDir(e){return this.fsw._isntIgnored(this.entryPath(e),e.stats)}},Le=class extends d{constructor(e={}){super(),this.closed=!1,this._closers=new Map,this._ignoredPaths=new Set,this._throttled=new Map,this._streams=new Set,this._symlinkPaths=new Map,this._watched=new Map,this._pendingWrites=new Map,this._pendingUnlinks=new Map,this._readyCount=0,this._readyEmitted=!1;let t=e.awaitWriteFinish,n={stabilityThreshold:2e3,pollInterval:100},r={persistent:!0,ignoreInitial:!1,ignorePermissionErrors:!1,interval:100,binaryInterval:300,followSymlinks:!0,usePolling:!1,atomic:!0,...e,ignored:e.ignored?K(e.ignored):K([]),awaitWriteFinish:t===!0?n:typeof t==`object`?{...n,...t}:!1};ge&&(r.usePolling=!0),r.atomic===void 0&&(r.atomic=!r.usePolling);let i=process.env.CHOKIDAR_USEPOLLING;if(i!==void 0){let e=i.toLowerCase();e===`false`||e===`0`?r.usePolling=!1:e===`true`||e===`1`?r.usePolling=!0:r.usePolling=!!e}let a=process.env.CHOKIDAR_INTERVAL;a&&(r.interval=Number.parseInt(a,10));let o=0;this._emitReady=()=>{o++,o>=this._readyCount&&(this._emitReady=w,this._readyEmitted=!0,process.nextTick(()=>this.emit(D.READY)))},this._emitRaw=(...e)=>this.emit(D.RAW,...e),this._boundRemove=this._remove.bind(this),this.options=r,this._nodeFsHandler=new Se(this),Object.freeze(r)}_addIgnoredPath(e){if(q(e)){for(let t of this._ignoredPaths)if(q(t)&&t.path===e.path&&t.recursive===e.recursive)return}this._ignoredPaths.add(e)}_removeIgnoredPath(e){if(this._ignoredPaths.delete(e),typeof e==`string`)for(let t of this._ignoredPaths)q(t)&&t.path===e&&this._ignoredPaths.delete(t)}add(e,t,n){let{cwd:r}=this.options;this.closed=!1,this._closePromise=void 0;let i=Y(e);return r&&(i=i.map(e=>{let t=Me(e,r);return t})),i.forEach(e=>{this._removeIgnoredPath(e)}),this._userIgnored=void 0,this._readyCount||=0,this._readyCount+=i.length,Promise.all(i.map(async e=>{let r=await this._nodeFsHandler._addToNodeFs(e,!n,void 0,0,t);return r&&this._emitReady(),r})).then(e=>{this.closed||e.forEach(e=>{e&&this.add(a.dirname(e),a.basename(t||e))})}),this}unwatch(e){if(this.closed)return this;let t=Y(e),{cwd:n}=this.options;return t.forEach(e=>{!a.isAbsolute(e)&&!this._closers.has(e)&&(n&&(e=a.join(n,e)),e=a.resolve(e)),this._closePath(e),this._addIgnoredPath(e),this._watched.has(e)&&this._addIgnoredPath({path:e,recursive:!0}),this._userIgnored=void 0}),this}close(){if(this._closePromise)return this._closePromise;this.closed=!0,this.removeAllListeners();let e=[];return this._closers.forEach(t=>t.forEach(t=>{let n=t();n instanceof Promise&&e.push(n)})),this._streams.forEach(e=>e.destroy()),this._userIgnored=void 0,this._readyCount=0,this._readyEmitted=!1,this._watched.forEach(e=>e.dispose()),this._closers.clear(),this._watched.clear(),this._streams.clear(),this._symlinkPaths.clear(),this._throttled.clear(),this._closePromise=e.length?Promise.all(e).then(()=>void 0):Promise.resolve(),this._closePromise}getWatched(){let e={};return this._watched.forEach((t,n)=>{let r=this.options.cwd?a.relative(this.options.cwd,n):n,i=r||W;e[i]=t.getChildren().sort()}),e}emitWithAll(e,t){this.emit(e,...t),e!==D.ERROR&&this.emit(D.ALL,e,...t)}async _emit(e,t,n){if(this.closed)return;let r=this.options;E&&(t=a.normalize(t)),r.cwd&&(t=a.relative(r.cwd,t));let i=[t];n!=null&&i.push(n);let o=r.awaitWriteFinish,s;if(o&&(s=this._pendingWrites.get(t)))return s.lastChange=new Date,this;if(r.atomic){if(e===D.UNLINK)return this._pendingUnlinks.set(t,[e,...i]),setTimeout(()=>{this._pendingUnlinks.forEach((e,t)=>{this.emit(...e),this.emit(D.ALL,...e),this._pendingUnlinks.delete(t)})},typeof r.atomic==`number`?r.atomic:100),this;e===D.ADD&&this._pendingUnlinks.has(t)&&(e=D.CHANGE,this._pendingUnlinks.delete(t))}if(o&&(e===D.ADD||e===D.CHANGE)&&this._readyEmitted){let n=(t,n)=>{t?(e=D.ERROR,i[0]=t,this.emitWithAll(e,i)):n&&(i.length>1?i[1]=n:i.push(n),this.emitWithAll(e,i))};return this._awaitWriteFinish(t,o.stabilityThreshold,e,n),this}if(e===D.CHANGE){let e=!this._throttle(D.CHANGE,t,50);if(e)return this}if(r.alwaysStat&&n===void 0&&(e===D.ADD||e===D.ADD_DIR||e===D.CHANGE)){let e=r.cwd?a.join(r.cwd,t):t,n;try{n=await u(e)}catch{}if(!n||this.closed)return;i.push(n)}return this.emitWithAll(e,i),this}_handleError(e){let t=e&&e.code;return e&&t!==`ENOENT`&&t!==`ENOTDIR`&&(!this.options.ignorePermissionErrors||t!==`EPERM`&&t!==`EACCES`)&&this.emit(D.ERROR,e),e||this.closed}_throttle(e,t,n){this._throttled.has(e)||this._throttled.set(e,new Map);let r=this._throttled.get(e);if(!r)throw Error(`invalid throttle`);let i=r.get(t);if(i)return i.count++,!1;let a,o=()=>{let e=r.get(t),n=e?e.count:0;return r.delete(t),clearTimeout(a),e&&clearTimeout(e.timeoutObject),n};a=setTimeout(o,n);let s={timeoutObject:a,clear:o,count:0};return r.set(t,s),s}_incrReadyCount(){return this._readyCount++}_awaitWriteFinish(t,n,r,i){let o=this.options.awaitWriteFinish;if(typeof o!=`object`)return;let s=o.pollInterval,c,l=t;this.options.cwd&&!a.isAbsolute(t)&&(l=a.join(this.options.cwd,t));let u=new Date,d=this._pendingWrites;function f(r){e(l,(e,a)=>{if(e||!d.has(t)){e&&e.code!==`ENOENT`&&i(e);return}let o=Number(new Date);r&&a.size!==r.size&&(d.get(t).lastChange=o);let l=d.get(t),u=o-l.lastChange;u>=n?(d.delete(t),i(void 0,a)):c=setTimeout(f,s,a)})}d.has(t)||(d.set(t,{lastChange:u,cancelWait:()=>(d.delete(t),clearTimeout(c),r)}),c=setTimeout(f,s))}_isIgnored(e,t){if(this.options.atomic&&De.test(e))return!0;if(!this._userIgnored){let{cwd:e}=this.options,t=this.options.ignored,n=(t||[]).map(Q(e)),r=[...this._ignoredPaths],i=[...r.map(Q(e)),...n];this._userIgnored=je(i,void 0)}return this._userIgnored(e,t)}_isntIgnored(e,t){return!this._isIgnored(e,t)}_getWatchHelpers(e){return new Ie(e,this.options.followSymlinks,this)}_getWatchedDir(e){let t=a.resolve(e);return this._watched.has(t)||this._watched.set(t,new $(t,this._boundRemove)),this._watched.get(t)}_hasReadPermissions(e){return this.options.ignorePermissionErrors?!0:!!(Number(e.mode)&256)}_remove(e,t,n){let r=a.join(e,t),i=a.resolve(r);if(n??=this._watched.has(r)||this._watched.has(i),!this._throttle(`remove`,r,100))return;!n&&this._watched.size===1&&this.add(e,t,!0);let o=this._getWatchedDir(r),s=o.getChildren();s.forEach(e=>this._remove(r,e));let c=this._getWatchedDir(e),l=c.has(t);c.remove(t),this._symlinkPaths.has(i)&&this._symlinkPaths.delete(i);let u=r;if(this.options.cwd&&(u=a.relative(this.options.cwd,r)),this.options.awaitWriteFinish&&this._pendingWrites.has(u)){let e=this._pendingWrites.get(u).cancelWait();if(e===D.ADD)return}this._watched.delete(r),this._watched.delete(i);let d=n?D.UNLINK_DIR:D.UNLINK;l&&!this._isIgnored(r)&&this._emit(d,r),this._closePath(r)}_closePath(e){this._closeFile(e);let t=a.dirname(e);this._getWatchedDir(t).remove(a.basename(e))}_closeFile(e){let t=this._closers.get(e);t&&(t.forEach(e=>e()),this._closers.delete(e))}_addPathCloser(e,t){if(!t)return;let n=this._closers.get(e);n||(n=[],this._closers.set(e,n)),n.push(t)}_readdirp(e,t){if(this.closed)return;let n={type:D.ALL,alwaysStat:!0,lstat:!0,...t,depth:0},r=ue(e,n);return this._streams.add(r),r.once(fe,()=>{r=void 0}),r.once(C,()=>{r&&(this._streams.delete(r),r=void 0)}),r}};function Re(e,t={}){let n=new Le(t);return n.add(e),n}export{Re as watch};
|