bunup 0.3.11 → 0.3.12

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
@@ -20,7 +20,7 @@ To fix this, use named entries in your configuration:
20
20
  }
21
21
  }
22
22
 
23
- See: https://bunup.arshadyaseen.com/#using-a-configuration-file-with-named-entries`,{muted:!0,verticalSpace:!0}),t.push({name:c,path:o})}else t.push({name:i,path:o}),e.add(i),r[i]=o}if(Array.isArray(n))for(let i of n){let o=A(i);s(o,i)}else if(typeof n==="object")Object.entries(n).forEach(([i,o])=>{s(i,o)});else{let i=A(n);s(i,n)}return t}function hn(n,t){return`[dir]/${n}${t}`}import{loadTsConfig as Qn}from"load-tsconfig";function xn(n){try{return Qn(".",n)}catch(t){return l.warn(`Failed to load tsconfig: ${m(t)}`),{path:n,data:{},files:[]}}}import Q from"node:path";async function yn(n){let t=[".ts",".js",".mjs",".cjs",".mts",".cts",".json",".jsonc"];for(let e of t){let r=Q.join(n,`bunup.config${e}`);try{if(!await Bun.file(r).exists())continue;let i=await Zn(r,e);if(!i)continue;return{configs:Fn(i,n),configFilePath:r}}catch(s){throw new y(`Failed to load config from ${r}: ${m(s)}`)}}return{configs:[],configFilePath:""}}async function Zn(n,t){if(t===".json"||t===".jsonc")return zn(n);return Xn(n)}async function zn(n){try{let t=await Bun.file(n).text(),e=JSON.parse(t);return e.bunup||e}catch(t){throw new Error(`Invalid JSON in config file. ${m(t)}`)}}async function Xn(n){try{let t=await import(`file://${n}`),e=t.default||t;if(!e)return l.warn(`No export found in ${n}. Make sure you're exporting your configuration.`),{};return e}catch(t){throw new Error(`Failed to import config file. ${m(t)}`)}}function Fn(n,t){let e=[];if(Vn(n))nt(n,t,e);else if(Array.isArray(n))tt(n,t,e);else if(n&&typeof n==="object")e.push({options:n,rootDir:t});else throw new Error("Invalid configuration format. Expected an object, array, or workspace configuration.");return e}function Vn(n){return Array.isArray(n)&&n.length>0&&n.every((t)=>typeof t==="object"&&t!==null&&("name"in t)&&("root"in t)&&("config"in t))}function nt(n,t,e){for(let r of n){let s=Q.resolve(t,r.root);if(Array.isArray(r.config))for(let i of r.config)e.push({options:{name:r.name,...i},rootDir:s});else e.push({options:{name:r.name,...r.config},rootDir:s})}}function tt(n,t,e){for(let r of n){if(!r||typeof r!=="object")throw new Error("Invalid configuration item. Expected an object.");e.push({options:r,rootDir:t})}}async function wn(n){let t=Q.join(n,"package.json");try{if(!await Bun.file(t).exists())return{packageJson:null,path:t};let r=await Bun.file(t).text();return{packageJson:JSON.parse(r),path:t}}catch(e){return l.warn(`Failed to load package.json at ${t}: ${m(e)}`),{packageJson:null,path:t}}}function bn(n,t){return{name:"bunup:external-plugin",setup(e){e.onResolve({filter:/.*/},(r)=>{let s=r.path;if(n.some((o)=>o.test(s))&&!t.some((o)=>o.test(s)))return{path:s,external:!0};return null})}}}var v=new Set;async function D(n,t){if(!n.entry||n.entry.length===0||!n.outDir)throw new y("Nothing to build. Please make sure you have provided a proper bunup configuration or cli arguments.");let{packageJson:e,path:r}=await wn(t);if(e)l.cli(`Using package.json: ${w(r)}`,{muted:!0});let s=e?.type,i=k(n,e),o=L(n),a=[bn(i,o)],c=T(n.entry),u=z(n,t),p=n.format.flatMap((f)=>c.map((x)=>{return et(n,t,x,f,s,a,u)}));if(await Promise.all(p),n.dts){let f=xn(n.preferredTsconfigPath);if(f.path)l.cli(`Using tsconfig: ${w(f.path)}`,{muted:!0});let x=n.format.filter((O)=>{if(O==="iife"&&!N(s)&&n.format.includes("cjs"))return!1;return!0}),$=typeof n.dts==="object"&&n.dts.entry?T(n.dts.entry):c;try{await Promise.all($.map(async(O)=>{let Rn=await dn(t,O.path,n,f,e);await Promise.all(x.map(async(Sn)=>{let jn=V(Sn,s),G=`${t}/${n.outDir}/${O.name}${jn}`;await Bun.write(G,Rn);let An=Bun.file(G).size||0;l.progress("DTS",w(G),P(An),n.name)}))}))}catch(O){throw new d(m(O))}}}async function et(n,t,e,r,s,i,o){let a=F(r,s),c=await Bun.build({...o,entrypoints:[`${t}/${e.path}`],format:r,naming:{entry:hn(e.name,a)},splitting:tn(n.splitting,r),plugins:i,throw:!1});if(!c.success)c.logs.forEach((f)=>{if(f.level==="error")throw new y(f.message);else if(f.level==="warning")l.warn(f.message);else if(f.level==="info")l.info(f.message)});let u=`${t}/${n.outDir}/${e.name}${a}`,p=Bun.file(u).size||0;l.progress(r.toUpperCase(),w(u),P(p),n.name)}var H="0.3.11";var $n="https://bun.sh/docs/installation",On="https://bunup.arshadyaseen.com/#cli-options";function b(n){return(t,e)=>{e[n]=t===!0?!0:t==="true"}}function S(n){return(t,e)=>{if(typeof t==="string")e[n]=t;else throw new h(`Option --${n} requires a string value`)}}function Cn(n){return(t,e)=>{if(typeof t==="string")e[n]=t.split(",");else throw new h(`Option --${n} requires a string value`)}}function st(){console.log(`
23
+ See: https://bunup.arshadyaseen.com/#using-a-configuration-file-with-named-entries`,{muted:!0,verticalSpace:!0}),t.push({name:c,path:o})}else t.push({name:i,path:o}),e.add(i),r[i]=o}if(Array.isArray(n))for(let i of n){let o=A(i);s(o,i)}else if(typeof n==="object")Object.entries(n).forEach(([i,o])=>{s(i,o)});else{let i=A(n);s(i,n)}return t}function hn(n,t){return`[dir]/${n}${t}`}import{loadTsConfig as Qn}from"load-tsconfig";function xn(n){try{return Qn(".",n)}catch(t){return l.warn(`Failed to load tsconfig: ${m(t)}`),{path:n,data:{},files:[]}}}import Q from"node:path";async function yn(n){let t=[".ts",".js",".mjs",".cjs",".mts",".cts",".json",".jsonc"];for(let e of t){let r=Q.join(n,`bunup.config${e}`);try{if(!await Bun.file(r).exists())continue;let i=await Zn(r,e);if(!i)continue;return{configs:Fn(i,n),configFilePath:r}}catch(s){throw new y(`Failed to load config from ${r}: ${m(s)}`)}}return{configs:[],configFilePath:""}}async function Zn(n,t){if(t===".json"||t===".jsonc")return zn(n);return Xn(n)}async function zn(n){try{let t=await Bun.file(n).text(),e=JSON.parse(t);return e.bunup||e}catch(t){throw new Error(`Invalid JSON in config file. ${m(t)}`)}}async function Xn(n){try{let t=await import(`file://${n}`),e=t.default||t;if(!e)return l.warn(`No export found in ${n}. Make sure you're exporting your configuration.`),{};return e}catch(t){throw new Error(`Failed to import config file. ${m(t)}`)}}function Fn(n,t){let e=[];if(Vn(n))nt(n,t,e);else if(Array.isArray(n))tt(n,t,e);else if(n&&typeof n==="object")e.push({options:n,rootDir:t});else throw new Error("Invalid configuration format. Expected an object, array, or workspace configuration.");return e}function Vn(n){return Array.isArray(n)&&n.length>0&&n.every((t)=>typeof t==="object"&&t!==null&&("name"in t)&&("root"in t)&&("config"in t))}function nt(n,t,e){for(let r of n){let s=Q.resolve(t,r.root);if(Array.isArray(r.config))for(let i of r.config)e.push({options:{name:r.name,...i},rootDir:s});else e.push({options:{name:r.name,...r.config},rootDir:s})}}function tt(n,t,e){for(let r of n){if(!r||typeof r!=="object")throw new Error("Invalid configuration item. Expected an object.");e.push({options:r,rootDir:t})}}async function wn(n){let t=Q.join(n,"package.json");try{if(!await Bun.file(t).exists())return{packageJson:null,path:t};let r=await Bun.file(t).text();return{packageJson:JSON.parse(r),path:t}}catch(e){return l.warn(`Failed to load package.json at ${t}: ${m(e)}`),{packageJson:null,path:t}}}function bn(n,t){return{name:"bunup:external-plugin",setup(e){e.onResolve({filter:/.*/},(r)=>{let s=r.path;if(n.some((o)=>o.test(s))&&!t.some((o)=>o.test(s)))return{path:s,external:!0};return null})}}}var v=new Set;async function D(n,t){if(!n.entry||n.entry.length===0||!n.outDir)throw new y("Nothing to build. Please make sure you have provided a proper bunup configuration or cli arguments.");let{packageJson:e,path:r}=await wn(t);if(e)l.cli(`Using package.json: ${w(r)}`,{muted:!0});let s=e?.type,i=k(n,e),o=L(n),a=[bn(i,o)],c=T(n.entry),u=z(n,t),p=n.format.flatMap((f)=>c.map((x)=>{return et(n,t,x,f,s,a,u)}));if(await Promise.all(p),n.dts){let f=xn(n.preferredTsconfigPath);if(f.path)l.cli(`Using tsconfig: ${w(f.path)}`,{muted:!0});let x=n.format.filter((O)=>{if(O==="iife"&&!N(s)&&n.format.includes("cjs"))return!1;return!0}),$=typeof n.dts==="object"&&n.dts.entry?T(n.dts.entry):c;try{await Promise.all($.map(async(O)=>{let Rn=await dn(t,O.path,n,f,e);await Promise.all(x.map(async(Sn)=>{let jn=V(Sn,s),G=`${t}/${n.outDir}/${O.name}${jn}`;await Bun.write(G,Rn);let An=Bun.file(G).size||0;l.progress("DTS",w(G),P(An),n.name)}))}))}catch(O){throw new d(m(O))}}}async function et(n,t,e,r,s,i,o){let a=F(r,s),c=await Bun.build({...o,entrypoints:[`${t}/${e.path}`],format:r,naming:{entry:hn(e.name,a)},splitting:tn(n.splitting,r),plugins:i,throw:!1});if(!c.success)c.logs.forEach((f)=>{if(f.level==="error")throw new y(f.message);else if(f.level==="warning")l.warn(f.message);else if(f.level==="info")l.info(f.message)});let u=`${t}/${n.outDir}/${e.name}${a}`,p=Bun.file(u).size||0;l.progress(r.toUpperCase(),w(u),P(p),n.name)}var H="0.3.12";var $n="https://bun.sh/docs/installation",On="https://bunup.arshadyaseen.com/#cli-options";function b(n){return(t,e)=>{e[n]=t===!0?!0:t==="true"}}function S(n){return(t,e)=>{if(typeof t==="string")e[n]=t;else throw new h(`Option --${n} requires a string value`)}}function Cn(n){return(t,e)=>{if(typeof t==="string")e[n]=t.split(",");else throw new h(`Option --${n} requires a string value`)}}function st(){console.log(`
24
24
  Bunup - An extremely fast, zero-config bundler for JavaScript and TypeScript, powered by Bun.
25
25
  `),console.log("For more information on available options, visit:"),console.log(`\x1B[36m\x1B[4m${On}\x1B[0m
26
26
  `),process.exit(0)}function it(){console.log(H),process.exit(0)}var ot={name:{flags:["n","name"],handler:S("name")},format:{flags:["f","format"],handler:(n,t)=>{if(typeof n==="string")t.format=n.split(",");else throw new h("Option --format requires a string value")}},outDir:{flags:["o","out-dir"],handler:S("outDir")},minify:{flags:["m","minify"],handler:b("minify")},watch:{flags:["w","watch"],handler:b("watch")},dts:{flags:["d","dts"],handler:b("dts")},banner:{flags:["b","banner"],handler:S("banner")},footer:{flags:["f","footer"],handler:S("footer")},external:{flags:["e","external"],handler:Cn("external")},sourcemap:{flags:["sm","sourcemap"],handler:S("sourcemap")},target:{flags:["t","target"],handler:S("target")},minifyWhitespace:{flags:["mw","minify-whitespace"],handler:b("minifyWhitespace")},minifyIdentifiers:{flags:["mi","minify-identifiers"],handler:b("minifyIdentifiers")},minifySyntax:{flags:["ms","minify-syntax"],handler:b("minifySyntax")},clean:{flags:["c","clean"],handler:b("clean")},splitting:{flags:["s","splitting"],handler:b("splitting")},noExternal:{flags:["ne","no-external"],handler:Cn("noExternal")}},at={help:{flags:["h","help"],handler:()=>st()},version:{flags:["v","version"],handler:()=>it()}},U={};for(let n of Object.values(ot))if(n)for(let t of n.flags)U[t]=n.handler;for(let n of Object.values(at))for(let t of n.flags)U[t]=n.handler;function En(n){let t={},e={},r=0;while(r<n.length){let s=n[r];if(s.startsWith("--")){let i,o;if(s.includes("=")){let[a,c]=s.slice(2).split("=",2);i=a,o=c}else{i=s.slice(2);let a=n[r+1];if(o=a&&!a.startsWith("-")?a:!0,typeof o==="string")r++}if(i==="entry")if(typeof o==="string"){let a=A(o);if(e[a])l.warn(`Duplicate entry name '${a}' derived from '${o}'. Overwriting previous entry.`);e[a]=o}else throw new h("Option --entry requires a string value");else if(i.startsWith("entry.")){let a=i.slice(6);if(typeof o==="string"){if(e[a])l.warn(`Duplicate entry name '${a}' provided via --entry.${a}. Overwriting previous entry.`);e[a]=o}else throw new h(`Option --entry.${a} requires a string value`)}else{let a=U[i];if(a)a(o,t);else throw new h(`Unknown option: --${i}`)}}else if(s.startsWith("-")){let i=s.slice(1),o=n[r+1],a=o&&!o.startsWith("-")?o:!0;if(typeof a==="string")r++;let c=U[i];if(c)c(a,t);else throw new h(`Unknown option: -${i}`)}else{let i=A(s);if(e[i])l.warn(`Duplicate entry name '${i}' derived from positional argument '${s}'. Overwriting previous entry.`);e[i]=s}r++}if(Object.keys(e).length>0)t.entry=e;return t}(()=>{if(typeof Bun==="undefined")throw new h(`Bunup requires Bun to run.
package/build/index.d.mts CHANGED
@@ -12,23 +12,27 @@ type DtsOptions = {
12
12
  * Entry point files for TypeScript declaration file generation
13
13
  *
14
14
  * This can be:
15
+ * - A string path to a file
15
16
  * - An array of file paths
16
17
  * - An object where keys are output names and values are input file paths
17
18
  *
18
19
  * The key names are used for the generated declaration files.
19
- * For example, {custom: './src/index.ts'} will generate custom.d.ts
20
+ * For example, `{custom: 'src/index.ts'}` will generate `custom.d.ts`
20
21
  *
21
22
  * If not specified, the main entry points will be used for declaration file generation.
22
23
  *
23
- * If a string path is provided in an array, the file name (without extension)
24
+ * If it's a string or an array of strings, the file name (without extension)
24
25
  * will be used as the name for the output declaration file.
25
26
  *
26
27
  * @example
28
+ * // Using a string path
29
+ * entry: 'src/index.ts' // Generates index.d.ts
30
+ *
27
31
  * // Using string paths in an array
28
- * entry: ['./src/index.ts'] // Generates index.d.ts
32
+ * entry: ['src/index.ts'] // Generates index.d.ts
29
33
  *
30
34
  * // Using named outputs as an object
31
- * entry: { myModule: './src/index.ts', utils: './src/utility-functions.ts' } // Generates myModule.d.ts and utils.d.ts
35
+ * entry: { myModule: 'src/index.ts', utils: 'src/utility-functions.ts' } // Generates myModule.d.ts and utils.d.ts
32
36
  */
33
37
  entry?: Entry
34
38
  /**
@@ -46,21 +50,25 @@ interface BunupOptions {
46
50
  * Entry point files for the build
47
51
  *
48
52
  * This can be:
53
+ * - A string path to a file
49
54
  * - An array of file paths
50
55
  * - An object where keys are output names and values are input file paths
51
56
  *
52
57
  * The key names are used for the generated output files.
53
- * For example, {custom: './src/index.ts'} will generate custom.js
58
+ * For example, `{custom: 'src/index.ts'}` will generate `custom.js`
54
59
  *
55
- * If a string path is provided in an array, the file name (without extension)
60
+ * If it's a string or an array of strings, the file name (without extension)
56
61
  * will be used as the name for the output file.
57
62
  *
58
63
  * @example
64
+ * // Using a string path
65
+ * entry: 'src/index.ts' // Generates index.js
66
+ *
59
67
  * // Using string paths in an array
60
- * entry: ['./src/index.ts'] // Generates index.js
68
+ * entry: ['src/index.ts'] // Generates index.js
61
69
  *
62
70
  * // Using named outputs as an object
63
- * entry: { myModule: './src/index.ts', utils: './src/utility-functions.ts' } // Generates myModule.js and utils.js
71
+ * entry: { myModule: 'src/index.ts', utils: 'src/utility-functions.ts' } // Generates myModule.js and utils.js
64
72
  */
65
73
  entry: Entry;
66
74
  /**
package/build/index.d.ts CHANGED
@@ -12,23 +12,27 @@ type DtsOptions = {
12
12
  * Entry point files for TypeScript declaration file generation
13
13
  *
14
14
  * This can be:
15
+ * - A string path to a file
15
16
  * - An array of file paths
16
17
  * - An object where keys are output names and values are input file paths
17
18
  *
18
19
  * The key names are used for the generated declaration files.
19
- * For example, {custom: './src/index.ts'} will generate custom.d.ts
20
+ * For example, `{custom: 'src/index.ts'}` will generate `custom.d.ts`
20
21
  *
21
22
  * If not specified, the main entry points will be used for declaration file generation.
22
23
  *
23
- * If a string path is provided in an array, the file name (without extension)
24
+ * If it's a string or an array of strings, the file name (without extension)
24
25
  * will be used as the name for the output declaration file.
25
26
  *
26
27
  * @example
28
+ * // Using a string path
29
+ * entry: 'src/index.ts' // Generates index.d.ts
30
+ *
27
31
  * // Using string paths in an array
28
- * entry: ['./src/index.ts'] // Generates index.d.ts
32
+ * entry: ['src/index.ts'] // Generates index.d.ts
29
33
  *
30
34
  * // Using named outputs as an object
31
- * entry: { myModule: './src/index.ts', utils: './src/utility-functions.ts' } // Generates myModule.d.ts and utils.d.ts
35
+ * entry: { myModule: 'src/index.ts', utils: 'src/utility-functions.ts' } // Generates myModule.d.ts and utils.d.ts
32
36
  */
33
37
  entry?: Entry
34
38
  /**
@@ -46,21 +50,25 @@ interface BunupOptions {
46
50
  * Entry point files for the build
47
51
  *
48
52
  * This can be:
53
+ * - A string path to a file
49
54
  * - An array of file paths
50
55
  * - An object where keys are output names and values are input file paths
51
56
  *
52
57
  * The key names are used for the generated output files.
53
- * For example, {custom: './src/index.ts'} will generate custom.js
58
+ * For example, `{custom: 'src/index.ts'}` will generate `custom.js`
54
59
  *
55
- * If a string path is provided in an array, the file name (without extension)
60
+ * If it's a string or an array of strings, the file name (without extension)
56
61
  * will be used as the name for the output file.
57
62
  *
58
63
  * @example
64
+ * // Using a string path
65
+ * entry: 'src/index.ts' // Generates index.js
66
+ *
59
67
  * // Using string paths in an array
60
- * entry: ['./src/index.ts'] // Generates index.js
68
+ * entry: ['src/index.ts'] // Generates index.js
61
69
  *
62
70
  * // Using named outputs as an object
63
- * entry: { myModule: './src/index.ts', utils: './src/utility-functions.ts' } // Generates myModule.js and utils.js
71
+ * entry: { myModule: 'src/index.ts', utils: 'src/utility-functions.ts' } // Generates myModule.js and utils.js
64
72
  */
65
73
  entry: Entry;
66
74
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bunup",
3
- "version": "0.3.11",
3
+ "version": "0.3.12",
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",