bunup 0.4.4 → 0.4.5

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/build/cli.mjs CHANGED
@@ -31,7 +31,7 @@ See: https://bunup.arshadyaseen.com/#named-entries`,{muted:!0,verticalSpace:!0})
31
31
  const importMetaUrl = pathToFileURL(__filename).href;
32
32
 
33
33
  `}};var pt=/\.(js|ts|jsx|tsx|mts|cts)$/;function ke({format:e,target:t,shims:n}){let s=mt(n).map((o)=>N[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:pt},async({path:i})=>{let a=await Bun.file(i).text(),l=s.filter((p)=>p.isNeededInFile(a));if(l.length===0)return;let{shebangLine:c,codeContent:f}=dt(a),m=l.map((p)=>p.generateCode()).join("");return{contents:c+m+f}})}}}function mt(e){if(e===!0)return Object.keys(N);if(!e)return[];return Object.entries(e).filter(([t,n])=>n&&(t in N)).map(([t])=>t)}function dt(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 F(e,t){let n=U(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)ue(t,n.outDir);D(n.silent);let{packageJson:r,path:s}=await Be(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=v(n,r),l=M(n);if(!n.dtsOnly){let c=[De(a,l)],f=n.format.flatMap((m)=>o.map((p)=>{return gt(n,t,p,m,i,c)}));await Promise.all(f)}if(n.dts||n.dtsOnly){let c=await Le(t,n.preferredTsconfigPath);if(c.path)u.cli(`Using tsconfig: ${x(c.path,2)}`,{muted:!0,identifier:n.name,once:`${c.path}:${n.name}`});let f=n.format.filter((p)=>{if(p==="iife"&&!L(i)&&n.format.includes("cjs"))return!1;return!0}),m=typeof n.dts==="object"&&n.dts.entry?P(n.dts.entry):Re(o);try{await Promise.all(m.map(async(p)=>{let G=await $e(t,p.path,n,c,r);await Promise.all(f.map(async(We)=>{let He=le(We,i),V=`${t}/${n.outDir}/${p.name}${He}`;await Bun.write(V,G);let qe=Bun.file(V).size||0;u.progress("DTS",x(V),J(qe),n.name)}))}))}catch(p){throw new h(b(p))}}}async function gt(e,t,n,r,s,o){let i=ae(r,s),a=await Bun.build({entrypoints:[`${t}/${n.path}`],format:r,naming:{entry:Se(n.name,i)},splitting:Me(e.splitting,r),bytecode:Ie(e.bytecode,r),define:ve(e.define,e.shims,r),minify:Ae(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,plugins:[...o,ke({format:r,target:e.target,shims:e.shims})],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 l=`${t}/${e.outDir}/${n.name}${i}`,c=Bun.file(l).size||0;u.progress(r.toUpperCase(),x(l),J(c),e.name)}var W="0.4.4";var _e="https://bun.sh/docs/installation",je="https://bunup.arshadyaseen.com/#cli-options";function g(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 d(`Option --${e} requires a string value`)}}function ee(e){return(t,n)=>{if(typeof t==="string")n[e]=t.split(",");else throw new d(`Option --${e} requires a string value`)}}function bt(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 d(`Option --${e} requires a boolean or string value`)}}function xt(){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 F(e,t){let n=U(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)ue(t,n.outDir);D(n.silent);let{packageJson:r,path:s}=await Be(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=v(n,r),l=M(n);if(!n.dtsOnly){let c=[De(a,l)],f=n.format.flatMap((m)=>o.map((p)=>{return gt(n,t,p,m,i,c)}));await Promise.all(f)}if(n.dts||n.dtsOnly){let c=await Le(t,n.preferredTsconfigPath);if(c.path)u.cli(`Using tsconfig: ${x(c.path,2)}`,{muted:!0,identifier:n.name,once:`${c.path}:${n.name}`});let f=n.format.filter((p)=>{if(p==="iife"&&!L(i)&&n.format.includes("cjs"))return!1;return!0}),m=typeof n.dts==="object"&&n.dts.entry?P(n.dts.entry):Re(o);try{await Promise.all(m.map(async(p)=>{let G=await $e(t,p.path,n,c,r);await Promise.all(f.map(async(We)=>{let He=le(We,i),V=`${t}/${n.outDir}/${p.name}${He}`;await Bun.write(V,G);let qe=Bun.file(V).size||0;u.progress("DTS",x(V),J(qe),n.name)}))}))}catch(p){throw new h(b(p))}}}async function gt(e,t,n,r,s,o){let i=ae(r,s),a=await Bun.build({entrypoints:[`${t}/${n.path}`],format:r,naming:{entry:Se(n.name,i)},splitting:Me(e.splitting,r),bytecode:Ie(e.bytecode,r),define:ve(e.define,e.shims,r),minify:Ae(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,plugins:[...o,ke({format:r,target:e.target,shims:e.shims})],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 l=`${t}/${e.outDir}/${n.name}${i}`,c=Bun.file(l).size||0;u.progress(r.toUpperCase(),x(l),J(c),e.name)}var W="0.4.5";var _e="https://bun.sh/docs/installation",je="https://bunup.arshadyaseen.com/#cli-options";function g(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 d(`Option --${e} requires a string value`)}}function ee(e){return(t,n)=>{if(typeof t==="string")n[e]=t.split(",");else throw new d(`Option --${e} requires a string value`)}}function bt(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 d(`Option --${e} requires a boolean or string value`)}}function xt(){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${je}\x1B[0m
37
37
  `),process.exit(0)}function yt(){console.log(W),process.exit(0)}var Ue={name:{flags:["n","name"],handler:y("name")},format:{flags:["f","format"],handler:ee("format")},outDir:{flags:["o","out-dir"],handler:y("outDir")},minify:{flags:["m","minify"],handler:g("minify")},watch:{flags:["w","watch"],handler:g("watch")},dts:{flags:["d","dts"],handler:g("dts")},banner:{flags:["bn","banner"],handler:y("banner")},footer:{flags:["ft","footer"],handler:y("footer")},external:{flags:["e","external"],handler:ee("external")},sourcemap:{flags:["sm","sourcemap"],handler:bt("sourcemap")},target:{flags:["t","target"],handler:y("target")},minifyWhitespace:{flags:["mw","minify-whitespace"],handler:g("minifyWhitespace")},minifyIdentifiers:{flags:["mi","minify-identifiers"],handler:g("minifyIdentifiers")},minifySyntax:{flags:["ms","minify-syntax"],handler:g("minifySyntax")},clean:{flags:["c","clean"],handler:g("clean")},splitting:{flags:["s","splitting"],handler:g("splitting")},noExternal:{flags:["ne","no-external"],handler:ee("noExternal")},preferredTsconfigPath:{flags:["tsconfig","preferred-tsconfig-path"],handler:y("preferredTsconfigPath")},bytecode:{flags:["bc","bytecode"],handler:g("bytecode")},dtsOnly:{flags:["do","dts-only"],handler:g("dtsOnly")},silent:{flags:["silent"],handler:g("silent")},config:{flags:["config"],handler:y("config")},publicPath:{flags:["pp","public-path"],handler:y("publicPath")},shims:{flags:["shims"],handler:g("shims")},entry:{flags:["entry"],handler:(e,t,n)=>{if(typeof e!=="string")throw new d(`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=j(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:()=>xt()},version:{flags:["v","version"],handler:()=>yt()}},H={};for(let e of Object.values(Ue))for(let t of e.flags)H[t]=e.handler;function Ne(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),l=H[i];if(l)l(o,t,a);else throw new d(`Unknown option: --${s}`)}else{let i=H[s];if(i)i(o,t);else throw new d(`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=H[s];if(a)a(i,t);else throw new d(`Unknown option: -${s}`)}else Ue.entry.handler(r,t,void 0)}return t}(()=>{if(typeof Bun==="undefined")throw new d(`Bunup requires Bun to run.
package/build/index.d.mts CHANGED
@@ -9,7 +9,13 @@ type Target = BunBuildOptions["target"];
9
9
  type External = (string | RegExp)[];
10
10
  type Entry = Arrayable<string> | Record<string, string>;
11
11
  type ShimOptions = {
12
+ /**
13
+ * Adds __dirname and __filename shims for ESM files when used
14
+ */
12
15
  dirnameFilename?: boolean
16
+ /**
17
+ * Adds import.meta.url shims for CJS files when used
18
+ */
13
19
  importMetaUrl?: boolean
14
20
  };
15
21
  type Shims = boolean | ShimOptions;
@@ -282,8 +288,7 @@ interface BuildOptions {
282
288
  * When set to an object, only injects the specified shims
283
289
  *
284
290
  * Available shims:
285
- * - dirname: Adds __dirname for ESM files when used
286
- * - filename: Adds __filename for ESM files when used
291
+ * - dirnameFilename: Adds __dirname and __filename for ESM files when used
287
292
  * - importMetaUrl: Adds import.meta.url for CJS files when used
288
293
  *
289
294
  * @example
@@ -291,7 +296,7 @@ interface BuildOptions {
291
296
  * shims: true
292
297
  *
293
298
  * // Enable only specific shims
294
- * shims: { dirname: true, importMetaUrl: true }
299
+ * shims: { dirnameFilename: true, importMetaUrl: true }
295
300
  */
296
301
  shims?: Shims;
297
302
  }
package/build/index.d.ts CHANGED
@@ -9,7 +9,13 @@ type Target = BunBuildOptions["target"];
9
9
  type External = (string | RegExp)[];
10
10
  type Entry = Arrayable<string> | Record<string, string>;
11
11
  type ShimOptions = {
12
+ /**
13
+ * Adds __dirname and __filename shims for ESM files when used
14
+ */
12
15
  dirnameFilename?: boolean
16
+ /**
17
+ * Adds import.meta.url shims for CJS files when used
18
+ */
13
19
  importMetaUrl?: boolean
14
20
  };
15
21
  type Shims = boolean | ShimOptions;
@@ -282,8 +288,7 @@ interface BuildOptions {
282
288
  * When set to an object, only injects the specified shims
283
289
  *
284
290
  * Available shims:
285
- * - dirname: Adds __dirname for ESM files when used
286
- * - filename: Adds __filename for ESM files when used
291
+ * - dirnameFilename: Adds __dirname and __filename for ESM files when used
287
292
  * - importMetaUrl: Adds import.meta.url for CJS files when used
288
293
  *
289
294
  * @example
@@ -291,7 +296,7 @@ interface BuildOptions {
291
296
  * shims: true
292
297
  *
293
298
  * // Enable only specific shims
294
- * shims: { dirname: true, importMetaUrl: true }
299
+ * shims: { dirnameFilename: true, importMetaUrl: true }
295
300
  */
296
301
  shims?: Shims;
297
302
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bunup",
3
- "version": "0.4.4",
3
+ "version": "0.4.5",
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.1",
21
21
  "husky": "^9.1.7",
22
22
  "typescript": "^5.8.3",
23
- "create-bunup": "0.4.4"
23
+ "create-bunup": "0.4.5"
24
24
  },
25
25
  "peerDependencies": {
26
26
  "typescript": ">=4.5.0"