@zntc/react-native 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (45) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +48 -0
  3. package/dist/dev-server/hmr-bridge.d.ts +22 -0
  4. package/dist/dev-server/http-server.d.ts +32 -0
  5. package/dist/dev-server/http-utils.d.ts +11 -0
  6. package/dist/dev-server/index.d.ts +18 -0
  7. package/dist/dev-server/logger.d.ts +35 -0
  8. package/dist/dev-server/middleware/cli-server-api.d.ts +25 -0
  9. package/dist/dev-server/middleware/dev-middleware.d.ts +33 -0
  10. package/dist/dev-server/options.d.ts +30 -0
  11. package/dist/dev-server/platform-state.d.ts +37 -0
  12. package/dist/dev-server/routes/_shared.d.ts +3 -0
  13. package/dist/dev-server/routes/assets.d.ts +12 -0
  14. package/dist/dev-server/routes/bundle.d.ts +8 -0
  15. package/dist/dev-server/routes/devmenu.d.ts +4 -0
  16. package/dist/dev-server/routes/index-page.d.ts +3 -0
  17. package/dist/dev-server/routes/open-url.d.ts +4 -0
  18. package/dist/dev-server/routes/reload.d.ts +4 -0
  19. package/dist/dev-server/routes/status.d.ts +3 -0
  20. package/dist/dev-server/routes/symbolicate.d.ts +5 -0
  21. package/dist/dev-server/serve.d.ts +27 -0
  22. package/dist/dev-server/sourcemap.d.ts +15 -0
  23. package/dist/dev-server/symbolicate-source.d.ts +54 -0
  24. package/dist/dev-server/terminal-actions.d.ts +32 -0
  25. package/dist/dev-server/types.d.ts +22 -0
  26. package/dist/index.d.ts +16 -0
  27. package/dist/index.js +3471 -0
  28. package/dist/metro-hmr-adapter.d.ts +29 -0
  29. package/dist/metro-resolver-types.d.ts +39 -0
  30. package/dist/plugins/asset.d.ts +11 -0
  31. package/dist/plugins/babel.d.ts +42 -0
  32. package/dist/plugins/codegen.d.ts +16 -0
  33. package/dist/plugins/escape-regex.d.ts +1 -0
  34. package/dist/plugins/internal.d.ts +37 -0
  35. package/dist/plugins/metro-resolve-request.d.ts +7 -0
  36. package/dist/plugins/require-context.d.ts +7 -0
  37. package/dist/plugins/styled-components-native.d.ts +11 -0
  38. package/dist/plugins/types.d.ts +25 -0
  39. package/dist/preset.d.ts +142 -0
  40. package/dist/rn-constants.d.ts +21 -0
  41. package/dist/runtime-loader.d.ts +14 -0
  42. package/dist/withExpo.d.ts +60 -0
  43. package/package.json +70 -0
  44. package/runtime/.gitkeep +0 -0
  45. package/runtime/zntc-hmr-client.cjs +328 -0
@@ -0,0 +1,29 @@
1
+ import { type BunHmrClient, type HmrChannel, type HmrRnErrorBody, type HmrRnUpdateModule } from '@zntc/server';
2
+ /**
3
+ * ZNTC build error → Metro 호환 `BuildError` body 로 변환. file:line:col 추출
4
+ * 실패해도 단일 entry 의 description 만으로 fallback. bungae 의 formatHmrError
5
+ * (zntc-bundler/server/index.ts L824) 와 동일 로직 (#2605 audit).
6
+ */
7
+ export declare function formatBuildError(message: string): HmrRnErrorBody;
8
+ export interface MetroHmrAdapter {
9
+ /**
10
+ * 내부 HmrChannel — caller 가 직접 `accept(req, socket)` (Node http upgrade)
11
+ * 또는 `addBunClient(ws)` (Bun.serve websocket) 로 lifecycle 등록. adapter
12
+ * 는 send 만 wrapping 하므로 channel 자체에 직접 접근 가능.
13
+ */
14
+ readonly channel: HmrChannel;
15
+ /**
16
+ * Initial connection 직후 송출 — `update-start{isInitialUpdate:true}` →
17
+ * `update-done` sequence. RN runtime 의 'Refreshing...' 배너 회피용. caller
18
+ * 가 새 client connection 후 한 번 호출.
19
+ */
20
+ sendInitialGreeting(): void;
21
+ /** Module delta 송출. caller 가 revisionId 따라 modules 배열 구성. */
22
+ sendUpdate(modules: readonly HmrRnUpdateModule[]): void;
23
+ /** RN runtime 의 `__zntc_reload()` 또는 `location.reload()` 호출. */
24
+ sendReload(): void;
25
+ /** RN runtime 의 `console.error('[ZNTC HMR]', message)` 호출. */
26
+ sendError(message: string): void;
27
+ }
28
+ export declare function createMetroHmrAdapter(): MetroHmrAdapter;
29
+ export type { BunHmrClient, HmrChannel, HmrRnUpdateModule };
@@ -0,0 +1,39 @@
1
+ /**
2
+ * Metro RN runtime platform 식별자. core 의 `Platform` (build target —
3
+ * "browser" / "node" / "neutral" / "react-native") 와 namespace 충돌 회피
4
+ * 위해 `Metro` prefix. `web` 은 caller 가 RN-on-web 시나리오에서 사용 가능.
5
+ */
6
+ export type MetroPlatform = 'ios' | 'android' | 'web';
7
+ /** Metro `resolveRequest` 의 반환 타입 — Metro 표준 호환. */
8
+ export type Resolution = {
9
+ type: 'sourceFile';
10
+ filePath: string;
11
+ } | {
12
+ type: 'assetFiles';
13
+ filePaths: readonly string[];
14
+ } | {
15
+ type: 'empty';
16
+ };
17
+ /**
18
+ * Metro `resolveRequest` 의 첫 번째 인자 (context). Metro 의 ResolutionContext
19
+ * 를 단순화 — `originModulePath`, `platform`, default resolver fallback 만.
20
+ *
21
+ * `context.resolveRequest(context, moduleName, platform)` 호출하면 default
22
+ * resolver 로 위임 (Metro 동작과 동일). 무한 재귀 방지를 위해 호출 시 자기
23
+ * 자신은 제외됨.
24
+ */
25
+ export interface ResolutionContext {
26
+ /** 요청한 모듈의 absolute path. */
27
+ originModulePath: string;
28
+ /** 현재 빌드 플랫폼. ios/android 또는 null (default). */
29
+ platform: string | null;
30
+ /** Default resolver — 무한 재귀 방지 시 자기 자신 제외 후 호출. */
31
+ resolveRequest: CustomResolver;
32
+ }
33
+ /**
34
+ * 사용자 resolveRequest 함수 시그니처 (Metro 호환).
35
+ * - `context.resolveRequest(context, moduleName, platform)` 로 default 위임 가능.
36
+ * - 결과로 Resolution 반환 또는 throw — throw 시 caller (createMetroResolveRequestPlugin)
37
+ * 가 sentinel `__ZNTC_RN_DELEGATE_TO_DEFAULT__` 를 잡아 default resolver fallthrough.
38
+ */
39
+ export type CustomResolver = (context: ResolutionContext, moduleName: string, platform: string | null) => Resolution;
@@ -0,0 +1,11 @@
1
+ import type { ZntcPlugin } from '@zntc/core';
2
+ import type { PluginConfig } from './types.ts';
3
+ export declare function createSvgComponentModule(svg: string, filePath: string): string;
4
+ /**
5
+ * RN runtime 통합 plugin:
6
+ * - Metro HMRClient.js path → ZNTC HMR runtime (`runtime/zntc-hmr-client.js`) 교체
7
+ * - `.svg` sourceExt 는 ZNTC 내장 transformer 로 직접 JS module 생성
8
+ * - 사용자 babelTransformerPath 는 ZNTC 내장 transformer 가 처리하지 않는 custom
9
+ * sourceExt 에만 적용한다. Babel AST 반환은 처리하지 않는다.
10
+ */
11
+ export declare function createAssetPlugin(config: PluginConfig): ZntcPlugin;
@@ -0,0 +1,42 @@
1
+ import type { ZntcPlugin } from '@zntc/core';
2
+ import type { InlineBabelConfig, PluginConfig } from './types.ts';
3
+ /**
4
+ * ZNTC native 처리 plugin patterns — Babel pass-through 시 제외 (이 list 에 매칭
5
+ * 되면 ZNTC 가 이미 처리). 사용자 babel.config.js 의 plugin 중 *이 list 외* 만
6
+ * Babel 로 forward.
7
+ */
8
+ export declare const ZNTC_NATIVE_PLUGIN_PATTERNS: string[];
9
+ /** Plugin name 이 ZNTC 가 native 처리하는 list 에 매칭되는가. substring 매칭. */
10
+ export declare function isZntcNativePlugin(name: string): boolean;
11
+ /**
12
+ * Babel plugin 이름 컨벤션을 적용 (`@babel/core` 의 `standardizeName` 와 동등).
13
+ *
14
+ * - `'lodash'` → `'babel-plugin-lodash'`
15
+ * - `'@babel/foo'` → `'@babel/plugin-foo'`
16
+ * - `'@scope/foo'` → `'@scope/babel-plugin-foo'`
17
+ * - 절대/상대 경로, `module:` prefix, 이미 prefix 를 가진 이름은 그대로.
18
+ *
19
+ * babel CLI 는 이 prefix 를 자동 적용하지만 ZNTC 는 plugin 을 사전 절대경로로 resolve
20
+ * 해 babel 에 넘기므로 직접 적용해야 한다. 안 그러면 `'lodash'` 가 lodash 라이브러리
21
+ * 자체로 풀려 babel 이 `.__wrapped__ is not a valid Plugin property` 로 reject.
22
+ */
23
+ export declare function applyBabelPluginPrefix(name: string): string;
24
+ /**
25
+ * Babel pass 가 필요한지 판정. (a) babel.config.js 의 plugins 또는 (b) inline
26
+ * config (zntc.config.ts `transformer.babel`) 중 하나라도 ZNTC native list 외
27
+ * plugin/preset 이 있으면 true. 둘 다 0 → false (Babel pass skip).
28
+ */
29
+ export declare function detectCustomPlugins(projectRoot: string, inline?: InlineBabelConfig): boolean;
30
+ /**
31
+ * Lazy Babel transformer factory. 첫 transform 호출 시점에 require('@babel/core')
32
+ * + babel.config.js 평가 + inline config (zntc.config.ts `transformer.babel`)
33
+ * concat. Babel options 한 번 빌드 후 캐시. plugin require.resolve 는 user 의
34
+ * node_modules 우선 (Bun deep-link symlink 미생성 케이스 대비 fallback 명시).
35
+ */
36
+ export declare function createBabelTransformer(projectRoot: string, inline?: InlineBabelConfig): (code: string, filename: string) => string | null;
37
+ /**
38
+ * Babel transform plugin — 사용자 babel.config.js 의 custom plugin (Reanimated
39
+ * / NativeWind / 사용자 worklet) 을 source file 마다 적용. caller (preset.ts)
40
+ * 가 `detectCustomPlugins` 으로 게이트하므로 setup 시점엔 custom plugin 보장.
41
+ */
42
+ export declare function createBabelPlugin(config: PluginConfig): ZntcPlugin;
@@ -0,0 +1,16 @@
1
+ import type { ZntcPlugin } from '@zntc/core';
2
+ import type { PluginConfig } from './types.ts';
3
+ /** `codegenNativeComponent` literal — code 에 이 marker 미포함 시 transform skip. */
4
+ export declare const CODEGEN_NATIVE_COMPONENT_MARKER = "codegenNativeComponent";
5
+ /**
6
+ * Lazy codegen transformer factory. 첫 transform 호출 시점에
7
+ * `@react-native/babel-plugin-codegen` resolve (projectRoot 우선, 미발견 시
8
+ * cli node_modules fallback). RN 0.85+ Fabric crash 회피 patch.
9
+ */
10
+ export declare function createCodegenTransformer(projectRoot: string): (code: string, filename: string) => string | null;
11
+ /**
12
+ * Codegen plugin — `codegenNativeComponent` marker 가진 .js/.ts 파일을 Babel
13
+ * 로 transform 해서 view config 인라인. node_modules 포함 모든 파일 적용 (RN
14
+ * core 의 NativeComponent.js 까지 — DebuggingOverlay 등).
15
+ */
16
+ export declare function createCodegenPlugin(config: PluginConfig): ZntcPlugin;
@@ -0,0 +1 @@
1
+ export declare function escapeRegex(s: string): string;
@@ -0,0 +1,37 @@
1
+ /** ZNTC CLI 의 createRequire — fallback / require 의 모든 plugin 공용. */
2
+ export declare const requireFromCli: NodeRequire;
3
+ /** Babel @babel/core 의 transformSync 표면. babel.ts / codegen.ts 가 lazy load 후 사용. */
4
+ export interface BabelInstance {
5
+ transformSync(code: string, options: BabelTransformOptions): {
6
+ code?: string;
7
+ } | null;
8
+ transformFromAstSync?(ast: unknown, code: string | undefined, options: {
9
+ filename?: string;
10
+ babelrc?: boolean;
11
+ configFile?: boolean;
12
+ }): {
13
+ code?: string;
14
+ } | null;
15
+ }
16
+ export interface BabelTransformOptions {
17
+ cwd?: string;
18
+ root?: string;
19
+ filename?: string;
20
+ presets?: unknown[];
21
+ plugins?: unknown[];
22
+ babelrc?: boolean;
23
+ configFile?: boolean;
24
+ compact?: boolean;
25
+ retainLines?: boolean;
26
+ sourceMaps?: boolean;
27
+ parserOpts?: {
28
+ plugins?: string[];
29
+ };
30
+ }
31
+ /**
32
+ * `unknown` error 에서 message string 추출. 4 plugin 파일이 stderr write
33
+ * 시점에 사용 — 매번 `as { message?: string }` cast 의 boilerplate 회피.
34
+ */
35
+ export declare function getErrorMessage(err: unknown, max?: number): string;
36
+ /** `"ext"` / `".ext"` → `".ext"`. sourceExts/assetExts 정규화 공용. */
37
+ export declare function normalizeExt(ext: string): string;
@@ -0,0 +1,7 @@
1
+ import type { ZntcPlugin } from '@zntc/core';
2
+ import type { CustomResolver, MetroPlatform } from '../metro-resolver-types.ts';
3
+ export interface MetroResolveRequestOptions {
4
+ resolveRequest: CustomResolver;
5
+ platform: MetroPlatform;
6
+ }
7
+ export declare function createMetroResolveRequestPlugin(opts: MetroResolveRequestOptions): ZntcPlugin;
@@ -0,0 +1,7 @@
1
+ import type { ZntcPlugin } from '@zntc/core';
2
+ /**
3
+ * `require.context(dir, recursive, filter, flags?)` 의 host-side 평가. 디렉토리
4
+ * 가 없으면 graph 가 invalid 처리하지 않도록 빈 배열 응답. 파일 path 는 항상
5
+ * `./` prefix + forward slash (Windows path separator 정규화).
6
+ */
7
+ export declare function createRequireContextPlugin(): ZntcPlugin;
@@ -0,0 +1,11 @@
1
+ import type { ZntcPlugin } from '@zntc/core';
2
+ export declare const STYLED_COMPONENTS_NATIVE_PATH_RE: RegExp;
3
+ export declare function disableStyledComponentsNativeDomProbe(code: string): string | null;
4
+ /**
5
+ * RN 0.85 의 setUpDOM 은 `HTMLElement` 를 global/window 에 lazy polyfill 하지만,
6
+ * browser `document` 는 제공하지 않는다. styled-components/native v6 는
7
+ * `"HTMLElement" in window` 만으로 browser sheet 경로를 선택해 module 평가 중
8
+ * `document.querySelectorAll` 을 호출할 수 있으므로 native entry 에서는 DOM 감지를
9
+ * 명시적으로 꺼 둔다.
10
+ */
11
+ export declare function createStyledComponentsNativePlugin(): ZntcPlugin;
@@ -0,0 +1,25 @@
1
+ /** Inline babel config — Metro `transformer.babel` 호환. */
2
+ export interface InlineBabelConfig {
3
+ presets?: (string | [string, Record<string, unknown>])[];
4
+ plugins?: (string | [string, Record<string, unknown>])[];
5
+ }
6
+ export interface PluginConfig {
7
+ /** RN 프로젝트 root — Babel/codegen plugin resolve 의 base. */
8
+ projectRoot: string;
9
+ /** RN asset 확장자 (`.png` / `.jpg` / `.svg` 등). */
10
+ assetExts: string[];
11
+ /** RN runtime platform — codegen / asset 의 platform 분기. */
12
+ rnPlatform: 'ios' | 'android';
13
+ /** Metro transformer dev flag. 미지정 시 기존 dev-server 기본값인 true. */
14
+ dev?: boolean;
15
+ /** Source 확장자 (`.ts` / `.tsx` / `.js` / `.jsx` / `.svg` 등). */
16
+ sourceExts: string[];
17
+ /** Metro 호환 custom file transformer path (예: react-native-svg-transformer). */
18
+ babelTransformerPath?: string;
19
+ /**
20
+ * Inline babel preset / plugin (zntc.config.ts 의 `transformer.babel`). 사용자
21
+ * babel.config.js 의 plugins 와 concat 되며 양쪽 모두 ZNTC native filter 통과
22
+ * 후 babel pass 에 등록. TS/Flow strip 은 ZNTC native transform 이 처리한다.
23
+ */
24
+ inlineBabel?: InlineBabelConfig;
25
+ }
@@ -0,0 +1,142 @@
1
+ import { type BuildOptions, type BuildResult, type WatchHandle, type WatchReadyEvent, type WatchRebuildEvent, type ZntcPlugin } from '@zntc/core';
2
+ import type { CustomResolver } from './metro-resolver-types.ts';
3
+ import type { InlineBabelConfig } from './plugins/types.ts';
4
+ export interface RnBundleInput {
5
+ /** 절대 경로 entry. */
6
+ entry: string;
7
+ /** 프로젝트 루트 — RN polyfill / InitializeCore / Reanimated worklets resolve 의 base. */
8
+ projectRoot: string;
9
+ /** RN platform — preset 의 default ext / mainFields / asset loaders 결정. */
10
+ rnPlatform: 'ios' | 'android';
11
+ /** dev mode — banner / jsx / devMode / reactRefresh / footer 분기. */
12
+ dev: boolean;
13
+ /** sourcemap emit. dev 시 inline 권장. */
14
+ sourcemap?: boolean;
15
+ /** prod build 의 minify. */
16
+ minify?: boolean;
17
+ /** console.* 호출 제거. Metro production Babel plugin 과 같은 정책을 원하는 release 경로에서 사용. */
18
+ dropConsole?: boolean;
19
+ /** debugger statement 제거. */
20
+ dropDebugger?: boolean;
21
+ /**
22
+ * preset 위에 user override. semantics:
23
+ * - **Object dict** (`define` / `loader` / `alias` / `fallback` 등) — preset
24
+ * value 와 deep merge (key 단위 union, 충돌 시 override 우선)
25
+ * - **Array** (`plugins` / `resolveExtensions` / `mainFields` 등) — replace
26
+ * (preset 의 array 무시)
27
+ * - **Primitive** (`target` / `minify` 등) — replace
28
+ *
29
+ * preset 의 default 가 ZNTC RN 호환 보장 — array override 는 RN 동작 깨질
30
+ * 위험 있음 (caller 가 의도적 변경 시만 사용).
31
+ */
32
+ override?: Partial<BuildOptions>;
33
+ /** Metro 호환 추가 옵션 (caller 의 ResolvedConfig 에서 추출). */
34
+ extra?: {
35
+ watchFolders?: string[];
36
+ /** Metro `resolver.nodeModulesPaths` 호환. bare import 추가 탐색 경로. */
37
+ nodeModulesPaths?: string[];
38
+ /**
39
+ * Metro `resolver.disableHierarchicalLookup` 호환. true 면 entry 디렉토리
40
+ * 외부의 `node_modules` walk-up 탐색을 차단 — monorepo 에서 dependency
41
+ * hoisting 강제 또는 워크스페이스 외부 모듈 누수 방지에 사용.
42
+ */
43
+ disableHierarchicalLookup?: boolean;
44
+ blockList?: (RegExp | string)[];
45
+ fallback?: Record<string, string | false>;
46
+ /** RN 외 사용자 plugin (asset/babel/codegen/require-context/metro-resolve-request 외 추가). */
47
+ additionalPlugins?: ZntcPlugin[];
48
+ /** Custom Metro resolveRequest — Metro 시그니처 그대로. */
49
+ metroResolveRequest?: CustomResolver;
50
+ /** Metro 호환 babel transformer path (svg-transformer 등). */
51
+ babelTransformerPath?: string;
52
+ /** RN sourceExts override (default RN preset). */
53
+ sourceExts?: string[];
54
+ /** RN assetExts override (default RN preset). */
55
+ assetExts?: string[];
56
+ /**
57
+ * Metro `resolver.platforms` 호환. caller 가 인식 가능한 platform 이름 set.
58
+ * `rnPlatform` 이 이 list 안에 있어야 하며, list 자체는 prefix 확장에는
59
+ * 영향 없음 (Metro 동작과 동일 — current platform suffix 만 expand). 이
60
+ * sugar 는 사용자가 자신의 platform list 를 명시했을 때 `rnPlatform`
61
+ * 누락을 빌드 직전에 잡는 validation 용. 미래의 platform typing 확장
62
+ * (e.g. `tvos`/`macos`) 의 placeholder.
63
+ */
64
+ platforms?: string[];
65
+ /** 사용자 추가 polyfill (preset 의 RN polyfill 와 concat — Metro `serializer.polyfills` 호환). */
66
+ polyfills?: string[];
67
+ /**
68
+ * 추가 global 변수 — banner 의 `var <key>=<JSON.stringify(value)>` 로 inject.
69
+ * Metro `serializer.extraVars` 호환. zntc 의 `define` 과 의도가 다름:
70
+ * `define` 은 source 의 식별자 substitution (compile-time), `extraVars` 는
71
+ * runtime-time prelude 의 globals declaration (RN 코드 도착 전에 평가).
72
+ */
73
+ extraVars?: Record<string, unknown>;
74
+ /**
75
+ * Entry 전 실행할 module path (Metro `serializer.prelude` 호환). 절대 경로 또는
76
+ * projectRoot 기준 상대 경로. preset 의 `runBeforeMain` (InitializeCore) 와 concat
77
+ * 되어 RN runtime 부팅 직후 / entry 전에 실행. babel.config.js 같은 transform 영역
78
+ * 이 아닌 **번들에 prepend 되는 module list**.
79
+ */
80
+ prelude?: string[];
81
+ /**
82
+ * 사용자 babel preset / plugin (Metro `transformer.babel` 호환). babel.config.js
83
+ * 외에 zntc.config.ts 안에서 inline 으로 babel 설정. ZNTC native 처리 plugin (TS
84
+ * strip / RN preset / Reanimated 등) 은 자동 제외 — 충돌 회피.
85
+ *
86
+ * 사용자 babel.config.js 의 plugins 와 concat 되며 양쪽 모두 ZNTC native filter
87
+ * 통과 후 babel pass 에 forward. TS/Flow strip 은 ZNTC native transform 이 처리하므로
88
+ * presets 는 사용자가 명시한 non-native 항목만 forward 됨.
89
+ */
90
+ babel?: InlineBabelConfig;
91
+ /**
92
+ * Sourcemap 을 bundle 에 inline 으로 embed (Metro `serializer.inlineSourceMap`
93
+ * 호환). zntc core 의 `sourcemapMode='inline'` 으로 forward.
94
+ */
95
+ inlineSourceMap?: boolean;
96
+ /**
97
+ * Sourcemap 의 `sourceRoot` field (Metro `sourcemapSourcesRoot` 호환). 절대
98
+ * 경로를 source 로 변환하는 base. zntc core 의 `sourceRoot` 으로 forward.
99
+ */
100
+ sourceRoot?: string;
101
+ /**
102
+ * `console.error` setter intercept 의 RegExp source string 배열 — match 시
103
+ * silent swallow. zntc core 의 `silentConsoleErrorPatterns` 로 forward
104
+ * (Metro `server.silentConsoleErrorPatterns` 호환). consumer (e.g.
105
+ * `withExpo()`) 가 환경 감지 후 패턴 주입.
106
+ */
107
+ silentConsoleErrorPatterns?: string[];
108
+ /**
109
+ * Metro `server.forwardClientLogs` 호환. RN core 의 HMRClient.log 경유 로그를
110
+ * dev server 터미널로 forwarding. 기본 true.
111
+ */
112
+ forwardClientLogs?: boolean;
113
+ };
114
+ /** RN prelude 끝에 append 할 사용자 banner string. */
115
+ bannerExtras?: string;
116
+ /** Reanimated worklets 의 jsVersion 검증용. 미지정 시 자동 resolve. */
117
+ workletPluginVersion?: string;
118
+ }
119
+ export declare const DEFAULT_ASSET_EXTS: string[];
120
+ /**
121
+ * RN preset — RnBundleInput → BuildOptions. 번개 napi-build.ts L74-L268 의 RN
122
+ * 분기와 동등 동작.
123
+ */
124
+ export declare function buildRnBundleOptions(input: RnBundleInput): BuildOptions;
125
+ /**
126
+ * One-shot wrapper — `init()` + `build(buildRnBundleOptions(input))`. caller 가
127
+ * NAPI direct 호출이 아니라 단순 prod bundle 시나리오.
128
+ *
129
+ * `init()` 은 idempotent (core 의 module-cache `if (native) return`) — caller
130
+ * 가 별도로 `init(path)` 호출 후 `bundleRn` 호출해도 안전 (앞선 path 가 우선).
131
+ */
132
+ export declare function bundleRn(input: RnBundleInput): Promise<BuildResult>;
133
+ export interface RnWatchInput extends RnBundleInput {
134
+ outfile: string;
135
+ onReady?: (event: WatchReadyEvent) => void;
136
+ onRebuild?: (event: WatchRebuildEvent) => void | Promise<void>;
137
+ }
138
+ /**
139
+ * Watch wrapper — `init()` + `watch(buildRnBundleOptions(input))` + outfile +
140
+ * onReady/onRebuild wire-up. handle 반환 (caller 가 close). `init()` idempotent.
141
+ */
142
+ export declare function watchRn(input: RnWatchInput): WatchHandle;
@@ -0,0 +1,21 @@
1
+ /** `require.resolve` with try/catch — 미해결 시 null. caller 가 fallback chain 구성. */
2
+ export declare function tryResolve(specifier: string, fromDir: string): string | null;
3
+ /**
4
+ * RN polyfill paths (console.js, error-guard.js 등) resolve.
5
+ * - 1순위: `react-native/rn-get-polyfills` (RN 0.73+)
6
+ * - 2순위: `@react-native/js-polyfills` (legacy)
7
+ * 둘 다 미설치 시 console.warn + 빈 배열 반환 — caller 는 graceful skip.
8
+ */
9
+ export declare function resolveRnPolyfills(projectRoot: string): string[];
10
+ /**
11
+ * RN core packages — Metro/RN 은 이 패키지들의 인스턴스가 번들에 단 하나만
12
+ * 존재한다고 가정한다 (InitializeCore / DevTools / Fabric singleton). pnpm 처럼
13
+ * `.pnpm/<dep>/node_modules/react-native` 같은 peer farm 이 노출되면 동일 패키지의
14
+ * 별도 module id 가 만들어져 InitializeCore 가 두 번 실행될 수 있다 → alias 로 강제.
15
+ */
16
+ export declare const RN_SINGLETON_PACKAGES: readonly ["react", "react-native", "react-native-safe-area-context"];
17
+ /**
18
+ * RN reserved global identifiers (RN 0.83 기준 — minor 마다 변할 수 있어 audit 필요).
19
+ * `polyfillGlobal()` 로 등록되는 native global — scope hoisting 시 shadowing 회피.
20
+ */
21
+ export declare const RN_GLOBAL_IDENTIFIERS: readonly ["Promise", "regeneratorRuntime", "XMLHttpRequest", "FormData", "fetch", "Headers", "Request", "Response", "WebSocket", "Blob", "File", "FileReader", "URL", "URLSearchParams", "AbortController", "AbortSignal", "queueMicrotask", "setImmediate", "clearImmediate", "requestIdleCallback", "cancelIdleCallback", "setTimeout", "clearTimeout", "setInterval", "clearInterval", "requestAnimationFrame", "cancelAnimationFrame", "DOMRect", "DOMRectReadOnly", "DOMRectList", "HTMLCollection", "NodeList", "Node", "Document", "CharacterData", "Text", "Element", "HTMLElement", "IntersectionObserver", "MutationObserver", "MutationRecord", "EventCounts", "Performance", "PerformanceEntry", "PerformanceEventTiming", "PerformanceLongTaskTiming", "PerformanceMark", "PerformanceMeasure", "PerformanceObserver", "PerformanceObserverEntryList", "PerformanceResourceTiming", "TaskAttributionTiming"];
@@ -0,0 +1,14 @@
1
+ /**
2
+ * RN runtime 의 HMRClient interface 호환 코드 (string).
3
+ * runtime/zntc-hmr-client.cjs 가 dist 와 함께 publish 되어야 정상 로드.
4
+ *
5
+ * fallback dummy: build 직후 / 누락 환경에서 dynamic require 가 throw 안 하도록
6
+ * minimal no-op HMRClient 객체 export (RN 의 setUpBatchedBridge 가 default
7
+ * 접근 — `module.exports.default` 보존).
8
+ */
9
+ export declare const ZNTC_HMR_CLIENT_CODE: string;
10
+ /**
11
+ * RN runtime 의 `HMRClient.js` 의 path suffix (Metro 의 모듈 path 가 이 suffix
12
+ * 로 끝남). plugin factory 가 onLoad path 매칭 시 사용.
13
+ */
14
+ export declare const HMR_CLIENT_SUFFIX = "/Libraries/Utilities/HMRClient.js";
@@ -0,0 +1,60 @@
1
+ /**
2
+ * withExpo — Apply Expo-specific options to a ZNTC RN config.
3
+ *
4
+ * Mirrors the runtime opt-in pattern of `@expo/metro-config`:
5
+ * import { withExpo } from '@zntc/react-native';
6
+ * export default withExpo({ root: __dirname, entry: 'index.js', ... });
7
+ *
8
+ * Adds:
9
+ * - serializer.prelude: `expo/winter` + `@expo/metro-runtime`
10
+ * - resolver.assetExts: `.heic`, `.avif`, `.db` (expo-image, expo-sqlite)
11
+ * - resolver.blockList: `.expo/types/**` (generated d.ts)
12
+ * - server.silentConsoleErrorPatterns: winter polyfill warning
13
+ *
14
+ * Resolves all paths from `config.root`, so monorepo hoisting in unrelated
15
+ * workspace packages cannot leak Expo into a vanilla RN config.
16
+ *
17
+ * 번개 packages/bungae/src/bundler/zntc-bundler/withExpo.ts 의 ZNTC 포팅.
18
+ * BungaeConfig 대신 ZNTC 의 Metro-shape config (rn-dev-input.mjs 가 인식하는
19
+ * `resolver.assetExts` / `resolver.blockList` / `serializer.prelude` /
20
+ * `server.silentConsoleErrorPatterns` 영역) 를 변형.
21
+ */
22
+ /**
23
+ * Detect whether a project's own `package.json` declares Expo as a direct
24
+ * dependency. Used by zero-config mode to decide whether to auto-apply
25
+ * `withExpo()`. Hoisted-monorepo dependencies in workspace root do NOT
26
+ * trigger detection — only the project's own deps do.
27
+ */
28
+ export declare function detectExpo(projectRoot: string): {
29
+ name: 'expo' | 'expo-router';
30
+ version: string;
31
+ } | undefined;
32
+ /**
33
+ * expo `installGlobal.ts:96` 의 winter polyfill (TextEncoderStream/TextDecoderStream/
34
+ * Location) 이 Hermes 의 `configurable: false` spec global 위에 redefine 시도 →
35
+ * catch 후 무해 console.error. dev console 을 오염시키므로 silent swallow.
36
+ */
37
+ export declare const WINTER_POLYFILL_WARNING_PATTERN = "^Failed to set polyfill\\.\\s+\\w+\\s+is not configurable\\.?$";
38
+ /**
39
+ * ZNTC 의 Metro-shape config 가 가질 수 있는 영역 — withExpo 가 만지는 부분만
40
+ * 명시. caller 가 `defineConfig` 없이 plain object 로 export 하므로 `T extends`
41
+ * 형태로 generic 보존 — 추가 필드는 그대로 통과.
42
+ */
43
+ export interface ZntcRnExpoConfig {
44
+ root?: string;
45
+ resolver?: {
46
+ assetExts?: string[];
47
+ blockList?: (RegExp | string)[];
48
+ [key: string]: unknown;
49
+ };
50
+ serializer?: {
51
+ prelude?: string[];
52
+ [key: string]: unknown;
53
+ };
54
+ server?: {
55
+ silentConsoleErrorPatterns?: string[];
56
+ [key: string]: unknown;
57
+ };
58
+ [key: string]: unknown;
59
+ }
60
+ export declare function withExpo<T extends ZntcRnExpoConfig>(config: T): T;
package/package.json ADDED
@@ -0,0 +1,70 @@
1
+ {
2
+ "name": "@zntc/react-native",
3
+ "version": "0.1.0",
4
+ "description": "ZNTC React Native platform — Metro HMR adapter + RN preset (buildRnBundleOptions) + plugin factories + RN runtime",
5
+ "keywords": [
6
+ "bundler",
7
+ "flow",
8
+ "hermes",
9
+ "metro",
10
+ "react-native",
11
+ "reanimated",
12
+ "transpiler",
13
+ "worklets",
14
+ "zntc"
15
+ ],
16
+ "homepage": "https://ohah.github.io/zntc",
17
+ "bugs": {
18
+ "url": "https://github.com/ohah/zntc/issues"
19
+ },
20
+ "license": "MIT",
21
+ "author": "ohah",
22
+ "repository": {
23
+ "type": "git",
24
+ "url": "git+https://github.com/ohah/zntc.git",
25
+ "directory": "packages/react-native"
26
+ },
27
+ "files": [
28
+ "dist/",
29
+ "runtime/",
30
+ "README.md"
31
+ ],
32
+ "type": "module",
33
+ "main": "./dist/index.js",
34
+ "types": "./dist/index.d.ts",
35
+ "exports": {
36
+ ".": {
37
+ "types": "./dist/index.d.ts",
38
+ "import": "./dist/index.js"
39
+ },
40
+ "./runtime/zntc-hmr-client.cjs": "./runtime/zntc-hmr-client.cjs"
41
+ },
42
+ "scripts": {
43
+ "build:bundle": "node ../core/bin/zntc.mjs --bundle src/index.ts --outfile dist/index.js --format=esm --target=node --conditions=source --external @zntc/core --external @babel/core --external @react-native/babel-plugin-codegen --external @react-native/babel-preset --external metro-resolver --external react-native --external @react-native/js-polyfills",
44
+ "build:dts": "bun x tsc -b",
45
+ "build": "bun run build:bundle && bun run build:dts",
46
+ "test": "bun test --timeout 10000",
47
+ "prepublishOnly": "bun run build && bunx publint --strict --level error ."
48
+ },
49
+ "dependencies": {
50
+ "@react-native-community/cli-server-api": "^15.0.0",
51
+ "@zntc/core": "workspace:*",
52
+ "jsc-safe-url": "^0.2.4",
53
+ "source-map": "^0.7.4"
54
+ },
55
+ "devDependencies": {
56
+ "@types/node": "^25.5.2",
57
+ "@zntc/server": "workspace:*"
58
+ },
59
+ "optionalDependencies": {
60
+ "@babel/core": "^7.26.0",
61
+ "@react-native/babel-plugin-codegen": "^0.83.0",
62
+ "@react-native/babel-preset": "^0.83.0",
63
+ "@react-native/js-polyfills": "^0.83.0",
64
+ "metro-resolver": "^0.83.0",
65
+ "react-native": "^0.83.0"
66
+ },
67
+ "engines": {
68
+ "node": ">=24.0.0"
69
+ }
70
+ }
File without changes