Skip to content

fix(plugins): extract MDX after the MDX compiler - #960

Merged
owjs3901 merged 3 commits into
mainfrom
fix/mdx-compiled-output
Nov 17, 2026
Merged

owjs3901 merged 3 commits into
mainfrom
fix/mdx-compiled-output

Conversation

@owjs3901

Copy link
Copy Markdown
Contributor

Summary

PLG-06(MDX 부분)과 NXT-19(#686): .mdx 파일의 Devup 컴포넌트가 추출되지 않고 런타임 placeholder("Cannot run on the runtime")에 닿던 문제를, MDX 컴파일러가 만든 JavaScript를 추출하도록 해서 고칩니다. 안전하게 할 수 있는 부분만 구현하고 나머지는 문서화했습니다.

재검증 (origin/main 1160bf646)

  • extractor는 SourceType::from_path가 모르는 .mdx를 Unknown extension으로 거부했습니다.
  • Vite/webpack/Rsbuild의 filter는 ts/tsx/js/mjs/jsx만 받습니다. 게다가 Vite 플러그인은 enforce: 'pre'라 .mdx를 넣으면 raw MDX를 받게 됩니다.

변경

  • extractor: parsing::path_source_type가 .mdx(대소문자 무시)를 JSX를 허용하는 JavaScript ES module(SourceType::jsx())로 읽습니다. MDX 컴파일러 출력은 JSX runtime 호출(_jsx/_jsxs/_jsxDEV)이고, jsx 옵션을 쓰면 JSX가 남습니다. 둘 다 이미 지원하는 형태입니다. path에서 source type을 정하던 곳(barrel, imported styled, pragma, module reference, stylesheet dispatch, dead properties)도 이 함수를 씁니다.
  • Vite: enforce: 'post'인 devup-ui:mdx 플러그인을 반환 배열 끝에 추가했습니다. @mdx-js/rollup이 normal이든 pre이든(landing처럼) 그 뒤에 실행됩니다. 추출 본문은 extractModule로 꺼내 기존 pre transform과 같이 씁니다. 기존 transform 동작은 바뀌지 않습니다.
  • webpack (Next.js webpack 모드 포함): source rule과 같은 loader를 쓰는 .mdx rule을 enforce: 'post'로 추가했습니다. normal loader(@mdx-js/loader, @next/mdx의 [babel, mdx])가 다 끝난 뒤 실행됩니다.
  • Rsbuild: 같은 handler로 { test: /\.mdx$/i, order: 'post' } transform을 추가했습니다.
  • 문서: limitations 페이지에 MDX를 어떻게 추출하는지와 아직 안 되는 곳을 적었습니다.

하지 않은 것 (문서화)

  • Turbopack: @next/mdx는 turbopack.rules['{*,next-mdx-rule}']에 as: '*.tsx'로 규칙을 넣고, 기존 rules를 spread로 합칩니다. 그래서 Devup의 Object.assign과 키가 겹치지 않아 서로 덮어쓰지는 않습니다. 하지만 as 뒤의 모듈이 Devup의 *.{tsx,...} 규칙을 어떤 경로/순서로 다시 타는지는 실제 Next 빌드 없이 확인할 수 없습니다. 기존의 .mdx.[tj]sx?$ 제외(9813476 "Fix loader issue")가 바로 그 경로를 막고 있어서 이번에는 손대지 않았습니다. extractor가 이제 .mdx를 받으므로, 후속 작업은 이 제외를 풀고 Next+@next/mdx e2e로 순서를 확인하는 것입니다.
  • Bun 플러그인: Bun에는 MDX 컴파일 뒤에 끼어들 단계가 없습니다.
  • 예약 pre-scan / import graph / prewarm: raw .mdx를 읽을 수 없으므로 계속 제외합니다. 문서 자신의 클래스는 컴파일될 때 이름이 정해집니다. Vite/webpack/Rsbuild의 단일 프로세스 빌드에서는 문제가 없습니다.

겹치는 open PR

  • fix(plugins): compile modern modules, resolve bundler conditions and hoist over every source root #934(open)가 같은 extension 목록/filter(/\.(tsx|ts|js|mjs|jsx)$/)를 .mts/.cts/.cjs로 넓힙니다. 이 PR은 origin/main 기준이고 MDX용 rule/transform을 따로 추가하므로 내용은 겹치지 않지만, Vite transform filter 줄과 webpack/Rsbuild rule 블록에서 텍스트 충돌이 날 수 있습니다. 이 PR은 Vite transform 본문을 extractModule로 옮겼으니 rebase할 때 그 점을 보세요.

Test plan

  • Rust: reads_mdx_as_compiled_javascript(.mdx/.MDX)와 extracts_compiled_mdx(JSX runtime 출력, dev runtime 출력, JSX가 남은 출력 세 가지: Box 추출, has_devup_ui true)
  • cargo test -p extractor --tests -j 2, cargo clippy -p extractor --all-targets -- -D warnings, cargo fmt --all -- --check
  • Vite: devup-ui:mdx가 post이고 .mdx(쿼리 포함)만 추출하는지, pre transform은 .mdx를 건너뛰는지 확인 (bun --config=./bunfig.vite.toml test packages/vite-plugin/src/__tests__/plugin.test.ts, 621 pass)
  • webpack: .mdx post rule이 source rule의 loader를 쓰는지 확인, rule 수 2에서 3으로 (3513 pass)
  • Rsbuild: .mdx post transform이 source handler와 같은지 확인 (564 pass, plugin.ts 100%)
  • bunx tsc --noEmit (vite/webpack/rsbuild 플러그인), bunx prettier --check
  • 실제 @mdx-js/rollup/@mdx-js/loader e2e는 CI에 맡깁니다

Refs #686

🤖 Generated with Claude Code

The engine rejected `.mdx` filenames as an unknown extension. It now
reads an `.mdx` path as what an MDX compiler (`@mdx-js/loader`,
`@mdx-js/rollup`, `@next/mdx`) makes of it: an ES module of JavaScript
that may keep JSX. Every place that took a source type from a path goes
through the same function.

The plugins extract MDX in a phase after the MDX plugin runs:
- Vite: a `devup-ui:mdx` plugin with `enforce: 'post'`, sharing the
  source transform's extraction
- webpack (and Next.js with webpack): a `.mdx` rule with
  `enforce: 'post'` and the source rule's loader
- Rsbuild: a `.mdx` transform with `order: 'post'` and the source
  transform's handler

Next.js with Turbopack, the Bun plugin and the pre-build class
reservation scan still skip MDX; the limitations page says so.

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 Δ
libs/extractor/src/barrel.rs 100.00% <ø> (ø)
libs/extractor/src/dead_properties/calls.rs 100.00% <100.00%> (ø)
libs/extractor/src/imported_styled.rs 100.00% <100.00%> (ø)
libs/extractor/src/jsx_pragmas.rs 100.00% <ø> (ø)
libs/extractor/src/module_reference.rs 100.00% <100.00%> (ø)
libs/extractor/src/parsing.rs 100.00% <100.00%> (ø)
libs/extractor/src/stylesheet_policy_dispatch.rs 100.00% <ø> (ø)
packages/rsbuild-plugin/src/plugin.ts 100.00% <ø> (ø)
packages/vite-plugin/src/plugin.ts 100.00% <100.00%> (ø)
packages/webpack-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.

… probe

The MDX post rule runs the source loader a second time, so the relocated
install probe now sees three loaders that must all resolve to the
installed plugin and share its plugin-utils.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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
owjs3901 merged commit ecb6e21 into main Nov 17, 2026
27 checks passed
@owjs3901
owjs3901 deleted the fix/mdx-compiled-output branch November 17, 2026 02:38
owjs3901 added a commit that referenced this pull request Nov 17, 2026
Resolve the conflicts with #924 and #960. The Bun plugin keeps
bunConditions, withDependencyImports and sourceLoader and takes main's
writeDataFiles, which rejects a theme error on the first load. In Vite,
webpack and Rsbuild main moved the source transform into one handler shared
with the MDX post transform; that handler now matches SOURCE_FILE_REGEX, so
.mts/.cts/.cjs modules are extracted, and Rsbuild's handler still sets the
environment's module resolver. Main's Rsbuild MDX test now looks the source
transform up by SOURCE_FILE_REGEX.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
owjs3901 added a commit that referenced this pull request Nov 17, 2026
Resolve the conflict with #960 in Rsbuild: main moved the source transform
into one handler shared with the MDX post transform. That handler now also
registers devup.json and the configs it extends, existing ones with
addDependency and missing ones with addMissingDependency, so MDX modules
reload the theme too.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
owjs3901 added a commit that referenced this pull request Nov 17, 2026
Resolve the conflict with #960 in webpack: main builds the source loader
rule once and reuses it for the MDX post loader. That rule now passes the
project `root` to the loader, so MDX modules get root-relative extraction
ids and dependencies as well.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
owjs3901 added a commit that referenced this pull request Nov 17, 2026
…rent merges (#990)

* test(rsbuild-plugin): expect the MDX post transform in the hook order

#957 recorded the hook order before #960 added an order: post transform
for .mdx modules. Both landed, so main registers two source transforms and
the test failed. Label the MDX transform and expect it last.

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

* test(wasm): count removeFile in the documented argument positions

#952 counted 45 validated argument positions; #951, merged alongside it,
added removeFile.filename, so main validates 46 and the ABI gate failed.

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

---------

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