@xyrah/oven 0.0.3 → 0.0.4

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
@@ -35,6 +35,24 @@ await oven.build();
35
35
 
36
36
  `files` are entrypoints relative to `dir` (default `["index.ts"]`). The default output directory is `./dist` for `target: "bun"` and `./client` for `target: "browser"`. Set `split: true` to let Bun emit shared chunks; with one entrypoint and `split: false` you get a single bundle. A success callback can be set with the `successFN` option or the `onsuccess` setter.
37
37
 
38
+ CSS imports use the file loader by default, preserving Oven's existing behavior. Choose `css: "bundle"` to let Bun bundle imported CSS into a stylesheet associated with the JavaScript entry:
39
+
40
+ ```ts
41
+ new Oven({ files: ["app.tsx"], css: "bundle" });
42
+ ```
43
+
44
+ Additional `Bun.build()` settings are available through `build`, excluding options already provided by Oven (`entrypoints`, `outdir`, `target`, `splitting`, `minify`, `define`, `packages`, `external`, `drop`, `plugins`, `naming`, `jsx`, and `tsconfig`). For example:
45
+
46
+ ```ts
47
+ new Oven({
48
+ files: ["app.tsx"],
49
+ css: "bundle",
50
+ build: { format: "esm", sourcemap: "external", publicPath: "/assets/" },
51
+ });
52
+ ```
53
+
54
+ Oven still controls the options listed above. The `build` object is spread first, and Oven's corresponding settings take precedence. Loader overrides in `build.loader` apply to other extensions; Oven sets `.css` from the `css` option.
55
+
38
56
  ### JSX
39
57
 
40
58
  By default JSX follows Bun's defaults, which read your project's `tsconfig.json`. Point `jsx` and `jsxImportSource` at your runtime of choice — for example [`yvee`](https://www.npmjs.com/package/yvee):
package/dist/index.d.ts CHANGED
@@ -28,9 +28,11 @@ type _jsx = {
28
28
  /** Emit the development runtime (`jsxDEV`) instead of the production one. */
29
29
  development?: boolean;
30
30
  };
31
+ /** Bun.build options not already represented by Oven's top-level options. */
32
+ type _build = Omit<Parameters<typeof Bun.build>[0], "entrypoints" | "outdir" | "target" | "splitting" | "minify" | "define" | "packages" | "external" | "drop" | "plugins" | "naming" | "jsx" | "tsconfig">;
31
33
  type ovenOptions = {
32
34
  files?: string[];
33
- target?: "browser" | "bun";
35
+ target?: "browser" | "bun" | "node";
34
36
  define?: Record<string, any>;
35
37
  hashAsset?: boolean;
36
38
  external?: string[];
@@ -47,6 +49,10 @@ type ovenOptions = {
47
49
  jsx?: _jsx;
48
50
  /** Custom `tsconfig.json` path (or directory containing one) used by the build. */
49
51
  tsconfig?: string;
52
+ /** CSS handling for CSS imports: emit a bundled stylesheet or treat CSS as an asset file. */
53
+ css?: "bundle" | "file";
54
+ /** Additional `Bun.build()` options not covered by Oven's top-level options. */
55
+ build?: _build;
50
56
  };
51
57
  declare function watch(dir: string, callback: (filename: string) => void | Promise<void>, condition?: (filename: string) => boolean): Promise<fs.FSWatcher>;
52
58
  declare class Oven {
@@ -62,13 +68,15 @@ declare class Oven {
62
68
  plugins: BunPlugin[];
63
69
  exclude: string[];
64
70
  clearAll: boolean;
65
- target: string;
71
+ target: "browser" | "bun" | "node";
66
72
  define: Record<string, any>;
67
73
  jsx?: _jsx | undefined;
68
74
  tsconfig?: string | undefined;
75
+ css: "bundle" | "file";
76
+ buildOptions: _build;
69
77
  private clearing?;
70
78
  protected successFN?: (() => Promise<void>) | undefined;
71
- constructor({ files, target, dir, out, split, base, define, external, packages, drop, plugins, hashAsset, minify, successFN, jsx, tsconfig, }?: ovenOptions);
79
+ constructor({ files, target, dir, out, split, base, define, external, packages, drop, plugins, hashAsset, minify, successFN, jsx, tsconfig, css, build: buildOptions, }?: ovenOptions);
72
80
  set onsuccess(fn: () => Promise<void>);
73
81
  build(status?: watchStatus): Promise<this>;
74
82
  watch(condition?: (filename: string) => boolean): Promise<fs.FSWatcher>;
package/dist/index.js CHANGED
@@ -1,3 +1,3 @@
1
1
  // @bun
2
- import{existsSync as k,mkdirSync as S}from"fs";var d=(t)=>{if(k(t))return!0;return S(t,{recursive:!0}),!0},l=(t)=>{let s=new Date().toLocaleTimeString();console.log(`${t} @ ${s}`)};import{watch as D}from"fs";import{readdir as m,rmdir as P,stat as A,unlink as B}from"fs/promises";import I from"path";async function y(t,s,i=()=>!0){let e=0,n=D(t,{recursive:!0},async(r,o)=>{if(!o||!i(o))return;let a=Date.now();if(a-e<1000)return;e=a;try{await s(o)}catch(u){console.error(u)}});return process.on("SIGINT",()=>{console.log(`
3
- watcher closed...`),n.close(),process.exit(0)}),n}class b{dir;out;split;minify;hashAsset;drop;files;external;packages;plugins;exclude=[];clearAll=!1;target;define={};jsx;tsconfig;clearing=!1;successFN;constructor({files:t=["."],target:s="bun",dir:i="./src",out:e,split:n=!0,base:r="",define:o={},external:a=[],packages:u="bundle",drop:p=[],plugins:f=[],hashAsset:g,minify:x={},successFN:O,jsx:v,tsconfig:j}={}){this.target=s,this.dir=i+r,this.packages=u,this.jsx=v,this.tsconfig=j,this.out=(e?e:s==="browser"?"./client":"./dist")+r,this.split=n,this.files=t.map((R)=>(this.dir+"/"+R).replaceAll("//","/")),d(this.out),this.hashAsset=g===void 0?!1:g,this.minify={identifiers:!0,whitespace:!0,syntax:!0},this.external=a,this.drop=p,this.plugins=f,this.successFN=O,Object.assign(this.minify,x),Object.assign(this.define,o)}set onsuccess(t){this.successFN=t}async build(t={building:!1}){let s=`[dir]/[name]${this.hashAsset?"-[hash]":""}.[ext]`;if(this.files.length)try{let i=await Bun.build({...this.jsx===void 0?{}:{jsx:this.jsx},...this.tsconfig===void 0?{}:{tsconfig:this.tsconfig},entrypoints:this.files,outdir:this.out,splitting:this.split,minify:this.minify,target:this.target??"browser",naming:{chunk:"[dir]/[name]-[hash].[ext]",entry:"[dir]/[name].[ext]",asset:s},define:{...N(this.define)},loader:{".css":"file"},packages:this.packages,external:this.external,drop:this.drop,plugins:this.plugins});if(i.success)try{await this.successFN?.(),l("builder"),t.building=!1}catch(e){console.log(e)}else console.log(i.logs)}catch(i){t.building=!1,console.log(i)}return this}async watch(t=()=>!0){let s={building:!1};return y(this.dir,async()=>{if(s.building)return;s.building=!0,this.clearing&&await this.clear();try{await this.build(s)}catch(i){s.building=!1,console.error(i)}},t)}async clear(t={exclude:[]}){if(t.exclude&&t.exclude.length)this.exclude.push(...t.exclude);if(t.all!==void 0)this.clearAll=t.all;this.clearing=!0;let s=async(i)=>{let e=await m(i);for(let r of e){if(r.startsWith(".")||!this.clearAll&&(r.endsWith(".html")||this.exclude.includes(r)))continue;let o=I.join(i,r);if((await A(o)).isDirectory())await s(o);else await B(o)}if((await m(i)).length===0)await P(i)};return await s(this.out),this}}var N=(t)=>Object.fromEntries(Object.entries(t).map(([s,i])=>{let e=i;if(typeof i==="function")e=i();return[s,JSON.stringify(e)]}));import{rollup as F}from"rollup";import{dts as _}from"rollup-plugin-dts";import c from"path";async function h(t,s){let i=t.split(";");for(let e of i){let n=e.trim().split(" ");await Bun.spawn(n).exited}s&&l("cmd")}class w{log;warnings;plugins;tsconfig;alias;dir;out;input;options;constructor(t){let{log:s,dir:i="./types",out:e="./dist",input:n,plugins:r,tsconfig:o,warnings:a=!1,...u}=t;if(this.dir=i,this.out=e,this.warnings=a,this.tsconfig=o&&c.resolve(o),typeof n==="object")if(Array.isArray(n))this.input=n.map((p)=>c.resolve(this.dir,p));else{let p=Object.entries(n).map(([f,g])=>[f,c.resolve(this.dir,g)]);this.input=Object.fromEntries(p)}else this.input=c.resolve(this.dir,n??"");this.plugins=r?Array.isArray(r)?[...r]:[r]:[],this.options=u,this.log=Boolean(s),delete t.log}paths(t={}){let s=Object.entries(t).map(([i,e])=>({find:i,replacement:c.resolve(this.dir,e)}));return this.alias={name:"oven-declaration-alias",async resolveId(i,e){let n=s.find(({find:o})=>i===o||i.startsWith(`${o}/`));if(!n)return null;let r=n.replacement+i.slice(n.find.length);return this.resolve(r,e,{skipSelf:!0})}},this}async tsc(t={}){let{clear:s,path:i}=t;if(s)await h(`rm -r ${this.dir}`);await h("tsc"+(i?` -p ${i}`:""))}async output(t){t.file&&=c.resolve(this.out,t.file),t.format??="es";try{let s=await F({input:this.input,...this.options,onwarn:(i,e)=>{if(!this.warnings)return;if(this.options.onwarn)this.options.onwarn(i,e);else e(i)},plugins:[...this.plugins,this.alias,_(this.tsconfig?{tsconfig:this.tsconfig}:{})]});await s.write(t),await s.close(),this.log&&l("rollup")}catch(s){console.error("Build failed:",s)}}}export{h as Cmd,b as Oven,w as Roll,y as watch};
2
+ import{existsSync as S,mkdirSync as D}from"fs";var f=(t)=>{if(S(t))return!0;return D(t,{recursive:!0}),!0},a=(t)=>{let s=new Date().toLocaleTimeString();console.log(`${t} @ ${s}`)};import{watch as B}from"fs";import{readdir as m,rmdir as A,stat as _,unlink as I}from"fs/promises";import N from"path";async function b(t,s,i=()=>!0){let e=0,n=B(t,{recursive:!0},async(r,o)=>{if(!o||!i(o))return;let l=Date.now();if(l-e<1000)return;e=l;try{await s(o)}catch(u){console.error(u)}});return process.on("SIGINT",()=>{console.log(`
3
+ watcher closed...`),n.close(),process.exit(0)}),n}class y{dir;out;split;minify;hashAsset;drop;files;external;packages;plugins;exclude=[];clearAll=!1;target;define={};jsx;tsconfig;css;buildOptions;clearing=!1;successFN;constructor({files:t=["."],target:s="bun",dir:i="./src",out:e,split:n=!0,base:r="",define:o={},external:l=[],packages:u="bundle",drop:p=[],plugins:h=[],hashAsset:d,minify:w={},successFN:O,jsx:v,tsconfig:j,css:R="file",build:k={}}={}){this.target=s,this.dir=i+r,this.packages=u,this.jsx=v,this.tsconfig=j,this.css=R,this.buildOptions=k,this.out=(e?e:s==="browser"?"./client":"./dist")+r,this.split=n,this.files=t.map((P)=>(this.dir+"/"+P).replaceAll("//","/")),f(this.out),this.hashAsset=d===void 0?!1:d,this.minify={identifiers:!0,whitespace:!0,syntax:!0},this.external=l,this.drop=p,this.plugins=h,this.successFN=O,Object.assign(this.minify,w),Object.assign(this.define,o)}set onsuccess(t){this.successFN=t}async build(t={building:!1}){let s=`[dir]/[name]${this.hashAsset?"-[hash]":""}.[ext]`;if(this.files.length)try{let i=await Bun.build({...this.buildOptions,...this.jsx===void 0?{}:{jsx:this.jsx},...this.tsconfig===void 0?{}:{tsconfig:this.tsconfig},entrypoints:this.files,outdir:this.out,splitting:this.split,minify:this.minify,target:this.target,naming:{chunk:"[dir]/[name]-[hash].[ext]",entry:"[dir]/[name].[ext]",asset:s},define:{...F(this.define)},loader:{...this.buildOptions.loader,".css":this.css==="bundle"?"css":"file"},packages:this.packages,external:this.external,drop:this.drop,plugins:this.plugins});if(i.success)try{await this.successFN?.(),a("builder"),t.building=!1}catch(e){console.log(e)}else console.log(i.logs)}catch(i){t.building=!1,console.log(i)}return this}async watch(t=()=>!0){let s={building:!1};return b(this.dir,async()=>{if(s.building)return;s.building=!0,this.clearing&&await this.clear();try{await this.build(s)}catch(i){s.building=!1,console.error(i)}},t)}async clear(t={exclude:[]}){if(t.exclude&&t.exclude.length)this.exclude.push(...t.exclude);if(t.all!==void 0)this.clearAll=t.all;this.clearing=!0;let s=async(i)=>{let e=await m(i);for(let r of e){if(r.startsWith(".")||!this.clearAll&&(r.endsWith(".html")||this.exclude.includes(r)))continue;let o=N.join(i,r);if((await _(o)).isDirectory())await s(o);else await I(o)}if((await m(i)).length===0)await A(i)};return await s(this.out),this}}var F=(t)=>Object.fromEntries(Object.entries(t).map(([s,i])=>{let e=i;if(typeof i==="function")e=i();return[s,JSON.stringify(e)]}));import{rollup as C}from"rollup";import{dts as W}from"rollup-plugin-dts";import c from"path";async function g(t,s){let i=t.split(";");for(let e of i){let n=e.trim().split(" ");await Bun.spawn(n).exited}s&&a("cmd")}class x{log;warnings;plugins;tsconfig;alias;dir;out;input;options;constructor(t){let{log:s,dir:i="./types",out:e="./dist",input:n,plugins:r,tsconfig:o,warnings:l=!1,...u}=t;if(this.dir=i,this.out=e,this.warnings=l,this.tsconfig=o&&c.resolve(o),typeof n==="object")if(Array.isArray(n))this.input=n.map((p)=>c.resolve(this.dir,p));else{let p=Object.entries(n).map(([h,d])=>[h,c.resolve(this.dir,d)]);this.input=Object.fromEntries(p)}else this.input=c.resolve(this.dir,n??"");this.plugins=r?Array.isArray(r)?[...r]:[r]:[],this.options=u,this.log=Boolean(s),delete t.log}paths(t={}){let s=Object.entries(t).map(([i,e])=>({find:i,replacement:c.resolve(this.dir,e)}));return this.alias={name:"oven-declaration-alias",async resolveId(i,e){let n=s.find(({find:o})=>i===o||i.startsWith(`${o}/`));if(!n)return null;let r=n.replacement+i.slice(n.find.length);return this.resolve(r,e,{skipSelf:!0})}},this}async tsc(t={}){let{clear:s,path:i}=t;if(s)await g(`rm -r ${this.dir}`);await g("tsc"+(i?` -p ${i}`:""))}async output(t){t.file&&=c.resolve(this.out,t.file),t.format??="es";try{let s=await C({input:this.input,...this.options,onwarn:(i,e)=>{if(!this.warnings)return;if(this.options.onwarn)this.options.onwarn(i,e);else e(i)},plugins:[...this.plugins,this.alias,W(this.tsconfig?{tsconfig:this.tsconfig}:{})]});await s.write(t),await s.close(),this.log&&a("rollup")}catch(s){console.error("Build failed:",s)}}}export{g as Cmd,y as Oven,x as Roll,b as watch};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xyrah/oven",
3
- "version": "0.0.3",
3
+ "version": "0.0.4",
4
4
  "description": "Bun based bundler utility: bundle JS with Bun.build, declaration files with Rollup, and run commands.",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",