@visulima/packem 1.0.3 → 1.0.4

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.
@@ -1,8 +1,8 @@
1
- "use strict";var Dt=Object.create;var ce=Object.defineProperty;var Nt=Object.getOwnPropertyDescriptor;var _t=Object.getOwnPropertyNames;var Pt=Object.getPrototypeOf,Ct=Object.prototype.hasOwnProperty;var m=(e,t)=>ce(e,"name",{value:t,configurable:!0});var Rt=(e,t,o,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of _t(t))!Ct.call(e,r)&&r!==o&&ce(e,r,{get:()=>t[r],enumerable:!(n=Nt(t,r))||n.enumerable});return e};var _=(e,t,o)=>(o=e!=null?Dt(Pt(e)):{},Rt(t||!e||!e.__esModule?ce(o,"default",{value:e,enumerable:!0}):o,e));const V=require("node:fs"),ie=require("node:fs/promises"),Tt=require("node:module"),he=require("node:process"),j=require("@visulima/colorize"),At=require("@visulima/find-cache-dir"),$=require("@visulima/fs"),P=require("@visulima/humanizer"),f=require("@visulima/path"),$e=require("@visulima/tsconfig"),It=require("defu"),Mt=require("hookable"),Ue=require("jiti"),U=require("rollup"),Ft=require("@rollup/plugin-alias"),Jt=require("@rollup/plugin-commonjs"),Lt=require("@rollup/plugin-dynamic-import-vars"),Ve=require("@rollup/plugin-node-resolve"),qt=require("@rollup/plugin-replace"),Bt=require("@rollup/plugin-wasm"),Wt=require("rollup-plugin-polyfill-node"),Ut=require("rollup-plugin-visualizer"),Z=require("semver"),w=require("./packem_shared/constants-pJ3EadoV.cjs"),Vt=require("node:assert/strict"),C=require("@rollup/pluginutils"),zt=require("magic-string"),Gt=require("glob-parent"),ze=require("tinyglobby"),B=require("mlly"),Kt=require("oxc-parser"),Xt=require("@rollup/plugin-json"),Ht=require("rollup-plugin-license"),Yt=require("node:crypto"),Qt=require("node:url"),Zt=require("@babel/parser"),eo=require("typedoc"),to=require("@visulima/package/package-json"),oo=require("@visulima/fs/error"),no=require("@visulima/path/utils"),ro=require("is-glob"),io=require("fastest-levenshtein");var J=typeof document<"u"?document.currentScript:null;const D=m(e=>e&&typeof e=="object"&&"default"in e?e.default:e,"_interopDefaultCompat"),Ee=D(Tt),Ge=D(Ft),so=D(Jt),ao=D(Lt),Ke=D(qt),lo=D(Wt),ee=D(Vt),I=D(zt),co=D(Gt),po=D(Xt),uo=D(Ht),ke=D(ro);var fo=Object.defineProperty,mo=m((e,t)=>fo(e,"name",{value:t,configurable:!0}),"a$g");const me=mo((e,t)=>e.some(o=>o instanceof RegExp?o.test(t):o===t),"arrayIncludes");var go=Object.defineProperty,yo=m((e,t)=>go(e,"name",{value:t,configurable:!0}),"a$f");const W=yo(e=>e==null?[]:Array.isArray(e)?e:[e],"arrayify");var ho=Object.defineProperty,vo=m((e,t)=>ho(e,"name",{value:t,configurable:!0}),"a$e");const Xe=vo((e="")=>{const t=e.split("/");return t[0].startsWith("@")?t[0]+"/"+t[1]:t[0]},"getPackageName");var bo=Object.defineProperty,He=m((e,t)=>bo(e,"name",{value:t,configurable:!0}),"s$g");const jo=He((e,t,o)=>{const n=o??new Map;return(...r)=>{const i=t?typeof t=="function"?t(...r):t:JSON.stringify({args:r}),s=n.get(i);if(s!==void 0)return s;const a=e(...r);return n.set(i,a),a}},"memoize"),wo=He(e=>{const t=new Map;return o=>jo(e,o,t)},"memoizeByKey");var $o=Object.defineProperty,z=m((e,t)=>$o(e,"name",{value:t,configurable:!0}),"r$e");const Eo=z(function*(e){switch(e.declaration?.type){case"ClassDeclaration":case"FunctionDeclaration":{const{id:t}=e.declaration;ee(t,"Expected class/function to have a name"),yield t.name;break}case"VariableDeclaration":{for(const t of e.declaration.declarations)for(const o of C.extractAssignedNames(t.id))yield o;break}}},"exportName"),ko=z(function*(e){if(e.declaration)for(const t of Eo(e))yield{exportedName:t,from:"self",type:"named"};else if(e.source)yield{bindings:e.specifiers.map(t=>({exportedName:t.exported.name,importedName:t.local.name})),from:"other",source:e.source.value,type:"named"};else for(const t of e.specifiers)yield{exportedName:t.exported.name,from:"self",type:"named"}},"parseExportNamed"),xo=z(function*(e){e.exported?yield{exportedName:e.exported.name,from:"self",type:"named"}:yield{from:"other",source:e.source.value,type:"barrel"}},"parseExportAll"),So=z(function*(){yield{exportedName:"default",from:"self",type:"named"}},"parseExportDefault"),Oo=z(function*(e,t){ee(t.code!=null,`Module ${t.id} doesn't have associated code`);const o=e.parse(t.code);for(const n of o.body)switch(n.type){case"ExportAllDeclaration":{yield*xo(n);break}case"ExportDefaultDeclaration":{yield*So();break}case"ExportNamedDeclaration":{yield*ko(n);break}}},"parseExports");var Do=Object.defineProperty,G=m((e,t)=>Do(e,"name",{value:t,configurable:!0}),"n$9");const Ye=G(async function(e,t,o){const n=await e.resolve(t,o.id);if(ee(n,`Rollup can't resolve ${t} from ${o.id}`),n.external)return null;const r=await e.load(n);return ee(r,`Rollup doesn't have a module for id ${n.id}`),r},"getImportedModule"),No=G(async function*(e,t,o){const n=await Ye(e,t.source,o);n&&(yield*ve(e,n))},"gatherBarrelReExports"),_o=G(async function*(e,t,o){const n=await Ye(e,t.source,o);if(!n)return;const r=new Map(t.bindings.map(i=>[i.importedName,i]));for await(const i of ve(e,n)){const s=r.get(i.exportedName);s&&(yield{...i,exportedName:s.exportedName})}},"gatherNamedReExports"),Po=G(async function*(e,t){yield{exportedName:t.exportedName,id:e.id,sourceName:t.exportedName}},"gatherNamedSelfExports"),ve=G(async function*(e,t){for(const o of Oo(e,t))o.from==="self"?yield*Po(t,o):o.type==="barrel"?yield*No(e,o,t):yield*_o(e,o,t)},"gatherExports");var Co=Object.defineProperty,Ro=m((e,t)=>Co(e,"name",{value:t,configurable:!0}),"r$d");const To=Ro(()=>({moduleParsed:{async handler(e){if(e.isEntry)for await(const t of ve(this,e))t.id!==e.id&&this.emitFile({id:t.id,name:t.exportedName,preserveSignature:"exports-only",type:"chunk"})},order:"post"},name:"packem:chunk-splitter"}),"chunkSplitter");var Ao=Object.defineProperty,Io=m((e,t)=>Ao(e,"name",{value:t,configurable:!0}),"r$c");const Mo=Io((e,t)=>{const o=e,n=[];let r;for(;(r=o.exec(t))!==null;)r.index===o.lastIndex&&o.lastIndex++,r.forEach(i=>{n.push(i)});return n.filter(Boolean)},"getRegexMatches");var Fo=Object.defineProperty,Jo=m((e,t)=>Fo(e,"name",{value:t,configurable:!0}),"a$d");const Qe=Jo(e=>{const t=Mo(/export\s(\{\s(.*)\s\}|default\s.*);/g,e);if(t.length===0)return null;const o=t.at(-1).split(", ");let n="";for(const r of o)if(!r.includes("type")&&(r.includes("default ")&&(n=r.split("default ")[1]),r.includes("as"))){const[i,s]=r.split(" as ");s==="default"&&(n=i)}if(n!==""){const r=new I(e);return r.replace(new RegExp(`(,s)?${n} as default(,)?`),""),r.replace(new RegExp(`export default ${n};
1
+ "use strict";var Dt=Object.create;var ce=Object.defineProperty;var Nt=Object.getOwnPropertyDescriptor;var _t=Object.getOwnPropertyNames;var Pt=Object.getPrototypeOf,Ct=Object.prototype.hasOwnProperty;var m=(e,t)=>ce(e,"name",{value:t,configurable:!0});var Rt=(e,t,o,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of _t(t))!Ct.call(e,r)&&r!==o&&ce(e,r,{get:()=>t[r],enumerable:!(n=Nt(t,r))||n.enumerable});return e};var _=(e,t,o)=>(o=e!=null?Dt(Pt(e)):{},Rt(t||!e||!e.__esModule?ce(o,"default",{value:e,enumerable:!0}):o,e));const V=require("node:fs"),ie=require("node:fs/promises"),Tt=require("node:module"),he=require("node:process"),j=require("@visulima/colorize"),At=require("@visulima/find-cache-dir"),$=require("@visulima/fs"),P=require("@visulima/humanizer"),f=require("@visulima/path"),$e=require("@visulima/tsconfig"),It=require("defu"),Mt=require("hookable"),Ue=require("jiti"),U=require("rollup"),Ft=require("@rollup/plugin-alias"),Jt=require("@rollup/plugin-commonjs"),Lt=require("@rollup/plugin-dynamic-import-vars"),Ve=require("@rollup/plugin-node-resolve"),qt=require("@rollup/plugin-replace"),Bt=require("@rollup/plugin-wasm"),Wt=require("rollup-plugin-polyfill-node"),Ut=require("rollup-plugin-visualizer"),Z=require("semver"),w=require("./packem_shared/constants-pJ3EadoV.cjs"),Vt=require("node:assert/strict"),C=require("@rollup/pluginutils"),zt=require("magic-string"),Gt=require("glob-parent"),ze=require("tinyglobby"),L=require("mlly"),Kt=require("oxc-parser"),Xt=require("@rollup/plugin-json"),Ht=require("rollup-plugin-license"),Yt=require("node:crypto"),Qt=require("node:url"),Zt=require("@babel/parser"),eo=require("typedoc"),to=require("@visulima/package/package-json"),oo=require("@visulima/fs/error"),no=require("@visulima/path/utils"),ro=require("is-glob"),io=require("fastest-levenshtein");var J=typeof document<"u"?document.currentScript:null;const D=m(e=>e&&typeof e=="object"&&"default"in e?e.default:e,"_interopDefaultCompat"),Ee=D(Tt),Ge=D(Ft),so=D(Jt),ao=D(Lt),Ke=D(qt),lo=D(Wt),ee=D(Vt),I=D(zt),co=D(Gt),po=D(Xt),uo=D(Ht),ke=D(ro);var fo=Object.defineProperty,mo=m((e,t)=>fo(e,"name",{value:t,configurable:!0}),"a$g");const me=mo((e,t)=>e.some(o=>o instanceof RegExp?o.test(t):o===t),"arrayIncludes");var go=Object.defineProperty,yo=m((e,t)=>go(e,"name",{value:t,configurable:!0}),"a$f");const W=yo(e=>e==null?[]:Array.isArray(e)?e:[e],"arrayify");var ho=Object.defineProperty,vo=m((e,t)=>ho(e,"name",{value:t,configurable:!0}),"a$e");const Xe=vo((e="")=>{const t=e.split("/");return t[0].startsWith("@")?t[0]+"/"+t[1]:t[0]},"getPackageName");var bo=Object.defineProperty,He=m((e,t)=>bo(e,"name",{value:t,configurable:!0}),"s$g");const jo=He((e,t,o)=>{const n=o??new Map;return(...r)=>{const i=t?typeof t=="function"?t(...r):t:JSON.stringify({args:r}),s=n.get(i);if(s!==void 0)return s;const a=e(...r);return n.set(i,a),a}},"memoize"),wo=He(e=>{const t=new Map;return o=>jo(e,o,t)},"memoizeByKey");var $o=Object.defineProperty,z=m((e,t)=>$o(e,"name",{value:t,configurable:!0}),"r$e");const Eo=z(function*(e){switch(e.declaration?.type){case"ClassDeclaration":case"FunctionDeclaration":{const{id:t}=e.declaration;ee(t,"Expected class/function to have a name"),yield t.name;break}case"VariableDeclaration":{for(const t of e.declaration.declarations)for(const o of C.extractAssignedNames(t.id))yield o;break}}},"exportName"),ko=z(function*(e){if(e.declaration)for(const t of Eo(e))yield{exportedName:t,from:"self",type:"named"};else if(e.source)yield{bindings:e.specifiers.map(t=>({exportedName:t.exported.name,importedName:t.local.name})),from:"other",source:e.source.value,type:"named"};else for(const t of e.specifiers)yield{exportedName:t.exported.name,from:"self",type:"named"}},"parseExportNamed"),xo=z(function*(e){e.exported?yield{exportedName:e.exported.name,from:"self",type:"named"}:yield{from:"other",source:e.source.value,type:"barrel"}},"parseExportAll"),So=z(function*(){yield{exportedName:"default",from:"self",type:"named"}},"parseExportDefault"),Oo=z(function*(e,t){ee(t.code!=null,`Module ${t.id} doesn't have associated code`);const o=e.parse(t.code);for(const n of o.body)switch(n.type){case"ExportAllDeclaration":{yield*xo(n);break}case"ExportDefaultDeclaration":{yield*So();break}case"ExportNamedDeclaration":{yield*ko(n);break}}},"parseExports");var Do=Object.defineProperty,G=m((e,t)=>Do(e,"name",{value:t,configurable:!0}),"n$9");const Ye=G(async function(e,t,o){const n=await e.resolve(t,o.id);if(ee(n,`Rollup can't resolve ${t} from ${o.id}`),n.external)return null;const r=await e.load(n);return ee(r,`Rollup doesn't have a module for id ${n.id}`),r},"getImportedModule"),No=G(async function*(e,t,o){const n=await Ye(e,t.source,o);n&&(yield*ve(e,n))},"gatherBarrelReExports"),_o=G(async function*(e,t,o){const n=await Ye(e,t.source,o);if(!n)return;const r=new Map(t.bindings.map(i=>[i.importedName,i]));for await(const i of ve(e,n)){const s=r.get(i.exportedName);s&&(yield{...i,exportedName:s.exportedName})}},"gatherNamedReExports"),Po=G(async function*(e,t){yield{exportedName:t.exportedName,id:e.id,sourceName:t.exportedName}},"gatherNamedSelfExports"),ve=G(async function*(e,t){for(const o of Oo(e,t))o.from==="self"?yield*Po(t,o):o.type==="barrel"?yield*No(e,o,t):yield*_o(e,o,t)},"gatherExports");var Co=Object.defineProperty,Ro=m((e,t)=>Co(e,"name",{value:t,configurable:!0}),"r$d");const To=Ro(()=>({moduleParsed:{async handler(e){if(e.isEntry)for await(const t of ve(this,e))t.id!==e.id&&this.emitFile({id:t.id,name:t.exportedName,preserveSignature:"exports-only",type:"chunk"})},order:"post"},name:"packem:chunk-splitter"}),"chunkSplitter");var Ao=Object.defineProperty,Io=m((e,t)=>Ao(e,"name",{value:t,configurable:!0}),"r$c");const Mo=Io((e,t)=>{const o=e,n=[];let r;for(;(r=o.exec(t))!==null;)r.index===o.lastIndex&&o.lastIndex++,r.forEach(i=>{n.push(i)});return n.filter(Boolean)},"getRegexMatches");var Fo=Object.defineProperty,Jo=m((e,t)=>Fo(e,"name",{value:t,configurable:!0}),"a$d");const Qe=Jo(e=>{const t=Mo(/export\s(\{\s(.*)\s\}|default\s.*);/g,e);if(t.length===0)return null;const o=t.at(-1).split(", ");let n="";for(const r of o)if(!r.includes("type")&&(r.includes("default ")&&(n=r.split("default ")[1]),r.includes("as"))){const[i,s]=r.split(" as ");s==="default"&&(n=i)}if(n!==""){const r=new I(e);return r.replace(new RegExp(`(,s)?${n} as default(,)?`),""),r.replace(new RegExp(`export default ${n};
2
2
  ?`),""),r.append(`
3
3
 
4
4
  export = `+n+";"),{code:r.toString().replace(/export\s\{\s\s\};/,""),map:r.generateMap({hires:!0})}}return null},"patchCjsDefaultExport");var Lo=Object.defineProperty,xe=m((e,t)=>Lo(e,"name",{value:t,configurable:!0}),"i$b");const Ze=xe(({addDefaultProperty:e=!1,logger:t,type:o})=>({name:"packem:cjs-interop",renderChunk:xe(async(n,r,i)=>{if(r.type!=="chunk"||!r.isEntry)return null;if(i.format==="cjs"&&i.exports==="auto"){const s=/(exports(?:\['default'\]|\.default)) = (.*);/i.exec(n);if(s===null||s.length<3)return null;const a=new I(n);a.replace("",""),a.replaceAll(/exports\.(.*) = (.*);/g,"module.module.exports.$1 = $2;"),e&&a.append(`
5
- module.module.exports = `+s[2]+";");let l=a.toString();return l=l.replace(/(?:module\.)?exports(?:\['default'\]|\.default)/i,"module.exports"),t.debug({message:"Applied CommonJS interop to entry chunk "+r.fileName+".",prefix:"plugin:cjs-interop"}),{code:l,map:a.generateMap({hires:!0})}}return i.format==="es"&&/\.d\.(?:ts|cts)$/.test(r.fileName)?o!=="commonjs"&&r.fileName.endsWith(".d.mts")?null:Qe(n):null},"renderChunk")}),"cjsInteropPlugin");var qo=Object.defineProperty,Bo=m((e,t)=>qo(e,"name",{value:t,configurable:!0}),"f$9");const Wo=Bo((e,t)=>{const o=new Map,n={copyOnce:!0,exactFileNames:!0,flatten:!1,...e};let{targets:r}=n;return Array.isArray(r)?r=r.map(i=>{if(typeof i=="string")return{src:i};if(typeof i=="object"&&"src"in i)return i}).filter(Boolean):typeof r=="string"&&(r=[{src:r}]),{async buildStart(){const i=await Promise.all(r.flatMap(s=>Array.isArray(s.src)?s.src.map(a=>({...s,src:a})):s).map(async s=>await ze.glob(W(s.src),{ignore:W(s.exclude).filter(Boolean)}).then(a=>({dest:s.dest??"",parent:co(s.src),src:a}))));for(const s of i)for(const a of s.src){let l;o.has(a)?l=o.get(a):(l={copied:[],dest:[],timestamp:0},o.set(a,l));const c=n.flatten?f.normalize(s.dest):f.join(s.dest,f.relative(s.parent,f.dirname(a)));l.dest.includes(c)||l.dest.push(c),this.addWatchFile(a)}t.info({message:"Copying files...",prefix:"plugin:copy"}),await Promise.all([...o].map(async([s,a])=>{let l;try{const c=await ie.stat(s);if(!c.isFile())return;const d=c.mtime.getTime();d>a.timestamp&&(a.timestamp=d,a.copied=[]),l=await $.readFile(s,{buffer:!0})}catch(c){t.error({context:[c],message:`error reading file ${s}`,prefix:"plugin:copy"});return}for(const c of a.dest){if(n.copyOnce&&a.copied.includes(c))continue;const d=f.basename(s),p=f.join(c,d);try{this.emitFile({[n.exactFileNames?"fileName":"name"]:p,source:l,type:"asset"}),t.debug({message:`copied ${s} → ${p}`,prefix:"plugin:copy"}),a.copied.push(c)}catch(u){t.error({context:[u],message:`error copying file ${s} → ${p}`,prefix:"plugin:copy"})}}}))},name:"packem:copy"}},"copyPlugin");var Uo=Object.defineProperty,se=m((e,t)=>Uo(e,"name",{value:t,configurable:!0}),"t$a");const Vo=/\Wrequire(?:\.resolve)?\(/,zo=se((e,t)=>{if(he.env.INTERNAL_PACKEM_BUILD!=="1"&&(e.includes("// -- packem CommonJS __filename shim")||e.includes("// -- packem CommonJS __dirname shim")||e.includes("// -- packem CommonJS require shim")))return null;let o=!1,n=!1,r=!1;if(e.includes("__filename")&&(o=!0),e.includes("__dirname")&&(n=!0),Vo.test(e)&&(r=!0),!o&&!n&&!r)return null;const i=B.findStaticImports(e).pop(),s=i?i.end:0,a=new I(e);return a.appendRight(s,t(o,n,r)),{code:a.toString(),map:a.generateMap()}},"CJSToESM"),Go=se((e,t,o)=>{let n="";return(e||t)&&(n+=`import __cjs_url__ from "node:url"; // -- packem CommonJS __filename shim --
5
+ module.module.exports = `+s[2]+";");let l=a.toString();return l=l.replace(/(?:module\.)?exports(?:\['default'\]|\.default)/i,"module.exports"),t.debug({message:"Applied CommonJS interop to entry chunk "+r.fileName+".",prefix:"plugin:cjs-interop"}),{code:l,map:a.generateMap({hires:!0})}}return i.format==="es"&&/\.d\.(?:ts|cts)$/.test(r.fileName)?o!=="commonjs"&&r.fileName.endsWith(".d.mts")?null:Qe(n):null},"renderChunk")}),"cjsInteropPlugin");var qo=Object.defineProperty,Bo=m((e,t)=>qo(e,"name",{value:t,configurable:!0}),"f$9");const Wo=Bo((e,t)=>{const o=new Map,n={copyOnce:!0,exactFileNames:!0,flatten:!1,...e};let{targets:r}=n;return Array.isArray(r)?r=r.map(i=>{if(typeof i=="string")return{src:i};if(typeof i=="object"&&"src"in i)return i}).filter(Boolean):typeof r=="string"&&(r=[{src:r}]),{async buildStart(){const i=await Promise.all(r.flatMap(s=>Array.isArray(s.src)?s.src.map(a=>({...s,src:a})):s).map(async s=>await ze.glob(W(s.src),{ignore:W(s.exclude).filter(Boolean)}).then(a=>({dest:s.dest??"",parent:co(s.src),src:a}))));for(const s of i)for(const a of s.src){let l;o.has(a)?l=o.get(a):(l={copied:[],dest:[],timestamp:0},o.set(a,l));const c=n.flatten?f.normalize(s.dest):f.join(s.dest,f.relative(s.parent,f.dirname(a)));l.dest.includes(c)||l.dest.push(c),this.addWatchFile(a)}t.info({message:"Copying files...",prefix:"plugin:copy"}),await Promise.all([...o].map(async([s,a])=>{let l;try{const c=await ie.stat(s);if(!c.isFile())return;const d=c.mtime.getTime();d>a.timestamp&&(a.timestamp=d,a.copied=[]),l=await $.readFile(s,{buffer:!0})}catch(c){t.error({context:[c],message:`error reading file ${s}`,prefix:"plugin:copy"});return}for(const c of a.dest){if(n.copyOnce&&a.copied.includes(c))continue;const d=f.basename(s),p=f.join(c,d);try{this.emitFile({[n.exactFileNames?"fileName":"name"]:p,source:l,type:"asset"}),t.debug({message:`copied ${s} → ${p}`,prefix:"plugin:copy"}),a.copied.push(c)}catch(u){t.error({context:[u],message:`error copying file ${s} → ${p}`,prefix:"plugin:copy"})}}}))},name:"packem:copy"}},"copyPlugin");var Uo=Object.defineProperty,se=m((e,t)=>Uo(e,"name",{value:t,configurable:!0}),"t$a");const Vo=/\Wrequire(?:\.resolve)?\(/,zo=se((e,t)=>{if(he.env.INTERNAL_PACKEM_BUILD!=="1"&&(e.includes("// -- packem CommonJS __filename shim")||e.includes("// -- packem CommonJS __dirname shim")||e.includes("// -- packem CommonJS require shim")))return null;let o=!1,n=!1,r=!1;if(e.includes("__filename")&&(o=!0),e.includes("__dirname")&&(n=!0),Vo.test(e)&&(r=!0),!o&&!n&&!r)return null;const i=L.findStaticImports(e).pop(),s=i?i.end:0,a=new I(e);return a.appendRight(s,t(o,n,r)),{code:a.toString(),map:a.generateMap()}},"CJSToESM"),Go=se((e,t,o)=>{let n="";return(e||t)&&(n+=`import __cjs_url__ from "node:url"; // -- packem CommonJS __filename shim --
6
6
  `),t&&(n+=`import __cjs_path__ from "node:path"; // -- packem CommonJS __dirname shim --
7
7
  `),o&&(n+=`import __cjs_mod__ from "node:module"; // -- packem CommonJS require shim --
8
8
  `),(e||t)&&(n+=`const __filename = __cjs_url__.fileURLToPath(import.meta.url);
@@ -29,7 +29,7 @@ $2`)},"replaceContentWithin");var hn=Object.defineProperty,nt=m((e,t)=>hn(e,"nam
29
29
  `);if(c===""){n.info({message:"No dependencies license information found.",prefix:"plugin:license:"+i});return}const d=o(vn(l),c,s);try{const p=$.readFileSync(t),u=ot(p,r,d);if(!u){n.error({message:`Could not find the license marker: <!-- ${r} --><!-- /${r} --> in ${t}`,prefix:"plugin:license:"+i});return}p!==u&&($.writeFileSync(t,u),n.info({message:`${t} updated.`,prefix:"plugin:license:"+i}))}catch(p){n.error(p)}}}),"license");var bn=Object.defineProperty,jn=m((e,t)=>bn(e,"name",{value:t,configurable:!0}),"i$9");const wn=jn(e=>({async buildEnd(){const t=[];for(const n of this.getModuleIds()){const r=this.getModuleInfo(n);if(r!=null&&!r.isExternal)for(const i of r.importedIds)t.push({source:n,target:i})}if(Array.isArray(t)&&t.length===0)return;const o=f.resolve(e.rootDir,e.outDir,"graph.json");$.writeJsonSync(o,t)},name:"packem:metafile"}),"metafilePlugin");var $n=Object.defineProperty,En=m((e,t)=>$n(e,"name",{value:t,configurable:!0}),"g$7");let De=!1;const kn=En((e,t,o,n,r,i)=>{if(i!=="*"&&Z.valid(Z.coerce(i))===null)throw new Error("Invalid typeScriptVersion option. It must be a valid semver range.");return{name:"packem:node10-compatibility",writeBundle(){De||(e.info({message:"Declaration node10 compatibility mode is enabled.",prefix:"plugin:node10-compatibility"}),De=!0);const s={};for(const c of t)for(const d of c.exportKey)d.includes("/*")?s[d]=["./"+f.join(o,f.dirname(c.name),"*.d.ts")]:s[d]=[...s[d]??[],"./"+f.join(o,c.name+".d.ts")];const a=f.join(n,"package.json"),l=$.readJsonSync(a);r==="file"&&Object.keys(s).length>0?($.writeJsonSync(a,{...l,typesVersions:{...l.typesVersions,[i]:s}},{detectIndent:!0}),e.info({message:'Your package.json "typesVersions" field has been updated.',prefix:"plugin:node10-compatibility"})):Object.keys(s).length>0&&e.info({message:`Please add the following field into your package.json to enable node 10 compatibility:
30
30
 
31
31
  ${JSON.stringify({typesVersions:{"*":s}},null,4)}
32
- `,prefix:"plugin:node10-compatibility"})}}},"node10CompatibilityPlugin");var xn=Object.defineProperty,Sn=m((e,t)=>xn(e,"name",{value:t,configurable:!0}),"r$9");const T=Sn(e=>{const t=Yt.createHash("md5");return t.update(e),t.digest("hex")},"getHash");var On=Object.defineProperty,it=m((e,t)=>On(e,"name",{value:t,configurable:!0}),"d$a");const q=it(e=>e.handler||e,"getHandler"),S=it((e,t,o="")=>({...e,async buildEnd(n){e.buildEnd&&await q(e.buildEnd).call(this,n)},async buildStart(n){e.buildStart&&await q(e.buildStart).call(this,n)},async load(n){if(!e.load)return null;const r=f.join(o,e.name),i=f.join("load",T(n));if(t.has(i,r))return await t.get(i,r);const s=await q(e.load).call(this,n);return t.set(i,s,r),s},name:`cached(${e.name})`,async resolveId(n,r,i){if(!e.resolveId)return null;const s=f.join(o,e.name),a=f.join("resolveId",T(n),r?T(r):"",T(JSON.stringify(i)));if(t.has(a,s))return await t.get(a,s);const l=await q(e.resolveId).call(this,n,r,i);return t.set(a,l,s),l},async transform(n,r){if(!e.transform)return null;const i=f.join(o,e.name),s=f.join("transform",T(r),T(n));if(t.has(s,i))return await t.get(s,i);const a=await q(e.transform).call(this,n,r);return t.set(s,a,i),a}}),"cachingPlugin");var Dn=Object.defineProperty,Nn=m((e,t)=>Dn(e,"name",{value:t,configurable:!0}),"n$6");const _n=Nn(()=>({name:"packem:prepend-directive",transform:{handler(e,t){const o=this.getModuleInfo(t);if(o?.meta.preserveDirectives){const n=o.meta.preserveDirectives.directives[0];if(n)return`'${n.value}';
32
+ `,prefix:"plugin:node10-compatibility"})}}},"node10CompatibilityPlugin");var xn=Object.defineProperty,Sn=m((e,t)=>xn(e,"name",{value:t,configurable:!0}),"r$9");const T=Sn(e=>{const t=Yt.createHash("md5");return t.update(e),t.digest("hex")},"getHash");var On=Object.defineProperty,it=m((e,t)=>On(e,"name",{value:t,configurable:!0}),"d$a");const B=it(e=>e.handler||e,"getHandler"),S=it((e,t,o="")=>({...e,async buildEnd(n){e.buildEnd&&await B(e.buildEnd).call(this,n)},async buildStart(n){e.buildStart&&await B(e.buildStart).call(this,n)},async load(n){if(!e.load)return null;const r=f.join(o,e.name),i=f.join("load",T(n));if(t.has(i,r))return await t.get(i,r);const s=await B(e.load).call(this,n);return t.set(i,s,r),s},name:`cached(${e.name})`,async resolveId(n,r,i){if(!e.resolveId)return null;const s=f.join(o,e.name),a=f.join("resolveId",T(n),r?T(r):"",T(JSON.stringify(i)));if(t.has(a,s))return await t.get(a,s);const l=await B(e.resolveId).call(this,n,r,i);return t.set(a,l,s),l},async transform(n,r){if(!e.transform)return null;const i=f.join(o,e.name),s=f.join("transform",T(r),T(n));if(t.has(s,i))return await t.get(s,i);const a=await B(e.transform).call(this,n,r);return t.set(s,a,i),a}}),"cachingPlugin");var Dn=Object.defineProperty,Nn=m((e,t)=>Dn(e,"name",{value:t,configurable:!0}),"n$6");const _n=Nn(()=>({name:"packem:prepend-directive",transform:{handler(e,t){const o=this.getModuleInfo(t);if(o?.meta.preserveDirectives){const n=o.meta.preserveDirectives.directives[0];if(n)return`'${n.value}';
33
33
  `+e}return null},order:"post"}}),"prependDirectivePlugin");var Pn=Object.defineProperty,Cn=m((e,t)=>Pn(e,"name",{value:t,configurable:!0}),"c$8");const Rn=Cn(({directiveRegex:e,exclude:t=[],include:o=[],logger:n})=>{const r={},i={},s=C.createFilter(o,t);return{name:"packem:preserve-directives",onLog(a,l){return l.code==="MODULE_LEVEL_DIRECTIVE"&&a==="warn"?!1:null},renderChunk:{handler(a,l,{sourcemap:c}){const d=l.moduleIds.map(y=>r[y]?r[y]:null).reduce((y,h)=>(h&&h.forEach(g=>{y.add(g)}),y),new Set),p=new I(a);d.size>0&&(n.debug({message:`directives for chunk "${l.fileName}" are preserved.`,prefix:"plugin:preserve-directives"}),p.prepend(`${[...d].map(y=>`'${y}';`).join(`
34
34
  `)}
35
35
  `));let u;return l.facadeModuleId&&typeof i[l.facadeModuleId]=="string"&&(u=i[l.facadeModuleId]),u&&(n.debug({message:`shebang for chunk "${l.fileName}" is preserved.`,prefix:"plugin:preserve-directives"}),p.prepend(`${u}
@@ -38,7 +38,7 @@ ${JSON.stringify({typesVersions:{"*":s}},null,4)}
38
38
  `),{code:s.toString(),map:r.sourcemap?s.generateMap({hires:!0}):void 0}}return null},order:"post"},async writeBundle(o,n){for(const[r,i]of Object.entries(n))if(i.type==="chunk"&&te.test(i.code)&&o.dir){const s=f.resolve(o.dir,r);await ge(s)}}}),"shebangPlugin"),qn=ae(()=>({name:"packem:remove-shebang",renderChunk(e){return e.replace(te,"")}}),"removeShebangPlugin"),Bn=ae((e,t=`
39
39
  `)=>{const o=te.exec(e);return o?o+t:""},"getShebang");var Wn=Object.defineProperty,M=m((e,t)=>Wn(e,"name",{value:t,configurable:!0}),"r$7");const Un=/\/\*[^*]*\*+(?:[^/*][^*]*\*+)*\//g,Vn=/MIT License|MIT license|BSD license/,zn=/\n{2,}/g,Gn=/\b(\w+)\$\d+\b/g,Kn=/[-/\\^$*+?.()|[\]{}]/g,Xn=M(e=>e.replaceAll(Kn,"\\$&"),"escapeRegex"),Hn=M(e=>[...new Set(e)],"unique"),Yn=M(e=>e.replaceAll(Un,t=>Vn.test(t)?"":t).replaceAll(zn,`
40
40
 
41
- `),"cleanUnnecessaryComments"),Ne=new Map;function at(e,t,{identifierReplacements:o},n){const r=B.findStaticImports(e);for(const s in o){const a=r.find(c=>c.specifier===s&&c.imports.includes("{"));if(!a){this.warn(`${t.fileName} does not import "${s}" for replacement`),process.exitCode=1;continue}const l=o[s];for(const c in l){if(!a.imports.includes(c))throw new Error(`${t.fileName} does not import "${c}" from "${s}" for replacement`);const d=l[c],p=Xn(c);d.includes(".")&&(e=e.replace(new RegExp(`\\b\\w+\\b as ${p},?\\s?`),"")),e=e.replaceAll(new RegExp(`\\b${p}\\b`,"g"),d)}}const i=Hn(Array.from(e.matchAll(Gn),s=>s[0]));if(i.length>0){const s=i.map(l=>`
41
+ `),"cleanUnnecessaryComments"),Ne=new Map;function at(e,t,{identifierReplacements:o},n){const r=L.findStaticImports(e);for(const s in o){const a=r.find(c=>c.specifier===s&&c.imports.includes("{"));if(!a){this.warn(`${t.fileName} does not import "${s}" for replacement`),process.exitCode=1;continue}const l=o[s];for(const c in l){if(!a.imports.includes(c))throw new Error(`${t.fileName} does not import "${c}" from "${s}" for replacement`);const d=l[c],p=Xn(c);d.includes(".")&&(e=e.replace(new RegExp(`\\b\\w+\\b as ${p},?\\s?`),"")),e=e.replaceAll(new RegExp(`\\b${p}\\b`,"g"),d)}}const i=Hn(Array.from(e.matchAll(Gn),s=>s[0]));if(i.length>0){const s=i.map(l=>`
42
42
  - ${l}`).join(""),a=t.fileName.replace(/\.[^/.]+$/,"");Ne.has(a)||n.warn({message:`${t.fileName} contains confusing identifier names${s}
43
43
 
44
44
  To replace these, add them to the "rollup -> patchTypes -> identifierReplacements" option in your packem config.`,prefix:"plugin:patch-types"}),Ne.set(a,!0)}return e}m(at,"I");M(at,"replaceConfusingTypeNames");const Qn=M((e,t)=>{if(t.leadingComments?.some(o=>o.type==="CommentBlock"&&o.value.includes("@internal"))){const o=e.original[t.end]===","?t.end+1:t.end;return e.remove(t.leadingComments[0].start,o),!0}return!1},"removeInternal");function lt(e,t){if(e.includes("@internal")){const o=new I(e),n=Zt.parse(e,{plugins:["typescript"],sourceType:"module"});if(tt(n,{enter(r){Qn(o,r)&&this.skip()}}),e=o.toString(),e.includes("@internal"))throw new Error(`${t.fileName} has unhandled @internal declarations`)}return e}m(lt,"S$1");M(lt,"stripInternalTypes");const Zn=M((e,t)=>({name:"packem:patch-types",renderChunk(o,n){return o=at.call(this,o,n,e,t),o=lt.call(this,o,n),o=Yn(o),o},resolveId(o){return o.startsWith("types/")?{external:!0,id:"../../"+(o.endsWith(".js")?o:o+".js")}:null}}),"patchTypescriptTypes");var er=Object.defineProperty,ct=m((e,t)=>er(e,"name",{value:t,configurable:!0}),"m$8");const pt=ct((e,t=!0)=>{if(!e)return null;const{config:o,path:n}=e;if(!o.compilerOptions)return null;const{baseUrl:r,paths:i}=o.compilerOptions;if(!r)return null;const s=f.resolve(f.dirname(n),r),a=[];if(i)for(const[l,c]of Object.entries(i)){let d;l==="@"||l==="~"||l==="#"?d=new RegExp(`^${l}/(.+)$`):d=new RegExp(`^${[...l].map(u=>u==="*"?"(.+)":u.replace(/[\\^$*+?.()|[\]{}]/,"\\$&")).join("")}$`);let p=0;for(const u of c){const y=[...C.normalizePath(f.resolve(s,u))].map(h=>h==="*"?"$"+(++p+""):h==="$"?"$$":h).join("");a.push({find:d,replacement:y})}}return t&&a.push({find:/^(?!\.*\/|\.*$|\w:)(.+)$/,replacement:`${[...C.normalizePath(s)].map(l=>l==="$"?"$$":l).join("")}/$1`}),a},"getConfigAlias"),ut=ct((e,t)=>{const o=pt(e);return{name:"packem:resolve-tsconfig-paths",async resolveId(n,r,i){if(!o||n.includes("\0"))return null;for(const{find:s,replacement:a}of o)if(s.test(n)){const l=n.replace(s,a),c=await this.resolve(l,r,{skipSelf:!0,...i});if(c)return t.debug({message:`Resolved ${n} to ${c.id} using paths from tsconfig.json.`,prefix:"plugin:resolve-tsconfig-paths"}),c.id}return null}}},"resolveTsconfigPaths");var tr=Object.defineProperty,dt=m((e,t)=>tr(e,"name",{value:t,configurable:!0}),"u$4");const or=dt((e,t)=>{if(!t)return null;const{config:o,path:n}=t;if(!o.compilerOptions)return null;const{rootDirs:r}=o.compilerOptions;if(!r)return null;const i=[];for(const s of r){if(s.startsWith("."))throw new Error(`Invalid rootDir value '.' in ${n}.`);if(s.startsWith(".."))throw new Error(`Invalid rootDir value '..' in ${n}.`);i.push(f.resolve(e,s))}return i},"getRootDirectories"),ft=dt((e,t,o)=>{const n=or(e,o);return{name:"packem:resolve-tsconfig-root-dirs",async resolveId(r,i,s){if(n===null||n.length===0)return null;if(r.startsWith("."))for(const a of n){const l=f.join(a,r),c=await this.resolve(l,i,{skipSelf:!0,...s});if(c)return t.debug({message:`Resolved ${r} to ${c.id} using rootDirs from tsconfig.json.`,prefix:"plugin:resolve-tsconfig-root-dirs"}),c.id}return null}}},"resolveTsconfigRootDirectories");var nr=Object.defineProperty,rr=m((e,t)=>nr(e,"name",{value:t,configurable:!0}),"r$6");const mt=rr(()=>{const e=/\.(?:[mc]?js|jsx)$/;return{name:"packem:resolve-typescript-mjs-cjs",async resolveId(t,o,n){return e.test(t)&&o?await this.resolve(t.replace(/js(x?)$/,"ts$1"),o,n):null}}},"resolveTypescriptMjsCts");var ir=Object.defineProperty,gt=m((e,t)=>ir(e,"name",{value:t,configurable:!0}),"u$3");const _e=gt((e,t,o,n)=>{const r=e.findIndex(s=>typeof s=="object"?s.name===o:!1);if(r===-1)throw new Error(`Plugin with name "${o}" was not found, try one of: ${e.map(s=>{if(typeof s=="object")return s.name}).filter(Boolean).join(", ")}`);const i=n?r+1:r;return e.splice(i,0,t),e},"appendPlugin"),yt=gt((e,t)=>{if(!t)return e;for(const{after:o=void 0,before:n=void 0,plugin:r}of t)e=o?_e(e,r,o,!0):_e(e,r,n,!1);return e},"appendPlugins");var sr=Object.defineProperty,ar=m((e,t)=>sr(e,"name",{value:t,configurable:!0}),"s$8");const lr=ar(e=>{const t=f.basename(e).split(".");if(t.length>=2){const[o,n]=t.slice(-2),r=t[0],i=/^(\w+)-runtime$/.exec(o)?.[1];if(w.DEFAULT_EXTENSIONS.includes(n)&&i&&i.length>0)return r+"-"+i}},"getCustomModuleLayer");var cr=Object.defineProperty,pr=m((e,t)=>cr(e,"name",{value:t,configurable:!0}),"i$5");const ue=pr(e=>(e.preserveDirectives||{directives:[]}).directives.map(t=>t.replace(/^use /,"")).find(t=>t!=="strict"),"getModuleLayer");var ur=Object.defineProperty,Pe=m((e,t)=>ur(e,"name",{value:t,configurable:!0}),"d$8");const dr=Pe((e,t)=>{const o=new Map;return Pe(function(n,r){const i=r.getModuleInfo(n);if(!i)return;const{isEntry:s}=i,a=i.meta,l=ue(a);if(!s){const c=o.get(n);if(c)return c;const d=lr(n);if(d)return o.set(n,d),d}if(s){const c=r.getModuleIds();for(const d of c)r.getModuleInfo(d)&&ue(a)===l&&(e.has(d)||e.set(d,new Set),e.get(d).add([n,l]))}if(l&&!s&&e.has(n)){const c=[...e.get(n)];if(c.some(([p])=>{if(t.some(u=>u.path===p)){const u=r.getModuleInfo(p);return ue(u?u.meta:{})===l}return!1}))return;if(c.every(([,p])=>p===l))return o.has(n)?o.get(n):void 0;const d=f.basename(n,f.extname(n))+"-"+l;return o.set(n,d),d}},"splitChunks")},"createSplitChunks");var fr=Object.defineProperty,mr=m((e,t)=>fr(e,"name",{value:t,configurable:!0}),"n$4");const A=mr((e,t)=>e.isDynamicEntry?`${w.CHUNKS_PACKEM_FOLDER}/[name].${t}`:`${w.SHARED_PACKEM_FOLDER}/${e.name}-[hash].${t}`,"getChunkFilename");var gr=Object.defineProperty,yr=m((e,t)=>gr(e,"name",{value:t,configurable:!0}),"s$6");const hr=process.platform==="win32",Ce=yr((e,t)=>{const o=hr?"\\":"/";return e.name?.includes("node_modules"+o+".pnpm")?(e.name.replace("node_modules"+o+".pnpm","external")+"."+t).replace("node_modules"+o,""):e.name?.includes("node_modules")?e.name.replace("node_modules","external")+"."+t:"[name]."+t},"getEntryFileNames");var vr=Object.defineProperty,br=m((e,t)=>vr(e,"name",{value:t,configurable:!0}),"p$2");const be=br((e,t)=>{let o={};if(e.pkg.name&&(o[e.pkg.name]=e.options.rootDir),e.pkg.imports){const{imports:n}=e.pkg;for(const r in n){if(r.startsWith("#"))continue;const i=n[r];typeof i=="string"&&(o[r]=f.join(e.options.rootDir,i))}}return o={...o,...e.options.alias},e.options.rollup.alias&&(Array.isArray(e.options.rollup.alias.entries)?Object.assign(o,Object.fromEntries(e.options.rollup.alias.entries.map(n=>[n.find,n.replacement]))):Object.assign(o,e.options.rollup.alias.entries??e.options.rollup.alias)),e.logger.debug({message:"Resolved aliases: "+JSON.stringify(o),prefix:t}),o},"resolveAliases");var jr=Object.defineProperty,O=m((e,t)=>jr(e,"name",{value:t,configurable:!0}),"p$1");const wr=O((e,t)=>{if(e==="esbuild"){if(!t.options.rollup.esbuild)throw new Error("No esbuild options found in your configuration.");t.tsconfig?.config.compilerOptions?.target?.toLowerCase()==="es3"&&(t.logger.warn(["ES3 target is not supported by esbuild, so ES5 will be used instead..","Please set 'target' option in tsconfig to at least ES5 to disable this error"].join(" ")),t.tsconfig.config.compilerOptions.target="es5",t.options.rollup.esbuild.target="es5");let o="node"+he.versions.node.split(".")[0];if(t.pkg.engines?.node){const n=Z.minVersion(t.pkg.engines.node);n&&(o="node"+n.major)}if(t.options.rollup.esbuild.target){const n=W(t.options.rollup.esbuild.target);n.some(r=>r.startsWith("node"))||(t.options.rollup.esbuild.target=[...new Set([...W(o),...n])])}else t.options.rollup.esbuild.target=W(o);return t.tsconfig?.config.compilerOptions?.target==="es5"&&(t.options.rollup.esbuild.keepNames=!1,t.logger.debug("Disabling keepNames because target is set to es5")),{logger:t.logger,minify:t.options.minify,minifyWhitespace:t.options.minify,sourceMap:t.options.sourcemap,...t.options.rollup.esbuild}}if(e==="swc"){if(!t.options.rollup.swc)throw new Error("No swc options found in your configuration.");return{minify:t.options.minify,...t.options.rollup.swc,jsc:{minify:{compress:{directives:!1},format:{comments:"some"},mangle:{topLevel:!0},sourceMap:t.options.sourcemap,toplevel:t.options.emitCJS??t.options.emitESM},...t.options.rollup.swc.jsc},sourceMaps:t.options.sourcemap}}if(e==="sucrase"){if(!t.options.rollup.sucrase)throw new Error("No sucrase options found in your configuration.");return t.options.rollup.sucrase}throw new Error("A Unknown transformer was provided")},"getTransformerConfig"),ht=O((e,t)=>{if(e.code==="CIRCULAR_DEPENDENCY"&&/Circular dependency:[\s\S]*node_modules/.test(e.message))return!0;if(e.code==="UNRESOLVED_IMPORT")throw new Error(`Failed to resolve the module "${e.exporter}" imported by "${j.cyan(f.relative(f.resolve(),e.id))}"
@@ -62,10 +62,10 @@ ${s.chunks.map(c=>{const d=t.buildEntries.find(p=>p.path===c)??{};return j.gray(
62
62
  └─ `)+j.bold(o(a.path))+" (total size: "+j.cyan(P.formatBytes(a.bytes??0))+")");s+=`
63
63
 
64
64
  `,e.raw(s)}return n&&e.raw("Σ Total dist size (byte size):",j.cyan(P.formatBytes(t.buildEntries.reduce((s,a)=>s+(a.bytes??0),0))),`
65
- `),n},"showSizeInformation"),Cr=oe((e,t)=>{const o=Nr(e.options.entries,"environment","runtime"),n=[];for(const[r,i]of Object.entries(o))for(const[s,a]of Object.entries(i)){const l={...e};!e.options.dtsOnly&&(r!=="undefined"||s!=="undefined")&&e.logger.info("Preparing build for "+(r==="undefined"?"":j.cyan(r)+" environment"+(s==="undefined"?"":" with "))+(s==="undefined"?"":j.cyan(s)+" runtime")),l.options.rollup.replace?(l.options.rollup.replace.values===void 0&&(l.options.rollup.replace.values={}),r!=="undefined"&&(l.options.rollup.replace.values={...l.options.rollup.replace.values,[["process","env","NODE_ENV"].join(".")]:JSON.stringify(r)}),l.options.rollup.replace.values={...l.options.rollup.replace.values,[["process","env","EdgeRuntime"].join(".")]:JSON.stringify(s==="edge-light")}):e.logger.warn("'replace' plugin is disabled. You should enable it to replace 'process.env.*' environments.");let c="";r!=="undefined"&&(c+=r+"/"),s!=="undefined"&&(c+=s+"/");let d=!1;l.options.minify!==void 0&&(d=l.options.minify),r==="development"?d=!1:r==="production"&&(d=!0);const p=[],u=[],y=[],h=[];for(const g of a)g.cjs&&g.esm?p.push(g):g.cjs?y.push(g):g.esm?u.push(g):g.declaration&&h.push(g);if(p.length>0){const g={...l,options:{...l.options,emitCJS:!0,emitESM:!0,entries:p,minify:d}};if(e.options.dtsOnly||n.push(fe(g,t,c)),e.options.declaration){const v=g.options.entries.filter(E=>E.declaration);v.length>0&&n.push(H({...g,options:{...g.options,entries:v}},t,c))}}if(u.length>0){const g={...l,options:{...l.options,emitCJS:!1,emitESM:!0,entries:u,minify:d}};if(e.options.dtsOnly||n.push(fe(g,t,c)),e.options.declaration){const v=g.options.entries.filter(E=>E.declaration);v.length>0&&n.push(H({...g,options:{...g.options,entries:v}},t,c))}}if(y.length>0){const g={...l,options:{...l.options,emitCJS:!0,emitESM:!1,entries:y,minify:d}};if(e.options.dtsOnly||n.push(fe(g,t,c)),e.options.declaration){const v=g.options.entries.filter(E=>E.declaration);v.length>0&&n.push(H({...g,options:{...g.options,entries:v}},t,c))}}if(l.options.declaration&&h.length>0){const g={...l,options:{...l.options,emitCJS:!1,emitESM:!1,entries:h,minify:d}};n.push(H(g,t,c))}}return n.filter(Boolean)},"prepareRollupConfig"),Rr=oe(async(e,t)=>{await e.hooks.callHook("build:before",e),await Promise.all(Cr(e,t)),e.logger.success(j.green(e.options.name?"Build succeeded for "+e.options.name:"Build succeeded"));for await(const o of $.walk(f.join(e.options.rootDir,e.options.outDir))){let n=e.buildEntries.find(r=>f.join(e.options.rootDir,e.options.outDir,r.path)===o.path);if(n||(n={chunk:!0,path:o.path},e.buildEntries.push(n)),!n.bytes){const r=await ie.stat(f.resolve(e.options.rootDir,e.options.outDir,o.path));n.bytes=r.size}}return await e.hooks.callHook("build:done",e),Pr(e.logger,e)},"build");var Tr=Object.defineProperty,Ar=m((e,t)=>Tr(e,"name",{value:t,configurable:!0}),"r$4");const k=Ar((e,t)=>{e.warnings.has(t)||e.warnings.add(t)},"warn");var Ir=Object.defineProperty,wt=m((e,t)=>Ir(e,"name",{value:t,configurable:!0}),"t$4");const ne=wt(e=>{if(e.endsWith(".mjs")||e.endsWith(".d.mts"))return"esm";if(e.endsWith(".cjs")||e.endsWith(".d.cts"))return"cjs"},"inferExportTypeFromFileName"),ye=wt((e,t,o,n)=>{if(e==="module-sync")return"esm";if(n){const s=ne(n);if(s)return s}if(e==="module"||e==="import")return"esm";if(e==="require")return"cjs";if(t.length===0)return o;const[r,...i]=t;return ye(r,i,o,n)},"inferExportType");var Mr=Object.defineProperty,Fr=m((e,t)=>Mr(e,"name",{value:t,configurable:!0}),"y$1");const Jr=new Set(["electron","import","require","node","node-addons","default","types","deno","browser","module-sync","bun","workerd",...w.RUNTIME_EXPORT_CONVENTIONS,...w.SPECIAL_EXPORT_CONVENTIONS]),je=Fr((e,t,o,n=[])=>{if(!e)return[];if(typeof e=="string"){const r=ne(e);if(r&&r!==t)throw new Error(`Exported file "${e}" has an extension that does not match the package.json type "${t==="esm"?"module":"commonjs"}".`);return[{file:e,key:"exports",type:r??t}]}if(typeof e=="object"){const r=Object.entries(e).filter(([s])=>!s.endsWith(".json"));let i=[];for(const[s,a]of r)if(typeof a=="string"){let l={};Number.isInteger(+s)?l={exportKey:"*"}:s.startsWith("./")?l={exportKey:s.replace("./","")}:l={exportKey:s==="."?".":"*",subKey:s},i.push({...l,file:a,key:"exports",type:ye(s,n,t,a)})}else if(typeof a=="object"&&a!==null)for(const[l,c]of Object.entries(a)){if(o===!1&&l==="types")return[];const d=Number.isInteger(+s)?l:s;typeof c=="string"?i.push({exportKey:d.replace("./",""),file:c,key:"exports",...Jr.has(l)?{subKey:l}:{},type:ye(l,n,t,c)}):i=[...i,...je({[d]:c},t,o,[...n,l])]}return i}return[]},"extractExportFilenames");var Lr=Object.defineProperty,le=m((e,t)=>Lr(e,"name",{value:t,configurable:!0}),"c$3");const qr=le((e,t)=>e.key==="exports"&&e.subKey===w.PRODUCTION_ENV?w.PRODUCTION_ENV:e.key==="exports"&&e.subKey===w.DEVELOPMENT_ENV?w.DEVELOPMENT_ENV:t,"getEnvironment"),Y=le((e,t,o,n,r,i,s)=>{const a=qr(r,i.environment);let l="node";for(const p of w.RUNTIME_EXPORT_CONVENTIONS)if(r.file.includes("."+p+".")||r.subKey===p){l=p;break}let c=e.find(p=>p.input===t&&p.environment===a&&p.runtime===l);c===void 0?c=e[e.push({environment:a,exportKey:new Set([r.exportKey].filter(Boolean)),input:t,runtime:l})-1]:c.exportKey&&r.exportKey&&c.exportKey.add(r.exportKey),s&&(c.isGlob=!0),o&&(c.outDir=n),r.isExecutable?(c.executable=!0,c.declaration=!1,r.type==="cjs"?c.cjs=!0:r.type==="esm"&&(c.esm=!0)):(/\.d\.[mc]?ts$/.test(r.file)&&i.options.declaration!==!1&&(c.declaration=i.options.declaration),r.type==="cjs"?c.cjs=!0:r.type==="esm"&&(c.esm=!0));const d=r.file.replace(f.extname(r.file),"").replace(new RegExp(`^./${i.options.outDir.replace(/^\.\//,"")}/`),"");w.SPECIAL_EXPORT_CONVENTIONS.has(r.subKey)&&!t.includes(d)&&(c.fileAlias=d)},"createOrUpdateEntry");let Ie=!1;const Me=le(e=>{if(e.pkg?.dependencies?.typescript===void 0&&e.pkg?.devDependencies?.typescript===void 0)throw new Error("You tried to use a `.ts`, `.cts` or `.mts` file but `typescript` was not found in your package.json.")},"validateIfTypescriptIsInstalled"),Br=le((e,t,o)=>{const n=[];t.sort((a,l)=>a.split("/").length-l.split("/").length);const r=e.type==="module"?"esm":"cjs";r==="esm"&&(o.options.emitESM=!0),r==="cjs"&&(o.options.emitCJS=!0);const i=je(e.exports,r,o.options.declaration);if(e.bin){const a=(typeof e.bin=="string"?[e.bin]:Object.values(e.bin)).filter(Boolean);for(const l of a){const c=ne(l);if(c&&c!==r)throw new Error(`Exported file "${l}" has an extension that does not match the package.json type "${e.type??"commonjs"}".`);i.push({file:l,isExecutable:!0,key:"bin",type:c??r})}}e.main&&i.push({file:e.main,key:"main",type:ne(e.main)??r}),e.module&&i.push({file:e.module,key:"module",type:"esm"}),(e.types||e.typings)&&(Me(o),o.options.declaration===void 0&&(o.options.declaration="compatible"),i.push({file:e.types??e.typings,key:"types"}));const s=[];for(const a of i){o.options.declaration===void 0&&(a.key==="types"||a.subKey==="types")&&(o.options.declaration=a.file.includes(".d.ts")?"compatible":!0),o.options.emitCJS===void 0&&a.type==="cjs"&&(o.options.emitCJS=!0),o.options.emitESM===void 0&&a.type==="esm"&&(o.options.emitESM=!0);const l=a.file.replace(/(?:\*[^/\\]|\.d\.[mc]?ts|\.\w+)$/,""),c=l.endsWith("/");if(c&&["./","/"].includes(l))continue;const d=l.replace(new RegExp("(./)?"+o.options.outDir),o.options.sourceDir).replace("./",""),p="(?<=/|$)",u=c?"":"\\.\\w+$";if(a.file.includes("/*")&&a.key==="exports"){Ie||(o.logger.debug("Private subfolders are not supported, if you need this feature please open an issue on GitHub."),Ie=!0);const v=[],E=new RegExp(p+d.replace("*","(.*)")+u),x=new RegExp(p+d.replace(/(.*)\.[^.]*$/,"$1").replace("*","(.*)")+u);for(const b of t)(E.test(b)||w.SPECIAL_EXPORT_CONVENTIONS.has(a.subKey)&&x.test(b))&&v.push(b);if(v.length===0){n.push(`Could not find entrypoint for \`${a.file}\``);continue}for(const b of v)Y(s,b,c,l,a,o,!0);continue}const y=new RegExp(p+d+u);let h=t.find(v=>y.test(v));if(w.SPECIAL_EXPORT_CONVENTIONS.has(a.subKey)&&h===void 0){const v=new RegExp(p+d.replace(/(.*)\.[^.]*$/,"$1")+u);h=t.find(E=>v.test(E))}if(h===void 0){$.isAccessibleSync(f.resolve(o.options.rootDir,a.file))||n.push(`Could not find entrypoint for \`${a.file}\``);continue}(h.endsWith(".ts")||h.endsWith(".cts")||h.endsWith(".mts"))&&$.isAccessibleSync(h)&&Me(o);const g=f.toNamespacedPath(h.replace(w.ENDING_RE,""));$.isAccessibleSync(g+".cts")&&$.isAccessibleSync(g+".mts")?(Y(s,g+".cts",c,l,{...a,type:"cjs"},o,!1),Y(s,g+".mts",c,l,{...a,type:"esm"},o,!1)):Y(s,h,c,l,a,o,!1)}return{entries:s,warnings:n}},"inferEntries");var Wr=Object.defineProperty,Ur=m((e,t)=>Wr(e,"name",{value:t,configurable:!0}),"o$2");const Vr=Ur((e,t)=>{const{publishConfig:o}=e;return o&&(o.bin&&(typeof o.bin=="object"||typeof o.bin=="string")&&(e.bin=o.bin),o.type&&typeof o.type=="string"&&o.type!==""&&(e.type=o.type),o.main&&typeof o.main=="string"&&o.main!==""&&(e.main=o.main),o.module&&typeof o.module=="string"&&o.module!==""&&(e.module=o.module),t===void 0&&o.types&&typeof o.types=="string"&&o.types!==""?e.types=o.types:t===void 0&&o.typings&&typeof o.typings=="string"&&o.typings!==""&&(e.typings=o.typings),o.exports&&typeof o.exports=="object"&&(e.exports=o.exports)),e},"overwriteWithPublishConfig");var zr=Object.defineProperty,Gr=m((e,t)=>zr(e,"name",{value:t,configurable:!0}),"t$3");const Kr={hooks:{"build:prepare":Gr(function(e){if(e.options.entries.length>0)return;const t=f.join(e.options.rootDir,e.options.sourceDir);if(!V.existsSync(t))throw new Error("No 'src' directory found. Please provide entries manually.");const o=$.collectSync(t,{extensions:[],includeDirs:!1,includeSymlinks:!1});if(o.length===0)throw new Error("No source files found in 'src' directory. Please provide entries manually.");let n={...e.pkg};n.publishConfig&&(e.logger.info('Using publishConfig found in package.json, to override the default key-value pairs of "'+Object.keys(n.publishConfig).join(", ")+'".'),e.logger.debug(n.publishConfig),n=Vr(n,e.options.declaration));const r=Br(n,o,e);for(const i of r.warnings)k(e,i);if(e.options.entries.push(...r.entries),e.options.entries.length===0)throw new Error("No entries detected. Please provide entries manually.");e.logger.info("Automatically detected entries:",j.cyan(e.options.entries.map(i=>i.fileAlias?j.bold(i.fileAlias)+" => "+j.bold(i.input.replace(`${e.options.rootDir}/`,"").replace(/\/$/,"/*")):j.bold(i.input.replace(`${e.options.rootDir}/`,"").replace(/\/$/,"/*"))).join(", ")),j.gray([e.options.emitESM&&"esm",e.options.emitCJS&&"cjs",e.options.declaration&&"dts"].filter(Boolean).map(i=>`[${i}]`).join(" ")))},"build:prepare")}};var Xr=Object.defineProperty,Hr=m((e,t)=>Xr(e,"name",{value:t,configurable:!0}),"t$2");const Yr=Hr(async(e,t)=>{if(e==="auto")e=Kr;else{if(e==="none")return{};typeof e=="string"&&(e=await t.import(e)||{})}return typeof e=="function"&&(e=e()),e},"resolvePreset");var Qr=Object.defineProperty,Zr=m((e,t)=>Qr(e,"name",{value:t,configurable:!0}),"j");const ei=Zr(async e=>{const t=e.options.jiti.transformOptions?.babel?.plugins,o=[],n=JSON.stringify({...e.options.jiti,alias:{...be(e,"jit"),...e.options.jiti.alias},transformOptions:{...e.options.jiti.transformOptions,babel:{...e.options.jiti.transformOptions?.babel,plugins:"__$BABEL_PLUGINS"}}},null,2).replace('"__$BABEL_PLUGINS"',Array.isArray(t)?"["+t.map((r,i)=>{if(Array.isArray(r)){const[s,...a]=r;return o.push(s),"["+["plugin"+i,...a.map(l=>JSON.stringify(l))].join(", ")+"]"}return o.push(r),"plugin"+i}).join(",")+"]":"[]");for(const r of e.options.entries){const i=f.resolve(e.options.rootDir,e.options.outDir,r.name),s=f.normalize(e.jiti.esmResolve(r.input,{try:!0})??r.input),a=s.replace(w.ENDING_RE,""),l=$.readFileSync(s),c=Bn(l);let d=[];try{d=await B.resolveModuleExportNames(s,{extensions:w.DEFAULT_EXTENSIONS})}catch(u){k(e,`Cannot analyze ${s} for exports: ${u.toString()}`);return}const p=d.includes("default")||d.length===0;if(e.options.emitESM){const u=f.relative(f.dirname(i),await B.resolvePath("jiti",{conditions:["node","import"],url:typeof document>"u"?require("url").pathToFileURL(__filename).href:J&&J.tagName.toUpperCase()==="SCRIPT"&&J.src||new URL("create-bundler.cjs",document.baseURI).href})),y=a+".d.mts";$.writeFileSync(`${i}.mjs`,c+['import { createJiti } from "'+u+'";',...o.map((h,g)=>"import plugin"+g+' from "'+h+'";'),"","const jiti = createJiti(import.meta.url, "+n+");","",'/** @type {import("'+y+'")} */','const _module = await jiti.import("'+s+'");',p?`
65
+ `),n},"showSizeInformation"),Cr=oe((e,t)=>{const o=Nr(e.options.entries,"environment","runtime"),n=[];for(const[r,i]of Object.entries(o))for(const[s,a]of Object.entries(i)){const l={...e};!e.options.dtsOnly&&(r!=="undefined"||s!=="undefined")&&e.logger.info("Preparing build for "+(r==="undefined"?"":j.cyan(r)+" environment"+(s==="undefined"?"":" with "))+(s==="undefined"?"":j.cyan(s)+" runtime")),l.options.rollup.replace?(l.options.rollup.replace.values===void 0&&(l.options.rollup.replace.values={}),r!=="undefined"&&(l.options.rollup.replace.values={...l.options.rollup.replace.values,[["process","env","NODE_ENV"].join(".")]:JSON.stringify(r)}),l.options.rollup.replace.values={...l.options.rollup.replace.values,[["process","env","EdgeRuntime"].join(".")]:JSON.stringify(s==="edge-light")}):e.logger.warn("'replace' plugin is disabled. You should enable it to replace 'process.env.*' environments.");let c="";r!=="undefined"&&(c+=r+"/"),s!=="undefined"&&(c+=s+"/");let d=!1;l.options.minify!==void 0&&(d=l.options.minify),r==="development"?d=!1:r==="production"&&(d=!0);const p=[],u=[],y=[],h=[];for(const g of a)g.cjs&&g.esm?p.push(g):g.cjs?y.push(g):g.esm?u.push(g):g.declaration&&h.push(g);if(p.length>0){const g={...l,options:{...l.options,emitCJS:!0,emitESM:!0,entries:p,minify:d}};if(e.options.dtsOnly||n.push(fe(g,t,c)),e.options.declaration){const v=g.options.entries.filter(E=>E.declaration);v.length>0&&n.push(H({...g,options:{...g.options,entries:v}},t,c))}}if(u.length>0){const g={...l,options:{...l.options,emitCJS:!1,emitESM:!0,entries:u,minify:d}};if(e.options.dtsOnly||n.push(fe(g,t,c)),e.options.declaration){const v=g.options.entries.filter(E=>E.declaration);v.length>0&&n.push(H({...g,options:{...g.options,entries:v}},t,c))}}if(y.length>0){const g={...l,options:{...l.options,emitCJS:!0,emitESM:!1,entries:y,minify:d}};if(e.options.dtsOnly||n.push(fe(g,t,c)),e.options.declaration){const v=g.options.entries.filter(E=>E.declaration);v.length>0&&n.push(H({...g,options:{...g.options,entries:v}},t,c))}}if(l.options.declaration&&h.length>0){const g={...l,options:{...l.options,emitCJS:!1,emitESM:!1,entries:h,minify:d}};n.push(H(g,t,c))}}return n.filter(Boolean)},"prepareRollupConfig"),Rr=oe(async(e,t)=>{await e.hooks.callHook("build:before",e),await Promise.all(Cr(e,t)),e.logger.success(j.green(e.options.name?"Build succeeded for "+e.options.name:"Build succeeded"));for await(const o of $.walk(f.join(e.options.rootDir,e.options.outDir))){let n=e.buildEntries.find(r=>f.join(e.options.rootDir,e.options.outDir,r.path)===o.path);if(n||(n={chunk:!0,path:o.path},e.buildEntries.push(n)),!n.bytes){const r=await ie.stat(f.resolve(e.options.rootDir,e.options.outDir,o.path));n.bytes=r.size}}return await e.hooks.callHook("build:done",e),Pr(e.logger,e)},"build");var Tr=Object.defineProperty,Ar=m((e,t)=>Tr(e,"name",{value:t,configurable:!0}),"r$4");const k=Ar((e,t)=>{e.warnings.has(t)||e.warnings.add(t)},"warn");var Ir=Object.defineProperty,wt=m((e,t)=>Ir(e,"name",{value:t,configurable:!0}),"t$4");const ne=wt(e=>{if(e.endsWith(".mjs")||e.endsWith(".d.mts"))return"esm";if(e.endsWith(".cjs")||e.endsWith(".d.cts"))return"cjs"},"inferExportTypeFromFileName"),ye=wt((e,t,o,n)=>{if(e==="module-sync")return"esm";if(n){const s=ne(n);if(s)return s}if(e==="module"||e==="import")return"esm";if(e==="require")return"cjs";if(t.length===0)return o;const[r,...i]=t;return ye(r,i,o,n)},"inferExportType");var Mr=Object.defineProperty,Fr=m((e,t)=>Mr(e,"name",{value:t,configurable:!0}),"y$1");const Jr=new Set(["electron","import","require","node","node-addons","default","types","deno","browser","module-sync","bun","workerd",...w.RUNTIME_EXPORT_CONVENTIONS,...w.SPECIAL_EXPORT_CONVENTIONS]),je=Fr((e,t,o,n=[])=>{if(!e)return[];if(typeof e=="string"){const r=ne(e);if(r&&r!==t)throw new Error(`Exported file "${e}" has an extension that does not match the package.json type "${t==="esm"?"module":"commonjs"}".`);return[{file:e,key:"exports",type:r??t}]}if(typeof e=="object"){const r=Object.entries(e).filter(([s])=>!s.endsWith(".json"));let i=[];for(const[s,a]of r)if(typeof a=="string"){let l={};Number.isInteger(+s)?l={exportKey:"*"}:s.startsWith("./")?l={exportKey:s.replace("./","")}:l={exportKey:s==="."?".":"*",subKey:s},i.push({...l,file:a,key:"exports",type:ye(s,n,t,a)})}else if(typeof a=="object"&&a!==null)for(const[l,c]of Object.entries(a)){if(o===!1&&l==="types")return[];const d=Number.isInteger(+s)?l:s;typeof c=="string"?i.push({exportKey:d.replace("./",""),file:c,key:"exports",...Jr.has(l)?{subKey:l}:{},type:ye(l,n,t,c)}):i=[...i,...je({[d]:c},t,o,[...n,l])]}return i}return[]},"extractExportFilenames");var Lr=Object.defineProperty,le=m((e,t)=>Lr(e,"name",{value:t,configurable:!0}),"c$3");const qr=le((e,t)=>e.key==="exports"&&e.subKey===w.PRODUCTION_ENV?w.PRODUCTION_ENV:e.key==="exports"&&e.subKey===w.DEVELOPMENT_ENV?w.DEVELOPMENT_ENV:t,"getEnvironment"),Y=le((e,t,o,n,r,i,s)=>{const a=qr(r,i.environment);let l="node";for(const p of w.RUNTIME_EXPORT_CONVENTIONS)if(r.file.includes("."+p+".")||r.subKey===p){l=p;break}let c=e.find(p=>p.input===t&&p.environment===a&&p.runtime===l);c===void 0?c=e[e.push({environment:a,exportKey:new Set([r.exportKey].filter(Boolean)),input:t,runtime:l})-1]:c.exportKey&&r.exportKey&&c.exportKey.add(r.exportKey),s&&(c.isGlob=!0),o&&(c.outDir=n),r.isExecutable?(c.executable=!0,c.declaration=!1,r.type==="cjs"?c.cjs=!0:r.type==="esm"&&(c.esm=!0)):(/\.d\.[mc]?ts$/.test(r.file)&&i.options.declaration!==!1&&(c.declaration=i.options.declaration),r.type==="cjs"?c.cjs=!0:r.type==="esm"&&(c.esm=!0));const d=r.file.replace(f.extname(r.file),"").replace(new RegExp(`^./${i.options.outDir.replace(/^\.\//,"")}/`),"");w.SPECIAL_EXPORT_CONVENTIONS.has(r.subKey)&&!t.includes(d)&&(c.fileAlias=d)},"createOrUpdateEntry");let Ie=!1;const Me=le(e=>{if(e.pkg?.dependencies?.typescript===void 0&&e.pkg?.devDependencies?.typescript===void 0)throw new Error("You tried to use a `.ts`, `.cts` or `.mts` file but `typescript` was not found in your package.json.")},"validateIfTypescriptIsInstalled"),Br=le((e,t,o)=>{const n=[];t.sort((a,l)=>a.split("/").length-l.split("/").length);const r=e.type==="module"?"esm":"cjs";r==="esm"&&(o.options.emitESM=!0),r==="cjs"&&(o.options.emitCJS=!0);const i=je(e.exports,r,o.options.declaration);if(e.bin){const a=(typeof e.bin=="string"?[e.bin]:Object.values(e.bin)).filter(Boolean);for(const l of a){const c=ne(l);if(c&&c!==r)throw new Error(`Exported file "${l}" has an extension that does not match the package.json type "${e.type??"commonjs"}".`);i.push({file:l,isExecutable:!0,key:"bin",type:c??r})}}e.main&&i.push({file:e.main,key:"main",type:ne(e.main)??r}),e.module&&i.push({file:e.module,key:"module",type:"esm"}),(e.types||e.typings)&&(Me(o),o.options.declaration===void 0&&(o.options.declaration="compatible"),i.push({file:e.types??e.typings,key:"types"}));const s=[];for(const a of i){o.options.declaration===void 0&&(a.key==="types"||a.subKey==="types")&&(o.options.declaration=a.file.includes(".d.ts")?"compatible":!0),o.options.emitCJS===void 0&&a.type==="cjs"&&(o.options.emitCJS=!0),o.options.emitESM===void 0&&a.type==="esm"&&(o.options.emitESM=!0);const l=a.file.replace(/(?:\*[^/\\]|\.d\.[mc]?ts|\.\w+)$/,""),c=l.endsWith("/");if(c&&["./","/"].includes(l))continue;const d=l.replace(new RegExp("(./)?"+o.options.outDir),o.options.sourceDir).replace("./",""),p="(?<=/|$)",u=c?"":"\\.\\w+$";if(a.file.includes("/*")&&a.key==="exports"){Ie||(o.logger.debug("Private subfolders are not supported, if you need this feature please open an issue on GitHub."),Ie=!0);const v=[],E=new RegExp(p+d.replace("*","(.*)")+u),x=new RegExp(p+d.replace(/(.*)\.[^.]*$/,"$1").replace("*","(.*)")+u);for(const b of t)(E.test(b)||w.SPECIAL_EXPORT_CONVENTIONS.has(a.subKey)&&x.test(b))&&v.push(b);if(v.length===0){n.push(`Could not find entrypoint for \`${a.file}\``);continue}for(const b of v)Y(s,b,c,l,a,o,!0);continue}const y=new RegExp(p+d+u);let h=t.find(v=>y.test(v));if(w.SPECIAL_EXPORT_CONVENTIONS.has(a.subKey)&&h===void 0){const v=new RegExp(p+d.replace(/(.*)\.[^.]*$/,"$1")+u);h=t.find(E=>v.test(E))}if(h===void 0){$.isAccessibleSync(f.resolve(o.options.rootDir,a.file))||n.push(`Could not find entrypoint for \`${a.file}\``);continue}(h.endsWith(".ts")||h.endsWith(".cts")||h.endsWith(".mts"))&&$.isAccessibleSync(h)&&Me(o);const g=f.toNamespacedPath(h.replace(w.ENDING_RE,""));$.isAccessibleSync(g+".cts")&&$.isAccessibleSync(g+".mts")?(Y(s,g+".cts",c,l,{...a,type:"cjs"},o,!1),Y(s,g+".mts",c,l,{...a,type:"esm"},o,!1)):Y(s,h,c,l,a,o,!1)}return{entries:s,warnings:n}},"inferEntries");var Wr=Object.defineProperty,Ur=m((e,t)=>Wr(e,"name",{value:t,configurable:!0}),"o$2");const Vr=Ur((e,t)=>{const{publishConfig:o}=e;return o&&(o.bin&&(typeof o.bin=="object"||typeof o.bin=="string")&&(e.bin=o.bin),o.type&&typeof o.type=="string"&&o.type!==""&&(e.type=o.type),o.main&&typeof o.main=="string"&&o.main!==""&&(e.main=o.main),o.module&&typeof o.module=="string"&&o.module!==""&&(e.module=o.module),t===void 0&&o.types&&typeof o.types=="string"&&o.types!==""?e.types=o.types:t===void 0&&o.typings&&typeof o.typings=="string"&&o.typings!==""&&(e.typings=o.typings),o.exports&&typeof o.exports=="object"&&(e.exports=o.exports)),e},"overwriteWithPublishConfig");var zr=Object.defineProperty,Gr=m((e,t)=>zr(e,"name",{value:t,configurable:!0}),"t$3");const Kr={hooks:{"build:prepare":Gr(function(e){if(e.options.entries.length>0)return;const t=f.join(e.options.rootDir,e.options.sourceDir);if(!V.existsSync(t))throw new Error("No 'src' directory found. Please provide entries manually.");const o=$.collectSync(t,{extensions:[],includeDirs:!1,includeSymlinks:!1});if(o.length===0)throw new Error("No source files found in 'src' directory. Please provide entries manually.");let n={...e.pkg};n.publishConfig&&(e.logger.info('Using publishConfig found in package.json, to override the default key-value pairs of "'+Object.keys(n.publishConfig).join(", ")+'".'),e.logger.debug(n.publishConfig),n=Vr(n,e.options.declaration));const r=Br(n,o,e);for(const i of r.warnings)k(e,i);if(e.options.entries.push(...r.entries),e.options.entries.length===0)throw new Error("No entries detected. Please provide entries manually.");e.logger.info("Automatically detected entries:",j.cyan(e.options.entries.map(i=>i.fileAlias?j.bold(i.fileAlias)+" => "+j.bold(i.input.replace(`${e.options.rootDir}/`,"").replace(/\/$/,"/*")):j.bold(i.input.replace(`${e.options.rootDir}/`,"").replace(/\/$/,"/*"))).join(", ")),j.gray([e.options.emitESM&&"esm",e.options.emitCJS&&"cjs",e.options.declaration&&"dts"].filter(Boolean).map(i=>`[${i}]`).join(" ")))},"build:prepare")}};var Xr=Object.defineProperty,Hr=m((e,t)=>Xr(e,"name",{value:t,configurable:!0}),"t$2");const Yr=Hr(async(e,t)=>{if(e==="auto")e=Kr;else{if(e==="none")return{};typeof e=="string"&&(e=await t.import(e)||{})}return typeof e=="function"&&(e=e()),e},"resolvePreset");var Qr=Object.defineProperty,Zr=m((e,t)=>Qr(e,"name",{value:t,configurable:!0}),"j");const ei=Zr(async e=>{const t=e.options.jiti.transformOptions?.babel?.plugins,o=[],n=JSON.stringify({...e.options.jiti,alias:{...be(e,"jit"),...e.options.jiti.alias},transformOptions:{...e.options.jiti.transformOptions,babel:{...e.options.jiti.transformOptions?.babel,plugins:"__$BABEL_PLUGINS"}}},null,2).replace('"__$BABEL_PLUGINS"',Array.isArray(t)?"["+t.map((r,i)=>{if(Array.isArray(r)){const[s,...a]=r;return o.push(s),"["+["plugin"+i,...a.map(l=>JSON.stringify(l))].join(", ")+"]"}return o.push(r),"plugin"+i}).join(",")+"]":"[]");for(const r of e.options.entries){const i=f.resolve(e.options.rootDir,e.options.outDir,r.name),s=L.fileURLToPath(e.jiti.esmResolve(r.input,{try:!0})??r.input),a=s.replace(w.ENDING_RE,""),l=$.readFileSync(s),c=Bn(l);let d=[];try{d=await L.resolveModuleExportNames(s,{extensions:w.DEFAULT_EXTENSIONS})}catch(u){k(e,`Cannot analyze ${s} for exports: ${u.toString()}`);return}const p=d.includes("default")||d.length===0;if(e.options.emitESM){const u=f.relative(f.dirname(i),await L.resolvePath("jiti",{conditions:["node","import"],url:typeof document>"u"?require("url").pathToFileURL(__filename).href:J&&J.tagName.toUpperCase()==="SCRIPT"&&J.src||new URL("create-bundler.cjs",document.baseURI).href})),y=a+".d.mts";$.writeFileSync(`${i}.mjs`,c+['import { createJiti } from "'+u+'";',...o.map((h,g)=>"import plugin"+g+' from "'+h+'";'),"","const jiti = createJiti(import.meta.url, "+n+");","",'/** @type {import("'+y+'")} */','const _module = await jiti.import("'+s+'");',p?`
66
66
  export default _module;`:"",...d.filter(h=>h!=="default").map(h=>`export const ${h} = _module.${h};`)].join(`
67
67
  `)),e.options.declaration&&$.writeFileSync(`${i}.d.mts`,'export * from "'+y+`";
68
- `+(p?'export { default } from "'+y+'";':""))}if(e.options.emitCJS){const u=f.relative(f.dirname(i),await B.resolvePath("jiti",{conditions:["node","require"],url:typeof document>"u"?require("url").pathToFileURL(__filename).href:J&&J.tagName.toUpperCase()==="SCRIPT"&&J.src||new URL("create-bundler.cjs",document.baseURI).href})),y=a+".d.cts";$.writeFileSync(`${i}.cjs`,c+['const { createJiti } = require("'+u+'");',...o.map((h,g)=>"const plugin"+g+" = require("+JSON.stringify(h)+")"),"","const jiti = createJiti(__filename, "+n+");","",'/** @type {import("'+y+'")} */','module.exports = jiti("'+s+'")'].join(`
68
+ `+(p?'export { default } from "'+y+'";':""))}if(e.options.emitCJS){const u=f.relative(f.dirname(i),await L.resolvePath("jiti",{conditions:["node","require"],url:typeof document>"u"?require("url").pathToFileURL(__filename).href:J&&J.tagName.toUpperCase()==="SCRIPT"&&J.src||new URL("create-bundler.cjs",document.baseURI).href})),y=a+".d.cts";$.writeFileSync(`${i}.cjs`,c+['const { createJiti } = require("'+u+'");',...o.map((h,g)=>"const plugin"+g+" = require("+JSON.stringify(h)+")"),"","const jiti = createJiti(__filename, "+n+");","",'/** @type {import("'+y+'")} */','module.exports = jiti("'+s+'")'].join(`
69
69
  `)),e.options.declaration&&$.writeFileSync(i+".d.cts",'export * from "'+y+`";
70
70
  `+(p?'export { default } from "'+y+'";':""))}c&&(await ge(`${i}.cjs`),await ge(`${i}.mjs`))}await e.hooks.callHook("rollup:done",e)},"createStub");var ti=Object.defineProperty,we=m((e,t)=>ti(e,"name",{value:t,configurable:!0}),"i$3");const oi=we(e=>{const{message:t,name:o="Error",stack:n}=e;if(!n)return n;const r=`${o}: ${t}
71
71
  `;return n.startsWith(r)?n.slice(r.length):n},"extractStack"),ni=we(e=>`
@@ -98,8 +98,8 @@ The published ${y} artifact additionally contains code with the following licens
98
98
  Because none of the third-party transpiler, packem uses under the hood is type-aware, some techniques or features often used in TypeScript are not properly checked and can cause mis-compilation or even runtime errors.
99
99
  To mitigate this, you should set the isolatedModules option to true in tsconfig and let your IDE warn you when such incompatible constructs are used.`),await $i(u),u},"createContext"),Vi=N(async e=>{const t=[];if(e.options.clean)for(const o of new Set(e.options.entries.map(n=>n.outDir).filter(Boolean).sort()))o===e.options.rootDir||o===e.options.sourceDir||e.options.rootDir.startsWith(o.endsWith("/")?o:`${o}/`)||t.some(n=>o.startsWith(n))||(t.push(o),e.logger.info(`Cleaning dist directory: \`./${f.relative(e.options.rootDir,o)}\``),await $.emptyDir(o))},"cleanDistributionDirectories"),zi=N(async(e,t,o)=>{if(e&&$.isAccessibleSync(f.join(e,"keystore1.json"))){const n=$.readJsonSync(f.join(e,"keystore.json")),r=V.readdirSync(e,{withFileTypes:!0}).filter(s=>s.isDirectory());let i=o;for await(const s of r)n[s.name]||(await ie.rm(f.join(e,s.name),{force:!0,recursive:!0}),i&&t.raw(`
100
100
 
101
- `),t.info({message:"Removing "+s.name+" file cache, the cache key is not used anymore.",prefix:"file-cache"}),i=!1)}},"removeOldCacheFolders"),Gi=N(e=>{switch(e){case"jit":return"Stubbing";case"watch":return"Watching";case"tsdoc":return"Generating TSDoc";default:return"Building"}},"getMode"),Ki=N(async(e,t,o,n,r={})=>{const{configPath:i,debug:s,tsconfigPath:a,...l}=r;n.wrapAll(),e=f.resolve(he.cwd(),e),n.debug("Root directory:",e);const{packageJson:c,packageJsonPath:d}=xt(e);n.debug("Using package.json found at",d);let p;if(a){const h=f.join(e,a);if(!await $.isAccessible(h))throw new Error("tsconfig.json not found at "+h);p={config:$e.readTsConfig(h),path:h},n.info("Using tsconfig settings at",h)}else if(c.dependencies?.typescript||c.devDependencies?.typescript)try{p=await $e.findTsConfig(e),n.debug("Using tsconfig settings found at",p.path)}catch{n.info("No tsconfig.json or jsconfig.json found.")}const u=At.findCacheDirSync("@visulima/packem",{cwd:e});let y=!1;try{let h=i??"";if(!h){const L=["packem.config.js","packem.config.mjs","packem.config.cjs","packem.config.ts","packem.config.cts","packem.config.mts"];for(const F of L)if($.isAccessibleSync(f.join(e,F))){h="./"+F;break}}const g=Ue.createJiti(e,{debug:s,interopDefault:!0});if(!/\.(?:js|mjs|cjs|ts|cts|mts)$/.test(h))throw new Error("Invalid packem config file extension. Only .js, .mjs, .cjs, .ts, .cts and .mts extensions are allowed.");let v=await g.import(h,{try:!0})||{};typeof v=="function"&&(v=await v(o,t)),n.debug("Using packem config found at",f.join(e,h));const E=T(JSON.stringify({version:c.version,...c.dependencies,...c.devDependencies,...c.peerDependencies,...c.peerDependenciesMeta,browser:c.browser,eNode:c.engines?.node,exports:c.exports,main:c.main,module:c.module,type:c.type,types:c.types}))+T(JSON.stringify(v));u&&Je(E,u,n);const x=new fi(e,u,E,n),b=await Ui(n,e,t,o,s??!1,l,v,c,p,g);x.isEnabled=b.options.fileCache,b.logger.info(j.cyan(Gi(t)+" "+b.options.name)),b.logger.debug({context:b.options.entries,message:`${j.bold("Root dir:")} ${b.options.rootDir}
102
- ${j.bold("Entries:")}}`}),await Vi(b);const R=Date.now(),K=N(()=>P.duration(Math.floor(Date.now()-R)),"getDuration");if(t==="watch"){if(b.options.rollup.watch===!1)throw new Error("Rollup watch is disabled. You should check your packem.config file.");await ii(b,x),Le(b,!1);return}if(t==="jit"?(await ei(b),await b.hooks.callHook("build:done",b)):(y=await Rr(b,x),await b.hooks.callHook("validate:before",b),Ii(b),await b.hooks.callHook("validate:done",b),Le(b,y)),b.options.typedoc&&b.options.typedoc.format!==void 0){let L="unknown";c.dependencies?.typedoc?L=c.dependencies.typedoc:c.devDependencies?.typedoc&&(L=c.devDependencies.typedoc),u&&Je("typedoc",u,n,!0),y&&b.logger.raw(`
103
- `),b.logger.info({message:"Using "+j.cyan("typedoc")+" "+L+" to generate reference documentation",prefix:"typedoc"}),await b.hooks.callHook("typedoc:before",b);let F=f.join(b.options.rootDir,"api-docs");b.options.typedoc.format==="inline"&&u&&(F=f.join(u,"typedoc")),b.options.typedoc.output&&(F=b.options.typedoc.output),await li(b.options.typedoc,b.options.entries,F,b.logger),await b.hooks.callHook("typedoc:done",b)}n.raw(`
101
+ `),t.info({message:"Removing "+s.name+" file cache, the cache key is not used anymore.",prefix:"file-cache"}),i=!1)}},"removeOldCacheFolders"),Gi=N(e=>{switch(e){case"jit":return"Stubbing";case"watch":return"Watching";case"tsdoc":return"Generating TSDoc";default:return"Building"}},"getMode"),Ki=N(async(e,t,o,n,r={})=>{const{configPath:i,debug:s,tsconfigPath:a,...l}=r;n.wrapAll(),e=f.resolve(he.cwd(),e),n.debug("Root directory:",e);const{packageJson:c,packageJsonPath:d}=xt(e);n.debug("Using package.json found at",d);let p;if(a){const h=f.join(e,a);if(!await $.isAccessible(h))throw new Error("tsconfig.json not found at "+h);p={config:$e.readTsConfig(h),path:h},n.info("Using tsconfig settings at",h)}else if(c.dependencies?.typescript||c.devDependencies?.typescript)try{p=await $e.findTsConfig(e),n.debug("Using tsconfig settings found at",p.path)}catch{n.info("No tsconfig.json or jsconfig.json found.")}const u=At.findCacheDirSync("@visulima/packem",{cwd:e});let y=!1;try{let h=i??"";if(!h){const q=["packem.config.js","packem.config.mjs","packem.config.cjs","packem.config.ts","packem.config.cts","packem.config.mts"];for(const F of q)if($.isAccessibleSync(f.join(e,F))){h="./"+F;break}}const g=Ue.createJiti(e,{debug:s,interopDefault:!0});if(!/\.(?:js|mjs|cjs|ts|cts|mts)$/.test(h))throw new Error("Invalid packem config file extension. Only .js, .mjs, .cjs, .ts, .cts and .mts extensions are allowed.");let v=await g.import(h,{try:!0})||{};typeof v=="function"&&(v=await v(o,t)),n.debug("Using packem config found at",f.join(e,h));const E=T(JSON.stringify({version:c.version,...c.dependencies,...c.devDependencies,...c.peerDependencies,...c.peerDependenciesMeta,browser:c.browser,eNode:c.engines?.node,exports:c.exports,main:c.main,module:c.module,type:c.type,types:c.types}))+T(JSON.stringify(v));u&&Je(E,u,n);const x=new fi(e,u,E,n),b=await Ui(n,e,t,o,s??!1,l,v,c,p,g);x.isEnabled=b.options.fileCache,b.logger.info(j.cyan(Gi(t)+" "+b.options.name)),b.logger.debug({context:b.options.entries,message:`${j.bold("Root dir:")} ${b.options.rootDir}
102
+ ${j.bold("Entries:")}}`}),await Vi(b);const R=Date.now(),K=N(()=>P.duration(Math.floor(Date.now()-R)),"getDuration");if(t==="watch"){if(b.options.rollup.watch===!1)throw new Error("Rollup watch is disabled. You should check your packem.config file.");await ii(b,x),Le(b,!1);return}if(t==="jit"?(await ei(b),await b.hooks.callHook("build:done",b)):(y=await Rr(b,x),await b.hooks.callHook("validate:before",b),Ii(b),await b.hooks.callHook("validate:done",b),Le(b,y)),b.options.typedoc&&b.options.typedoc.format!==void 0){let q="unknown";c.dependencies?.typedoc?q=c.dependencies.typedoc:c.devDependencies?.typedoc&&(q=c.devDependencies.typedoc),u&&Je("typedoc",u,n,!0),y&&b.logger.raw(`
103
+ `),b.logger.info({message:"Using "+j.cyan("typedoc")+" "+q+" to generate reference documentation",prefix:"typedoc"}),await b.hooks.callHook("typedoc:before",b);let F=f.join(b.options.rootDir,"api-docs");b.options.typedoc.format==="inline"&&u&&(F=f.join(u,"typedoc")),b.options.typedoc.output&&(F=b.options.typedoc.output),await li(b.options.typedoc,b.options.entries,F,b.logger),await b.hooks.callHook("typedoc:done",b)}n.raw(`
104
104
  ⚡️ Build run in `+K()),n.restoreAll()}catch(h){throw n.raw(`
105
105
  `),$t(h),h}finally{await zi(u,n,y)}},"createBundler");module.exports=Ki;