bunup 0.4.7 → 0.4.9

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/README.md CHANGED
@@ -20,7 +20,7 @@ To run the benchmarks yourself, clone this repo and run `pnpm benchmark` and che
20
20
 
21
21
  - 🔄 **Tsup-Compatible**: Drop-in replacement for tsup with familiar CLI and config.
22
22
 
23
- - ⚡ **Ultra-Fast Builds**: ~50× faster than tsup using Bun's runtime and oxc compiler.
23
+ - ⚡ **Ultra-Fast Builds**: ~50× faster than tsup using Bun's bundler and oxc compiler.
24
24
 
25
25
  - 🔥 **Bytecode Generation**: Faster startups by compiling to Bun bytecode—perfect for CLIs.
26
26
 
@@ -53,7 +53,7 @@ Create a simple TypeScript file:
53
53
  ```typescript
54
54
  // src/index.ts
55
55
  export function greet(name: string): string {
56
- return `Hello, ${name}!`;
56
+ return `Hello, ${name}!`;
57
57
  }
58
58
  ```
59
59
 
@@ -71,10 +71,10 @@ Add a build script to your `package.json`:
71
71
 
72
72
  ```json
73
73
  {
74
- "name": "my-package",
75
- "scripts": {
76
- "build": "bunup src/index.ts --format esm,cjs --dts"
77
- }
74
+ "name": "my-package",
75
+ "scripts": {
76
+ "build": "bunup src/index.ts --format esm,cjs --dts"
77
+ }
78
78
  }
79
79
  ```
80
80
 
@@ -89,14 +89,14 @@ npm run build
89
89
  Create a `bunup.config.ts` file for more control:
90
90
 
91
91
  ```typescript
92
- import {defineConfig} from 'bunup';
92
+ import { defineConfig } from "bunup";
93
93
 
94
94
  export default defineConfig({
95
- entry: ['src/index.ts'],
96
- outDir: 'dist',
97
- format: ['esm', 'cjs'],
98
- dts: true,
99
- minify: true,
95
+ entry: ["src/index.ts"],
96
+ outDir: "dist",
97
+ format: ["esm", "cjs"],
98
+ dts: true,
99
+ minify: true,
100
100
  });
101
101
  ```
102
102
 
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 mt=/\.(js|ts|jsx|tsx|mts|cts)$/;function ke({format:e,target:t,shims:n}){let s=dt(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:mt},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}=gt(a),m=l.map((p)=>p.generateCode()).join("");return{contents:c+m+f}})}}}function dt(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 gt(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);_(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=M(n,r),l=D(n);if(!n.dtsOnly){let c=[ve(a,l)],f=n.format.flatMap((m)=>o.map((p)=>{return ht(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(He)=>{let qe=le(He,i),V=`${t}/${n.outDir}/${p.name}${qe}`;await Bun.write(V,G);let Ge=Bun.file(V).size||0;u.progress("DTS",x(V),J(Ge),n.name)}))}))}catch(p){throw new h(b(p))}}}async function ht(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:De(e.splitting,r),bytecode:Ie(e.bytecode,r),define:Me(e.define,e.shims,e.env,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,env:_e(e.env),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.7";var je="https://bun.sh/docs/installation",Ue="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 xt(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 yt(){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);_(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=M(n,r),l=D(n);if(!n.dtsOnly){let c=[ve(a,l)],f=n.format.flatMap((m)=>o.map((p)=>{return ht(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(He)=>{let qe=le(He,i),V=`${t}/${n.outDir}/${p.name}${qe}`;await Bun.write(V,G);let Ge=Bun.file(V).size||0;u.progress("DTS",x(V),J(Ge),n.name)}))}))}catch(p){throw new h(b(p))}}}async function ht(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:De(e.splitting,r),bytecode:Ie(e.bytecode,r),define:Me(e.define,e.shims,e.env,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,env:_e(e.env),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.9";var je="https://bun.sh/docs/installation",Ue="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 xt(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 yt(){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${Ue}\x1B[0m
37
37
  `),process.exit(0)}function wt(){console.log(W),process.exit(0)}var Ne={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:xt("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")},env:{flags:["env"],handler:y("env")},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:()=>yt()},version:{flags:["v","version"],handler:()=>wt()}},H={};for(let e of Object.values(Ne))for(let t of e.flags)H[t]=e.handler;function Fe(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 Ne.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
@@ -304,33 +304,31 @@ interface BuildOptions {
304
304
  * Controls how environment variables are handled during bundling.
305
305
  *
306
306
  * Can be one of:
307
- * - `"inline"`: Injects environment variables into the bundled output by converting `process.env.FOO`
308
- * references to string literals containing the actual environment variable values
309
- * - `"disable"`: Disables environment variable injection entirely
310
- * - A string ending in `*`: Inlines environment variables that match the given prefix.
311
- * For example, `"MY_PUBLIC_*"` will only include env vars starting with "MY_PUBLIC_"
312
- * - An object of key-value pairs where the key is the env name and value is the value
307
+ * - `"inline"`: Replaces all `process.env.FOO` references in your code with the actual values
308
+ * of those environment variables at the time the build runs.
309
+ * - `"disable"`: Disables environment variable injection entirely, leaving `process.env.*` as-is.
310
+ * - A string ending in `*`: Only inlines environment variables matching the given prefix.
311
+ * For example, `"MY_PUBLIC_*"` will inline variables like `MY_PUBLIC_API_URL`.
312
+ * - An object of key-value pairs: Replaces both `process.env.KEY` and `import.meta.env.KEY`
313
+ * with the provided values, regardless of the runtime environment.
313
314
  *
314
- * @see https://bun.sh/docs/bundler#env to learn more about inline, disable and prefix methods
315
+ * Note: Values are injected at build time. Secrets or private keys should be excluded
316
+ * from inlining when targeting browser environments.
317
+ *
318
+ * @see https://bun.sh/docs/bundler#env to learn more about inline, disable, prefix, and object modes
315
319
  *
316
320
  * @example
317
- * // Inline all environment variables
321
+ * // Inline all environment variables available at build time
318
322
  * env: "inline"
319
323
  *
320
- * // Disable environment variable injection
324
+ * // Disable all environment variable injection
321
325
  * env: "disable"
322
326
  *
323
327
  * // Only inline environment variables with a specific prefix
324
328
  * env: "PUBLIC_*"
325
329
  *
326
- * // Provide specific environment variables
330
+ * // Provide specific environment variables manually
327
331
  * env: { API_URL: "https://api.example.com", DEBUG: "false" }
328
- *
329
- * @example [CLI]
330
- * To inline specific environment variables at build time:
331
- * ```sh
332
- * FOO=bar API_KEY=secret bunup src/index.ts --env inline
333
- * ```
334
332
  */
335
333
  env?: Env;
336
334
  }
package/build/index.d.ts CHANGED
@@ -304,33 +304,31 @@ interface BuildOptions {
304
304
  * Controls how environment variables are handled during bundling.
305
305
  *
306
306
  * Can be one of:
307
- * - `"inline"`: Injects environment variables into the bundled output by converting `process.env.FOO`
308
- * references to string literals containing the actual environment variable values
309
- * - `"disable"`: Disables environment variable injection entirely
310
- * - A string ending in `*`: Inlines environment variables that match the given prefix.
311
- * For example, `"MY_PUBLIC_*"` will only include env vars starting with "MY_PUBLIC_"
312
- * - An object of key-value pairs where the key is the env name and value is the value
307
+ * - `"inline"`: Replaces all `process.env.FOO` references in your code with the actual values
308
+ * of those environment variables at the time the build runs.
309
+ * - `"disable"`: Disables environment variable injection entirely, leaving `process.env.*` as-is.
310
+ * - A string ending in `*`: Only inlines environment variables matching the given prefix.
311
+ * For example, `"MY_PUBLIC_*"` will inline variables like `MY_PUBLIC_API_URL`.
312
+ * - An object of key-value pairs: Replaces both `process.env.KEY` and `import.meta.env.KEY`
313
+ * with the provided values, regardless of the runtime environment.
313
314
  *
314
- * @see https://bun.sh/docs/bundler#env to learn more about inline, disable and prefix methods
315
+ * Note: Values are injected at build time. Secrets or private keys should be excluded
316
+ * from inlining when targeting browser environments.
317
+ *
318
+ * @see https://bun.sh/docs/bundler#env to learn more about inline, disable, prefix, and object modes
315
319
  *
316
320
  * @example
317
- * // Inline all environment variables
321
+ * // Inline all environment variables available at build time
318
322
  * env: "inline"
319
323
  *
320
- * // Disable environment variable injection
324
+ * // Disable all environment variable injection
321
325
  * env: "disable"
322
326
  *
323
327
  * // Only inline environment variables with a specific prefix
324
328
  * env: "PUBLIC_*"
325
329
  *
326
- * // Provide specific environment variables
330
+ * // Provide specific environment variables manually
327
331
  * env: { API_URL: "https://api.example.com", DEBUG: "false" }
328
- *
329
- * @example [CLI]
330
- * To inline specific environment variables at build time:
331
- * ```sh
332
- * FOO=bar API_KEY=secret bunup src/index.ts --env inline
333
- * ```
334
332
  */
335
333
  env?: Env;
336
334
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bunup",
3
- "version": "0.4.7",
3
+ "version": "0.4.9",
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",
@@ -17,10 +17,10 @@
17
17
  "@commitlint/config-conventional": "^19.5.0",
18
18
  "@types/bun": "^1.2.5",
19
19
  "bumpp": "^10.1.0",
20
- "bunup": "^0.4.1",
20
+ "bunup": "^0.4.7",
21
21
  "husky": "^9.1.7",
22
22
  "typescript": "^5.8.3",
23
- "create-bunup": "0.4.7"
23
+ "create-bunup": "0.4.9"
24
24
  },
25
25
  "peerDependencies": {
26
26
  "typescript": ">=4.5.0"