Skip to content

fix(bun-plugin): write the base CSS the imports resolve to - #634

Closed
owjs3901 wants to merge 1 commit into
mainfrom
owjs3901/bun-plugin-write-base-css
Closed

fix(bun-plugin): write the base CSS the imports resolve to#634
owjs3901 wants to merge 1 commit into
mainfrom
owjs3901/bun-plugin-write-base-css

Conversation

@owjs3901

Copy link
Copy Markdown
Contributor

Two problems

1. The plugin never wrote the file its own imports resolve to.

onResolve maps every devup-ui.css import to df/devup-ui/devup-ui.css, but writeDataFiles() only created the directory. codeExtract returns the collected styles and updatedBaseStyle, and both were discarded:

const code = codeExtract(...)
return { contents: code.code, loader }   // css, cssFile, updatedBaseStyle dropped

So the plugin resolved imports to a path it never produced. It appeared to work only where another plugin had already left a file there. In a checkout without one - a fresh clone, a git worktree, CI - the first import fails to resolve and the run dies before any style is collected.

plugin.test.ts already spies on getCss, which the source never called.

2. registerShorthands was called without being imported.

Introduced in #632. The next, vite, rsbuild and webpack plugins all import it from @devup-ui/wasm; the bun plugin does not, so it throws ReferenceError: registerShorthands is not defined on startup. bun test packages/bun-plugin fails on main today for this reason.

Change

  • write the base stylesheet on initialize, so the first resolve has a target
  • refresh it whenever codeExtract reports updatedBaseStyle, matching webpack-plugin/src/loader.ts
  • import registerShorthands from @devup-ui/wasm

Verification

bunx tsc --noEmit -p packages/bun-plugin   exit 0
bun test packages/bun-plugin               12 pass, 0 fail
bun run build                              exit 0

On main the same test command fails with the ReferenceError.

How this surfaced

In another repository the frontend suite failed only outside the primary checkout:

Cannot find module 'C:\...\<main checkout>\df\devup-ui\devup-ui.css'
  from 'C:\...\<worktree>\...\ProjectRail.tsx'

It reproduced on an untouched worktree and on a clean clone of the same commit, and disappeared with BUN_RUNTIME_TRANSPILER_CACHE_PATH=0 - Bun's transpiler cache is keyed by file content, so identical sources in a second checkout reused a resolution belonging to the first. That is only reachable because the resolved file is absent in the second checkout; once the plugin writes its own base stylesheet, each checkout resolves to a file it actually has.

@github-actions

Copy link
Copy Markdown
Contributor

Changepacks

@devup-ui/wasm@1.0.75 → 1.0.76 - bindings/devup-ui-wasm/package.json

Patch

  • Add plugin-configured custom shorthands with generated TypeScript completion

@devup-ui/bun-plugin@1.0.12 → 1.0.13 - packages/bun-plugin/package.json

Patch

  • Add plugin-configured custom shorthands with generated TypeScript completion

@devup-ui/components@0.1.50 → 0.1.51 - packages/components/package.json

Patch

  • Auto-update: depends on '@devup-ui/react' via a local workspace dependency

@devup-ui/next-plugin@1.0.80 → 1.0.81 - packages/next-plugin/package.json

Patch

  • Add plugin-configured custom shorthands with generated TypeScript completion

@devup-ui/plugin-utils@1.0.10 → 1.0.11 - packages/plugin-utils/package.json

Patch

  • Add plugin-configured custom shorthands with generated TypeScript completion

@devup-ui/react@1.0.37 → 1.0.38 - packages/react/package.json

Patch

  • Add plugin-configured custom shorthands with generated TypeScript completion

@devup-ui/reset-css@1.0.24 → 1.0.25 - packages/reset-css/package.json

Patch

  • Auto-update: depends on '@devup-ui/react' via a local workspace dependency

@devup-ui/rsbuild-plugin@1.0.58 → 1.0.59 - packages/rsbuild-plugin/package.json

Patch

  • Add plugin-configured custom shorthands with generated TypeScript completion

@devup-ui/vite-plugin@1.0.64 → 1.0.65 - packages/vite-plugin/package.json

Patch

  • Add plugin-configured custom shorthands with generated TypeScript completion

@devup-ui/webpack-plugin@1.0.63 → 1.0.64 - packages/webpack-plugin/package.json

Patch

  • Add plugin-configured custom shorthands with generated TypeScript completion

@codecov

codecov Bot commented Aug 23, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@owjs3901

Copy link
Copy Markdown
Contributor Author

Closing this: both claims in the description were wrong, and I verified that only after opening it.

"The plugin never writes the base CSS its imports resolve to."
Disproven. df/devup-ui/devup-ui.css does not exist in either the primary checkout or a second one, yet the consuming test suite passes in both. So resolution is not depending on that file, and the missing write is not what broke anything.

"registerShorthands is called without being imported."
Self-inflicted. origin/main at efbd436 already imports it; my own edit adding getCss to the same import block is what removed it. The ReferenceError I attributed to #632 was introduced by me in this branch.

The real symptom I started from - a second checkout resolving devup-ui.css to the first checkout's absolute path - disappeared once node_modules was reinstalled, which cleared Bun's transpiler cache. That points at cache staleness rather than at this plugin, and I no longer have a reproduction to justify a change here.

Sorry for the noise.

@owjs3901 owjs3901 closed this Aug 23, 2026
@owjs3901
owjs3901 deleted the owjs3901/bun-plugin-write-base-css branch August 23, 2026 17:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant