bundle-budget-lite 0.1.0

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 ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Tejas Kadam
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,41 @@
1
+ # bundle-budget-lite
2
+
3
+ Checks file sizes against a budget config and reports pass/fail per entry — pluggable size source, no bundler coupling, ideal for CI.
4
+
5
+ ## Install
6
+
7
+ ```bash
8
+ npm install bundle-budget-lite
9
+ ```
10
+
11
+ ## Quick start
12
+
13
+ ```ts
14
+ import { checkBudget, hasFailures, formatReport } from 'bundle-budget-lite';
15
+ import { statSync } from 'fs';
16
+
17
+ const entries = [
18
+ { name: 'main.js', maxBytes: 100_000, warnBytes: 80_000 },
19
+ { name: 'vendor.js', maxBytes: 250_000 }
20
+ ];
21
+
22
+ const sizes = Object.fromEntries(entries.map((e) => [e.name, statSync(`dist/${e.name}`).size]));
23
+ const results = checkBudget(entries, sizes);
24
+
25
+ console.log(formatReport(results));
26
+ if (hasFailures(results)) process.exit(1);
27
+ ```
28
+
29
+ ## Why bundle-budget-lite
30
+
31
+ Bundle size budgets are usually baked into a specific bundler's plugin ecosystem, which makes them awkward to reuse across projects or CI systems. bundle-budget-lite takes the size numbers as plain input — a `Record<string, number>` you can build from `fs.statSync`, a bundler's stats output, or a gzip size check — and just does the comparison: pass, warn (below max but past an optional warn threshold), fail (over max), or missing (no size reported for that entry). `hasFailures` gives you a one-line CI gate, and `formatReport` renders a readable summary.
32
+
33
+ ## API
34
+
35
+ - `checkBudget(entries, sizes)` — returns one `BudgetResult` per entry with `status` (`pass` | `warn` | `fail` | `missing`) and `overBytes`.
36
+ - `hasFailures(results)` — true if any result is `fail`.
37
+ - `formatReport(results)` — renders a plain-text summary, one line per entry.
38
+
39
+ ## License
40
+
41
+ MIT
@@ -0,0 +1,26 @@
1
+ interface BudgetEntry {
2
+ /** A label or glob-like path identifying the artifact (informational; matching is by SizeSource key). */
3
+ name: string;
4
+ /** Maximum allowed size in bytes. */
5
+ maxBytes: number;
6
+ /** Optional warning threshold in bytes, below maxBytes, that produces a 'warn' status instead of 'pass'. */
7
+ warnBytes?: number;
8
+ }
9
+ type SizeSource = Record<string, number>;
10
+ type BudgetStatus = 'pass' | 'warn' | 'fail' | 'missing';
11
+ interface BudgetResult {
12
+ name: string;
13
+ actualBytes: number | null;
14
+ maxBytes: number;
15
+ warnBytes?: number;
16
+ status: BudgetStatus;
17
+ overBytes: number;
18
+ }
19
+ /** Checks a set of budget entries against actual sizes, returning one result per entry. */
20
+ declare function checkBudget(entries: BudgetEntry[], sizes: SizeSource): BudgetResult[];
21
+ /** True if any result has status 'fail' (useful as a CI exit-code gate). */
22
+ declare function hasFailures(results: BudgetResult[]): boolean;
23
+ /** Renders a plain-text summary table, one line per result. */
24
+ declare function formatReport(results: BudgetResult[]): string;
25
+
26
+ export { type BudgetEntry, type BudgetResult, type BudgetStatus, type SizeSource, checkBudget, formatReport, hasFailures };
@@ -0,0 +1,26 @@
1
+ interface BudgetEntry {
2
+ /** A label or glob-like path identifying the artifact (informational; matching is by SizeSource key). */
3
+ name: string;
4
+ /** Maximum allowed size in bytes. */
5
+ maxBytes: number;
6
+ /** Optional warning threshold in bytes, below maxBytes, that produces a 'warn' status instead of 'pass'. */
7
+ warnBytes?: number;
8
+ }
9
+ type SizeSource = Record<string, number>;
10
+ type BudgetStatus = 'pass' | 'warn' | 'fail' | 'missing';
11
+ interface BudgetResult {
12
+ name: string;
13
+ actualBytes: number | null;
14
+ maxBytes: number;
15
+ warnBytes?: number;
16
+ status: BudgetStatus;
17
+ overBytes: number;
18
+ }
19
+ /** Checks a set of budget entries against actual sizes, returning one result per entry. */
20
+ declare function checkBudget(entries: BudgetEntry[], sizes: SizeSource): BudgetResult[];
21
+ /** True if any result has status 'fail' (useful as a CI exit-code gate). */
22
+ declare function hasFailures(results: BudgetResult[]): boolean;
23
+ /** Renders a plain-text summary table, one line per result. */
24
+ declare function formatReport(results: BudgetResult[]): string;
25
+
26
+ export { type BudgetEntry, type BudgetResult, type BudgetStatus, type SizeSource, checkBudget, formatReport, hasFailures };
package/dist/index.js ADDED
@@ -0,0 +1,71 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/index.ts
21
+ var index_exports = {};
22
+ __export(index_exports, {
23
+ checkBudget: () => checkBudget,
24
+ formatReport: () => formatReport,
25
+ hasFailures: () => hasFailures
26
+ });
27
+ module.exports = __toCommonJS(index_exports);
28
+ function checkBudget(entries, sizes) {
29
+ return entries.map((entry) => {
30
+ const actualBytes = Object.prototype.hasOwnProperty.call(sizes, entry.name) ? sizes[entry.name] : null;
31
+ if (actualBytes === null) {
32
+ return { name: entry.name, actualBytes: null, maxBytes: entry.maxBytes, warnBytes: entry.warnBytes, status: "missing", overBytes: 0 };
33
+ }
34
+ if (actualBytes > entry.maxBytes) {
35
+ return {
36
+ name: entry.name,
37
+ actualBytes,
38
+ maxBytes: entry.maxBytes,
39
+ warnBytes: entry.warnBytes,
40
+ status: "fail",
41
+ overBytes: actualBytes - entry.maxBytes
42
+ };
43
+ }
44
+ if (entry.warnBytes !== void 0 && actualBytes > entry.warnBytes) {
45
+ return { name: entry.name, actualBytes, maxBytes: entry.maxBytes, warnBytes: entry.warnBytes, status: "warn", overBytes: 0 };
46
+ }
47
+ return { name: entry.name, actualBytes, maxBytes: entry.maxBytes, warnBytes: entry.warnBytes, status: "pass", overBytes: 0 };
48
+ });
49
+ }
50
+ function hasFailures(results) {
51
+ return results.some((r) => r.status === "fail");
52
+ }
53
+ function formatBytes(bytes) {
54
+ if (bytes < 1024) return `${bytes} B`;
55
+ return `${(bytes / 1024).toFixed(1)} KB`;
56
+ }
57
+ function formatReport(results) {
58
+ return results.map((r) => {
59
+ const actual = r.actualBytes === null ? "MISSING" : formatBytes(r.actualBytes);
60
+ const budget = formatBytes(r.maxBytes);
61
+ const marker = r.status === "pass" ? "OK" : r.status.toUpperCase();
62
+ const overNote = r.overBytes > 0 ? ` (+${formatBytes(r.overBytes)} over)` : "";
63
+ return `[${marker}] ${r.name}: ${actual} / ${budget}${overNote}`;
64
+ }).join("\n");
65
+ }
66
+ // Annotate the CommonJS export names for ESM import in node:
67
+ 0 && (module.exports = {
68
+ checkBudget,
69
+ formatReport,
70
+ hasFailures
71
+ });
package/dist/index.mjs ADDED
@@ -0,0 +1,44 @@
1
+ // src/index.ts
2
+ function checkBudget(entries, sizes) {
3
+ return entries.map((entry) => {
4
+ const actualBytes = Object.prototype.hasOwnProperty.call(sizes, entry.name) ? sizes[entry.name] : null;
5
+ if (actualBytes === null) {
6
+ return { name: entry.name, actualBytes: null, maxBytes: entry.maxBytes, warnBytes: entry.warnBytes, status: "missing", overBytes: 0 };
7
+ }
8
+ if (actualBytes > entry.maxBytes) {
9
+ return {
10
+ name: entry.name,
11
+ actualBytes,
12
+ maxBytes: entry.maxBytes,
13
+ warnBytes: entry.warnBytes,
14
+ status: "fail",
15
+ overBytes: actualBytes - entry.maxBytes
16
+ };
17
+ }
18
+ if (entry.warnBytes !== void 0 && actualBytes > entry.warnBytes) {
19
+ return { name: entry.name, actualBytes, maxBytes: entry.maxBytes, warnBytes: entry.warnBytes, status: "warn", overBytes: 0 };
20
+ }
21
+ return { name: entry.name, actualBytes, maxBytes: entry.maxBytes, warnBytes: entry.warnBytes, status: "pass", overBytes: 0 };
22
+ });
23
+ }
24
+ function hasFailures(results) {
25
+ return results.some((r) => r.status === "fail");
26
+ }
27
+ function formatBytes(bytes) {
28
+ if (bytes < 1024) return `${bytes} B`;
29
+ return `${(bytes / 1024).toFixed(1)} KB`;
30
+ }
31
+ function formatReport(results) {
32
+ return results.map((r) => {
33
+ const actual = r.actualBytes === null ? "MISSING" : formatBytes(r.actualBytes);
34
+ const budget = formatBytes(r.maxBytes);
35
+ const marker = r.status === "pass" ? "OK" : r.status.toUpperCase();
36
+ const overNote = r.overBytes > 0 ? ` (+${formatBytes(r.overBytes)} over)` : "";
37
+ return `[${marker}] ${r.name}: ${actual} / ${budget}${overNote}`;
38
+ }).join("\n");
39
+ }
40
+ export {
41
+ checkBudget,
42
+ formatReport,
43
+ hasFailures
44
+ };
package/package.json ADDED
@@ -0,0 +1,11 @@
1
+ {
2
+ "name": "bundle-budget-lite",
3
+ "version": "0.1.0",
4
+ "description": "Checks file sizes against a budget config and reports pass/fail per entry — pluggable size source, no bundler coupling, ideal for CI.",
5
+ "main": "dist/index.js", "module": "dist/index.mjs", "types": "dist/index.d.ts", "files": ["dist"],
6
+ "license": "MIT", "author": "Tejas Kadam",
7
+ "repository": { "type": "git", "url": "git+https://github.com/tejas821/bundle-budget-lite.git" },
8
+ "keywords": ["bundle-size", "ci", "performance", "typescript"],
9
+ "scripts": { "build": "tsup src/index.ts --format cjs,esm --dts", "test": "jest", "typecheck": "tsc --noEmit" },
10
+ "devDependencies": { "typescript": "^5.5.4", "tsup": "^8.2.4", "jest": "^29.7.0", "ts-jest": "^29.2.5", "@types/jest": "^29.5.12" }
11
+ }