UNPKG

cmpl

Version:

no deps, no operations, no vowels - just a tiny compiler

3 lines (2 loc) 6.37 kB
var S=Object.create;var N=Object.defineProperty,M=Object.defineProperties,V=Object.getOwnPropertyDescriptor,H=Object.getOwnPropertyDescriptors,_=Object.getOwnPropertyNames,T=Object.getOwnPropertySymbols,G=Object.getPrototypeOf,W=Object.prototype.hasOwnProperty,U=Object.prototype.propertyIsEnumerable;var j=(t,e,r)=>e in t?N(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,k=(t,e)=>{for(var r in e||(e={}))W.call(e,r)&&j(t,r,e[r]);if(T)for(var r of T(e))U.call(e,r)&&j(t,r,e[r]);return t},I=(t,e)=>M(t,H(e));var $=(t,e)=>{for(var r in e)N(t,r,{get:e[r],enumerable:!0})},q=(t,e,r,l)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of _(e))!W.call(t,s)&&s!==r&&N(t,s,{get:()=>e[s],enumerable:!(l=V(e,s))||l.enumerable});return t};var x=(t,e,r)=>(r=t!=null?S(G(t)):{},q(e||!t||!t.__esModule?N(r,"default",{value:t,enumerable:!0}):r,t)),Q=t=>q(N({},"__esModule",{value:!0}),t);var ee={};$(ee,{cmpl:()=>C,cntntChngd:()=>J,cntntHsh:()=>z,prcss:()=>B,wtch:()=>K});module.exports=Q(ee);const z=(t=8,e=import("node:crypto"),r=import("node:path"))=>async(l,s)=>{const{createHash:u}=await e,{basename:P,extname:a}=await r;return`${P(l,a(l))}-${u("sha256").update(s).digest("hex").substring(0,t).toUpperCase()}${a(l)}`},J=(t=import("node:crypto"))=>{const e=new Map;return async(r,l,s)=>{const{createHash:u}=await t,P=await(s==null?void 0:s())||null;if(P===null||l)return!0;const a=u("sha256").update(P).digest("hex");return!e.has(r)||e.get(r)!==a?(e.set(r,a),!0):!1}};async function B(t,{entry:e,fs:r=import("node:fs/promises"),path:l=import("node:path")},s){const{relative:u,dirname:P,join:a}=await l,{readFile:F,mkdir:A,writeFile:v}=await r,p=F(t),y=u(e,t);return Promise.all(s.map(async i=>{var g;if(!i)return i;const d=(await l).basename(y);!L(i)&&typeof i.rename=="function"&&console.warn("WARING: unexpected rename method on transform processor, will be ignored!","Return new name from transform method via { content: Buffer, name: string }");const o=L(i)?{content:await p,name:await((g=i.rename)==null?void 0:g.call(i,y,await p))||d}:await i.transform(await p,y);if(o===null)return null;const h=a(i.outDir,u(e,P(t))),w=Array.isArray(o)?o:o instanceof Buffer?[{content:o,name:d}]:[o];if(w.length===0)return null;const c=await Promise.all(w.map(async({content:f,name:m})=>{const n=a(h,m);return await A(P(n),{recursive:!0}),await v(n,f),u(i.outDir,n)}));return{[y]:Array.isArray(o)?c:c[0]}}))}async function C({entry:t,processors:e,fs:r=import("node:fs/promises"),path:l=import("node:path")}){const s=Array.from({length:e.length}).map(()=>({})),{relative:u,join:P,dirname:a}=await l,{readdir:F,stat:A,readFile:v}=await r;let p;const y=async(d,o,h)=>{const w=P(o,d),c=(await A(w)).isDirectory();if(p||(p=c?t:a(t)),c){let g=!1;const f=await Promise.all(h.map(async m=>{const n=m&&(d===t||m.recursive!==!1&&(!m.include||await m.include(u(p,w),!0)));return n&&(g=!0),n?m:null}));g&&await i(w,f)}if(!c){let g=!1;const f=await Promise.all(h.map(async m=>{const n=m&&(!m.include||await m.include(u(p,w),!1,()=>v(w)))?m:null;return n&&(g=!0),n}));if(!g)return;(await B(w,{fs:r,path:l,entry:t===d?p:t},f)).forEach((m,n)=>{m!==null&&Object.assign(s[n],m)})}},i=async(d,o)=>{await Promise.all((await F(d)).map(h=>y(h,d,o)))};return await y(t,"",await Promise.all(e)),e.length===1?s[0]:s}async function*K({signal:t,entry:e,processors:r,poll:l=Y(),onError:s=process.env.CI?a=>{throw a}:a=>console.log(a instanceof Error?a.message:a),fs:u=import("node:fs/promises"),path:P=import("node:path")}){const a={entry:e,fs:u,processors:r,path:P},{join:F,dirname:A}=await P,{watch:v,stat:p,readFile:y}=await u;let i=null;const d=()=>i.length===1?Object.assign({},i[0]):i.map(n=>Object.assign({},n));try{const n=await C(a);i=Array.isArray(n)?n:[n],yield d()}catch(n){s(n)}const o=(await p(e)).isDirectory(),h=o?e:A(e),w=o?a:I(k({},a),{entry:h}),c=(await Promise.all(r)).some(({recursive:n})=>n!==!1),g=l?X({fs:u,path:P,interval:typeof l=="number"?l:void 0}):v,f=new Z;t==null||t.addEventListener("abort",()=>{f.done(!0)});async function m(){for await(const n of g(e,{recursive:o?c:!1,signal:t}))f.push(n);f.done()}m();for await(const n of f)try{if(i)switch(n.eventType){case"rename":if(i.some(D=>D[n.filename])){i.forEach(D=>{D[n.filename]&&delete D[n.filename]}),yield d();break}case"change":{let b=!1;const D=await Promise.all((await Promise.all(r)).map(async O=>{const E=O&&(!O.include||await O.include(n.filename,!1,async()=>{try{return await y(F(h,n.filename))}catch(R){if((R==null?void 0:R.code)==="ENOENT")return null;throw R}}))?O:null;return E&&(b=!0),E}));b&&((await B(F(h,n.filename),w,D)).forEach((O,E)=>{O!==null&&Object.assign(i[E],O)}),yield d());break}}else{const b=await C(a);i=Array.isArray(b)?b:[b],yield d()}}catch(b){s(b)}}function X({path:t,fs:e,interval:r=300}){return async function*(s,u){var y,i,d;const{join:P,relative:a}=await t,{readdir:F,stat:A}=await e,v=async(o,h={})=>(await Promise.all((await F(o)).map(async w=>{const c=P(o,w),g=await A(c);g.isDirectory()&&u.recursive?await v(c,h):h[a(s,c)]=g.mtimeMs})),h);let p=await v(s);for(;!((y=u.signal)!=null&&y.aborted)&&(await new Promise(c=>setTimeout(c,r)),!((i=u.signal)!=null&&i.aborted));){const o=await v(s);if((d=u.signal)!=null&&d.aborted)break;const h=Object.entries(p);for(let c=0,g=h.length;c<g;c++){const[f,m]=h[c];o[f]?o[f]!==m&&(yield{eventType:"change",filename:f}):yield{eventType:"rename",filename:f}}const w=Object.entries(p);for(let c=0,g=w.length;c<g;c++){const[f]=w[c];p[f]||(yield{eventType:"rename",filename:f})}p=o}}}function Y(){if(!process.env.CMPL_USE_POLLING)return!1;const t=parseInt(process.env.CMPL_USE_POLLING);return isNaN(t)?!0:t}function L(t){return typeof t.transform!="function"}class Z{constructor(){this.queue=[];this.resolveNext=null;this.isDone=!1}done(e){var r;this.isDone=e?"abort":!0,(r=this.onAbort)==null||r.call(this,"done")}push(e){if(this.isDone)throw new Error("Can not push to done queue");this.queue.push(e),this.resolveNext&&this.resolveNext()}async pop(){if(this.queue.length===0){if(this.isDone)throw"done";await new Promise((r,l)=>{this.onAbort=l,this.resolveNext=r}),this.onAbort=void 0}return this.queue.shift()}[Symbol.asyncIterator](){return{next:async()=>{try{if(this.isDone==="abort")throw"done";return{value:await this.pop(),done:!1}}catch(e){if(e==="done")return{done:!0,value:void 0};throw e}}}}} //# sourceMappingURL=cjs.js.map