Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .changepacks/changepack_log_bun_runtime_sheet_writes.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"changes":{"packages/bun-plugin/package.json":"Patch"},"note":"Under the Bun runtime, rewrite devup-ui.css only when a module adds or removes styles, from the sheet the extraction already serialized, instead of serializing and writing the whole sheet after every compiled module.","date":"2026-11-15T00:00:00.000Z"}
23 changes: 23 additions & 0 deletions packages/bun-plugin/src/__tests__/plugin.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,29 @@ describe('registered Bun hooks', () => {
expect(writeSync).not.toHaveBeenCalled()
})

it('writes the runtime sheet only when a module changes it', async () => {
const first = join(root, 'sheet-first.ts')
const same = join(root, 'sheet-same.ts')
const style =
"import { css } from '@devup-ui/react'; export const className = css({ color: 'olive' })"
await Bun.write(first, style)
await Bun.write(same, style)
await register({ engine: 'wasm' })

await load(first)
expect(writeSync).toHaveBeenCalledTimes(1)
expect(writeSync).toHaveBeenCalledWith(
expect.stringContaining('devup-ui.css'),
wasm.getCss(null, false),
'utf-8',
)

// The same file again, and another file with only styles the sheet holds
await load(first)
await load(same)
expect(writeSync).toHaveBeenCalledTimes(1)
})

it('propagates source read errors instead of returning partial output', async () => {
await register({ engine: 'wasm' })
await expect(load(join(root, 'missing.ts'))).rejects.toThrow()
Expand Down
15 changes: 7 additions & 8 deletions packages/bun-plugin/src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,14 +155,13 @@ async function loadSourceFile(
importAliases,
)
// Under the runtime the stylesheet is read from disk. singleCss stores
// every extracted style in the base sheet; synchronous writes keep
// concurrent source loads from overwriting a newer sheet with an older one.
if (!bundling)
writeFileSync(
join(cssDir, 'devup-ui.css'),
compiler.getCss(null, false),
'utf-8',
)
// every extracted style in the base sheet, which the output carries only
// when this module changed it, so a module that adds no style writes
// nothing. Synchronous writes keep concurrent source loads from
// overwriting a newer sheet with an older one.
const sheet = code.css
if (!bundling && sheet !== undefined)
writeFileSync(join(cssDir, 'devup-ui.css'), sheet, 'utf-8')
return { contents: code.code, loader }
}
return { contents, loader }
Expand Down
Loading