Skip to content

feat(metro-plugin): compile Devup UI for React Native in Metro (+ Expo example) - #1041

Open
owjs3901 wants to merge 7 commits into
mainfrom
feat/react-native-metro
Open

owjs3901 wants to merge 7 commits into
mainfrom
feat/react-native-metro

Conversation

@owjs3901

@owjs3901 owjs3901 commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

Part of #411 — PR 2 of the React Native plan: Metro plugin + Expo example.

Builds on #1039 (now merged into main).

What

  • New package @devup-ui/metro-plugin (0.0.0, private: true, README marked experimental; nothing is published).
    // metro.config.js
    const { getDefaultConfig } = require('expo/metro-config')
    const { withDevupUI } = require('@devup-ui/metro-plugin')
    module.exports = withDevupUI(getDefaultConfig(__dirname))
    • withDevupUI(config, options) sets transformer.babelTransformerPath to its transformer. The transformer runs codeExtractNative through loadCompiler() (native engine by default, engine: 'wasm' as in the other plugins), then hands the code to the upstream transformer: upstreamTransformer option → the config's babelTransformerPath (Expo's / RN's getDefaultConfig set it) → @expo/metro-config/babel-transformer → @react-native/metro-babel-transformer.
    • Options: package, devupFile, include, runtime (default true), engine, upstreamTransformer. The settings reach Metro's worker processes through one environment variable, since Metro passes Babel transformers no options.
    • Platform comes from Metro's options.platform.
    • Only JS/TS files whose source contains the package name are compiled (node_modules skipped except @devup-ui/* and include, the same rule as the other plugins); everything else goes upstream untouched without loading the engine.
    • getCacheKey = upstream key + devup.json and its extends chain + engine package version + settings.
    • Build errors become a DevupUIBuildError with loc and a code frame, so Metro shows file:line:col (verified with expo export):
      ERROR  DevupUIBuildError: src\App.tsx:16:7: `<Flex>` cannot use `_pressed` on React Native: ... Fix: ...
        15 |       p={6}
      > 16 |       _pressed={{ bg: "red" }}
           |       ^
      
    • Source maps: the engine hoists StyleSheet.create above the code, which shifts lines. The locations of the AST the upstream transformer returns are moved back through the engine's map, so Metro's source map points at the file as written (checked on the exported bundle: onPress, useState, ... map to their original lines).
    • Responsive values, themes and _pressed stay build errors (PRs 3–5).
  • apps/expo: minimal Expo SDK 58 / React Native 0.88 (New Architecture) app using Box, Flex, Text, Image, Input, Button from @devup-ui/react with static styles.
  • CI:
    • native-changes decides whether the change touches native code (libs/extractor/src/native/, libs/binding/, the two engine bindings, packages/metro-plugin/, packages/plugin-utils/, apps/expo/, the workflow); expo runs only then (D10).
    • expo runs expo export --platform ios --platform android --no-bytecode --source-maps on Linux and check-bundle.mjs asserts each bundle has no Cannot run on the runtime, no module of @devup-ui/react in its source map, and the compiled StyleSheet styles.
  • Changepack: packages/metro-plugin Minor (private, so changepacks does not publish it).

Install impact for web developers

apps/expo is a workspace member (as D10 proposed), so bun install also installs Expo/RN:

  • +259 packages (1127 → ~1386), bun.lock 830 KB → 989 KB (+19%).
  • Incremental bun install after pulling this branch: ~17 s locally (warm cache, Windows). The install still succeeds without any native toolchain (Expo's postinstalls are blocked by Bun by default).
  • If this is too heavy, "!apps/expo" in workspaces (Bun supports negation) would move the app to its own install; the CI job would then install it separately.

Tests

  • 39 bun tests, 100% line/function coverage of packages/metro-plugin (upstream transformer and engine mocked, plus one test through the real WASM engine and the module Metro loads).
  • ESLint clean; tsc in the package build.
  • Local expo export for iOS and Android + bundle check pass.

#411의 일부입니다. React Native 계획의 PR 2(Metro 플러그인 + Expo 예제)입니다.

#1039(이제 main에 머지됨) 위에서 작업했습니다.

내용

  • 새 패키지 @devup-ui/metro-plugin(0.0.0, private: true, README에 experimental 표시, 배포하지 않음).
    • withDevupUI(config, options)가 transformer.babelTransformerPath를 자체 transformer로 바꿉니다. 이 transformer는 loadCompiler()(기본 native 엔진, 다른 플러그인처럼 engine: 'wasm' 선택 가능)로 codeExtractNative를 실행한 뒤 상위 transformer로 넘깁니다. 상위 transformer는 upstreamTransformer 옵션 → config의 babelTransformerPath(Expo/RN의 getDefaultConfig가 설정) → @expo/metro-config/babel-transformer → @react-native/metro-babel-transformer 순서로 정합니다.
    • 옵션: package, devupFile, include, runtime(기본 true), engine, upstreamTransformer. Metro는 Babel transformer에 옵션을 넘기지 않으므로 설정은 환경 변수 하나로 worker 프로세스에 전달합니다.
    • 플랫폼은 Metro의 options.platform을 씁니다.
    • 패키지 이름이 들어 있는 JS/TS 파일만 컴파일합니다(node_modules는 다른 플러그인과 같은 규칙으로 @devup-ui/*와 include만 포함). 나머지는 엔진을 로드하지 않고 그대로 상위로 넘깁니다.
    • getCacheKey = 상위 키 + devup.json과 extends 체인 + 엔진 패키지 버전 + 설정.
    • 빌드 에러는 loc와 code frame을 가진 DevupUIBuildError가 되어 Metro에 file:line:col로 표시됩니다(expo export로 확인, 위 예시 참고).
    • 소스맵: 엔진이 StyleSheet.create를 코드 위로 끌어올려 줄이 밀리므로, 상위 transformer가 돌려준 AST의 위치를 엔진의 맵으로 원래 위치로 옮깁니다. 그래서 Metro 소스맵이 작성한 파일 그대로를 가리킵니다(export한 번들에서 onPress, useState 등이 원래 줄로 매핑되는 것을 확인).
    • 반응형 값, 테마, _pressed는 계속 빌드 에러입니다(PR 3–5).
  • apps/expo: @devup-ui/react의 Box, Flex, Text, Image, Input, Button을 정적 스타일로 쓰는 최소 Expo SDK 58 / React Native 0.88(New Architecture) 앱.
  • CI:
    • native-changes가 native 관련 파일(libs/extractor/src/native/, libs/binding/, 두 엔진 바인딩, packages/metro-plugin/, packages/plugin-utils/, apps/expo/, 워크플로)이 바뀌었는지 판단하고, 그때만 expo가 실행됩니다(D10).
    • expo는 Linux에서 expo export --platform ios --platform android --no-bytecode --source-maps를 실행하고, check-bundle.mjs로 각 번들에 Cannot run on the runtime이 없고, 소스맵에 @devup-ui/react 모듈이 없으며, 컴파일된 StyleSheet 스타일이 있는지 확인합니다.
  • Changepack: packages/metro-plugin Minor(private이라 changepacks가 배포하지 않음).

웹 개발자 설치 영향

apps/expo는 D10 제안대로 workspace 멤버라서 bun install이 Expo/RN도 설치합니다.

  • 패키지 +259개(1127 → 약 1386), bun.lock 830 KB → 989 KB(+19%).
  • 이 브랜치를 받은 뒤 증분 bun install: 로컬에서 약 17초(캐시 있음, Windows). native 툴체인 없이도 설치는 성공합니다(Expo의 postinstall은 Bun이 기본으로 막음).
  • 부담스럽다면 workspaces에 "!apps/expo"(Bun이 부정 패턴 지원)를 넣어 앱을 별도 설치로 분리하고, CI job에서 따로 설치하면 됩니다.

테스트

  • bun 테스트 39개, packages/metro-plugin 라인/함수 coverage 100%(상위 transformer와 엔진 mock, 실제 WASM 엔진과 Metro가 로드하는 모듈을 거치는 테스트 1개 포함).
  • ESLint 통과, 패키지 빌드에서 tsc 통과.
  • 로컬 expo export(iOS, Android)와 번들 검사 통과.

🤖 Generated with Claude Code

owjs3901 and others added 5 commits November 19, 2026 22:55
Add a Native target to ExtractOption that turns Devup UI elements into
React Native components with their styles hoisted into one
StyleSheet.create per file, and expose it as codeExtractNative in the
WASM and NAPI bindings.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…tive into the ABI checks

Snapshot every supported prop shape, platform and build error of the
native target, list codeExtractNative in the binding ABI guards and the
cross-engine corpus, document it and add its changepack.

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

A dynamic length such as p={x} reached React Native unscaled, so x = 2
gave padding 2 where the web build gives 8px for the constant. Wrap
values read at runtime in a file-local function that converts them as
the build converts a literal: numbers and numeric strings take the
property's scale (four pixels a unit for lengths), px lengths become
numbers and rem/em lengths become pixels. Colors, keywords and other
text pass through as they are.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… conversion in the changepack

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Add @devup-ui/metro-plugin (experimental, private 0.x): withDevupUI()
points babelTransformerPath at a transformer that runs codeExtractNative
on files importing Devup UI and chains to the upstream transformer
(the config's, else Expo's, else React Native's). Build errors carry
loc and a code frame so Metro reports file:line:col, the upstream AST
locations are moved back to the source through the engine's map, and
the cache key covers the upstream key, devup.json, the engine version
and the options.

Add apps/expo (Expo SDK 58, RN 0.88) and a path-filtered CI job that
exports iOS and Android bundles and checks no @devup-ui/react module
or runtime placeholder is left.

Part of #411.

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

codecov Bot commented Nov 19, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

Files with missing lines Coverage Δ
packages/metro-plugin/src/index.ts 100.00% <100.00%> (ø)
packages/metro-plugin/src/located-error.ts 100.00% <100.00%> (ø)
packages/metro-plugin/src/plugin.ts 100.00% <100.00%> (ø)
packages/metro-plugin/src/settings.ts 100.00% <100.00%> (ø)
packages/metro-plugin/src/source-map.ts 100.00% <100.00%> (ø)
packages/metro-plugin/src/transform.ts 100.00% <100.00%> (ø)
packages/metro-plugin/src/transformer.ts 100.00% <100.00%> (ø)

... and 10 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.

Base automatically changed from feat/react-native-core to main November 19, 2026 22:39
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