text: "use strict";function e(e){return e&&"object"==typeof e&&"default"in e?e.default:e}var n=e(require("fs-extra")),t=require("@hapi/joi"),r=e(require("rx"));const i=t.object().keys({resources:t.array().items(t.string().required()).required(),delay:t.number().integer().min(0).default(0),interval:t.number().integer().min(0).default(250),log:t.boolean().default(!1),reverse:t.boolean().default(!1),timeout:t.number().integer().min(0).default(Infinity),verbose:t.boolean().default(!1),window:t.number().integer().min(0).default(750)});function o(e,o){const u=t.validate(e,i);if(u.error&&o)return o(u.error);const l=u.value;l.window<l.interval&&(l.window=l.interval);const s=l.verbose?console.log.bind(console):function(){},a=l.log?console.log.bind(console):function(){};let c,f=null;function d(e){f&&(clearTimeout(f),f=null),o&&(o(e),o=null)}Infinity!==l.timeout&&(f=setTimeout(function(){a("wait-file(%s) timed out waiting for: %s; exiting with error",process.pid,c),o&&o(new Error("Timeout"))},l.timeout));let b=null,m=r.Observable.timer(l.delay,l.interval).concatMap(()=>r.Observable.from(l.resources).concatMap(function(e){return function(e){const t=r.Observable.fromNodeCallback(n.stat)(e),i=r.Observable.just({size:-1});return r.Observable.catch(t,i).map(function(e){return{val:e.size,data:e}})}(e)},function(e,n){return{resource:e,val:n.val,data:n.data}}).reduce(function(e,n){return e[n.resource]=n.val,e},{})).map(function(e){return b=e,e}).distinctUntilChanged().windowWithTime(l.window).subscribe(function(e){let n=e.toArray().subscribe(function(e){s("child next",e),function(){if(!b)return!1;var e=l.resources.filter(function(e){var n=b&&b[e],t="number"!=typeof n||n<0;return l.reverse?!t:t}),n=e.join(", ");return n&&n!==c&&(a("wait-file(%s) waiting for: %s",process.pid,n),c=n),!e.length}()&&!e.length&&(s("stabilized"),a("wait-file(%s) exiting successfully found all: %s",process.pid,l.resources.join(", ")),n.dispose(),m.dispose(),d())},function(e){s("child err",e)},function(){s("child complete")})},function(e){s("err: ",e),a("wait-file(%s) exiting with error",process.pid,e),d(e)},function(){s("complete"),d()})}exports.waitFile=function(e,n){return n&&void 0!==n?o(e,n):new Promise((n,t)=>{o(e,e=>{e?t(e):n()})})};
  //# sourceMappingURL=wait-file.cjs.production.min.js.map
  