@visulima/packem 1.0.0-alpha.94 → 1.0.0-alpha.96
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/CHANGELOG.md +14 -0
- package/dist/cli.mjs +107 -8
- package/dist/config.d.cts +2 -2
- package/dist/config.d.mts +2 -2
- package/dist/config.d.ts +2 -2
- package/dist/create-bundler.cjs +67 -68
- package/dist/create-bundler.d.cts +2 -2
- package/dist/create-bundler.d.mts +2 -2
- package/dist/create-bundler.d.ts +2 -2
- package/dist/create-bundler.mjs +58 -59
- package/dist/rollup/plugins/esbuild/index.d.cts +0 -2
- package/dist/rollup/plugins/esbuild/index.d.ts +0 -2
- package/dist/rollup/plugins/esbuild/index.mjs +2 -2
- package/dist/rollup/plugins/oxc/isolated-declarations-oxc-transformer.d.cts +1 -3
- package/dist/rollup/plugins/oxc/isolated-declarations-oxc-transformer.d.mts +1 -1
- package/dist/rollup/plugins/oxc/isolated-declarations-oxc-transformer.d.ts +1 -3
- package/dist/rollup/plugins/sucrase/index.d.cts +0 -2
- package/dist/rollup/plugins/sucrase/index.d.ts +0 -2
- package/dist/rollup/plugins/sucrase/index.mjs +1 -1
- package/dist/rollup/plugins/swc/isolated-declarations-swc-transformer.d.cts +1 -3
- package/dist/rollup/plugins/swc/isolated-declarations-swc-transformer.d.mts +1 -1
- package/dist/rollup/plugins/swc/isolated-declarations-swc-transformer.d.ts +1 -3
- package/dist/rollup/plugins/swc/swc-plugin.d.cts +0 -2
- package/dist/rollup/plugins/swc/swc-plugin.d.ts +0 -2
- package/dist/rollup/plugins/swc/swc-plugin.mjs +1 -1
- package/dist/rollup/plugins/typescript/isolated-declarations-typescript-transformer.d.cts +1 -3
- package/dist/rollup/plugins/typescript/isolated-declarations-typescript-transformer.d.mts +1 -1
- package/dist/rollup/plugins/typescript/isolated-declarations-typescript-transformer.d.ts +1 -3
- package/dist/shared/{constants-DcRh98q_.mjs → constants-bGKeOK8V.mjs} +1 -1
- package/dist/shared/{types-htgF7Xtw.d.ts → types-BTXISiJt.d.ts} +2 -1
- package/dist/shared/{types-DsYp-kFd.d.cts → types-BzEjQ1ba.d.cts} +2 -1
- package/dist/shared/{types-BvTSoulI.d.mts → types-DIVjp2ON.d.mts} +2 -1
- package/package.json +11 -13
- package/dist/cli.cjs +0 -16
package/dist/create-bundler.mjs
CHANGED
|
@@ -1,103 +1,102 @@
|
|
|
1
|
-
var
|
|
1
|
+
var It=Object.defineProperty;var m=(e,t)=>It(e,"name",{value:t,configurable:!0});import Ee from"node:module";import{env as Rt,versions as Ft,cwd as Tt}from"node:process";import{cyan as j,bold as D,gray as R,green as At,yellow as Jt,grey as Wt}from"@visulima/colorize";import{readFile as oe,readFileSync as Ve,writeFileSync as He,writeJsonSync as qe,readJsonSync as Bt,walk as Lt,isAccessibleSync as O,collectSync as Ut,writeFile as V,ensureDirSync as zt,emptyDir as Ke,isAccessible as Vt}from"@visulima/fs";import{formatBytes as M,duration as Ht}from"@visulima/humanizer";import{parsePackageJson as qt}from"@visulima/package/package-json";import{normalize as me,join as w,relative as N,dirname as fe,basename as ge,toNamespacedPath as pe,resolve as $,extname as he,isAbsolute as Ge}from"@visulima/path";import{readTsConfig as Kt,findTsConfig as Gt}from"@visulima/tsconfig";import{defu as Yt}from"defu";import{createHooks as Xt}from"hookable";import{rollup as Ye,watch as Oe,VERSION as Qt}from"rollup";import{stat as Xe,chmod as Zt}from"node:fs/promises";import Qe from"@rollup/plugin-alias";import eo from"@rollup/plugin-commonjs";import to from"@rollup/plugin-dynamic-import-vars";import{nodeResolve as Ze}from"@rollup/plugin-node-resolve";import et from"@rollup/plugin-replace";import{wasm as oo}from"@rollup/plugin-wasm";import ro from"rollup-plugin-polyfill-node";import{visualizer as no}from"rollup-plugin-visualizer";import{minVersion as tt}from"semver";import X from"node:assert/strict";import{extractAssignedNames as so,createFilter as T,normalizePath as Se}from"@rollup/pluginutils";import C from"magic-string";import io from"glob-parent";import{glob as ao,globSync as lo}from"tinyglobby";import{findStaticImports as ot,resolvePath as co,resolveModuleExportNames as po}from"mlly";import{parseAsync as uo}from"oxc-parser";import{E as Q,D as ye,S as Z,P as W,a as De,R as mo,b as H}from"./shared/constants-bGKeOK8V.mjs";import fo from"@rollup/plugin-json";import go from"rollup-plugin-license";import{createHash as ho}from"node:crypto";import{fileURLToPath as yo,pathToFileURL as vo}from"node:url";import{parse as bo}from"@babel/parser";import rt from"jiti";import{existsSync as nt,rmSync as $o}from"node:fs";import{findCacheDirSync as wo}from"@visulima/find-cache-dir";import{NotFoundError as jo}from"@visulima/fs/error";import{isRelative as ko}from"@visulima/path/utils";import Ne from"is-glob";import{distance as xo}from"fastest-levenshtein";import __cjs_url__ from "node:url"; // -- packem CommonJS __filename shim --
|
|
2
2
|
import __cjs_path__ from "node:path"; // -- packem CommonJS __dirname shim --
|
|
3
3
|
import __cjs_mod__ from "node:module"; // -- packem CommonJS require shim --
|
|
4
4
|
const __filename = __cjs_url__.fileURLToPath(import.meta.url);
|
|
5
5
|
const __dirname = __cjs_path__.dirname(__filename);
|
|
6
6
|
const require = __cjs_mod__.createRequire(import.meta.url);
|
|
7
|
-
var
|
|
8
|
-
|
|
9
|
-
`)=>{const o=ve.exec(e);return o?o+t:""},"getShebang");var qo=Object.defineProperty,Ko=m((e,t)=>qo(e,"name",{value:t,configurable:!0}),"p$2");const be=Ko((e,t)=>{let o={};if(e.pkg.name&&(o[e.pkg.name]=e.options.rootDir),e.pkg.imports){const{imports:r}=e.pkg;for(const n in r){if(n.startsWith("#"))continue;const s=r[n];typeof s=="string"&&(o[n]=w(e.options.rootDir,s))}}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(r=>[r.find,r.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 Go=Object.defineProperty,Yo=m((e,t)=>Go(e,"name",{value:t,configurable:!0}),"o$3");const Xo=Yo((e,t)=>{const o=Ge(t,{esmResolve:!0,interopDefault:!0});try{return o.resolve(e)}catch(r){if(r.code!=="MODULE_NOT_FOUND")throw new Error(`Error trying import ${e} from ${t}`,{cause:r});return e}},"tryResolve");var Qo=Object.defineProperty,Zo=m((e,t)=>Qo(e,"name",{value:t,configurable:!0}),"u$d");const er=Zo(async e=>{const t=await eo("jiti",{url:import.meta.url}),o=JSON.stringify({...e.options.stubOptions.jiti,alias:{...be(e,"jit"),...e.options.stubOptions.jiti.alias}},null,2);for(const r of e.options.entries){const n=b(e.options.rootDir,e.options.outDir,r.name),s=de(Xo(r.input,e.options.rootDir)||r.input),i=s.slice(0,Math.max(0,s.length-ue(s).length)),l=await ee(s),a=Ho(l);e.options.emitCJS&&await z(`${n}.cjs`,a+[`const jiti = require(${JSON.stringify(t)})`,"",`const _jiti = jiti(null, ${o})`,"",`/** @type {import(${JSON.stringify(i)})} */`,`module.exports = _jiti(${JSON.stringify(s)})`].join(`
|
|
10
|
-
`));let c=[];try{c=await to(s,{extensions:ge})}catch(d){L(e,`Cannot analyze ${s} for exports: ${d.toString()}`);return}const p=c.includes("default")||c.length===0;await z(`${n}.mjs`,a+[`import jiti from ${JSON.stringify(Qt(t).href)};`,"",`const _jiti = jiti(null, ${o})`,"",`/** @type {import(${JSON.stringify(s)})} */`,`const _module = await _jiti.import(${JSON.stringify(s)});`,p?`
|
|
11
|
-
export default _module;`:"",...c.filter(d=>d!=="default").map(d=>`export const ${d} = _module.${d};`)].join(`
|
|
12
|
-
`)),await z(`${n}.d.cts`,[`export * from ${JSON.stringify(i)};`,p?`export { default } from ${JSON.stringify(i)};`:""].join(`
|
|
13
|
-
`)),await z(`${n}.d.mts`,[`export * from ${JSON.stringify(s)};`,p?`export { default } from ${JSON.stringify(s)};`:""].join(`
|
|
14
|
-
`)),a&&(await ce(`${n}.cjs`),await ce(`${n}.mjs`))}await e.hooks.callHook("rollup:done",e)},"createStub");var tr=Object.defineProperty,or=m((e,t)=>tr(e,"name",{value:t,configurable:!0}),"a$c");const pe=or((e,t)=>e.some(o=>o instanceof RegExp?o.test(t):o===t),"arrayIncludes");var rr=Object.defineProperty,nr=m((e,t)=>rr(e,"name",{value:t,configurable:!0}),"a$b");const W=nr(e=>e==null?[]:Array.isArray(e)?e:[e],"arrayify");var sr=Object.defineProperty,ir=m((e,t)=>sr(e,"name",{value:t,configurable:!0}),"a$a");const st=ir((e="")=>{const t=e.split("/");return t[0].startsWith("@")?t[0]+"/"+t[1]:t[0]},"getPackageName");var ar=Object.defineProperty,it=m((e,t)=>ar(e,"name",{value:t,configurable:!0}),"s$c");const lr=it((e,t,o)=>{const r=o??new Map;return(...n)=>{const s=t?typeof t=="function"?t(...n):t:JSON.stringify({args:n}),i=r.get(s);if(i!==void 0)return i;const l=e(...n);return r.set(s,l),l}},"memoize"),cr=it(e=>{const t=new Map;return o=>lr(e,o,t)},"memoizeByKey");var pr=Object.defineProperty,B=m((e,t)=>pr(e,"name",{value:t,configurable:!0}),"r$5");const ur=B(function*(e){switch(e.declaration?.type){case"ClassDeclaration":case"FunctionDeclaration":{const{id:t}=e.declaration;Q(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 ao(t.id))yield o;break}}},"exportName"),dr=B(function*(e){if(e.declaration)for(const t of ur(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"),mr=B(function*(e){e.exported?yield{exportedName:e.exported.name,from:"self",type:"named"}:yield{from:"other",source:e.source.value,type:"barrel"}},"parseExportAll"),fr=B(function*(){yield{exportedName:"default",from:"self",type:"named"}},"parseExportDefault"),gr=B(function*(e,t){Q(t.code!=null,`Module ${t.id} doesn't have associated code`);const o=e.parse(t.code);for(const r of o.body)switch(r.type){case"ExportAllDeclaration":{yield*mr(r);break}case"ExportDefaultDeclaration":{yield*fr();break}case"ExportNamedDeclaration":{yield*dr(r);break}}},"parseExports");var hr=Object.defineProperty,U=m((e,t)=>hr(e,"name",{value:t,configurable:!0}),"n$6");const at=U(async function(e,t,o){const r=await e.resolve(t,o.id);if(Q(r,`Rollup can't resolve ${t} from ${o.id}`),r.external)return null;const n=await e.load(r);return Q(n,`Rollup doesn't have a module for id ${r.id}`),n},"getImportedModule"),yr=U(async function*(e,t,o){const r=await at(e,t.source,o);r&&(yield*$e(e,r))},"gatherBarrelReExports"),vr=U(async function*(e,t,o){const r=await at(e,t.source,o);if(!r)return;const n=new Map(t.bindings.map(s=>[s.importedName,s]));for await(const s of $e(e,r)){const i=n.get(s.exportedName);i&&(yield{...s,exportedName:i.exportedName})}},"gatherNamedReExports"),br=U(async function*(e,t){yield{exportedName:t.exportedName,id:e.id,sourceName:t.exportedName}},"gatherNamedSelfExports"),$e=U(async function*(e,t){for(const o of gr(e,t))o.from==="self"?yield*br(t,o):o.type==="barrel"?yield*yr(e,o,t):yield*vr(e,o,t)},"gatherExports");var $r=Object.defineProperty,wr=m((e,t)=>$r(e,"name",{value:t,configurable:!0}),"n$5");const jr=wr(({preserveChunkSignature:e=!1}={})=>({moduleParsed:{async handler(t){if(t.isEntry)for await(const o of $e(this,t))o.id!==t.id&&this.emitFile({id:o.id,name:o.exportedName,preserveSignature:e,type:"chunk"})},order:"post"},name:"packem:chunk-splitter"}),"chunkSplitter");var kr=Object.defineProperty,_e=m((e,t)=>kr(e,"name",{value:t,configurable:!0}),"u$9");const lt=_e(({addDefaultProperty:e=!1,logger:t,type:o})=>({name:"packem:cjs-interop",renderChunk:_e(async(r,n,s)=>{if(n.type!=="chunk"||!n.isEntry)return null;if(s.format==="cjs"&&s.exports==="auto"){const i=/(exports(?:\['default'\]|\.default)) = (.*);/i.exec(r);if(i===null||i.length<3)return null;const l=new C(r);l.replace("Object.defineProperty(exports, '__esModule', { value: true });",""),l.replaceAll(/exports\.(.*) = (.*);/g,"module.exports.$1 = $2;"),e&&l.append(`
|
|
15
|
-
module.exports.default = `+i[2]+";");let a=l.toString();return a=a.replace(/(?:module\.)?exports(?:\['default'\]|\.default)/i,"module.exports"),t.debug({message:"Applied CommonJS interop to entry chunk "+n.fileName+".",prefix:"plugin:cjs-interop"}),{code:a,map:l.generateMap({hires:!0})}}if(s.format==="es"&&/\.d\.(?:ts|cts)$/.test(n.fileName)){if(o!=="commonjs"&&n.fileName.endsWith(".d.mts"))return null;const i=[];let l;const a=/export\s\{\s(.*)\s\}/g;for(;(l=a.exec(r))!==null;)l.index===a.lastIndex&&a.lastIndex++,l.forEach(d=>{i.push(d)});if(i.length===0)return null;const c=i.at(-1).split(", ");let p="";for(const d of c)if(!d.includes("type")&&d.includes("as")){const[u,f]=d.split(" as ");f==="default"&&(p=u)}if(p!==""){const d=new C(r);return d.replace(new RegExp(`(,s)?${p} as default(,)?`),""),d.append(`
|
|
7
|
+
var Eo=Object.defineProperty,Oo=m((e,t)=>Eo(e,"name",{value:t,configurable:!0}),"a$f");const ue=Oo((e,t)=>e.some(o=>o instanceof RegExp?o.test(t):o===t),"arrayIncludes");var So=Object.defineProperty,Do=m((e,t)=>So(e,"name",{value:t,configurable:!0}),"a$e");const B=Do(e=>e==null?[]:Array.isArray(e)?e:[e],"arrayify");var No=Object.defineProperty,Po=m((e,t)=>No(e,"name",{value:t,configurable:!0}),"a$d");const st=Po((e="")=>{const t=e.split("/");return t[0].startsWith("@")?t[0]+"/"+t[1]:t[0]},"getPackageName");var _o=Object.defineProperty,it=m((e,t)=>_o(e,"name",{value:t,configurable:!0}),"s$g");const Co=it((e,t,o)=>{const r=o??new Map;return(...s)=>{const n=t?typeof t=="function"?t(...s):t:JSON.stringify({args:s}),i=r.get(n);if(i!==void 0)return i;const l=e(...s);return r.set(n,l),l}},"memoize"),Mo=it(e=>{const t=new Map;return o=>Co(e,o,t)},"memoizeByKey");var Io=Object.defineProperty,U=m((e,t)=>Io(e,"name",{value:t,configurable:!0}),"r$b");const Ro=U(function*(e){switch(e.declaration?.type){case"ClassDeclaration":case"FunctionDeclaration":{const{id:t}=e.declaration;X(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 so(t.id))yield o;break}}},"exportName"),Fo=U(function*(e){if(e.declaration)for(const t of Ro(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"),To=U(function*(e){e.exported?yield{exportedName:e.exported.name,from:"self",type:"named"}:yield{from:"other",source:e.source.value,type:"barrel"}},"parseExportAll"),Ao=U(function*(){yield{exportedName:"default",from:"self",type:"named"}},"parseExportDefault"),Jo=U(function*(e,t){X(t.code!=null,`Module ${t.id} doesn't have associated code`);const o=e.parse(t.code);for(const r of o.body)switch(r.type){case"ExportAllDeclaration":{yield*To(r);break}case"ExportDefaultDeclaration":{yield*Ao();break}case"ExportNamedDeclaration":{yield*Fo(r);break}}},"parseExports");var Wo=Object.defineProperty,z=m((e,t)=>Wo(e,"name",{value:t,configurable:!0}),"n$b");const at=z(async function(e,t,o){const r=await e.resolve(t,o.id);if(X(r,`Rollup can't resolve ${t} from ${o.id}`),r.external)return null;const s=await e.load(r);return X(s,`Rollup doesn't have a module for id ${r.id}`),s},"getImportedModule"),Bo=z(async function*(e,t,o){const r=await at(e,t.source,o);r&&(yield*ve(e,r))},"gatherBarrelReExports"),Lo=z(async function*(e,t,o){const r=await at(e,t.source,o);if(!r)return;const s=new Map(t.bindings.map(n=>[n.importedName,n]));for await(const n of ve(e,r)){const i=s.get(n.exportedName);i&&(yield{...n,exportedName:i.exportedName})}},"gatherNamedReExports"),Uo=z(async function*(e,t){yield{exportedName:t.exportedName,id:e.id,sourceName:t.exportedName}},"gatherNamedSelfExports"),ve=z(async function*(e,t){for(const o of Jo(e,t))o.from==="self"?yield*Uo(t,o):o.type==="barrel"?yield*Bo(e,o,t):yield*Lo(e,o,t)},"gatherExports");var zo=Object.defineProperty,Vo=m((e,t)=>zo(e,"name",{value:t,configurable:!0}),"r$a");const Ho=Vo(()=>({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 qo=Object.defineProperty,Pe=m((e,t)=>qo(e,"name",{value:t,configurable:!0}),"u$b");const lt=Pe(({addDefaultProperty:e=!1,logger:t,type:o})=>({name:"packem:cjs-interop",renderChunk:Pe(async(r,s,n)=>{if(s.type!=="chunk"||!s.isEntry)return null;if(n.format==="cjs"&&n.exports==="auto"){const i=/(exports(?:\['default'\]|\.default)) = (.*);/i.exec(r);if(i===null||i.length<3)return null;const l=new C(r);l.replace("Object.defineProperty(exports, '__esModule', { value: true });",""),l.replaceAll(/exports\.(.*) = (.*);/g,"module.exports.$1 = $2;"),e&&l.append(`
|
|
8
|
+
module.exports.default = `+i[2]+";");let a=l.toString();return a=a.replace(/(?:module\.)?exports(?:\['default'\]|\.default)/i,"module.exports"),t.debug({message:"Applied CommonJS interop to entry chunk "+s.fileName+".",prefix:"plugin:cjs-interop"}),{code:a,map:l.generateMap({hires:!0})}}if(n.format==="es"&&/\.d\.(?:ts|cts)$/.test(s.fileName)){if(o!=="commonjs"&&s.fileName.endsWith(".d.mts"))return null;const i=[];let l;const a=/export\s\{\s(.*)\s\}/g;for(;(l=a.exec(r))!==null;)l.index===a.lastIndex&&a.lastIndex++,l.forEach(d=>{i.push(d)});if(i.length===0)return null;const c=i.at(-1).split(", ");let p="";for(const d of c)if(!d.includes("type")&&d.includes("as")){const[u,f]=d.split(" as ");f==="default"&&(p=u)}if(p!==""){const d=new C(r);return d.replace(new RegExp(`(,s)?${p} as default(,)?`),""),d.append(`
|
|
16
9
|
|
|
17
|
-
export = `+p+";"),t.debug({message:"Applied CommonJS interop to entry chunk "+
|
|
10
|
+
export = `+p+";"),t.debug({message:"Applied CommonJS interop to entry chunk "+s.fileName+".",prefix:"plugin:cjs-interop"}),{code:d.toString().replace(/export\s\{\s\s\};/,""),map:d.generateMap({hires:!0})}}}return null},"renderChunk")}),"cjsInteropPlugin");var Ko=Object.defineProperty,Go=m((e,t)=>Ko(e,"name",{value:t,configurable:!0}),"u$a");const Yo=Go((e,t)=>{const o=new Map,r={copyOnce:!0,exactFileNames:!0,flatten:!1,...e};let{targets:s}=r;return Array.isArray(s)?s=s.map(n=>{if(typeof n=="string")return{src:n};if(typeof n=="object"&&"src"in n)return n}).filter(Boolean):typeof s=="string"&&(s=[{src:s}]),{async buildStart(){const n=await Promise.all(s.flatMap(i=>Array.isArray(i.src)?i.src.map(l=>({...i,src:l})):i).map(async i=>await ao(B(i.src),{ignore:B(i.exclude).filter(Boolean)}).then(l=>({dest:i.dest??"",parent:io(i.src),src:l}))));for(const i of n)for(const l of i.src){let a;o.has(l)?a=o.get(l):(a={copied:[],dest:[],timestamp:0},o.set(l,a));const c=r.flatten?me(i.dest):w(i.dest,N(i.parent,fe(l)));a.dest.includes(c)||a.dest.push(c),this.addWatchFile(l)}t.info({message:"Copying files...",prefix:"plugin:copy"}),await Promise.all([...o].map(async([i,l])=>{let a;try{const c=await Xe(i);if(!c.isFile())return;const p=c.mtime.getTime();p>l.timestamp&&(l.timestamp=p,l.copied=[]),a=await oe(i,{buffer:!0})}catch(c){t.error({context:[c],message:`error reading file ${i}`,prefix:"plugin:copy"});return}for(const c of l.dest){if(r.copyOnce&&l.copied.includes(c))continue;const p=ge(i),d=w(c,p);try{this.emitFile({[r.exactFileNames?"fileName":"name"]:d,source:a,type:"asset"}),t.debug({message:`copied ${i} → ${d}`,prefix:"plugin:copy"}),l.copied.push(c)}catch(u){t.error({context:[u],message:`error copying file ${i} → ${d}`,prefix:"plugin:copy"})}}}))},name:"packem:copy"}},"copyPlugin");var Xo=Object.defineProperty,re=m((e,t)=>Xo(e,"name",{value:t,configurable:!0}),"t$6");const Qo=/\Wrequire(?:\.resolve)?\(/,Zo=re((e,t)=>{if(Rt.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,r=!1,s=!1;if(e.includes("__filename")&&(o=!0),e.includes("__dirname")&&(r=!0),Qo.test(e)&&(s=!0),!o&&!r&&!s)return null;const n=ot(e).pop(),i=n?n.end:0,l=new C(e);return l.appendRight(i,t(o,r,s)),{code:l.toString(),map:l.generateMap()}},"CJSToESM"),er=re((e,t,o)=>{let r="";return(e||t)&&(r+=`import __cjs_url__ from "node:url"; // -- packem CommonJS __filename shim --
|
|
18
11
|
`),t&&(r+=`import __cjs_path__ from "node:path"; // -- packem CommonJS __dirname shim --
|
|
19
12
|
`),o&&(r+=`import __cjs_mod__ from "node:module"; // -- packem CommonJS require shim --
|
|
20
13
|
`),(e||t)&&(r+=`const __filename = __cjs_url__.fileURLToPath(import.meta.url);
|
|
21
14
|
`),t&&(r+=`const __dirname = __cjs_path__.dirname(__filename);
|
|
22
15
|
`),o&&(r+=`const require = __cjs_mod__.createRequire(import.meta.url);
|
|
23
|
-
`),r},"generateCJSShim"),
|
|
16
|
+
`),r},"generateCJSShim"),tr=re((e,t,o)=>{let r="";return o&&(r+=`import __cjs_mod__ from "node:module"; // -- packem CommonJS require shim --
|
|
24
17
|
`),e&&(r+=`const __filename = import.meta.filename; // -- packem CommonJS __filename shim --
|
|
25
18
|
`),t&&(r+=`const __dirname = import.meta.dirname; // -- packem CommonJS __dirname shim --
|
|
26
19
|
`),o&&(r+=`const require = __cjs_mod__.createRequire(import.meta.url);
|
|
27
|
-
`),r},"generateCJSShimNode20_11"),
|
|
20
|
+
`),r},"generateCJSShimNode20_11"),or=re((e,t)=>{const o=T(t.include,t.exclude);return{name:"packem:esm-shim-cjs-syntax",renderChunk(r,s,n){if(n.format==="es"&&o(s.fileName)){let i=er;if(e.engines?.node){const l=tt(e.engines.node);l&&l.major>=20&&l.minor>=11&&(i=tr)}return Zo(r,i)}return null}}},"esmShimCjsSyntaxPlugin");var rr=Object.defineProperty,nr=m((e,t)=>rr(e,"name",{value:t,configurable:!0}),"n$9");const sr=nr(()=>({name:"packem:cjs",renderChunk(e,t,o){return o.format==="es"||o.format==="cjs"?{code:e.replaceAll(/(import\(.*)(.ts)(['´"`]\))/g,"$1."+(o.format==="es"?"mjs":"cjs")+"$3"),map:null}:null}}),"fixDynamicImportExtension");var ir=Object.defineProperty,ar=m((e,t)=>ir(e,"name",{value:t,configurable:!0}),"s$e");const lr=ar((...e)=>{if(e.length===0)return"";if(e.length===1)return fe(e[0]);e=e.map(s=>pe(s));const[t,...o]=e;let r=t.split("/");for(const s of o){const n=s.split("/",r.length);let i=0;for(const l of n)if(l===r[i])i+=1;else{r=r.slice(0,i);break}r=r.slice(0,i)}return r.length<=1&&r[0]===""?`/${r[0]}`:r.join("/")},"lowestCommonAncestor");var cr=Object.defineProperty,ie=m((e,t)=>cr(e,"name",{value:t,configurable:!0}),"m$5");const pr=ie((e,t,o,r={})=>{const s=T(r.include,r.exclude),n={},i=ie((c,p)=>{n[c.replace(/\..?[jt]s$/,"")]=p},"addOutput");async function l(c,p){if(!s(p))return;const{errors:d,sourceText:u}=await e(p,c);if(d.length>0){if(r.ignoreErrors){this.warn(d[0]);return}return this.error(d[0])}i(p,u);let f;try{const g=await uo(c,{sourceFilename:p});f=JSON.parse(g.program)}catch{return}const h=f.body.filter(g=>g.type!=="ImportDeclaration"?!1:g.importKind==="type"?!0:(g.specifiers||[]).every(b=>b.type==="ImportSpecifier"&&b.importKind==="type"));for await(const g of h){const b=await this.resolve(g.source.value,p);if(!b)return;const v=b.id;if(s(v)&&!n[v.replace(Q,"")])try{const y=await oe(v);await l.call(this,y,v)}catch{}}}m(l,"g"),ie(l,"transform");const a=o==="module"?"es":"cjs";return{name:"packem:isolated-declarations",renderStart(c,{input:p}){const d=lr(...Array.isArray(p)?p:Object.values(p));typeof c.entryFileNames=="function"&&(c.entryFileNames=c.entryFileNames({name:c.name}));const u=c.entryFileNames.replace(/\.(.)?[jt]s$/,(f,h)=>`.d.${h||""}ts`);for(const[f,h]of Object.entries(n)){(t===!0||t==="compatible")&&c.format===a&&this.emitFile({fileName:u.replace("[name]",N(d,f)).replace(a==="cjs"?".cts":".mts",".ts"),source:h,type:"asset"});const g=h.includes("from '")?"'":'"';this.emitFile({fileName:u.replace("[name]",N(d,f)),source:h.replaceAll(/from\s+['"]([^'"]+)['"]/g,(b,v)=>`from ${g}${v.replace(Q,"")}${c.format==="cjs"?".cts":".mts"}${g}`),type:"asset"})}},transform:l}},"isolatedDeclarationsPlugin");var ur=Object.defineProperty,dr=m((e,t)=>ur(e,"name",{value:t,configurable:!0}),"n$8");const _e="export default ",ct=dr(e=>{const t=fo(e);return{...t,name:"packem:json",transform(o,r){const s=t.transform?.call(this,o,r);return s&&typeof s!="string"&&"code"in s&&s.code?.startsWith(_e)&&(s.code=s.code.replace(_e,"module.exports = ")),s}}},"JSONPlugin");class mr{static{m(this,"WalkerBase")}constructor(){this.should_skip=!1,this.should_remove=!1,this.replacement=null,this.context={skip:m(()=>this.should_skip=!0,"skip"),remove:m(()=>this.should_remove=!0,"remove"),replace:m(t=>this.replacement=t,"replace")}}replace(t,o,r,s){t&&o&&(r!=null?t[o][r]=s:t[o]=s)}remove(t,o,r){t&&o&&(r!=null?t[o].splice(r,1):delete t[o])}}class fr extends mr{static{m(this,"SyncWalker")}constructor(t,o){super(),this.should_skip=!1,this.should_remove=!1,this.replacement=null,this.context={skip:m(()=>this.should_skip=!0,"skip"),remove:m(()=>this.should_remove=!0,"remove"),replace:m(r=>this.replacement=r,"replace")},this.enter=t,this.leave=o}visit(t,o,r,s){if(t){if(this.enter){const i=this.should_skip,l=this.should_remove,a=this.replacement;this.should_skip=!1,this.should_remove=!1,this.replacement=null,this.enter.call(this.context,t,o,r,s),this.replacement&&(t=this.replacement,this.replace(o,r,s,t)),this.should_remove&&this.remove(o,r,s);const c=this.should_skip,p=this.should_remove;if(this.should_skip=i,this.should_remove=l,this.replacement=a,c)return t;if(p)return null}let n;for(n in t){const i=t[n];if(i&&typeof i=="object")if(Array.isArray(i)){const l=i;for(let a=0;a<l.length;a+=1){const c=l[a];Ce(c)&&(this.visit(c,t,n,a)||a--)}}else Ce(i)&&this.visit(i,t,n,null)}if(this.leave){const i=this.replacement,l=this.should_remove;this.replacement=null,this.should_remove=!1,this.leave.call(this.context,t,o,r,s),this.replacement&&(t=this.replacement,this.replace(o,r,s,t)),this.should_remove&&this.remove(o,r,s);const a=this.should_remove;if(this.replacement=i,this.should_remove=l,a)return null}}return t}}function Ce(e){return e!==null&&typeof e=="object"&&"type"in e&&typeof e.type=="string"}m(Ce,"isNode");function pt(e,{enter:t,leave:o}){return new fr(t,o).visit(e,null)}m(pt,"walk");var gr=Object.defineProperty,hr=m((e,t)=>gr(e,"name",{value:t,configurable:!0}),"u$9");const yr=hr(({attributes:e,logger:t})=>{const o=T([/\.[tj]sx$/],/node_modules/);if(!Array.isArray(e)||e.length===0)throw new Error("[packem:jsx-remove-attributes]: attributes must be a non-empty array of strings.");return{name:"packem:jsx-remove-attributes",transform(r,s){if(!o(s))return null;let n=null;try{n=this.parse(r,{allowReturnOutsideFunction:!0})}catch(a){return this.warn({code:"PARSE_ERROR",message:`[packem:jsx-remove-attributes]: failed to parse "${s}" and remove the jsx attribute.`}),t.warn(a),null}let i=!1;const l=new C(r);return pt(n,{enter(a){if(a.type==="CallExpression"&&a.callee.type==="Identifier"&&a.callee.name==="jsx"){const c=a.arguments.filter(p=>p.type==="ObjectExpression"&&Array.isArray(p.properties));for(const p of c)for(const d of p.properties)d.type==="Property"&&d.key.type==="Literal"&&d.value.type==="Literal"&&e.includes(d.key.value)&&(l.overwrite(d.start-2,d.end,""),i=!0)}}}),i?{code:l.toString(),map:l.generateMap({hires:!0})}:null}}},"jsxRemoveAttributes");var vr=Object.defineProperty,be=m((e,t)=>vr(e,"name",{value:t,configurable:!0}),"g$3");const br=be(e=>{const t=[],o=[];return e.forEach(r=>{r.startsWith("(")?t.push(r):o.push(r)}),[...o.sort(),...t.sort()]},"sortLicenses"),$r=be((e,t,o)=>{const r=new RegExp(`(<!-- ${t} -->)[\\s\\S]*?(<!-- ${t} -->)`,"g");if(r.test(e))return e.replace(r,`$1
|
|
28
21
|
${o}
|
|
29
|
-
$2`)},"replaceContentWithin"),ut=
|
|
30
|
-
`;f&&(
|
|
31
|
-
`);const
|
|
32
|
-
`),
|
|
33
|
-
`),h&&(
|
|
22
|
+
$2`)},"replaceContentWithin"),ut=be(({dtsMarker:e,licenseFilePath:t,licenseTemplate:o,logger:r,marker:s,mode:n,packageName:i})=>go({thirdParty(l){const a=new Set,c=l.sort(({name:d},{name:u})=>(d||0)>(u||0)?1:(u||0)>(d||0)?-1:0).map(({author:d,contributors:u,license:f,licenseText:h,maintainers:g,name:b,repository:v})=>{let y="## "+b+`
|
|
23
|
+
`;f&&(y+=`License: ${f}
|
|
24
|
+
`);const x=new Set;for(const S of[d,...g,...u]){const A=typeof S=="string"?S:S?.name;A&&x.add(A)}return x.size>0&&(y+=`By: ${[...x].join(", ")}
|
|
25
|
+
`),v&&(y+=`Repository: ${typeof v=="string"?v:v.url}
|
|
26
|
+
`),h&&(y+=`
|
|
34
27
|
`+h.trim().replaceAll(/\r\n|\r/g,`
|
|
35
|
-
`).replaceAll(`<!-- ${
|
|
36
|
-
`).map(
|
|
28
|
+
`).replaceAll(`<!-- ${s} -->`,"").replaceAll(e?`<!-- ${e} -->`:"","").trim().split(`
|
|
29
|
+
`).map(S=>S?`> ${S}`:">").join(`
|
|
37
30
|
`)+`
|
|
38
|
-
`),f&&a.add(f)
|
|
31
|
+
`),f&&a.add(f),y}).join(`
|
|
39
32
|
---------------------------------------
|
|
40
33
|
|
|
41
|
-
`);if(c===""){r.info({message:"No dependencies license information found.",prefix:"plugin:license:"+
|
|
42
|
-
|
|
34
|
+
`);if(c===""){r.info({message:"No dependencies license information found.",prefix:"plugin:license:"+n});return}const p=o(br(a),c,i);try{const d=Ve(t),u=$r(d,s,p);if(!u){r.error({message:`Could not find the license marker: <!-- ${s} --> in ${t}`,prefix:"plugin:license:"+n});return}d!==u&&(He(t,u),r.info({message:`${t} updated.`,prefix:"plugin:license:"+n}))}catch(d){r.error(d)}}}),"license");var wr=Object.defineProperty,jr=m((e,t)=>wr(e,"name",{value:t,configurable:!0}),"i$a");const kr=jr(e=>({async buildEnd(){const t=[];for(const r of this.getModuleIds()){const s=this.getModuleInfo(r);if(s!=null&&!s.isExternal)for(const n of s.importedIds)t.push({source:r,target:n})}if(Array.isArray(t)&&t.length===0)return;const o=$(e.rootDir,e.outDir,"graph.json");qe(o,t)},name:"packem:metafile"}),"metafilePlugin");var xr=Object.defineProperty,dt=m((e,t)=>xr(e,"name",{value:t,configurable:!0}),"n$7");let Me=!1;const Er=dt(e=>{e.logger.info(`Compatibility mode enabled. This will generate a typesVersions field ${e.options.writeTypesVersionsToPackageJson?"and write it to package.json":" and display it in the console"}.`);const t=[];for(const o of e.buildEntries.filter(r=>!r.chunk))o.type==="entry"&&o.path.endsWith(".cjs")&&t.push("./"+w(e.options.outDir,o.path.replace(/\.cjs$/,".d.ts")));if(e.options.writeTypesVersionsToPackageJson){const o=w(e.options.rootDir,"package.json"),r=Bt(o);qe(o,{...r,typesVersions:{...r.typesVersions,"*":{"*":t.sort()}}},{detectIndent:!0})}else e.logger.info(`Please add the following field into your package.json to enable node 10 compatibility:
|
|
35
|
+
|
|
36
|
+
${JSON.stringify({typesVersions:{"*":{"*":t.sort()}}},null,4)}`)},"generateNode10Compatibility"),Or=dt(e=>({name:"packem:node10-compatibility",writeBundle(){Me||e.options.declaration!=="compatible"||(Er(e),Me=!0)}}),"node10Compatibility");var Sr=Object.defineProperty,Dr=m((e,t)=>Sr(e,"name",{value:t,configurable:!0}),"r$7");const I=Dr(e=>{const t=ho("md5");return t.update(e),t.digest("hex")},"getHash");var Nr=Object.defineProperty,mt=m((e,t)=>Nr(e,"name",{value:t,configurable:!0}),"d$7");const J=mt(e=>e.handler||e,"getHandler"),E=mt((e,t,o="")=>({...e,async buildEnd(r){e.buildEnd&&await J(e.buildEnd).call(this,r)},async buildStart(r){e.buildStart&&await J(e.buildStart).call(this,r)},async load(r){if(!e.load)return null;const s=w(o,e.name),n=w("load",I(r));if(t.has(n,s))return await t.get(n,s);const i=await J(e.load).call(this,r);return t.set(n,i,s),i},name:`cached(${e.name})`,async resolveId(r,s,n){if(!e.resolveId)return null;const i=w(o,e.name),l=w("resolveId",I(r),s?I(s):"",I(JSON.stringify(n)));if(t.has(l,i))return await t.get(l,i);const a=await J(e.resolveId).call(this,r,s,n);return t.set(l,a,i),a},async transform(r,s){if(!e.transform)return null;const n=w(o,e.name),i=w("transform",I(s),I(r));if(t.has(i,n))return await t.get(i,n);const l=await J(e.transform).call(this,r,s);return t.set(i,l,n),l}}),"cachingPlugin");var Pr=Object.defineProperty,_r=m((e,t)=>Pr(e,"name",{value:t,configurable:!0}),"n$6");const Cr=_r(()=>({name:"prependDirective",transform:{handler(e,t){const o=this.getModuleInfo(t);if(o?.meta.preserveDirectives){const r=o.meta.preserveDirectives.directives[0];if(r)return`'${r.value}';
|
|
37
|
+
`+e}return null},order:"post"}}),"prependDirectivePlugin");var Mr=Object.defineProperty,Ir=m((e,t)=>Mr(e,"name",{value:t,configurable:!0}),"c$a");const Rr=Ir(({directiveRegex:e,exclude:t=[],include:o=[],logger:r})=>{const s={},n={},i=T(o,t);return{name:"packem:preserve-directives",onLog(l,a){return a.code==="MODULE_LEVEL_DIRECTIVE"&&l==="warn"?!1:null},renderChunk:{handler(l,a,{sourcemap:c}){const p=a.moduleIds.map(f=>s[f]?s[f]:null).reduce((f,h)=>(h&&h.forEach(g=>{f.add(g)}),f),new Set),d=new C(l);p.size>0&&(r.debug({message:`directives for chunk "${a.fileName}" are preserved.`,prefix:"plugin:preserve-directives"}),d.prepend(`${[...p].map(f=>`'${f}';`).join(`
|
|
43
38
|
`)}
|
|
44
|
-
`));let u=null;return a.facadeModuleId&&typeof
|
|
45
|
-
`)),p.size===0&&u===null?null:{code:d.toString(),map:c?d.generateMap({hires:!0}):null}},order:"post"},transform(l,a){if(!i(a))return null;let c=!1;const p=new C(l);if(l.startsWith("#")&&l[1]==="!"){let u=0;for(let f=2,h=l.length;f<h;f++){const g=l.codePointAt(f);if(g===10||g===13||g===8232||g===8233){u=f;break}}u&&(
|
|
39
|
+
`));let u=null;return a.facadeModuleId&&typeof n[a.facadeModuleId]=="string"&&(u=n[a.facadeModuleId]),u&&(r.debug({message:`shebang for chunk "${a.fileName}" is preserved.`,prefix:"plugin:preserve-directives"}),d.prepend(`${u}
|
|
40
|
+
`)),p.size===0&&u===null?null:{code:d.toString(),map:c?d.generateMap({hires:!0}):null}},order:"post"},transform(l,a){if(!i(a))return null;let c=!1;const p=new C(l);if(l.startsWith("#")&&l[1]==="!"){let u=0;for(let f=2,h=l.length;f<h;f++){const g=l.codePointAt(f);if(g===10||g===13||g===8232||g===8233){u=f;break}}u&&(n[a]=l.slice(0,u),p.remove(0,u+1),c=!0,r.debug({message:`shebang for module "${a}" is preserved.`,prefix:"plugin:preserve-directives"}))}let d=null;try{d=this.parse(p.toString(),{allowReturnOutsideFunction:!0})}catch(u){return this.warn({code:"PARSE_ERROR",message:`failed to parse "${a}" and extract the directives.`}),r.warn(u),null}if(d.type!=="Program")return null;for(const u of d.body.filter(Boolean)){if(u.type!=="ExpressionStatement")break;let f=null;"directive"in u?f=u.directive:u.expression.type==="Literal"&&typeof u.expression.value=="string"&&e.test(u.expression.value)&&(f=u.expression.value),f!=="use strict"&&f&&(s[a]||=new Set,s[a].add(f),"start"in u&&typeof u.start=="number"&&"end"in u&&typeof u.end=="number"&&(p.remove(u.start,u.end),c=!0),r.debug({message:`directive "${f}" for module "${a}" is preserved.`,prefix:"plugin:preserve-directives"}))}return c?{code:p.toString(),map:p.generateMap({hires:!0}),meta:{preserveDirectives:{directives:[...s[a]??[]],shebang:n[a]??null}}}:null}}},"preserveDirectives");var Fr=Object.defineProperty,Tr=m((e,t)=>Fr(e,"name",{value:t,configurable:!0}),"t$4");const Ar=Tr(e=>{const t=T(e.include,e.exclude);return{name:"packem:raw",transform(o,r){return t(r)?{code:`export default ${JSON.stringify(o)}`,map:null}:null}}},"rawPlugin");var Jr=Object.defineProperty,Wr=m((e,t)=>Jr(e,"name",{value:t,configurable:!0}),"l$8");const ae="\0__file_url__",ft=Wr(()=>({async load(e){if(e.startsWith(ae)){const t=yo(e.slice(ae.length));return await oe(t)}},name:"packem:resolve-file-url",resolveId(e){if(e.startsWith("file://"))return`${ae}${e}`}}),"resolveFileUrl");var Br=Object.defineProperty,ne=m((e,t)=>Br(e,"name",{value:t,configurable:!0}),"i$7");const $e=/^#![^\n]*/,de=ne(async e=>{await Zt(e,493).catch(()=>{})},"makeExecutable"),Lr=ne((e,t=`#!/usr/bin/env node
|
|
41
|
+
`)=>({name:"packem:shebang",renderChunk:{handler(o,r,s){if(!r.isEntry||!r.facadeModuleId||o.startsWith("#")&&o[1]==="!")return null;if(e.includes(r.name)){const n=new C(o);return n.prepend(t),{code:n.toString(),map:s.sourcemap?n.generateMap({hires:!0}):void 0}}return null},order:"post"},async writeBundle(o,r){for(const[s,n]of Object.entries(r))if(n.type==="chunk"&&$e.test(n.code)&&o.dir){const i=$(o.dir,s);await de(i)}}}),"shebangPlugin"),Ur=ne(()=>({name:"packem:remove-shebang",renderChunk(e){return e.replace($e,"")}}),"removeShebangPlugin"),zr=ne((e,t=`
|
|
42
|
+
`)=>{const o=$e.exec(e);return o?o+t:""},"getShebang");var Vr=Object.defineProperty,F=m((e,t)=>Vr(e,"name",{value:t,configurable:!0}),"r$6");const Hr=/\/\*[^*]*\*+(?:[^/*][^*]*\*+)*\//g,qr=/MIT License|MIT license|BSD license/,Kr=/\n{2,}/g,Gr=/\b(\w+)\$\d+\b/g,Yr=/[-/\\^$*+?.()|[\]{}]/g,Xr=F(e=>e.replaceAll(Yr,"\\$&"),"escapeRegex"),Qr=F(e=>[...new Set(e)],"unique"),Zr=F(e=>e.replaceAll(Hr,t=>qr.test(t)?"":t).replaceAll(Kr,`
|
|
46
43
|
|
|
47
|
-
`),"cleanUnnecessaryComments"),Ie=new Map;function
|
|
44
|
+
`),"cleanUnnecessaryComments"),Ie=new Map;function gt(e,t,{identifierReplacements:o},r){const s=ot(e);for(const i in o){const l=s.find(c=>c.specifier===i&&c.imports.includes("{"));if(!l){this.warn(`${t.fileName} does not import "${i}" for replacement`),process.exitCode=1;continue}const a=o[i];for(const c in a){if(!l.imports.includes(c))throw new Error(`${t.fileName} does not import "${c}" from "${i}" for replacement`);const p=a[c],d=Xr(c);p.includes(".")&&(e=e.replace(new RegExp(`\\b\\w+\\b as ${d},?\\s?`),"")),e=e.replaceAll(new RegExp(`\\b${d}\\b`,"g"),p)}}const n=Qr(Array.from(e.matchAll(Gr),i=>i[0]));if(n.length>0){const i=n.map(a=>`
|
|
48
45
|
- ${a}`).join(""),l=t.fileName.replace(/\.[^/.]+$/,"");Ie.has(l)||r.warn({message:`${t.fileName} contains confusing identifier names${i}
|
|
49
46
|
|
|
50
|
-
To replace these, add them to the "rollup -> patchTypes -> identifierReplacements" option in your packem config.`,prefix:"plugin:patch-types"}),Ie.set(l,!0)}return e}m(
|
|
47
|
+
To replace these, add them to the "rollup -> patchTypes -> identifierReplacements" option in your packem config.`,prefix:"plugin:patch-types"}),Ie.set(l,!0)}return e}m(gt,"I$1");F(gt,"replaceConfusingTypeNames");const en=F((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 ht(e,t){if(e.includes("@internal")){const o=new C(e),r=bo(e,{plugins:["typescript"],sourceType:"module"});if(pt(r,{enter(s){en(o,s)&&this.skip()}}),e=o.toString(),e.includes("@internal"))throw new Error(`${t.fileName} has unhandled @internal declarations`)}return e}m(ht,"S$1");F(ht,"stripInternalTypes");const tn=F((e,t)=>({name:"packem:patch-types",renderChunk(o,r){return o=gt.call(this,o,r,e,t),o=ht.call(this,o,r),o=Zr(o),o},resolveId(o){return o.startsWith("types/")?{external:!0,id:"../../"+(o.endsWith(".js")?o:o+".js")}:null}}),"patchTypescriptTypes");var on=Object.defineProperty,yt=m((e,t)=>on(e,"name",{value:t,configurable:!0}),"m$4");const vt=yt((e,t=!0)=>{if(!e)return null;const{config:o,path:r}=e;if(!o.compilerOptions)return null;const{baseUrl:s,paths:n}=o.compilerOptions;if(!s)return null;const i=$(fe(r),s),l=[];if(n)for(const[a,c]of Object.entries(n)){let p;a==="@"||a==="~"||a==="#"?p=new RegExp(`^${a}/(.+)$`):p=new RegExp(`^${[...a].map(u=>u==="*"?"(.+)":u.replace(/[\\^$*+?.()|[\]{}]/,"\\$&")).join("")}$`);let d=0;for(const u of c){const f=[...Se($(i,u))].map(h=>h==="*"?"$"+(++d+""):h==="$"?"$$":h).join("");l.push({find:p,replacement:f})}}return t&&l.push({find:/^(?!\.*\/|\.*$|\w:)(.+)$/,replacement:`${[...Se(i)].map(a=>a==="$"?"$$":a).join("")}/$1`}),l},"getConfigAlias"),bt=yt((e,t)=>{const o=vt(e);return{name:"packem:resolve-tsconfig-paths",async resolveId(r,s,n){if(!o||r.includes("\0"))return null;for(const{find:i,replacement:l}of o)if(i.test(r)){const a=r.replace(i,l),c=await this.resolve(a,s,{skipSelf:!0,...n});if(c)return t.debug({message:`Resolved ${r} to ${c.id} using paths from tsconfig.json.`,prefix:"plugin:resolve-tsconfig-paths"}),c.id}return null}}},"resolveTsconfigPaths");var rn=Object.defineProperty,$t=m((e,t)=>rn(e,"name",{value:t,configurable:!0}),"u$5");const nn=$t((e,t)=>{if(!t)return null;const{config:o,path:r}=t;if(!o.compilerOptions)return null;const{rootDirs:s}=o.compilerOptions;if(!s)return null;const n=[];for(const i of s){if(i.startsWith("."))throw new Error(`Invalid rootDir value '.' in ${r}.`);if(i.startsWith(".."))throw new Error(`Invalid rootDir value '..' in ${r}.`);n.push($(e,i))}return n},"getRootDirectories"),wt=$t((e,t,o)=>{const r=nn(e,o);return{name:"packem:resolve-tsconfig-root-dirs",async resolveId(s,n,i){if(r===null||r.length===0)return null;if(s.startsWith("."))for(const l of r){const a=w(l,s),c=await this.resolve(a,n,{skipSelf:!0,...i});if(c)return t.debug({message:`Resolved ${s} to ${c.id} using rootDirs from tsconfig.json.`,prefix:"plugin:resolve-tsconfig-root-dirs"}),c.id}return null}}},"resolveTsconfigRootDirectories");var sn=Object.defineProperty,an=m((e,t)=>sn(e,"name",{value:t,configurable:!0}),"r$5");const jt=an(()=>{const e=/\.(?:[mc]?js|jsx)$/;return{name:"packem:resolve-typescript-mjs-cjs",async resolveId(t,o,r){return e.test(t)&&o?await this.resolve(t.replace(/js(x?)$/,"ts$1"),o,r):null}}},"resolveTypescriptMjsCts");var ln=Object.defineProperty,cn=m((e,t)=>ln(e,"name",{value:t,configurable:!0}),"s$a");const pn=cn(e=>{const t=ge(e).split(".");if(t.length>=2){const[o,r]=t.slice(-2),s=t[0],n=/^(\w+)-runtime$/.exec(o)?.[1];if(ye.includes(r)&&n&&n.length>0)return s+"-"+n}},"getCustomModuleLayer");var un=Object.defineProperty,dn=m((e,t)=>un(e,"name",{value:t,configurable:!0}),"i$6");const le=dn(e=>(e.preserveDirectives||{directives:[]}).directives.map(t=>t.replace(/^use /,"")).find(t=>t!=="strict"),"getModuleLayer");var mn=Object.defineProperty,Re=m((e,t)=>mn(e,"name",{value:t,configurable:!0}),"c$7");const fn=Re((e,t)=>{const o=new Map;return Re(function(r,s){const n=s.getModuleInfo(r);if(!n)return;const{isEntry:i}=n,l=n.meta,a=le(l);if(!i){const c=o.get(r);if(c)return c;const p=pn(r);if(p)return o.set(r,p),p}if(i){const c=s.getModuleIds();for(const p of c)s.getModuleInfo(p)&&le(l)===a&&(e.has(p)||e.set(p,new Set),e.get(p).add([r,a]))}if(a&&!i&&e.has(r)){const c=[...e.get(r)];if(c.some(([d])=>{if(t.some(u=>u.path===d)){const u=s.getModuleInfo(d);return le(u?u.meta:{})===a}return!1}))return;if(c.every(([,d])=>d===a))return o.has(r)?o.get(r):void 0;const p=ge(r,he(r))+"-"+a;return o.set(r,p),p}},"splitChunks")},"createSplitChunks");var gn=Object.defineProperty,hn=m((e,t)=>gn(e,"name",{value:t,configurable:!0}),"n$4");const P=hn((e,t)=>e.isDynamicEntry?`chunks/[name].${t}`:`shared/${e.name}-[hash].${t}`,"getChunkFilename");var yn=Object.defineProperty,vn=m((e,t)=>yn(e,"name",{value:t,configurable:!0}),"s$8");const bn=process.platform==="win32",Fe=vn((e,t)=>{const o=bn?"\\":"/";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 $n=Object.defineProperty,wn=m((e,t)=>$n(e,"name",{value:t,configurable:!0}),"p$1");const we=wn((e,t)=>{let o={};if(e.pkg.name&&(o[e.pkg.name]=e.options.rootDir),e.pkg.imports){const{imports:r}=e.pkg;for(const s in r){if(s.startsWith("#"))continue;const n=r[s];typeof n=="string"&&(o[s]=w(e.options.rootDir,n))}}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(r=>[r.find,r.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 jn=Object.defineProperty,k=m((e,t)=>jn(e,"name",{value:t,configurable:!0}),"l$7");const kn=k((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"+Ft.node.split(".")[0];if(t.pkg.engines?.node){const r=tt(t.pkg.engines.node);r&&(o="node"+r.major)}if(t.options.rollup.esbuild.target){const r=B(t.options.rollup.esbuild.target);r.some(s=>s.startsWith("node"))||(t.options.rollup.esbuild.target=[...new Set([...B(o),...r])])}else t.options.rollup.esbuild.target=B(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"),kt=k((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(N($(),e.id))}"
|
|
51
48
|
Is the module installed? Note:
|
|
52
49
|
↳ to inline a module into your bundle, install it to "devDependencies".
|
|
53
|
-
↳ to depend on a module via import/require, install it to "dependencies".`);return e.code==="MODULE_LEVEL_DIRECTIVE"?!0:e.code==="MIXED_EXPORTS"&&t.options.cjsInterop===!0},"sharedOnWarn"),Te=new Map,
|
|
54
|
-
${i.stack}`),
|
|
55
|
-
|
|
50
|
+
↳ to depend on a module via import/require, install it to "dependencies".`);return e.code==="MODULE_LEVEL_DIRECTIVE"?!0:e.code==="MIXED_EXPORTS"&&t.options.cjsInterop===!0},"sharedOnWarn"),Te=new Map,xt=k((e,t,o)=>{const r=k(n=>{for(const[i,l]of Object.entries(t))if(n.startsWith(i))return n.replace(i,l)},"findAlias"),s=vt(e.tsconfig,!1);return{external(n){const i=r(n);i&&(n=i);const l=st(n);if(ue(e.options.externals,l)||ue(e.options.externals,n))return!0;const{pkg:a}=e;if(n.startsWith(".")||Ge(n)||/src[/\\]/.test(n)||a.name&&n.startsWith(a.name)||a?.imports?.[n]!==void 0)return!1;if(s){for(const{find:c}of s)if(c.test(n))return e.logger.debug({message:`Resolved alias ${n} to ${c.source}`,prefix:o}),!1}return Te.has(n)||e.logger.info({message:'Inlined implicit external "'+j(n)+'". If this is incorrect, add it to the "externals" option.',prefix:o}),Te.set(n,!0),!1},input:Object.fromEntries(e.options.entries.map(n=>[n.name,$(e.options.rootDir,n.input)])),logLevel:e.options.debug?"debug":"info",onLog:k((n,i)=>{let l=i.message;switch(i.stack&&(l=`${l}
|
|
51
|
+
${i.stack}`),n){case"info":{e.logger.info({message:l,prefix:o+(i.plugin?":plugin:"+i.plugin:"")});return}case"warn":{e.logger.warn({message:l,prefix:o+(i.plugin?":plugin:"+i.plugin:"")});return}case"debug":e.logger.debug({message:l,prefix:o+(i.plugin?":plugin:"+i.plugin:"")})}},"onLog"),onwarn(n,i){kt(n,e)||n.code||i(n)},watch:e.mode==="watch"?e.options.rollup.watch:!1}},"baseRollupOptions"),Et=k(async(e,t)=>{const o=we(e,"build");let r;e.options.rollup.resolve&&(r=E(Ze({...e.options.rollup.resolve}),t));const s=e.options.rollup.output?.preserveModules?{preserveModules:!0,preserveModulesRoot:e.options.rollup.output.preserveModulesRoot??"src"}:{manualChunks:fn(e.dependencyGraphMap,e.buildEntries),preserveModules:!1};return{...xt(e,o,"dependencies"),output:[e.options.emitCJS&&{chunkFileNames:k(n=>P(n,"cjs"),"chunkFileNames"),dir:$(e.options.rootDir,e.options.outDir),entryFileNames:k(n=>Fe(n,"cjs"),"entryFileNames"),exports:"auto",externalLiveBindings:!1,format:"cjs",freeze:!1,generatedCode:{arrowFunctions:!0,constBindings:!0,objectShorthand:!0,preset:e.tsconfig?.config.compilerOptions?.target==="es5"?"es5":"es2015",reservedNamesAsProps:!0,symbols:!0},hoistTransitiveImports:!1,interop:"compat",sourcemap:e.options.sourcemap,validate:!0,...e.options.rollup.output,...s},e.options.emitESM&&{chunkFileNames:k(n=>P(n,"mjs"),"chunkFileNames"),dir:$(e.options.rootDir,e.options.outDir),entryFileNames:k(n=>Fe(n,"mjs"),"entryFileNames"),exports:"auto",externalLiveBindings:!1,format:"esm",freeze:!1,generatedCode:{arrowFunctions:!0,constBindings:!0,objectShorthand:!0,preset:e.tsconfig?.config.compilerOptions?.target==="es5"?"es5":"es2015",reservedNamesAsProps:!0,symbols:!0},hoistTransitiveImports:!1,sourcemap:e.options.sourcemap,validate:!0,...e.options.rollup.output,...s}].filter(Boolean),plugins:[E(ft(),t),E(jt(),t),e.tsconfig&&E(wt(e.options.rootDir,e.logger,e.tsconfig),t),e.tsconfig&&E(bt(e.tsconfig,e.logger),t),e.options.rollup.replace&&et({sourcemap:e.options.sourcemap,...e.options.rollup.replace,values:{...e.options.replace,...e.options.rollup.replace.values}}),e.options.rollup.alias&&Qe({customResolver:r,...e.options.rollup.alias,entries:o}),r,e.options.rollup.polyfillNode&&ro({sourceMap:e.options.sourcemap,...e.options.rollup.polyfillNode}),e.options.rollup.json&&ct({...e.options.rollup.json}),Ho(),e.options.rollup.wsam&&oo(e.options.rollup.wsam),e.options.declaration&&e.options.rollup.isolatedDeclarations&&e.options.isolatedDeclarationTransformer&&pr(e.options.isolatedDeclarationTransformer,e.options.declaration,e.pkg.type,e.options.rollup.isolatedDeclarations),e.options.transformer?.(kn(e.options.transformerName,e)),Rr({directiveRegex:/^['|"](use (\w+))['|"]$/,...e.options.rollup.preserveDirectives,logger:e.logger}),Lr(e.options.entries.filter(n=>n.executable).map(n=>n.name).filter(Boolean)),e.options.cjsInterop&&e.options.emitCJS&<({...e.options.rollup.cjsInterop,logger:e.logger,type:e.pkg.type??"commonjs"}),e.options.rollup.dynamicVars&&sr(),e.options.rollup.dynamicVars&&to(e.options.rollup.dynamicVars),e.options.rollup.commonjs&&E(eo({sourceMap:e.options.sourcemap,...e.options.rollup.commonjs}),t),e.options.rollup.preserveDynamicImports&&{renderDynamicImport(){return{left:"import(",right:")"}}},e.options.rollup.shim&&or(e.pkg,e.options.rollup.shim),e.options.rollup.raw&&Ar(e.options.rollup.raw),e.options.rollup.jsxRemoveAttributes&&yr({attributes:e.options.rollup.jsxRemoveAttributes.attributes,logger:e.logger}),e.options.rollup.metafile&&kr({outDir:$(e.options.rootDir,e.options.outDir),rootDir:e.options.rootDir}),e.options.rollup.copy&&Yo(e.options.rollup.copy,e.logger),e.options.rollup.license&&e.options.rollup.license.path&&typeof e.options.rollup.license.dependenciesTemplate=="function"&&ut({dtsMarker:e.options.rollup.license.dtsMarker??"TYPE_DEPENDENCIES",licenseFilePath:e.options.rollup.license.path,licenseTemplate:e.options.rollup.license.dependenciesTemplate,logger:e.logger,marker:e.options.rollup.license.dependenciesMarker??"DEPENDENCIES",mode:"dependencies",packageName:e.pkg.name}),Cr(),e.options.rollup.visualizer&&no({brotliSize:!0,filename:"packem-bundle-analyze.html",gzipSize:!0,projectRoot:e.options.rootDir,sourcemap:e.options.sourcemap,title:"Packem Visualizer",...e.options.rollup.visualizer})].filter(Boolean)}},"getRollupOptions"),xn=k(async e=>{const{dts:t}=require("rollup-plugin-dts");return t({compilerOptions:{...e.options.rollup.dts.compilerOptions,incremental:void 0,inlineSources:void 0,sourceMap:void 0,tsBuildInfoFile:void 0},respectExternal:e.options.rollup.dts.respectExternal,tsconfig:e.tsconfig?.path})},"createDtsPlugin"),En=Mo(xn),Ot=k(async(e,t)=>{const o=we(e,"types"),r={load(l){return/\.(?:js|cjs|mjs|jsx|ts|tsx|mts|json)$/.test(l)?null:""},name:"packem:ignore-files"},s=e.tsconfig?.config.compilerOptions;delete s?.lib;let n;e.options.rollup.resolve&&(n=E(Ze({...e.options.rollup.resolve}),t));const i="dts-plugin:"+process.pid+e.tsconfig.path;return{...xt(e,o,"dts"),onwarn(l,a){kt(l,e)||l.code!=="EMPTY_BUNDLE"&&a(l)},output:[e.options.emitCJS&&{chunkFileNames:k(l=>P(l,"d.cts"),"chunkFileNames"),dir:$(e.options.rootDir,e.options.outDir),entryFileNames:"[name].d.cts",format:"cjs",sourcemap:e.options.sourcemap,...e.options.rollup.output},e.options.emitESM&&{chunkFileNames:k(l=>P(l,"d.mts"),"chunkFileNames"),dir:$(e.options.rootDir,e.options.outDir),entryFileNames:"[name].d.mts",format:"esm",sourcemap:e.options.sourcemap,...e.options.rollup.output},e.options.declaration==="compatible"&&{chunkFileNames:k(l=>P(l,"d.ts"),"chunkFileNames"),dir:$(e.options.rootDir,e.options.outDir),entryFileNames:"[name].d.ts",format:"cjs",sourcemap:e.options.sourcemap,...e.options.rollup.output}].filter(Boolean),plugins:[E(ft(),t),E(jt(),t),e.options.rollup.json&&ct({...e.options.rollup.json}),r,e.tsconfig&&E(wt(e.options.rootDir,e.logger,e.tsconfig),t),e.tsconfig&&E(bt(e.tsconfig,e.logger),t),e.options.rollup.replace&&et({sourcemap:e.options.sourcemap,...e.options.rollup.replace,values:{...e.options.replace,...e.options.rollup.replace.values}}),e.options.rollup.alias&&Qe({customResolver:n,...e.options.rollup.alias,entries:o}),n,await En(i)(e),e.options.cjsInterop&&e.options.emitCJS&<({...e.options.rollup.cjsInterop,logger:e.logger,type:e.pkg.type??"commonjs"}),e.options.rollup.patchTypes&&tn(e.options.rollup.patchTypes,e.logger),Ur(),e.options.rollup.license&&e.options.rollup.license.path&&typeof e.options.rollup.license.dtsTemplate=="function"&&ut({licenseFilePath:e.options.rollup.license.path,licenseTemplate:e.options.rollup.license.dtsTemplate,logger:e.logger,marker:e.options.rollup.license.dtsMarker??"TYPE_DEPENDENCIES",mode:"types",packageName:e.pkg.name}),Or(e)].filter(Boolean)}},"getRollupDtsOptions");var On=Object.defineProperty,Sn=m((e,t)=>On(e,"name",{value:t,configurable:!0}),"c$6");const ce=Sn(async(e,t,o)=>{const r=await Et(e,t);if(await e.hooks.callHook("rollup:options",e,r),Object.keys(r.input).length===0)return;const s="rollup-build.json";r.cache=t.get(s,o);const n=await Ye(r);t.set(s,n.cache,o),await e.hooks.callHook("rollup:build",e,n);const i=new Map;for(const l of r.output){const{output:a}=await n.write(l),c=new Set,p=a.filter(u=>u.type==="chunk");for(const u of p){c.add(u.fileName);for(const f of u.imports)e.usedImports.add(f);u.isEntry&&e.buildEntries.push({bytes:Buffer.byteLength(u.code,"utf8"),chunks:u.imports.filter(f=>p.find(h=>h.fileName===f)),exports:u.exports,modules:Object.entries(u.modules).map(([f,h])=>({bytes:h.renderedLength,id:f})),path:u.fileName,type:"entry"})}const d=a.filter(u=>u.type==="asset");for(const u of d)i.has(u.fileName)||i.set(u.fileName,{bytes:Buffer.byteLength(u.source,"utf8"),path:u.fileName,type:"asset"});for(const u of c)e.usedImports.delete(u)}e.buildEntries.push(...i.values())},"build");var Dn=Object.defineProperty,q=m((e,t)=>Dn(e,"name",{value:t,configurable:!0}),"a$7");const K=q(async(e,t,o)=>{if(e.options.declaration&&e.options.rollup.isolatedDeclarations&&e.options.isolatedDeclarationTransformer){e.logger.info({message:"Using isolated declaration transformer to generate declaration files...",prefix:"dts"});return}const r=await Ot(e,t);if(await e.hooks.callHook("rollup:dts:options",e,r),Object.keys(r.input).length===0)return;const s="rollup-dts.json";r.cache=t.get(s,o);const n=await Ye(r);t.set(s,n.cache,o),await e.hooks.callHook("rollup:dts:build",e,n),e.logger.info({message:"Building declaration files...",prefix:"dts"}),e.options.emitCJS&&await n.write({chunkFileNames:q(i=>P(i,"d.cts"),"chunkFileNames"),dir:$(e.options.rootDir,e.options.outDir),entryFileNames:"[name].d.cts"}),e.options.emitESM&&await n.write({chunkFileNames:q(i=>P(i,"d.mts"),"chunkFileNames"),dir:$(e.options.rootDir,e.options.outDir),entryFileNames:"[name].d.mts"}),e.options.declaration==="compatible"&&await n.write({chunkFileNames:q(i=>P(i,"d.mjs"),"chunkFileNames"),dir:$(e.options.rootDir,e.options.outDir),entryFileNames:"[name].d.ts"}),await e.hooks.callHook("rollup:dts:done",e)},"buildTypes");var Nn=Object.defineProperty,Pn=m((e,t)=>Nn(e,"name",{value:t,configurable:!0}),"y$1");const _n=Pn((e,t,o)=>e.reduce((r,s)=>{const n=s[t],i=s[o];return r[n]||(r[n]={}),r[n][i]||(r[n][i]=[]),r[n][i].push(s),r},{}),"groupByKeys");var Cn=Object.defineProperty,ee=m((e,t)=>Cn(e,"name",{value:t,configurable:!0}),"b$1");const Mn=ee((e,t,o)=>{const r=ee(n=>N(t.options.rootDir,$(t.options.outDir,n)),"rPath");let s=!1;for(const n of t.buildEntries.filter(i=>!i.chunk)){let i=n.bytes??0;for(const a of n.chunks??[])i+=t.buildEntries.find(c=>c.path===a)?.bytes??0;let l=` ${D(r(n.path))} (${["total size: "+j(M(i)),n.type!=="asset"&&n.bytes&&"chunk size: "+j(M(n.bytes))].filter(Boolean).join(", ")})`;if(l+=n.exports?.length?`
|
|
52
|
+
exports: `+R(n.exports.join(", ")):"",n.chunks?.length&&(l+=`
|
|
53
|
+
${n.chunks.map(a=>{const c=t.buildEntries.find(p=>p.path===a)??{};return R(" └─ "+r(a)+D(c.bytes?" ("+M(c?.bytes)+")":""))}).join(`
|
|
54
|
+
`)}`),n.modules&&n.modules.length>0){const a=n.modules.filter(c=>c.id.includes("node_modules")).sort((c,p)=>(p.bytes||0)-(c.bytes||0)).map(c=>R(" 📦 "+r(c.id)+D(c.bytes?" ("+M(c.bytes)+")":""))).join(`
|
|
55
|
+
`);l+=a.length>0?`
|
|
56
|
+
inlined modules:
|
|
57
|
+
`+a:""}if(t.options.declaration&&n.type==="entry"){let a=n.path.replace(/\.js$/,".d.ts"),c="commonjs";n.path.endsWith(".cjs")?a=n.path.replace(/\.cjs$/,".d.cts"):n.path.endsWith(".mjs")&&(c="module",a=n.path.replace(/\.mjs$/,".d.mts"));const p=t.buildEntries.find(d=>d.path.endsWith(a));if(p){let d;a.includes(".d.ts")||(a=a.replace(c==="commonjs"?".d.c":".d.m",".d."),d=t.buildEntries.find(u=>u.path.endsWith(a))),l+=d&&c===o.type?`
|
|
58
|
+
types:
|
|
59
|
+
`+[p,d].map(u=>R(" └─ ")+D(r(u.path))+" (total size: "+j(M(u.bytes??0))+")").join(`
|
|
60
|
+
`):`
|
|
61
|
+
types: `+D(r(p.path))+" (total size: "+j(M(p.bytes??0))+")"}}s=!0,l+=`
|
|
62
|
+
|
|
63
|
+
`,e.raw(n.chunk?R(l):l)}return s&&e.raw("Σ Total dist size (byte size):",j(M(t.buildEntries.reduce((n,i)=>n+(i.bytes??0),0))),`
|
|
64
|
+
`),s},"showSizeInformation"),In=ee((e,t)=>{const o=_n(e.options.entries,"environment","runtime"),r=[];for(const[s,n]of Object.entries(o))for(const[i,l]of Object.entries(n)){const a={...e};(s!=="undefined"||i!=="undefined")&&e.logger.info("Preparing build for "+(s==="undefined"?"":j(s)+" environment"+(i==="undefined"?"":" with "))+(i==="undefined"?"":j(i)+" runtime")),a.options.rollup.replace?(a.options.rollup.replace.values===void 0&&(a.options.rollup.replace.values={}),s!=="undefined"&&(a.options.rollup.replace.values={...a.options.rollup.replace.values,[["process","env","NODE_ENV"].join(".")]:JSON.stringify(s)}),a.options.rollup.replace.values={...a.options.rollup.replace.values,[["process","env","EdgeRuntime"].join(".")]:JSON.stringify(i==="edge-light")}):e.logger.warn("'replace' plugin is disabled. You should enable it to replace 'process.env.*' environments.");let c="";s!=="undefined"&&(c+=s+"/"),i!=="undefined"&&(c+=i+"/");let p=!1;a.options.minify!==void 0&&(p=a.options.minify),s==="development"?p=!1:s==="production"&&(p=!0);const d=[],u=[],f=[],h=[];for(const g of l)g.cjs&&g.esm?d.push(g):g.cjs?f.push(g):g.esm?u.push(g):g.declaration&&h.push(g);if(d.length>0){const g={...a,options:{...a.options,emitCJS:!0,emitESM:!0,entries:d,minify:p}};r.push(ce(g,t,c));const b=g.options.entries.filter(v=>v.declaration);e.options.declaration&&b.length>0&&r.push(K({...g,options:{...g.options,entries:b}},t,c))}if(u.length>0){const g={...a,options:{...a.options,emitCJS:!1,emitESM:!0,entries:u,minify:p}};r.push(ce(g,t,c));const b=g.options.entries.filter(v=>v.declaration);e.options.declaration&&b.length>0&&r.push(K({...g,options:{...g.options,entries:b}},t,c))}if(f.length>0){const g={...a,options:{...a.options,emitCJS:!0,emitESM:!1,entries:f,minify:p}};r.push(ce(g,t,c));const b=g.options.entries.filter(v=>v.declaration);e.options.declaration&&b.length>0&&r.push(K({...g,options:{...g.options,entries:b}},t,c))}if(a.options.declaration&&h.length>0){const g={...a,options:{...a.options,emitCJS:!1,emitESM:!1,entries:h,minify:p}};r.push(K(g,t,c))}}return r},"prepareRollupConfig"),Rn=ee(async(e,t,o)=>{await e.hooks.callHook("build:before",e),e.options.minify&&e.logger.info("Minification is enabled, the output will be minified");const r=t.dependencies?.typescript!==void 0||t.devDependencies?.typescript!==void 0;if(e.options.declaration&&e.tsconfig===void 0&&r)throw new Error("Cannot build declaration files without a tsconfig.json");r?e.options.declaration===!1&&e.logger.info({message:"Generation of declaration files are disabled.",prefix:"dts"}):(e.options.declaration=!1,e.logger.info({message:"Typescript is not installed. Generation of declaration files are disabled.",prefix:"dts"})),e.options.declaration&&e.logger.info("Using typescript version: "+j(t.devDependencies?.typescript??t.dependencies?.typescript??"unknown")),e.options.declaration&&(t.dependencies?.typescript||t.devDependencies?.typescript)&&!e.tsconfig?.config.compilerOptions?.isolatedModules&&e.logger.warn(`'compilerOptions.isolatedModules' is not enabled in tsconfig.
|
|
65
|
+
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.
|
|
66
|
+
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 Promise.all(In(e,o)),e.logger.success(At(e.options.name?"Build succeeded for "+e.options.name:"Build succeeded"));for await(const s of Lt(w(e.options.rootDir,e.options.outDir))){let n=e.buildEntries.find(i=>w(e.options.rootDir,e.options.outDir,i.path)===s.path);if(n||(n={chunk:!0,path:s.path},e.buildEntries.push(n)),!n.bytes){const i=await Xe($(e.options.rootDir,e.options.outDir,s.path));n.bytes=i.size}}return await e.hooks.callHook("build:done",e),Mn(e.logger,e,t)},"build");var Fn=Object.defineProperty,Tn=m((e,t)=>Fn(e,"name",{value:t,configurable:!0}),"r$3");const St=Tn((e,t)=>rt(t,{esmResolve:!0,interopDefault:!0})(e),"tryRequire");var An=Object.defineProperty,Jn=m((e,t)=>An(e,"name",{value:t,configurable:!0}),"i$4");const je=Jn(e=>`{ ${Object.keys(e).map(t=>`${t}: ${JSON.stringify(e[t])}`).join(", ")} }`,"dumpObject");var Wn=Object.defineProperty,Bn=m((e,t)=>Wn(e,"name",{value:t,configurable:!0}),"r$1");const L=Bn((e,t)=>{e.warnings.has(t)||e.warnings.add(t)},"warn");var Ln=Object.defineProperty,Dt=m((e,t)=>Ln(e,"name",{value:t,configurable:!0}),"e$1");const te=Dt(e=>{if(e.endsWith(".mjs")||e.endsWith(".d.mts"))return"esm";if(e.endsWith(".cjs")||e.endsWith(".d.cts"))return"cjs"},"inferExportTypeFromFileName"),Nt=Dt((e,t,o,r)=>{if(r){const i=te(r);if(i)return i}if(e==="module"||e==="import")return"esm";if(e==="require")return"cjs";if(t.length===0)return o;const[s,...n]=t;return Nt(s,n,o,r)},"inferExportType");var Un=Object.defineProperty,zn=m((e,t)=>Un(e,"name",{value:t,configurable:!0}),"i$2");const Vn=new Set(["import","require","node","node-addons","default","types","deno","browser",...Z]),ke=zn((e,t,o,r=[])=>{if(!e)return[];if(typeof e=="string"){const s=te(e);if(s&&s!==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:s??t}]}return Object.entries(e).filter(([s])=>!s.endsWith(".json")).flatMap(([s,n])=>o===!1&&s==="types"?[]:typeof n=="string"?{file:n,key:"exports",...Vn.has(s)?{subKey:s}:{},type:Nt(s,r,t,n)}:ke(n,t,o,[...r,s]))},"extractExportFilenames");var Hn=Object.defineProperty,se=m((e,t)=>Hn(e,"name",{value:t,configurable:!0}),"c$3");const qn=se((e,t)=>e.key==="exports"&&e.subKey===W?W:e.key==="exports"&&e.subKey===De?De:t,"getEnvironment"),G=se((e,t,o,r,s,n)=>{const i=qn(s,n.environment);let l="node";for(const p of mo)if(s.file.includes("."+p+".")||s.subKey===p){l=p;break}let a=e.find(p=>p.input===t&&p.environment===i&&p.runtime===l);a===void 0&&(a=e[e.push({environment:i,input:t,runtime:l})-1]),o&&(a.outDir=r),s.isExecutable?(a.executable=!0,a.declaration=!1,s.type==="cjs"&&(a.cjs=!0),s.type==="esm"&&(a.esm=!0)):(/\.d\.[mc]?ts$/.test(s.file)&&n.options.declaration!==!1&&(a.declaration=n.options.declaration),s.type==="cjs"&&(a.cjs=!0),s.type==="esm"&&(a.esm=!0));const c=s.file.replace(he(s.file),"").replace(new RegExp(`^./${n.options.outDir.replace(/^\.\//,"")}/`),"");Z.has(s.subKey)&&!t.includes(c)&&(a.fileAlias=c)},"createOrUpdateEntry");let Ae=!1;const Je=se(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"),Kn=se((e,t,o)=>{const r=[];t.sort((l,a)=>l.split("/").length-a.split("/").length);const s=e.type==="module"?"esm":"cjs";s==="esm"&&(o.options.emitESM=!0),s==="cjs"&&(o.options.emitCJS=!0);const n=ke(e.exports,s,o.options.declaration);if(e.bin){const l=(typeof e.bin=="string"?[e.bin]:Object.values(e.bin)).filter(Boolean);for(const a of l){const c=te(a);if(c&&c!==s)throw new Error(`Exported file "${a}" has an extension that does not match the package.json type "${e.type??"commonjs"}".`);n.push({file:a,isExecutable:!0,key:"bin",type:c??s})}}e.main&&n.push({file:e.main,key:"main",type:te(e.main)??s}),e.module&&n.push({file:e.module,key:"module",type:"esm"}),(e.types||e.typings)&&(Je(o),o.options.declaration===void 0&&(o.options.declaration="compatible"),n.push({file:e.types??e.typings,key:"types"}));const i=[];for(const l of n){o.options.declaration===void 0&&(l.key==="types"||l.subKey==="types")&&(o.options.declaration=l.file.includes(".d.ts")?"compatible":!0),o.options.emitCJS===void 0&&l.type==="cjs"&&(o.options.emitCJS=!0),o.options.emitESM===void 0&&l.type==="esm"&&(o.options.emitESM=!0);const a=l.file.replace(/(?:\*[^/\\]|\.d\.[mc]?ts|\.\w+)$/,""),c=a.endsWith("/");if(c&&["./","/"].includes(a))continue;const p=a.replace(new RegExp("(./)?"+o.options.outDir),o.options.sourceDir).replace("./",""),d="(?<=/|$)",u=c?"":"\\.\\w+$";if(l.file.includes("/*")&&l.key==="exports"){Ae||(o.logger.debug("Private subfolders are not supported, if you need this feature please open an issue on GitHub."),Ae=!0);const b=[],v=new RegExp(d+p.replace("*","(.*)")+u),y=new RegExp(d+p.replace(/(.*)\.[^.]*$/,"$1").replace("*","(.*)")+u);for(const x of t)(v.test(x)||Z.has(l.subKey)&&y.test(x))&&b.push(x);if(b.length===0){r.push(`Could not find entrypoint for \`${l.file}\``);continue}for(const x of b)G(i,x,c,a,l,o);continue}const f=new RegExp(d+p+u);let h=t.find(b=>f.test(b));if(Z.has(l.subKey)&&h===void 0){const b=new RegExp(d+p.replace(/(.*)\.[^.]*$/,"$1")+u);h=t.find(v=>b.test(v))}if(h===void 0){O($(o.options.rootDir,l.file))||r.push(`Could not find entrypoint for \`${l.file}\``);continue}(h.endsWith(".ts")||h.endsWith(".cts")||h.endsWith(".mts"))&&O(h)&&Je(o);const g=h.replace(Q,"");O(g+".cts")&&O(g+".mts")?(G(i,g+".cts",c,a,{...l,type:"cjs"},o),G(i,g+".mts",c,a,{...l,type:"esm"},o)):G(i,h,c,a,l,o)}return{entries:i,warnings:r}},"inferEntries");var Gn=Object.defineProperty,Yn=m((e,t)=>Gn(e,"name",{value:t,configurable:!0}),"o$3");const Xn=Yn((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 Qn=Object.defineProperty,Zn=m((e,t)=>Qn(e,"name",{value:t,configurable:!0}),"l$6");const es={hooks:{"build:prepare":Zn(function(e){if(e.options.entries.length>0)return;const t=w(e.options.rootDir,e.options.sourceDir);if(!nt(t))throw new Error("No 'src' directory found. Please provide entries manually.");const o=Ut(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 r={...e.pkg};r.publishConfig&&(e.logger.info('Using publishConfig found in package.json, to override the default key-value pairs of "'+Object.keys(r.publishConfig).join(", ")+'".'),e.logger.debug(je(r.publishConfig)),r=Xn(r,e.options.declaration));const s=Kn(r,o,e);for(const n of s.warnings)L(e,n);if(e.options.entries.push(...s.entries),e.options.entries.length===0)throw new Error("No entries detected. Please provide entries manually.");e.logger.info("Automatically detected entries:",j(e.options.entries.map(n=>n.fileAlias?D(n.fileAlias)+" => "+D(n.input.replace(`${e.options.rootDir}/`,"").replace(/\/$/,"/*")):D(n.input.replace(`${e.options.rootDir}/`,"").replace(/\/$/,"/*"))).join(", ")),R([e.options.emitESM&&"esm",e.options.emitCJS&&"cjs",e.options.declaration&&"dts"].filter(Boolean).map(n=>`[${n}]`).join(" ")))},"build:prepare")}};var ts=Object.defineProperty,os=m((e,t)=>ts(e,"name",{value:t,configurable:!0}),"n$1");const rs=os((e,t)=>{if(e==="auto")e=es;else{if(e==="none")return{};typeof e=="string"&&(e=St(e,t))}return typeof e=="function"&&(e=e()),e},"resolvePreset");var ns=Object.defineProperty,ss=m((e,t)=>ns(e,"name",{value:t,configurable:!0}),"o$2");const is=ss((e,t)=>{const o=rt(t,{esmResolve:!0,interopDefault:!0});try{return o.resolve(e)}catch(r){if(r.code!=="MODULE_NOT_FOUND")throw new Error(`Error trying import ${e} from ${t}`,{cause:r});return e}},"tryResolve");var as=Object.defineProperty,ls=m((e,t)=>as(e,"name",{value:t,configurable:!0}),"u$2");const cs=ls(async e=>{const t=await co("jiti",{url:import.meta.url}),o=JSON.stringify({...e.options.stubOptions.jiti,alias:{...we(e,"jit"),...e.options.stubOptions.jiti.alias}},null,2);for(const r of e.options.entries){const s=$(e.options.rootDir,e.options.outDir,r.name),n=me(is(r.input,e.options.rootDir)||r.input),i=n.slice(0,Math.max(0,n.length-he(n).length)),l=await oe(n),a=zr(l);e.options.emitCJS&&await V(`${s}.cjs`,a+[`const jiti = require(${JSON.stringify(t)})`,"",`const _jiti = jiti(null, ${o})`,"",`/** @type {import(${JSON.stringify(i)})} */`,`module.exports = _jiti(${JSON.stringify(n)})`].join(`
|
|
67
|
+
`));let c=[];try{c=await po(n,{extensions:ye})}catch(d){L(e,`Cannot analyze ${n} for exports: ${d.toString()}`);return}const p=c.includes("default")||c.length===0;await V(`${s}.mjs`,a+[`import jiti from ${JSON.stringify(vo(t).href)};`,"",`const _jiti = jiti(null, ${o})`,"",`/** @type {import(${JSON.stringify(n)})} */`,`const _module = await _jiti.import(${JSON.stringify(n)});`,p?`
|
|
68
|
+
export default _module;`:"",...c.filter(d=>d!=="default").map(d=>`export const ${d} = _module.${d};`)].join(`
|
|
69
|
+
`)),await V(`${s}.d.cts`,[`export * from ${JSON.stringify(i)};`,p?`export { default } from ${JSON.stringify(i)};`:""].join(`
|
|
70
|
+
`)),await V(`${s}.d.mts`,[`export * from ${JSON.stringify(n)};`,p?`export { default } from ${JSON.stringify(n)};`:""].join(`
|
|
71
|
+
`)),a&&(await de(`${s}.cjs`),await de(`${s}.mjs`))}await e.hooks.callHook("rollup:done",e)},"createStub");var ps=Object.defineProperty,xe=m((e,t)=>ps(e,"name",{value:t,configurable:!0}),"i$1");const us=xe(e=>{const{message:t,name:o="Error",stack:r}=e;if(!r)return r;const s=`${o}: ${t}
|
|
72
|
+
`;return r.startsWith(s)?r.slice(s.length):r},"extractStack"),ds=xe(e=>`
|
|
56
73
|
${e.replaceAll(/^\n|\n$/g,"")}
|
|
57
|
-
`,"normalizeCodeFrame"),
|
|
74
|
+
`,"normalizeCodeFrame"),Pt=xe(e=>{const t=us(e);let o=(e.plugin?`[${e.plugin}] `:"")+e.message;e.id&&(o+=`
|
|
58
75
|
file: ${j(e.id+(e.loc?":"+e.loc.line+":"+e.loc.column:""))}`),e.frame&&(o+=`
|
|
59
|
-
`+
|
|
60
|
-
${t}`)},"enhanceRollupError");var
|
|
61
|
-
└─ ${N(process.cwd(),i)}`);if(e.logger.info(
|
|
62
|
-
- `+j(l)+(a.length>0?Tt` (did you mean ${a.map(c=>`"${c}"`).join(", ")}?)`:"")}L(t,i)}},"validatePackage");var xs=Object.defineProperty,x=m((e,t)=>xs(e,"name",{value:t,configurable:!0}),"h");const Pt=x((e,t)=>{if(e.warnings.size>0&&(t&&e.logger.raw(`
|
|
76
|
+
`+Jt(ds(e.frame))),e.message=o,t!==void 0&&(e.stack=`${e.message}
|
|
77
|
+
${t}`)},"enhanceRollupError");var ms=Object.defineProperty,_t=m((e,t)=>ms(e,"name",{value:t,configurable:!0}),"l$4");const We=_t((e,t,o)=>{const r="watcher:"+t;e.on("change",(s,{event:n})=>{o.info({message:`${j(N(".",s))} was ${n}d`,prefix:r})}),e.on("restart",()=>{o.info({message:"Rebuilding "+t+"...",prefix:r})}),e.on("event",async s=>{switch(s.code){case"END":{o.success({message:"Rebuild "+t+" finished",prefix:r});break}case"BUNDLE_START":{o.info({message:j("build started..."),prefix:r});break}case"BUNDLE_END":{await s.result.close(),o.info({message:j(`built in ${s.duration+""}ms.`),prefix:r});break}case"ERROR":{Pt(s.error),o.error({context:[s.error],message:"Rebuild "+t+" failed: "+s.error.message,prefix:r});break}}})},"watchHandler"),fs=_t(async(e,t)=>{const o=await Et(e,t);if(await e.hooks.callHook("rollup:options",e,o),Object.keys(o.input).length===0)return;o.cache=t.get("rollup-watch"),typeof o.watch=="object"&&o.watch.include===void 0&&(o.watch.include=[w(e.options.sourceDir,"**")],o.watch.chokidar={cwd:e.options.rootDir,...o.watch.chokidar});const r=Oe(o);await e.hooks.callHook("rollup:watch",e,r);const s=[...Array.isArray(o.input)?o.input:typeof o.input=="string"?[o.input]:Object.keys(o.input??{})];let n="Starting watchers for entries:";for(const i of s)n+=R(`
|
|
78
|
+
└─ ${N(process.cwd(),i)}`);if(e.logger.info(n),We(r,"bundle",e.logger),e.options.declaration){const i=await Ot(e,t);await e.hooks.callHook("rollup:dts:options",e,i);const l=Oe(i);await e.hooks.callHook("rollup:watch",e,l),We(l,"types",e.logger)}},"watch");var gs=Object.defineProperty,hs=m((e,t)=>gs(e,"name",{value:t,configurable:!0}),"a$4");class ys{static{m(this,"p")}static{hs(this,"FileCache")}#r;#e;#n;#t=!0;#o=new Map;#s;constructor(t,o,r){this.#r=t,this.#e=wo("@visulima/packem",{cwd:t}),this.#n=o,this.#s=r,this.#e===void 0?r.debug("Could not create cache directory."):r.debug(`Cache path is: ${this.#e}`)}set isEnabled(t){this.#t=t}get cachePath(){return this.#e}has(t,o){return!this.#t||this.#e===void 0?!1:O(this.getFilePath(t,o))}get(t,o){if(!this.#t||this.#e===void 0)return;const r=this.getFilePath(t,o);if(this.#o.has(r))return this.#o.get(r);if(!O(r))return;const s=Ve(r);try{const n=JSON.parse(s);return this.#o.set(r,n),n}catch{this.#s.warn(`Could not parse cache file: ${r}, deleting the broken cache file.`),this.#o.delete(r),$o(r,{force:!0});return}}set(t,o,r){if(!this.#t||this.#e===void 0||o===void 0)return;const s=this.getFilePath(t,r);typeof o=="object"&&(o=JSON.stringify(o)),He(s,o,{overwrite:!0})}getFilePath(t,o){let r=t.replaceAll(pe(this.#r),"");return r=r.replaceAll(":","-"),w(this.#e,this.#n,o?.replaceAll(":","-")??"",pe(r))}}var vs=Object.defineProperty,Y=m((e,t)=>vs(e,"name",{value:t,configurable:!0}),"l$3");const bs=T,$s=Y((e,t)=>{const{sideEffects:o}=t;let r;if(typeof o=="boolean")r=Y(()=>o,"hasSideEffects");else if(Array.isArray(o))if(o.length<=0)r=Y(()=>!1,"hasSideEffects");else{const s=o.map(n=>n.includes("/")?n:`**/${n}`);r=bs(s,null,{resolve:e})}else r=Y(()=>null,"hasSideEffects");return r},"getPackageSideEffect");var ws=Object.defineProperty,js=m((e,t)=>ws(e,"name",{value:t,configurable:!0}),"r");const Be=js((e,t)=>{if(e.warnings.size>0&&(t&&e.logger.raw(`
|
|
63
79
|
`),e.logger.warn(`Build is done with some warnings:
|
|
64
80
|
|
|
65
81
|
${[...e.warnings].map(o=>`- ${o}`).join(`
|
|
66
|
-
`)}`),e.options.failOnWarn))throw new Error("Exiting with code (1). You can change this behavior by setting `failOnWarn: false`.")},"
|
|
82
|
+
`)}`),e.options.failOnWarn))throw new Error("Exiting with code (1). You can change this behavior by setting `failOnWarn: false`.")},"logBuildErrors");var ks=Object.defineProperty,Ct=m((e,t)=>ks(e,"name",{value:t,configurable:!0}),"n");const Le=Ct(async(e,t)=>{if(typeof e.name!="string"){let o=Ge(e.input)?N(t.options.rootDir,e.input):me(e.input);o.startsWith("./")&&(o=o.slice(2)),e.name=o.replace(new RegExp(`^${t.options.sourceDir}/`),"").replace(Q,"")}if(!e.input)throw new Error(`Missing entry input: ${je(e)}`);ko(e.input)&&(e.input=$(t.options.rootDir,e.input)),t.options.declaration&&e.declaration===void 0&&(e.declaration=t.options.declaration),e.executable&&(e.cjs===void 0||e.esm===void 0)?t.pkg.type==="commonjs"&&e.cjs===void 0&&t.options.emitCJS!==void 0?(e.cjs=t.options.emitCJS,e.esm=!1):t.pkg.type==="module"&&e.esm===void 0&&t.options.emitESM!==void 0&&(e.esm=t.options.emitESM,e.cjs=!1):(t.options.emitCJS!==void 0&&e.cjs===void 0&&(e.cjs=t.options.emitCJS),t.options.emitESM!==void 0&&e.esm===void 0&&(e.esm=t.options.emitESM)),e.outDir=$(t.options.rootDir,e.outDir??t.options.outDir)},"extendEntry"),xs=Ct(async e=>{e.options.entries=e.options.entries.map(t=>typeof t=="string"?{input:t,isGlob:Ne(t)}:{...t,isGlob:Ne(t.input)});for(const t of e.options.entries.filter(o=>o.isGlob)){const{isGlob:o,...r}=t,s=lo([r.input],{cwd:e.options.rootDir,dot:!1,ignore:["**/node_modules/**"],onlyFiles:!0});if(s.length===0)throw new jo("No files found in the glob pattern: "+j(w(e.options.rootDir,r.input)));for(const n of s)e.options.entries.push({...r,input:$(e.options.rootDir,n)});e.options.entries.splice(e.options.entries.indexOf(t),1)}for await(const t of e.options.entries.filter(o=>o.fileAlias===void 0))await Le(t,e);for await(const t of e.options.entries.filter(o=>o.fileAlias!==void 0))t.name=t.fileAlias,t.fileAlias=void 0,await Le(t,e)},"prepareEntries");var Es=Object.defineProperty,Os=m((e,t)=>Es(e,"name",{value:t,configurable:!0}),"a$2");const Ss=/^[^a-z_@#~]|[^\w/@#~-]|@\/|#\/|~\//i,Ds=new Set(["abstract","await","boolean","break","byte","case","catch","char","class","const","continue","debugger","default","delete","do","double","else","enum","export","extends","false","final","finally","float","for","function","goto","if","implements","import","in","instanceof","int","interface","let","long","native","new","null","package","private","protected","public","return","short","static","super","switch","synchronized","this","throw","throws","transient","true","try","typeof","var","void","volatile","while","with","yield"]),Ue=Os(e=>{if(!Array.isArray(e)&&e!==null)for(const[t,o]of Object.entries(e)){if(typeof t!="string"||t.trim()==="")throw new Error(`Alias name "${t}" is invalid. Alias names should be non-empty strings.`);if(Ss.test(t))throw new Error(`Alias name "${t}" is invalid. Alias names should start with a letter or underscore and only contain letters, numbers, underscores, and dashes.`);if(Ds.has(t))throw new Error(`Alias name "${t}" is a reserved keyword and cannot be used.`);const r=$(o);if(!O(r))throw new Error(`Target path "${r}" for alias "${t}" does not exist.`)}},"validateAliasEntries");var Ns=Object.defineProperty,Ps=m((e,t)=>Ns(e,"name",{value:t,configurable:!0}),"o");const _s=Ps(e=>{const t=new Set,o=new Set(Object.keys(e.pkg?.dependencies??{})),r=new Set;for(const s of e.usedImports)o.delete(s),t.add(s);if(e.pkg?.dependencies)for(const s of Object.keys(e.pkg?.dependencies))o.delete(s);for(const s of t){const n=st(s);!ue(e.options.externals,s)&&!s.startsWith("chunks/")&&e.pkg?.dependencies?.[n]===void 0&&e.pkg?.peerDependencies?.[n]===void 0&&r.add(s)}o.size>0&&L(e,`Potential unused dependencies found: ${[...o].map(s=>j(s)).join(", ")}`),r.size>0&&L(e,`Potential implicit dependencies found: ${[...r].map(s=>j(s)).join(", ")}`)},"validateDependencies");var Cs=Object.defineProperty,Mt=m((e,t)=>Cs(e,"name",{value:t,configurable:!0}),"i");const Ms=Mt((e,t)=>xo(e,t)<=e.length/3||t.includes(e),"isSimilar"),Is=Mt((e,t)=>{const o=e.toLowerCase();return t.filter(r=>Ms(r.toLowerCase(),o))},"findAlternatives");var Rs=Object.defineProperty,ze=m((e,t)=>Rs(e,"name",{value:t,configurable:!0}),"s");const Fs=ze((e,t)=>{const o=new Set([...typeof e.bin=="string"?[e.bin]:Object.values(e.bin??{}),e.main,e.module,t.options.declaration?e.types:"",t.options.declaration?e.typings:"",...ke(e.exports,e.type==="module"?"esm":"cjs",t.options.declaration).map(s=>s.file)].map(s=>s&&$(t.options.rootDir,s.replace(/\/[^*/]*\*[^\n\r/\u2028\u2029]*(?:[\n\r\u2028\u2029][^*/]*\*[^\n\r/\u2028\u2029]*)*(?:\/.*)?$/,"")))),r=[];for(const s of o)s&&!s.includes("*")&&!nt(s)&&r.push(s.replace(`${t.options.rootDir}/`,""));if(r.length>0){const s=ze(l=>N(t.options.rootDir,$(t.options.outDir,l)),"rPath"),n=t.buildEntries.filter(l=>!l.chunk).map(l=>s(l.path));let i="Potential missing or wrong package.json files:";for(const l of r){const a=Is(l,n);i+=`
|
|
83
|
+
- `+j(l)+(a.length>0?Wt` (did you mean ${a.map(c=>`"${c}"`).join(", ")}?)`:"")}L(t,i)}},"validatePackage");var Ts=Object.defineProperty,_=m((e,t)=>Ts(e,"name",{value:t,configurable:!0}),"d");const As=_(e=>{switch(e){case"preserve":case"react-native":return"preserve";case"react":return"transform";case"react-jsx":case"react-jsxdev":return"automatic";default:return}},"resolveTsconfigJsxToJsxRuntime"),Js=_((e,t,o,r,s,n,i,l,a,c)=>{const p=As(c?.config.compilerOptions?.jsx),d=Yt(i,n,l,{alias:{},cjsInterop:!1,clean:!0,debug:s,declaration:void 0,emitCJS:void 0,emitESM:void 0,entries:[],externals:[...Ee.builtinModules,...Ee.builtinModules.map(u=>`node:${u}`)],failOnWarn:!0,fileCache:!0,minify:r===W,name:(a.name??"").split("/").pop()??"default",outDir:c?.config.compilerOptions?.outDir??"dist",replace:{},rollup:{alias:{},cjsInterop:{addDefaultProperty:!1},commonjs:{extensions:[".mjs",".js",".json",".node",".cjs"],ignoreTryCatch:!0,preserveSymlinks:!0,transformMixedEsModules:!1},dts:{compilerOptions:{baseUrl:c?.config.compilerOptions?.baseUrl??".",checkJs:!1,composite:!1,declaration:!0,declarationMap:!1,emitDeclarationOnly:!0,incremental:!1,moduleResolution:100,noEmit:!1,noEmitOnError:!0,preserveSymlinks:!1,skipLibCheck:!0,target:99},respectExternal:!0},dynamicVars:{errorWhenNoFilesFound:!0,include:/\bimport\s*[(/]/},esbuild:{charset:"utf8",include:/\.[jt]sx?$/,jsx:p,jsxDev:c?.config.compilerOptions?.jsx==="react-jsxdev",jsxFactory:c?.config.compilerOptions?.jsxFactory,jsxFragment:c?.config.compilerOptions?.jsxFragmentFactory,jsxImportSource:c?.config.compilerOptions?.jsxImportSource,jsxSideEffects:!0,keepNames:!0,sourcesContent:!1,target:c?.config.compilerOptions?.target,treeShaking:!0,tsconfigRaw:c?.config},isolatedDeclarations:{exclude:H,ignoreErrors:!1,include:[/\.[cm]?ts$/]},json:{preferConst:!0},license:{dependenciesTemplate:_((u,f,h)=>`
|
|
67
84
|
# Licenses of bundled dependencies
|
|
68
85
|
The published ${h} artifact additionally contains code with the following licenses:
|
|
69
86
|
`+(u.length>0?`${u.join(", ")}
|
|
70
87
|
|
|
71
88
|
`:`
|
|
72
89
|
`)+`# Bundled dependencies:
|
|
73
|
-
`+f,"dependenciesTemplate"),dtsTemplate:
|
|
90
|
+
`+f,"dependenciesTemplate"),dtsTemplate:_((u,f,h)=>`
|
|
74
91
|
# Licenses of bundled types
|
|
75
92
|
The published ${h} artifact additionally contains code with the following licenses:
|
|
76
93
|
`+(u.length>0?`${u.join(", ")}
|
|
77
94
|
|
|
78
95
|
`:`
|
|
79
96
|
`)+`# Bundled types:
|
|
80
|
-
`+f,"dtsTemplate")},patchTypes:{},polyfillNode:{},preserveDirectives:{exclude:
|
|
81
|
-
exports: `+R(s.exports.join(", ")):"",s.chunks?.length&&(l+=`
|
|
82
|
-
${s.chunks.map(a=>{const c=t.buildEntries.find(p=>p.path===a)??{};return R(" └─ "+r(a)+D(c.bytes?" ("+M(c?.bytes)+")":""))}).join(`
|
|
83
|
-
`)}`),s.modules&&s.modules.length>0){const a=s.modules.filter(c=>c.id.includes("node_modules")).sort((c,p)=>(p.bytes||0)-(c.bytes||0)).map(c=>R(" 📦 "+r(c.id)+D(c.bytes?" ("+M(c.bytes)+")":""))).join(`
|
|
84
|
-
`);l+=a.length>0?`
|
|
85
|
-
inlined modules:
|
|
86
|
-
`+a:""}if(t.options.declaration&&s.type==="entry"){let a=s.path.replace(/\.js$/,".d.ts"),c="commonjs";s.path.endsWith(".cjs")?a=s.path.replace(/\.cjs$/,".d.cts"):s.path.endsWith(".mjs")&&(c="module",a=s.path.replace(/\.mjs$/,".d.mts"));const p=t.buildEntries.find(d=>d.path.endsWith(a));if(p){let d;a.includes(".d.ts")||(a=a.replace(c==="commonjs"?".d.c":".d.m",".d."),d=t.buildEntries.find(u=>u.path.endsWith(a))),l+=d&&c===o.type?`
|
|
87
|
-
types:
|
|
88
|
-
`+[p,d].map(u=>R(" └─ ")+D(r(u.path))+" (total size: "+j(M(u.bytes??0))+")").join(`
|
|
89
|
-
`):`
|
|
90
|
-
types: `+D(r(p.path))+" (total size: "+j(M(p.bytes??0))+")"}}n=!0,l+=`
|
|
91
|
-
|
|
92
|
-
`,e.raw(s.chunk?R(l):l)}return n&&e.raw("Σ Total dist size (byte size):",j(M(t.buildEntries.reduce((s,i)=>s+(i.bytes??0),0))),`
|
|
93
|
-
`),n},"showSizeInformation"),Ds=x(async(e,t,o,r,n,s,i,l,a)=>{const c=Bo(i.preset??s.preset??"auto",t),p=Os(e,t,o,r,n,s,i,c,l,a);Wt(w(p.rootDir,p.outDir));const d={buildEntries:[],dependencyGraphMap:new Map,environment:r,hooks:Kt(),logger:e,mode:o,options:p,pkg:l,tsconfig:a,usedImports:new Set,warnings:new Set};return c.hooks&&d.hooks.addHooks(c.hooks),s.hooks&&d.hooks.addHooks(s.hooks),i.hooks&&d.hooks.addHooks(i.hooks),await d.hooks.callHook("build:prepare",d),d.options.emitESM===void 0&&d.logger.info("Emitting of ESM bundles, is disabled."),d.options.emitCJS===void 0&&d.logger.info("Emitting of CJS bundles, is disabled."),d},"createContext"),Ns=x(async e=>{const t=[];if(e.options.clean)for(const o of new Set(e.options.entries.map(r=>r.outDir).filter(Boolean).sort()))o===e.options.rootDir||o===e.options.sourceDir||e.options.rootDir.startsWith(o.endsWith("/")?o:`${o}/`)||t.some(r=>o.startsWith(r))||(t.push(o),e.logger.info(`Cleaning dist directory: \`./${N(e.options.rootDir,o)}\``),await He(o))},"cleanDistributionDirectories"),Ps=x((e,t)=>{const o=cs(e.options.entries,"environment","runtime"),r=[];for(const[n,s]of Object.entries(o))for(const[i,l]of Object.entries(s)){const a={...e};(n!=="undefined"||i!=="undefined")&&e.logger.info("Preparing build for "+(n==="undefined"?"":j(n)+" environment"+(i==="undefined"?"":" with "))+(i==="undefined"?"":j(i)+" runtime")),a.options.rollup.replace?(a.options.rollup.replace.values===void 0&&(a.options.rollup.replace.values={}),n!=="undefined"&&(a.options.rollup.replace.values={...a.options.rollup.replace.values,[["process","env","NODE_ENV"].join(".")]:JSON.stringify(n)}),a.options.rollup.replace.values={...a.options.rollup.replace.values,[["process","env","EdgeRuntime"].join(".")]:JSON.stringify(i==="edge-light")}):e.logger.warn("'replace' plugin is disabled. You should enable it to replace 'process.env.*' environments.");let c="";n!=="undefined"&&(c+=n+"/"),i!=="undefined"&&(c+=i+"/");let p=!1;a.options.minify!==void 0&&(p=a.options.minify),n==="development"?p=!1:n==="production"&&(p=!0);const d=[],u=[],f=[],h=[];for(const g of l)g.cjs&&g.esm?d.push(g):g.cjs?f.push(g):g.esm?u.push(g):g.declaration&&h.push(g);if(d.length>0){const g={...a,options:{...a.options,emitCJS:!0,emitESM:!0,entries:d,minify:p}};r.push(ae(g,t,c));const v=g.options.entries.filter(y=>y.declaration);e.options.declaration&&v.length>0&&r.push(K({...g,options:{...g.options,entries:v}},t,c))}if(u.length>0){const g={...a,options:{...a.options,emitCJS:!1,emitESM:!0,entries:u,minify:p}};r.push(ae(g,t,c));const v=g.options.entries.filter(y=>y.declaration);e.options.declaration&&v.length>0&&r.push(K({...g,options:{...g.options,entries:v}},t,c))}if(f.length>0){const g={...a,options:{...a.options,emitCJS:!0,emitESM:!1,entries:f,minify:p}};r.push(ae(g,t,c));const v=g.options.entries.filter(y=>y.declaration);e.options.declaration&&v.length>0&&r.push(K({...g,options:{...g.options,entries:v}},t,c))}if(a.options.declaration&&h.length>0){const g={...a,options:{...a.options,emitCJS:!1,emitESM:!1,entries:h,minify:p}};r.push(K(g,t,c))}}return r},"prepareRollupConfig"),_s=x((e,t)=>{if(e.options.declaration==="compatible"){e.logger.raw(`
|
|
94
|
-
`),e.logger.info(`Compatibility mode enabled. This will generate a typesVersions field ${e.options.writeTypesVersionsToPackageJson?"and write it to package.json":" and display it in the console"}.`);const o=[];for(const r of e.buildEntries.filter(n=>!n.chunk))if(r.type==="entry"&&r.path.endsWith(".cjs")){const n=e.buildEntries.find(s=>s.path.endsWith(r.path.replace(".cjs",".d.ts")));n&&o.push(n.path.replace(e.options.rootDir,"."))}if(e.options.writeTypesVersionsToPackageJson){const r={...t};delete r._id,delete r.readme,Ve(w(e.options.rootDir,"package.json"),{...r,typesVersions:{...r.typesVersions,"*":{"*":o.sort()}}},{detectIndent:!0})}else e.logger.info(`Please add the following field into your package.json to enable node 10 compatibility:
|
|
95
|
-
|
|
96
|
-
${JSON.stringify({typesVersions:{"*":{"*":o.sort()}}},null,4)}`)}},"generateNode10Compatibility"),Cs=x(async(e,t,o)=>{await e.hooks.callHook("build:before",e),e.options.minify&&e.logger.info("Minification is enabled, the output will be minified");const r=t.dependencies?.typescript!==void 0||t.devDependencies?.typescript!==void 0;if(e.options.declaration&&e.tsconfig===void 0&&r)throw new Error("Cannot build declaration files without a tsconfig.json");r?e.options.declaration===!1&&e.logger.info({message:"Generation of declaration files are disabled.",prefix:"dts"}):(e.options.declaration=!1,e.logger.info({message:"Typescript is not installed. Generation of declaration files are disabled.",prefix:"dts"})),e.options.declaration&&e.logger.info("Using typescript version: "+j(t.devDependencies?.typescript??t.dependencies?.typescript??"unknown")),e.options.declaration&&(t.dependencies?.typescript||t.devDependencies?.typescript)&&!e.tsconfig?.config.compilerOptions?.isolatedModules&&e.logger.warn(`'compilerOptions.isolatedModules' is not enabled in tsconfig.
|
|
97
|
-
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.
|
|
98
|
-
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 Promise.all(Ps(e,o)),e.logger.success(At(e.options.name?"Build succeeded for "+e.options.name:"Build succeeded"));for await(const s of Lt(w(e.options.rootDir,e.options.outDir))){let i=e.buildEntries.find(l=>w(e.options.rootDir,e.options.outDir,l.path)===s.path);if(i||(i={chunk:!0,path:s.path},e.buildEntries.push(i)),!i.bytes){const l=await Be(b(e.options.rootDir,e.options.outDir,s.path));i.bytes=l.size}}const n=Ss(e.logger,e,t);await e.hooks.callHook("build:done",e),_s(e,t),vs(e),ks(t,e),await e.hooks.callHook("validate:done",e),Pt(e,n)},"build"),wi=x(async(e,t,o,r,n={})=>{const{configPath:s,debug:i,tsconfigPath:l,...a}=n;r.wrapAll(),e=b(Rt(),e),r.debug("Root directory:",e);const c=w(e,"package.json");if(!S(c))throw new Error("package.json not found at "+c);const p=zt(c);r.debug("Using package.json found at",c);let d;if(l){const u=w(e,l);if(!await Bt(u))throw new Error("tsconfig.json not found at "+u);d={config:Vt(u),path:u},r.info("Using tsconfig settings at",u)}else if(p.dependencies?.typescript||p.devDependencies?.typescript)try{d=await Ht(e),r.debug("Using tsconfig settings found at",d.path)}catch{r.info("No tsconfig.json or jsconfig.json found.")}try{let u=s??"";if(!u){const E=["packem.config.js","packem.config.mjs","packem.config.cjs","packem.config.ts","packem.config.cts","packem.config.mts"];for(const P of E)if(S(w(e,P))){u="./"+P;break}}if(!/\.(?:js|mjs|cjs|ts|cts|mts)$/.test(u))throw new Error("Invalid packem config file extension. Only .js, .mjs, .cjs, .ts, .cts and .mts extensions are allowed.");let f=ot(u,e);typeof f=="function"&&(f=f(o,t)),r.debug("Using packem config found at",w(e,u));const h=Date.now(),g=x(()=>Ut(Math.floor(Date.now()-h)),"getDuration"),v=I(JSON.stringify({version:p.version,...p.dependencies,...p.devDependencies,...p.peerDependencies,...p.peerDependenciesMeta,browser:p.browser,eNode:p.engines?.node,exports:p.exports,main:p.main,module:p.module,type:p.type,types:p.types})),y=new rs(e,v,r);y.cachePath&&!S(w(y.cachePath,v))&&S(y.cachePath)&&(r.info("Clearing file cache because the cache key has changed."),await He(y.cachePath));const $=await Ds(r,e,t,o,i??!1,a,f,p,d);if(y.isEnabled=$.options.fileCache,await us($),$.logger.info(j((t==="watch"?"Watching":t==="jit"?"Stubbing":"Building")+" "+$.options.name)),$.logger.debug(`${D("Root dir:")} ${$.options.rootDir}
|
|
97
|
+
`+f,"dtsTemplate")},patchTypes:{},polyfillNode:{},preserveDirectives:{exclude:H,include:[/\.(?:m|c)?(?:j|t)sx?$/]},preserveDynamicImports:!0,raw:{exclude:H,include:[/\.(md|txt|css|htm|html|data)$/]},replace:{objectGuards:!0,preventAssignment:!0},resolve:{allowExportsFolderMapping:!1,extensions:ye,preferBuiltins:!1},shim:{exclude:[/node_modules/],include:[/\.(js|cjs|mjs|tsx|mts|cts)$/]},sucrase:{disableESTransforms:!0,enableLegacyBabel5ModuleInterop:!1,enableLegacyTypeScriptModuleInterop:c?.config.compilerOptions?.esModuleInterop===!1,include:/\.[jt]sx?$/,injectCreateRequireForImportRequire:!1,preserveDynamicImport:!0,production:r===W,...c?.config.compilerOptions?.jsx&&["react","react-jsx","react-jsxdev"].includes(c.config.compilerOptions.jsx)?{jsxFragmentPragma:c.config.compilerOptions.jsxFragmentFactory,jsxImportSource:c.config.compilerOptions.jsxImportSource,jsxPragma:c.config.compilerOptions.jsxFactory,jsxRuntime:p,transforms:["typescript","jsx",...c.config.compilerOptions.esModuleInterop?["imports"]:[]]}:{transforms:["typescript",...c?.config.compilerOptions?.esModuleInterop?["imports"]:[]]}},swc:{include:/\.[jt]sx?$/,inlineSourcesContent:!1,inputSourceMap:!1,isModule:!0,jsc:{experimental:{keepImportAttributes:!0},externalHelpers:!1,keepClassNames:!0,loose:!0,parser:{decorators:c?.config.compilerOptions?.experimentalDecorators,syntax:c?"typescript":"ecmascript",[c?"tsx":"jsx"]:!0},target:c?.config.compilerOptions?.target?.toLowerCase(),transform:{decoratorMetadata:c?.config.compilerOptions?.emitDecoratorMetadata,legacyDecorator:c?.config.compilerOptions?.experimentalDecorators,react:{development:r!==W,pragma:c?.config.compilerOptions?.jsxFactory,pragmaFrag:c?.config.compilerOptions?.jsxFragmentFactory,runtime:p,throwIfNamespace:!0},treatConstEnumAsEnum:c?.config.compilerOptions?.preserveConstEnums,useDefineForClassFields:c?.config.compilerOptions?.useDefineForClassFields}},module:{ignoreDynamic:!0,importInterop:"none",preserveImportMeta:!0,strict:!1,strictMode:!1,type:"es6"},transform:{decoratorVersion:"2022-03"}},treeshake:{moduleSideEffects:$s(t,a),preset:"recommended",propertyReadSideEffects:!0},watch:{chokidar:{ignoreInitial:!0,ignorePermissionErrors:!0},clearScreen:!0,exclude:H}},rootDir:t,sourceDir:"src",sourcemap:!1,stub:o==="jit",stubOptions:{jiti:{alias:{},esmResolve:!0,interopDefault:!0}},transformerName:void 0});if(!d.transformerName){const u=new Map([...Object.entries(a.dependencies??{}),...Object.entries(a.devDependencies??{})]);let f="0.0.0";if(u.has("esbuild"))d.transformerName="esbuild",f=u.get("esbuild");else if(u.has("@swc/core"))d.transformerName="swc",f=u.get("@swc/core");else if(u.has("sucrase"))d.transformerName="sucrase",f=u.get("sucrase");else throw new Error("Unknown transformer, check your transformer options or install one of the supported transformers: esbuild, swc, sucrase");e.info("Using "+j("rollup ")+Qt),e.info({message:"Using "+j(d.transformerName)+" "+f,prefix:"transformer"})}return d.rollup.resolve&&d.rollup.resolve.preferBuiltins===!0&&(d.rollup.polyfillNode=!1,e.debug("Disabling polyfillNode because preferBuiltins is set to true")),a.dependencies&&d.externals.push(...Object.keys(a.dependencies)),a.peerDependencies&&d.externals.push(...Object.keys(a.peerDependencies)),a.optionalDependencies&&d.externals.push(...Object.keys(a.optionalDependencies)),Ue(d.alias),d.rollup.alias&&d.rollup.alias.entries&&Ue(d.rollup.alias.entries),d},"generateOptions"),Ws=_(async(e,t,o,r,s,n,i,l,a)=>{const c=rs(i.preset??n.preset??"auto",t),p=Js(e,t,o,r,s,n,i,c,l,a);zt(w(p.rootDir,p.outDir));const d={buildEntries:[],dependencyGraphMap:new Map,environment:r,hooks:Xt(),logger:e,mode:o,options:p,pkg:l,tsconfig:a,usedImports:new Set,warnings:new Set};return c.hooks&&d.hooks.addHooks(c.hooks),n.hooks&&d.hooks.addHooks(n.hooks),i.hooks&&d.hooks.addHooks(i.hooks),await d.hooks.callHook("build:prepare",d),d.options.emitESM===void 0&&d.logger.info("Emitting of ESM bundles, is disabled."),d.options.emitCJS===void 0&&d.logger.info("Emitting of CJS bundles, is disabled."),d},"createContext"),Bs=_(async e=>{const t=[];if(e.options.clean)for(const o of new Set(e.options.entries.map(r=>r.outDir).filter(Boolean).sort()))o===e.options.rootDir||o===e.options.sourceDir||e.options.rootDir.startsWith(o.endsWith("/")?o:`${o}/`)||t.some(r=>o.startsWith(r))||(t.push(o),e.logger.info(`Cleaning dist directory: \`./${N(e.options.rootDir,o)}\``),await Ke(o))},"cleanDistributionDirectories"),Pi=_(async(e,t,o,r,s={})=>{const{configPath:n,debug:i,tsconfigPath:l,...a}=s;r.wrapAll(),e=$(Tt(),e),r.debug("Root directory:",e);const c=w(e,"package.json");if(!O(c))throw new Error("package.json not found at "+c);const p=qt(c);r.debug("Using package.json found at",c);let d;if(l){const u=w(e,l);if(!await Vt(u))throw new Error("tsconfig.json not found at "+u);d={config:Kt(u),path:u},r.info("Using tsconfig settings at",u)}else if(p.dependencies?.typescript||p.devDependencies?.typescript)try{d=await Gt(e),r.debug("Using tsconfig settings found at",d.path)}catch{r.info("No tsconfig.json or jsconfig.json found.")}try{let u=n??"";if(!u){const S=["packem.config.js","packem.config.mjs","packem.config.cjs","packem.config.ts","packem.config.cts","packem.config.mts"];for(const A of S)if(O(w(e,A))){u="./"+A;break}}if(!/\.(?:js|mjs|cjs|ts|cts|mts)$/.test(u))throw new Error("Invalid packem config file extension. Only .js, .mjs, .cjs, .ts, .cts and .mts extensions are allowed.");let f=St(u,e);typeof f=="function"&&(f=f(o,t)),r.debug("Using packem config found at",w(e,u));const h=Date.now(),g=_(()=>Ht(Math.floor(Date.now()-h)),"getDuration"),b=I(JSON.stringify({version:p.version,...p.dependencies,...p.devDependencies,...p.peerDependencies,...p.peerDependenciesMeta,browser:p.browser,eNode:p.engines?.node,exports:p.exports,main:p.main,module:p.module,type:p.type,types:p.types})),v=new ys(e,b,r);v.cachePath&&!O(w(v.cachePath,b))&&O(v.cachePath)&&(r.info("Clearing file cache because the cache key has changed."),await Ke(v.cachePath));const y=await Ws(r,e,t,o,i??!1,a,f,p,d);if(v.isEnabled=y.options.fileCache,await xs(y),y.logger.info(j((t==="watch"?"Watching":t==="jit"?"Stubbing":"Building")+" "+y.options.name)),y.logger.debug(`${D("Root dir:")} ${y.options.rootDir}
|
|
99
98
|
${D("Entries:")}
|
|
100
|
-
${
|
|
101
|
-
`)}`),await
|
|
99
|
+
${y.options.entries.map(S=>` ${je(S)}`).join(`
|
|
100
|
+
`)}`),await Bs(y),y.options.stub){await cs(y),await y.hooks.callHook("build:done",y);return}if(t==="watch"){if(y.options.rollup.watch===!1)throw new Error("Rollup watch is disabled. You should check your packem.config file.");await fs(y,v),Be(y,!1);return}const x=await Rn(y,p,v);await y.hooks.callHook("validate:before",y),_s(y),Fs(p,y),await y.hooks.callHook("validate:done",y),Be(y,x),r.raw(`
|
|
102
101
|
⚡️ Build run in `+g()),r.restoreAll()}catch(u){throw r.raw(`
|
|
103
|
-
`),
|
|
102
|
+
`),Pt(u),u}},"createBundler");export{Pi as default};
|