Skip to content

fix(plugin-utils): match include package names exactly - #914

Merged
owjs3901 merged 3 commits into
mainfrom
fix/include-package-match
Nov 15, 2026
Merged

owjs3901 merged 3 commits into
mainfrom
fix/include-package-match

Conversation

@owjs3901

Copy link
Copy Markdown
Contributor

Summary

#686의 PLG-05, PLG-28을 고칩니다.

  • PLG-05: createNodeModulesExcludeRegex가 include 이름을 escape하지 않고 정규식에 넣었고, node_modules 뒤 어디에서든 이름이 나오면 포함으로 봤습니다.
    • include: ['foo.bar']이 node_modules/fooXbar도 컴파일했습니다.
    • include: ['pkg']이 node_modules/@scope/pkg, node_modules/pkg-extra도 컴파일했습니다.
    • include: ['foo+bar']는 자기 자신과 맞지 않았습니다.
    • 포함된 패키지 안의 node_modules에 있는 의존성(node_modules/@devup-ui/react/node_modules/lodash)도 함께 컴파일했습니다.
  • 이제 파일이 속한 패키지를 가장 안쪽 node_modules 바로 아래 디렉터리로 보고, 이름을 escape한 뒤 그 디렉터리 전체와 일치할 때만 포함합니다. Windows 경로와 pnpm·Bun store 경로(node_modules/.pnpm/pkg@1.0.0/node_modules/pkg/...)는 그대로 포함됩니다.
  • PLG-28: Vite와 Rsbuild가 모듈을 변환할 때마다 이 정규식을 다시 만들었습니다. 이제 플러그인마다 한 번만 만듭니다. webpack과 Next는 이미 한 번만 만들었습니다.

#755와 겹치는 부분

#755(fix/plugin-core, 병합되지 않음)도 같은 함수를 고칩니다. 가장 안쪽 node_modules 기준은 같은 방향입니다. 이 PR은 main에서 새로 만들었고, #755 브랜치는 건드리지 않았습니다.

새로 생기는 오류

없음.

Test plan

  • plugin-utils shared.test.ts: foo.bar/fooXbar, pkg/@scope/pkg/pkg-extra, foo+bar, 중첩 node_modules, Windows·pnpm·Bun store 경로
  • rsbuild·webpack·next plugin.test.ts, vite plugin.test.ts 로컬 통과. webpack·Turbopack rule의 정규식 기대값은 새 패턴으로 바꿨습니다.
  • CI 전체와 커버리지

Refs #686

🤖 Generated with Claude Code

owjs3901 and others added 3 commits November 15, 2026 09:45
`createNodeModulesExcludeRegex` joined the `include` names into the regex
unescaped and matched them anywhere after `node_modules`. `foo.bar` also
compiled `node_modules/fooXbar`, `pkg` also compiled `@scope/pkg`, and
`foo+bar` never matched itself. Escape each name and match it only as a
whole package directory right under a `node_modules` directory.

Vite and Rsbuild now build the matcher once per plugin instead of on every
transformed module.

Refs #686 (PLG-05, PLG-28)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ack rules

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

A dependency nested in an included package's own `node_modules` was compiled
with it, because the name could match anywhere in the path. The package a
file belongs to is the directory right under its innermost `node_modules`
(pnpm and Bun stores included), so match the names only there.

Refs #686 (PLG-05)

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/plugin-utils/src/shared.ts 100.00% <100.00%> (ø)
packages/rsbuild-plugin/src/plugin.ts 100.00% <100.00%> (ø)
packages/vite-plugin/src/plugin.ts 100.00% <100.00%> (ø)
🚀 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 added a commit that referenced this pull request Nov 15, 2026
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>
@owjs3901
owjs3901 merged commit ac568c9 into main Nov 15, 2026
27 checks passed
@owjs3901
owjs3901 deleted the fix/include-package-match branch November 15, 2026 22:40
owjs3901 added a commit that referenced this pull request Nov 15, 2026
Conflicts in rsbuild-plugin/src/plugin.ts:
- writeDataFiles: kept main's sequential mkdir and stylesheet write
  (the cold-start ENOENT fix) and returned this branch's
  { tailwindFiles, configFiles }.
- JS transform: kept main's hoisted excludeRegex (#914) and added this
  branch's addMissingDependency and config-file dependencies.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
owjs3901 added a commit that referenced this pull request Nov 15, 2026
Conflicts:
- rsbuild-plugin/src/plugin.ts: kept this branch's shared extractModule
  handler for the source and MDX post transforms, using main's hoisted
  excludeRegex (#914) in it.
- vite-plugin/src/plugin.ts: kept both extractModule (this branch) and
  main's removeSource (#951); extractModule uses main's excludeRegex,
  and the pre transform stays a SOURCE_FILE_RE check plus extractModule.
- webpack-plugin/src/__tests__/plugin.test.ts (no textual conflict):
  the MDX post-rule test now expects #914's exact package exclude regex.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
owjs3901 added a commit that referenced this pull request Nov 15, 2026
Conflicts:
- webpack, Rsbuild and Vite plugin.ts imports: kept main's setupWarning
  (#945) next to this branch's SOURCE_FILE_REGEX.
- Rsbuild transform: kept this branch's `environment` parameter, with
  main's hoisted excludeRegex (#914) in place of the per-call
  createNodeModulesExcludeRegex(include).
- Vite transform: kept this branch's SOURCE_FILE_REGEX check, with
  main's hoisted excludeRegex.
- Bun loadSourceFile: kept main's runtime sheet write, which writes only
  the sheet a module changed (#942), and this branch's
  withDependencyImports return.

Dropped from this branch in favor of main: the per-call exclude regex in
the Rsbuild and Vite transforms (#914) and the unconditional runtime
sheet write in Bun (#942).

Also updated the "Compiled Files" section that #949 added to the Bun
README: `.mts`/`.cts` are compiled, and `Bun.build` compiles the
project's own `.js`/`.cjs` outside node_modules.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
owjs3901 added a commit that referenced this pull request Nov 17, 2026
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>
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