@visulima/packem 1.0.0-alpha.16 → 1.0.0-alpha.18
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.cjs +1 -1
- package/dist/cli.mjs +1 -1
- package/dist/create-bundler.cjs +34 -34
- package/dist/create-bundler.mjs +39 -39
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,17 @@
|
|
|
1
|
+
## @visulima/packem [1.0.0-alpha.18](https://github.com/visulima/packem/compare/@visulima/packem@1.0.0-alpha.17...@visulima/packem@1.0.0-alpha.18) (2024-05-28)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* new debug message ([ef7db6f](https://github.com/visulima/packem/commit/ef7db6ff4af9a91372ae57241dc38a38093e5d6b))
|
|
7
|
+
|
|
8
|
+
## @visulima/packem [1.0.0-alpha.17](https://github.com/visulima/packem/compare/@visulima/packem@1.0.0-alpha.16...@visulima/packem@1.0.0-alpha.17) (2024-05-28)
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Bug Fixes
|
|
12
|
+
|
|
13
|
+
* working on better tests ([a6a569e](https://github.com/visulima/packem/commit/a6a569e88496ac30bfebebc05c0b0f967d8810b8))
|
|
14
|
+
|
|
1
15
|
## @visulima/packem [1.0.0-alpha.16](https://github.com/visulima/packem/compare/@visulima/packem@1.0.0-alpha.15...@visulima/packem@1.0.0-alpha.16) (2024-05-28)
|
|
2
16
|
|
|
3
17
|
|
package/dist/cli.cjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
"use strict";var v=Object.defineProperty;var s=(n,e)=>v(n,"name",{value:e,configurable:!0});const r=require("node:process"),k=require("@visulima/cerebro"),b=require("./create-bundler.cjs"),h=require("@antfu/install-pkg"),i=require("@clack/prompts"),c=require("@visulima/fs"),j=require("@visulima/package/package-json"),l=require("@visulima/path");function w(n){return n&&typeof n=="object"&&"default"in n?n.default:n}s(w,"_interopDefaultCompat");const x=w(k),C="@visulima/packem",P="1.0.0-alpha.
|
|
2
|
+
"use strict";var v=Object.defineProperty;var s=(n,e)=>v(n,"name",{value:e,configurable:!0});const r=require("node:process"),k=require("@visulima/cerebro"),b=require("./create-bundler.cjs"),h=require("@antfu/install-pkg"),i=require("@clack/prompts"),c=require("@visulima/fs"),j=require("@visulima/package/package-json"),l=require("@visulima/path");function w(n){return n&&typeof n=="object"&&"default"in n?n.default:n}s(w,"_interopDefaultCompat");const x=w(k),C="@visulima/packem",P="1.0.0-alpha.17";var S=Object.defineProperty,p=s((n,e)=>S(n,"name",{value:e,configurable:!0}),"n");const q=p(n=>{n.addCommand({description:"Demonstrate options required",execute:p(async({options:e})=>{let t="build";e.watch?t="watch":e.jit&&(t="jit");const a={};if(e.env)for(const o of e.env)a[o.key]=o.value;await b(e.dir,t,{cjsInterop:e.cjsInterop,configPath:e.config??void 0,debug:e.debug,minify:e.minify,replace:{...a},rollup:{esbuild:{target:e.target},license:{path:e.license},metafile:e.metafile,...e.analyze?{visualizer:{}}:{visualizer:!1}},sourcemap:e.sourcemap,tsconfigPath:e.tsconfig??void 0})},"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},{description:"Watch for changes",name:"watch",type:Boolean},{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:p(e=>{const[t,a]=e.split("=");return{key:t,value:a}},"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}]})},"createBuildCommand");var z=Object.defineProperty,g=s((n,e)=>z(n,"name",{value:e,configurable:!0}),"i");const B=g(n=>{n.addCommand({description:"Initialize packem configuration",execute:g(async({logger:e,options:t})=>{if(i.intro("Welcome to packem setup"),c.isAccessibleSync(l.join(t.dir,"packem.config.ts")))return e.info("Packem project already initialized, you can use `packem build` to build your project"),r.exit(0);if(i.isCancel(t.transformer))return i.cancel("Operation cancelled"),r.exit(0);if(t.transformer===void 0){const u=l.join(t.dir,"package.json");if(!c.isAccessibleSync(u))return e.error("No package.json found in the directory"),r.exit(1);const d=j.parsePackageJson(u),y=[...Object.keys(d.dependencies??{}),...Object.keys(d.devDependencies??{})];if(t.transformer=await i.select({message:"Pick a transformer",options:[{label:"esbuild",value:"esbuild"},{label:"swc",value:"swc"},{label:"Sucrase",value:"sucrase"}]}),!y.includes(t.transformer)&&await i.confirm({message:"Do you want to install "+t.transformer+"?"})){const f=i.spinner();f.start("Installing "+t.transformer),await h.installPackage(t.transformer==="swc"?"@swc/core":t.transformer,{cwd:t.dir,dev:!0,silent:!0}),f.stop("")}}const a=`import { defineConfig } from "@visulima/packem/config";
|
|
3
3
|
import transformer from "@visulima/packem/transformer/${t.transformer}";
|
|
4
4
|
|
|
5
5
|
export default defineConfig({
|
package/dist/cli.mjs
CHANGED
|
@@ -7,7 +7,7 @@ import __cjs_mod__ from "node:module";
|
|
|
7
7
|
const __filename = __cjs_url__.fileURLToPath(import.meta.url);
|
|
8
8
|
const __dirname = __cjs_path__.dirname(__filename);
|
|
9
9
|
const require = __cjs_mod__.createRequire(import.meta.url);
|
|
10
|
-
const I="@visulima/packem",N="1.0.0-alpha.
|
|
10
|
+
const I="@visulima/packem",N="1.0.0-alpha.17";var O=Object.defineProperty,s=r((i,e)=>O(i,"name",{value:e,configurable:!0}),"n");const V=s(i=>{i.addCommand({description:"Demonstrate options required",execute:s(async({options:e})=>{let t="build";e.watch?t="watch":e.jit&&(t="jit");const n={};if(e.env)for(const o of e.env)n[o.key]=o.value;await b(e.dir,t,{cjsInterop:e.cjsInterop,configPath:e.config??void 0,debug:e.debug,minify:e.minify,replace:{...n},rollup:{esbuild:{target:e.target},license:{path:e.license},metafile:e.metafile,...e.analyze?{visualizer:{}}:{visualizer:!1}},sourcemap:e.sourcemap,tsconfigPath:e.tsconfig??void 0})},"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},{description:"Watch for changes",name:"watch",type:Boolean},{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:s(e=>{const[t,n]=e.split("=");return{key:t,value:n}},"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}]})},"createBuildCommand");var D=Object.defineProperty,g=r((i,e)=>D(i,"name",{value:e,configurable:!0}),"i");const E=g(i=>{i.addCommand({description:"Initialize packem configuration",execute:g(async({logger:e,options:t})=>{if(j("Welcome to packem setup"),u(c(t.dir,"packem.config.ts")))return e.info("Packem project already initialized, you can use `packem build` to build your project"),a(0);if(w(t.transformer))return C("Operation cancelled"),a(0);if(t.transformer===void 0){const p=c(t.dir,"package.json");if(!u(p))return e.error("No package.json found in the directory"),a(1);const l=B(p),y=[...Object.keys(l.dependencies??{}),...Object.keys(l.devDependencies??{})];if(t.transformer=await x({message:"Pick a transformer",options:[{label:"esbuild",value:"esbuild"},{label:"swc",value:"swc"},{label:"Sucrase",value:"sucrase"}]}),!y.includes(t.transformer)&&await P({message:"Do you want to install "+t.transformer+"?"})){const d=f();d.start("Installing "+t.transformer),await h(t.transformer==="swc"?"@swc/core":t.transformer,{cwd:t.dir,dev:!0,silent:!0}),d.stop("")}}const n=`import { defineConfig } from "@visulima/packem/config";
|
|
11
11
|
import transformer from "@visulima/packem/transformer/${t.transformer}";
|
|
12
12
|
|
|
13
13
|
export default defineConfig({
|
package/dist/create-bundler.cjs
CHANGED
|
@@ -1,36 +1,36 @@
|
|
|
1
|
-
"use strict";var
|
|
2
|
-
`)=>({name:"packem:shebang",renderChunk:{handler(o,n,r){if(!n.isEntry||!n.facadeModuleId||o.startsWith("#")&&o[1]==="!")return null;if(e.includes(n.name)){const s=new D(o);return s.prepend(t),{code:s.toString(),map:r.sourcemap?s.generateMap({hires:!0}):void 0}}return null},order:"post"},async writeBundle(o,n){for(const[r,s]of Object.entries(n))if(s.type==="chunk"&&G.test(s.code)&&o.dir){const i=f.resolve(o.dir,r);await U(i)}}}),"shebangPlugin"),
|
|
3
|
-
`)=>{const o=G.exec(e);return o?o+t:""},"getShebang");var
|
|
4
|
-
`));let a=[];try{a=await T.resolveModuleExportNames(s,{extensions:S.DEFAULT_EXTENSIONS})}catch(c){I(e,`Cannot analyze ${s} for exports:${c}`);return}const u=a.includes("default")||a.length===0;await
|
|
1
|
+
"use strict";var Xe=Object.defineProperty;var d=(e,t)=>Xe(e,"name",{value:t,configurable:!0});const q=require("node:fs/promises"),Ge=require("node:module"),w=require("node:process"),g=require("@visulima/colorize"),v=require("@visulima/fs"),Ye=require("@visulima/fs/error"),P=require("@visulima/humanizer"),te=require("@visulima/package"),Ke=require("@visulima/package/package-json"),Qe=require("@visulima/pail"),L=require("@visulima/pail/processor"),f=require("@visulima/path"),Ze=require("defu"),et=require("hookable"),S=require("./shared/packem.CKW9adaV.cjs"),fe=require("node:url"),T=require("mlly"),tt=require("magic-string"),ot=require("jiti"),A=require("rollup"),rt=require("@rollup/plugin-alias"),nt=require("@rollup/plugin-commonjs"),st=require("@rollup/plugin-dynamic-import-vars"),ge=require("@rollup/plugin-node-resolve"),it=require("@rollup/plugin-replace"),at=require("@rollup/plugin-wasm"),lt=require("rollup-plugin-polyfill-node"),ct=require("rollup-plugin-visualizer"),he=require("semver"),pt=require("glob"),ut=require("glob-parent"),dt=require("@rollup/plugin-json"),F=require("@rollup/pluginutils"),mt=require("rollup-plugin-license"),ft=require("@babel/parser"),X=require("node:fs"),gt=require("fastest-levenshtein");var oe=typeof document<"u"?document.currentScript:null;function E(e){return e&&typeof e=="object"&&"default"in e?e.default:e}d(E,"_interopDefaultCompat");const re=E(Ge),D=E(tt),ye=E(ot),ve=E(rt),ht=E(nt),yt=E(st),be=E(it),vt=E(lt),bt=E(ut),$t=E(dt),jt=E(mt);var wt=Object.defineProperty,B=d((e,t)=>wt(e,"name",{value:t,configurable:!0}),"i$9");const G=/^#![^\n]*/,U=B(async e=>{await q.chmod(e,493).catch(()=>{})},"makeExecutable"),kt=B((e,t=`#!/usr/bin/env node
|
|
2
|
+
`)=>({name:"packem:shebang",renderChunk:{handler(o,n,r){if(!n.isEntry||!n.facadeModuleId||o.startsWith("#")&&o[1]==="!")return null;if(e.includes(n.name)){const s=new D(o);return s.prepend(t),{code:s.toString(),map:r.sourcemap?s.generateMap({hires:!0}):void 0}}return null},order:"post"},async writeBundle(o,n){for(const[r,s]of Object.entries(n))if(s.type==="chunk"&&G.test(s.code)&&o.dir){const i=f.resolve(o.dir,r);await U(i)}}}),"shebangPlugin"),xt=B(()=>({name:"packem:remove-shebang",renderChunk(e){return e.replace(G,"")}}),"removeShebangPlugin"),Et=B((e,t=`
|
|
3
|
+
`)=>{const o=G.exec(e);return o?o+t:""},"getShebang");var _t=Object.defineProperty,Ot=d((e,t)=>_t(e,"name",{value:t,configurable:!0}),"p$1");const Y=Ot((e,t)=>{let o={};if(e.pkg.name&&(o[e.pkg.name]=e.options.rootDir),e.pkg.imports){const{imports:n}=e.pkg;for(const r in n){if(r.startsWith("#"))continue;const s=n[r];typeof s=="string"&&(o[r]=f.join(e.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(n=>[n.find,n.replacement]))):Object.assign(o,e.options.rollup.alias.entries||e.options.rollup.alias)),e.logger.debug({message:"Resolved aliases: "+JSON.stringify(o),prefix:t}),o},"resolveAliases");var St=Object.defineProperty,Dt=d((e,t)=>St(e,"name",{value:t,configurable:!0}),"o$3");const Nt=Dt((e,t)=>{const o=ye(t,{esmResolve:!0,interopDefault:!0});try{return o.resolve(e)}catch(n){if(n.code!=="MODULE_NOT_FOUND")throw new Error(`Error trying import ${e} from ${t}`,{cause:n});return e}},"tryResolve");var Pt=Object.defineProperty,Mt=d((e,t)=>Pt(e,"name",{value:t,configurable:!0}),"r$7");const I=Mt((e,t)=>{e.warnings.has(t)||e.warnings.add(t)},"warn");var Ft=Object.defineProperty,It=d((e,t)=>Ft(e,"name",{value:t,configurable:!0}),"u$8");const Rt=It(async e=>{const t=await T.resolvePath("jiti",{url:typeof document>"u"?require("url").pathToFileURL(__filename).href:oe&&oe.src||new URL("create-bundler.cjs",document.baseURI).href}),o=JSON.stringify({...e.options.stubOptions.jiti,alias:{...Y(e,"jit"),...e.options.stubOptions.jiti.alias}},null,2);for(const n of e.options.entries){const r=f.resolve(e.options.rootDir,e.options.outDir,n.name),s=f.normalize(Nt(n.input,e.options.rootDir)||n.input),i=s.slice(0,Math.max(0,s.length-f.extname(s).length)),l=await v.readFile(s),p=Et(l);e.options.emitCJS&&await v.writeFile(`${r}.cjs`,p+[`const jiti = require(${JSON.stringify(t)})`,"",`const _jiti = jiti(null, ${o})`,"",`/** @type {import(${JSON.stringify(i)})} */`,`module.exports = _jiti(${JSON.stringify(s)})`].join(`
|
|
4
|
+
`));let a=[];try{a=await T.resolveModuleExportNames(s,{extensions:S.DEFAULT_EXTENSIONS})}catch(c){I(e,`Cannot analyze ${s} for exports:${c}`);return}const u=a.includes("default")||a.length===0;await v.writeFile(`${r}.mjs`,p+[`import jiti from ${JSON.stringify(fe.pathToFileURL(t).href)};`,"",`const _jiti = jiti(null, ${o})`,"",`/** @type {import(${JSON.stringify(s)})} */`,`const _module = await _jiti.import(${JSON.stringify(s)});`,u?`
|
|
5
5
|
export default _module;`:"",...a.filter(c=>c!=="default").map(c=>`export const ${c} = _module.${c};`)].join(`
|
|
6
|
-
`)),await
|
|
7
|
-
`)),await
|
|
8
|
-
`)),p&&(await U(`${r}.cjs`),await U(`${r}.mjs`))}await e.hooks.callHook("rollup:done",e)},"createStub");var
|
|
9
|
-
module.exports.default = `+i[2]+";");let p=l.toString();return p=p.replace(/(?:module\.)?exports(?:\['default'\]|\.default)/i,"module.exports"),t.debug({message:"Applied CommonJS interop to entry chunk "+r.fileName+".",prefix:"cjs-interop"}),{code:p,map:l.generateMap({hires:!0})}}if(s.format==="es"&&/\.d\.(?:ts|cts)$/.test(r.fileName)){if(o!=="commonjs"&&r.fileName.endsWith(".d.ts"))return null;const i=/export\s\{\s(.*)\s\}/i.exec(n);if(i===null||i.length<2)return null;const l=i[1].split(", "),p=[];let a;for(const c of l)if(!c.includes("type"))if(c.includes("as")){const[m,
|
|
6
|
+
`)),await v.writeFile(`${r}.d.cts`,[`export * from ${JSON.stringify(i)};`,u?`export { default } from ${JSON.stringify(i)};`:""].join(`
|
|
7
|
+
`)),await v.writeFile(`${r}.d.mts`,[`export * from ${JSON.stringify(s)};`,u?`export { default } from ${JSON.stringify(s)};`:""].join(`
|
|
8
|
+
`)),p&&(await U(`${r}.cjs`),await U(`${r}.mjs`))}await e.hooks.callHook("rollup:done",e)},"createStub");var Ct=Object.defineProperty,Tt=d((e,t)=>Ct(e,"name",{value:t,configurable:!0}),"a$b");const H=Tt((e,t)=>e.some(o=>o instanceof RegExp?o.test(t):o===t),"arrayIncludes");var At=Object.defineProperty,qt=d((e,t)=>At(e,"name",{value:t,configurable:!0}),"a$a");const W=qt(e=>e===void 0?[]:Array.isArray(e)?e:[e],"arrayify");var Bt=Object.defineProperty,Lt=d((e,t)=>Bt(e,"name",{value:t,configurable:!0}),"e$2");const V=Lt((e="")=>{const t=e.split("/");return t[0][0]==="@"?`${t[0]}/${t[1]}`:t[0]},"getPackageName");var Wt=Object.defineProperty,$e=d((e,t)=>Wt(e,"name",{value:t,configurable:!0}),"s$c");const Jt=$e((e,t,o)=>{const n=o??new Map;return(...r)=>{const s=t?typeof t=="function"?t(...r):t:JSON.stringify({args:r}),i=n.get(s);if(i!==void 0)return i;const l=e(...r);return n.set(s,l),l}},"memoize"),zt=$e(e=>{const t=new Map;return o=>Jt(e,o,t)},"memoizeByKey");var Ut=Object.defineProperty,Ht=d((e,t)=>Ut(e,"name",{value:t,configurable:!0}),"m$5");const je=Ht(({addDefaultProperty:e=!1,logger:t,type:o})=>({name:"packem:cjs-interop",renderChunk(n,r,s){if(r.type!=="chunk"||!r.isEntry)return null;if(s.format==="cjs"&&s.exports==="auto"){const i=/(exports(?:\['default'\]|\.default)) = (.*);/i.exec(n);if(i===null||i.length<3)return null;const l=new D(n);l.replace("Object.defineProperty(exports, '__esModule', { value: true });",""),l.replaceAll(/exports\.(.*) = (.*);/g,"module.exports.$1 = $2;"),e&&l.append(`
|
|
9
|
+
module.exports.default = `+i[2]+";");let p=l.toString();return p=p.replace(/(?:module\.)?exports(?:\['default'\]|\.default)/i,"module.exports"),t.debug({message:"Applied CommonJS interop to entry chunk "+r.fileName+".",prefix:"cjs-interop"}),{code:p,map:l.generateMap({hires:!0})}}if(s.format==="es"&&/\.d\.(?:ts|cts)$/.test(r.fileName)){if(o!=="commonjs"&&r.fileName.endsWith(".d.ts"))return null;const i=/export\s\{\s(.*)\s\}/i.exec(n);if(i===null||i.length<2)return null;const l=i[1].split(", "),p=[];let a;for(const c of l)if(!c.includes("type"))if(c.includes("as")){const[m,y]=c.split(" as ");if(y==="default"&&(a=m,!e))continue;p.push(y+": typeof "+m+";")}else p.push(c+": typeof "+c+";");const u=new D(n);return u.replace(" "+a+" as default,",""),u.append(`
|
|
10
10
|
|
|
11
11
|
declare const defaultExport: {
|
|
12
12
|
`+(p.length>0?" ":"")+p.join(`
|
|
13
13
|
`)+`
|
|
14
14
|
} & typeof `+a+`;
|
|
15
15
|
|
|
16
|
-
export default defaultExport;`),t.debug({message:"Applied CommonJS interop to entry chunk "+r.fileName+".",prefix:"cjs-interop"}),{code:u.toString(),map:u.generateMap({hires:!0})}}return null}}),"cjsInterop");var
|
|
16
|
+
export default defaultExport;`),t.debug({message:"Applied CommonJS interop to entry chunk "+r.fileName+".",prefix:"cjs-interop"}),{code:u.toString(),map:u.generateMap({hires:!0})}}return null}}),"cjsInterop");var Vt=Object.defineProperty,Xt=d((e,t)=>Vt(e,"name",{value:t,configurable:!0}),"u$6");const Gt=Xt((e,t)=>{const o=new Map,n={copyOnce:!0,exactFileNames:!0,flatten:!1,...e};let{targets:r}=n;return Array.isArray(r)?r=r.map(s=>{if(typeof s=="string")return{src:s};if(typeof s=="object"&&"src"in s)return s}).filter(Boolean):typeof r=="string"&&(r=[{src:r}]),{async buildStart(){const s=await Promise.all(r.flatMap(i=>Array.isArray(i.src)?i.src.map(l=>({...i,src:l})):i).map(async i=>await pt.glob(i.src,{ignore:i.exclude}).then(l=>({dest:i.dest??"",parent:bt(i.src),src:l}))));for(const i of s)for(const l of i.src){let p;o.has(l)?p=o.get(l):(p={copied:[],dest:[],timestamp:0},o.set(l,p));const a=n.flatten?f.normalize(i.dest):f.join(i.dest,f.relative(i.parent,f.dirname(l)));p.dest.includes(a)||p.dest.push(a),this.addWatchFile(l)}t.info({message:"Copying files...",prefix:"copy"}),await Promise.all([...o].map(async([i,l])=>{let p;try{const a=await q.stat(i);if(!a.isFile())return;const u=a.mtime.getTime();u>l.timestamp&&(l.timestamp=u,l.copied=[]),p=await v.readFile(i,{buffer:!0})}catch(a){t.error({context:[a],message:`error reading file ${i}`,prefix:"copy"});return}for(const a of l.dest){if(n.copyOnce&&l.copied.includes(a))continue;const u=f.basename(i),c=f.join(a,u);try{this.emitFile({[n.exactFileNames?"fileName":"name"]:c,source:p,type:"asset"}),t.debug({message:`copied ${i} → ${c}`,prefix:"copy"}),l.copied.push(a)}catch(m){t.error({context:[m],message:`error copying file ${i} → ${c}`,prefix:"copy"})}}}))},name:"packem:copy"}},"copyPlugin");var Yt=Object.defineProperty,Kt=d((e,t)=>Yt(e,"name",{value:t,configurable:!0}),"n$8");const ne="export default ",we=Kt(e=>{const t=$t(e);return{...t,name:"packem:json",transform(o,n){const r=t.transform?.call(this,o,n);return r&&typeof r!="string"&&"code"in r&&r.code?.startsWith(ne)&&(r.code=r.code.replace(ne,"module.exports = ")),r}}},"JSONPlugin");class Qt{static{d(this,"WalkerBase")}constructor(){this.should_skip=!1,this.should_remove=!1,this.replacement=null,this.context={skip:d(()=>this.should_skip=!0,"skip"),remove:d(()=>this.should_remove=!0,"remove"),replace:d(t=>this.replacement=t,"replace")}}replace(t,o,n,r){t&&o&&(n!=null?t[o][n]=r:t[o]=r)}remove(t,o,n){t&&o&&(n!=null?t[o].splice(n,1):delete t[o])}}class Zt extends Qt{static{d(this,"SyncWalker")}constructor(t,o){super(),this.should_skip=!1,this.should_remove=!1,this.replacement=null,this.context={skip:d(()=>this.should_skip=!0,"skip"),remove:d(()=>this.should_remove=!0,"remove"),replace:d(n=>this.replacement=n,"replace")},this.enter=t,this.leave=o}visit(t,o,n,r){if(t){if(this.enter){const i=this.should_skip,l=this.should_remove,p=this.replacement;this.should_skip=!1,this.should_remove=!1,this.replacement=null,this.enter.call(this.context,t,o,n,r),this.replacement&&(t=this.replacement,this.replace(o,n,r,t)),this.should_remove&&this.remove(o,n,r);const a=this.should_skip,u=this.should_remove;if(this.should_skip=i,this.should_remove=l,this.replacement=p,a)return t;if(u)return null}let s;for(s in t){const i=t[s];if(i&&typeof i=="object")if(Array.isArray(i)){const l=i;for(let p=0;p<l.length;p+=1){const a=l[p];se(a)&&(this.visit(a,t,s,p)||p--)}}else se(i)&&this.visit(i,t,s,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,n,r),this.replacement&&(t=this.replacement,this.replace(o,n,r,t)),this.should_remove&&this.remove(o,n,r);const p=this.should_remove;if(this.replacement=i,this.should_remove=l,p)return null}}return t}}function se(e){return e!==null&&typeof e=="object"&&"type"in e&&typeof e.type=="string"}d(se,"isNode");function ke(e,{enter:t,leave:o}){return new Zt(t,o).visit(e,null)}d(ke,"walk");var eo=Object.defineProperty,to=d((e,t)=>eo(e,"name",{value:t,configurable:!0}),"u$5");const oo=to(({attributes:e,logger:t})=>{const o=F.createFilter([/\.[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(n,r){if(!o(r))return null;let s=null;try{s=this.parse(n,{allowReturnOutsideFunction:!0})}catch(p){return this.warn({code:"PARSE_ERROR",message:`[packem:jsx-remove-attributes]: failed to parse "${r}" and remove the jsx attribute.`}),t.warn(p),null}let i=!1;const l=new D(n);return ke(s,{enter(p){if(p.type==="CallExpression"&&p.callee.type==="Identifier"&&p.callee.name==="jsx"){const a=p.arguments.filter(u=>u.type==="ObjectExpression"&&Array.isArray(u.properties));for(const u of a)for(const c of u.properties)c.type==="Property"&&c.key.type==="Literal"&&c.value.type==="Literal"&&e.includes(c.key.value)&&(l.overwrite(c.start-2,c.end,""),i=!0)}}}),i?{code:l.toString(),map:l.generateMap({hires:!0})}:null}}},"jsxRemoveAttributes");var ro=Object.defineProperty,K=d((e,t)=>ro(e,"name",{value:t,configurable:!0}),"p");const no=K(e=>{const t=[],o=[];return e.forEach(n=>{n.startsWith("(")?t.push(n):o.push(n)}),[...o.sort(),...t.sort()]},"sortLicenses"),so=K((e,t,o)=>{const n=new RegExp(`(<!-- ${t} -->)[\\s\\S]*?(<!-- ${t} -->)`,"g");if(n.test(e))return e.replace(n,`$1
|
|
17
17
|
${o}
|
|
18
|
-
$2`)},"replaceContentWithin"),
|
|
19
|
-
`;m&&(
|
|
20
|
-
`);const
|
|
21
|
-
`),
|
|
22
|
-
`),
|
|
23
|
-
`+
|
|
18
|
+
$2`)},"replaceContentWithin"),xe=K(({licenseFilePath:e,licenseTemplate:t,logger:o,marker:n,mode:r,packageName:s})=>jt({thirdParty(i){const l=new Set,p=i.sort(({name:u},{name:c})=>u>c?1:c>u?-1:0).map(({author:u,contributors:c,license:m,licenseText:y,maintainers:h,name:$,repository:b})=>{let _=`## ${$}
|
|
19
|
+
`;m&&(_+=`License: ${m}
|
|
20
|
+
`);const N=new Set;for(const k of[u,...h,...c]){const ee=typeof k=="string"?k:k?.name;ee&&N.add(ee)}return N.size>0&&(_+=`By: ${[...N].join(", ")}
|
|
21
|
+
`),b&&(_+=`Repository: ${typeof b=="string"?b:b.url}
|
|
22
|
+
`),y&&(_+=`
|
|
23
|
+
`+y.trim().replaceAll(/(\r\n|\r)/g,`
|
|
24
24
|
`).split(`
|
|
25
|
-
`).map(
|
|
25
|
+
`).map(k=>`> ${k}`).join(`
|
|
26
26
|
`)+`
|
|
27
|
-
`),m&&l.add(m),
|
|
27
|
+
`),m&&l.add(m),_}).join(`
|
|
28
28
|
---------------------------------------
|
|
29
29
|
|
|
30
|
-
`),a=t(
|
|
30
|
+
`),a=t(no(l),p,s);try{const u=v.readFileSync(e),c=so(u,n,a);if(!c){o.error(`Could not find the license marker: <!-- ${n} --> in ${e}`);return}u!==c&&(v.writeFileSync(e,c),o.info({message:`${e} updated.`,prefix:`license:${r}`}))}catch(u){o.error(u)}}}),"license");var io=Object.defineProperty,ao=d((e,t)=>io(e,"name",{value:t,configurable:!0}),"i$6");const lo=ao(e=>({async buildEnd(){const t=[];for(const n of this.getModuleIds()){const r=this.getModuleInfo(n);if(r!=null&&!r.isExternal)for(const s of r.importedIds)t.push({source:n,target:s})}if(Array.isArray(t)&&t.length===0)return;const o=f.resolve(e.outDir,"graph.json");v.writeJsonSync(o,t)},name:"packem:metafile"}),"metafilePlugin");var co=Object.defineProperty,po=d((e,t)=>co(e,"name",{value:t,configurable:!0}),"c$4");const uo=/\.(?:m|c)?(?:j|t)sx?$/,mo=/^use \w+$/,fo=po(e=>{const t={},o={};return{name:"packem:preserve-directives",onLog(n,r){return r.code==="MODULE_LEVEL_DIRECTIVE"&&n==="warn"?!1:null},renderChunk:{handler(n,r,{sourcemap:s}){const i=r.moduleIds.map(a=>t[a]?t[a]:null).reduce((a,u)=>(u&&u.forEach(c=>{a.add(c)}),a),new Set),l=new D(n);i.size>0&&(e.debug({message:`directives for chunk "${r.fileName}" are preserved.`,prefix:"preserve-directives"}),l.prepend(`${[...i].map(a=>`'${a}';`).join(`
|
|
31
31
|
`)}
|
|
32
32
|
`));let p=null;return r.facadeModuleId&&typeof o[r.facadeModuleId]=="string"&&(p=o[r.facadeModuleId]),p&&(e.debug({message:`shebang for chunk "${r.fileName}" is preserved.`,prefix:"preserve-directives"}),l.prepend(`${p}
|
|
33
|
-
`)),i.size===0&&p===null?null:{code:l.toString(),map:s?l.generateMap({hires:!0}):null}},order:"post"},transform:{handler(n,r){const s=f.extname(r);if(!
|
|
33
|
+
`)),i.size===0&&p===null?null:{code:l.toString(),map:s?l.generateMap({hires:!0}):null}},order:"post"},transform:{handler(n,r){const s=f.extname(r);if(!uo.test(s))return null;let i=!1;const l=new D(n);if(n.startsWith("#")&&n[1]==="!"){let a=0;for(let u=2,c=n.length;u<c;u++){const m=n.codePointAt(u);if(m===10||m===13||m===8232||m===8233){a=u;break}}a&&(o[r]=n.slice(0,a),l.remove(0,a+1),i=!0,e.debug({message:`shebang for module "${r}" is preserved.`,prefix:"preserve-directives"}))}let p=null;try{p=this.parse(l.toString(),{allowReturnOutsideFunction:!0})}catch(a){return this.warn({code:"PARSE_ERROR",message:`[packem:preserve-directives]: failed to parse "${r}" and extract the directives.`}),e.warn(a),null}if(p.type!=="Program")return null;for(const a of p.body.filter(Boolean)){if(a.type!=="ExpressionStatement")break;let u=null;"directive"in a?u=a.directive:a.expression.type==="Literal"&&typeof a.expression.value=="string"&&mo.test(a.expression.value)&&(u=a.expression.value),u!=="use strict"&&u&&(t[r]||=new Set,t[r].add(u),"start"in a&&typeof a.start=="number"&&"end"in a&&typeof a.end=="number"&&(l.remove(a.start,a.end),i=!0),e.debug({message:`directive "${u}" for module "${r}" is preserved.`,prefix:"preserve-directives"}))}return i?{code:l.toString(),map:l.generateMap({hires:!0}),meta:{preserveDirectives:{directives:[...t[r]??[]],shebang:o[r]??null}}}:null},order:"post"}}},"preserveDirectives");var go=Object.defineProperty,ho=d((e,t)=>go(e,"name",{value:t,configurable:!0}),"r$5");const yo={exclude:[],include:[/\.(md|txt|css|htm|html)$/]},vo=ho((e={})=>{e={...e,...yo};const t=F.createFilter(e.include,e.exclude);return{name:"packem:raw",transform(o,n){return t(n)?{code:`export default ${JSON.stringify(o)}`,map:null}:null}}},"rawPlugin");var bo=Object.defineProperty,$o=d((e,t)=>bo(e,"name",{value:t,configurable:!0}),"l$5");const J="\0__file_url__",Ee=$o(()=>({async load(e){if(e.startsWith(J)){const t=fe.fileURLToPath(e.slice(J.length));return await v.readFile(t)}},name:"packem:resolve-file-url",resolveId(e){if(e.startsWith("file://"))return`${J}${e}`}}),"resolveFileUrl");var jo=Object.defineProperty,_e=d((e,t)=>jo(e,"name",{value:t,configurable:!0}),"i$3");const wo=/__filename|__dirname|require\(|require\.resolve\(/,Oe=`
|
|
34
34
|
// -- pack CommonJS Shims --
|
|
35
35
|
import __cjs_url__ from "node:url";
|
|
36
36
|
import __cjs_path__ from "node:path";
|
|
@@ -38,41 +38,41 @@ import __cjs_mod__ from "node:module";
|
|
|
38
38
|
const __filename = __cjs_url__.fileURLToPath(import.meta.url);
|
|
39
39
|
const __dirname = __cjs_path__.dirname(__filename);
|
|
40
40
|
const require = __cjs_mod__.createRequire(import.meta.url);
|
|
41
|
-
`,
|
|
41
|
+
`,Se=`
|
|
42
42
|
// -- pack CommonJS Shims Node 20.11 --
|
|
43
43
|
import __cjs_mod__ from "node:module";
|
|
44
44
|
const __filename = import.meta.filename;
|
|
45
45
|
const __dirname = import.meta.dirname;
|
|
46
46
|
const require = __cjs_mod__.createRequire(import.meta.url);
|
|
47
|
-
`,
|
|
47
|
+
`,ko=_e((e,t)=>{if(w.env.INTERNAL_PACKEM_BUILD!=="1"&&(e.includes(Oe)||e.includes(Se)||!wo.test(e)))return null;const o=T.findStaticImports(e).pop(),n=o?o.end:0,r=new D(e);return r.appendRight(n,t),{code:r.toString(),map:r.generateMap()}},"CJSToESM"),xo=_e(e=>({name:"packem:cjs",renderChunk(t,o,n){if(n.format==="es"){let r=Oe;if(e.engines?.node){const s=he.minVersion(e.engines.node);s&&s.major>=20&&s.minor>=11&&(r=Se)}return ko(t,r)}return null}}),"cjsPlugin");var Eo=Object.defineProperty,M=d((e,t)=>Eo(e,"name",{value:t,configurable:!0}),"s$9");const _o=/\/\*[^*]*\*+(?:[^/*][^*]*\*+)*\//g,Oo=/MIT License|MIT license|BSD license/,So=/\n{2,}/g,Do=/\b(\w+)\$\d+\b/g,No=/[-/\\^$*+?.()|[\]{}]/g,Po=M(e=>e.replaceAll(No,"\\$&"),"escapeRegex"),Mo=M(e=>[...new Set(e)],"unique"),Fo=M(e=>e.replaceAll(_o,t=>Oo.test(t)?"":t).replaceAll(So,`
|
|
48
48
|
|
|
49
|
-
`),"cleanUnnecessaryComments"),ie=new Map;function
|
|
49
|
+
`),"cleanUnnecessaryComments"),ie=new Map;function De(e,t,{identifierReplacements:o},n){const r=T.findStaticImports(e);for(const i in o){const l=r.find(a=>a.specifier===i&&a.imports.includes("{"));if(!l){this.warn(`${t.fileName} does not import "${i}" for replacement`),process.exitCode=1;continue}const p=o[i];for(const a in p){l.imports.includes(a)||(this.warn(`${t.fileName} does not import "${a}" from "${i}" for replacement`),w.exit(1));const u=p[a],c=Po(a);u.includes(".")&&(e=e.replace(new RegExp(`\\b\\w+\\b as ${c},?\\s?`),"")),e=e.replaceAll(new RegExp(`\\b${c}\\b`,"g"),u)}}const s=Mo(Array.from(e.matchAll(Do),i=>i[0]));if(s.length>0){const i=s.map(p=>`
|
|
50
50
|
- ${p}`).join(""),l=t.fileName.replace(/\.[^/.]+$/,"");ie.has(l)||n.warn({message:`${t.fileName} contains confusing identifier names${i}
|
|
51
51
|
|
|
52
|
-
To replace these, add them to the "patchTypes -> identifierReplacements" option in your packem config.`,prefix:"patch-types"}),ie.set(l,!0)}return e}d(
|
|
52
|
+
To replace these, add them to the "patchTypes -> identifierReplacements" option in your packem config.`,prefix:"patch-types"}),ie.set(l,!0)}return e}d(De,"v$2");M(De,"replaceConfusingTypeNames");function Ne(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}d(Ne,"N");M(Ne,"removeInternal");function Pe(e,t){if(e.includes("@internal")){const o=new D(e),n=ft.parse(e,{plugins:["typescript"],sourceType:"module"});ke(n,{enter(r){Ne(o,r)&&this.skip()}}),e=o.toString(),e.includes("@internal")&&(this.warn(`${t.fileName} has unhandled @internal declarations`),w.exit(1))}return e}d(Pe,"S");M(Pe,"stripInternalTypes");const Io=M((e,t)=>({name:"packem:patch-types",renderChunk(o,n){return o=De.call(this,o,n,e,t),o=Pe.call(this,o,n),o=Fo(o),o},resolveId(o){return o.startsWith("types/")?{external:!0,id:"../../"+(o.endsWith(".js")?o:o+".js")}:null}}),"patchTypescriptTypes");var Ro=Object.defineProperty,Me=d((e,t)=>Ro(e,"name",{value:t,configurable:!0}),"u$3");const Fe=Me((e,t=!0)=>{if(!e)return null;const{config:o,path:n}=e;if(!o.compilerOptions)return null;const{baseUrl:r,paths:s}=o.compilerOptions;if(!r)return null;const i=f.resolve(f.dirname(n),r),l=[];if(s)for(const[p,a]of Object.entries(s)){const u=new RegExp(`^${[...p].map(m=>m==="*"?"(.+)":m.replace(/[\\^$*+?.()|[\]{}]/,"\\$&")).join("")}$`);let c=0;for(const m of a){const y=[...F.normalizePath(f.resolve(i,m))].map(h=>h==="*"?`$${++c}`:h==="$"?"$$":h).join("");l.push({find:u,replacement:y})}}return t&&l.push({find:/^(?!\.*\/|\.*$|\w:)(.+)$/,replacement:`${[...F.normalizePath(i)].map(p=>p==="$"?"$$":p).join("")}/$1`}),l},"getConfigAlias"),Ie=Me((e,t)=>{const o=Fe(e);return{name:"packem:resolve-tsconfig-paths",async resolveId(n,r,s){if(!o||n.includes("\0"))return null;for(const{find:i,replacement:l}of o)if(i.test(n)){const p=n.replace(i,l),a=await this.resolve(p,r,{skipSelf:!0,...s});if(a)return t.debug({message:`Resolved ${n} to ${a.id} using paths from tsconfig.json.`,prefix:"resolve-tsconfig-paths"}),a.id}return null}}},"resolveTsconfigPaths");var Co=Object.defineProperty,Re=d((e,t)=>Co(e,"name",{value:t,configurable:!0}),"u$2");const To=Re((e,t)=>{if(!t)return null;const{config:o,path:n}=t;if(!o.compilerOptions)return null;const{rootDirs:r}=o.compilerOptions;if(!r)return null;const s=[];for(const i of r){if(i.startsWith("."))throw new Error(`Invalid rootDir value '.' in ${n}.`);if(i.startsWith(".."))throw new Error(`Invalid rootDir value '..' in ${n}.`);s.push(f.resolve(e,i))}return s},"getRootDirectories"),Ce=Re((e,t,o)=>{const n=To(e,o);return{name:"packem:resolve-tsconfig-root-dirs",async resolveId(r,s,i){if(n===null||n.length===0)return null;if(r.startsWith("."))for(const l of n){const p=f.join(l,r),a=await this.resolve(p,s,{skipSelf:!0,...i});if(a)return t.debug({message:`Resolved ${r} to ${a.id} using rootDirs from tsconfig.json.`,prefix:"resolve-tsconfig-root-dirs"}),a.id}return null}}},"resolveTsconfigRootDirectories");var Ao=Object.defineProperty,qo=d((e,t)=>Ao(e,"name",{value:t,configurable:!0}),"r$4");const Te=qo(()=>{const e=/\.(?:[mc]?js|jsx)$/;return{name:"packem:resolve-typescript-mjs-cjs",async resolveId(t,o,n){return e.test(t)&&o?await this.resolve(t.replace(/js(x?)$/,"ts$1"),o,n):null}}},"resolveTypescriptMjsCts");var Bo=Object.defineProperty,Lo=d((e,t)=>Bo(e,"name",{value:t,configurable:!0}),"s$8");const Wo=Lo(e=>{const t=f.basename(e).split(".");if(t.length>=2){const[o,n]=t.slice(-2),r=t[0],s=/^(\w+)-runtime$/.exec(o)?.[1];if(S.DEFAULT_EXTENSIONS.includes(n)&&s&&s.length>0)return r+"-"+s}},"getCustomModuleLayer");var Jo=Object.defineProperty,zo=d((e,t)=>Jo(e,"name",{value:t,configurable:!0}),"i$2");const z=zo(e=>(e.preserveDirectives||{directives:[]}).directives.map(t=>t.replace(/^use /,"")).find(t=>t!=="strict"),"getModuleLayer");var Uo=Object.defineProperty,ae=d((e,t)=>Uo(e,"name",{value:t,configurable:!0}),"c$2");const le=ae((e,t)=>{const o=new Map;return ae(function(n,r){const s=r.getModuleInfo(n);if(!s)return;const{isEntry:i}=s,l=s.meta,p=z(l);if(!i){const a=o.get(n);if(a)return a;const u=Wo(n);if(u)return o.set(n,u),u}if(i){const a=r.getModuleIds();for(const u of a)r.getModuleInfo(u)&&z(l)===p&&(e.has(u)||e.set(u,new Set),e.get(u).add([n,p]))}if(p&&!i&&e.has(n)){const a=[...e.get(n)];if(a.some(([c])=>{if(console.log(c),t.some(m=>m.path===c)){const m=r.getModuleInfo(c);return z(m?m.meta:{})===p}return!1}))return;if(a.every(([,c])=>c===p))return o.has(n)?o.get(n):void 0;const u=`${f.basename(n,f.extname(n))}-${p}`;return o.set(n,u),u}},"splitChunks")},"createSplitChunks");var Ho=Object.defineProperty,Vo=d((e,t)=>Ho(e,"name",{value:t,configurable:!0}),"n$6");const O=Vo((e,t,o)=>t.isDynamicEntry?`chunks/[name].${o}`:`shared/${e.options.name}.[hash].${o}`,"getChunkFilename");var Xo=Object.defineProperty,Go=d((e,t)=>Xo(e,"name",{value:t,configurable:!0}),"s$6");const Yo=process.platform==="win32",ce=Go((e,t)=>{const o=Yo?"\\":"/";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 Ko=Object.defineProperty,j=d((e,t)=>Ko(e,"name",{value:t,configurable:!0}),"l$4");const Qo=j((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"+w.versions.node.split(".")[0];if(t.pkg.engines?.node){const n=he.minVersion(t.pkg.engines.node);n&&(o="node"+n.major)}if(t.options.rollup.esbuild.target){const n=W(t.options.rollup.esbuild.target);n.some(r=>r.startsWith("node"))||(t.options.rollup.esbuild.target=[...new Set([...W(o),...n])])}else t.options.rollup.esbuild.target=W(o);return t.tsconfig?.config.compilerOptions?.target==="es5"&&(t.options.rollup.esbuild.keepNames=!1,t.logger.debug("Disabling keepNames because target is set to es5")),{minify:t.options.minify,sourceMap:t.options.sourcemap,...t.options.rollup.esbuild,logger:t.logger}}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"),Ae=j((e,t)=>e.code==="CIRCULAR_DEPENDENCY"&&/Circular dependency:[\s\S]*node_modules/.test(e.message)?!0:e.code==="UNRESOLVED_IMPORT"?(t.logger.error(`Failed to resolve the module "${e.exporter}" imported by "${g.cyan(f.relative(f.resolve(),e.id))}"
|
|
53
53
|
Is the module installed? Note:
|
|
54
54
|
↳ to inline a module into your bundle, install it to "devDependencies".
|
|
55
|
-
↳ to depend on a module via import/require, install it to "dependencies".`),process.exitCode=1,!0):e.code==="MIXED_EXPORTS"&&t.options.cjsInterop===!0,"sharedOnWarn"),pe=new Map,
|
|
56
|
-
└─ ${f.relative(process.cwd(),s)}`);if(e.logger.info(r),ue(o,"bundle",e.logger),e.options.declaration){const s=await
|
|
57
|
-
- `+g.cyan(l)+(p.length>0?g.grey` (did you mean ${p.map(a=>`"${a}"`).join(", ")}?)`:"")}I(t,i)}},"validatePackage");var
|
|
55
|
+
↳ to depend on a module via import/require, install it to "dependencies".`),process.exitCode=1,!0):e.code==="MIXED_EXPORTS"&&t.options.cjsInterop===!0,"sharedOnWarn"),pe=new Map,qe=j((e,t)=>{const o=j(r=>{for(const[s,i]of Object.entries(t))if(r.startsWith(s))return r.replace(s,i)},"findAlias"),n=Fe(e.tsconfig,!1);return{external(r){const s=o(r);s&&(r=s);const i=V(r),l=H(e.options.externals,i)||H(e.options.externals,r);if(l)return!0;if(r.startsWith(".")||f.isAbsolute(r)||/src[/\\]/.test(r)||e.pkg.name&&r.startsWith(e.pkg.name))return!1;if(n){for(const{find:p}of n)if(p.test(r))return e.logger.debug(`Resolved alias ${r} to ${p.source}`),!1}return!l&&pe.has(r)&&e.logger.info('Inlined implicit external "'+g.cyan(r)+'". If this is incorrect, add it to the "externals" option.'),pe.set(r,!0),l},input:Object.fromEntries(e.options.entries.map(r=>[r.name,f.resolve(e.options.rootDir,r.input)])),onwarn(r,s){Ae(r,e)||r.code||s(r)},watch:e.mode==="watch"?e.options.rollup.watch:!1}},"baseRollupOptions"),Be=j(async e=>{const t=Y(e,"build");let o;return e.options.rollup.resolve&&(o=ge.nodeResolve({extensions:S.DEFAULT_EXTENSIONS,...e.options.rollup.resolve})),{...qe(e,t),output:[e.options.emitCJS&&{chunkFileNames:j(n=>O(e,n,"cjs"),"chunkFileNames"),dir:f.resolve(e.options.rootDir,e.options.outDir),entryFileNames:j(n=>ce(n,"cjs"),"entryFileNames"),exports:"auto",externalLiveBindings:!1,format:"cjs",freeze:!1,generatedCode:{constBindings:!0},hoistTransitiveImports:!1,interop:"compat",sourcemap:e.options.sourcemap,...e.options.rollup.output,...e.options.rollup.output?.preserveModules?{preserveModules:!0,preserveModulesRoot:e.options.rollup.output.preserveModulesRoot??"src"}:{manualChunks:le(e.dependencyGraphMap,e.buildEntries),preserveModules:!1}},e.options.emitESM&&{chunkFileNames:j(n=>O(e,n,"mjs"),"chunkFileNames"),dir:f.resolve(e.options.rootDir,e.options.outDir),entryFileNames:j(n=>ce(n,"mjs"),"entryFileNames"),exports:"auto",externalLiveBindings:!1,format:"esm",freeze:!1,generatedCode:{constBindings:!0},hoistTransitiveImports:!1,sourcemap:e.options.sourcemap,...e.options.rollup.output,...e.options.rollup.output?.preserveModules?{preserveModules:!0,preserveModulesRoot:e.options.rollup.output.preserveModulesRoot??"src"}:{manualChunks:le(e.dependencyGraphMap,e.buildEntries),preserveModules:!1}}].filter(Boolean),plugins:[Ee(),Te(),e.tsconfig&&Ce(e.options.rootDir,e.logger,e.tsconfig),e.tsconfig&&Ie(e.tsconfig,e.logger),e.options.rollup.replace&&be({...e.options.rollup.replace,values:{...e.options.replace,...e.options.rollup.replace.values}}),e.options.rollup.alias&&ve({customResolver:o?.resolveId,...e.options.rollup.alias,entries:t}),o,e.options.rollup.polyfillNode&&vt({sourceMap:e.options.sourcemap,...e.options.rollup.polyfillNode}),e.options.rollup.json&&we({...e.options.rollup.json}),fo(e.logger),kt(e.options.entries.filter(n=>n.isExecutable).map(n=>n.name).filter(Boolean)),e.options.rollup.wsam&&at.wasm(e.options.rollup.wsam),e.options.transformer?.(Qo(e.options.transformerName,e)),e.options.cjsInterop&&e.options.emitCJS&&je({...e.options.rollup.cjsInterop,logger:e.logger,type:e.pkg.type??"commonjs"}),e.options.rollup.dynamicVars&&yt(e.options.rollup.dynamicVars),e.options.rollup.commonjs&&ht({extensions:S.DEFAULT_EXTENSIONS,sourceMap:e.options.sourcemap,...e.options.rollup.commonjs}),e.options.rollup.preserveDynamicImports&&{renderDynamicImport(){return{left:"import(",right:")"}}},e.options.rollup.shim&&xo(e.pkg),e.options.rollup.raw&&vo(e.options.rollup.raw),e.options.rollup.jsxRemoveAttributes&&oo({attributes:e.options.rollup.jsxRemoveAttributes.attributes,logger:e.logger}),e.options.rollup.metafile&&lo({outDir:f.resolve(e.options.rootDir,e.options.outDir),rootDir:e.options.rootDir}),e.options.rollup.copy&&Gt(e.options.rollup.copy,e.logger),e.options.rollup.license&&e.options.rollup.license.path&&typeof e.options.rollup.license.template=="function"&&xe({licenseFilePath:e.options.rollup.license.path,licenseTemplate:e.options.rollup.license.template,logger:e.logger,marker:e.options.rollup.license.marker??"DEPENDENCIES",mode:"dependencies",packageName:e.pkg.name}),e.options.rollup.visualizer&&ct.visualizer({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"),Zo=j(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"),er=zt(Zo),Le=j(async e=>{const t=Y(e,"types"),o={load(i){return/\.(?:js|cjs|mjs|jsx|ts|tsx|mts|json)$/.test(i)?null:""},name:"packem:ignore-files"},n=e.tsconfig?.config.compilerOptions;delete n?.lib;let r;e.options.rollup.resolve&&(r=ge.nodeResolve({extensions:S.DEFAULT_EXTENSIONS,...e.options.rollup.resolve}));const s="dts-plugin:"+process.pid+e.tsconfig.path;return{...qe(e,t),onwarn(i,l){Ae(i,e)||i.code!=="EMPTY_BUNDLE"&&l(i)},output:[e.options.emitCJS&&{chunkFileNames:j(i=>O(e,i,"d.cts"),"chunkFileNames"),dir:f.resolve(e.options.rootDir,e.options.outDir),entryFileNames:"[name].d.cts",format:"cjs",sourcemap:e.options.sourcemap,...e.options.rollup.output},{chunkFileNames:j(i=>O(e,i,"d.mts"),"chunkFileNames"),dir:f.resolve(e.options.rootDir,e.options.outDir),entryFileNames:"[name].d.mts",format:"esm",sourcemap:e.options.sourcemap,...e.options.rollup.output},(e.options.declaration===!0||e.options.declaration==="compatible")&&{chunkFileNames:j(i=>O(e,i,"d.ts"),"chunkFileNames"),dir:f.resolve(e.options.rootDir,e.options.outDir),entryFileNames:"[name].d.ts",format:"cjs",sourcemap:e.options.sourcemap,...e.options.rollup.output}].filter(Boolean),plugins:[Ee(),Te(),e.options.rollup.json&&we({...e.options.rollup.json}),o,e.tsconfig&&Ce(e.options.rootDir,e.logger,e.tsconfig),e.tsconfig&&Ie(e.tsconfig,e.logger),e.options.rollup.replace&&be({...e.options.rollup.replace,values:{...e.options.replace,...e.options.rollup.replace.values}}),e.options.rollup.alias&&ve({customResolver:r?.resolveId,...e.options.rollup.alias,entries:t}),r,await er(s)(e),e.options.cjsInterop&&e.options.emitCJS&&je({...e.options.rollup.cjsInterop,logger:e.logger,type:e.pkg.type??"commonjs"}),e.options.rollup.patchTypes&&Io(e.options.rollup.patchTypes,e.logger),xt(),e.options.rollup.license&&e.options.rollup.license.path&&typeof e.options.rollup.license.dtsTemplate=="function"&&xe({licenseFilePath:e.options.rollup.license.path,licenseTemplate:e.options.rollup.license.dtsTemplate,logger:e.logger,marker:e.options.rollup.license.marker??"TYPE_DEPENDENCIES",mode:"types",packageName:e.pkg.name})].filter(Boolean)}},"getRollupDtsOptions");var tr=Object.defineProperty,or=d((e,t)=>tr(e,"name",{value:t,configurable:!0}),"a$3");const rr=or(async e=>{const t=await Be(e);if(await e.hooks.callHook("rollup:options",e,t),Object.keys(t.input).length===0)return;const o=await A.rollup(t);await e.hooks.callHook("rollup:build",e,o);const n=t.output,r=new Map;for(const s of n){const{output:i}=await o.write(s),l=new Set,p=i.filter(u=>u.type==="chunk");for(const u of p){l.add(u.fileName);for(const c of u.imports)e.usedImports.add(c);u.isEntry&&e.buildEntries.push({bytes:Buffer.byteLength(u.code,"utf8"),chunks:u.imports.filter(c=>p.find(m=>m.fileName===c)),exports:u.exports,modules:Object.entries(u.modules).map(([c,m])=>({bytes:m.renderedLength,id:c})),path:u.fileName,type:"entry"})}const a=i.filter(u=>u.type==="asset");for(const u of a)r.has(u.fileName)||r.set(u.fileName,{bytes:Buffer.byteLength(u.source,"utf8"),path:u.fileName,type:"asset"});for(const u of l)e.usedImports.delete(u)}e.buildEntries.push(...r.values())},"build");var nr=Object.defineProperty,R=d((e,t)=>nr(e,"name",{value:t,configurable:!0}),"r$2");const sr=R(async e=>{const t=await Le(e);if(await e.hooks.callHook("rollup:dts:options",e,t),Object.keys(t.input).length===0)return;const o=await A.rollup(t);await e.hooks.callHook("rollup:dts:build",e,o),e.logger.info({message:"Building declaration files...",prefix:"dts"}),e.options.emitCJS&&await o.write({chunkFileNames:R(n=>O(e,n,"d.cts"),"chunkFileNames"),dir:f.resolve(e.options.rootDir,e.options.outDir),entryFileNames:"[name].d.cts"}),e.options.emitESM&&await o.write({chunkFileNames:R(n=>O(e,n,"d.mts"),"chunkFileNames"),dir:f.resolve(e.options.rootDir,e.options.outDir),entryFileNames:"[name].d.mts"}),e.options.declaration===!0&&await o.write({chunkFileNames:R(n=>O(e,n,"d.ts"),"chunkFileNames"),dir:f.resolve(e.options.rootDir,e.options.outDir),entryFileNames:"[name].d.ts"}),await e.hooks.callHook("rollup:dts:done",e)},"buildTypes");var ir=Object.defineProperty,We=d((e,t)=>ir(e,"name",{value:t,configurable:!0}),"l$3");const ue=We((e,t,o)=>{const n="watcher:"+t;e.on("change",(r,{event:s})=>{o.info({message:`${g.cyan(f.relative(".",r))} was ${s}d`,prefix:n})}),e.on("restart",()=>{o.info({message:"Rebuilding "+t+"...",prefix:n})}),e.on("event",r=>{r.code==="END"&&o.success({message:"Rebuild "+t+" finished",prefix:n}),r.code==="ERROR"&&o.error({context:[r.error],message:"Rebuild "+t+" failed: "+r.error.message,prefix:n})})},"watchHandler"),ar=We(async e=>{const t=await Be(e);if(await e.hooks.callHook("rollup:options",e,t),Object.keys(t.input).length===0)return;const o=A.watch(t);await e.hooks.callHook("rollup:watch",e,o);const n=[...Array.isArray(t.input)?t.input:typeof t.input=="string"?[t.input]:Object.keys(t.input??{})];let r="Starting watchers for entries:";for(const s of n)r+=g.gray(`
|
|
56
|
+
└─ ${f.relative(process.cwd(),s)}`);if(e.logger.info(r),ue(o,"bundle",e.logger),e.options.declaration){const s=await Le(e);await e.hooks.callHook("rollup:dts:options",e,s);const i=A.watch(s);await e.hooks.callHook("rollup:watch",e,i),ue(i,"types",e.logger)}},"watch");var lr=Object.defineProperty,cr=d((e,t)=>lr(e,"name",{value:t,configurable:!0}),"i$1");const Je=cr(e=>`{ ${Object.keys(e).map(t=>`${t}: ${JSON.stringify(e[t])}`).join(", ")} }`,"dumpObject");var pr=Object.defineProperty,C=d((e,t)=>pr(e,"name",{value:t,configurable:!0}),"l$2");const ur=F.createFilter,dr=C((e,t)=>{const{sideEffects:o}=t;let n;if(typeof o=="boolean")n=C(()=>o,"hasSideEffects");else if(Array.isArray(o))if(o.length<=0)n=C(()=>!1,"hasSideEffects");else{const r=o.map(s=>s.includes("/")?s:`**/${s}`);n=ur(r,null,{resolve:e})}else n=C(()=>null,"hasSideEffects");return n},"getPackageSideEffect");var mr=Object.defineProperty,fr=d((e,t)=>mr(e,"name",{value:t,configurable:!0}),"t$4");const gr=fr(e=>e.replace(/\.(js|mjs|cjs|ts|mts|cts|json|jsx|tsx)$/,""),"removeExtension");var hr=Object.defineProperty,ze=d((e,t)=>hr(e,"name",{value:t,configurable:!0}),"t$3");const Q=ze(e=>{if(e.endsWith(".mjs")||e.endsWith(".d.mts"))return"esm";if(e.endsWith(".cjs")||e.endsWith(".d.cts"))return"cjs"},"inferExportTypeFromFileName"),Ue=ze((e,t,o,n)=>{if(o){const i=Q(o);if(i)return i}if(e==="module"||e==="import")return"esm";if(e==="require")return"cjs";if(t.length===0)return n==="commonjs"?"cjs":"esm";const[r,...s]=t;return Ue(r,s,o,n)},"inferExportType");var yr=Object.defineProperty,vr=d((e,t)=>yr(e,"name",{value:t,configurable:!0}),"f$3");const Z=vr((e,t,o,n=[])=>{if(!e)return[];if(typeof e=="string"){const r=Q(e),s=t==="module"?"esm":"cjs";if(r&&r!==s)throw new Error(`Exported file "${e}" has an extension that does not match the package.json type "${t}".`);return[{file:e,type:r??s}]}return Object.entries(e).filter(([r])=>!r.endsWith(".json")).flatMap(([r,s])=>r==="types"&&!o?[]:typeof s=="string"?{file:s,type:Ue(r,n,s,t)}:Z(s,t,o,[...n,r]))},"extractExportFilenames");var br=Object.defineProperty,$r=d((e,t)=>br(e,"name",{value:t,configurable:!0}),"e");const jr=$r(e=>{const t=f.normalize(e).split("/");return t.map((o,n)=>t.slice(n).join("/")).filter(Boolean)},"getEntrypointPaths");var wr=Object.defineProperty,kr=d((e,t)=>wr(e,"name",{value:t,configurable:!0}),"h$1");const xr=kr((e,t,o,n=".")=>{const r=[];t.sort((c,m)=>c.split("/").length-m.split("/").length);const s=Z(e.exports,e.type??"commonjs",o);if(e.bin){const c=typeof e.bin=="string"?[e.bin]:Object.values(e.bin);for(const m of c)s.push({file:m,isExecutable:!0})}e.main&&s.push({file:e.main,type:Q(e.main)??(e.type==="module"?"esm":"cjs")}),e.module&&s.push({file:e.module,type:"esm"}),o===void 0&&(e.types||e.typings)&&s.push({file:e.types??e.typings});const i=e.type==="module";for(const c of s.filter(m=>!m.type)){const m=c.file.endsWith(".js");i&&m||c.file.endsWith(".mjs")?c.type="esm":(!i&&m||c.file.endsWith(".cjs"))&&(c.type="cjs")}let l=!1,p=!1,a=!1;const u=[];for(const c of s){const m=c.file.replace(/(?:\*[^/\\]*|\.d\.(?:m|c)?ts|\.\w+)$/,""),y=m.endsWith("/");if(y&&["./","/"].includes(m))continue;const h=jr(m).reduce((b,_)=>{if(b)return b;const N=new RegExp(`(?<=/|$)${_}${y?"":"\\.\\w+"}$`);return t.find(k=>N.test(k))?.replace(/(?:\.d\.(?:m|c)?ts|\.\w+)$/,"")},void 0);if(!h){X.existsSync(f.resolve(n,c.file))||r.push(`Could not find entrypoint for \`${c.file}\``);continue}c.type==="cjs"&&(l=!0),c.type==="esm"&&(p=!0);const $=u.find(b=>b.input===h)??u[u.push({input:h})-1];/\.d\.(?:m|c)?ts$/.test(c.file)&&(a=!0),y&&($.outDir=m),c.isExecutable&&($.isExecutable=!0)}return{cjs:l,dts:a,entries:u,esm:p,warnings:r}},"inferEntries");var Er=Object.defineProperty,_r=d((e,t)=>Er(e,"name",{value:t,configurable:!0}),"t$2");const Or=_r((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 Sr=Object.defineProperty,Dr=d((e,t)=>Sr(e,"name",{value:t,configurable:!0}),"t$1");const Nr={hooks:{"build:prepare":Dr(function(e){if(e.options.entries.length>0)return;const t=f.join(e.options.rootDir,"src");if(!X.existsSync(t))throw new Error("No 'src' directory found. Please provide entries manually.");const o=v.collectSync(t,{extensions:[],includeDirs:!1,includeSymlinks:!1});if(o.length===0)throw new Error("No source files found in 'src' directory. Please provide entries manually.");let n={...e.pkg};n.publishConfig&&(n=Or(n,e.options.declaration));const r=xr(n,o,e.options.declaration,e.options.rootDir);for(const s of r.warnings)I(e,s);if(e.options.entries.push(...r.entries),e.options.emitCJS===void 0&&r.cjs&&(e.options.emitCJS=!0),e.options.emitESM===void 0&&r.esm&&(e.options.emitESM=!0),e.options.declaration===void 0&&r.dts&&(e.options.declaration=r.dts),e.options.entries.length===0)throw new Error("No entries detected. Please provide entries manually.");e.logger.info("Automatically detected entries:",g.cyan(e.options.entries.map(s=>g.bold(s.input.replace(`${e.options.rootDir}/`,"").replace(/\/$/,"/*"))).join(", ")),g.gray([r.esm&&"esm",r.cjs&&"cjs",r.dts&&"dts"].filter(Boolean).map(s=>`[${s}]`).join(" ")))},"build:prepare")}};var Pr=Object.defineProperty,Mr=d((e,t)=>Pr(e,"name",{value:t,configurable:!0}),"n$2");const He=Mr((e,t,o)=>{const n=ye(t,{esmResolve:!0,interopDefault:!0});try{return n(e)}catch(r){if(r.code!=="MODULE_NOT_FOUND")throw new Error(`Error trying import ${e} from ${t}`,{cause:r});return o}},"tryRequire");var Fr=Object.defineProperty,Ir=d((e,t)=>Fr(e,"name",{value:t,configurable:!0}),"t");const Rr=Ir((e,t)=>(e==="auto"?e=Nr:typeof e=="string"&&(e=He(e,t,{})),typeof e=="function"&&(e=e()),e),"resolvePreset");var Cr=Object.defineProperty,Tr=d((e,t)=>Cr(e,"name",{value:t,configurable:!0}),"o");const Ar=Tr(e=>{const t=new Set,o=new Set(Object.keys(e.pkg.dependencies??{})),n=new Set;for(const r of e.usedImports)o.delete(r),t.add(r);if(Array.isArray(e.options.dependencies))for(const r of e.options.dependencies)o.delete(r);for(const r of t)!H(e.options.externals,r)&&!r.startsWith("chunks/")&&!e.options.dependencies.includes(V(r))&&!e.options.peerDependencies.includes(V(r))&&n.add(r);o.size>0&&I(e,`Potential unused dependencies found: ${[...o].map(r=>g.cyan(r)).join(", ")}`),n.size>0&&I(e,`Potential implicit dependencies found: ${[...n].map(r=>g.cyan(r)).join(", ")}`)},"validateDependencies");var qr=Object.defineProperty,Ve=d((e,t)=>qr(e,"name",{value:t,configurable:!0}),"i");const Br=Ve((e,t)=>gt.distance(e,t)<=e.length/3||t.includes(e),"isSimilar"),Lr=Ve((e,t)=>{const o=e.toLowerCase();return t.filter(n=>Br(n.toLowerCase(),o))},"findAlternatives");var Wr=Object.defineProperty,de=d((e,t)=>Wr(e,"name",{value:t,configurable:!0}),"n");const Jr=de((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:"",...Z(e.exports,e.type??"commonjs",t.options.declaration).map(r=>r.file)].map(r=>r&&f.resolve(t.rootDir,r.replace(/\/[^*/]*\*[^\n\r/\u2028\u2029]*(?:[\n\r\u2028\u2029][^*/]*\*[^\n\r/\u2028\u2029]*)*(?:\/.*)?$/,"")))),n=[];for(const r of o)r&&!r.includes("*")&&!X.existsSync(r)&&n.push(r.replace(`${t.rootDir}/`,""));if(n.length>0){const r=de(l=>f.relative(t.rootDir,f.resolve(t.options.outDir,l)),"rPath"),s=t.buildEntries.filter(l=>!l.chunk).map(l=>r(l.path));let i="Potential missing or wrong package.json files:";for(const l of n){const p=Lr(l,s);i+=`
|
|
57
|
+
- `+g.cyan(l)+(p.length>0?g.grey` (did you mean ${p.map(a=>`"${a}"`).join(", ")}?)`:"")}I(t,i)}},"validatePackage");var zr=Object.defineProperty,x=d((e,t)=>zr(e,"name",{value:t,configurable:!0}),"m");const me=x((e,t)=>{e.warnings.size>0&&(t&&e.logger.raw(`
|
|
58
58
|
`),e.logger.warn(`Build is done with some warnings:
|
|
59
59
|
|
|
60
60
|
${[...e.warnings].map(o=>`- ${o}`).join(`
|
|
61
|
-
`)}`),e.options.failOnWarn&&(e.logger.error("Exiting with code (1). You can change this behavior by setting `failOnWarn: false`."),w.exit(1)))},"logErrors"),
|
|
61
|
+
`)}`),e.options.failOnWarn&&(e.logger.error("Exiting with code (1). You can change this behavior by setting `failOnWarn: false`."),w.exit(1)))},"logErrors"),Ur=x(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"),Hr=x((e,t,o,n,r,s,i,l)=>{const p=Ur(l?.config.compilerOptions?.jsx),a=Ze.defu(r,i.packem,n,s,{alias:{},clean:!0,declaration:void 0,dependencies:[],devDependencies:[],emitCJS:void 0,emitESM:void 0,entries:[],externals:[...re.builtinModules,...re.builtinModules.map(u=>`node:${u}`)],failOnWarn:!0,minify:w.env.NODE_ENV==="production",name:(i.name??"").split("/").pop()??"default",optionalDependencies:[],outDir:"dist",peerDependencies:[],replace:{},rollup:{alias:{},cjsInterop:{addDefaultProperty:!1},commonjs:{ignoreTryCatch:!0,preserveSymlinks:!0,transformMixedEsModules:!1},dts:{compilerOptions:{baseUrl:l?.config.compilerOptions?.baseUrl??".",checkJs:!1,composite:!1,declaration:!0,declarationMap:!1,emitDeclarationOnly:!0,incremental:!1,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:l?.config.compilerOptions?.jsx==="react-jsxdev",jsxFactory:l?.config.compilerOptions?.jsxFactory,jsxFragment:l?.config.compilerOptions?.jsxFragmentFactory,jsxImportSource:l?.config.compilerOptions?.jsxImportSource,jsxSideEffects:!0,keepNames:!0,minifyWhitespace:w.env.NODE_ENV==="production",sourcesContent:!1,target:l?.config.compilerOptions?.target,treeShaking:!0,tsconfigRaw:l?.config},json:{preferConst:!0},license:{dtsTemplate:x((u,c,m)=>`
|
|
62
62
|
# Licenses of bundled types
|
|
63
63
|
The published ${m} artifact additionally contains code with the following licenses:
|
|
64
64
|
${u.join(", ")}
|
|
65
65
|
|
|
66
66
|
# Bundled types:
|
|
67
|
-
`+c,"dtsTemplate"),template:
|
|
67
|
+
`+c,"dtsTemplate"),template:x((u,c,m)=>`
|
|
68
68
|
# Licenses of bundled dependencies
|
|
69
69
|
The published ${m} artifact additionally contains code with the following licenses:
|
|
70
70
|
${u.join(", ")}
|
|
71
71
|
|
|
72
72
|
# Bundled dependencies:
|
|
73
|
-
`+c,"template")},patchTypes:{},polyfillNode:{},preserveDynamicImports:!0,raw:{exclude:S.EXCLUDE_REGEXP,include:["**/*.data","**/*.txt"]},replace:{objectGuards:!0,preventAssignment:!0},resolve:{allowExportsFolderMapping:!1,preferBuiltins:!1},shim:!0,sucrase:{disableESTransforms:!0,enableLegacyBabel5ModuleInterop:!1,enableLegacyTypeScriptModuleInterop:l?.config.compilerOptions?.esModuleInterop===!1,include:/\.[jt]sx?$/,injectCreateRequireForImportRequire:!1,preserveDynamicImport:!0,production:w.env.NODE_ENV==="production",...l?.config.compilerOptions?.jsx&&["react","react-jsx","react-jsxdev"].includes(l.config.compilerOptions.jsx)?{jsxFragmentPragma:l.config.compilerOptions.jsxFragmentFactory,jsxImportSource:l.config.compilerOptions.jsxImportSource,jsxPragma:l.config.compilerOptions.jsxFactory,jsxRuntime:p,transforms:["typescript","jsx",...l.config.compilerOptions.esModuleInterop?["imports"]:[]]}:{transforms:["typescript",...l?.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:l?.config.compilerOptions?.experimentalDecorators,dynamicImport:!0,syntax:l?"typescript":"ecmascript",[l?"tsx":"jsx"]:!0},target:l?.config.compilerOptions?.target?.toLowerCase(),transform:{decoratorMetadata:l?.config.compilerOptions?.emitDecoratorMetadata,legacyDecorator:!0,react:{development:w.env.NODE_ENV!=="production",pragma:l?.config.compilerOptions?.jsxFactory,pragmaFrag:l?.config.compilerOptions?.jsxFragmentFactory,runtime:p,throwIfNamespace:!0,useBuiltins:!0}}},module:{ignoreDynamic:!0,importInterop:"none",preserveImportMeta:!0,strict:!1,strictMode:!1,type:"es6"}},treeshake:{moduleSideEffects:
|
|
73
|
+
`+c,"template")},patchTypes:{},polyfillNode:{},preserveDynamicImports:!0,raw:{exclude:S.EXCLUDE_REGEXP,include:["**/*.data","**/*.txt"]},replace:{objectGuards:!0,preventAssignment:!0},resolve:{allowExportsFolderMapping:!1,preferBuiltins:!1},shim:!0,sucrase:{disableESTransforms:!0,enableLegacyBabel5ModuleInterop:!1,enableLegacyTypeScriptModuleInterop:l?.config.compilerOptions?.esModuleInterop===!1,include:/\.[jt]sx?$/,injectCreateRequireForImportRequire:!1,preserveDynamicImport:!0,production:w.env.NODE_ENV==="production",...l?.config.compilerOptions?.jsx&&["react","react-jsx","react-jsxdev"].includes(l.config.compilerOptions.jsx)?{jsxFragmentPragma:l.config.compilerOptions.jsxFragmentFactory,jsxImportSource:l.config.compilerOptions.jsxImportSource,jsxPragma:l.config.compilerOptions.jsxFactory,jsxRuntime:p,transforms:["typescript","jsx",...l.config.compilerOptions.esModuleInterop?["imports"]:[]]}:{transforms:["typescript",...l?.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:l?.config.compilerOptions?.experimentalDecorators,dynamicImport:!0,syntax:l?"typescript":"ecmascript",[l?"tsx":"jsx"]:!0},target:l?.config.compilerOptions?.target?.toLowerCase(),transform:{decoratorMetadata:l?.config.compilerOptions?.emitDecoratorMetadata,legacyDecorator:!0,react:{development:w.env.NODE_ENV!=="production",pragma:l?.config.compilerOptions?.jsxFactory,pragmaFrag:l?.config.compilerOptions?.jsxFragmentFactory,runtime:p,throwIfNamespace:!0,useBuiltins:!0}}},module:{ignoreDynamic:!0,importInterop:"none",preserveImportMeta:!0,strict:!1,strictMode:!1,type:"es6"}},treeshake:{moduleSideEffects:dr(t,i),preset:"recommended"},watch:{clearScreen:!0,exclude:S.EXCLUDE_REGEXP}},rootDir:t,sourcemap:!1,stub:o==="jit",stubOptions:{jiti:{alias:{},esmResolve:!0,interopDefault:!0}},transformerName:void 0});if(!a.transformerName){const u=new Set([...Object.keys(i.dependencies??{}),...Object.keys(i.devDependencies??{})]);if(u.has("esbuild"))a.transformerName="esbuild";else if(u.has("@swc/core"))a.transformerName="swc";else if(u.has("sucrase"))a.transformerName="sucrase";else throw new Error("Unknown transformer, check your transformer options or install one of the supported transformers: esbuild, swc, sucrase");e.info('Using "'+g.cyan(a.transformerName)+'" as transformer.')}return a.outDir=f.resolve(a.rootDir,a.outDir),a.rollup.resolve&&a.rollup.resolve.preferBuiltins===!0&&(a.rollup.polyfillNode=!1,e.debug("Disabling polyfillNode because preferBuiltins is set to true")),l?.config.compilerOptions?.isolatedModules||e.warn(`'compilerOptions.isolatedModules' is not enabled in tsconfig.
|
|
74
74
|
Because none of the third-party transpilers, 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.
|
|
75
|
-
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.`),a.dependencies=Object.keys(i.dependencies??{}),a.peerDependencies=Object.keys(i.peerDependencies??{}),a.devDependencies=Object.keys(i.devDependencies??{}),a.optionalDependencies=Object.keys(i.optionalDependencies??{}),a.externals.push(...a.dependencies,...a.peerDependencies,...a.optionalDependencies),a},"generateOptions"),
|
|
75
|
+
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.`),a.dependencies=Object.keys(i.dependencies??{}),a.peerDependencies=Object.keys(i.peerDependencies??{}),a.devDependencies=Object.keys(i.devDependencies??{}),a.optionalDependencies=Object.keys(i.optionalDependencies??{}),a.externals.push(...a.dependencies,...a.peerDependencies,...a.optionalDependencies),a},"generateOptions"),Vr=x(async(e,t)=>{e.options.entries=e.options.entries.map(o=>typeof o=="string"?{input:o}:o);for await(const o of e.options.entries){if(typeof o.name!="string"){let n=f.isAbsolute(o.input)?f.relative(t,o.input):f.normalize(o.input);n.startsWith("./")&&(n=n.slice(2)),o.name=gr(n.replace(/^src\//,""))}if(!o.input)throw new Error(`Missing entry input: ${Je(o)}`);if(!e.options.declaration&&o.declaration===void 0&&(o.declaration=e.options.declaration),o.input=f.resolve(e.options.rootDir,o.input),!v.isAccessibleSync(o.input)){const n=new Set(await q.readdir(f.dirname(o.input)));let r=!1;for(const s of S.DEFAULT_EXTENSIONS)if(n.has(f.basename(o.input)+s)){r=!0;break}if(!r)throw new Ye.NotFoundError("Your configured entry: "+g.cyan(o.input)+" does not exist.")}o.outDir=f.resolve(e.options.rootDir,o.outDir??e.options.outDir)}},"prepareEntries"),Xr=x((e,t,o)=>{const n=x(s=>f.relative(t.rootDir,f.resolve(t.options.outDir,s)),"rPath");let r=!1;for(const s of t.buildEntries.filter(i=>!i.chunk)){let i=s.bytes??0;for(const p of s.chunks??[])i+=t.buildEntries.find(a=>a.path===p)?.bytes??0;let l=` ${g.bold(n(s.path))} (${["total size: "+g.cyan(P.formatBytes(i)),s.type!=="asset"&&s.bytes&&"chunk size: "+g.cyan(P.formatBytes(s.bytes))].filter(Boolean).join(", ")})`;if(l+=s.exports?.length?`
|
|
76
76
|
exports: `+g.gray(s.exports.join(", ")):"",s.chunks?.length&&(l+=`
|
|
77
77
|
${s.chunks.map(p=>{const a=t.buildEntries.find(u=>u.path===p)??{};return g.gray(" └─ "+n(p)+g.bold(a.bytes?" ("+P.formatBytes(a?.bytes)+")":""))}).join(`
|
|
78
78
|
`)}`),s.modules&&s.modules.length>0){const p=s.modules.filter(a=>a.id.includes("node_modules")).sort((a,u)=>(u.bytes||0)-(a.bytes||0)).map(a=>g.gray(" 📦 "+n(a.id)+g.bold(a.bytes?" ("+P.formatBytes(a.bytes)+")":""))).join(`
|
|
@@ -85,8 +85,8 @@ ${s.chunks.map(p=>{const a=t.buildEntries.find(u=>u.path===p)??{};return g.gray(
|
|
|
85
85
|
types: `+g.bold(n(u.path))+" (total size: "+g.cyan(P.formatBytes(u.bytes??0))+")"}}r=!0,l+=`
|
|
86
86
|
|
|
87
87
|
`,e.raw(s.chunk?g.gray(l):l)}return r&&e.raw("Σ Total dist size (byte size):",g.cyan(P.formatBytes(t.buildEntries.reduce((s,i)=>s+(i.bytes??0),0))),`
|
|
88
|
-
`),r},"showSizeInformation"),
|
|
88
|
+
`),r},"showSizeInformation"),Gr=x(async(e,t,o,n,r,s,i,l,p)=>{const a=Rr(n,t),u=Hr(e,t,o,r,s,a,i,l);v.ensureDirSync(u.outDir);const c={buildEntries:[],dependencyGraphMap:new Map,hooks:et.createHooks(),logger:e,mode:o,options:u,pkg:i,rootDir:t,tsconfig:l,usedImports:new Set,warnings:new Set};if(a.hooks&&c.hooks.addHooks(a.hooks),r.hooks&&c.hooks.addHooks(r.hooks),s.hooks&&c.hooks.addHooks(s.hooks),await c.hooks.callHook("build:prepare",c),c.options.emitESM===!1&&c.options.emitCJS===!1)throw new Error("Both emitESM and emitCJS are disabled. At least one of them must be enabled.");if(c.options.declaration&&l===void 0)throw new Error("Cannot build declaration files without a tsconfig.json");c.options.emitESM===void 0&&e.info("Emitting ESM bundles, is disabled."),c.options.emitCJS===void 0&&e.info("Emitting CJS bundles, is disabled."),c.options.declaration||e.info("Declaration files, are disabled."),await Vr(c,t),await c.hooks.callHook("build:before",c);let m="Building";if(o==="watch"?m="Watching":o==="jit"&&(m="Stubbing"),e.info(g.cyan(`${m} ${c.options.name}`)),e.debug(`${g.bold("Root dir:")} ${c.options.rootDir}
|
|
89
89
|
${g.bold("Entries:")}
|
|
90
|
-
${c.options.entries.map(h=>` ${
|
|
91
|
-
`)}`),c.options.clean)for(const h of new Set(c.options.entries.map($=>$.outDir).filter(Boolean).sort()))h!==c.options.rootDir&&(p.push(h),e.info(`Cleaning dist directory: \`./${f.relative(c.options.rootDir,h)}\``),await
|
|
92
|
-
⚡️ Build run in ${
|
|
90
|
+
${c.options.entries.map(h=>` ${Je(h)}`).join(`
|
|
91
|
+
`)}`),c.options.clean)for(const h of new Set(c.options.entries.map($=>$.outDir).filter(Boolean).sort()))h!==c.options.rootDir&&(p.push(h),e.info(`Cleaning dist directory: \`./${f.relative(c.options.rootDir,h)}\``),await v.emptyDir(h));if(c.options.stub){await Rt(c),await c.hooks.callHook("build:done",c);return}if(o==="watch"){await ar(c),me(c,!1);return}await Promise.allSettled([rr(c),c.options.declaration&&sr(c)]),e.success(g.green(`Build succeeded for ${c.options.name}`));for await(const h of v.walk(c.options.outDir)){let $=c.buildEntries.find(b=>f.join(c.options.outDir,b.path)===h.path);if($||($={chunk:!0,path:h.path},c.buildEntries.push($)),!$.bytes){const b=await q.stat(f.resolve(c.options.outDir,h.path));$.bytes=b.size}}const y=Xr(e,c,i);Ar(c),Jr(i,c),await c.hooks.callHook("build:done",c),me(c,y)},"build"),Yr=x(async(e,t,o={})=>{const{configPath:n,debug:r,tsconfigPath:s,...i}=o,l=[new L.MessageFormatterProcessor,new L.ErrorProcessor];r&&l.push(new L.CallerProcessor);const p=Qe.createPail({logLevel:r?"debug":"informational",processors:l,scope:"packem"});p.wrapAll(),e=f.resolve(w.cwd(),e),p.debug("Root directory:",e);let a;if(s)await v.isAccessible(s)||(p.error("tsconfig.json not found at",s),w.exit(1)),a={config:te.readTsConfig(s),path:s},p.info("Using tsconfig settings found at",s);else try{a=await te.findTSConfig(e),p.debug("Using tsconfig settings found at",a.path)}catch{p.info("No tsconfig.json or jsconfig.json found.")}try{const u=f.join(e,"package.json"),c=Ke.parsePackageJson(u);p.debug("Using package.json found at",u);const m=n??"./packem.config",y=He(m,e,[]);p.debug("Using packem.config.ts found at",f.join(e,m));const h=(Array.isArray(y)?y:[y]).filter(Boolean),$=Date.now(),b=x(()=>Math.floor(Date.now()-$)+"ms","getDuration");let _=c.packem?.preset??o.preset??"auto";const N=[];await Promise.allSettled(h.map(async k=>{k.preset&&(_=k.preset),await Gr(p,e,t,_,i,k,c,a,N)})),p.raw(`
|
|
92
|
+
⚡️ Build run in ${b()}`),p.restoreAll(),w.exit(0)}catch(u){p.error("An error occurred while building",u),w.exit(1)}},"createBundler");module.exports=Yr;
|
package/dist/create-bundler.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
var
|
|
1
|
+
var rt=Object.defineProperty;var m=(e,t)=>rt(e,"name",{value:t,configurable:!0});import{chmod as nt,stat as $e,readdir as st}from"node:fs/promises";import ie from"node:module";import{env as R,exit as C,versions as it,cwd as at}from"node:process";import{cyan as v,gray as P,bold as x,grey as lt,green as pt}from"@visulima/colorize";import{readFile as X,writeFile as T,readFileSync as ct,writeFileSync as ut,writeJsonSync as mt,collectSync as dt,isAccessibleSync as ft,ensureDirSync as gt,emptyDir as ht,walk as yt,isAccessible as vt}from"@visulima/fs";import{NotFoundError as bt}from"@visulima/fs/error";import{formatBytes as N}from"@visulima/humanizer";import{readTsConfig as $t,findTSConfig as jt}from"@visulima/package";import{parsePackageJson as wt}from"@visulima/package/package-json";import{createPail as kt}from"@visulima/pail";import{MessageFormatterProcessor as xt,ErrorProcessor as Et,CallerProcessor as Ot}from"@visulima/pail/processor";import{resolve as f,join as O,normalize as B,extname as Y,relative as D,dirname as K,basename as J,isAbsolute as je}from"@visulima/path";import{defu as St}from"defu";import{createHooks as Dt}from"hookable";import{a as I,E as ae}from"./shared/packem.CxExFSHU.mjs";import{pathToFileURL as _t,fileURLToPath as Nt}from"node:url";import{resolvePath as Pt,resolveModuleExportNames as Mt,findStaticImports as we}from"mlly";import S from"magic-string";import ke from"jiti";import{rollup as xe,watch as le}from"rollup";import Ee from"@rollup/plugin-alias";import Ct from"@rollup/plugin-commonjs";import It from"@rollup/plugin-dynamic-import-vars";import{nodeResolve as Oe}from"@rollup/plugin-node-resolve";import Se from"@rollup/plugin-replace";import{wasm as Rt}from"@rollup/plugin-wasm";import Ft from"rollup-plugin-polyfill-node";import{visualizer as Tt}from"rollup-plugin-visualizer";import{minVersion as De}from"semver";import{glob as At}from"glob";import Wt from"glob-parent";import Bt from"@rollup/plugin-json";import{createFilter as Q,normalizePath as pe}from"@rollup/pluginutils";import Jt from"rollup-plugin-license";import{parse as Lt}from"@babel/parser";import{existsSync as Z}from"node:fs";import{distance as zt}from"fastest-levenshtein";
|
|
2
2
|
// -- pack CommonJS Shims --
|
|
3
3
|
import __cjs_url__ from "node:url";
|
|
4
4
|
import __cjs_path__ from "node:path";
|
|
@@ -6,39 +6,39 @@ import __cjs_mod__ from "node:module";
|
|
|
6
6
|
const __filename = __cjs_url__.fileURLToPath(import.meta.url);
|
|
7
7
|
const __dirname = __cjs_path__.dirname(__filename);
|
|
8
8
|
const require = __cjs_mod__.createRequire(import.meta.url);
|
|
9
|
-
var
|
|
10
|
-
`)=>({name:"packem:shebang",renderChunk:{handler(o,n,r){if(!n.isEntry||!n.facadeModuleId||o.startsWith("#")&&o[1]==="!")return null;if(e.includes(n.name)){const s=new
|
|
11
|
-
`)=>{const o=ee.exec(e);return o?o+t:""},"getShebang");var
|
|
12
|
-
`));let a=[];try{a=await
|
|
9
|
+
var Ut=Object.defineProperty,L=m((e,t)=>Ut(e,"name",{value:t,configurable:!0}),"i$9");const ee=/^#![^\n]*/,q=L(async e=>{await nt(e,493).catch(()=>{})},"makeExecutable"),Ht=L((e,t=`#!/usr/bin/env node
|
|
10
|
+
`)=>({name:"packem:shebang",renderChunk:{handler(o,n,r){if(!n.isEntry||!n.facadeModuleId||o.startsWith("#")&&o[1]==="!")return null;if(e.includes(n.name)){const s=new S(o);return s.prepend(t),{code:s.toString(),map:r.sourcemap?s.generateMap({hires:!0}):void 0}}return null},order:"post"},async writeBundle(o,n){for(const[r,s]of Object.entries(n))if(s.type==="chunk"&&ee.test(s.code)&&o.dir){const i=f(o.dir,r);await q(i)}}}),"shebangPlugin"),qt=L(()=>({name:"packem:remove-shebang",renderChunk(e){return e.replace(ee,"")}}),"removeShebangPlugin"),Vt=L((e,t=`
|
|
11
|
+
`)=>{const o=ee.exec(e);return o?o+t:""},"getShebang");var Gt=Object.defineProperty,Xt=m((e,t)=>Gt(e,"name",{value:t,configurable:!0}),"p$1");const te=Xt((e,t)=>{let o={};if(e.pkg.name&&(o[e.pkg.name]=e.options.rootDir),e.pkg.imports){const{imports:n}=e.pkg;for(const r in n){if(r.startsWith("#"))continue;const s=n[r];typeof s=="string"&&(o[r]=O(e.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(n=>[n.find,n.replacement]))):Object.assign(o,e.options.rollup.alias.entries||e.options.rollup.alias)),e.logger.debug({message:"Resolved aliases: "+JSON.stringify(o),prefix:t}),o},"resolveAliases");var Yt=Object.defineProperty,Kt=m((e,t)=>Yt(e,"name",{value:t,configurable:!0}),"o$3");const Qt=Kt((e,t)=>{const o=ke(t,{esmResolve:!0,interopDefault:!0});try{return o.resolve(e)}catch(n){if(n.code!=="MODULE_NOT_FOUND")throw new Error(`Error trying import ${e} from ${t}`,{cause:n});return e}},"tryResolve");var Zt=Object.defineProperty,eo=m((e,t)=>Zt(e,"name",{value:t,configurable:!0}),"r$7");const F=eo((e,t)=>{e.warnings.has(t)||e.warnings.add(t)},"warn");var to=Object.defineProperty,oo=m((e,t)=>to(e,"name",{value:t,configurable:!0}),"u$8");const ro=oo(async e=>{const t=await Pt("jiti",{url:import.meta.url}),o=JSON.stringify({...e.options.stubOptions.jiti,alias:{...te(e,"jit"),...e.options.stubOptions.jiti.alias}},null,2);for(const n of e.options.entries){const r=f(e.options.rootDir,e.options.outDir,n.name),s=B(Qt(n.input,e.options.rootDir)||n.input),i=s.slice(0,Math.max(0,s.length-Y(s).length)),l=await X(s),c=Vt(l);e.options.emitCJS&&await T(`${r}.cjs`,c+[`const jiti = require(${JSON.stringify(t)})`,"",`const _jiti = jiti(null, ${o})`,"",`/** @type {import(${JSON.stringify(i)})} */`,`module.exports = _jiti(${JSON.stringify(s)})`].join(`
|
|
12
|
+
`));let a=[];try{a=await Mt(s,{extensions:I})}catch(p){F(e,`Cannot analyze ${s} for exports:${p}`);return}const u=a.includes("default")||a.length===0;await T(`${r}.mjs`,c+[`import jiti from ${JSON.stringify(_t(t).href)};`,"",`const _jiti = jiti(null, ${o})`,"",`/** @type {import(${JSON.stringify(s)})} */`,`const _module = await _jiti.import(${JSON.stringify(s)});`,u?`
|
|
13
13
|
export default _module;`:"",...a.filter(p=>p!=="default").map(p=>`export const ${p} = _module.${p};`)].join(`
|
|
14
14
|
`)),await T(`${r}.d.cts`,[`export * from ${JSON.stringify(i)};`,u?`export { default } from ${JSON.stringify(i)};`:""].join(`
|
|
15
15
|
`)),await T(`${r}.d.mts`,[`export * from ${JSON.stringify(s)};`,u?`export { default } from ${JSON.stringify(s)};`:""].join(`
|
|
16
|
-
`)),c&&(await q(`${r}.cjs`),await q(`${r}.mjs`))}await e.hooks.callHook("rollup:done",e)},"createStub");var
|
|
17
|
-
module.exports.default = `+i[2]+";");let c=l.toString();return c=c.replace(/(?:module\.)?exports(?:\['default'\]|\.default)/i,"module.exports"),t.debug({message:"Applied CommonJS interop to entry chunk "+r.fileName+".",prefix:"cjs-interop"}),{code:c,map:l.generateMap({hires:!0})}}if(s.format==="es"&&/\.d\.(?:ts|cts)$/.test(r.fileName)){if(o!=="commonjs"&&r.fileName.endsWith(".d.ts"))return null;const i=/export\s\{\s(.*)\s\}/i.exec(n);if(i===null||i.length<2)return null;const l=i[1].split(", "),c=[];let a;for(const p of l)if(!p.includes("type"))if(p.includes("as")){const[d,
|
|
16
|
+
`)),c&&(await q(`${r}.cjs`),await q(`${r}.mjs`))}await e.hooks.callHook("rollup:done",e)},"createStub");var no=Object.defineProperty,so=m((e,t)=>no(e,"name",{value:t,configurable:!0}),"a$b");const V=so((e,t)=>e.some(o=>o instanceof RegExp?o.test(t):o===t),"arrayIncludes");var io=Object.defineProperty,ao=m((e,t)=>io(e,"name",{value:t,configurable:!0}),"a$a");const z=ao(e=>e===void 0?[]:Array.isArray(e)?e:[e],"arrayify");var lo=Object.defineProperty,po=m((e,t)=>lo(e,"name",{value:t,configurable:!0}),"e$2");const G=po((e="")=>{const t=e.split("/");return t[0][0]==="@"?`${t[0]}/${t[1]}`:t[0]},"getPackageName");var co=Object.defineProperty,_e=m((e,t)=>co(e,"name",{value:t,configurable:!0}),"s$c");const uo=_e((e,t,o)=>{const n=o??new Map;return(...r)=>{const s=t?typeof t=="function"?t(...r):t:JSON.stringify({args:r}),i=n.get(s);if(i!==void 0)return i;const l=e(...r);return n.set(s,l),l}},"memoize"),mo=_e(e=>{const t=new Map;return o=>uo(e,o,t)},"memoizeByKey");var fo=Object.defineProperty,go=m((e,t)=>fo(e,"name",{value:t,configurable:!0}),"m$5");const Ne=go(({addDefaultProperty:e=!1,logger:t,type:o})=>({name:"packem:cjs-interop",renderChunk(n,r,s){if(r.type!=="chunk"||!r.isEntry)return null;if(s.format==="cjs"&&s.exports==="auto"){const i=/(exports(?:\['default'\]|\.default)) = (.*);/i.exec(n);if(i===null||i.length<3)return null;const l=new S(n);l.replace("Object.defineProperty(exports, '__esModule', { value: true });",""),l.replaceAll(/exports\.(.*) = (.*);/g,"module.exports.$1 = $2;"),e&&l.append(`
|
|
17
|
+
module.exports.default = `+i[2]+";");let c=l.toString();return c=c.replace(/(?:module\.)?exports(?:\['default'\]|\.default)/i,"module.exports"),t.debug({message:"Applied CommonJS interop to entry chunk "+r.fileName+".",prefix:"cjs-interop"}),{code:c,map:l.generateMap({hires:!0})}}if(s.format==="es"&&/\.d\.(?:ts|cts)$/.test(r.fileName)){if(o!=="commonjs"&&r.fileName.endsWith(".d.ts"))return null;const i=/export\s\{\s(.*)\s\}/i.exec(n);if(i===null||i.length<2)return null;const l=i[1].split(", "),c=[];let a;for(const p of l)if(!p.includes("type"))if(p.includes("as")){const[d,h]=p.split(" as ");if(h==="default"&&(a=d,!e))continue;c.push(h+": typeof "+d+";")}else c.push(p+": typeof "+p+";");const u=new S(n);return u.replace(" "+a+" as default,",""),u.append(`
|
|
18
18
|
|
|
19
19
|
declare const defaultExport: {
|
|
20
20
|
`+(c.length>0?" ":"")+c.join(`
|
|
21
21
|
`)+`
|
|
22
22
|
} & typeof `+a+`;
|
|
23
23
|
|
|
24
|
-
export default defaultExport;`),t.debug({message:"Applied CommonJS interop to entry chunk "+r.fileName+".",prefix:"cjs-interop"}),{code:u.toString(),map:u.generateMap({hires:!0})}}return null}}),"cjsInterop");var
|
|
24
|
+
export default defaultExport;`),t.debug({message:"Applied CommonJS interop to entry chunk "+r.fileName+".",prefix:"cjs-interop"}),{code:u.toString(),map:u.generateMap({hires:!0})}}return null}}),"cjsInterop");var ho=Object.defineProperty,yo=m((e,t)=>ho(e,"name",{value:t,configurable:!0}),"u$6");const vo=yo((e,t)=>{const o=new Map,n={copyOnce:!0,exactFileNames:!0,flatten:!1,...e};let{targets:r}=n;return Array.isArray(r)?r=r.map(s=>{if(typeof s=="string")return{src:s};if(typeof s=="object"&&"src"in s)return s}).filter(Boolean):typeof r=="string"&&(r=[{src:r}]),{async buildStart(){const s=await Promise.all(r.flatMap(i=>Array.isArray(i.src)?i.src.map(l=>({...i,src:l})):i).map(async i=>await At(i.src,{ignore:i.exclude}).then(l=>({dest:i.dest??"",parent:Wt(i.src),src:l}))));for(const i of s)for(const l of i.src){let c;o.has(l)?c=o.get(l):(c={copied:[],dest:[],timestamp:0},o.set(l,c));const a=n.flatten?B(i.dest):O(i.dest,D(i.parent,K(l)));c.dest.includes(a)||c.dest.push(a),this.addWatchFile(l)}t.info({message:"Copying files...",prefix:"copy"}),await Promise.all([...o].map(async([i,l])=>{let c;try{const a=await $e(i);if(!a.isFile())return;const u=a.mtime.getTime();u>l.timestamp&&(l.timestamp=u,l.copied=[]),c=await X(i,{buffer:!0})}catch(a){t.error({context:[a],message:`error reading file ${i}`,prefix:"copy"});return}for(const a of l.dest){if(n.copyOnce&&l.copied.includes(a))continue;const u=J(i),p=O(a,u);try{this.emitFile({[n.exactFileNames?"fileName":"name"]:p,source:c,type:"asset"}),t.debug({message:`copied ${i} → ${p}`,prefix:"copy"}),l.copied.push(a)}catch(d){t.error({context:[d],message:`error copying file ${i} → ${p}`,prefix:"copy"})}}}))},name:"packem:copy"}},"copyPlugin");var bo=Object.defineProperty,$o=m((e,t)=>bo(e,"name",{value:t,configurable:!0}),"n$8");const ce="export default ",Pe=$o(e=>{const t=Bt(e);return{...t,name:"packem:json",transform(o,n){const r=t.transform?.call(this,o,n);return r&&typeof r!="string"&&"code"in r&&r.code?.startsWith(ce)&&(r.code=r.code.replace(ce,"module.exports = ")),r}}},"JSONPlugin");class jo{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,n,r){t&&o&&(n!=null?t[o][n]=r:t[o]=r)}remove(t,o,n){t&&o&&(n!=null?t[o].splice(n,1):delete t[o])}}class wo extends jo{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(n=>this.replacement=n,"replace")},this.enter=t,this.leave=o}visit(t,o,n,r){if(t){if(this.enter){const i=this.should_skip,l=this.should_remove,c=this.replacement;this.should_skip=!1,this.should_remove=!1,this.replacement=null,this.enter.call(this.context,t,o,n,r),this.replacement&&(t=this.replacement,this.replace(o,n,r,t)),this.should_remove&&this.remove(o,n,r);const a=this.should_skip,u=this.should_remove;if(this.should_skip=i,this.should_remove=l,this.replacement=c,a)return t;if(u)return null}let s;for(s in t){const i=t[s];if(i&&typeof i=="object")if(Array.isArray(i)){const l=i;for(let c=0;c<l.length;c+=1){const a=l[c];ue(a)&&(this.visit(a,t,s,c)||c--)}}else ue(i)&&this.visit(i,t,s,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,n,r),this.replacement&&(t=this.replacement,this.replace(o,n,r,t)),this.should_remove&&this.remove(o,n,r);const c=this.should_remove;if(this.replacement=i,this.should_remove=l,c)return null}}return t}}function ue(e){return e!==null&&typeof e=="object"&&"type"in e&&typeof e.type=="string"}m(ue,"isNode");function Me(e,{enter:t,leave:o}){return new wo(t,o).visit(e,null)}m(Me,"walk");var ko=Object.defineProperty,xo=m((e,t)=>ko(e,"name",{value:t,configurable:!0}),"u$5");const Eo=xo(({attributes:e,logger:t})=>{const o=Q([/\.[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(n,r){if(!o(r))return null;let s=null;try{s=this.parse(n,{allowReturnOutsideFunction:!0})}catch(c){return this.warn({code:"PARSE_ERROR",message:`[packem:jsx-remove-attributes]: failed to parse "${r}" and remove the jsx attribute.`}),t.warn(c),null}let i=!1;const l=new S(n);return Me(s,{enter(c){if(c.type==="CallExpression"&&c.callee.type==="Identifier"&&c.callee.name==="jsx"){const a=c.arguments.filter(u=>u.type==="ObjectExpression"&&Array.isArray(u.properties));for(const u of a)for(const p of u.properties)p.type==="Property"&&p.key.type==="Literal"&&p.value.type==="Literal"&&e.includes(p.key.value)&&(l.overwrite(p.start-2,p.end,""),i=!0)}}}),i?{code:l.toString(),map:l.generateMap({hires:!0})}:null}}},"jsxRemoveAttributes");var Oo=Object.defineProperty,oe=m((e,t)=>Oo(e,"name",{value:t,configurable:!0}),"p");const So=oe(e=>{const t=[],o=[];return e.forEach(n=>{n.startsWith("(")?t.push(n):o.push(n)}),[...o.sort(),...t.sort()]},"sortLicenses"),Do=oe((e,t,o)=>{const n=new RegExp(`(<!-- ${t} -->)[\\s\\S]*?(<!-- ${t} -->)`,"g");if(n.test(e))return e.replace(n,`$1
|
|
25
25
|
${o}
|
|
26
|
-
$2`)},"replaceContentWithin"),
|
|
27
|
-
`;d&&(
|
|
28
|
-
`);const
|
|
29
|
-
`),
|
|
30
|
-
`),
|
|
31
|
-
`+
|
|
26
|
+
$2`)},"replaceContentWithin"),Ce=oe(({licenseFilePath:e,licenseTemplate:t,logger:o,marker:n,mode:r,packageName:s})=>Jt({thirdParty(i){const l=new Set,c=i.sort(({name:u},{name:p})=>u>p?1:p>u?-1:0).map(({author:u,contributors:p,license:d,licenseText:h,maintainers:g,name:b,repository:y})=>{let k=`## ${b}
|
|
27
|
+
`;d&&(k+=`License: ${d}
|
|
28
|
+
`);const _=new Set;for(const j of[u,...g,...p]){const se=typeof j=="string"?j:j?.name;se&&_.add(se)}return _.size>0&&(k+=`By: ${[..._].join(", ")}
|
|
29
|
+
`),y&&(k+=`Repository: ${typeof y=="string"?y:y.url}
|
|
30
|
+
`),h&&(k+=`
|
|
31
|
+
`+h.trim().replaceAll(/(\r\n|\r)/g,`
|
|
32
32
|
`).split(`
|
|
33
|
-
`).map(
|
|
33
|
+
`).map(j=>`> ${j}`).join(`
|
|
34
34
|
`)+`
|
|
35
|
-
`),d&&l.add(d),
|
|
35
|
+
`),d&&l.add(d),k}).join(`
|
|
36
36
|
---------------------------------------
|
|
37
37
|
|
|
38
|
-
`),a=t(
|
|
38
|
+
`),a=t(So(l),c,s);try{const u=ct(e),p=Do(u,n,a);if(!p){o.error(`Could not find the license marker: <!-- ${n} --> in ${e}`);return}u!==p&&(ut(e,p),o.info({message:`${e} updated.`,prefix:`license:${r}`}))}catch(u){o.error(u)}}}),"license");var _o=Object.defineProperty,No=m((e,t)=>_o(e,"name",{value:t,configurable:!0}),"i$6");const Po=No(e=>({async buildEnd(){const t=[];for(const n of this.getModuleIds()){const r=this.getModuleInfo(n);if(r!=null&&!r.isExternal)for(const s of r.importedIds)t.push({source:n,target:s})}if(Array.isArray(t)&&t.length===0)return;const o=f(e.outDir,"graph.json");mt(o,t)},name:"packem:metafile"}),"metafilePlugin");var Mo=Object.defineProperty,Co=m((e,t)=>Mo(e,"name",{value:t,configurable:!0}),"c$4");const Io=/\.(?:m|c)?(?:j|t)sx?$/,Ro=/^use \w+$/,Fo=Co(e=>{const t={},o={};return{name:"packem:preserve-directives",onLog(n,r){return r.code==="MODULE_LEVEL_DIRECTIVE"&&n==="warn"?!1:null},renderChunk:{handler(n,r,{sourcemap:s}){const i=r.moduleIds.map(a=>t[a]?t[a]:null).reduce((a,u)=>(u&&u.forEach(p=>{a.add(p)}),a),new Set),l=new S(n);i.size>0&&(e.debug({message:`directives for chunk "${r.fileName}" are preserved.`,prefix:"preserve-directives"}),l.prepend(`${[...i].map(a=>`'${a}';`).join(`
|
|
39
39
|
`)}
|
|
40
40
|
`));let c=null;return r.facadeModuleId&&typeof o[r.facadeModuleId]=="string"&&(c=o[r.facadeModuleId]),c&&(e.debug({message:`shebang for chunk "${r.fileName}" is preserved.`,prefix:"preserve-directives"}),l.prepend(`${c}
|
|
41
|
-
`)),i.size===0&&c===null?null:{code:l.toString(),map:s?l.generateMap({hires:!0}):null}},order:"post"},transform:{handler(n,r){const s=Y(r);if(!
|
|
41
|
+
`)),i.size===0&&c===null?null:{code:l.toString(),map:s?l.generateMap({hires:!0}):null}},order:"post"},transform:{handler(n,r){const s=Y(r);if(!Io.test(s))return null;let i=!1;const l=new S(n);if(n.startsWith("#")&&n[1]==="!"){let a=0;for(let u=2,p=n.length;u<p;u++){const d=n.codePointAt(u);if(d===10||d===13||d===8232||d===8233){a=u;break}}a&&(o[r]=n.slice(0,a),l.remove(0,a+1),i=!0,e.debug({message:`shebang for module "${r}" is preserved.`,prefix:"preserve-directives"}))}let c=null;try{c=this.parse(l.toString(),{allowReturnOutsideFunction:!0})}catch(a){return this.warn({code:"PARSE_ERROR",message:`[packem:preserve-directives]: failed to parse "${r}" and extract the directives.`}),e.warn(a),null}if(c.type!=="Program")return null;for(const a of c.body.filter(Boolean)){if(a.type!=="ExpressionStatement")break;let u=null;"directive"in a?u=a.directive:a.expression.type==="Literal"&&typeof a.expression.value=="string"&&Ro.test(a.expression.value)&&(u=a.expression.value),u!=="use strict"&&u&&(t[r]||=new Set,t[r].add(u),"start"in a&&typeof a.start=="number"&&"end"in a&&typeof a.end=="number"&&(l.remove(a.start,a.end),i=!0),e.debug({message:`directive "${u}" for module "${r}" is preserved.`,prefix:"preserve-directives"}))}return i?{code:l.toString(),map:l.generateMap({hires:!0}),meta:{preserveDirectives:{directives:[...t[r]??[]],shebang:o[r]??null}}}:null},order:"post"}}},"preserveDirectives");var To=Object.defineProperty,Ao=m((e,t)=>To(e,"name",{value:t,configurable:!0}),"r$5");const Wo={exclude:[],include:[/\.(md|txt|css|htm|html)$/]},Bo=Ao((e={})=>{e={...e,...Wo};const t=Q(e.include,e.exclude);return{name:"packem:raw",transform(o,n){return t(n)?{code:`export default ${JSON.stringify(o)}`,map:null}:null}}},"rawPlugin");var Jo=Object.defineProperty,Lo=m((e,t)=>Jo(e,"name",{value:t,configurable:!0}),"l$5");const U="\0__file_url__",Ie=Lo(()=>({async load(e){if(e.startsWith(U)){const t=Nt(e.slice(U.length));return await X(t)}},name:"packem:resolve-file-url",resolveId(e){if(e.startsWith("file://"))return`${U}${e}`}}),"resolveFileUrl");var zo=Object.defineProperty,Re=m((e,t)=>zo(e,"name",{value:t,configurable:!0}),"i$3");const Uo=/__filename|__dirname|require\(|require\.resolve\(/,Fe=`
|
|
42
42
|
// -- pack CommonJS Shims --
|
|
43
43
|
import __cjs_url__ from "node:url";
|
|
44
44
|
import __cjs_path__ from "node:path";
|
|
@@ -46,55 +46,55 @@ import __cjs_mod__ from "node:module";
|
|
|
46
46
|
const __filename = __cjs_url__.fileURLToPath(import.meta.url);
|
|
47
47
|
const __dirname = __cjs_path__.dirname(__filename);
|
|
48
48
|
const require = __cjs_mod__.createRequire(import.meta.url);
|
|
49
|
-
`,
|
|
49
|
+
`,Te=`
|
|
50
50
|
// -- pack CommonJS Shims Node 20.11 --
|
|
51
51
|
import __cjs_mod__ from "node:module";
|
|
52
52
|
const __filename = import.meta.filename;
|
|
53
53
|
const __dirname = import.meta.dirname;
|
|
54
54
|
const require = __cjs_mod__.createRequire(import.meta.url);
|
|
55
|
-
`,
|
|
55
|
+
`,Ho=Re((e,t)=>{if(R.INTERNAL_PACKEM_BUILD!=="1"&&(e.includes(Fe)||e.includes(Te)||!Uo.test(e)))return null;const o=we(e).pop(),n=o?o.end:0,r=new S(e);return r.appendRight(n,t),{code:r.toString(),map:r.generateMap()}},"CJSToESM"),qo=Re(e=>({name:"packem:cjs",renderChunk(t,o,n){if(n.format==="es"){let r=Fe;if(e.engines?.node){const s=De(e.engines.node);s&&s.major>=20&&s.minor>=11&&(r=Te)}return Ho(t,r)}return null}}),"cjsPlugin");var Vo=Object.defineProperty,M=m((e,t)=>Vo(e,"name",{value:t,configurable:!0}),"s$9");const Go=/\/\*[^*]*\*+(?:[^/*][^*]*\*+)*\//g,Xo=/MIT License|MIT license|BSD license/,Yo=/\n{2,}/g,Ko=/\b(\w+)\$\d+\b/g,Qo=/[-/\\^$*+?.()|[\]{}]/g,Zo=M(e=>e.replaceAll(Qo,"\\$&"),"escapeRegex"),er=M(e=>[...new Set(e)],"unique"),tr=M(e=>e.replaceAll(Go,t=>Xo.test(t)?"":t).replaceAll(Yo,`
|
|
56
56
|
|
|
57
|
-
`),"cleanUnnecessaryComments"),me=new Map;function
|
|
57
|
+
`),"cleanUnnecessaryComments"),me=new Map;function Ae(e,t,{identifierReplacements:o},n){const r=we(e);for(const i in o){const l=r.find(a=>a.specifier===i&&a.imports.includes("{"));if(!l){this.warn(`${t.fileName} does not import "${i}" for replacement`),process.exitCode=1;continue}const c=o[i];for(const a in c){l.imports.includes(a)||(this.warn(`${t.fileName} does not import "${a}" from "${i}" for replacement`),C(1));const u=c[a],p=Zo(a);u.includes(".")&&(e=e.replace(new RegExp(`\\b\\w+\\b as ${p},?\\s?`),"")),e=e.replaceAll(new RegExp(`\\b${p}\\b`,"g"),u)}}const s=er(Array.from(e.matchAll(Ko),i=>i[0]));if(s.length>0){const i=s.map(c=>`
|
|
58
58
|
- ${c}`).join(""),l=t.fileName.replace(/\.[^/.]+$/,"");me.has(l)||n.warn({message:`${t.fileName} contains confusing identifier names${i}
|
|
59
59
|
|
|
60
|
-
To replace these, add them to the "patchTypes -> identifierReplacements" option in your packem config.`,prefix:"patch-types"}),me.set(l,!0)}return e}m(
|
|
60
|
+
To replace these, add them to the "patchTypes -> identifierReplacements" option in your packem config.`,prefix:"patch-types"}),me.set(l,!0)}return e}m(Ae,"v$2");M(Ae,"replaceConfusingTypeNames");function We(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}m(We,"N");M(We,"removeInternal");function Be(e,t){if(e.includes("@internal")){const o=new S(e),n=Lt(e,{plugins:["typescript"],sourceType:"module"});Me(n,{enter(r){We(o,r)&&this.skip()}}),e=o.toString(),e.includes("@internal")&&(this.warn(`${t.fileName} has unhandled @internal declarations`),C(1))}return e}m(Be,"S");M(Be,"stripInternalTypes");const or=M((e,t)=>({name:"packem:patch-types",renderChunk(o,n){return o=Ae.call(this,o,n,e,t),o=Be.call(this,o,n),o=tr(o),o},resolveId(o){return o.startsWith("types/")?{external:!0,id:"../../"+(o.endsWith(".js")?o:o+".js")}:null}}),"patchTypescriptTypes");var rr=Object.defineProperty,Je=m((e,t)=>rr(e,"name",{value:t,configurable:!0}),"u$3");const Le=Je((e,t=!0)=>{if(!e)return null;const{config:o,path:n}=e;if(!o.compilerOptions)return null;const{baseUrl:r,paths:s}=o.compilerOptions;if(!r)return null;const i=f(K(n),r),l=[];if(s)for(const[c,a]of Object.entries(s)){const u=new RegExp(`^${[...c].map(d=>d==="*"?"(.+)":d.replace(/[\\^$*+?.()|[\]{}]/,"\\$&")).join("")}$`);let p=0;for(const d of a){const h=[...pe(f(i,d))].map(g=>g==="*"?`$${++p}`:g==="$"?"$$":g).join("");l.push({find:u,replacement:h})}}return t&&l.push({find:/^(?!\.*\/|\.*$|\w:)(.+)$/,replacement:`${[...pe(i)].map(c=>c==="$"?"$$":c).join("")}/$1`}),l},"getConfigAlias"),ze=Je((e,t)=>{const o=Le(e);return{name:"packem:resolve-tsconfig-paths",async resolveId(n,r,s){if(!o||n.includes("\0"))return null;for(const{find:i,replacement:l}of o)if(i.test(n)){const c=n.replace(i,l),a=await this.resolve(c,r,{skipSelf:!0,...s});if(a)return t.debug({message:`Resolved ${n} to ${a.id} using paths from tsconfig.json.`,prefix:"resolve-tsconfig-paths"}),a.id}return null}}},"resolveTsconfigPaths");var nr=Object.defineProperty,Ue=m((e,t)=>nr(e,"name",{value:t,configurable:!0}),"u$2");const sr=Ue((e,t)=>{if(!t)return null;const{config:o,path:n}=t;if(!o.compilerOptions)return null;const{rootDirs:r}=o.compilerOptions;if(!r)return null;const s=[];for(const i of r){if(i.startsWith("."))throw new Error(`Invalid rootDir value '.' in ${n}.`);if(i.startsWith(".."))throw new Error(`Invalid rootDir value '..' in ${n}.`);s.push(f(e,i))}return s},"getRootDirectories"),He=Ue((e,t,o)=>{const n=sr(e,o);return{name:"packem:resolve-tsconfig-root-dirs",async resolveId(r,s,i){if(n===null||n.length===0)return null;if(r.startsWith("."))for(const l of n){const c=O(l,r),a=await this.resolve(c,s,{skipSelf:!0,...i});if(a)return t.debug({message:`Resolved ${r} to ${a.id} using rootDirs from tsconfig.json.`,prefix:"resolve-tsconfig-root-dirs"}),a.id}return null}}},"resolveTsconfigRootDirectories");var ir=Object.defineProperty,ar=m((e,t)=>ir(e,"name",{value:t,configurable:!0}),"r$4");const qe=ar(()=>{const e=/\.(?:[mc]?js|jsx)$/;return{name:"packem:resolve-typescript-mjs-cjs",async resolveId(t,o,n){return e.test(t)&&o?await this.resolve(t.replace(/js(x?)$/,"ts$1"),o,n):null}}},"resolveTypescriptMjsCts");var lr=Object.defineProperty,pr=m((e,t)=>lr(e,"name",{value:t,configurable:!0}),"s$8");const cr=pr(e=>{const t=J(e).split(".");if(t.length>=2){const[o,n]=t.slice(-2),r=t[0],s=/^(\w+)-runtime$/.exec(o)?.[1];if(I.includes(n)&&s&&s.length>0)return r+"-"+s}},"getCustomModuleLayer");var ur=Object.defineProperty,mr=m((e,t)=>ur(e,"name",{value:t,configurable:!0}),"i$2");const H=mr(e=>(e.preserveDirectives||{directives:[]}).directives.map(t=>t.replace(/^use /,"")).find(t=>t!=="strict"),"getModuleLayer");var dr=Object.defineProperty,de=m((e,t)=>dr(e,"name",{value:t,configurable:!0}),"c$2");const fe=de((e,t)=>{const o=new Map;return de(function(n,r){const s=r.getModuleInfo(n);if(!s)return;const{isEntry:i}=s,l=s.meta,c=H(l);if(!i){const a=o.get(n);if(a)return a;const u=cr(n);if(u)return o.set(n,u),u}if(i){const a=r.getModuleIds();for(const u of a)r.getModuleInfo(u)&&H(l)===c&&(e.has(u)||e.set(u,new Set),e.get(u).add([n,c]))}if(c&&!i&&e.has(n)){const a=[...e.get(n)];if(a.some(([p])=>{if(console.log(p),t.some(d=>d.path===p)){const d=r.getModuleInfo(p);return H(d?d.meta:{})===c}return!1}))return;if(a.every(([,p])=>p===c))return o.has(n)?o.get(n):void 0;const u=`${J(n,Y(n))}-${c}`;return o.set(n,u),u}},"splitChunks")},"createSplitChunks");var fr=Object.defineProperty,gr=m((e,t)=>fr(e,"name",{value:t,configurable:!0}),"n$6");const E=gr((e,t,o)=>t.isDynamicEntry?`chunks/[name].${o}`:`shared/${e.options.name}.[hash].${o}`,"getChunkFilename");var hr=Object.defineProperty,yr=m((e,t)=>hr(e,"name",{value:t,configurable:!0}),"s$6");const vr=process.platform==="win32",ge=yr((e,t)=>{const o=vr?"\\":"/";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 br=Object.defineProperty,$=m((e,t)=>br(e,"name",{value:t,configurable:!0}),"l$4");const $r=$((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"+it.node.split(".")[0];if(t.pkg.engines?.node){const n=De(t.pkg.engines.node);n&&(o="node"+n.major)}if(t.options.rollup.esbuild.target){const n=z(t.options.rollup.esbuild.target);n.some(r=>r.startsWith("node"))||(t.options.rollup.esbuild.target=[...new Set([...z(o),...n])])}else t.options.rollup.esbuild.target=z(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")),{minify:t.options.minify,sourceMap:t.options.sourcemap,...t.options.rollup.esbuild,logger:t.logger}}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"),Ve=$((e,t)=>e.code==="CIRCULAR_DEPENDENCY"&&/Circular dependency:[\s\S]*node_modules/.test(e.message)?!0:e.code==="UNRESOLVED_IMPORT"?(t.logger.error(`Failed to resolve the module "${e.exporter}" imported by "${v(D(f(),e.id))}"
|
|
61
61
|
Is the module installed? Note:
|
|
62
62
|
↳ to inline a module into your bundle, install it to "devDependencies".
|
|
63
|
-
↳ to depend on a module via import/require, install it to "dependencies".`),process.exitCode=1,!0):e.code==="MIXED_EXPORTS"&&t.options.cjsInterop===!0,"sharedOnWarn"),he=new Map,
|
|
64
|
-
└─ ${
|
|
65
|
-
- `+v(l)+(c.length>0?
|
|
63
|
+
↳ to depend on a module via import/require, install it to "dependencies".`),process.exitCode=1,!0):e.code==="MIXED_EXPORTS"&&t.options.cjsInterop===!0,"sharedOnWarn"),he=new Map,Ge=$((e,t)=>{const o=$(r=>{for(const[s,i]of Object.entries(t))if(r.startsWith(s))return r.replace(s,i)},"findAlias"),n=Le(e.tsconfig,!1);return{external(r){const s=o(r);s&&(r=s);const i=G(r),l=V(e.options.externals,i)||V(e.options.externals,r);if(l)return!0;if(r.startsWith(".")||je(r)||/src[/\\]/.test(r)||e.pkg.name&&r.startsWith(e.pkg.name))return!1;if(n){for(const{find:c}of n)if(c.test(r))return e.logger.debug(`Resolved alias ${r} to ${c.source}`),!1}return!l&&he.has(r)&&e.logger.info('Inlined implicit external "'+v(r)+'". If this is incorrect, add it to the "externals" option.'),he.set(r,!0),l},input:Object.fromEntries(e.options.entries.map(r=>[r.name,f(e.options.rootDir,r.input)])),onwarn(r,s){Ve(r,e)||r.code||s(r)},watch:e.mode==="watch"?e.options.rollup.watch:!1}},"baseRollupOptions"),Xe=$(async e=>{const t=te(e,"build");let o;return e.options.rollup.resolve&&(o=Oe({extensions:I,...e.options.rollup.resolve})),{...Ge(e,t),output:[e.options.emitCJS&&{chunkFileNames:$(n=>E(e,n,"cjs"),"chunkFileNames"),dir:f(e.options.rootDir,e.options.outDir),entryFileNames:$(n=>ge(n,"cjs"),"entryFileNames"),exports:"auto",externalLiveBindings:!1,format:"cjs",freeze:!1,generatedCode:{constBindings:!0},hoistTransitiveImports:!1,interop:"compat",sourcemap:e.options.sourcemap,...e.options.rollup.output,...e.options.rollup.output?.preserveModules?{preserveModules:!0,preserveModulesRoot:e.options.rollup.output.preserveModulesRoot??"src"}:{manualChunks:fe(e.dependencyGraphMap,e.buildEntries),preserveModules:!1}},e.options.emitESM&&{chunkFileNames:$(n=>E(e,n,"mjs"),"chunkFileNames"),dir:f(e.options.rootDir,e.options.outDir),entryFileNames:$(n=>ge(n,"mjs"),"entryFileNames"),exports:"auto",externalLiveBindings:!1,format:"esm",freeze:!1,generatedCode:{constBindings:!0},hoistTransitiveImports:!1,sourcemap:e.options.sourcemap,...e.options.rollup.output,...e.options.rollup.output?.preserveModules?{preserveModules:!0,preserveModulesRoot:e.options.rollup.output.preserveModulesRoot??"src"}:{manualChunks:fe(e.dependencyGraphMap,e.buildEntries),preserveModules:!1}}].filter(Boolean),plugins:[Ie(),qe(),e.tsconfig&&He(e.options.rootDir,e.logger,e.tsconfig),e.tsconfig&&ze(e.tsconfig,e.logger),e.options.rollup.replace&&Se({...e.options.rollup.replace,values:{...e.options.replace,...e.options.rollup.replace.values}}),e.options.rollup.alias&&Ee({customResolver:o?.resolveId,...e.options.rollup.alias,entries:t}),o,e.options.rollup.polyfillNode&&Ft({sourceMap:e.options.sourcemap,...e.options.rollup.polyfillNode}),e.options.rollup.json&&Pe({...e.options.rollup.json}),Fo(e.logger),Ht(e.options.entries.filter(n=>n.isExecutable).map(n=>n.name).filter(Boolean)),e.options.rollup.wsam&&Rt(e.options.rollup.wsam),e.options.transformer?.($r(e.options.transformerName,e)),e.options.cjsInterop&&e.options.emitCJS&&Ne({...e.options.rollup.cjsInterop,logger:e.logger,type:e.pkg.type??"commonjs"}),e.options.rollup.dynamicVars&&It(e.options.rollup.dynamicVars),e.options.rollup.commonjs&&Ct({extensions:I,sourceMap:e.options.sourcemap,...e.options.rollup.commonjs}),e.options.rollup.preserveDynamicImports&&{renderDynamicImport(){return{left:"import(",right:")"}}},e.options.rollup.shim&&qo(e.pkg),e.options.rollup.raw&&Bo(e.options.rollup.raw),e.options.rollup.jsxRemoveAttributes&&Eo({attributes:e.options.rollup.jsxRemoveAttributes.attributes,logger:e.logger}),e.options.rollup.metafile&&Po({outDir:f(e.options.rootDir,e.options.outDir),rootDir:e.options.rootDir}),e.options.rollup.copy&&vo(e.options.rollup.copy,e.logger),e.options.rollup.license&&e.options.rollup.license.path&&typeof e.options.rollup.license.template=="function"&&Ce({licenseFilePath:e.options.rollup.license.path,licenseTemplate:e.options.rollup.license.template,logger:e.logger,marker:e.options.rollup.license.marker??"DEPENDENCIES",mode:"dependencies",packageName:e.pkg.name}),e.options.rollup.visualizer&&Tt({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"),jr=$(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"),wr=mo(jr),Ye=$(async e=>{const t=te(e,"types"),o={load(i){return/\.(?:js|cjs|mjs|jsx|ts|tsx|mts|json)$/.test(i)?null:""},name:"packem:ignore-files"},n=e.tsconfig?.config.compilerOptions;delete n?.lib;let r;e.options.rollup.resolve&&(r=Oe({extensions:I,...e.options.rollup.resolve}));const s="dts-plugin:"+process.pid+e.tsconfig.path;return{...Ge(e,t),onwarn(i,l){Ve(i,e)||i.code!=="EMPTY_BUNDLE"&&l(i)},output:[e.options.emitCJS&&{chunkFileNames:$(i=>E(e,i,"d.cts"),"chunkFileNames"),dir:f(e.options.rootDir,e.options.outDir),entryFileNames:"[name].d.cts",format:"cjs",sourcemap:e.options.sourcemap,...e.options.rollup.output},{chunkFileNames:$(i=>E(e,i,"d.mts"),"chunkFileNames"),dir:f(e.options.rootDir,e.options.outDir),entryFileNames:"[name].d.mts",format:"esm",sourcemap:e.options.sourcemap,...e.options.rollup.output},(e.options.declaration===!0||e.options.declaration==="compatible")&&{chunkFileNames:$(i=>E(e,i,"d.ts"),"chunkFileNames"),dir:f(e.options.rootDir,e.options.outDir),entryFileNames:"[name].d.ts",format:"cjs",sourcemap:e.options.sourcemap,...e.options.rollup.output}].filter(Boolean),plugins:[Ie(),qe(),e.options.rollup.json&&Pe({...e.options.rollup.json}),o,e.tsconfig&&He(e.options.rootDir,e.logger,e.tsconfig),e.tsconfig&&ze(e.tsconfig,e.logger),e.options.rollup.replace&&Se({...e.options.rollup.replace,values:{...e.options.replace,...e.options.rollup.replace.values}}),e.options.rollup.alias&&Ee({customResolver:r?.resolveId,...e.options.rollup.alias,entries:t}),r,await wr(s)(e),e.options.cjsInterop&&e.options.emitCJS&&Ne({...e.options.rollup.cjsInterop,logger:e.logger,type:e.pkg.type??"commonjs"}),e.options.rollup.patchTypes&&or(e.options.rollup.patchTypes,e.logger),qt(),e.options.rollup.license&&e.options.rollup.license.path&&typeof e.options.rollup.license.dtsTemplate=="function"&&Ce({licenseFilePath:e.options.rollup.license.path,licenseTemplate:e.options.rollup.license.dtsTemplate,logger:e.logger,marker:e.options.rollup.license.marker??"TYPE_DEPENDENCIES",mode:"types",packageName:e.pkg.name})].filter(Boolean)}},"getRollupDtsOptions");var kr=Object.defineProperty,xr=m((e,t)=>kr(e,"name",{value:t,configurable:!0}),"a$3");const Er=xr(async e=>{const t=await Xe(e);if(await e.hooks.callHook("rollup:options",e,t),Object.keys(t.input).length===0)return;const o=await xe(t);await e.hooks.callHook("rollup:build",e,o);const n=t.output,r=new Map;for(const s of n){const{output:i}=await o.write(s),l=new Set,c=i.filter(u=>u.type==="chunk");for(const u of c){l.add(u.fileName);for(const p of u.imports)e.usedImports.add(p);u.isEntry&&e.buildEntries.push({bytes:Buffer.byteLength(u.code,"utf8"),chunks:u.imports.filter(p=>c.find(d=>d.fileName===p)),exports:u.exports,modules:Object.entries(u.modules).map(([p,d])=>({bytes:d.renderedLength,id:p})),path:u.fileName,type:"entry"})}const a=i.filter(u=>u.type==="asset");for(const u of a)r.has(u.fileName)||r.set(u.fileName,{bytes:Buffer.byteLength(u.source,"utf8"),path:u.fileName,type:"asset"});for(const u of l)e.usedImports.delete(u)}e.buildEntries.push(...r.values())},"build");var Or=Object.defineProperty,A=m((e,t)=>Or(e,"name",{value:t,configurable:!0}),"r$2");const Sr=A(async e=>{const t=await Ye(e);if(await e.hooks.callHook("rollup:dts:options",e,t),Object.keys(t.input).length===0)return;const o=await xe(t);await e.hooks.callHook("rollup:dts:build",e,o),e.logger.info({message:"Building declaration files...",prefix:"dts"}),e.options.emitCJS&&await o.write({chunkFileNames:A(n=>E(e,n,"d.cts"),"chunkFileNames"),dir:f(e.options.rootDir,e.options.outDir),entryFileNames:"[name].d.cts"}),e.options.emitESM&&await o.write({chunkFileNames:A(n=>E(e,n,"d.mts"),"chunkFileNames"),dir:f(e.options.rootDir,e.options.outDir),entryFileNames:"[name].d.mts"}),e.options.declaration===!0&&await o.write({chunkFileNames:A(n=>E(e,n,"d.ts"),"chunkFileNames"),dir:f(e.options.rootDir,e.options.outDir),entryFileNames:"[name].d.ts"}),await e.hooks.callHook("rollup:dts:done",e)},"buildTypes");var Dr=Object.defineProperty,Ke=m((e,t)=>Dr(e,"name",{value:t,configurable:!0}),"l$3");const ye=Ke((e,t,o)=>{const n="watcher:"+t;e.on("change",(r,{event:s})=>{o.info({message:`${v(D(".",r))} was ${s}d`,prefix:n})}),e.on("restart",()=>{o.info({message:"Rebuilding "+t+"...",prefix:n})}),e.on("event",r=>{r.code==="END"&&o.success({message:"Rebuild "+t+" finished",prefix:n}),r.code==="ERROR"&&o.error({context:[r.error],message:"Rebuild "+t+" failed: "+r.error.message,prefix:n})})},"watchHandler"),_r=Ke(async e=>{const t=await Xe(e);if(await e.hooks.callHook("rollup:options",e,t),Object.keys(t.input).length===0)return;const o=le(t);await e.hooks.callHook("rollup:watch",e,o);const n=[...Array.isArray(t.input)?t.input:typeof t.input=="string"?[t.input]:Object.keys(t.input??{})];let r="Starting watchers for entries:";for(const s of n)r+=P(`
|
|
64
|
+
└─ ${D(process.cwd(),s)}`);if(e.logger.info(r),ye(o,"bundle",e.logger),e.options.declaration){const s=await Ye(e);await e.hooks.callHook("rollup:dts:options",e,s);const i=le(s);await e.hooks.callHook("rollup:watch",e,i),ye(i,"types",e.logger)}},"watch");var Nr=Object.defineProperty,Pr=m((e,t)=>Nr(e,"name",{value:t,configurable:!0}),"i$1");const Qe=Pr(e=>`{ ${Object.keys(e).map(t=>`${t}: ${JSON.stringify(e[t])}`).join(", ")} }`,"dumpObject");var Mr=Object.defineProperty,W=m((e,t)=>Mr(e,"name",{value:t,configurable:!0}),"l$2");const Cr=Q,Ir=W((e,t)=>{const{sideEffects:o}=t;let n;if(typeof o=="boolean")n=W(()=>o,"hasSideEffects");else if(Array.isArray(o))if(o.length<=0)n=W(()=>!1,"hasSideEffects");else{const r=o.map(s=>s.includes("/")?s:`**/${s}`);n=Cr(r,null,{resolve:e})}else n=W(()=>null,"hasSideEffects");return n},"getPackageSideEffect");var Rr=Object.defineProperty,Fr=m((e,t)=>Rr(e,"name",{value:t,configurable:!0}),"t$4");const Tr=Fr(e=>e.replace(/\.(js|mjs|cjs|ts|mts|cts|json|jsx|tsx)$/,""),"removeExtension");var Ar=Object.defineProperty,Ze=m((e,t)=>Ar(e,"name",{value:t,configurable:!0}),"t$3");const re=Ze(e=>{if(e.endsWith(".mjs")||e.endsWith(".d.mts"))return"esm";if(e.endsWith(".cjs")||e.endsWith(".d.cts"))return"cjs"},"inferExportTypeFromFileName"),et=Ze((e,t,o,n)=>{if(o){const i=re(o);if(i)return i}if(e==="module"||e==="import")return"esm";if(e==="require")return"cjs";if(t.length===0)return n==="commonjs"?"cjs":"esm";const[r,...s]=t;return et(r,s,o,n)},"inferExportType");var Wr=Object.defineProperty,Br=m((e,t)=>Wr(e,"name",{value:t,configurable:!0}),"f$3");const ne=Br((e,t,o,n=[])=>{if(!e)return[];if(typeof e=="string"){const r=re(e),s=t==="module"?"esm":"cjs";if(r&&r!==s)throw new Error(`Exported file "${e}" has an extension that does not match the package.json type "${t}".`);return[{file:e,type:r??s}]}return Object.entries(e).filter(([r])=>!r.endsWith(".json")).flatMap(([r,s])=>r==="types"&&!o?[]:typeof s=="string"?{file:s,type:et(r,n,s,t)}:ne(s,t,o,[...n,r]))},"extractExportFilenames");var Jr=Object.defineProperty,Lr=m((e,t)=>Jr(e,"name",{value:t,configurable:!0}),"e");const zr=Lr(e=>{const t=B(e).split("/");return t.map((o,n)=>t.slice(n).join("/")).filter(Boolean)},"getEntrypointPaths");var Ur=Object.defineProperty,Hr=m((e,t)=>Ur(e,"name",{value:t,configurable:!0}),"h$1");const qr=Hr((e,t,o,n=".")=>{const r=[];t.sort((p,d)=>p.split("/").length-d.split("/").length);const s=ne(e.exports,e.type??"commonjs",o);if(e.bin){const p=typeof e.bin=="string"?[e.bin]:Object.values(e.bin);for(const d of p)s.push({file:d,isExecutable:!0})}e.main&&s.push({file:e.main,type:re(e.main)??(e.type==="module"?"esm":"cjs")}),e.module&&s.push({file:e.module,type:"esm"}),o===void 0&&(e.types||e.typings)&&s.push({file:e.types??e.typings});const i=e.type==="module";for(const p of s.filter(d=>!d.type)){const d=p.file.endsWith(".js");i&&d||p.file.endsWith(".mjs")?p.type="esm":(!i&&d||p.file.endsWith(".cjs"))&&(p.type="cjs")}let l=!1,c=!1,a=!1;const u=[];for(const p of s){const d=p.file.replace(/(?:\*[^/\\]*|\.d\.(?:m|c)?ts|\.\w+)$/,""),h=d.endsWith("/");if(h&&["./","/"].includes(d))continue;const g=zr(d).reduce((y,k)=>{if(y)return y;const _=new RegExp(`(?<=/|$)${k}${h?"":"\\.\\w+"}$`);return t.find(j=>_.test(j))?.replace(/(?:\.d\.(?:m|c)?ts|\.\w+)$/,"")},void 0);if(!g){Z(f(n,p.file))||r.push(`Could not find entrypoint for \`${p.file}\``);continue}p.type==="cjs"&&(l=!0),p.type==="esm"&&(c=!0);const b=u.find(y=>y.input===g)??u[u.push({input:g})-1];/\.d\.(?:m|c)?ts$/.test(p.file)&&(a=!0),h&&(b.outDir=d),p.isExecutable&&(b.isExecutable=!0)}return{cjs:l,dts:a,entries:u,esm:c,warnings:r}},"inferEntries");var Vr=Object.defineProperty,Gr=m((e,t)=>Vr(e,"name",{value:t,configurable:!0}),"t$2");const Xr=Gr((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 Yr=Object.defineProperty,Kr=m((e,t)=>Yr(e,"name",{value:t,configurable:!0}),"t$1");const Qr={hooks:{"build:prepare":Kr(function(e){if(e.options.entries.length>0)return;const t=O(e.options.rootDir,"src");if(!Z(t))throw new Error("No 'src' directory found. Please provide entries manually.");const o=dt(t,{extensions:[],includeDirs:!1,includeSymlinks:!1});if(o.length===0)throw new Error("No source files found in 'src' directory. Please provide entries manually.");let n={...e.pkg};n.publishConfig&&(n=Xr(n,e.options.declaration));const r=qr(n,o,e.options.declaration,e.options.rootDir);for(const s of r.warnings)F(e,s);if(e.options.entries.push(...r.entries),e.options.emitCJS===void 0&&r.cjs&&(e.options.emitCJS=!0),e.options.emitESM===void 0&&r.esm&&(e.options.emitESM=!0),e.options.declaration===void 0&&r.dts&&(e.options.declaration=r.dts),e.options.entries.length===0)throw new Error("No entries detected. Please provide entries manually.");e.logger.info("Automatically detected entries:",v(e.options.entries.map(s=>x(s.input.replace(`${e.options.rootDir}/`,"").replace(/\/$/,"/*"))).join(", ")),P([r.esm&&"esm",r.cjs&&"cjs",r.dts&&"dts"].filter(Boolean).map(s=>`[${s}]`).join(" ")))},"build:prepare")}};var Zr=Object.defineProperty,en=m((e,t)=>Zr(e,"name",{value:t,configurable:!0}),"n$2");const tt=en((e,t,o)=>{const n=ke(t,{esmResolve:!0,interopDefault:!0});try{return n(e)}catch(r){if(r.code!=="MODULE_NOT_FOUND")throw new Error(`Error trying import ${e} from ${t}`,{cause:r});return o}},"tryRequire");var tn=Object.defineProperty,on=m((e,t)=>tn(e,"name",{value:t,configurable:!0}),"t");const rn=on((e,t)=>(e==="auto"?e=Qr:typeof e=="string"&&(e=tt(e,t,{})),typeof e=="function"&&(e=e()),e),"resolvePreset");var nn=Object.defineProperty,sn=m((e,t)=>nn(e,"name",{value:t,configurable:!0}),"o");const an=sn(e=>{const t=new Set,o=new Set(Object.keys(e.pkg.dependencies??{})),n=new Set;for(const r of e.usedImports)o.delete(r),t.add(r);if(Array.isArray(e.options.dependencies))for(const r of e.options.dependencies)o.delete(r);for(const r of t)!V(e.options.externals,r)&&!r.startsWith("chunks/")&&!e.options.dependencies.includes(G(r))&&!e.options.peerDependencies.includes(G(r))&&n.add(r);o.size>0&&F(e,`Potential unused dependencies found: ${[...o].map(r=>v(r)).join(", ")}`),n.size>0&&F(e,`Potential implicit dependencies found: ${[...n].map(r=>v(r)).join(", ")}`)},"validateDependencies");var ln=Object.defineProperty,ot=m((e,t)=>ln(e,"name",{value:t,configurable:!0}),"i");const pn=ot((e,t)=>zt(e,t)<=e.length/3||t.includes(e),"isSimilar"),cn=ot((e,t)=>{const o=e.toLowerCase();return t.filter(n=>pn(n.toLowerCase(),o))},"findAlternatives");var un=Object.defineProperty,ve=m((e,t)=>un(e,"name",{value:t,configurable:!0}),"n");const mn=ve((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:"",...ne(e.exports,e.type??"commonjs",t.options.declaration).map(r=>r.file)].map(r=>r&&f(t.rootDir,r.replace(/\/[^*/]*\*[^\n\r/\u2028\u2029]*(?:[\n\r\u2028\u2029][^*/]*\*[^\n\r/\u2028\u2029]*)*(?:\/.*)?$/,"")))),n=[];for(const r of o)r&&!r.includes("*")&&!Z(r)&&n.push(r.replace(`${t.rootDir}/`,""));if(n.length>0){const r=ve(l=>D(t.rootDir,f(t.options.outDir,l)),"rPath"),s=t.buildEntries.filter(l=>!l.chunk).map(l=>r(l.path));let i="Potential missing or wrong package.json files:";for(const l of n){const c=cn(l,s);i+=`
|
|
65
|
+
- `+v(l)+(c.length>0?lt` (did you mean ${c.map(a=>`"${a}"`).join(", ")}?)`:"")}F(t,i)}},"validatePackage");var dn=Object.defineProperty,w=m((e,t)=>dn(e,"name",{value:t,configurable:!0}),"m");const be=w((e,t)=>{e.warnings.size>0&&(t&&e.logger.raw(`
|
|
66
66
|
`),e.logger.warn(`Build is done with some warnings:
|
|
67
67
|
|
|
68
68
|
${[...e.warnings].map(o=>`- ${o}`).join(`
|
|
69
|
-
`)}`),e.options.failOnWarn&&(e.logger.error("Exiting with code (1). You can change this behavior by setting `failOnWarn: false`."),C(1)))},"logErrors"),
|
|
69
|
+
`)}`),e.options.failOnWarn&&(e.logger.error("Exiting with code (1). You can change this behavior by setting `failOnWarn: false`."),C(1)))},"logErrors"),fn=w(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"),gn=w((e,t,o,n,r,s,i,l)=>{const c=fn(l?.config.compilerOptions?.jsx),a=St(r,i.packem,n,s,{alias:{},clean:!0,declaration:void 0,dependencies:[],devDependencies:[],emitCJS:void 0,emitESM:void 0,entries:[],externals:[...ie.builtinModules,...ie.builtinModules.map(u=>`node:${u}`)],failOnWarn:!0,minify:R.NODE_ENV==="production",name:(i.name??"").split("/").pop()??"default",optionalDependencies:[],outDir:"dist",peerDependencies:[],replace:{},rollup:{alias:{},cjsInterop:{addDefaultProperty:!1},commonjs:{ignoreTryCatch:!0,preserveSymlinks:!0,transformMixedEsModules:!1},dts:{compilerOptions:{baseUrl:l?.config.compilerOptions?.baseUrl??".",checkJs:!1,composite:!1,declaration:!0,declarationMap:!1,emitDeclarationOnly:!0,incremental:!1,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:c,jsxDev:l?.config.compilerOptions?.jsx==="react-jsxdev",jsxFactory:l?.config.compilerOptions?.jsxFactory,jsxFragment:l?.config.compilerOptions?.jsxFragmentFactory,jsxImportSource:l?.config.compilerOptions?.jsxImportSource,jsxSideEffects:!0,keepNames:!0,minifyWhitespace:R.NODE_ENV==="production",sourcesContent:!1,target:l?.config.compilerOptions?.target,treeShaking:!0,tsconfigRaw:l?.config},json:{preferConst:!0},license:{dtsTemplate:w((u,p,d)=>`
|
|
70
70
|
# Licenses of bundled types
|
|
71
71
|
The published ${d} artifact additionally contains code with the following licenses:
|
|
72
72
|
${u.join(", ")}
|
|
73
73
|
|
|
74
74
|
# Bundled types:
|
|
75
|
-
`+p,"dtsTemplate"),template:
|
|
75
|
+
`+p,"dtsTemplate"),template:w((u,p,d)=>`
|
|
76
76
|
# Licenses of bundled dependencies
|
|
77
77
|
The published ${d} artifact additionally contains code with the following licenses:
|
|
78
78
|
${u.join(", ")}
|
|
79
79
|
|
|
80
80
|
# Bundled dependencies:
|
|
81
|
-
`+p,"template")},patchTypes:{},polyfillNode:{},preserveDynamicImports:!0,raw:{exclude:ae,include:["**/*.data","**/*.txt"]},replace:{objectGuards:!0,preventAssignment:!0},resolve:{allowExportsFolderMapping:!1,preferBuiltins:!1},shim:!0,sucrase:{disableESTransforms:!0,enableLegacyBabel5ModuleInterop:!1,enableLegacyTypeScriptModuleInterop:l?.config.compilerOptions?.esModuleInterop===!1,include:/\.[jt]sx?$/,injectCreateRequireForImportRequire:!1,preserveDynamicImport:!0,production:R.NODE_ENV==="production",...l?.config.compilerOptions?.jsx&&["react","react-jsx","react-jsxdev"].includes(l.config.compilerOptions.jsx)?{jsxFragmentPragma:l.config.compilerOptions.jsxFragmentFactory,jsxImportSource:l.config.compilerOptions.jsxImportSource,jsxPragma:l.config.compilerOptions.jsxFactory,jsxRuntime:c,transforms:["typescript","jsx",...l.config.compilerOptions.esModuleInterop?["imports"]:[]]}:{transforms:["typescript",...l?.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:l?.config.compilerOptions?.experimentalDecorators,dynamicImport:!0,syntax:l?"typescript":"ecmascript",[l?"tsx":"jsx"]:!0},target:l?.config.compilerOptions?.target?.toLowerCase(),transform:{decoratorMetadata:l?.config.compilerOptions?.emitDecoratorMetadata,legacyDecorator:!0,react:{development:R.NODE_ENV!=="production",pragma:l?.config.compilerOptions?.jsxFactory,pragmaFrag:l?.config.compilerOptions?.jsxFragmentFactory,runtime:c,throwIfNamespace:!0,useBuiltins:!0}}},module:{ignoreDynamic:!0,importInterop:"none",preserveImportMeta:!0,strict:!1,strictMode:!1,type:"es6"}},treeshake:{moduleSideEffects:
|
|
81
|
+
`+p,"template")},patchTypes:{},polyfillNode:{},preserveDynamicImports:!0,raw:{exclude:ae,include:["**/*.data","**/*.txt"]},replace:{objectGuards:!0,preventAssignment:!0},resolve:{allowExportsFolderMapping:!1,preferBuiltins:!1},shim:!0,sucrase:{disableESTransforms:!0,enableLegacyBabel5ModuleInterop:!1,enableLegacyTypeScriptModuleInterop:l?.config.compilerOptions?.esModuleInterop===!1,include:/\.[jt]sx?$/,injectCreateRequireForImportRequire:!1,preserveDynamicImport:!0,production:R.NODE_ENV==="production",...l?.config.compilerOptions?.jsx&&["react","react-jsx","react-jsxdev"].includes(l.config.compilerOptions.jsx)?{jsxFragmentPragma:l.config.compilerOptions.jsxFragmentFactory,jsxImportSource:l.config.compilerOptions.jsxImportSource,jsxPragma:l.config.compilerOptions.jsxFactory,jsxRuntime:c,transforms:["typescript","jsx",...l.config.compilerOptions.esModuleInterop?["imports"]:[]]}:{transforms:["typescript",...l?.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:l?.config.compilerOptions?.experimentalDecorators,dynamicImport:!0,syntax:l?"typescript":"ecmascript",[l?"tsx":"jsx"]:!0},target:l?.config.compilerOptions?.target?.toLowerCase(),transform:{decoratorMetadata:l?.config.compilerOptions?.emitDecoratorMetadata,legacyDecorator:!0,react:{development:R.NODE_ENV!=="production",pragma:l?.config.compilerOptions?.jsxFactory,pragmaFrag:l?.config.compilerOptions?.jsxFragmentFactory,runtime:c,throwIfNamespace:!0,useBuiltins:!0}}},module:{ignoreDynamic:!0,importInterop:"none",preserveImportMeta:!0,strict:!1,strictMode:!1,type:"es6"}},treeshake:{moduleSideEffects:Ir(t,i),preset:"recommended"},watch:{clearScreen:!0,exclude:ae}},rootDir:t,sourcemap:!1,stub:o==="jit",stubOptions:{jiti:{alias:{},esmResolve:!0,interopDefault:!0}},transformerName:void 0});if(!a.transformerName){const u=new Set([...Object.keys(i.dependencies??{}),...Object.keys(i.devDependencies??{})]);if(u.has("esbuild"))a.transformerName="esbuild";else if(u.has("@swc/core"))a.transformerName="swc";else if(u.has("sucrase"))a.transformerName="sucrase";else throw new Error("Unknown transformer, check your transformer options or install one of the supported transformers: esbuild, swc, sucrase");e.info('Using "'+v(a.transformerName)+'" as transformer.')}return a.outDir=f(a.rootDir,a.outDir),a.rollup.resolve&&a.rollup.resolve.preferBuiltins===!0&&(a.rollup.polyfillNode=!1,e.debug("Disabling polyfillNode because preferBuiltins is set to true")),l?.config.compilerOptions?.isolatedModules||e.warn(`'compilerOptions.isolatedModules' is not enabled in tsconfig.
|
|
82
82
|
Because none of the third-party transpilers, 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.
|
|
83
|
-
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.`),a.dependencies=Object.keys(i.dependencies??{}),a.peerDependencies=Object.keys(i.peerDependencies??{}),a.devDependencies=Object.keys(i.devDependencies??{}),a.optionalDependencies=Object.keys(i.optionalDependencies??{}),a.externals.push(...a.dependencies,...a.peerDependencies,...a.optionalDependencies),a},"generateOptions"),
|
|
84
|
-
exports: `+
|
|
85
|
-
${s.chunks.map(c=>{const a=t.buildEntries.find(u=>u.path===c)??{};return
|
|
86
|
-
`)}`),s.modules&&s.modules.length>0){const c=s.modules.filter(a=>a.id.includes("node_modules")).sort((a,u)=>(u.bytes||0)-(a.bytes||0)).map(a=>
|
|
83
|
+
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.`),a.dependencies=Object.keys(i.dependencies??{}),a.peerDependencies=Object.keys(i.peerDependencies??{}),a.devDependencies=Object.keys(i.devDependencies??{}),a.optionalDependencies=Object.keys(i.optionalDependencies??{}),a.externals.push(...a.dependencies,...a.peerDependencies,...a.optionalDependencies),a},"generateOptions"),hn=w(async(e,t)=>{e.options.entries=e.options.entries.map(o=>typeof o=="string"?{input:o}:o);for await(const o of e.options.entries){if(typeof o.name!="string"){let n=je(o.input)?D(t,o.input):B(o.input);n.startsWith("./")&&(n=n.slice(2)),o.name=Tr(n.replace(/^src\//,""))}if(!o.input)throw new Error(`Missing entry input: ${Qe(o)}`);if(!e.options.declaration&&o.declaration===void 0&&(o.declaration=e.options.declaration),o.input=f(e.options.rootDir,o.input),!ft(o.input)){const n=new Set(await st(K(o.input)));let r=!1;for(const s of I)if(n.has(J(o.input)+s)){r=!0;break}if(!r)throw new bt("Your configured entry: "+v(o.input)+" does not exist.")}o.outDir=f(e.options.rootDir,o.outDir??e.options.outDir)}},"prepareEntries"),yn=w((e,t,o)=>{const n=w(s=>D(t.rootDir,f(t.options.outDir,s)),"rPath");let r=!1;for(const s of t.buildEntries.filter(i=>!i.chunk)){let i=s.bytes??0;for(const c of s.chunks??[])i+=t.buildEntries.find(a=>a.path===c)?.bytes??0;let l=` ${x(n(s.path))} (${["total size: "+v(N(i)),s.type!=="asset"&&s.bytes&&"chunk size: "+v(N(s.bytes))].filter(Boolean).join(", ")})`;if(l+=s.exports?.length?`
|
|
84
|
+
exports: `+P(s.exports.join(", ")):"",s.chunks?.length&&(l+=`
|
|
85
|
+
${s.chunks.map(c=>{const a=t.buildEntries.find(u=>u.path===c)??{};return P(" └─ "+n(c)+x(a.bytes?" ("+N(a?.bytes)+")":""))}).join(`
|
|
86
|
+
`)}`),s.modules&&s.modules.length>0){const c=s.modules.filter(a=>a.id.includes("node_modules")).sort((a,u)=>(u.bytes||0)-(a.bytes||0)).map(a=>P(" 📦 "+n(a.id)+x(a.bytes?" ("+N(a.bytes)+")":""))).join(`
|
|
87
87
|
`);l+=c.length>0?`
|
|
88
88
|
inlined modules:
|
|
89
89
|
`+c:""}if(t.options.declaration&&s.type==="entry"){let c=s.path.replace(/\.js$/,".d.ts"),a="commonjs";s.path.endsWith(".cjs")?c=s.path.replace(/\.cjs$/,".d.cts"):s.path.endsWith(".mjs")&&(a="module",c=s.path.replace(/\.mjs$/,".d.mts"));const u=t.buildEntries.find(p=>p.path.endsWith(c));if(u){let p;(t.options.declaration===!0||t.options.declaration==="compatible")&&!c.includes(".d.ts")&&(c=c.replace(a==="commonjs"?".d.c":".d.m",".d."),p=t.buildEntries.find(d=>d.path.endsWith(c))),l+=p&&a===o.type?`
|
|
90
90
|
types:
|
|
91
|
-
`+[u,p].map(d=>
|
|
91
|
+
`+[u,p].map(d=>P(" └─ ")+x(n(d.path))+" (total size: "+v(N(d.bytes??0))+")").join(`
|
|
92
92
|
`):`
|
|
93
|
-
types: `+x(n(u.path))+" (total size: "+v(
|
|
93
|
+
types: `+x(n(u.path))+" (total size: "+v(N(u.bytes??0))+")"}}r=!0,l+=`
|
|
94
94
|
|
|
95
|
-
`,e.raw(s.chunk?
|
|
96
|
-
`),r},"showSizeInformation")
|
|
95
|
+
`,e.raw(s.chunk?P(l):l)}return r&&e.raw("Σ Total dist size (byte size):",v(N(t.buildEntries.reduce((s,i)=>s+(i.bytes??0),0))),`
|
|
96
|
+
`),r},"showSizeInformation"),vn=w(async(e,t,o,n,r,s,i,l,c)=>{const a=rn(n,t),u=gn(e,t,o,r,s,a,i,l);gt(u.outDir);const p={buildEntries:[],dependencyGraphMap:new Map,hooks:Dt(),logger:e,mode:o,options:u,pkg:i,rootDir:t,tsconfig:l,usedImports:new Set,warnings:new Set};if(a.hooks&&p.hooks.addHooks(a.hooks),r.hooks&&p.hooks.addHooks(r.hooks),s.hooks&&p.hooks.addHooks(s.hooks),await p.hooks.callHook("build:prepare",p),p.options.emitESM===!1&&p.options.emitCJS===!1)throw new Error("Both emitESM and emitCJS are disabled. At least one of them must be enabled.");if(p.options.declaration&&l===void 0)throw new Error("Cannot build declaration files without a tsconfig.json");p.options.emitESM===void 0&&e.info("Emitting ESM bundles, is disabled."),p.options.emitCJS===void 0&&e.info("Emitting CJS bundles, is disabled."),p.options.declaration||e.info("Declaration files, are disabled."),await hn(p,t),await p.hooks.callHook("build:before",p);let d="Building";if(o==="watch"?d="Watching":o==="jit"&&(d="Stubbing"),e.info(v(`${d} ${p.options.name}`)),e.debug(`${x("Root dir:")} ${p.options.rootDir}
|
|
97
97
|
${x("Entries:")}
|
|
98
|
-
${p.options.entries.map(g=>` ${
|
|
99
|
-
`)}`),p.options.clean)for(const g of new Set(p.options.entries.map(b=>b.outDir).filter(Boolean).sort()))g!==p.options.rootDir&&(c.push(g),e.info(`Cleaning dist directory: \`./${
|
|
100
|
-
⚡️ Build run in ${
|
|
98
|
+
${p.options.entries.map(g=>` ${Qe(g)}`).join(`
|
|
99
|
+
`)}`),p.options.clean)for(const g of new Set(p.options.entries.map(b=>b.outDir).filter(Boolean).sort()))g!==p.options.rootDir&&(c.push(g),e.info(`Cleaning dist directory: \`./${D(p.options.rootDir,g)}\``),await ht(g));if(p.options.stub){await ro(p),await p.hooks.callHook("build:done",p);return}if(o==="watch"){await _r(p),be(p,!1);return}await Promise.allSettled([Er(p),p.options.declaration&&Sr(p)]),e.success(pt(`Build succeeded for ${p.options.name}`));for await(const g of yt(p.options.outDir)){let b=p.buildEntries.find(y=>O(p.options.outDir,y.path)===g.path);if(b||(b={chunk:!0,path:g.path},p.buildEntries.push(b)),!b.bytes){const y=await $e(f(p.options.outDir,g.path));b.bytes=y.size}}const h=yn(e,p,i);an(p),mn(i,p),await p.hooks.callHook("build:done",p),be(p,h)},"build"),rs=w(async(e,t,o={})=>{const{configPath:n,debug:r,tsconfigPath:s,...i}=o,l=[new xt,new Et];r&&l.push(new Ot);const c=kt({logLevel:r?"debug":"informational",processors:l,scope:"packem"});c.wrapAll(),e=f(at(),e),c.debug("Root directory:",e);let a;if(s)await vt(s)||(c.error("tsconfig.json not found at",s),C(1)),a={config:$t(s),path:s},c.info("Using tsconfig settings found at",s);else try{a=await jt(e),c.debug("Using tsconfig settings found at",a.path)}catch{c.info("No tsconfig.json or jsconfig.json found.")}try{const u=O(e,"package.json"),p=wt(u);c.debug("Using package.json found at",u);const d=n??"./packem.config",h=tt(d,e,[]);c.debug("Using packem.config.ts found at",O(e,d));const g=(Array.isArray(h)?h:[h]).filter(Boolean),b=Date.now(),y=w(()=>Math.floor(Date.now()-b)+"ms","getDuration");let k=p.packem?.preset??o.preset??"auto";const _=[];await Promise.allSettled(g.map(async j=>{j.preset&&(k=j.preset),await vn(c,e,t,k,i,j,p,a,_)})),c.raw(`
|
|
100
|
+
⚡️ Build run in ${y()}`),c.restoreAll(),C(0)}catch(u){c.error("An error occurred while building",u),C(1)}},"createBundler");export{rs as default};
|