vxrn 1.12.8 → 1.13.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 (208) hide show
  1. package/dist/config/getAdditionalViteConfig.mjs +1 -4
  2. package/dist/config/getAdditionalViteConfig.mjs.map +1 -1
  3. package/dist/config/getAdditionalViteConfig.native.js +1 -4
  4. package/dist/config/getAdditionalViteConfig.native.js.map +1 -1
  5. package/dist/config/getReactNativePlugins.mjs +1 -5
  6. package/dist/config/getReactNativePlugins.mjs.map +1 -1
  7. package/dist/config/getReactNativePlugins.native.js +1 -5
  8. package/dist/config/getReactNativePlugins.native.js.map +1 -1
  9. package/dist/exports/build.mjs +5 -0
  10. package/dist/exports/build.mjs.map +1 -1
  11. package/dist/exports/build.native.js +5 -0
  12. package/dist/exports/build.native.js.map +1 -1
  13. package/dist/exports/createServer.mjs +30 -25
  14. package/dist/exports/createServer.mjs.map +1 -1
  15. package/dist/exports/createServer.native.js +6 -3
  16. package/dist/exports/createServer.native.js.map +1 -1
  17. package/dist/exports/prebuild.mjs +25 -1
  18. package/dist/exports/prebuild.mjs.map +1 -1
  19. package/dist/exports/prebuild.native.js +30 -1
  20. package/dist/exports/prebuild.native.js.map +1 -1
  21. package/dist/exports/serve.mjs +2 -2
  22. package/dist/exports/serve.mjs.map +1 -1
  23. package/dist/exports/serve.native.js +2 -2
  24. package/dist/exports/serve.native.js.map +1 -1
  25. package/dist/exports/serveStaticAssets.mjs +43 -11
  26. package/dist/exports/serveStaticAssets.mjs.map +1 -1
  27. package/dist/exports/serveStaticAssets.native.js +69 -6
  28. package/dist/exports/serveStaticAssets.native.js.map +1 -1
  29. package/dist/index.js +1 -2
  30. package/dist/index.js.map +1 -1
  31. package/dist/index.mjs +1 -2
  32. package/dist/index.mjs.map +1 -1
  33. package/dist/index.native.js +1 -2
  34. package/dist/index.native.js.map +1 -1
  35. package/dist/patches/builtInDepPatches.mjs +14 -0
  36. package/dist/patches/builtInDepPatches.mjs.map +1 -1
  37. package/dist/patches/builtInDepPatches.native.js +14 -0
  38. package/dist/patches/builtInDepPatches.native.js.map +1 -1
  39. package/dist/plugins/clientInjectPlugin.mjs +2 -62
  40. package/dist/plugins/clientInjectPlugin.mjs.map +1 -1
  41. package/dist/plugins/clientInjectPlugin.native.js +2 -75
  42. package/dist/plugins/clientInjectPlugin.native.js.map +1 -1
  43. package/dist/plugins/reactNativeDevAssetPlugin.mjs +1 -3
  44. package/dist/plugins/reactNativeDevAssetPlugin.mjs.map +1 -1
  45. package/dist/plugins/reactNativeDevAssetPlugin.native.js +1 -3
  46. package/dist/plugins/reactNativeDevAssetPlugin.native.js.map +1 -1
  47. package/dist/plugins/reactNativeDevServer.mjs +55 -77
  48. package/dist/plugins/reactNativeDevServer.mjs.map +1 -1
  49. package/dist/plugins/reactNativeDevServer.native.js +73 -84
  50. package/dist/plugins/reactNativeDevServer.native.js.map +1 -1
  51. package/dist/plugins/serverExtensions.test.mjs +12 -6
  52. package/dist/plugins/serverExtensions.test.mjs.map +1 -1
  53. package/dist/plugins/serverExtensions.test.native.js +12 -6
  54. package/dist/plugins/serverExtensions.test.native.js.map +1 -1
  55. package/dist/rn-commands/bundle/buildBundle.mjs +11 -35
  56. package/dist/rn-commands/bundle/buildBundle.mjs.map +1 -1
  57. package/dist/rn-commands/bundle/buildBundle.native.js +9 -36
  58. package/dist/rn-commands/bundle/buildBundle.native.js.map +1 -1
  59. package/dist/runtime/hmr-client.mjs +125 -0
  60. package/dist/runtime/hmr-client.mjs.map +1 -0
  61. package/dist/runtime/hmr-client.native.js +197 -0
  62. package/dist/runtime/hmr-client.native.js.map +1 -0
  63. package/dist/runtime/hmr-runtime.mjs +162 -0
  64. package/dist/runtime/hmr-runtime.mjs.map +1 -0
  65. package/dist/runtime/hmr-runtime.native.js +348 -0
  66. package/dist/runtime/hmr-runtime.native.js.map +1 -0
  67. package/dist/runtime/hmr-types.mjs +2 -0
  68. package/dist/runtime/hmr-types.mjs.map +1 -0
  69. package/dist/runtime/hmr-types.native.js +2 -0
  70. package/dist/runtime/hmr-types.native.js.map +1 -0
  71. package/dist/runtime/native-prelude.mjs +97 -0
  72. package/dist/runtime/native-prelude.mjs.map +1 -0
  73. package/dist/runtime/native-prelude.native.js +97 -0
  74. package/dist/runtime/native-prelude.native.js.map +1 -0
  75. package/dist/runtime/react-refresh-utils.mjs +19 -0
  76. package/dist/runtime/react-refresh-utils.mjs.map +1 -0
  77. package/dist/runtime/react-refresh-utils.native.js +24 -0
  78. package/dist/runtime/react-refresh-utils.native.js.map +1 -0
  79. package/dist/utils/createNativeDevEngine.mjs +661 -0
  80. package/dist/utils/createNativeDevEngine.mjs.map +1 -0
  81. package/dist/utils/createNativeDevEngine.native.js +702 -0
  82. package/dist/utils/createNativeDevEngine.native.js.map +1 -0
  83. package/dist/utils/patches.mjs +6 -2
  84. package/dist/utils/patches.mjs.map +1 -1
  85. package/dist/utils/patches.native.js +6 -2
  86. package/dist/utils/patches.native.js.map +1 -1
  87. package/dist/utils/scanDepsToOptimize.mjs +4 -3
  88. package/dist/utils/scanDepsToOptimize.mjs.map +1 -1
  89. package/dist/utils/scanDepsToOptimize.native.js +4 -3
  90. package/dist/utils/scanDepsToOptimize.native.js.map +1 -1
  91. package/expo-plugin.cjs +122 -0
  92. package/package.json +15 -19
  93. package/src/config/getAdditionalViteConfig.ts +1 -3
  94. package/src/config/getReactNativePlugins.ts +0 -6
  95. package/src/exports/build.ts +5 -0
  96. package/src/exports/createServer.ts +7 -2
  97. package/src/exports/prebuild.ts +45 -0
  98. package/src/exports/serve.ts +2 -1
  99. package/src/exports/serveStaticAssets.ts +67 -4
  100. package/src/index.ts +0 -2
  101. package/src/patches/builtInDepPatches.ts +29 -0
  102. package/src/plugins/clientInjectPlugin.ts +2 -109
  103. package/src/plugins/reactNativeDevAssetPlugin.ts +0 -21
  104. package/src/plugins/reactNativeDevServer.ts +57 -84
  105. package/src/plugins/serverExtensions.test.ts +6 -8
  106. package/src/rn-commands/bundle/buildBundle.ts +9 -62
  107. package/src/runtime/hmr-client.ts +215 -0
  108. package/src/runtime/hmr-runtime.ts +276 -0
  109. package/src/runtime/hmr-types.ts +84 -0
  110. package/src/runtime/native-prelude.ts +110 -0
  111. package/src/runtime/react-refresh-utils.ts +36 -0
  112. package/src/types.ts +22 -4
  113. package/src/utils/createNativeDevEngine.ts +942 -0
  114. package/src/utils/patches.ts +36 -18
  115. package/src/utils/scanDepsToOptimize.ts +2 -3
  116. package/types/config/getAdditionalViteConfig.d.ts.map +1 -1
  117. package/types/config/getOptionsFilled.d.ts +2 -18
  118. package/types/config/getOptionsFilled.d.ts.map +1 -1
  119. package/types/config/getReactNativePlugins.d.ts.map +1 -1
  120. package/types/exports/build.d.ts +1 -9
  121. package/types/exports/build.d.ts.map +1 -1
  122. package/types/exports/createServer.d.ts.map +1 -1
  123. package/types/exports/prebuild.d.ts.map +1 -1
  124. package/types/exports/serve.d.ts +2 -1
  125. package/types/exports/serve.d.ts.map +1 -1
  126. package/types/exports/serveStaticAssets.d.ts +12 -1
  127. package/types/exports/serveStaticAssets.d.ts.map +1 -1
  128. package/types/index.d.ts +0 -1
  129. package/types/index.d.ts.map +1 -1
  130. package/types/patches/builtInDepPatches.d.ts.map +1 -1
  131. package/types/plugins/clientInjectPlugin.d.ts +1 -7
  132. package/types/plugins/clientInjectPlugin.d.ts.map +1 -1
  133. package/types/plugins/reactNativeDevAssetPlugin.d.ts.map +1 -1
  134. package/types/plugins/reactNativeDevServer.d.ts.map +1 -1
  135. package/types/rn-commands/bundle/buildBundle.d.ts.map +1 -1
  136. package/types/runtime/hmr-client.d.ts +40 -0
  137. package/types/runtime/hmr-client.d.ts.map +1 -0
  138. package/types/runtime/hmr-runtime.d.ts +69 -0
  139. package/types/runtime/hmr-runtime.d.ts.map +1 -0
  140. package/types/runtime/hmr-types.d.ts +76 -0
  141. package/types/runtime/hmr-types.d.ts.map +1 -0
  142. package/types/runtime/native-prelude.d.ts +11 -0
  143. package/types/runtime/native-prelude.d.ts.map +1 -0
  144. package/types/runtime/react-refresh-utils.d.ts +3 -0
  145. package/types/runtime/react-refresh-utils.d.ts.map +1 -0
  146. package/types/types.d.ts +15 -1
  147. package/types/types.d.ts.map +1 -1
  148. package/types/utils/createNativeDevEngine.d.ts +42 -0
  149. package/types/utils/createNativeDevEngine.d.ts.map +1 -0
  150. package/types/utils/patches.d.ts.map +1 -1
  151. package/types/utils/scanDepsToOptimize.d.ts.map +1 -1
  152. package/dist/config/getReactNativeBuildConfig.mjs +0 -200
  153. package/dist/config/getReactNativeBuildConfig.mjs.map +0 -1
  154. package/dist/config/getReactNativeBuildConfig.native.js +0 -204
  155. package/dist/config/getReactNativeBuildConfig.native.js.map +0 -1
  156. package/dist/plugins/reactNativeHMRPlugin.mjs +0 -120
  157. package/dist/plugins/reactNativeHMRPlugin.mjs.map +0 -1
  158. package/dist/plugins/reactNativeHMRPlugin.native.js +0 -151
  159. package/dist/plugins/reactNativeHMRPlugin.native.js.map +0 -1
  160. package/dist/utils/filterPluginsForNative.mjs +0 -27
  161. package/dist/utils/filterPluginsForNative.mjs.map +0 -1
  162. package/dist/utils/filterPluginsForNative.native.js +0 -33
  163. package/dist/utils/filterPluginsForNative.native.js.map +0 -1
  164. package/dist/utils/getReactNativeBundle.mjs +0 -104
  165. package/dist/utils/getReactNativeBundle.mjs.map +0 -1
  166. package/dist/utils/getReactNativeBundle.native.js +0 -135
  167. package/dist/utils/getReactNativeBundle.native.js.map +0 -1
  168. package/dist/utils/hotUpdateCache.mjs +0 -3
  169. package/dist/utils/hotUpdateCache.mjs.map +0 -1
  170. package/dist/utils/hotUpdateCache.native.js +0 -3
  171. package/dist/utils/hotUpdateCache.native.js.map +0 -1
  172. package/dist/utils/isBuildingNativeBundle.mjs +0 -6
  173. package/dist/utils/isBuildingNativeBundle.mjs.map +0 -1
  174. package/dist/utils/isBuildingNativeBundle.native.js +0 -7
  175. package/dist/utils/isBuildingNativeBundle.native.js.map +0 -1
  176. package/dist/utils/swapPrebuiltReactModules.mjs +0 -168
  177. package/dist/utils/swapPrebuiltReactModules.mjs.map +0 -1
  178. package/dist/utils/swapPrebuiltReactModules.native.js +0 -181
  179. package/dist/utils/swapPrebuiltReactModules.native.js.map +0 -1
  180. package/dist/worker.mjs +0 -55
  181. package/dist/worker.mjs.map +0 -1
  182. package/dist/worker.native.js +0 -55
  183. package/dist/worker.native.js.map +0 -1
  184. package/react-native-template.js +0 -375
  185. package/src/config/getReactNativeBuildConfig.ts +0 -349
  186. package/src/plugins/reactNativeHMRPlugin.ts +0 -237
  187. package/src/utils/filterPluginsForNative.ts +0 -55
  188. package/src/utils/getReactNativeBundle.ts +0 -243
  189. package/src/utils/hotUpdateCache.ts +0 -1
  190. package/src/utils/isBuildingNativeBundle.ts +0 -7
  191. package/src/utils/swapPrebuiltReactModules.ts +0 -341
  192. package/src/worker.ts +0 -90
  193. package/types/config/getReactNativeBuildConfig.d.ts +0 -72
  194. package/types/config/getReactNativeBuildConfig.d.ts.map +0 -1
  195. package/types/plugins/reactNativeHMRPlugin.d.ts +0 -10
  196. package/types/plugins/reactNativeHMRPlugin.d.ts.map +0 -1
  197. package/types/utils/filterPluginsForNative.d.ts +0 -8
  198. package/types/utils/filterPluginsForNative.d.ts.map +0 -1
  199. package/types/utils/getReactNativeBundle.d.ts +0 -12
  200. package/types/utils/getReactNativeBundle.d.ts.map +0 -1
  201. package/types/utils/hotUpdateCache.d.ts +0 -2
  202. package/types/utils/hotUpdateCache.d.ts.map +0 -1
  203. package/types/utils/isBuildingNativeBundle.d.ts +0 -3
  204. package/types/utils/isBuildingNativeBundle.d.ts.map +0 -1
  205. package/types/utils/swapPrebuiltReactModules.d.ts +0 -9
  206. package/types/utils/swapPrebuiltReactModules.d.ts.map +0 -1
  207. package/types/worker.d.ts +0 -13
  208. package/types/worker.d.ts.map +0 -1
@@ -0,0 +1,110 @@
1
+ /**
2
+ * native bundle prelude - minimal globals for React Native.
3
+ * injected via rolldown's `intro` output option.
4
+ * rolldown's devMode handles the module system.
5
+ */
6
+
7
+ // this is output as a raw string, not compiled as a module
8
+ export function getNativePrelude(options: {
9
+ dev: boolean
10
+ platform: string
11
+ serverUrl?: string
12
+ }): string {
13
+ return `
14
+ var __BUNDLE_START_TIME__ = globalThis.nativePerformanceNow ? nativePerformanceNow() : Date.now();
15
+
16
+ var global = typeof globalThis !== 'undefined' ? globalThis
17
+ : typeof global !== 'undefined' ? global
18
+ : typeof window !== 'undefined' ? window
19
+ : this;
20
+
21
+ globalThis.global = global;
22
+ globalThis.__DEV__ = ${options.dev};
23
+
24
+ // react native polyfills
25
+ global.__FUSEBOX_HAS_FULL_CONSOLE_SUPPORT__ = false;
26
+ global.Event = global.Event || function() { return this; };
27
+ global.dispatchEvent = global.dispatchEvent || function() {};
28
+ global.window = global.window || global;
29
+ global.self = global.self || global;
30
+ global.navigator = global.navigator || { product: 'ReactNative', userAgent: '' };
31
+ global.performance = global.performance || { now: function() { return Date.now(); } };
32
+
33
+ // ErrorUtils - used by RN's error handling system
34
+ if (!global.ErrorUtils) {
35
+ var _handler = null;
36
+ global.ErrorUtils = {
37
+ setGlobalHandler: function(h) { _handler = h; },
38
+ getGlobalHandler: function() { return _handler; },
39
+ reportFatalError: function(e) { if (_handler) _handler(e, true); else throw e; },
40
+ reportError: function(e) { if (_handler) _handler(e, false); },
41
+ applyWithGuard: function(fn, ctx, args) { try { return fn.apply(ctx, args); } catch(e) { this.reportError(e); } },
42
+ };
43
+ }
44
+
45
+ if (typeof process === 'undefined') {
46
+ globalThis.process = { env: {} };
47
+ }
48
+ process.env.NODE_ENV = ${JSON.stringify(options.dev ? 'development' : 'production')};
49
+ process.env.EXPO_OS = ${JSON.stringify(options.platform)};
50
+ ${options.serverUrl ? `process.env.ONE_SERVER_URL = ${JSON.stringify(options.serverUrl)};` : ''}
51
+
52
+ // polyfill setImmediate (used by react-native internals)
53
+ if (typeof globalThis.setImmediate === 'undefined') {
54
+ globalThis.setImmediate = function(fn) { return setTimeout(fn, 0); };
55
+ globalThis.clearImmediate = function(id) { clearTimeout(id); };
56
+ }
57
+
58
+ // polyfill URLSearchParams early (before whatwg-fetch checks for it)
59
+ // RN's polyfillGlobal sets this up later but some modules check at import time
60
+ if (typeof globalThis.URLSearchParams === 'undefined') {
61
+ // minimal URLSearchParams polyfill - will be overridden by RN's proper one
62
+ globalThis.URLSearchParams = function URLSearchParams(init) {
63
+ this._params = {};
64
+ if (typeof init === 'string') {
65
+ init.replace(/^\\?/, '').split('&').forEach(function(p) {
66
+ var kv = p.split('=');
67
+ if (kv[0]) this._params[decodeURIComponent(kv[0])] = decodeURIComponent(kv[1] || '');
68
+ }.bind(this));
69
+ }
70
+ };
71
+ globalThis.URLSearchParams.prototype.get = function(k) { return this._params[k] || null; };
72
+ globalThis.URLSearchParams.prototype.toString = function() {
73
+ return Object.keys(this._params).map(function(k) { return encodeURIComponent(k) + '=' + encodeURIComponent(this._params[k]); }.bind(this)).join('&');
74
+ };
75
+ }
76
+
77
+ // suppress HMRClient.setup() error from native side
78
+ // native calls HMRClient.setup() during bundle load but we don't use Metro HMR
79
+ // this intercept catches the error and prevents the red screen
80
+ var __origErrorHandler = globalThis.ErrorUtils && globalThis.ErrorUtils.getGlobalHandler && globalThis.ErrorUtils.getGlobalHandler();
81
+ if (globalThis.ErrorUtils && globalThis.ErrorUtils.setGlobalHandler) {
82
+ globalThis.ErrorUtils.setGlobalHandler(function(error, isFatal) {
83
+ if (error && error.message && error.message.indexOf('HMRClient') !== -1) {
84
+ // suppress HMRClient errors silently
85
+ return;
86
+ }
87
+ if (__origErrorHandler) __origErrorHandler(error, isFatal);
88
+ });
89
+ }
90
+
91
+ // reanimated compat - these console methods must exist to avoid EXC_BAD_ACCESS crash
92
+ console.assert = console.assert || function() {};
93
+ console.clear = console.clear || function() {};
94
+ console.dir = console.dir || function() {};
95
+ console.dirxml = console.dirxml || function() {};
96
+ console.profile = console.profile || function() {};
97
+ console.profileEnd = console.profileEnd || function() {};
98
+ console.table = console.table || function() {};
99
+
100
+ // react refresh stubs (overridden by react-refresh plugin in dev)
101
+ ${
102
+ options.dev
103
+ ? `
104
+ var $RefreshReg$ = function() {};
105
+ var $RefreshSig$ = function() { return function(v) { return v; }; };
106
+ `
107
+ : ''
108
+ }
109
+ `.trim()
110
+ }
@@ -0,0 +1,36 @@
1
+ export function isReactRefreshBoundary(moduleExports: Record<string, unknown>) {
2
+ if (globalThis.__ReactRefresh.isLikelyComponentType(moduleExports)) {
3
+ return true
4
+ }
5
+
6
+ if (
7
+ moduleExports === undefined ||
8
+ moduleExports === null ||
9
+ typeof moduleExports !== 'object'
10
+ ) {
11
+ return false
12
+ }
13
+
14
+ var hasExports = false
15
+ var areAllExportsComponents = true
16
+ for (var key in moduleExports) {
17
+ hasExports = true
18
+ if (key === '__esModule') continue
19
+ var exportValue = moduleExports[key]
20
+ if (!globalThis.__ReactRefresh.isLikelyComponentType(exportValue)) {
21
+ areAllExportsComponents = false
22
+ }
23
+ }
24
+
25
+ return hasExports && areAllExportsComponents
26
+ }
27
+
28
+ let timer: ReturnType<typeof setTimeout> | null = null
29
+
30
+ export function enqueueUpdate() {
31
+ if (timer) return
32
+ timer = setTimeout(() => {
33
+ globalThis.__ReactRefresh.performReactRefresh()
34
+ timer = null
35
+ }, 50)
36
+ }
package/src/types.ts CHANGED
@@ -112,6 +112,21 @@ export type VXRNOptions = {
112
112
  * @default false
113
113
  */
114
114
  loadEnv?: boolean
115
+
116
+ /**
117
+ * Custom cache-control rules for static assets.
118
+ * Map of glob patterns to Cache-Control header values.
119
+ * Hashed assets (e.g. app-CB4EB78V.js) are always immutable.
120
+ * Unmatched assets default to must-revalidate.
121
+ *
122
+ * @example
123
+ * cacheControl: {
124
+ * '*.worker.js': 'public, max-age=86400, stale-while-revalidate=604800',
125
+ * '*.wasm': 'public, max-age=86400',
126
+ * '/deps-*\/**': 'public, max-age=86400',
127
+ * }
128
+ */
129
+ cacheControl?: Record<string, string>
115
130
  }
116
131
 
117
132
  /**
@@ -135,10 +150,13 @@ export type HMRListener = (update: { file: string; contents: string }) => void
135
150
 
136
151
  type VXRNServeOptionsBase = VXRNOptions['server']
137
152
 
138
- export type VXRNServeOptionsFilled = Required<VXRNServeOptionsBase> & {
139
- url: string
140
- protocol: string
141
- }
153
+ export type VXRNServeOptionsFilled = Required<
154
+ Omit<NonNullable<VXRNServeOptionsBase>, 'cacheControl'>
155
+ > &
156
+ Pick<NonNullable<VXRNServeOptionsBase>, 'cacheControl'> & {
157
+ url: string
158
+ protocol: string
159
+ }
142
160
 
143
161
  export type VXRNServeOptions = VXRNServeOptionsBase & {
144
162
  app?: Hono