Skip to content

fix(bun-plugin): compile the .js files of included packages - #925

Merged
owjs3901 merged 3 commits into
mainfrom
fix/bun-include-js
Nov 17, 2026
Merged

owjs3901 merged 3 commits into
mainfrom
fix/bun-include-js

Conversation

@owjs3901

@owjs3901 owjs3901 commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Fixes the Bun plugin not compiling the .js of libraries listed in include (follow-up to the #686 audit).

Problem

  • Bun's source onLoad filter (/\.(?:tsx?|jsx|mjs)$|[\\/]@devup-ui[\\/].*\.js$/) accepted .js only under @devup-ui/.
  • The Bun plugin had no include option at all.
  • So libraries that ship Devup UI components as uncompiled .js hit the runtime stub directly (Cannot run on the runtime).

Changes

  • Added an include?: readonly string[] option to DevupUI({ include }) and register({ include }).
  • The source filter also accepts .js from the listed packages. The matching rules are the same as fix(plugin-utils): match include package names exactly #914's createNodeModulesExcludeRegex.
    • A package is the directory directly under the innermost node_modules. So the pnpm store (node_modules/.pnpm/pkg@1/node_modules/pkg/...) and the Bun store (node_modules/.bun/...) match, and so do Windows paths.
    • Names are escaped and then compared against the whole directory. pkg does not match pkg-extra or @scope/pkg, foo.bar does not match fooXbar, and foo+bar matches itself.
    • Dependencies inside an included package's own node_modules are not included.
    • Existing behavior (TS/JSX anywhere, .js under @devup-ui/) is unchanged. With an empty include, the filter is the same as before.
  • Added a "Libraries" section to the README.

Because #914 is not merged yet, the shared function is not reused. The Bun filter is an include pattern rather than a node_modules exclusion, so the same rules are implemented separately inside this plugin.

New errors

None.

Test plan

  • bun test packages/bun-plugin: 77 pass, plugin.ts 100%
    • node_modules/my-lib/dist/index.js is compiled through the real onLoad callback
    • Included: POSIX and Windows paths, Bun and pnpm stores, @scope/ui, foo.bar, foo+bar
    • Excluded: my-lib-extra, @scope/my-lib, nested node_modules, outside node_modules, .json, fooXbar, @scope/ui-kit
    • Without include, package .js is excluded while @devup-ui .js and TSX are still accepted
  • bunx prettier --single-quote --no-semi --check, tsc --noEmit pass
  • CI

요약

Bun 플러그인이 include에 넣은 라이브러리의 .js를 컴파일하지 않던 문제를 고칩니다 (#686 감사 후속).

문제

  • Bun의 소스 onLoad filter(/\.(?:tsx?|jsx|mjs)$|[\\/]@devup-ui[\\/].*\.js$/)는 .js를 @devup-ui/ 아래에서만 받았습니다.
  • Bun 플러그인에는 include 옵션 자체가 없었습니다.
  • 그래서 Devup UI 컴포넌트를 컴파일하지 않은 .js로 배포한 라이브러리는 런타임 stub에 그대로 닿았습니다 (Cannot run on the runtime).

변경

  • DevupUI({ include })와 register({ include })에 include?: readonly string[] 옵션을 추가했습니다.
  • source filter가 나열한 패키지의 .js도 받습니다. 매칭 규칙은 #914의 createNodeModulesExcludeRegex와 같습니다.
    • 패키지는 가장 안쪽 node_modules 바로 아래 디렉터리로 봅니다. 그래서 pnpm store(node_modules/.pnpm/pkg@1/node_modules/pkg/...)와 Bun store(node_modules/.bun/...)도 맞고, Windows 경로도 맞습니다.
    • 이름은 escape한 뒤 디렉터리 전체와 비교합니다. pkg는 pkg-extra나 @scope/pkg와 맞지 않고, foo.bar는 fooXbar와 맞지 않으며, foo+bar는 자기 자신과 맞습니다.
    • 포함된 패키지 자신의 node_modules 안에 있는 의존성은 포함되지 않습니다.
    • 기존 동작(어디서든 TS/JSX, @devup-ui/ 아래 .js)은 그대로입니다. include가 비어 있으면 filter도 예전과 같습니다.
  • README에 "Libraries" 절을 추가했습니다.

#914가 아직 머지되지 않아 공유 함수를 가져다 쓰지 않았습니다. Bun filter는 node_modules 제외가 아니라 포함 패턴이라 같은 규칙을 이 플러그인 안에서 따로 구현했습니다.

새 오류

없음.

테스트 계획

  • bun test packages/bun-plugin: 77 pass, plugin.ts 100%
    • 실제 onLoad 콜백으로 node_modules/my-lib/dist/index.js가 컴파일되는지
    • 포함: POSIX·Windows 경로, Bun·pnpm store, @scope/ui, foo.bar, foo+bar
    • 제외: my-lib-extra, @scope/my-lib, 중첩 node_modules, node_modules 밖, .json, fooXbar, @scope/ui-kit
    • include가 없으면 패키지 .js는 제외되고 @devup-ui .js와 TSX는 그대로 받는지
  • bunx prettier --single-quote --no-semi --check, tsc --noEmit 통과
  • CI

Refs #686

🤖 Generated with Claude Code

The source onLoad filter accepted .js only under @devup-ui/, and the plugin
had no include option, so a library that ships Devup UI components as
uncompiled .js reached the runtime stubs.

DevupUI and register take include, and the filter also accepts .js of each
listed package. A package is the directory right under the innermost
node_modules, so pnpm and Bun stores match, and names are escaped and
matched whole, the same rules as createNodeModulesExcludeRegex in #914:
pkg is not pkg-extra or @scope/pkg, foo.bar is not fooXbar, and the
dependencies in an included package's own node_modules stay out.

Refs #686

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@codecov

codecov Bot commented Nov 15, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

Files with missing lines Coverage Δ
packages/bun-plugin/src/plugin.ts 100.00% <100.00%> (ø)

... and 6 files with indirect coverage changes

🚀 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.

Conflicts:
- bun-plugin/README.md: main (#949) added a "Compiled Files" section
  saying `.js` is compiled only inside `@devup-ui` packages. Kept it,
  extended that sentence with the packages listed in `include`, and kept
  this branch's "Libraries" section after it, noting that under the
  runtime an included package's `.js` is read as an ES module.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Resolve the conflict with #924 in the Bun plugin: keep this branch's
`createSourceFilter` for `include` and take main's `writeDataFiles`, which
rejects a theme error on the first load and reports it only on a reload.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@owjs3901
owjs3901 merged commit dfa5153 into main Nov 17, 2026
27 checks passed
@owjs3901
owjs3901 deleted the fix/bun-include-js branch November 17, 2026 04:28
owjs3901 added a commit that referenced this pull request Nov 17, 2026
Resolve the onLoad filter against #925: createSourceFilter now loads .js
and .cjs outside node_modules and of @devup-ui and the include packages,
so an included CommonJS library goes through loadSourceFile and
commonJsSource under the runtime and keeps its exports. Add a runtime test
for an included CommonJS package and merge the README texts, dropping the
ES-modules-only caveat for include packages.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
owjs3901 added a commit that referenced this pull request Nov 17, 2026
Thread licenseBanner through the Next options next to #918's debug, and set
it with setDebug after restoreSessionState so a dropped state cannot undo it.
Keep the Bun licenseBanner option beside #925's include.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
owjs3901 added a commit that referenced this pull request Nov 17, 2026
Build the Bun source filter with #925's createSourceFilter, whose base now
takes .mts and .cts as this branch does, so included packages keep their .js
files. Merge the README sections, and move #944's Turbopack Tailwind test to
this branch's wider rule glob.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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