@bunit/build 0.0.0 → 0.0.1
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.
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
|
|
2
|
+
import{d as P}from"./index-c1bnfgh1.mjs";import{resolve as x}from"path";function _(Q,V){let H=x(Q),I=V||process.cwd(),Y=H.replace(/\\/g,"/"),Z=I.replace(/\\/g,"/");return Y.replace(Z,".")}function W(Q){if(Array.isArray(Q)){let Y=0,Z=0;for(let J of Q){let{size:$,files:q}=W(J);Y+=$,Z+=q}return{size:Y,files:Z}}let V=0,H=0,I=Array.from(new Bun.Glob("**/*").scanSync({cwd:Q,absolute:!0}));for(let Y of I){let Z=Bun.file(Y);if(Z.size>0)V+=Z.size,H++}return{size:V,files:H}}import{fileURLToPath as n,pathToFileURL as i}from"url";import{isAbsolute as D,join as r,resolve as e}from"path";import{rm as t}from"fs/promises";import{builtinModules as z}from"module";import{mkdir as f,chmod as d}from"fs/promises";import{dirname as F,relative as L,join as M,basename as m,extname as p,resolve as k}from"path";import u from"unplugin-isolated-decl/esbuild";import U from"pretty-bytes";async function E(Q,V,H){let I=c(V.input,Q);if(V.stub){for(let[q,K]of Object.entries(I)){let X=M(Q.pkgDir,"dist",`${q}.mjs`);await f(F(X),{recursive:!0}),console.log(`[bundle] ${_(X)} (stub)`);let O=await Bun.file(K).text(),B=new Bun.Transpiler({loader:"ts"}).scan(O).exports.includes("default"),w=O.split(`
|
|
3
3
|
`)[0],N=w.startsWith("#!"),G=L(F(X),K);if(G=G.replace(/\\/g,"/"),await Bun.write(X,`${N?w+`
|
|
4
4
|
`:""}export * from "${G}";
|
|
5
5
|
${B?`export { default } from "${G}";
|
|
6
6
|
`:""}`),N)await d(X,493);await Bun.write(X.replace(/\.mjs$/,".d.mts"),`export * from "${G}";
|
|
7
7
|
${B?`export { default } from "${G}";
|
|
8
|
-
`:""}`)}return}let Y=[...z,...z.map((q)=>`node:${q}`),...[...Object.keys(Q.pkg.dependencies||{}),...Object.keys(Q.pkg.peerDependencies||{})].flatMap((q)=>[q])],Z={root:Q.pkgDir,entrypoints:Object.values(I),outdir:k(Q.pkgDir,V.outDir||"dist"),target:"bun",format:"esm",external:Y,minify:V.minify??!1,naming:{entry:"[name].mjs",chunk:"_chunks/[name].mjs"},splitting:!0,metafile:!0,plugins:V.dts!==!1?[u()]:[],...V.bun};await H.bunConfig?.(Z,Q);let J=await Bun.build(Z);if(!J.success){console.error("Build failed:");for(let q of J.logs)if(q.level==="error")console.error(` ${q.message}`);throw Error("Build failed")}await H.bunOutput?.(Z,Q);let $=[];for(let[q,K]of Object.entries(J.metafile.outputs)){if(!K.entryPoint)continue;if(q.endsWith(".ts"))continue;let X=q.replace(`${Z.outdir}${
|
|
8
|
+
`:""}`)}return}let Y=[...z,...z.map((q)=>`node:${q}`),...[...Object.keys(Q.pkg.dependencies||{}),...Object.keys(Q.pkg.peerDependencies||{})].flatMap((q)=>[q])],Z={root:Q.pkgDir,entrypoints:Object.values(I),outdir:k(Q.pkgDir,V.outDir||"dist"),target:"bun",format:"esm",external:Y,minify:V.minify??!1,naming:{entry:"[name].mjs",chunk:"_chunks/[name]-[hash].mjs"},splitting:!0,metafile:!0,plugins:V.dts!==!1?[u()]:[],...V.bun};await H.bunConfig?.(Z,Q);let J=await Bun.build(Z);if(!J.success){console.error("Build failed:");for(let q of J.logs)if(q.level==="error")console.error(` ${q.message}`);throw Error("Build failed")}await H.bunOutput?.(Z,Q);let $=[];for(let[q,K]of Object.entries(J.metafile.outputs)){if(!K.entryPoint)continue;if(q.endsWith(".ts"))continue;let X=q.replace(`${Z.outdir}${P("path").sep}`,""),O=K.exports||[],C=(K.imports||[]).filter((R)=>!R.path.startsWith(".")).map((R)=>R.path).sort();$.push({name:X,exports:O,deps:C,size:K.bytes,minSize:K.bytes,minGzipSize:K.bytes,sideEffectSize:K.bytes})}console.log(`
|
|
9
9
|
${$.map((q)=>`[bundle] ${_(M(Z.outdir,q.name),Q.pkgDir)}
|
|
10
10
|
Size: ${U(q.size)}, ${U(q.minSize)} minified, ${U(q.minGzipSize)} min+gzipped (Side effects: ${U(q.sideEffectSize)})
|
|
11
11
|
${q.exports.some((K)=>K!=="default")?`Exports: ${q.exports.join(", ")}
|
|
@@ -17,7 +17,7 @@ ${q.exports.some((K)=>K!=="default")?`Exports: ${q.exports.join(", ")}
|
|
|
17
17
|
[transform] ${_(V.outDir+"/")}${V.stub?" (stub)":""}
|
|
18
18
|
${a(J.map(($)=>_($)))}`)}function a(Q,V=process.stdout.columns||80){if(Q.length===0)return"";let I=Math.max(...Q.map((J)=>J.length))+2,Y=Math.max(1,Math.floor(V/I)),Z=[];for(let J=0;J<Q.length;J+=Y){let $=Q.slice(J,J+Y);Z.push($.map((q)=>q.padEnd(I)).join(""))}return Z.join(`
|
|
19
19
|
`)}async function s(Q,V,H){let I=await Bun.file(Q).text();if(V.stub){let q=new Bun.Transpiler({loader:"ts"}).scan(I).exports.includes("default"),K=l(j(H),Q);return K=K.replace(/\\/g,"/"),`export * from "${K}";${q?`
|
|
20
|
-
export { default } from "${K}";`:""}`}let Y={loader:V.transpiler?.loader||"ts",target:V.transpiler?.target||"bun",tsconfig:V.transpiler?.tsconfig};return new Bun.Transpiler(Y).transformSync(I)}import qq from"pretty-bytes";async function
|
|
20
|
+
export { default } from "${K}";`:""}`}let Y={loader:V.transpiler?.loader||"ts",target:V.transpiler?.target||"bun",tsconfig:V.transpiler?.tsconfig};return new Bun.Transpiler(Y).transformSync(I)}import qq from"pretty-bytes";async function Cq(Q){let V=Date.now(),H=A(Q.cwd),Y={pkg:await Kq(r(H,"package.json")).catch(()=>({})),pkgDir:H};console.log(`Building \`${Y.pkg.name||"<no name>"}\` (\`${Y.pkgDir}\`)`);let Z=Q.hooks||{};await Z.start?.(Y);let J=(Q.entries||[]).map((q)=>{let K;if(typeof q==="string"){let[X,O]=q.split(":");K=X.endsWith("/")?{type:"transform",input:X,outDir:O}:{type:"bundle",input:X.split(","),outDir:O}}else K=q;if(!K.input)throw Error(`Build entry missing \`input\`: ${JSON.stringify(K,null,2)}`);return K={...K},K.outDir=A(K.outDir||"dist",H),K.input=Array.isArray(K.input)?K.input.map((X)=>A(X,H)):A(K.input,H),K});await Z.entries?.(J,Y);let $=[];for(let q of J.map((K)=>K.outDir).sort((K,X)=>(K??"").localeCompare(X??"")))if(!$.some((K)=>q.startsWith(K)))$.push(q);for(let q of $)console.log(`Cleaning up \`${_(q)}\``),await t(q,{recursive:!0,force:!0});for(let q of J)await(q.type==="bundle"?E(Y,q,Z):b(Y,q));if(await Z.end?.(Y),!J.every((q)=>q.stub)){let q=W($);console.log(`
|
|
21
21
|
\u03A3 Total dist byte size: ${qq(q.size)} (${q.files} files)`)}console.log(`
|
|
22
22
|
build finished in ${Date.now()-V}ms`)}function A(Q,V){return typeof Q==="string"&&D(Q)?Q:Q instanceof URL?n(Q):e(V||".",Q||".")}function Kq(Q){return import(D(Q)?i(Q).href:Q,{with:{type:"json"}}).then((H)=>H.default)}
|
|
23
|
-
export{_ as a,W as b,
|
|
23
|
+
export{_ as a,W as b,Cq as c};
|
package/dist/cli.mjs
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
#!/usr/bin/env bun
|
|
2
2
|
// @bun
|
|
3
|
-
import{c as d}from"./_chunks/index.mjs";import{defineCommand as u,runMain as l}from"citty";import{loadConfig as p}from"c12";var c=u({meta:{name:"build",version:"0.0.0",description:"Build your project with Bun"},args:{dir:{type:"string",description:"Project root directory",default:"."},stub:{type:"boolean",description:"Generate stub builds (re-export source files)",default:!1},entries:{type:"positional",description:"Build entries (e.g., src/index.ts or src/)",required:!1}},async run({args:i}){let{config:r={}}=await p({name:"build",configFile:"build.config",cwd:i.dir}),n=i.entries?Array.isArray(i.entries)?i.entries:[i.entries]:r.entries||[],o=n.map((e)=>{if(typeof e==="string"){let[t,s]=e.split(":");return t.endsWith("/")?{type:"transform",input:t,outDir:s}:{type:"bundle",input:t.split(","),outDir:s}}return e});if(i.stub)for(let e of o)e.stub=!0;if(n.length===0)console.error("No build entries specified."),process.exit(1);await d({cwd:i.dir,...r,entries:o})}});l(c);
|
|
3
|
+
import{c as d}from"./_chunks/index-sh9r61x3.mjs";import"./_chunks/index-c1bnfgh1.mjs";import{defineCommand as u,runMain as l}from"citty";import{loadConfig as p}from"c12";var c=u({meta:{name:"build",version:"0.0.0",description:"Build your project with Bun"},args:{dir:{type:"string",description:"Project root directory",default:"."},stub:{type:"boolean",description:"Generate stub builds (re-export source files)",default:!1},entries:{type:"positional",description:"Build entries (e.g., src/index.ts or src/)",required:!1}},async run({args:i}){let{config:r={}}=await p({name:"build",configFile:"build.config",cwd:i.dir}),n=i.entries?Array.isArray(i.entries)?i.entries:[i.entries]:r.entries||[],o=n.map((e)=>{if(typeof e==="string"){let[t,s]=e.split(":");return t.endsWith("/")?{type:"transform",input:t,outDir:s}:{type:"bundle",input:t.split(","),outDir:s}}return e});if(i.stub)for(let e of o)e.stub=!0;if(n.length===0)console.error("No build entries specified."),process.exit(1);await d({cwd:i.dir,...r,entries:o})}});l(c);
|
package/dist/config.d.ts
ADDED
package/dist/config.mjs
ADDED
package/dist/index.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
import{a as g,b as j,c as k}from"./_chunks/index.mjs";export{g as fmtPath,k as build,j as analyzeDir};
|
|
2
|
+
import{a as g,b as j,c as k}from"./_chunks/index-sh9r61x3.mjs";import"./_chunks/index-c1bnfgh1.mjs";export{g as fmtPath,k as build,j as analyzeDir};
|