Skip to content

Commit a2d8908

Browse files
fix(pkg): drop sideEffects:false, it broke the published bundle
Bun's bundler applies the package's own `sideEffects: false` while building the package itself; since src/index.ts only re-exports, every module looked removable and the 0.1.10 dist was tree-shaken to an export stub naming bindings it never declared — every consumer crashed on import. Same root cause as ts-collect 0.4.1/0.4.2. prepublishOnly now also runs scripts/smoke-dist.ts, which imports the built dist and round-trips a PNG, so an unimportable dist fails the publish instead of reaching npm. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
1 parent 630585b commit a2d8908

2 files changed

Lines changed: 39 additions & 2 deletions

File tree

packages/ts-images/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
{
22
"name": "ts-images",
33
"type": "module",
4-
"sideEffects": false,
54
"version": "0.1.10",
65
"description": "Modern image optimizations & manipulations.",
76
"author": "Chris Breuer <chris@stacksjs.org>",
@@ -61,7 +60,8 @@
6160
"lint:fix": "bunx --bun pickier . --fix",
6261
"fresh": "bunx rimraf node_modules/ bun.lock && bun i",
6362
"changelog": "bunx changelogen --output CHANGELOG.md",
64-
"prepublishOnly": "bun --bun run build && bun run compile:all && bun run zip:all",
63+
"prepublishOnly": "bun --bun run build && bun run smoke && bun run compile:all && bun run zip:all",
64+
"smoke": "bun --bun scripts/smoke-dist.ts",
6565
"release": "bun run changelog && bunx bumpp package.json --all",
6666
"release:patch": "bun --bun run changelog && bunx --bun bumpx patch --recursive --yes",
6767
"test": "bun test",
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// Guards against publishing a broken bundle: ts-images 0.1.10 shipped a dist
2+
// that Bun's bundler tree-shook down to an export stub with no declarations
3+
// (the package's own `sideEffects: false` made every re-exporting module look
4+
// removable), so any consumer crashed on import — the same failure that hit
5+
// ts-collect 0.4.1/0.4.2. This imports the built dist entry and checks the
6+
// public API; prepublishOnly runs it so an unimportable dist can't be published.
7+
function fail(message: string): never {
8+
console.error(`smoke-dist: ${message}`)
9+
process.exit(1)
10+
}
11+
12+
const distEntry = new URL('../dist/src/index.js', import.meta.url).href
13+
14+
let mod: Record<string, unknown>
15+
try {
16+
mod = await import(distEntry)
17+
}
18+
catch (error) {
19+
fail(`dist/src/index.js failed to import: ${error instanceof Error ? error.message : error}`)
20+
}
21+
22+
for (const name of ['decode', 'encode', 'getMetadata', 'resize', 'processImage', 'process', 'createImageData']) {
23+
if (typeof mod[name] !== 'function')
24+
fail(`expected dist entry to export function \`${name}\`, got ${typeof mod[name]}`)
25+
}
26+
27+
const { createImageData, encode, decode } = mod as unknown as typeof import('../src/index')
28+
const img = createImageData(4, 4)
29+
img.data.fill(128)
30+
const png = await encode(img, 'png', {})
31+
if (!(png instanceof Uint8Array) || png.byteLength === 0)
32+
fail('encode(png) returned no bytes')
33+
const roundTrip = await decode(png)
34+
if (roundTrip.width !== 4 || roundTrip.height !== 4)
35+
fail(`decode(encode(img)) returned ${roundTrip.width}x${roundTrip.height}, expected 4x4`)
36+
37+
console.log('smoke-dist: dist imports and png round-trips')

0 commit comments

Comments
 (0)