@lowdep/size-check 1.0.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 Rushabh Shah
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,139 @@
1
+ # size-check
2
+
3
+ ![Zero dependencies](https://img.shields.io/badge/dependencies-0-brightgreen) ![Node](https://img.shields.io/badge/node-%3E%3D14-blue) ![License: MIT](https://img.shields.io/badge/license-MIT-green) ![Platform](https://img.shields.io/badge/platform-Windows%20%7C%20macOS%20%7C%20Linux-lightgrey)
4
+
5
+
6
+ Assert that your build artifacts haven't exceeded size limits. Gzip and Brotli aware. Zero dependencies.
7
+
8
+ Like `size-limit` but with no dependencies. Like `bundlesize` but maintained.
9
+
10
+ ---
11
+
12
+ ## Install
13
+
14
+ ```bash
15
+ npm install -g size-check
16
+ ```
17
+
18
+ Or without installing:
19
+
20
+ ```bash
21
+ npx size-check
22
+ ```
23
+
24
+ ---
25
+
26
+ ## Quick Start
27
+
28
+ Add to your `package.json`:
29
+
30
+ ```json
31
+ {
32
+ "size-check": [
33
+ { "path": "dist/*.js", "maxSize": "100 kB" },
34
+ { "path": "dist/*.css", "maxSize": "20 kB", "gzip": true }
35
+ ]
36
+ }
37
+ ```
38
+
39
+ Then run:
40
+
41
+ ```bash
42
+ size-check
43
+ ```
44
+
45
+ ---
46
+
47
+ ## Example Output
48
+
49
+ ```
50
+ size-check package.json
51
+
52
+ PATH SIZE LIMIT % STATUS
53
+ ──────────────────────────────────────── ────────── ────────── ──── ──────
54
+ dist/main.js 87.4 kB 100 kB 87% PASS
55
+ dist/vendor.js 142.3 kB 100 kB 142% FAIL
56
+ dist/styles.css 14.2 kB gz 20 kB 71% PASS
57
+
58
+ ───────────────────────────────────────────────────────────────────────────────
59
+ 2 passed 1 failed
60
+ ```
61
+
62
+ ---
63
+
64
+ ## Config
65
+
66
+ In `package.json`:
67
+
68
+ ```json
69
+ {
70
+ "size-check": [
71
+ { "path": "dist/*.js", "maxSize": "100 kB" },
72
+ { "path": "dist/*.css", "maxSize": "20 kB", "gzip": true },
73
+ { "path": "dist/**/*", "maxSize": "500 kB", "brotli": true }
74
+ ]
75
+ }
76
+ ```
77
+
78
+ Or as `.sizecheckrc.json`:
79
+
80
+ ```json
81
+ [
82
+ { "path": "dist/bundle.js", "maxSize": "100 kB" },
83
+ { "path": "dist/styles.css", "maxSize": "20 kB" }
84
+ ]
85
+ ```
86
+
87
+ ### Entry fields
88
+
89
+ | Field | Type | Description |
90
+ |---|---|---|
91
+ | `path` | string | Glob pattern relative to config file |
92
+ | `maxSize` | string | Size limit: `100 kB`, `1 MB`, `500 B` |
93
+ | `gzip` | boolean | Check gzip-compressed size |
94
+ | `brotli` | boolean | Check brotli-compressed size |
95
+
96
+ ---
97
+
98
+ ## CI Integration
99
+
100
+ ```yaml
101
+ - name: Check bundle sizes
102
+ run: npx size-check
103
+ ```
104
+
105
+ Exit code is `1` if any limit is exceeded.
106
+
107
+ ---
108
+
109
+ ## Options
110
+
111
+ ```bash
112
+ size-check # Use .sizecheckrc.json or package.json
113
+ size-check limits.json # Use a specific config file
114
+ size-check --gzip # Force gzip checking for all entries
115
+ size-check --brotli # Force brotli checking for all entries
116
+ size-check --dir dist/ # Set base directory
117
+ ```
118
+
119
+ ---
120
+
121
+ ## License
122
+
123
+ MIT
124
+
125
+ ---
126
+
127
+ ## Keywords
128
+
129
+ `bundle size` · `size-limit alternative` · `bundlesize alternative` · `ci size check` · `gzip size` · `brotli size` · `build size` · `asset size` · `zero dependencies` · `ci`
130
+
131
+ ---
132
+
133
+ <div align="center">
134
+
135
+ **Built to solve, shared to help — Rushabh Shah 🛠️✨**
136
+
137
+ <sub>One of 40+ zero-dependency developer CLI tools — no <code>node_modules</code>, ever.</sub>
138
+
139
+ </div>
@@ -0,0 +1,329 @@
1
+ #!/usr/bin/env node
2
+ 'use strict';
3
+
4
+ const fs = require('fs');
5
+ const path = require('path');
6
+ const zlib = require('zlib');
7
+
8
+ const VERSION = '1.0.0';
9
+
10
+ // ─── ANSI ─────────────────────────────────────────────────────────────────────
11
+ const isTTY = process.stdout.isTTY;
12
+ const c = (code, t) => isTTY ? `\x1b[${code}m${t}\x1b[0m` : t;
13
+ const bold = t => c('1', t);
14
+ const dim = t => c('2', t);
15
+ const red = t => c('31', t);
16
+ const green = t => c('32', t);
17
+ const yellow = t => c('33', t);
18
+ const cyan = t => c('36', t);
19
+
20
+ // ─── Size parsing / formatting ────────────────────────────────────────────────
21
+ const SIZE_UNITS = {
22
+ b: 1,
23
+ kb: 1024,
24
+ mb: 1024 ** 2,
25
+ gb: 1024 ** 3,
26
+ };
27
+
28
+ function parseSize(str) {
29
+ const m = String(str).trim().match(/^([\d.]+)\s*(b|kb|kib|mb|mib|gb|gib)?$/i);
30
+ if (!m) throw new Error(`Invalid size: "${str}"`);
31
+ const num = parseFloat(m[1]);
32
+ const unit = (m[2] || 'b').toLowerCase().replace('ib', '').replace('i', '');
33
+ return Math.round(num * (SIZE_UNITS[unit] || 1));
34
+ }
35
+
36
+ function formatSize(bytes) {
37
+ if (bytes < 1024) return `${bytes} B`;
38
+ if (bytes < 1024 ** 2) return `${(bytes / 1024).toFixed(1)} kB`;
39
+ if (bytes < 1024 ** 3) return `${(bytes / 1024 ** 2).toFixed(2)} MB`;
40
+ return `${(bytes / 1024 ** 3).toFixed(2)} GB`;
41
+ }
42
+
43
+ function formatPercent(actual, limit) {
44
+ const pct = (actual / limit) * 100;
45
+ const s = pct.toFixed(0) + '%';
46
+ if (pct > 100) return red(s);
47
+ if (pct > 85) return yellow(s);
48
+ return green(s);
49
+ }
50
+
51
+ // ─── Glob-style file matching ─────────────────────────────────────────────────
52
+ function globFiles(pattern, baseDir) {
53
+ const parts = pattern.split(/[/\\]/);
54
+ const results = [];
55
+
56
+ function walk(dir, depth) {
57
+ let entries;
58
+ try { entries = fs.readdirSync(dir, { withFileTypes: true }); }
59
+ catch { return; }
60
+
61
+ const segment = parts[depth];
62
+ const isLast = depth === parts.length - 1;
63
+
64
+ for (const e of entries) {
65
+ const full = path.join(dir, e.name);
66
+ if (segment === '**') {
67
+ // Match zero or more directories
68
+ if (e.isDirectory()) {
69
+ walk(full, depth); // stay at ** level
70
+ walk(full, depth + 1); // advance past **
71
+ } else if (isLast || matchSegment(e.name, parts[depth + 1])) {
72
+ if (isLast) results.push(full);
73
+ else if (matchSegment(e.name, parts[depth + 1])) results.push(full);
74
+ }
75
+ } else if (matchSegment(e.name, segment)) {
76
+ if (isLast && e.isFile()) {
77
+ results.push(full);
78
+ } else if (!isLast && e.isDirectory()) {
79
+ walk(full, depth + 1);
80
+ }
81
+ }
82
+ }
83
+ }
84
+
85
+ const isAbsolute = path.isAbsolute(pattern);
86
+ const absPattern = isAbsolute ? pattern : path.join(baseDir, pattern);
87
+ const absParts = absPattern.split(/[/\\]/);
88
+
89
+ function walkAbs(dir, depth) {
90
+ let entries;
91
+ try { entries = fs.readdirSync(dir, { withFileTypes: true }); }
92
+ catch { return; }
93
+
94
+ const segment = absParts[depth];
95
+ if (!segment) return;
96
+ const isLast = depth === absParts.length - 1;
97
+
98
+ for (const e of entries) {
99
+ const full = path.join(dir, e.name);
100
+ if (segment === '**') {
101
+ if (e.isDirectory()) { walkAbs(full, depth); walkAbs(full, depth + 1); }
102
+ else if (isLast) { results.push(full); }
103
+ else if (matchSegment(e.name, absParts[depth + 1])) { results.push(full); }
104
+ } else if (matchSegment(e.name, segment)) {
105
+ if (isLast && e.isFile()) results.push(full);
106
+ else if (!isLast && e.isDirectory()) walkAbs(full, depth + 1);
107
+ else if (!isLast && e.isFile() && absParts.slice(depth + 1).every(p => p === '**')) results.push(full);
108
+ }
109
+ }
110
+ }
111
+
112
+ // Determine starting dir
113
+ let startDir = baseDir;
114
+ let startDepth = 0;
115
+ const ap = absPattern.split(/[/\\]/);
116
+ // Find first wildcard segment
117
+ for (let i = 0; i < ap.length; i++) {
118
+ if (ap[i].includes('*') || ap[i].includes('?')) { startDepth = i; break; }
119
+ if (i === ap.length - 1) {
120
+ // No wildcards — exact file
121
+ if (fs.existsSync(absPattern) && fs.statSync(absPattern).isFile()) results.push(absPattern);
122
+ return results;
123
+ }
124
+ startDir = ap.slice(0, i + 1).join(path.sep) || path.sep;
125
+ startDepth = i + 1;
126
+ }
127
+
128
+ walkAbs(startDir, startDepth);
129
+ return [...new Set(results)];
130
+ }
131
+
132
+ function matchSegment(name, pattern) {
133
+ if (!pattern || pattern === '**') return true;
134
+ const regStr = pattern
135
+ .replace(/[.+^${}()|[\]\\]/g, '\\$&')
136
+ .replace(/\*/g, '[^/\\\\]*')
137
+ .replace(/\?/g, '[^/\\\\]');
138
+ return new RegExp(`^${regStr}$`).test(name);
139
+ }
140
+
141
+ // ─── Compression size ─────────────────────────────────────────────────────────
142
+ function gzipSize(buf) {
143
+ return zlib.gzipSync(buf, { level: 9 }).length;
144
+ }
145
+
146
+ function brotliSize(buf) {
147
+ if (!zlib.brotliCompressSync) return null; // Node <10.16
148
+ return zlib.brotliCompressSync(buf, { params: { [zlib.constants.BROTLI_PARAM_QUALITY]: 11 } }).length;
149
+ }
150
+
151
+ // ─── Config loader ────────────────────────────────────────────────────────────
152
+ function loadConfig(dir) {
153
+ // Try .sizecheckrc.json
154
+ const rcPath = path.join(dir, '.sizecheckrc.json');
155
+ if (fs.existsSync(rcPath)) {
156
+ return { limits: JSON.parse(fs.readFileSync(rcPath, 'utf8')), configFile: rcPath };
157
+ }
158
+
159
+ // Try package.json "size-check" key
160
+ const pkgPath = path.join(dir, 'package.json');
161
+ if (fs.existsSync(pkgPath)) {
162
+ const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf8'));
163
+ if (pkg['size-check']) {
164
+ const cfg = pkg['size-check'];
165
+ return { limits: Array.isArray(cfg) ? cfg : cfg.limits, configFile: pkgPath };
166
+ }
167
+ }
168
+
169
+ return null;
170
+ }
171
+
172
+ // ─── CLI ──────────────────────────────────────────────────────────────────────
173
+ const args = process.argv.slice(2);
174
+ const VALUE_FLAGS = new Set(['--dir']);
175
+ const positional = [];
176
+ for (let i = 0; i < args.length; i++) {
177
+ if (args[i].startsWith('-')) { if (VALUE_FLAGS.has(args[i])) i++; }
178
+ else positional.push(args[i]);
179
+ }
180
+
181
+ function getFlag(f) {
182
+ const i = args.indexOf(f);
183
+ return i !== -1 ? args[i + 1] : null;
184
+ }
185
+ function hasFlag(f) { return args.includes(f); }
186
+
187
+ if (hasFlag('--version') || hasFlag('-v')) {
188
+ console.log(`size-check v${VERSION}`); process.exit(0);
189
+ }
190
+
191
+ if (hasFlag('--help') || hasFlag('-h')) {
192
+ console.log(`
193
+ ${bold('size-check')} — Assert file/bundle sizes haven't exceeded limits, zero dependencies
194
+
195
+ ${bold('USAGE')}
196
+ size-check [config.json] [options]
197
+
198
+ ${bold('CONFIG')}
199
+ Reads limits from (in order):
200
+ .sizecheckrc.json
201
+ package.json "size-check" key
202
+
203
+ ${bold('CONFIG FORMAT')}
204
+ [
205
+ { "path": "dist/*.js", "maxSize": "100 kB" },
206
+ { "path": "dist/*.css", "maxSize": "20 kB", "gzip": true },
207
+ { "path": "dist/**/*", "maxSize": "500 kB", "brotli": true }
208
+ ]
209
+
210
+ ${bold('OPTIONS')}
211
+ --gzip Check gzip-compressed size for all entries
212
+ --brotli Check brotli-compressed size for all entries
213
+ --dir <path> Base directory (default: .)
214
+ --version Show version
215
+
216
+ ${bold('EXAMPLES')}
217
+ size-check # Use .sizecheckrc.json or package.json
218
+ size-check limits.json # Use a specific config file
219
+ size-check --gzip # Override: check gzip sizes
220
+ `);
221
+ process.exit(0);
222
+ }
223
+
224
+ const baseDir = path.resolve(getFlag('--dir') || '.');
225
+ const forceGzip = hasFlag('--gzip');
226
+ const forceBrotli = hasFlag('--brotli');
227
+
228
+ // Load config
229
+ let limits;
230
+ let configFile;
231
+
232
+ if (positional[0]) {
233
+ const cfgPath = path.resolve(positional[0]);
234
+ if (!fs.existsSync(cfgPath)) {
235
+ console.error(red(`\nConfig file not found: ${cfgPath}\n`)); process.exit(1);
236
+ }
237
+ const raw = JSON.parse(fs.readFileSync(cfgPath, 'utf8'));
238
+ limits = Array.isArray(raw) ? raw : raw.limits;
239
+ configFile = cfgPath;
240
+ } else {
241
+ const cfg = loadConfig(baseDir);
242
+ if (!cfg) {
243
+ console.error(red(`\nNo size-check config found.`));
244
+ console.log(dim(` Create .sizecheckrc.json or add "size-check" to package.json\n`));
245
+ process.exit(1);
246
+ }
247
+ limits = cfg.limits;
248
+ configFile = cfg.configFile;
249
+ }
250
+
251
+ if (!Array.isArray(limits) || !limits.length) {
252
+ console.error(red('\nNo limits defined in config.\n')); process.exit(1);
253
+ }
254
+
255
+ // ─── Run checks ───────────────────────────────────────────────────────────────
256
+ // Collect all rows first, then render with proper column widths
257
+
258
+ const rows = [];
259
+ let pass = 0, fail = 0;
260
+
261
+ for (const entry of limits) {
262
+ let maxBytes;
263
+ try { maxBytes = parseSize(entry.maxSize || entry.max || entry.limit || '0'); }
264
+ catch (e) { console.error(red(` Invalid maxSize "${entry.maxSize}": ${e.message}`)); fail++; continue; }
265
+
266
+ const useGzip = forceGzip || entry.gzip;
267
+ const useBrotli = forceBrotli || entry.brotli;
268
+ const files = globFiles(entry.path, baseDir);
269
+
270
+ if (files.length === 0) {
271
+ rows.push({ pathStr: entry.path, sizeStr: '(no files)', limitStr: formatSize(maxBytes), pctStr: '—', ok: null });
272
+ continue;
273
+ }
274
+
275
+ for (const filePath of files) {
276
+ const buf = fs.readFileSync(filePath);
277
+ let size, suffix;
278
+
279
+ if (useBrotli) {
280
+ size = brotliSize(buf); suffix = ' br';
281
+ } else if (useGzip) {
282
+ size = gzipSize(buf); suffix = ' gz';
283
+ } else {
284
+ size = buf.length; suffix = '';
285
+ }
286
+
287
+ const ok = size <= maxBytes;
288
+ const pct = ((size / maxBytes) * 100).toFixed(0) + '%';
289
+ const rel = path.relative(baseDir, filePath);
290
+
291
+ rows.push({ pathStr: rel, sizeStr: formatSize(size) + suffix, limitStr: formatSize(maxBytes), pctStr: pct, ok });
292
+ if (ok) pass++; else fail++;
293
+ }
294
+ }
295
+
296
+ // Compute column widths from plain (un-colored) strings
297
+ const W = {
298
+ path: Math.max(4, ...rows.map(r => r.pathStr.length)),
299
+ size: Math.max(4, ...rows.map(r => r.sizeStr.length)),
300
+ limit: Math.max(5, ...rows.map(r => r.limitStr.length)),
301
+ pct: Math.max(1, ...rows.map(r => r.pctStr.length)),
302
+ };
303
+
304
+ console.log(`\n${bold('size-check')} ${dim(path.relative(process.cwd(), configFile))}\n`);
305
+ console.log(` ${'PATH'.padEnd(W.path)} ${'SIZE'.padEnd(W.size)} ${'LIMIT'.padEnd(W.limit)} ${'%'.padStart(W.pct)} STATUS`);
306
+ console.log(` ${'─'.repeat(W.path)} ${'─'.repeat(W.size)} ${'─'.repeat(W.limit)} ${'─'.repeat(W.pct)} ──────`);
307
+
308
+ for (const r of rows) {
309
+ if (r.ok === null) {
310
+ console.log(` ${dim(r.pathStr.padEnd(W.path))} ${yellow(r.sizeStr.padEnd(W.size))} ${dim(r.limitStr.padEnd(W.limit))} ${'—'.padStart(W.pct)} ${yellow('WARN')}`);
311
+ } else {
312
+ const pathFmt = r.ok ? r.pathStr.padEnd(W.path) : bold(r.pathStr.padEnd(W.path));
313
+ const sizeFmt = r.ok ? r.sizeStr.padEnd(W.size) : red(r.sizeStr.padEnd(W.size));
314
+ const limitFmt = dim(r.limitStr.padEnd(W.limit));
315
+ const pctFmt = r.pctStr.padStart(W.pct);
316
+ const colorPct = parseInt(r.pctStr) > 100 ? red(pctFmt) : parseInt(r.pctStr) > 85 ? yellow(pctFmt) : green(pctFmt);
317
+ const status = r.ok ? green('PASS') : red('FAIL');
318
+ console.log(` ${pathFmt} ${sizeFmt} ${limitFmt} ${colorPct} ${status}`);
319
+ }
320
+ }
321
+
322
+ console.log(`\n ${'─'.repeat(W.path + W.size + W.limit + W.pct + 20)}`);
323
+ if (fail === 0) {
324
+ console.log(green(` All ${pass} check(s) passed\n`));
325
+ } else {
326
+ console.log(` ${green(`${pass} passed`)} ${red(`${fail} failed`)}\n`);
327
+ }
328
+
329
+ process.exit(fail > 0 ? 1 : 0);
package/package.json ADDED
@@ -0,0 +1,45 @@
1
+ {
2
+ "name": "@lowdep/size-check",
3
+ "version": "1.0.0",
4
+ "description": "Assert build artifact sizes haven't exceeded limits — gzip/brotli aware CI tool, zero dependencies",
5
+ "bin": {
6
+ "size-check": "bin/size-check.js"
7
+ },
8
+ "keywords": [
9
+ "bundle-size",
10
+ "size-limit",
11
+ "ci",
12
+ "build",
13
+ "performance",
14
+ "cli",
15
+ "zero-dependencies",
16
+ "bundle size",
17
+ "size-limit alternative",
18
+ "bundlesize alternative",
19
+ "ci size check",
20
+ "gzip size",
21
+ "brotli size",
22
+ "build size",
23
+ "asset size",
24
+ "zero dependencies"
25
+ ],
26
+ "author": "Rushabh Shah",
27
+ "license": "MIT",
28
+ "engines": {
29
+ "node": ">=14"
30
+ },
31
+ "files": [
32
+ "bin/"
33
+ ],
34
+ "repository": {
35
+ "type": "git",
36
+ "url": "git+https://github.com/Rushabh5000/size-check.git"
37
+ },
38
+ "bugs": {
39
+ "url": "https://github.com/Rushabh5000/size-check/issues"
40
+ },
41
+ "homepage": "https://github.com/Rushabh5000/size-check#readme",
42
+ "publishConfig": {
43
+ "access": "public"
44
+ }
45
+ }