@xyrah/oven 0.0.4 → 0.0.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/LICENSE +1 -1
- package/README.md +16 -3
- package/dist/index.d.ts +13 -2
- package/dist/index.js +2 -2
- package/package.json +2 -1
package/LICENSE
CHANGED
package/README.md
CHANGED
|
@@ -8,7 +8,7 @@ Bun × Rollup package builder — a small toolkit for building packages with [Bu
|
|
|
8
8
|
|
|
9
9
|
## Requirements
|
|
10
10
|
|
|
11
|
-
- [Bun](https://bun.sh/) **≥ 1.3** — the implementation uses `Bun.build()` (including its `jsx` and `
|
|
11
|
+
- [Bun](https://bun.sh/) **≥ 1.3** — the implementation uses `Bun.build()` (including its `jsx`, `tsconfig` and `sourcemap` options) and `Bun.spawn()`.
|
|
12
12
|
- TypeScript available as `tsc` if you use `Roll.tsc()`.
|
|
13
13
|
|
|
14
14
|
## Install
|
|
@@ -41,18 +41,31 @@ CSS imports use the file loader by default, preserving Oven's existing behavior.
|
|
|
41
41
|
new Oven({ files: ["app.tsx"], css: "bundle" });
|
|
42
42
|
```
|
|
43
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:
|
|
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`, `sourcemap`, and `tsconfig`). For example:
|
|
45
45
|
|
|
46
46
|
```ts
|
|
47
47
|
new Oven({
|
|
48
48
|
files: ["app.tsx"],
|
|
49
49
|
css: "bundle",
|
|
50
|
-
build: { format: "esm",
|
|
50
|
+
build: { format: "esm", publicPath: "/assets/" },
|
|
51
51
|
});
|
|
52
52
|
```
|
|
53
53
|
|
|
54
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
55
|
|
|
56
|
+
### Source maps
|
|
57
|
+
|
|
58
|
+
Pass `sourcemap` to forward Bun's source-map mode. Omit it to keep Bun's default (no map). The accepted values are `true`, `false`, `"none"`, `"linked"`, `"external"` and `"inline"`:
|
|
59
|
+
|
|
60
|
+
```ts
|
|
61
|
+
new Oven({
|
|
62
|
+
files: ["app.tsx"],
|
|
63
|
+
sourcemap: "external",
|
|
64
|
+
});
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
`"external"` emits a `.map` file without a `sourceMappingURL` comment, `"linked"` emits the map and adds the comment, and `"inline"` embeds the map in the JavaScript output. Choose a mode that matches how the package is distributed; publishing map data is the caller's decision.
|
|
68
|
+
|
|
56
69
|
### JSX
|
|
57
70
|
|
|
58
71
|
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,8 +28,16 @@ type _jsx = {
|
|
|
28
28
|
/** Emit the development runtime (`jsxDEV`) instead of the production one. */
|
|
29
29
|
development?: boolean;
|
|
30
30
|
};
|
|
31
|
+
/**
|
|
32
|
+
* Source-map mode forwarded to `Bun.build`.
|
|
33
|
+
*
|
|
34
|
+
* Prefer `"external"` for build pipelines that must not reference maps from the
|
|
35
|
+
* emitted JavaScript; `"linked"` and `"inline"` add a `sourceMappingURL`
|
|
36
|
+
* comment, and `"inline"` embeds the whole map in the JavaScript bundle.
|
|
37
|
+
*/
|
|
38
|
+
type _sourcemap = "none" | "linked" | "inline" | "external" | boolean;
|
|
31
39
|
/** 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">;
|
|
40
|
+
type _build = Omit<Parameters<typeof Bun.build>[0], "entrypoints" | "outdir" | "target" | "splitting" | "minify" | "define" | "packages" | "external" | "drop" | "plugins" | "naming" | "jsx" | "sourcemap" | "tsconfig">;
|
|
33
41
|
type ovenOptions = {
|
|
34
42
|
files?: string[];
|
|
35
43
|
target?: "browser" | "bun" | "node";
|
|
@@ -47,6 +55,8 @@ type ovenOptions = {
|
|
|
47
55
|
successFN?: () => Promise<void>;
|
|
48
56
|
/** JSX transform options forwarded to `Bun.build`; unset keys keep Bun's defaults. */
|
|
49
57
|
jsx?: _jsx;
|
|
58
|
+
/** Source-map mode forwarded to `Bun.build`; omit to keep Bun's default (no map). */
|
|
59
|
+
sourcemap?: _sourcemap;
|
|
50
60
|
/** Custom `tsconfig.json` path (or directory containing one) used by the build. */
|
|
51
61
|
tsconfig?: string;
|
|
52
62
|
/** CSS handling for CSS imports: emit a bundled stylesheet or treat CSS as an asset file. */
|
|
@@ -71,12 +81,13 @@ declare class Oven {
|
|
|
71
81
|
target: "browser" | "bun" | "node";
|
|
72
82
|
define: Record<string, any>;
|
|
73
83
|
jsx?: _jsx | undefined;
|
|
84
|
+
sourcemap?: _sourcemap | undefined;
|
|
74
85
|
tsconfig?: string | undefined;
|
|
75
86
|
css: "bundle" | "file";
|
|
76
87
|
buildOptions: _build;
|
|
77
88
|
private clearing?;
|
|
78
89
|
protected successFN?: (() => Promise<void>) | undefined;
|
|
79
|
-
constructor({ files, target, dir, out, split, base, define, external, packages, drop, plugins, hashAsset, minify, successFN, jsx, tsconfig, css, build: buildOptions, }?: ovenOptions);
|
|
90
|
+
constructor({ files, target, dir, out, split, base, define, external, packages, drop, plugins, hashAsset, minify, successFN, jsx, sourcemap, tsconfig, css, build: buildOptions, }?: ovenOptions);
|
|
80
91
|
set onsuccess(fn: () => Promise<void>);
|
|
81
92
|
build(status?: watchStatus): Promise<this>;
|
|
82
93
|
watch(condition?: (filename: string) => boolean): Promise<fs.FSWatcher>;
|
package/dist/index.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
import{existsSync as
|
|
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,
|
|
2
|
+
import{existsSync as _,mkdirSync as D}from"fs";var f=(t)=>{if(_(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 I,unlink as N}from"fs/promises";import F 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;sourcemap;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,sourcemap:j,tsconfig:k,css:R="file",build:P={}}={}){this.target=s,this.dir=i+r,this.packages=u,this.jsx=v,this.sourcemap=j,this.tsconfig=k,this.css=R,this.buildOptions=P,this.out=(e?e:s==="browser"?"./client":"./dist")+r,this.split=n,this.files=t.map((S)=>(this.dir+"/"+S).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.sourcemap===void 0?{}:{sourcemap:this.sourcemap},...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:{...C(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=F.join(i,r);if((await I(o)).isDirectory())await s(o);else await N(o)}if((await m(i)).length===0)await A(i)};return await s(this.out),this}}var C=(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 W}from"rollup";import{dts as q}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 W({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,q(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
|
+
"version": "0.0.5",
|
|
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",
|
|
@@ -20,6 +20,7 @@
|
|
|
20
20
|
"ts": "cp ../../misc/tsconfig.json ./;",
|
|
21
21
|
"init": "bun run dirs && bun run ts;",
|
|
22
22
|
"build": "bun run builder.ts",
|
|
23
|
+
"test": "bun test test",
|
|
23
24
|
"prepublishOnly": "bun run builder.ts"
|
|
24
25
|
},
|
|
25
26
|
"keywords": [
|