bunup 0.4.32 → 0.4.33

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.
Files changed (2) hide show
  1. package/build/cli.mjs +1 -1
  2. package/package.json +2 -2
package/build/cli.mjs CHANGED
@@ -31,7 +31,7 @@ See: https://bunup.arshadyaseen.com/documentation/#named-entries`,{muted:!0,vert
31
31
  const importMetaUrl = pathToFileURL(__filename).href;
32
32
 
33
33
  `}};function De({format:e,target:t,shims:n}){let s=lt(n).map((o)=>J[o]).filter((o)=>o.appliesTo(e,t));if(s.length===0)return{name:"bunup:inject-shims",setup(){}};return{name:"bunup:inject-shims",setup(o){o.onLoad({filter:at},async({path:i})=>{let a=await Bun.file(i).text(),c=s.filter((m)=>m.isNeededInFile(a));if(c.length===0)return;let{shebangLine:l,codeContent:f}=ct(a),p=c.map((m)=>m.generateCode()).join("");return{contents:l+p+f}})}}}function lt(e){if(e===!0)return Object.keys(J);if(!e)return[];return Object.entries(e).filter(([t,n])=>n&&(t in J)).map(([t])=>t)}function ct(e){if(!e.startsWith("#!"))return{shebangLine:"",codeContent:e};let t=e.indexOf(`
34
- `);return t===-1?{shebangLine:"",codeContent:e}:{shebangLine:e.slice(0,t+1),codeContent:e.slice(t+1)}}var $=new Set;async function k(e,t){let n=j(e);if(!n.entry||n.entry.length===0||!n.outDir)throw new w("Nothing to build. Please make sure you have provided a proper bunup configuration or cli arguments.");if(n.clean)ce(t,n.outDir);v(n.silent);let{packageJson:r,path:s}=await $e(t);if(r&&s)u.cli(`Using package.json: ${x(s,2)}`,{muted:!0,identifier:n.name,once:`${s}:${n.name}`});let o=P(n.entry),i=r?.type,a=D(n,r),c=A(n);if(!n.dtsOnly){let l=[Ie(a,c)],f=n.format.flatMap((p)=>o.map((m)=>{return ut(n,t,m,p,i,l)}));await Promise.all(f)}if(n.dts||n.dtsOnly){let l=await Oe(t,n.preferredTsconfigPath);if(l.path)u.cli(`Using tsconfig: ${x(l.path,2)}`,{muted:!0,identifier:n.name,once:`${l.path}:${n.name}`});let f=n.format.filter((m)=>{if(m==="iife"&&!S(i)&&n.format.includes("cjs"))return!1;return!0}),p=typeof n.dts==="object"&&n.dts.entry?P(n.dts.entry):Ce(o);try{await Promise.all(p.map(async(m)=>{let W=await we(t,m.path,n,l,r);await Promise.all(f.map(async(Z)=>{let ke=n.outputExtension?.({format:Z,packageType:i,options:n,entry:m}).dts??ae(Z,i),H=`${t}/${n.outDir}/${m.name}${ke}`;await Bun.write(H,W);let Ne=Bun.file(H).size||0;u.progress("DTS",x(H),X(Ne),n.name)}))}))}catch(m){throw new g(h(m))}}if(n.onBuildSuccess)await n.onBuildSuccess(n)}async function ut(e,t,n,r,s,o){let i=e.outputExtension?.({format:r,packageType:s,options:e,entry:n}).js??oe(r,s),a=await Bun.build({entrypoints:[`${t}/${n.path}`],format:r,naming:{entry:Ee(n.name,i)},splitting:Be(e.splitting,r),bytecode:Pe(e.bytecode,r),define:ve(e.define,e.shims,e.env,r),minify:Te(e),outdir:`${t}/${e.outDir}`,target:e.target,sourcemap:e.sourcemap,loader:e.loader,drop:e.drop,banner:e.banner,footer:e.footer,publicPath:e.publicPath,env:Le(e.env),plugins:[...o,De({format:r,target:e.target,shims:e.shims}),...e.bunBuildPlugins??[]],throw:!1});if(!a.success)for(let f of a.logs){if(f.level==="error")throw new w(f.message);if(f.level==="warning")u.warn(f.message);else if(f.level==="info")u.info(f.message)}let c=`${t}/${e.outDir}/${n.name}${i}`,l=Bun.file(c).size||0;u.progress(r.toUpperCase(),x(c),X(l),e.name)}var N="0.4.32";var Ae="https://bunup.arshadyaseen.com/documentation/#cli-options";function d(e){return(t,n)=>{n[e]=t===!0||t==="true"}}function y(e){return(t,n)=>{if(typeof t==="string")n[e]=t;else throw new b(`Option --${e} requires a string value`)}}function z(e){return(t,n)=>{if(typeof t==="string")n[e]=t.split(",");else throw new b(`Option --${e} requires a string value`)}}function mt(e){return(t,n)=>{if(typeof t==="boolean")n[e]=t;else if(typeof t==="string")if(t.toLowerCase()==="true"||t.toLowerCase()==="false")n[e]=t.toLowerCase()==="true";else n[e]=t;else throw new b(`Option --${e} requires a boolean or string value`)}}function pt(){console.log(`
34
+ `);return t===-1?{shebangLine:"",codeContent:e}:{shebangLine:e.slice(0,t+1),codeContent:e.slice(t+1)}}var $=new Set;async function k(e,t){let n=j(e);if(!n.entry||n.entry.length===0||!n.outDir)throw new w("Nothing to build. Please make sure you have provided a proper bunup configuration or cli arguments.");if(n.clean)ce(t,n.outDir);v(n.silent);let{packageJson:r,path:s}=await $e(t);if(r&&s)u.cli(`Using package.json: ${x(s,2)}`,{muted:!0,identifier:n.name,once:`${s}:${n.name}`});let o=P(n.entry),i=r?.type,a=D(n,r),c=A(n);if(!n.dtsOnly){let l=[Ie(a,c)],f=n.format.flatMap((p)=>o.map((m)=>{return ut(n,t,m,p,i,l)}));await Promise.all(f)}if(n.dts||n.dtsOnly){let l=await Oe(t,n.preferredTsconfigPath);if(l.path)u.cli(`Using tsconfig: ${x(l.path,2)}`,{muted:!0,identifier:n.name,once:`${l.path}:${n.name}`});let f=n.format.filter((m)=>{if(m==="iife"&&!S(i)&&n.format.includes("cjs"))return!1;return!0}),p=typeof n.dts==="object"&&n.dts.entry?P(n.dts.entry):Ce(o);try{await Promise.all(p.map(async(m)=>{let W=await we(t,m.path,n,l,r);await Promise.all(f.map(async(Z)=>{let ke=n.outputExtension?.({format:Z,packageType:i,options:n,entry:m}).dts??ae(Z,i),H=`${t}/${n.outDir}/${m.name}${ke}`;await Bun.write(H,W);let Ne=Bun.file(H).size||0;u.progress("DTS",x(H),X(Ne),n.name)}))}))}catch(m){throw new g(h(m))}}if(n.onBuildSuccess)await n.onBuildSuccess(n)}async function ut(e,t,n,r,s,o){let i=e.outputExtension?.({format:r,packageType:s,options:e,entry:n}).js??oe(r,s),a=await Bun.build({entrypoints:[`${t}/${n.path}`],format:r,naming:{entry:Ee(n.name,i)},splitting:Be(e.splitting,r),bytecode:Pe(e.bytecode,r),define:ve(e.define,e.shims,e.env,r),minify:Te(e),outdir:`${t}/${e.outDir}`,target:e.target,sourcemap:e.sourcemap,loader:e.loader,drop:e.drop,banner:e.banner,footer:e.footer,publicPath:e.publicPath,env:Le(e.env),plugins:[...o,De({format:r,target:e.target,shims:e.shims}),...e.bunBuildPlugins??[]],throw:!1});if(!a.success)for(let f of a.logs){if(f.level==="error")throw new w(f.message);if(f.level==="warning")u.warn(f.message);else if(f.level==="info")u.info(f.message)}let c=`${t}/${e.outDir}/${n.name}${i}`,l=Bun.file(c).size||0;u.progress(r.toUpperCase(),x(c),X(l),e.name)}var N="0.4.33";var Ae="https://bunup.arshadyaseen.com/documentation/#cli-options";function d(e){return(t,n)=>{n[e]=t===!0||t==="true"}}function y(e){return(t,n)=>{if(typeof t==="string")n[e]=t;else throw new b(`Option --${e} requires a string value`)}}function z(e){return(t,n)=>{if(typeof t==="string")n[e]=t.split(",");else throw new b(`Option --${e} requires a string value`)}}function mt(e){return(t,n)=>{if(typeof t==="boolean")n[e]=t;else if(typeof t==="string")if(t.toLowerCase()==="true"||t.toLowerCase()==="false")n[e]=t.toLowerCase()==="true";else n[e]=t;else throw new b(`Option --${e} requires a boolean or string value`)}}function pt(){console.log(`
35
35
  Bunup - An extremely fast, zero-config bundler for JavaScript and TypeScript, powered by Bun.
36
36
  `),console.log("For more information on available options, visit:"),console.log(`\x1B[36m\x1B[4m${Ae}\x1B[0m
37
37
  `),process.exit(0)}function dt(){console.log(N),process.exit(0)}var Me={name:{flags:["n","name"],handler:y("name")},format:{flags:["f","format"],handler:z("format")},outDir:{flags:["o","out-dir"],handler:y("outDir")},minify:{flags:["m","minify"],handler:d("minify")},watch:{flags:["w","watch"],handler:d("watch")},dts:{flags:["d","dts"],handler:d("dts")},banner:{flags:["bn","banner"],handler:y("banner")},footer:{flags:["ft","footer"],handler:y("footer")},external:{flags:["e","external"],handler:z("external")},sourcemap:{flags:["sm","sourcemap"],handler:mt("sourcemap")},target:{flags:["t","target"],handler:y("target")},minifyWhitespace:{flags:["mw","minify-whitespace"],handler:d("minifyWhitespace")},minifyIdentifiers:{flags:["mi","minify-identifiers"],handler:d("minifyIdentifiers")},minifySyntax:{flags:["ms","minify-syntax"],handler:d("minifySyntax")},clean:{flags:["c","clean"],handler:d("clean")},splitting:{flags:["s","splitting"],handler:d("splitting")},noExternal:{flags:["ne","no-external"],handler:z("noExternal")},preferredTsconfigPath:{flags:["tsconfig","preferred-tsconfig-path"],handler:y("preferredTsconfigPath")},bytecode:{flags:["bc","bytecode"],handler:d("bytecode")},dtsOnly:{flags:["do","dts-only"],handler:d("dtsOnly")},silent:{flags:["silent"],handler:d("silent")},config:{flags:["config"],handler:y("config")},publicPath:{flags:["pp","public-path"],handler:y("publicPath")},env:{flags:["env"],handler:y("env")},shims:{flags:["shims"],handler:d("shims")},onSuccess:{flags:["onSuccess"],handler:y("onSuccess")},entry:{flags:["entry"],handler:(e,t,n)=>{if(typeof e!=="string")throw new b(`Entry${n?` --entry.${n}`:""} requires a string value`);let r=t.entry||{};if(n){if(r[n])u.warn(`Duplicate entry name '${n}' provided via --entry.${n}. Overwriting previous entry.`);r[n]=e}else{let s=_(e);if(r[s])u.warn(`Duplicate entry name '${s}' derived from '${e}'. Overwriting previous entry.`);r[s]=e}t.entry=r}},resolveDts:{flags:["rd","resolve-dts"],handler:(e,t)=>{if(!t.dts)t.dts={};if(typeof t.dts==="boolean")t.dts={};if(typeof e==="string")if(e==="true"||e==="false")t.dts.resolve=e==="true";else t.dts.resolve=e.split(",");else t.dts.resolve=!0}},help:{flags:["h","help"],handler:()=>pt()},version:{flags:["v","version"],handler:()=>dt()}},U={};for(let e of Object.values(Me))for(let t of e.flags)U[t]=e.handler;function _e(e){let t={};for(let n=0;n<e.length;n++){let r=e[n];if(r.startsWith("--")){let s,o;if(r.includes("=")){let[i,a]=r.slice(2).split("=",2);s=i,o=a}else{s=r.slice(2);let i=e[n+1];if(o=i&&!i.startsWith("-")?i:!0,typeof o==="string")n++}if(s.includes(".")){let[i,a]=s.split(".",2),c=U[i];if(c)c(o,t,a);else throw new b(`Unknown option: --${s}`)}else{let i=U[s];if(i)i(o,t);else throw new b(`Unknown option: --${s}`)}}else if(r.startsWith("-")){let s=r.slice(1),o=e[n+1],i=o&&!o.startsWith("-")?o:!0;if(typeof i==="string")n++;let a=U[s];if(a)a(i,t);else throw new b(`Unknown option: -${s}`)}else Me.entry.handler(r,t,void 0)}return t}import{loadConfig as bt}from"coffi";import F from"node:path";import gt from"chokidar";async function je(e,t){let n=new Set,r=j(e),s=P(r.entry);for(let c of s){let l=F.resolve(t,c.path),f=F.dirname(l);n.add(f)}let o=gt.watch(Array.from(n),{persistent:!0,awaitWriteFinish:{stabilityThreshold:100,pollInterval:50},ignoreInitial:!0,atomic:!0,ignorePermissionErrors:!0,ignored:[/[\\/]\.git[\\/]/,/[\\/]node_modules[\\/]/,F.join(t,r.outDir)]}),i=!1,a=async(c=!1)=>{if(i)return;i=!0;try{let l=performance.now();if(await k({...r,entry:s.map((f)=>f.path),clean:!1},t),!c)u.cli(`\uD83D\uDCE6 Rebuild finished in ${L(performance.now()-l)}`);await Q()}catch(l){V(l)}finally{i=!1}};o.on("change",(c)=>{let l=F.relative(t,c);u.cli(`File changed: ${l}`,{muted:!0,once:l}),a()}),o.on("error",(c)=>{throw new B(`Watcher error: ${h(c)}`)}),await a(!0)}async function yt(e=Bun.argv.slice(2)){let t=_e(e);v(t.silent);let n=process.cwd(),{config:r,filepath:s}=await bt({name:"bunup.config",extensions:[".ts",".js",".mjs",".cjs"],maxDepth:1,preferredPath:t.config}),o=!r?[{rootDir:n,options:t}]:await Re(r,n);if(u.cli(`Using bunup v${N} and bun v${Bun.version}`,{muted:!0}),s)u.cli(`Using config file: ${x(s,2)}`,{muted:!0});let i=performance.now();u.cli("Build started"),await Promise.all(o.flatMap(({options:l,rootDir:f})=>{return ie(l).map(async(m)=>{let W={...m,...xt(t)};return wt(W,f)})}));let a=performance.now()-i,c=L(a);if(u.cli(`\u26A1\uFE0F Build completed in ${c}`),await Q(),t.watch)u.cli("\uD83D\uDC40 Watching for file changes");if(t.onSuccess)u.cli(`Running command: ${t.onSuccess}`,{muted:!0}),ht(t.onSuccess,[],{nodeOptions:{shell:!0,stdio:"inherit"}});if(!t.watch)process.exit(0)}function xt(e){return{...e,onSuccess:void 0,config:void 0}}async function Q(){if($.size>0)await xe($),$.clear()}async function wt(e,t){if(e.watch)await je(e,t);else await k(e,t)}yt().catch((e)=>te(e));export{Q as validateDtsFiles,yt as main};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bunup",
3
- "version": "0.4.32",
3
+ "version": "0.4.33",
4
4
  "description": "An extremely fast, zero-config bundler for TypeScript & JavaScript, powered by Bun.",
5
5
  "main": "./build/index.js",
6
6
  "types": "./build/index.d.ts",
@@ -20,7 +20,7 @@
20
20
  "bunup": "^0.4.23",
21
21
  "husky": "^9.1.7",
22
22
  "typescript": "^5.8.3",
23
- "create-bunup": "0.4.32"
23
+ "create-bunup": "0.4.33"
24
24
  },
25
25
  "peerDependencies": {
26
26
  "typescript": ">=4.5.0"