Skip to content

Commit 66e725d

Browse files
committed
fix: avoid object spread helpers and track entry sizes
Use Object.assign in the plain wrapper to avoid ES2015 object-spread helpers. Add pnpm size to measure complete entry bundles and update the README, retaining the v2 build and entry compatibility.
1 parent 0cb9a3b commit 66e725d

6 files changed

Lines changed: 78 additions & 7 deletions

File tree

‎README.md‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,12 @@ A lightweight JavaScript debugging utility, forked from [debug](https://www.npmj
1414
1515
## Key Differences from `debug`
1616

17+
<!-- Run `pnpm size` to update the minified + gzip (level 9, decimal kB) entry sizes below. Node built-ins remain external. -->
18+
1719
- ✨ Minimal footprint
18-
- 7.7 kB package size
19-
- 1.4 KB minified + gzipped for browsers
20+
- 1.50 kB minified + gzipped (plain)
21+
- 1.48 kB minified + gzipped (browser)
22+
- 1.73 kB minified + gzipped (ansi)
2023
- 📦 Zero dependencies
2124
- 📝 Full TypeScript support
2225
- 🚀 Native ESM compatibility

‎package.json‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959
"lint": "eslint --cache .",
6060
"lint:fix": "pnpm run lint --fix",
6161
"build": "tsdown",
62+
"size": "node scripts/bundle-size.ts",
6263
"dev": "tsdown --watch",
6364
"test": "vitest",
6465
"test:coverage": "vitest --project node --coverage",

‎scripts/bundle-size.ts‎

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
import { Buffer } from 'node:buffer'
2+
import { mkdtemp, readdir, readFile, rm, writeFile } from 'node:fs/promises'
3+
import { tmpdir } from 'node:os'
4+
import { join } from 'node:path'
5+
import { fileURLToPath } from 'node:url'
6+
import { gzipSync } from 'node:zlib'
7+
import { build } from 'tsdown'
8+
import buildConfig from '../tsdown.config.ts'
9+
10+
const root = fileURLToPath(new URL('../', import.meta.url))
11+
const readmePath = join(root, 'README.md')
12+
const readme = await readFile(readmePath, 'utf8')
13+
const section = /^- ✨ Minimal footprint\r?\n(?: {2}[^\r\n]*\r?\n)*/m
14+
if (!section.test(readme)) {
15+
throw new Error('Cannot find the Minimal footprint section in README.md')
16+
}
17+
18+
const outDir = await mkdtemp(join(tmpdir(), 'obug-bundle-size-'))
19+
const sizes: { name: string; bytes: number; gzipBytes: number }[] = []
20+
try {
21+
for (const name of ['plain', 'browser', 'ansi']) {
22+
const entryDir = join(outDir, name)
23+
await build({
24+
...buildConfig[0],
25+
cwd: root,
26+
config: false,
27+
entry: { [name]: join(root, 'src', `${name}.ts`) },
28+
outDir: entryDir,
29+
dts: false,
30+
minify: true,
31+
report: false,
32+
logLevel: 'silent',
33+
})
34+
const files = await readdir(entryDir)
35+
if (files.length !== 1 || files[0] !== `${name}.js`) {
36+
throw new Error(`Expected a single complete bundle for ${name}: ${files}`)
37+
}
38+
const code = await readFile(join(entryDir, `${name}.js`))
39+
const gzipBytes = gzipSync(code, { level: 9 }).byteLength
40+
sizes.push({ name, bytes: Buffer.byteLength(code), gzipBytes })
41+
}
42+
} finally {
43+
await rm(outDir, { recursive: true, force: true })
44+
}
45+
46+
const newline = readme.includes('\r\n') ? '\r\n' : '\n'
47+
const footprint =
48+
[
49+
'- ✨ Minimal footprint',
50+
...sizes.map(
51+
({ name, gzipBytes }) =>
52+
` - ${(gzipBytes / 1000).toFixed(2)} kB minified + gzipped (${name})`,
53+
),
54+
].join(newline) + newline
55+
const updated = readme.replace(section, footprint)
56+
if (updated !== readme) {
57+
await writeFile(readmePath, updated)
58+
}
59+
console.table(sizes)
60+
console.log(
61+
updated === readme ? 'README.md is up to date' : 'Updated README.md',
62+
)

‎src/plain.ts‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,10 @@ export function createDebug(
1111
namespace: string,
1212
options?: DebugOptions,
1313
): Debugger {
14-
return createBrowserDebug(namespace, { ...options, useColors: false })
14+
return createBrowserDebug(
15+
namespace,
16+
Object.assign({}, options, { useColors: false }),
17+
)
1518
}
1619

1720
export type * from './types.ts'

‎tsconfig.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,5 @@
1818
"verbatimModuleSyntax": true,
1919
"skipLibCheck": true
2020
},
21-
"include": ["src", "tests"]
21+
"include": ["src", "tests", "scripts"]
2222
}

‎tsdown.config.ts‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { defineConfig } from 'tsdown'
1+
import type { UserConfig } from 'tsdown'
22

3-
export default defineConfig([
3+
const config: UserConfig[] = [
44
{
55
entry: ['./src/{ansi,browser,plain}.ts'],
66
platform: 'neutral',
@@ -25,4 +25,6 @@ export default defineConfig([
2525
dts: false,
2626
minify: true,
2727
},
28-
])
28+
]
29+
30+
export default config

0 commit comments

Comments
 (0)