@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,328 @@
1
+ /**
2
+ * ZNTC HMR Client - Metro HMRClient interface replacement for ZNTC bundler.
3
+ * Connects to the dev server WebSocket and applies ZNTC-format HMR updates
4
+ * via __zntc_apply_update() (injected by ZNTC dev mode runtime).
5
+ */
6
+ 'use strict';
7
+
8
+ var REFRESH_TEXT_COLOR = -1; // #ffffff
9
+ var REFRESH_BACKGROUND_COLOR = -14318360; // #2584e8
10
+ var BUFFER_LIMIT = 1024 * 1024;
11
+ var prettyFormat = require('pretty-format');
12
+ var prettyFormatImpl = prettyFormat && (prettyFormat.default || prettyFormat);
13
+
14
+ function getRoot() {
15
+ return (
16
+ (typeof global !== 'undefined' && global) ||
17
+ (typeof globalThis !== 'undefined' && globalThis) ||
18
+ (typeof window !== 'undefined' && window) ||
19
+ null
20
+ );
21
+ }
22
+
23
+ function getDirectNativeDevLoadingView() {
24
+ try {
25
+ var root = getRoot();
26
+ if (root) {
27
+ if (root.nativeModuleProxy && root.nativeModuleProxy.DevLoadingView) {
28
+ return root.nativeModuleProxy.DevLoadingView;
29
+ }
30
+ if (typeof root.__turboModuleProxy === 'function') {
31
+ var turboModule = root.__turboModuleProxy('DevLoadingView');
32
+ if (turboModule) return turboModule;
33
+ }
34
+ if (root.NativeModules && root.NativeModules.DevLoadingView) {
35
+ return root.NativeModules.DevLoadingView;
36
+ }
37
+ }
38
+ } catch {
39
+ // fallback 으로 내려간다.
40
+ }
41
+
42
+ try {
43
+ if (typeof require === 'function') {
44
+ var nativeModules = require('../BatchedBridge/NativeModules');
45
+ nativeModules = nativeModules && (nativeModules.default || nativeModules);
46
+ if (nativeModules && nativeModules.DevLoadingView) {
47
+ return nativeModules.DevLoadingView;
48
+ }
49
+ }
50
+ } catch {
51
+ // fallback 으로 내려간다.
52
+ }
53
+
54
+ try {
55
+ if (typeof require === 'function') {
56
+ var rn = require('react-native');
57
+ var rnNativeModules = rn && rn.NativeModules;
58
+ if (rnNativeModules && rnNativeModules.DevLoadingView) {
59
+ return rnNativeModules.DevLoadingView;
60
+ }
61
+ }
62
+ } catch {
63
+ // fallback 으로 내려간다.
64
+ }
65
+
66
+ return null;
67
+ }
68
+
69
+ function wrapNativeDevLoadingView(nativeDevLoadingView) {
70
+ return {
71
+ showMessage: function (message, _type, options) {
72
+ nativeDevLoadingView.showMessage(
73
+ message,
74
+ REFRESH_TEXT_COLOR,
75
+ REFRESH_BACKGROUND_COLOR,
76
+ !!(options && options.dismissButton),
77
+ );
78
+ },
79
+ hide: function () {
80
+ nativeDevLoadingView.hide();
81
+ },
82
+ };
83
+ }
84
+
85
+ // wrapper 내부 NativeDevLoadingView 값이 초기화 시점에 null 로 굳을 수 있어,
86
+ // 호출 시점 native module 재조회 경로를 먼저 시도한 뒤 require 로 폴백.
87
+ function getDevLoadingView() {
88
+ var nativeDevLoadingView = getDirectNativeDevLoadingView();
89
+ if (nativeDevLoadingView && typeof nativeDevLoadingView.showMessage === 'function') {
90
+ return wrapNativeDevLoadingView(nativeDevLoadingView);
91
+ }
92
+
93
+ try {
94
+ if (typeof require === 'function') {
95
+ var mod = require('./DevLoadingView');
96
+ return mod && (mod.default || mod) ? mod.default || mod : null;
97
+ }
98
+ } catch {
99
+ // RN module resolution 실패 시 fallback 으로 내려간다.
100
+ }
101
+
102
+ return null;
103
+ }
104
+
105
+ function formatLogItem(item) {
106
+ if (typeof item === 'string') return item;
107
+ return prettyFormatImpl.format(item, {
108
+ escapeString: true,
109
+ highlight: true,
110
+ maxDepth: 3,
111
+ min: true,
112
+ plugins: [prettyFormatImpl.plugins.ReactElement],
113
+ });
114
+ }
115
+
116
+ var HMRClient = {
117
+ _socket: null,
118
+ _enabled: true,
119
+ _pendingLogs: [],
120
+ // 중첩 update 카운트 — 마지막 update-done 에서만 배너 hide.
121
+ _pendingUpdates: 0,
122
+ // lazy cache — 첫 호출 때 1회 lookup (native module 가 setup 시점엔 아직 미로드).
123
+ // socket.onclose 에서 invalidate — reconnect 시 module 상태 재조회.
124
+ _devLoadingView: null,
125
+
126
+ _safeCallDlv: function (method, args) {
127
+ if (this._devLoadingView == null) this._devLoadingView = getDevLoadingView();
128
+ var dlv = this._devLoadingView;
129
+ if (dlv && typeof dlv[method] === 'function') {
130
+ try {
131
+ dlv[method].apply(dlv, args);
132
+ } catch {
133
+ // DevLoadingView 호출 실패는 HMR 동작과 무관 — 무시
134
+ }
135
+ }
136
+ },
137
+
138
+ _showRefreshing: function () {
139
+ this._safeCallDlv('showMessage', ['Refreshing...', 'refresh']);
140
+ },
141
+
142
+ _hideRefreshing: function () {
143
+ this._safeCallDlv('hide', []);
144
+ },
145
+
146
+ enable: function () {
147
+ this._enabled = true;
148
+ },
149
+
150
+ disable: function () {
151
+ this._enabled = false;
152
+ },
153
+
154
+ registerBundle: function (_requestUrl) {
155
+ // No-op: ZNTC bundler does not require bundle registration
156
+ },
157
+
158
+ _sendLog: function (level, data) {
159
+ var socket = this._socket;
160
+ if (!socket || socket.readyState !== 1 || socket.bufferedAmount > BUFFER_LIMIT) {
161
+ return false;
162
+ }
163
+ try {
164
+ var formatted = Array.prototype.map.call(data || [], function (item) {
165
+ return formatLogItem(item);
166
+ });
167
+ socket.send(JSON.stringify({ type: 'log', level: level, data: formatted }));
168
+ return true;
169
+ } catch {
170
+ return false;
171
+ }
172
+ },
173
+
174
+ _flushPendingLogs: function () {
175
+ var pending = this._pendingLogs;
176
+ this._pendingLogs = [];
177
+ for (var i = 0; i < pending.length; i++) {
178
+ this._sendLog(pending[i][0], pending[i][1]);
179
+ }
180
+ },
181
+
182
+ log: function (level, data) {
183
+ if (this._sendLog(level, data)) return;
184
+ if (!this._socket) {
185
+ this._pendingLogs.push([level, data]);
186
+ if (this._pendingLogs.length > 100) {
187
+ this._pendingLogs.shift();
188
+ }
189
+ }
190
+ },
191
+
192
+ setup: function (platform, bundleEntry, host, port, isEnabled, scheme) {
193
+ if (this._socket != null) {
194
+ return;
195
+ }
196
+ var protocol = scheme === 'https' ? 'wss' : 'ws';
197
+ var portPart = port != null && port !== '' ? ':' + port : '';
198
+ var wsUrl = protocol + '://' + host + portPart + '/hot';
199
+ var socket = new (typeof WebSocket !== 'undefined' ? WebSocket : global.WebSocket)(wsUrl);
200
+ this._socket = socket;
201
+ this._enabled = isEnabled !== false;
202
+
203
+ var self = this;
204
+
205
+ socket.onopen = function () {
206
+ socket.send(
207
+ JSON.stringify({
208
+ type: 'hmr:connected',
209
+ bundleEntry: bundleEntry,
210
+ platform: platform,
211
+ }),
212
+ );
213
+ self._flushPendingLogs();
214
+ };
215
+
216
+ socket.onmessage = function (event) {
217
+ try {
218
+ var msg = JSON.parse(event.data);
219
+ if (!self._enabled && msg.type !== 'hmr:error') {
220
+ return;
221
+ }
222
+ switch (msg.type) {
223
+ case 'hmr:update-start':
224
+ self._pendingUpdates++;
225
+ // initial sequence (connect 시 로딩바 dismiss 용) 는 실제 코드 변경이
226
+ // 아니므로 "Refreshing..." 배너 노출 skip.
227
+ if (self._enabled && !msg.isInitialUpdate) {
228
+ self._showRefreshing();
229
+ }
230
+ break;
231
+ case 'hmr:update':
232
+ // hmr-client debug — __ZNTC_HMR_DEBUG__ true 시에만 update 도착/주입
233
+ // 진행 로그 출력. 터미널 forwarding 여부와 별개로 기본 비활성화.
234
+ var hmrDebug = typeof __ZNTC_HMR_DEBUG__ !== 'undefined' ? __ZNTC_HMR_DEBUG__ : false;
235
+ if (hmrDebug) {
236
+ console.log(
237
+ '[ZNTC HMR] update received, modules:',
238
+ msg.modules ? msg.modules.length : 0,
239
+ );
240
+ }
241
+ var applyFn =
242
+ typeof __zntc_apply_update === 'function'
243
+ ? __zntc_apply_update
244
+ : global.__zntc_apply_update;
245
+ if (typeof applyFn === 'function' && msg.modules && msg.modules.length > 0) {
246
+ if (hmrDebug) {
247
+ console.log(
248
+ '[ZNTC HMR] applying',
249
+ msg.modules.length,
250
+ typeof __zntc_apply_update === 'function'
251
+ ? 'modules (local)'
252
+ : 'modules (global)',
253
+ );
254
+ }
255
+ try {
256
+ applyFn(msg.modules);
257
+ if (hmrDebug) console.log('[ZNTC HMR] apply OK');
258
+ } catch (e) {
259
+ // 항상 출력 — apply 실패는 silent 면 안 됨. 사용자 진단 정보.
260
+ console.error('[ZNTC HMR] __zntc_apply_update threw:', e);
261
+ }
262
+ } else if (hmrDebug || (msg.modules && msg.modules.length > 0)) {
263
+ // modules 가 있는데 applyFn 없으면 항상 warn (런타임 주입 누락 진단).
264
+ // modules 비었고 debug off 면 silent (normal idle).
265
+ console.warn('[ZNTC HMR] __zntc_apply_update not available or no modules');
266
+ }
267
+ break;
268
+ case 'hmr:update-done':
269
+ if (self._pendingUpdates > 0) self._pendingUpdates--;
270
+ if (self._pendingUpdates === 0) {
271
+ self._hideRefreshing();
272
+ }
273
+ break;
274
+ case 'hmr:reload':
275
+ // Reuse __zntc_reload() from ZNTC HMR runtime (injected via --dev mode)
276
+ if (typeof __zntc_reload === 'function') {
277
+ __zntc_reload();
278
+ } else if (typeof location !== 'undefined') {
279
+ location.reload();
280
+ }
281
+ break;
282
+ case 'hmr:error':
283
+ // body.errors 가 있으면 file:line:col 정보를 함께 출력 — RN LogBox 가
284
+ // source link 자동 추출 → 클릭 시 editor jump. backward-compat 으로
285
+ // body 가 없는 메시지는 단순 message 만 출력.
286
+ if (msg.body && msg.body.errors && msg.body.errors[0]) {
287
+ var err = msg.body.errors[0];
288
+ // filename / lineNumber / column 은 type 상 모두 optional.
289
+ // 셋 다 있을 때만 location 부착 — 없으면 'foo.ts:undefined:undefined' 같은
290
+ // false-positive 회피.
291
+ var hasLoc =
292
+ err.filename &&
293
+ typeof err.lineNumber === 'number' &&
294
+ typeof err.column === 'number';
295
+ var loc = hasLoc ? ' ' + err.filename + ':' + err.lineNumber + ':' + err.column : '';
296
+ console.error('[ZNTC HMR]' + loc, err.description || msg.message);
297
+ } else if (msg.message) {
298
+ console.error('[ZNTC HMR]', msg.message);
299
+ }
300
+ break;
301
+ default:
302
+ break;
303
+ }
304
+ } catch (e) {
305
+ console.warn('[ZNTC HMR] Invalid message', e);
306
+ }
307
+ };
308
+
309
+ socket.onerror = function () {
310
+ console.warn('[ZNTC HMR] WebSocket error');
311
+ };
312
+
313
+ socket.onclose = function () {
314
+ // 중첩 update 도중 socket drop 시 stuck banner 방지.
315
+ if (self._pendingUpdates > 0) {
316
+ self._pendingUpdates = 0;
317
+ self._hideRefreshing();
318
+ }
319
+ // DevLoadingView cache 무효화 — reconnect 시 module 상태 변경 가능.
320
+ self._devLoadingView = null;
321
+ self._socket = null;
322
+ };
323
+ },
324
+ };
325
+
326
+ // RN의 setUpBatchedBridge가 require('HMRClient').default로 접근하므로 default export 필요
327
+ module.exports = HMRClient;
328
+ module.exports.default = HMRClient;