@visulima/packem 1.0.0-alpha.97 → 1.0.0-alpha.98
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 +6 -0
- package/dist/cli.mjs +32 -32
- package/dist/create-bundler.cjs +30 -30
- package/dist/create-bundler.mjs +33 -33
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,9 @@
|
|
|
1
|
+
## @visulima/packem [1.0.0-alpha.98](https://github.com/visulima/packem/compare/@visulima/packem@1.0.0-alpha.97...@visulima/packem@1.0.0-alpha.98) (2024-09-07)
|
|
2
|
+
|
|
3
|
+
### Bug Fixes
|
|
4
|
+
|
|
5
|
+
* improved dx for node10 ([9868420](https://github.com/visulima/packem/commit/986842005338b6b4ba840bcc86882ba5a0232aeb))
|
|
6
|
+
|
|
1
7
|
## @visulima/packem [1.0.0-alpha.97](https://github.com/visulima/packem/compare/@visulima/packem@1.0.0-alpha.96...@visulima/packem@1.0.0-alpha.97) (2024-09-07)
|
|
2
8
|
|
|
3
9
|
### Bug Fixes
|
package/dist/cli.mjs
CHANGED
|
@@ -1,26 +1,26 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
var
|
|
2
|
+
var Ut=Object.defineProperty;var m=(e,t)=>Ut(e,"name",{value:t,configurable:!0});import Ht from"@visulima/cerebro";import{SimpleReporter as qt}from"@visulima/pail/reporter";import{env as Z,versions as Gt,cwd as Kt,exit as Yt}from"node:process";import{DEFAULTS as Xt,nodeResolve as tt}from"@rollup/plugin-node-resolve";import _e from"node:module";import{cyan as j,bold as S,gray as T,green as Qt,yellow as Zt,grey as eo}from"@visulima/colorize";import{readFile as se,readFileSync as ot,writeFileSync as ee,writeJsonSync as rt,readJsonSync as to,walk as oo,isAccessibleSync as x,collectSync as ro,writeFile as H,ensureDirSync as no,emptyDir as nt,isAccessible as io}from"@visulima/fs";import{formatBytes as M,duration as so}from"@visulima/humanizer";import{parsePackageJson as it}from"@visulima/package/package-json";import{normalize as ve,join as $,relative as N,dirname as be,basename as $e,toNamespacedPath as ge,resolve as w,extname as we,isAbsolute as st}from"@visulima/path";import{readTsConfig as ao,findTsConfig as lo}from"@visulima/tsconfig";import{defu as co}from"defu";import{createHooks as po}from"hookable";import{rollup as at,watch as Ce,VERSION as uo}from"rollup";import{stat as lt,chmod as mo}from"node:fs/promises";import ct from"@rollup/plugin-alias";import fo from"@rollup/plugin-commonjs";import go from"@rollup/plugin-dynamic-import-vars";import pt from"@rollup/plugin-replace";import{wasm as ho}from"@rollup/plugin-wasm";import yo from"rollup-plugin-polyfill-node";import{visualizer as vo}from"rollup-plugin-visualizer";import{minVersion as ut}from"semver";import te from"node:assert/strict";import{extractAssignedNames as bo,createFilter as A,normalizePath as Ie}from"@rollup/pluginutils";import I from"magic-string";import $o from"glob-parent";import{glob as wo,globSync as jo}from"tinyglobby";import{findStaticImports as dt,resolvePath as ko,resolveModuleExportNames as xo}from"mlly";import{parseAsync as Eo}from"oxc-parser";import Do from"@rollup/plugin-json";import Oo from"rollup-plugin-license";import{createHash as So}from"node:crypto";import{fileURLToPath as No,pathToFileURL as Po}from"node:url";import{parse as _o}from"@babel/parser";import mt from"jiti";import{existsSync as ft,rmSync as Co}from"node:fs";import{findCacheDirSync as Io}from"@visulima/find-cache-dir";import{NotFoundError as Mo}from"@visulima/fs/error";import{isRelative as Ro}from"@visulima/path/utils";import Me from"is-glob";import{distance as To}from"fastest-levenshtein";import{installPackage as Re}from"@antfu/install-pkg";import{intro as Fo,isCancel as Ao,cancel as Te,select as Fe,confirm as Ae,spinner as q,outro as Jo}from"@clack/prompts";import __cjs_url__ from "node:url"; // -- packem CommonJS __filename shim --
|
|
3
3
|
import __cjs_path__ from "node:path"; // -- packem CommonJS __dirname shim --
|
|
4
4
|
import __cjs_mod__ from "node:module"; // -- packem CommonJS require shim --
|
|
5
5
|
const __filename = __cjs_url__.fileURLToPath(import.meta.url);
|
|
6
6
|
const __dirname = __cjs_path__.dirname(__filename);
|
|
7
7
|
const require = __cjs_mod__.createRequire(import.meta.url);
|
|
8
|
-
const
|
|
8
|
+
const Bo="@visulima/packem",Wo="1.0.0-alpha.97",je=[...Xt.extensions,".cjs",".ts",".cts",".mts",".tsx",".jsx"],P="production",L="development",gt=new Set(["react-server","react-native","edge-light"]),oe=new Set([L,P,...gt]),G=/node_modules/,re=/(?:\.d\.[mc]?ts|\.\w+)$/;var Lo=Object.defineProperty,zo=m((e,t)=>Lo(e,"name",{value:t,configurable:!0}),"a$f");const he=zo((e,t)=>e.some(o=>o instanceof RegExp?o.test(t):o===t),"arrayIncludes");var Vo=Object.defineProperty,Uo=m((e,t)=>Vo(e,"name",{value:t,configurable:!0}),"a$e");const W=Uo(e=>e==null?[]:Array.isArray(e)?e:[e],"arrayify");var Ho=Object.defineProperty,qo=m((e,t)=>Ho(e,"name",{value:t,configurable:!0}),"a$d");const ht=qo((e="")=>{const t=e.split("/");return t[0].startsWith("@")?t[0]+"/"+t[1]:t[0]},"getPackageName");var Go=Object.defineProperty,yt=m((e,t)=>Go(e,"name",{value:t,configurable:!0}),"s$h");const Ko=yt((e,t,o)=>{const r=o??new Map;return(...i)=>{const n=t?typeof t=="function"?t(...i):t:JSON.stringify({args:i}),s=r.get(n);if(s!==void 0)return s;const l=e(...i);return r.set(n,l),l}},"memoize"),Yo=yt(e=>{const t=new Map;return o=>Ko(e,o,t)},"memoizeByKey");var Xo=Object.defineProperty,V=m((e,t)=>Xo(e,"name",{value:t,configurable:!0}),"r$c");const Qo=V(function*(e){switch(e.declaration?.type){case"ClassDeclaration":case"FunctionDeclaration":{const{id:t}=e.declaration;te(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 bo(t.id))yield o;break}}},"exportName"),Zo=V(function*(e){if(e.declaration)for(const t of Qo(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"),er=V(function*(e){e.exported?yield{exportedName:e.exported.name,from:"self",type:"named"}:yield{from:"other",source:e.source.value,type:"barrel"}},"parseExportAll"),tr=V(function*(){yield{exportedName:"default",from:"self",type:"named"}},"parseExportDefault"),or=V(function*(e,t){te(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*er(r);break}case"ExportDefaultDeclaration":{yield*tr();break}case"ExportNamedDeclaration":{yield*Zo(r);break}}},"parseExports");var rr=Object.defineProperty,U=m((e,t)=>rr(e,"name",{value:t,configurable:!0}),"n$a");const vt=U(async function(e,t,o){const r=await e.resolve(t,o.id);if(te(r,`Rollup can't resolve ${t} from ${o.id}`),r.external)return null;const i=await e.load(r);return te(i,`Rollup doesn't have a module for id ${r.id}`),i},"getImportedModule"),nr=U(async function*(e,t,o){const r=await vt(e,t.source,o);r&&(yield*ke(e,r))},"gatherBarrelReExports"),ir=U(async function*(e,t,o){const r=await vt(e,t.source,o);if(!r)return;const i=new Map(t.bindings.map(n=>[n.importedName,n]));for await(const n of ke(e,r)){const s=i.get(n.exportedName);s&&(yield{...n,exportedName:s.exportedName})}},"gatherNamedReExports"),sr=U(async function*(e,t){yield{exportedName:t.exportedName,id:e.id,sourceName:t.exportedName}},"gatherNamedSelfExports"),ke=U(async function*(e,t){for(const o of or(e,t))o.from==="self"?yield*sr(t,o):o.type==="barrel"?yield*nr(e,o,t):yield*ir(e,o,t)},"gatherExports");var ar=Object.defineProperty,lr=m((e,t)=>ar(e,"name",{value:t,configurable:!0}),"r$b");const cr=lr(()=>({moduleParsed:{async handler(e){if(e.isEntry)for await(const t of ke(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 pr=Object.defineProperty,Je=m((e,t)=>pr(e,"name",{value:t,configurable:!0}),"u$c");const bt=Je(({addDefaultProperty:e=!1,logger:t,type:o})=>({name:"packem:cjs-interop",renderChunk:Je(async(r,i,n)=>{if(i.type!=="chunk"||!i.isEntry)return null;if(n.format==="cjs"&&n.exports==="auto"){const s=/(exports(?:\['default'\]|\.default)) = (.*);/i.exec(r);if(s===null||s.length<3)return null;const l=new I(r);l.replace("Object.defineProperty(exports, '__esModule', { value: true });",""),l.replaceAll(/exports\.(.*) = (.*);/g,"module.exports.$1 = $2;"),e&&l.append(`
|
|
9
9
|
module.exports.default = `+s[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 "+i.fileName+".",prefix:"plugin:cjs-interop"}),{code:a,map:l.generateMap({hires:!0})}}if(n.format==="es"&&/\.d\.(?:ts|cts)$/.test(i.fileName)){if(o!=="commonjs"&&i.fileName.endsWith(".d.mts"))return null;const s=[];let l;const a=/export\s\{\s(.*)\s\}/g;for(;(l=a.exec(r))!==null;)l.index===a.lastIndex&&a.lastIndex++,l.forEach(d=>{s.push(d)});if(s.length===0)return null;const c=s.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 I(r);return d.replace(new RegExp(`(,s)?${p} as default(,)?`),""),d.append(`
|
|
10
10
|
|
|
11
|
-
export = `+p+";"),t.debug({message:"Applied CommonJS interop to entry chunk "+i.fileName+".",prefix:"plugin:cjs-interop"}),{code:d.toString().replace(/export\s\{\s\s\};/,""),map:d.generateMap({hires:!0})}}}return null},"renderChunk")}),"cjsInteropPlugin");var
|
|
11
|
+
export = `+p+";"),t.debug({message:"Applied CommonJS interop to entry chunk "+i.fileName+".",prefix:"plugin:cjs-interop"}),{code:d.toString().replace(/export\s\{\s\s\};/,""),map:d.generateMap({hires:!0})}}}return null},"renderChunk")}),"cjsInteropPlugin");var ur=Object.defineProperty,dr=m((e,t)=>ur(e,"name",{value:t,configurable:!0}),"u$b");const mr=dr((e,t)=>{const o=new Map,r={copyOnce:!0,exactFileNames:!0,flatten:!1,...e};let{targets:i}=r;return Array.isArray(i)?i=i.map(n=>{if(typeof n=="string")return{src:n};if(typeof n=="object"&&"src"in n)return n}).filter(Boolean):typeof i=="string"&&(i=[{src:i}]),{async buildStart(){const n=await Promise.all(i.flatMap(s=>Array.isArray(s.src)?s.src.map(l=>({...s,src:l})):s).map(async s=>await wo(W(s.src),{ignore:W(s.exclude).filter(Boolean)}).then(l=>({dest:s.dest??"",parent:$o(s.src),src:l}))));for(const s of n)for(const l of s.src){let a;o.has(l)?a=o.get(l):(a={copied:[],dest:[],timestamp:0},o.set(l,a));const c=r.flatten?ve(s.dest):$(s.dest,N(s.parent,be(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([s,l])=>{let a;try{const c=await lt(s);if(!c.isFile())return;const p=c.mtime.getTime();p>l.timestamp&&(l.timestamp=p,l.copied=[]),a=await se(s,{buffer:!0})}catch(c){t.error({context:[c],message:`error reading file ${s}`,prefix:"plugin:copy"});return}for(const c of l.dest){if(r.copyOnce&&l.copied.includes(c))continue;const p=$e(s),d=$(c,p);try{this.emitFile({[r.exactFileNames?"fileName":"name"]:d,source:a,type:"asset"}),t.debug({message:`copied ${s} → ${d}`,prefix:"plugin:copy"}),l.copied.push(c)}catch(u){t.error({context:[u],message:`error copying file ${s} → ${d}`,prefix:"plugin:copy"})}}}))},name:"packem:copy"}},"copyPlugin");var fr=Object.defineProperty,ae=m((e,t)=>fr(e,"name",{value:t,configurable:!0}),"t$6");const gr=/\Wrequire(?:\.resolve)?\(/,hr=ae((e,t)=>{if(Z.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,i=!1;if(e.includes("__filename")&&(o=!0),e.includes("__dirname")&&(r=!0),gr.test(e)&&(i=!0),!o&&!r&&!i)return null;const n=dt(e).pop(),s=n?n.end:0,l=new I(e);return l.appendRight(s,t(o,r,i)),{code:l.toString(),map:l.generateMap()}},"CJSToESM"),yr=ae((e,t,o)=>{let r="";return(e||t)&&(r+=`import __cjs_url__ from "node:url"; // -- packem CommonJS __filename shim --
|
|
12
12
|
`),t&&(r+=`import __cjs_path__ from "node:path"; // -- packem CommonJS __dirname shim --
|
|
13
13
|
`),o&&(r+=`import __cjs_mod__ from "node:module"; // -- packem CommonJS require shim --
|
|
14
14
|
`),(e||t)&&(r+=`const __filename = __cjs_url__.fileURLToPath(import.meta.url);
|
|
15
15
|
`),t&&(r+=`const __dirname = __cjs_path__.dirname(__filename);
|
|
16
16
|
`),o&&(r+=`const require = __cjs_mod__.createRequire(import.meta.url);
|
|
17
|
-
`),r},"generateCJSShim"),
|
|
17
|
+
`),r},"generateCJSShim"),vr=ae((e,t,o)=>{let r="";return o&&(r+=`import __cjs_mod__ from "node:module"; // -- packem CommonJS require shim --
|
|
18
18
|
`),e&&(r+=`const __filename = import.meta.filename; // -- packem CommonJS __filename shim --
|
|
19
19
|
`),t&&(r+=`const __dirname = import.meta.dirname; // -- packem CommonJS __dirname shim --
|
|
20
20
|
`),o&&(r+=`const require = __cjs_mod__.createRequire(import.meta.url);
|
|
21
|
-
`),r},"generateCJSShimNode20_11"),
|
|
21
|
+
`),r},"generateCJSShimNode20_11"),br=ae((e,t)=>{const o=A(t.include,t.exclude);return{name:"packem:esm-shim-cjs-syntax",renderChunk(r,i,n){if(n.format==="es"&&o(i.fileName)){let s=yr;if(e.engines?.node){const l=ut(e.engines.node);l&&l.major>=20&&l.minor>=11&&(s=vr)}return hr(r,s)}return null}}},"esmShimCjsSyntaxPlugin");var $r=Object.defineProperty,wr=m((e,t)=>$r(e,"name",{value:t,configurable:!0}),"n$8");const jr=wr(()=>({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 kr=Object.defineProperty,xr=m((e,t)=>kr(e,"name",{value:t,configurable:!0}),"s$f");const Er=xr((...e)=>{if(e.length===0)return"";if(e.length===1)return be(e[0]);e=e.map(i=>ge(i));const[t,...o]=e;let r=t.split("/");for(const i of o){const n=i.split("/",r.length);let s=0;for(const l of n)if(l===r[s])s+=1;else{r=r.slice(0,s);break}r=r.slice(0,s)}return r.length<=1&&r[0]===""?`/${r[0]}`:r.join("/")},"lowestCommonAncestor");var Dr=Object.defineProperty,pe=m((e,t)=>Dr(e,"name",{value:t,configurable:!0}),"m$6");const Or=pe((e,t,o,r={})=>{const i=A(r.include,r.exclude),n={},s=pe((c,p)=>{n[c.replace(/\..?[jt]s$/,"")]=p},"addOutput");async function l(c,p){if(!i(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])}s(p,u);let f;try{const g=await Eo(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(i(v)&&!n[v.replace(re,"")])try{const y=await se(v);await l.call(this,y,v)}catch{}}}m(l,"g"),pe(l,"transform");const a=o==="module"?"es":"cjs";return{name:"packem:isolated-declarations",renderStart(c,{input:p}){const d=Er(...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(re,"")}${c.format==="cjs"?".cts":".mts"}${g}`),type:"asset"})}},transform:l}},"isolatedDeclarationsPlugin");var Sr=Object.defineProperty,Nr=m((e,t)=>Sr(e,"name",{value:t,configurable:!0}),"n$7");const Be="export default ",$t=Nr(e=>{const t=Do(e);return{...t,name:"packem:json",transform(o,r){const i=t.transform?.call(this,o,r);return i&&typeof i!="string"&&"code"in i&&i.code?.startsWith(Be)&&(i.code=i.code.replace(Be,"module.exports = ")),i}}},"JSONPlugin");class Pr{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,i){t&&o&&(r!=null?t[o][r]=i:t[o]=i)}remove(t,o,r){t&&o&&(r!=null?t[o].splice(r,1):delete t[o])}}class _r extends Pr{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,i){if(t){if(this.enter){const s=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,i),this.replacement&&(t=this.replacement,this.replace(o,r,i,t)),this.should_remove&&this.remove(o,r,i);const c=this.should_skip,p=this.should_remove;if(this.should_skip=s,this.should_remove=l,this.replacement=a,c)return t;if(p)return null}let n;for(n in t){const s=t[n];if(s&&typeof s=="object")if(Array.isArray(s)){const l=s;for(let a=0;a<l.length;a+=1){const c=l[a];We(c)&&(this.visit(c,t,n,a)||a--)}}else We(s)&&this.visit(s,t,n,null)}if(this.leave){const s=this.replacement,l=this.should_remove;this.replacement=null,this.should_remove=!1,this.leave.call(this.context,t,o,r,i),this.replacement&&(t=this.replacement,this.replace(o,r,i,t)),this.should_remove&&this.remove(o,r,i);const a=this.should_remove;if(this.replacement=s,this.should_remove=l,a)return null}}return t}}function We(e){return e!==null&&typeof e=="object"&&"type"in e&&typeof e.type=="string"}m(We,"isNode");function wt(e,{enter:t,leave:o}){return new _r(t,o).visit(e,null)}m(wt,"walk");var Cr=Object.defineProperty,Ir=m((e,t)=>Cr(e,"name",{value:t,configurable:!0}),"u$a");const Mr=Ir(({attributes:e,logger:t})=>{const o=A([/\.[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,i){if(!o(i))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 "${i}" and remove the jsx attribute.`}),t.warn(a),null}let s=!1;const l=new I(r);return wt(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,""),s=!0)}}}),s?{code:l.toString(),map:l.generateMap({hires:!0})}:null}}},"jsxRemoveAttributes");var Rr=Object.defineProperty,xe=m((e,t)=>Rr(e,"name",{value:t,configurable:!0}),"g$4");const Tr=xe(e=>{const t=[],o=[];return e.forEach(r=>{r.startsWith("(")?t.push(r):o.push(r)}),[...o.sort(),...t.sort()]},"sortLicenses"),Fr=xe((e,t,o)=>{const r=new RegExp(`(<!-- ${t} -->)[\\s\\S]*?(<!-- ${t} -->)`,"g");if(r.test(e))return e.replace(r,`$1
|
|
22
22
|
${o}
|
|
23
|
-
$2`)},"replaceContentWithin"),
|
|
23
|
+
$2`)},"replaceContentWithin"),jt=xe(({dtsMarker:e,licenseFilePath:t,licenseTemplate:o,logger:r,marker:i,mode:n,packageName:s})=>Oo({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+`
|
|
24
24
|
`;f&&(y+=`License: ${f}
|
|
25
25
|
`);const E=new Set;for(const O of[d,...g,...u]){const J=typeof O=="string"?O:O?.name;J&&E.add(J)}return E.size>0&&(y+=`By: ${[...E].join(", ")}
|
|
26
26
|
`),v&&(y+=`Repository: ${typeof v=="string"?v:v.url}
|
|
@@ -32,24 +32,24 @@ $2`)},"replaceContentWithin"),wt=xe(({dtsMarker:e,licenseFilePath:t,licenseTempl
|
|
|
32
32
|
`),f&&a.add(f),y}).join(`
|
|
33
33
|
---------------------------------------
|
|
34
34
|
|
|
35
|
-
`);if(c===""){r.info({message:"No dependencies license information found.",prefix:"plugin:license:"+n});return}const p=o(
|
|
35
|
+
`);if(c===""){r.info({message:"No dependencies license information found.",prefix:"plugin:license:"+n});return}const p=o(Tr(a),c,s);try{const d=ot(t),u=Fr(d,i,p);if(!u){r.error({message:`Could not find the license marker: <!-- ${i} --> in ${t}`,prefix:"plugin:license:"+n});return}d!==u&&(ee(t,u),r.info({message:`${t} updated.`,prefix:"plugin:license:"+n}))}catch(d){r.error(d)}}}),"license");var Ar=Object.defineProperty,Jr=m((e,t)=>Ar(e,"name",{value:t,configurable:!0}),"i$a");const Br=Jr(e=>({async buildEnd(){const t=[];for(const r of this.getModuleIds()){const i=this.getModuleInfo(r);if(i!=null&&!i.isExternal)for(const n of i.importedIds)t.push({source:r,target:n})}if(Array.isArray(t)&&t.length===0)return;const o=w(e.rootDir,e.outDir,"graph.json");rt(o,t)},name:"packem:metafile"}),"metafilePlugin");var Wr=Object.defineProperty,kt=m((e,t)=>Wr(e,"name",{value:t,configurable:!0}),"r$9");let Le=!1;const Lr=kt(e=>{Le||(e.logger.info({message:"Declaration compatibility mode is enabled.",prefix:"dts"}),Le=!0);const t=[];for(const n of e.buildEntries.filter(s=>!s.chunk))n.type==="entry"&&n.path.endsWith(".cjs")&&t.push("./"+$(e.options.outDir,n.path.replace(/\.cjs$/,".d.ts")));const o=$(e.options.rootDir,"package.json"),r=to(o),i=t.sort((n,s)=>n.localeCompare(s));if(i===r.typesVersions?.["*"]?.["*"]){e.logger.debug({message:"No changes to typesVersions field in package.json",prefix:"dts"});return}e.options.writeTypesVersionsToPackageJson&&t.length>0?(rt(o,{...r,typesVersions:{...r.typesVersions,"*":{"*":i}}},{detectIndent:!0}),e.logger.info({message:"Your package.json has been updated to enable node 10 compatibility.",prefix:"dts"})):t.length>0&&e.logger.info(`Please add the following field into your package.json to enable node 10 compatibility:
|
|
36
36
|
|
|
37
|
-
${JSON.stringify({typesVersions:{"*":{"*":
|
|
38
|
-
`+e}return null},order:"post"}}),"prependDirectivePlugin");var
|
|
37
|
+
${JSON.stringify({typesVersions:{"*":{"*":i}}},null,4)}`)},"generateNode10Compatibility"),zr=kt(e=>({name:"packem:node10-compatibility",writeBundle(){Lr(e)}}),"node10Compatibility");var Vr=Object.defineProperty,Ur=m((e,t)=>Vr(e,"name",{value:t,configurable:!0}),"r$8");const R=Ur(e=>{const t=So("md5");return t.update(e),t.digest("hex")},"getHash");var Hr=Object.defineProperty,xt=m((e,t)=>Hr(e,"name",{value:t,configurable:!0}),"d$7");const B=xt(e=>e.handler||e,"getHandler"),D=xt((e,t,o="")=>({...e,async buildEnd(r){e.buildEnd&&await B(e.buildEnd).call(this,r)},async buildStart(r){e.buildStart&&await B(e.buildStart).call(this,r)},async load(r){if(!e.load)return null;const i=$(o,e.name),n=$("load",R(r));if(t.has(n,i))return await t.get(n,i);const s=await B(e.load).call(this,r);return t.set(n,s,i),s},name:`cached(${e.name})`,async resolveId(r,i,n){if(!e.resolveId)return null;const s=$(o,e.name),l=$("resolveId",R(r),i?R(i):"",R(JSON.stringify(n)));if(t.has(l,s))return await t.get(l,s);const a=await B(e.resolveId).call(this,r,i,n);return t.set(l,a,s),a},async transform(r,i){if(!e.transform)return null;const n=$(o,e.name),s=$("transform",R(i),R(r));if(t.has(s,n))return await t.get(s,n);const l=await B(e.transform).call(this,r,i);return t.set(s,l,n),l}}),"cachingPlugin");var qr=Object.defineProperty,Gr=m((e,t)=>qr(e,"name",{value:t,configurable:!0}),"n$6");const Kr=Gr(()=>({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}';
|
|
38
|
+
`+e}return null},order:"post"}}),"prependDirectivePlugin");var Yr=Object.defineProperty,Xr=m((e,t)=>Yr(e,"name",{value:t,configurable:!0}),"c$a");const Qr=Xr(({directiveRegex:e,exclude:t=[],include:o=[],logger:r})=>{const i={},n={},s=A(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=>i[f]?i[f]:null).reduce((f,h)=>(h&&h.forEach(g=>{f.add(g)}),f),new Set),d=new I(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(`
|
|
39
39
|
`)}
|
|
40
40
|
`));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}
|
|
41
|
-
`)),p.size===0&&u===null?null:{code:d.toString(),map:c?d.generateMap({hires:!0}):null}},order:"post"},transform(l,a){if(!s(a))return null;let c=!1;const p=new I(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&&(i[a]||=new Set,i[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:[...i[a]??[]],shebang:n[a]??null}}}:null}}},"preserveDirectives");var
|
|
42
|
-
`)=>({name:"packem:shebang",renderChunk:{handler(o,r,i){if(!r.isEntry||!r.facadeModuleId||o.startsWith("#")&&o[1]==="!")return null;if(e.includes(r.name)){const n=new I(o);return n.prepend(t),{code:n.toString(),map:i.sourcemap?n.generateMap({hires:!0}):void 0}}return null},order:"post"},async writeBundle(o,r){for(const[i,n]of Object.entries(r))if(n.type==="chunk"&&Ee.test(n.code)&&o.dir){const s=w(o.dir,i);await ye(s)}}}),"shebangPlugin"),
|
|
43
|
-
`)=>{const o=Ee.exec(e);return o?o+t:""},"getShebang");var
|
|
41
|
+
`)),p.size===0&&u===null?null:{code:d.toString(),map:c?d.generateMap({hires:!0}):null}},order:"post"},transform(l,a){if(!s(a))return null;let c=!1;const p=new I(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&&(i[a]||=new Set,i[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:[...i[a]??[]],shebang:n[a]??null}}}:null}}},"preserveDirectives");var Zr=Object.defineProperty,en=m((e,t)=>Zr(e,"name",{value:t,configurable:!0}),"t$4");const tn=en(e=>{const t=A(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 on=Object.defineProperty,rn=m((e,t)=>on(e,"name",{value:t,configurable:!0}),"l$7");const ue="\0__file_url__",Et=rn(()=>({async load(e){if(e.startsWith(ue)){const t=No(e.slice(ue.length));return await se(t)}},name:"packem:resolve-file-url",resolveId(e){if(e.startsWith("file://"))return`${ue}${e}`}}),"resolveFileUrl");var nn=Object.defineProperty,le=m((e,t)=>nn(e,"name",{value:t,configurable:!0}),"i$7");const Ee=/^#![^\n]*/,ye=le(async e=>{await mo(e,493).catch(()=>{})},"makeExecutable"),sn=le((e,t=`#!/usr/bin/env node
|
|
42
|
+
`)=>({name:"packem:shebang",renderChunk:{handler(o,r,i){if(!r.isEntry||!r.facadeModuleId||o.startsWith("#")&&o[1]==="!")return null;if(e.includes(r.name)){const n=new I(o);return n.prepend(t),{code:n.toString(),map:i.sourcemap?n.generateMap({hires:!0}):void 0}}return null},order:"post"},async writeBundle(o,r){for(const[i,n]of Object.entries(r))if(n.type==="chunk"&&Ee.test(n.code)&&o.dir){const s=w(o.dir,i);await ye(s)}}}),"shebangPlugin"),an=le(()=>({name:"packem:remove-shebang",renderChunk(e){return e.replace(Ee,"")}}),"removeShebangPlugin"),ln=le((e,t=`
|
|
43
|
+
`)=>{const o=Ee.exec(e);return o?o+t:""},"getShebang");var cn=Object.defineProperty,F=m((e,t)=>cn(e,"name",{value:t,configurable:!0}),"r$7");const pn=/\/\*[^*]*\*+(?:[^/*][^*]*\*+)*\//g,un=/MIT License|MIT license|BSD license/,dn=/\n{2,}/g,mn=/\b(\w+)\$\d+\b/g,fn=/[-/\\^$*+?.()|[\]{}]/g,gn=F(e=>e.replaceAll(fn,"\\$&"),"escapeRegex"),hn=F(e=>[...new Set(e)],"unique"),yn=F(e=>e.replaceAll(pn,t=>un.test(t)?"":t).replaceAll(dn,`
|
|
44
44
|
|
|
45
|
-
`),"cleanUnnecessaryComments"),
|
|
46
|
-
- ${a}`).join(""),l=t.fileName.replace(/\.[^/.]+$/,"");
|
|
45
|
+
`),"cleanUnnecessaryComments"),ze=new Map;function Dt(e,t,{identifierReplacements:o},r){const i=dt(e);for(const s in o){const l=i.find(c=>c.specifier===s&&c.imports.includes("{"));if(!l){this.warn(`${t.fileName} does not import "${s}" for replacement`),process.exitCode=1;continue}const a=o[s];for(const c in a){if(!l.imports.includes(c))throw new Error(`${t.fileName} does not import "${c}" from "${s}" for replacement`);const p=a[c],d=gn(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=hn(Array.from(e.matchAll(mn),s=>s[0]));if(n.length>0){const s=n.map(a=>`
|
|
46
|
+
- ${a}`).join(""),l=t.fileName.replace(/\.[^/.]+$/,"");ze.has(l)||r.warn({message:`${t.fileName} contains confusing identifier names${s}
|
|
47
47
|
|
|
48
|
-
To replace these, add them to the "rollup -> patchTypes -> identifierReplacements" option in your packem config.`,prefix:"plugin:patch-types"}),
|
|
48
|
+
To replace these, add them to the "rollup -> patchTypes -> identifierReplacements" option in your packem config.`,prefix:"plugin:patch-types"}),ze.set(l,!0)}return e}m(Dt,"I$1");F(Dt,"replaceConfusingTypeNames");const vn=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 Ot(e,t){if(e.includes("@internal")){const o=new I(e),r=_o(e,{plugins:["typescript"],sourceType:"module"});if(wt(r,{enter(i){vn(o,i)&&this.skip()}}),e=o.toString(),e.includes("@internal"))throw new Error(`${t.fileName} has unhandled @internal declarations`)}return e}m(Ot,"S");F(Ot,"stripInternalTypes");const bn=F((e,t)=>({name:"packem:patch-types",renderChunk(o,r){return o=Dt.call(this,o,r,e,t),o=Ot.call(this,o,r),o=yn(o),o},resolveId(o){return o.startsWith("types/")?{external:!0,id:"../../"+(o.endsWith(".js")?o:o+".js")}:null}}),"patchTypescriptTypes");var $n=Object.defineProperty,St=m((e,t)=>$n(e,"name",{value:t,configurable:!0}),"m$5");const Nt=St((e,t=!0)=>{if(!e)return null;const{config:o,path:r}=e;if(!o.compilerOptions)return null;const{baseUrl:i,paths:n}=o.compilerOptions;if(!i)return null;const s=w(be(r),i),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=[...Ie(w(s,u))].map(h=>h==="*"?"$"+(++d+""):h==="$"?"$$":h).join("");l.push({find:p,replacement:f})}}return t&&l.push({find:/^(?!\.*\/|\.*$|\w:)(.+)$/,replacement:`${[...Ie(s)].map(a=>a==="$"?"$$":a).join("")}/$1`}),l},"getConfigAlias"),Pt=St((e,t)=>{const o=Nt(e);return{name:"packem:resolve-tsconfig-paths",async resolveId(r,i,n){if(!o||r.includes("\0"))return null;for(const{find:s,replacement:l}of o)if(s.test(r)){const a=r.replace(s,l),c=await this.resolve(a,i,{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 wn=Object.defineProperty,_t=m((e,t)=>wn(e,"name",{value:t,configurable:!0}),"u$6");const jn=_t((e,t)=>{if(!t)return null;const{config:o,path:r}=t;if(!o.compilerOptions)return null;const{rootDirs:i}=o.compilerOptions;if(!i)return null;const n=[];for(const s of i){if(s.startsWith("."))throw new Error(`Invalid rootDir value '.' in ${r}.`);if(s.startsWith(".."))throw new Error(`Invalid rootDir value '..' in ${r}.`);n.push(w(e,s))}return n},"getRootDirectories"),Ct=_t((e,t,o)=>{const r=jn(e,o);return{name:"packem:resolve-tsconfig-root-dirs",async resolveId(i,n,s){if(r===null||r.length===0)return null;if(i.startsWith("."))for(const l of r){const a=$(l,i),c=await this.resolve(a,n,{skipSelf:!0,...s});if(c)return t.debug({message:`Resolved ${i} to ${c.id} using rootDirs from tsconfig.json.`,prefix:"plugin:resolve-tsconfig-root-dirs"}),c.id}return null}}},"resolveTsconfigRootDirectories");var kn=Object.defineProperty,xn=m((e,t)=>kn(e,"name",{value:t,configurable:!0}),"r$6");const It=xn(()=>{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 En=Object.defineProperty,Dn=m((e,t)=>En(e,"name",{value:t,configurable:!0}),"s$b");const On=Dn(e=>{const t=$e(e).split(".");if(t.length>=2){const[o,r]=t.slice(-2),i=t[0],n=/^(\w+)-runtime$/.exec(o)?.[1];if(je.includes(r)&&n&&n.length>0)return i+"-"+n}},"getCustomModuleLayer");var Sn=Object.defineProperty,Nn=m((e,t)=>Sn(e,"name",{value:t,configurable:!0}),"i$6");const de=Nn(e=>(e.preserveDirectives||{directives:[]}).directives.map(t=>t.replace(/^use /,"")).find(t=>t!=="strict"),"getModuleLayer");var Pn=Object.defineProperty,Ve=m((e,t)=>Pn(e,"name",{value:t,configurable:!0}),"c$7");const _n=Ve((e,t)=>{const o=new Map;return Ve(function(r,i){const n=i.getModuleInfo(r);if(!n)return;const{isEntry:s}=n,l=n.meta,a=de(l);if(!s){const c=o.get(r);if(c)return c;const p=On(r);if(p)return o.set(r,p),p}if(s){const c=i.getModuleIds();for(const p of c)i.getModuleInfo(p)&&de(l)===a&&(e.has(p)||e.set(p,new Set),e.get(p).add([r,a]))}if(a&&!s&&e.has(r)){const c=[...e.get(r)];if(c.some(([d])=>{if(t.some(u=>u.path===d)){const u=i.getModuleInfo(d);return de(u?u.meta:{})===a}return!1}))return;if(c.every(([,d])=>d===a))return o.has(r)?o.get(r):void 0;const p=$e(r,we(r))+"-"+a;return o.set(r,p),p}},"splitChunks")},"createSplitChunks");var Cn=Object.defineProperty,In=m((e,t)=>Cn(e,"name",{value:t,configurable:!0}),"n$4");const _=In((e,t)=>e.isDynamicEntry?`chunks/[name].${t}`:`shared/${e.name}-[hash].${t}`,"getChunkFilename");var Mn=Object.defineProperty,Rn=m((e,t)=>Mn(e,"name",{value:t,configurable:!0}),"s$9");const Tn=process.platform==="win32",Ue=Rn((e,t)=>{const o=Tn?"\\":"/";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 Fn=Object.defineProperty,An=m((e,t)=>Fn(e,"name",{value:t,configurable:!0}),"p$2");const De=An((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 i in r){if(i.startsWith("#"))continue;const n=r[i];typeof n=="string"&&(o[i]=$(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}),"p$1");const Bn=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"+Gt.node.split(".")[0];if(t.pkg.engines?.node){const r=ut(t.pkg.engines.node);r&&(o="node"+r.major)}if(t.options.rollup.esbuild.target){const r=W(t.options.rollup.esbuild.target);r.some(i=>i.startsWith("node"))||(t.options.rollup.esbuild.target=[...new Set([...W(o),...r])])}else t.options.rollup.esbuild.target=W(o);return t.tsconfig?.config.compilerOptions?.target==="es5"&&(t.options.rollup.esbuild.keepNames=!1,t.logger.debug("Disabling keepNames because target is set to es5")),{logger:t.logger,minify:t.options.minify,minifyWhitespace:t.options.minify,sourceMap:t.options.sourcemap,...t.options.rollup.esbuild}}if(e==="swc"){if(!t.options.rollup.swc)throw new Error("No swc options found in your configuration.");return{minify:t.options.minify,...t.options.rollup.swc,jsc:{minify:{compress:{directives:!1},format:{comments:"some"},mangle:{toplevel:!0},sourceMap:t.options.sourcemap,toplevel:t.options.emitCJS??t.options.emitESM},...t.options.rollup.swc.jsc},sourceMaps:t.options.sourcemap}}if(e==="sucrase"){if(!t.options.rollup.sucrase)throw new Error("No sucrase options found in your configuration.");return{...t.options.rollup.sucrase}}throw new Error("A Unknown transformer was provided")},"getTransformerConfig"),Mt=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(w(),e.id))}"
|
|
49
49
|
Is the module installed? Note:
|
|
50
50
|
↳ to inline a module into your bundle, install it to "devDependencies".
|
|
51
|
-
↳ 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"),
|
|
52
|
-
${s.stack}`),n){case"info":{e.logger.info({message:l,prefix:o+(s.plugin?":plugin:"+s.plugin:"")});return}case"warn":{e.logger.warn({message:l,prefix:o+(s.plugin?":plugin:"+s.plugin:"")});return}case"debug":e.logger.debug({message:l,prefix:o+(s.plugin?":plugin:"+s.plugin:"")})}},"onLog"),onwarn(n,s){
|
|
51
|
+
↳ 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"),He=new Map,Rt=k((e,t,o)=>{const r=k(n=>{for(const[s,l]of Object.entries(t))if(n.startsWith(s))return n.replace(s,l)},"findAlias"),i=Nt(e.tsconfig,!1);return{external(n){const s=r(n);s&&(n=s);const l=ht(n);if(he(e.options.externals,l)||he(e.options.externals,n))return!0;const{pkg:a}=e;if(n.startsWith(".")||st(n)||/src[/\\]/.test(n)||a.name&&n.startsWith(a.name)||a?.imports?.[n]!==void 0)return!1;if(i){for(const{find:c}of i)if(c.test(n))return e.logger.debug({message:`Resolved alias ${n} to ${c.source}`,prefix:o}),!1}return He.has(n)||e.logger.info({message:'Inlined implicit external "'+j(n)+'". If this is incorrect, add it to the "externals" option.',prefix:o}),He.set(n,!0),!1},input:Object.fromEntries(e.options.entries.map(n=>[n.name,w(e.options.rootDir,n.input)])),logLevel:e.options.debug?"debug":"info",onLog:k((n,s)=>{let l=s.message;switch(s.stack&&(l=`${l}
|
|
52
|
+
${s.stack}`),n){case"info":{e.logger.info({message:l,prefix:o+(s.plugin?":plugin:"+s.plugin:"")});return}case"warn":{e.logger.warn({message:l,prefix:o+(s.plugin?":plugin:"+s.plugin:"")});return}case"debug":e.logger.debug({message:l,prefix:o+(s.plugin?":plugin:"+s.plugin:"")})}},"onLog"),onwarn(n,s){Mt(n,e)||n.code||s(n)},watch:e.mode==="watch"?e.options.rollup.watch:!1}},"baseRollupOptions"),Tt=k(async(e,t)=>{const o=De(e,"build");let r;e.options.rollup.resolve&&(r=D(tt({...e.options.rollup.resolve}),t));const i=e.options.rollup.output?.preserveModules?{preserveModules:!0,preserveModulesRoot:e.options.rollup.output.preserveModulesRoot??"src"}:{manualChunks:_n(e.dependencyGraphMap,e.buildEntries),preserveModules:!1};return{...Rt(e,o,"dependencies"),output:[e.options.emitCJS&&{chunkFileNames:k(n=>_(n,"cjs"),"chunkFileNames"),dir:w(e.options.rootDir,e.options.outDir),entryFileNames:k(n=>Ue(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,...i},e.options.emitESM&&{chunkFileNames:k(n=>_(n,"mjs"),"chunkFileNames"),dir:w(e.options.rootDir,e.options.outDir),entryFileNames:k(n=>Ue(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,...i}].filter(Boolean),plugins:[D(Et(),t),D(It(),t),e.tsconfig&&D(Ct(e.options.rootDir,e.logger,e.tsconfig),t),e.tsconfig&&D(Pt(e.tsconfig,e.logger),t),e.options.rollup.replace&&pt({sourcemap:e.options.sourcemap,...e.options.rollup.replace,values:{...e.options.replace,...e.options.rollup.replace.values}}),e.options.rollup.alias&&ct({customResolver:r,...e.options.rollup.alias,entries:o}),r,e.options.rollup.polyfillNode&&yo({sourceMap:e.options.sourcemap,...e.options.rollup.polyfillNode}),e.options.rollup.json&&$t({...e.options.rollup.json}),cr(),e.options.rollup.wsam&&ho(e.options.rollup.wsam),e.options.declaration&&e.options.rollup.isolatedDeclarations&&e.options.isolatedDeclarationTransformer&&Or(e.options.isolatedDeclarationTransformer,e.options.declaration,e.pkg.type,e.options.rollup.isolatedDeclarations),e.options.transformer?.(Bn(e.options.transformerName,e)),Qr({directiveRegex:/^['|"](use (\w+))['|"]$/,...e.options.rollup.preserveDirectives,logger:e.logger}),sn(e.options.entries.filter(n=>n.executable).map(n=>n.name).filter(Boolean)),e.options.cjsInterop&&e.options.emitCJS&&bt({...e.options.rollup.cjsInterop,logger:e.logger,type:e.pkg.type??"commonjs"}),e.options.rollup.dynamicVars&&jr(),e.options.rollup.dynamicVars&&go(e.options.rollup.dynamicVars),e.options.rollup.commonjs&&D(fo({sourceMap:e.options.sourcemap,...e.options.rollup.commonjs}),t),e.options.rollup.preserveDynamicImports&&{renderDynamicImport(){return{left:"import(",right:")"}}},e.options.rollup.shim&&br(e.pkg,e.options.rollup.shim),e.options.rollup.raw&&tn(e.options.rollup.raw),e.options.rollup.jsxRemoveAttributes&&Mr({attributes:e.options.rollup.jsxRemoveAttributes.attributes,logger:e.logger}),e.options.rollup.metafile&&Br({outDir:w(e.options.rootDir,e.options.outDir),rootDir:e.options.rootDir}),e.options.rollup.copy&&mr(e.options.rollup.copy,e.logger),e.options.rollup.license&&e.options.rollup.license.path&&typeof e.options.rollup.license.dependenciesTemplate=="function"&&jt({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}),Kr(),e.options.emitCJS&&e.options.declaration==="compatible"&&zr(e),e.options.rollup.visualizer&&vo({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"),Wn=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"),Ln=Yo(Wn),Ft=k(async(e,t)=>{const o=De(e,"types"),r={load(l){return/\.(?:js|cjs|mjs|jsx|ts|tsx|mts|json)$/.test(l)?null:""},name:"packem:ignore-files"},i=e.tsconfig?.config.compilerOptions;delete i?.lib;let n;e.options.rollup.resolve&&(n=D(tt({...e.options.rollup.resolve}),t));const s="dts-plugin:"+process.pid+e.tsconfig.path;return{...Rt(e,o,"dts"),onwarn(l,a){Mt(l,e)||l.code!=="EMPTY_BUNDLE"&&a(l)},output:[e.options.emitCJS&&{chunkFileNames:k(l=>_(l,"d.cts"),"chunkFileNames"),dir:w(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=>_(l,"d.mts"),"chunkFileNames"),dir:w(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=>_(l,"d.ts"),"chunkFileNames"),dir:w(e.options.rootDir,e.options.outDir),entryFileNames:"[name].d.ts",format:"cjs",sourcemap:e.options.sourcemap,...e.options.rollup.output}].filter(Boolean),plugins:[D(Et(),t),D(It(),t),e.options.rollup.json&&$t({...e.options.rollup.json}),r,e.tsconfig&&D(Ct(e.options.rootDir,e.logger,e.tsconfig),t),e.tsconfig&&D(Pt(e.tsconfig,e.logger),t),e.options.rollup.replace&&pt({sourcemap:e.options.sourcemap,...e.options.rollup.replace,values:{...e.options.replace,...e.options.rollup.replace.values}}),e.options.rollup.alias&&ct({customResolver:n,...e.options.rollup.alias,entries:o}),n,await Ln(s)(e),e.options.cjsInterop&&e.options.emitCJS&&bt({...e.options.rollup.cjsInterop,logger:e.logger,type:e.pkg.type??"commonjs"}),e.options.rollup.patchTypes&&bn(e.options.rollup.patchTypes,e.logger),an(),e.options.rollup.license&&e.options.rollup.license.path&&typeof e.options.rollup.license.dtsTemplate=="function"&&jt({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})].filter(Boolean)}},"getRollupDtsOptions");var zn=Object.defineProperty,Vn=m((e,t)=>zn(e,"name",{value:t,configurable:!0}),"c$6");const me=Vn(async(e,t,o)=>{const r=await Tt(e,t);if(await e.hooks.callHook("rollup:options",e,r),Object.keys(r.input).length===0)return;const i="rollup-build.json";r.cache=t.get(i,o);const n=await at(r);t.set(i,n.cache,o),await e.hooks.callHook("rollup:build",e,n);const s=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)s.has(u.fileName)||s.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(...s.values())},"build");var Un=Object.defineProperty,K=m((e,t)=>Un(e,"name",{value:t,configurable:!0}),"a$8");const Y=K(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 Ft(e,t);if(await e.hooks.callHook("rollup:dts:options",e,r),Object.keys(r.input).length===0)return;const i="rollup-dts.json";r.cache=t.get(i,o);const n=await at(r);t.set(i,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:K(s=>_(s,"d.cts"),"chunkFileNames"),dir:w(e.options.rootDir,e.options.outDir),entryFileNames:"[name].d.cts"}),e.options.emitESM&&await n.write({chunkFileNames:K(s=>_(s,"d.mts"),"chunkFileNames"),dir:w(e.options.rootDir,e.options.outDir),entryFileNames:"[name].d.mts"}),e.options.declaration==="compatible"&&await n.write({chunkFileNames:K(s=>_(s,"d.mjs"),"chunkFileNames"),dir:w(e.options.rootDir,e.options.outDir),entryFileNames:"[name].d.ts"}),await e.hooks.callHook("rollup:dts:done",e)},"buildTypes");var Hn=Object.defineProperty,qn=m((e,t)=>Hn(e,"name",{value:t,configurable:!0}),"y$1");const Gn=qn((e,t,o)=>e.reduce((r,i)=>{const n=i[t],s=i[o];return r[n]||(r[n]={}),r[n][s]||(r[n][s]=[]),r[n][s].push(i),r},{}),"groupByKeys");var Kn=Object.defineProperty,ne=m((e,t)=>Kn(e,"name",{value:t,configurable:!0}),"b$1");const Yn=ne((e,t,o)=>{const r=ne(n=>N(t.options.rootDir,w(t.options.outDir,n)),"rPath");let i=!1;for(const n of t.buildEntries.filter(s=>!s.chunk)){let s=n.bytes??0;for(const a of n.chunks??[])s+=t.buildEntries.find(c=>c.path===a)?.bytes??0;let l=` ${S(r(n.path))} (${["total size: "+j(M(s)),n.type!=="asset"&&n.bytes&&"chunk size: "+j(M(n.bytes))].filter(Boolean).join(", ")})`;if(l+=n.exports?.length?`
|
|
53
53
|
exports: `+T(n.exports.join(", ")):"",n.chunks?.length&&(l+=`
|
|
54
54
|
${n.chunks.map(a=>{const c=t.buildEntries.find(p=>p.path===a)??{};return T(" └─ "+r(a)+S(c.bytes?" ("+M(c?.bytes)+")":""))}).join(`
|
|
55
55
|
`)}`),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=>T(" 📦 "+r(c.id)+S(c.bytes?" ("+M(c.bytes)+")":""))).join(`
|
|
@@ -62,26 +62,26 @@ ${n.chunks.map(a=>{const c=t.buildEntries.find(p=>p.path===a)??{};return T("
|
|
|
62
62
|
types: `+S(r(p.path))+" (total size: "+j(M(p.bytes??0))+")"}}i=!0,l+=`
|
|
63
63
|
|
|
64
64
|
`,e.raw(n.chunk?T(l):l)}return i&&e.raw("Σ Total dist size (byte size):",j(M(t.buildEntries.reduce((n,s)=>n+(s.bytes??0),0))),`
|
|
65
|
-
`),i},"showSizeInformation"),Xn=ne((e,t)=>{const o=
|
|
65
|
+
`),i},"showSizeInformation"),Xn=ne((e,t)=>{const o=Gn(e.options.entries,"environment","runtime"),r=[];for(const[i,n]of Object.entries(o))for(const[s,l]of Object.entries(n)){const a={...e};(i!=="undefined"||s!=="undefined")&&e.logger.info("Preparing build for "+(i==="undefined"?"":j(i)+" environment"+(s==="undefined"?"":" with "))+(s==="undefined"?"":j(s)+" runtime")),a.options.rollup.replace?(a.options.rollup.replace.values===void 0&&(a.options.rollup.replace.values={}),i!=="undefined"&&(a.options.rollup.replace.values={...a.options.rollup.replace.values,[["process","env","NODE_ENV"].join(".")]:JSON.stringify(i)}),a.options.rollup.replace.values={...a.options.rollup.replace.values,[["process","env","EdgeRuntime"].join(".")]:JSON.stringify(s==="edge-light")}):e.logger.warn("'replace' plugin is disabled. You should enable it to replace 'process.env.*' environments.");let c="";i!=="undefined"&&(c+=i+"/"),s!=="undefined"&&(c+=s+"/");let p=!1;a.options.minify!==void 0&&(p=a.options.minify),i==="development"?p=!1:i==="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(me(g,t,c));const b=g.options.entries.filter(v=>v.declaration);e.options.declaration&&b.length>0&&r.push(Y({...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(me(g,t,c));const b=g.options.entries.filter(v=>v.declaration);e.options.declaration&&b.length>0&&r.push(Y({...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(me(g,t,c));const b=g.options.entries.filter(v=>v.declaration);e.options.declaration&&b.length>0&&r.push(Y({...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(Y(g,t,c))}}return r},"prepareRollupConfig"),Qn=ne(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.
|
|
66
66
|
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.
|
|
67
|
-
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(Xn(e,o)),e.logger.success(
|
|
68
|
-
`));let c=[];try{c=await
|
|
67
|
+
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(Xn(e,o)),e.logger.success(Qt(e.options.name?"Build succeeded for "+e.options.name:"Build succeeded"));for await(const i of oo($(e.options.rootDir,e.options.outDir))){let n=e.buildEntries.find(s=>$(e.options.rootDir,e.options.outDir,s.path)===i.path);if(n||(n={chunk:!0,path:i.path},e.buildEntries.push(n)),!n.bytes){const s=await lt(w(e.options.rootDir,e.options.outDir,i.path));n.bytes=s.size}}return await e.hooks.callHook("build:done",e),Yn(e.logger,e,t)},"build");var Zn=Object.defineProperty,ei=m((e,t)=>Zn(e,"name",{value:t,configurable:!0}),"r$4");const At=ei((e,t)=>mt(t,{esmResolve:!0,interopDefault:!0})(e),"tryRequire");var ti=Object.defineProperty,oi=m((e,t)=>ti(e,"name",{value:t,configurable:!0}),"i$4");const Oe=oi(e=>`{ ${Object.keys(e).map(t=>`${t}: ${JSON.stringify(e[t])}`).join(", ")} }`,"dumpObject");var ri=Object.defineProperty,ni=m((e,t)=>ri(e,"name",{value:t,configurable:!0}),"r$2");const z=ni((e,t)=>{e.warnings.has(t)||e.warnings.add(t)},"warn");var ii=Object.defineProperty,Jt=m((e,t)=>ii(e,"name",{value:t,configurable:!0}),"e$1");const ie=Jt(e=>{if(e.endsWith(".mjs")||e.endsWith(".d.mts"))return"esm";if(e.endsWith(".cjs")||e.endsWith(".d.cts"))return"cjs"},"inferExportTypeFromFileName"),Bt=Jt((e,t,o,r)=>{if(r){const s=ie(r);if(s)return s}if(e==="module"||e==="import")return"esm";if(e==="require")return"cjs";if(t.length===0)return o;const[i,...n]=t;return Bt(i,n,o,r)},"inferExportType");var si=Object.defineProperty,ai=m((e,t)=>si(e,"name",{value:t,configurable:!0}),"i$2");const li=new Set(["import","require","node","node-addons","default","types","deno","browser",...oe]),Se=ai((e,t,o,r=[])=>{if(!e)return[];if(typeof e=="string"){const i=ie(e);if(i&&i!==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:i??t}]}return Object.entries(e).filter(([i])=>!i.endsWith(".json")).flatMap(([i,n])=>o===!1&&i==="types"?[]:typeof n=="string"?{file:n,key:"exports",...li.has(i)?{subKey:i}:{},type:Bt(i,r,t,n)}:Se(n,t,o,[...r,i]))},"extractExportFilenames");var ci=Object.defineProperty,ce=m((e,t)=>ci(e,"name",{value:t,configurable:!0}),"c$3");const pi=ce((e,t)=>e.key==="exports"&&e.subKey===P?P:e.key==="exports"&&e.subKey===L?L:t,"getEnvironment"),X=ce((e,t,o,r,i,n)=>{const s=pi(i,n.environment);let l="node";for(const p of gt)if(i.file.includes("."+p+".")||i.subKey===p){l=p;break}let a=e.find(p=>p.input===t&&p.environment===s&&p.runtime===l);a===void 0&&(a=e[e.push({environment:s,input:t,runtime:l})-1]),o&&(a.outDir=r),i.isExecutable?(a.executable=!0,a.declaration=!1,i.type==="cjs"&&(a.cjs=!0),i.type==="esm"&&(a.esm=!0)):(/\.d\.[mc]?ts$/.test(i.file)&&n.options.declaration!==!1&&(a.declaration=n.options.declaration),i.type==="cjs"&&(a.cjs=!0),i.type==="esm"&&(a.esm=!0));const c=i.file.replace(we(i.file),"").replace(new RegExp(`^./${n.options.outDir.replace(/^\.\//,"")}/`),"");oe.has(i.subKey)&&!t.includes(c)&&(a.fileAlias=c)},"createOrUpdateEntry");let qe=!1;const Ge=ce(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"),ui=ce((e,t,o)=>{const r=[];t.sort((l,a)=>l.split("/").length-a.split("/").length);const i=e.type==="module"?"esm":"cjs";i==="esm"&&(o.options.emitESM=!0),i==="cjs"&&(o.options.emitCJS=!0);const n=Se(e.exports,i,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=ie(a);if(c&&c!==i)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??i})}}e.main&&n.push({file:e.main,key:"main",type:ie(e.main)??i}),e.module&&n.push({file:e.module,key:"module",type:"esm"}),(e.types||e.typings)&&(Ge(o),o.options.declaration===void 0&&(o.options.declaration="compatible"),n.push({file:e.types??e.typings,key:"types"}));const s=[];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"){qe||(o.logger.debug("Private subfolders are not supported, if you need this feature please open an issue on GitHub."),qe=!0);const b=[],v=new RegExp(d+p.replace("*","(.*)")+u),y=new RegExp(d+p.replace(/(.*)\.[^.]*$/,"$1").replace("*","(.*)")+u);for(const E of t)(v.test(E)||oe.has(l.subKey)&&y.test(E))&&b.push(E);if(b.length===0){r.push(`Could not find entrypoint for \`${l.file}\``);continue}for(const E of b)X(s,E,c,a,l,o);continue}const f=new RegExp(d+p+u);let h=t.find(b=>f.test(b));if(oe.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){x(w(o.options.rootDir,l.file))||r.push(`Could not find entrypoint for \`${l.file}\``);continue}(h.endsWith(".ts")||h.endsWith(".cts")||h.endsWith(".mts"))&&x(h)&&Ge(o);const g=h.replace(re,"");x(g+".cts")&&x(g+".mts")?(X(s,g+".cts",c,a,{...l,type:"cjs"},o),X(s,g+".mts",c,a,{...l,type:"esm"},o)):X(s,h,c,a,l,o)}return{entries:s,warnings:r}},"inferEntries");var di=Object.defineProperty,mi=m((e,t)=>di(e,"name",{value:t,configurable:!0}),"o$3");const fi=mi((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 gi=Object.defineProperty,hi=m((e,t)=>gi(e,"name",{value:t,configurable:!0}),"l$6");const yi={hooks:{"build:prepare":hi(function(e){if(e.options.entries.length>0)return;const t=$(e.options.rootDir,e.options.sourceDir);if(!ft(t))throw new Error("No 'src' directory found. Please provide entries manually.");const o=ro(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(Oe(r.publishConfig)),r=fi(r,e.options.declaration));const i=ui(r,o,e);for(const n of i.warnings)z(e,n);if(e.options.entries.push(...i.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?S(n.fileAlias)+" => "+S(n.input.replace(`${e.options.rootDir}/`,"").replace(/\/$/,"/*")):S(n.input.replace(`${e.options.rootDir}/`,"").replace(/\/$/,"/*"))).join(", ")),T([e.options.emitESM&&"esm",e.options.emitCJS&&"cjs",e.options.declaration&&"dts"].filter(Boolean).map(n=>`[${n}]`).join(" ")))},"build:prepare")}};var vi=Object.defineProperty,bi=m((e,t)=>vi(e,"name",{value:t,configurable:!0}),"n$1");const $i=bi((e,t)=>{if(e==="auto")e=yi;else{if(e==="none")return{};typeof e=="string"&&(e=At(e,t))}return typeof e=="function"&&(e=e()),e},"resolvePreset");var wi=Object.defineProperty,ji=m((e,t)=>wi(e,"name",{value:t,configurable:!0}),"o$2");const ki=ji((e,t)=>{const o=mt(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 xi=Object.defineProperty,Ei=m((e,t)=>xi(e,"name",{value:t,configurable:!0}),"u$3");const Di=Ei(async e=>{const t=await ko("jiti",{url:import.meta.url}),o=JSON.stringify({...e.options.stubOptions.jiti,alias:{...De(e,"jit"),...e.options.stubOptions.jiti.alias}},null,2);for(const r of e.options.entries){const i=w(e.options.rootDir,e.options.outDir,r.name),n=ve(ki(r.input,e.options.rootDir)||r.input),s=n.slice(0,Math.max(0,n.length-we(n).length)),l=await se(n),a=ln(l);e.options.emitCJS&&await H(`${i}.cjs`,a+[`const jiti = require(${JSON.stringify(t)})`,"",`const _jiti = jiti(null, ${o})`,"",`/** @type {import(${JSON.stringify(s)})} */`,`module.exports = _jiti(${JSON.stringify(n)})`].join(`
|
|
68
|
+
`));let c=[];try{c=await xo(n,{extensions:je})}catch(d){z(e,`Cannot analyze ${n} for exports: ${d.toString()}`);return}const p=c.includes("default")||c.length===0;await H(`${i}.mjs`,a+[`import jiti from ${JSON.stringify(Po(t).href)};`,"",`const _jiti = jiti(null, ${o})`,"",`/** @type {import(${JSON.stringify(n)})} */`,`const _module = await _jiti.import(${JSON.stringify(n)});`,p?`
|
|
69
69
|
export default _module;`:"",...c.filter(d=>d!=="default").map(d=>`export const ${d} = _module.${d};`)].join(`
|
|
70
70
|
`)),await H(`${i}.d.cts`,[`export * from ${JSON.stringify(s)};`,p?`export { default } from ${JSON.stringify(s)};`:""].join(`
|
|
71
71
|
`)),await H(`${i}.d.mts`,[`export * from ${JSON.stringify(n)};`,p?`export { default } from ${JSON.stringify(n)};`:""].join(`
|
|
72
|
-
`)),a&&(await ye(`${i}.cjs`),await ye(`${i}.mjs`))}await e.hooks.callHook("rollup:done",e)},"createStub");var
|
|
73
|
-
`;return r.startsWith(i)?r.slice(i.length):r},"extractStack"),
|
|
72
|
+
`)),a&&(await ye(`${i}.cjs`),await ye(`${i}.mjs`))}await e.hooks.callHook("rollup:done",e)},"createStub");var Oi=Object.defineProperty,Ne=m((e,t)=>Oi(e,"name",{value:t,configurable:!0}),"i$1");const Si=Ne(e=>{const{message:t,name:o="Error",stack:r}=e;if(!r)return r;const i=`${o}: ${t}
|
|
73
|
+
`;return r.startsWith(i)?r.slice(i.length):r},"extractStack"),Ni=Ne(e=>`
|
|
74
74
|
${e.replaceAll(/^\n|\n$/g,"")}
|
|
75
|
-
`,"normalizeCodeFrame"),
|
|
75
|
+
`,"normalizeCodeFrame"),Wt=Ne(e=>{const t=Si(e);let o=(e.plugin?`[${e.plugin}] `:"")+e.message;e.id&&(o+=`
|
|
76
76
|
file: ${j(e.id+(e.loc?":"+e.loc.line+":"+e.loc.column:""))}`),e.frame&&(o+=`
|
|
77
|
-
`+
|
|
78
|
-
${t}`)},"enhanceRollupError");var
|
|
79
|
-
└─ ${N(process.cwd(),s)}`);if(e.logger.info(n),
|
|
77
|
+
`+Zt(Ni(e.frame))),e.message=o,t!==void 0&&(e.stack=`${e.message}
|
|
78
|
+
${t}`)},"enhanceRollupError");var Pi=Object.defineProperty,Lt=m((e,t)=>Pi(e,"name",{value:t,configurable:!0}),"l$4");const Ke=Lt((e,t,o)=>{const r="watcher:"+t;e.on("change",(i,{event:n})=>{o.info({message:`${j(N(".",i))} was ${n}d`,prefix:r})}),e.on("restart",()=>{o.info({message:"Rebuilding "+t+"...",prefix:r})}),e.on("event",async i=>{switch(i.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 i.result.close(),o.info({message:j(`built in ${i.duration+""}ms.`),prefix:r});break}case"ERROR":{Wt(i.error),o.error({context:[i.error],message:"Rebuild "+t+" failed: "+i.error.message,prefix:r});break}}})},"watchHandler"),_i=Lt(async(e,t)=>{const o=await Tt(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=[$(e.options.sourceDir,"**")],o.watch.chokidar={cwd:e.options.rootDir,...o.watch.chokidar});const r=Ce(o);await e.hooks.callHook("rollup:watch",e,r);const i=[...Array.isArray(o.input)?o.input:typeof o.input=="string"?[o.input]:Object.keys(o.input??{})];let n="Starting watchers for entries:";for(const s of i)n+=T(`
|
|
79
|
+
└─ ${N(process.cwd(),s)}`);if(e.logger.info(n),Ke(r,"bundle",e.logger),e.options.declaration){const s=await Ft(e,t);await e.hooks.callHook("rollup:dts:options",e,s);const l=Ce(s);await e.hooks.callHook("rollup:watch",e,l),Ke(l,"types",e.logger)}},"watch");var Ci=Object.defineProperty,Ii=m((e,t)=>Ci(e,"name",{value:t,configurable:!0}),"a$5");class Mi{static{m(this,"p")}static{Ii(this,"FileCache")}#r;#e;#n;#t=!0;#o=new Map;#i;constructor(t,o,r){this.#r=t,this.#e=Io("@visulima/packem",{cwd:t}),this.#n=o,this.#i=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:x(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(!x(r))return;const i=ot(r);try{const n=JSON.parse(i);return this.#o.set(r,n),n}catch{this.#i.warn(`Could not parse cache file: ${r}, deleting the broken cache file.`),this.#o.delete(r),Co(r,{force:!0});return}}set(t,o,r){if(!this.#t||this.#e===void 0||o===void 0)return;const i=this.getFilePath(t,r);typeof o=="object"&&(o=JSON.stringify(o)),ee(i,o,{overwrite:!0})}getFilePath(t,o){let r=t.replaceAll(ge(this.#r),"");return r=r.replaceAll(":","-"),$(this.#e,this.#n,o?.replaceAll(":","-")??"",ge(r))}}var Ri=Object.defineProperty,Q=m((e,t)=>Ri(e,"name",{value:t,configurable:!0}),"l$3");const Ti=A,Fi=Q((e,t)=>{const{sideEffects:o}=t;let r;if(typeof o=="boolean")r=Q(()=>o,"hasSideEffects");else if(Array.isArray(o))if(o.length<=0)r=Q(()=>!1,"hasSideEffects");else{const i=o.map(n=>n.includes("/")?n:`**/${n}`);r=Ti(i,null,{resolve:e})}else r=Q(()=>null,"hasSideEffects");return r},"getPackageSideEffect");var Ai=Object.defineProperty,Ji=m((e,t)=>Ai(e,"name",{value:t,configurable:!0}),"r$1");const Ye=Ji((e,t)=>{if(e.warnings.size>0&&(t&&e.logger.raw(`
|
|
80
80
|
`),e.logger.warn(`Build is done with some warnings:
|
|
81
81
|
|
|
82
82
|
${[...e.warnings].map(o=>`- ${o}`).join(`
|
|
83
|
-
`)}`),e.options.failOnWarn))throw new Error("Exiting with code (1). You can change this behavior by setting `failOnWarn: false`.")},"logBuildErrors");var
|
|
84
|
-
- `+j(l)+(a.length>0?
|
|
83
|
+
`)}`),e.options.failOnWarn))throw new Error("Exiting with code (1). You can change this behavior by setting `failOnWarn: false`.")},"logBuildErrors");var Bi=Object.defineProperty,zt=m((e,t)=>Bi(e,"name",{value:t,configurable:!0}),"n");const Xe=zt(async(e,t)=>{if(typeof e.name!="string"){let o=st(e.input)?N(t.options.rootDir,e.input):ve(e.input);o.startsWith("./")&&(o=o.slice(2)),e.name=o.replace(new RegExp(`^${t.options.sourceDir}/`),"").replace(re,"")}if(!e.input)throw new Error(`Missing entry input: ${Oe(e)}`);Ro(e.input)&&(e.input=w(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=w(t.options.rootDir,e.outDir??t.options.outDir)},"extendEntry"),Wi=zt(async e=>{e.options.entries=e.options.entries.map(t=>typeof t=="string"?{input:t,isGlob:Me(t)}:{...t,isGlob:Me(t.input)});for(const t of e.options.entries.filter(o=>o.isGlob)){const{isGlob:o,...r}=t,i=jo([r.input],{cwd:e.options.rootDir,dot:!1,ignore:["**/node_modules/**"],onlyFiles:!0});if(i.length===0)throw new Mo("No files found in the glob pattern: "+j($(e.options.rootDir,r.input)));for(const n of i)e.options.entries.push({...r,input:w(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 Xe(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 Xe(t,e)},"prepareEntries");var Li=Object.defineProperty,zi=m((e,t)=>Li(e,"name",{value:t,configurable:!0}),"a$3");const Vi=/^[^a-z_@#~]|[^\w/@#~-]|@\/|#\/|~\//i,Ui=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"]),Qe=zi(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(Vi.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(Ui.has(t))throw new Error(`Alias name "${t}" is a reserved keyword and cannot be used.`);const r=w(o);if(!x(r))throw new Error(`Target path "${r}" for alias "${t}" does not exist.`)}},"validateAliasEntries");var Hi=Object.defineProperty,qi=m((e,t)=>Hi(e,"name",{value:t,configurable:!0}),"o");const Gi=qi(e=>{const t=new Set,o=new Set(Object.keys(e.pkg?.dependencies??{})),r=new Set;for(const i of e.usedImports)o.delete(i),t.add(i);if(e.pkg?.dependencies)for(const i of Object.keys(e.pkg?.dependencies))o.delete(i);for(const i of t){const n=ht(i);!he(e.options.externals,i)&&!i.startsWith("chunks/")&&e.pkg?.dependencies?.[n]===void 0&&e.pkg?.peerDependencies?.[n]===void 0&&r.add(i)}o.size>0&&z(e,`Potential unused dependencies found: ${[...o].map(i=>j(i)).join(", ")}`),r.size>0&&z(e,`Potential implicit dependencies found: ${[...r].map(i=>j(i)).join(", ")}`)},"validateDependencies");var Ki=Object.defineProperty,Vt=m((e,t)=>Ki(e,"name",{value:t,configurable:!0}),"i");const Yi=Vt((e,t)=>To(e,t)<=e.length/3||t.includes(e),"isSimilar"),Xi=Vt((e,t)=>{const o=e.toLowerCase();return t.filter(r=>Yi(r.toLowerCase(),o))},"findAlternatives");var Qi=Object.defineProperty,Ze=m((e,t)=>Qi(e,"name",{value:t,configurable:!0}),"s$1");const Zi=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:"",...Se(e.exports,e.type==="module"?"esm":"cjs",t.options.declaration).map(i=>i.file)].map(i=>i&&w(t.options.rootDir,i.replace(/\/[^*/]*\*[^\n\r/\u2028\u2029]*(?:[\n\r\u2028\u2029][^*/]*\*[^\n\r/\u2028\u2029]*)*(?:\/.*)?$/,"")))),r=[];for(const i of o)i&&!i.includes("*")&&!ft(i)&&r.push(i.replace(`${t.options.rootDir}/`,""));if(r.length>0){const i=Ze(l=>N(t.options.rootDir,w(t.options.outDir,l)),"rPath"),n=t.buildEntries.filter(l=>!l.chunk).map(l=>i(l.path));let s="Potential missing or wrong package.json files:";for(const l of r){const a=Xi(l,n);s+=`
|
|
84
|
+
- `+j(l)+(a.length>0?eo` (did you mean ${a.map(c=>`"${c}"`).join(", ")}?)`:"")}z(t,s)}},"validatePackage");var es=Object.defineProperty,C=m((e,t)=>es(e,"name",{value:t,configurable:!0}),"d");const ts=C(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"),os=C((e,t,o,r,i,n,s,l,a,c)=>{const p=ts(c?.config.compilerOptions?.jsx),d=co(s,n,l,{alias:{},cjsInterop:!1,clean:!0,debug:i,declaration:void 0,emitCJS:void 0,emitESM:void 0,entries:[],externals:[..._e.builtinModules,..._e.builtinModules.map(u=>`node:${u}`)],failOnWarn:!0,fileCache:!0,minify:r===P,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:G,ignoreErrors:!1,include:[/\.[cm]?ts$/]},json:{preferConst:!0},license:{dependenciesTemplate:C((u,f,h)=>`
|
|
85
85
|
# Licenses of bundled dependencies
|
|
86
86
|
The published ${h} artifact additionally contains code with the following licenses:
|
|
87
87
|
`+(u.length>0?`${u.join(", ")}
|
|
@@ -95,12 +95,12 @@ The published ${h} artifact additionally contains code with the following licens
|
|
|
95
95
|
|
|
96
96
|
`:`
|
|
97
97
|
`)+`# Bundled types:
|
|
98
|
-
`+f,"dtsTemplate")},patchTypes:{},polyfillNode:{},preserveDirectives:{exclude:G,include:[/\.(?:m|c)?(?:j|t)sx?$/]},preserveDynamicImports:!0,raw:{exclude:G,include:[/\.(md|txt|css|htm|html|data)$/]},replace:{objectGuards:!0,preventAssignment:!0},resolve:{allowExportsFolderMapping:!1,extensions:je,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===P,...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!==P,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:
|
|
98
|
+
`+f,"dtsTemplate")},patchTypes:{},polyfillNode:{},preserveDirectives:{exclude:G,include:[/\.(?:m|c)?(?:j|t)sx?$/]},preserveDynamicImports:!0,raw:{exclude:G,include:[/\.(md|txt|css|htm|html|data)$/]},replace:{objectGuards:!0,preventAssignment:!0},resolve:{allowExportsFolderMapping:!1,extensions:je,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===P,...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!==P,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:Fi(t,a),preset:"recommended",propertyReadSideEffects:!0},watch:{chokidar:{ignoreInitial:!0,ignorePermissionErrors:!0},clearScreen:!0,exclude:G}},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 ")+uo),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)),Qe(d.alias),d.rollup.alias&&d.rollup.alias.entries&&Qe(d.rollup.alias.entries),d},"generateOptions"),rs=C(async(e,t,o,r,i,n,s,l,a)=>{const c=$i(s.preset??n.preset??"auto",t),p=os(e,t,o,r,i,n,s,c,l,a);no($(p.rootDir,p.outDir));const d={buildEntries:[],dependencyGraphMap:new Map,environment:r,hooks:po(),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),s.hooks&&d.hooks.addHooks(s.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=C(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 nt(o))},"cleanDistributionDirectories"),is=C(async(e,t,o,r,i={})=>{const{configPath:n,debug:s,tsconfigPath:l,...a}=i;r.wrapAll(),e=w(Kt(),e),r.debug("Root directory:",e);const c=$(e,"package.json");if(!x(c))throw new Error("package.json not found at "+c);const p=it(c);r.debug("Using package.json found at",c);let d;if(l){const u=$(e,l);if(!await io(u))throw new Error("tsconfig.json not found at "+u);d={config:ao(u),path:u},r.info("Using tsconfig settings at",u)}else if(p.dependencies?.typescript||p.devDependencies?.typescript)try{d=await lo(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 O=["packem.config.js","packem.config.mjs","packem.config.cjs","packem.config.ts","packem.config.cts","packem.config.mts"];for(const J of O)if(x($(e,J))){u="./"+J;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=At(u,e);typeof f=="function"&&(f=f(o,t)),r.debug("Using packem config found at",$(e,u));const h=Date.now(),g=C(()=>so(Math.floor(Date.now()-h)),"getDuration"),b=R(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 Mi(e,b,r);v.cachePath&&!x($(v.cachePath,b))&&x(v.cachePath)&&(r.info("Clearing file cache because the cache key has changed."),await nt(v.cachePath));const y=await rs(r,e,t,o,s??!1,a,f,p,d);if(v.isEnabled=y.options.fileCache,await Wi(y),y.logger.info(j((t==="watch"?"Watching":t==="jit"?"Stubbing":"Building")+" "+y.options.name)),y.logger.debug(`${S("Root dir:")} ${y.options.rootDir}
|
|
99
99
|
${S("Entries:")}
|
|
100
100
|
${y.options.entries.map(O=>` ${Oe(O)}`).join(`
|
|
101
|
-
`)}`),await
|
|
101
|
+
`)}`),await ns(y),y.options.stub){await Di(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 _i(y,v),Ye(y,!1);return}const E=await Qn(y,p,v);await y.hooks.callHook("validate:before",y),Gi(y),Zi(p,y),await y.hooks.callHook("validate:done",y),Ye(y,E),r.raw(`
|
|
102
102
|
⚡️ Build run in `+g()),r.restoreAll()}catch(u){throw r.raw(`
|
|
103
|
-
`),
|
|
103
|
+
`),Wt(u),u}},"createBundler");var ss=Object.defineProperty,fe=m((e,t)=>ss(e,"name",{value:t,configurable:!0}),"a");const as=fe(e=>{e.addCommand({description:"Demonstrate options required",execute:fe(async({logger:t,options:o})=>{let r="build";o.watch?r="watch":o.jit&&(r="jit");const i={};let n;if(Z.NODE_ENV&&[L,P].includes(Z.NODE_ENV)&&(n=Z.NODE_ENV),o.env)for(const s of o.env)if(s.key==="NODE_ENV"){if(n)throw new Error("NODE_ENV was already set, this can't be overridden.");n=s.value}else i["process.env."+s.key]=JSON.stringify(s.value);n===void 0&&(o.production?n=P:o.development&&(n=L));try{await is(o.dir,r,n,t,{cjsInterop:o.cjsInterop,clean:o.clean,configPath:o.config??void 0,debug:o.debug,minify:o.minify===void 0?n===P:o.minify,replace:{...i},rollup:{esbuild:{target:o.target},license:{path:o.license},metafile:o.metafile,...o.analyze?{visualizer:{}}:{visualizer:!1}},sourcemap:o.sourcemap,tsconfigPath:o.tsconfig??void 0})}catch(s){t.error(s),Yt(1)}},"execute"),name:"build",options:[{defaultValue:".",description:"The directory to build",name:"dir",type:String},{alias:"t",description:"Environments to support. `target` in tsconfig.json is automatically added. Defaults to the current Node.js version.",name:"target"},{description:"Use a custom config file",name:"config",type:String},{description:"Path to the tsconfig.json file",name:"tsconfig",type:String},{description:"Minify the output",name:"minify",type:Boolean},{description:"Generate sourcemaps (experimental)",name:"sourcemap",type:Boolean},{conflicts:"jit",description:"Watch for changes",name:"watch",type:Boolean},{conflicts:"watch",description:"Stub the package for JIT compilation",name:"jit",type:Boolean},{description:"Compile-time environment variables (eg. --env.NODE_ENV=production)",multiple:!0,name:"env",type:fe(t=>{const[o,r]=t.split("=");return{key:o,value:r}},"type")},{defaultValue:!1,description:"Generate meta file (experimental)",name:"metafile",type:Boolean},{description:"Path to the license file",name:"license",type:String},{conflicts:"watch",description:"Visualize and analyze the bundle",name:"analyze",type:Boolean},{description:"CJS interop mode, can export default and named export, (experimental).",name:"cjsInterop",type:Boolean},{conflicts:"development",description:"Run code in production environment",name:"production",type:Boolean},{conflicts:"production",description:"Run code in development environment",name:"development",type:Boolean},{description:"Do not clean the dist directory before building",name:"no-clean",type:Boolean}]})},"createBuildCommand");var ls=Object.defineProperty,et=m((e,t)=>ls(e,"name",{value:t,configurable:!0}),"m");const cs=et(e=>{e.addCommand({description:"Initialize packem configuration",execute:et(async({logger:t,options:o})=>{if(Fo("Welcome to packem setup"),x($(o.dir,"packem.config.ts"))){t.info("Packem project already initialized, you can use `packem build` to build your project");return}if(Ao(o.transformer)){Te("Operation cancelled");return}const r=$(o.dir,"package.json");if(!x(r))throw new Error("No package.json found in the directory");const i=it(r),n=[];if(i.dependencies&&n.push(...Object.keys(i.dependencies)),i.devDependencies&&n.push(...Object.keys(i.devDependencies)),o.transformer===void 0&&(o.transformer=await Fe({message:"Pick a transformer",options:[{label:"esbuild",value:"esbuild"},{label:"swc",value:"swc"},{label:"Sucrase",value:"sucrase"}]}),!n.includes(o.transformer)&&await Ae({message:"Do you want to install "+o.transformer+"?"}))){const s=q();s.start("Installing "+o.transformer),await Re(o.transformer==="swc"?"@swc/core":o.transformer,{cwd:o.dir,dev:!0,silent:!0}),s.stop("")}if(o.isolatedDeclarationTransformer===void 0&&(o.isolatedDeclarationTransformer=await Fe({message:"Pick a isolated declaration transformer",options:[{label:"Typescript",value:"typescript"},{label:"swc",value:"swc"},{label:"OXC",value:"oxc"},{label:"None",value:null}]}),o.isolatedDeclarationTransformer!==null)){let s;switch(o.isolatedDeclarationTransformer){case"typescript":{s="typescript";break}case"swc":{s="@swc/core";break}case"oxc":{s="oxc-transform";break}default:Te("Invalid isolated declaration transformer")}if(s&&!n.includes(s)&&await Ae({message:"Do you want to install "+s+"?"})){const l=q();l.start("Installing "+o.isolatedDeclarationTransformer),await Re(s,{cwd:o.dir,dev:!0,silent:!0}),l.stop("")}}if(n.includes("typescript")||i.type==="module"){const s=`import { defineConfig } from "@visulima/packem/config";
|
|
104
104
|
import transformer from "@visulima/packem/transformer/${o.transformer}";
|
|
105
105
|
${o.isolatedDeclarationTransformer===null?"":`import isolatedDeclarationTransformer from "@visulima/packem/dts/isolated/transformer/${o.isolatedDeclarationTransformer}";
|
|
106
106
|
`}
|
|
@@ -114,4 +114,4 @@ const transformer = require("@visulima/packem/transformer/${o.transformer}");
|
|
|
114
114
|
module.exports = defineConfig({
|
|
115
115
|
transformer
|
|
116
116
|
});
|
|
117
|
-
`,l=q();l.start("Creating packem.config.js"),ee($(o.dir,"packem.config.js"),s),l.stop("Created packem.config.js")}
|
|
117
|
+
`,l=q();l.start("Creating packem.config.js"),ee($(o.dir,"packem.config.js"),s),l.stop("Created packem.config.js")}Jo("Now you can run `packem build` to build your project")},"execute"),name:"init",options:[{defaultValue:".",description:"The directory to initialize",name:"dir",type:String},{description:"Choose a transformer",name:"transformer",type:String},{description:"Choose a isolated declaration transformer",name:"isolated-declaration-transformer",type:String}]})},"createInitCommand"),Pe=new Ht("packem",{logger:{reporters:[new qt({error:{hideErrorCauseCodeView:!0,hideErrorCodeView:!0,hideErrorErrorsCodeView:!0}})],scope:"packem"},packageName:Bo,packageVersion:Wo});cs(Pe);as(Pe);Pe.run({shouldExitProcess:!1});
|