@vxrn/react-native-prebuilt 1.1.160 → 1.1.161

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.
package/package.json CHANGED
@@ -1,13 +1,16 @@
1
1
  {
2
2
  "name": "@vxrn/react-native-prebuilt",
3
3
  "type": "module",
4
- "version": "1.1.160",
4
+ "version": "1.1.161",
5
5
  "types": "./types/index.d.ts",
6
6
  "main": "dist/cjs",
7
7
  "module": "dist/esm",
8
8
  "license": "MIT",
9
9
  "files": [
10
- "dist"
10
+ "dist",
11
+ "vendor",
12
+ "src",
13
+ "types"
11
14
  ],
12
15
  "scripts": {
13
16
  "prebuild": "node -r esbuild-register ./prebuild-react-native.ts",
@@ -27,8 +30,8 @@
27
30
  "./jsx-runtime": "./vendor/react/jsx-dev-runtime.js"
28
31
  },
29
32
  "dependencies": {
30
- "@vxrn/vite-flow": "1.1.160",
31
- "@vxrn/vite-native-hmr": "1.1.160",
33
+ "@vxrn/vite-flow": "1.1.161",
34
+ "@vxrn/vite-native-hmr": "1.1.161",
32
35
  "esbuild": "~0.19.3",
33
36
  "fs-extra": "^11.2.0",
34
37
  "import-meta-resolve": "^4.1.0"
package/src/index.ts ADDED
@@ -0,0 +1,327 @@
1
+ import { readFile } from 'node:fs/promises'
2
+
3
+ import { transformFlow } from '@vxrn/vite-flow'
4
+ import { build, type BuildOptions } from 'esbuild'
5
+ import FSExtra from 'fs-extra'
6
+ import { resolve as importMetaResolve } from 'import-meta-resolve'
7
+
8
+ const external = ['react', 'react/jsx-runtime', 'react/jsx-dev-runtime']
9
+
10
+ export async function buildAll() {
11
+ console.info(`Prebuilding React Native (one time cost...)`)
12
+ await Promise.all([
13
+ //
14
+ buildReactJSX(),
15
+ buildReact(),
16
+ buildReactNative(),
17
+ ])
18
+ }
19
+
20
+ const resolveFile = (path: string) => {
21
+ try {
22
+ return importMetaResolve(path, import.meta.url).replace('file://', '')
23
+ } catch {
24
+ return require.resolve(path)
25
+ }
26
+ }
27
+
28
+ export async function buildReactJSX(options: BuildOptions = {}) {
29
+ return build({
30
+ bundle: true,
31
+ entryPoints: [resolveFile('react/jsx-dev-runtime')],
32
+ format: 'cjs',
33
+ target: 'node16',
34
+ jsx: 'transform',
35
+ jsxFactory: 'react',
36
+ allowOverwrite: true,
37
+ platform: 'node',
38
+ define: {
39
+ __DEV__: 'true',
40
+ 'process.env.NODE_ENV': `"development"`,
41
+ },
42
+ external,
43
+ logLevel: 'warning',
44
+ ...options,
45
+ }).then(async () => {
46
+ // manual force exports
47
+ const bundled = await readFile(options.outfile!, 'utf-8')
48
+ const outCode = `
49
+ const run = () => {
50
+ ${bundled.replace(
51
+ `module.exports = require_react_jsx_dev_runtime_development();`,
52
+ `return require_react_jsx_dev_runtime_development();`
53
+ )}
54
+ }
55
+ const __mod__ = run()
56
+ ${['jsx', 'jsxs', 'jsxDEV', 'Fragment']
57
+ .map((n) => `export const ${n} = __mod__.${n} || __mod__.jsx || __mod__.jsxDEV`)
58
+ .join('\n')}
59
+ `
60
+ await FSExtra.writeFile(options.outfile!, outCode)
61
+ })
62
+ }
63
+
64
+ export async function buildReact(options: BuildOptions = {}) {
65
+ return build({
66
+ bundle: true,
67
+ entryPoints: [resolveFile('react')],
68
+ format: 'cjs',
69
+ target: 'node16',
70
+ jsx: 'transform',
71
+ jsxFactory: 'react',
72
+ allowOverwrite: true,
73
+ platform: 'node',
74
+ define: {
75
+ __DEV__: 'true',
76
+ 'process.env.NODE_ENV': `"development"`,
77
+ },
78
+ logLevel: 'warning',
79
+ external,
80
+ ...options,
81
+ }).then(async () => {
82
+ // manual force exports
83
+ const bundled = await readFile(options.outfile!, 'utf-8')
84
+ const outCode = `
85
+ const run = () => {
86
+ ${bundled.replace(
87
+ `module.exports = require_react_development();`,
88
+ `return require_react_development();`
89
+ )}
90
+ }
91
+ const __mod__ = run()
92
+ ${RExports.map((n) => `export const ${n} = __mod__.${n}`).join('\n')}
93
+ export default __mod__
94
+ `
95
+ await FSExtra.writeFile(options.outfile!, outCode)
96
+ })
97
+ }
98
+
99
+ export async function buildReactNative(options: BuildOptions = {}) {
100
+ return build({
101
+ bundle: true,
102
+ entryPoints: [resolveFile('react-native')],
103
+ format: 'cjs',
104
+ target: 'node20',
105
+ // Note: JSX is actually being transformed by the "remove-flow" plugin defined underneath, not by esbuild. The following JSX options may not actually make a difference.
106
+ jsx: 'transform',
107
+ jsxFactory: 'react',
108
+ allowOverwrite: true,
109
+ platform: 'node',
110
+ external,
111
+ loader: {
112
+ '.png': 'dataurl',
113
+ '.jpg': 'dataurl',
114
+ '.jpeg': 'dataurl',
115
+ '.gif': 'dataurl',
116
+ },
117
+ define: {
118
+ __DEV__: 'true',
119
+ 'process.env.NODE_ENV': `"development"`,
120
+ },
121
+ logLevel: 'warning',
122
+ resolveExtensions: [
123
+ '.ios.js',
124
+ '.native.js',
125
+ '.native.ts',
126
+ '.native.tsx',
127
+ '.js',
128
+ '.jsx',
129
+ '.json',
130
+ '.ts',
131
+ '.tsx',
132
+ '.mjs',
133
+ ],
134
+ ...options,
135
+ plugins: [
136
+ {
137
+ name: 'remove-flow',
138
+ setup(build) {
139
+ build.onResolve(
140
+ {
141
+ filter: /HMRClient/,
142
+ },
143
+ async (input) => {
144
+ return {
145
+ path: resolveFile('@vxrn/vite-native-hmr'),
146
+ }
147
+ }
148
+ )
149
+
150
+ build.onLoad(
151
+ {
152
+ filter: /.*.js/,
153
+ },
154
+ async (input) => {
155
+ if (!input.path.includes('react-native') && !input.path.includes(`vite-native-hmr`)) {
156
+ return
157
+ }
158
+
159
+ const code = await readFile(input.path, 'utf-8')
160
+
161
+ // omg so ugly but no class support?
162
+ const outagain = await transformFlow(code, { development: true })
163
+
164
+ return {
165
+ contents: outagain,
166
+ loader: 'jsx',
167
+ }
168
+ }
169
+ )
170
+ },
171
+ },
172
+ ],
173
+ }).then(async () => {
174
+ // manual force exports
175
+ const bundled = await readFile(options.outfile!, 'utf-8')
176
+ const outCode = `
177
+ const run = () => {
178
+ ${bundled
179
+ // .replaceAll('require("react/jsx-runtime")', 'require("react/jsx-dev-runtime")')
180
+ .replace(
181
+ esbuildCommonJSFunction,
182
+ `
183
+ // replaced commonjs function to allow importing internals
184
+ var __commonJS = (cb, mod) => function __require() {
185
+ if (mod) return mod
186
+ const path = __getOwnPropNames(cb)[0]
187
+ const moduleFn = cb[path]
188
+ mod = { exports: {} }
189
+ moduleFn(mod.exports, mod)
190
+ mod = mod.exports
191
+
192
+ // this is our patch basically allowing importing the inner contents:
193
+ globalThis['__cachedModules'][path.replace(/.*node_modules\\//, '').replace('.js', '')] = mod
194
+
195
+ return mod
196
+ };
197
+ `
198
+ )
199
+ .replace(`module.exports = require_react_native();`, `return require_react_native();`)}
200
+ }
201
+ const RN = run()
202
+ ${RNExportNames.map((n) => `export const ${n} = RN.${n}`).join('\n')}
203
+ `
204
+ await FSExtra.writeFile(options.outfile!, outCode)
205
+ })
206
+ }
207
+
208
+ const esbuildCommonJSFunction = `var __commonJS = (cb, mod) => function __require() {
209
+ return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
210
+ };`
211
+
212
+ const RNExportNames = [
213
+ 'registerCallableModule',
214
+ 'AccessibilityInfo',
215
+ 'ActivityIndicator',
216
+ 'Button',
217
+ 'DrawerLayoutAndroid',
218
+ 'FlatList',
219
+ 'Image',
220
+ 'ImageBackground',
221
+ 'InputAccessoryView',
222
+ 'KeyboardAvoidingView',
223
+ 'Modal',
224
+ 'Pressable',
225
+ 'RefreshControl',
226
+ 'SafeAreaView',
227
+ 'ScrollView',
228
+ 'SectionList',
229
+ 'StatusBar',
230
+ 'Switch',
231
+ 'Text',
232
+ 'TextInput',
233
+ 'Touchable',
234
+ 'TouchableHighlight',
235
+ 'TouchableNativeFeedback',
236
+ 'TouchableOpacity',
237
+ 'TouchableWithoutFeedback',
238
+ 'View',
239
+ 'VirtualizedList',
240
+ 'VirtualizedSectionList',
241
+ 'ActionSheetIOS',
242
+ 'Alert',
243
+ 'Animated',
244
+ 'Appearance',
245
+ 'AppRegistry',
246
+ 'AppState',
247
+ 'BackHandler',
248
+ 'DeviceInfo',
249
+ 'DevSettings',
250
+ 'Dimensions',
251
+ 'Easing',
252
+ 'findNodeHandle',
253
+ 'I18nManager',
254
+ 'InteractionManager',
255
+ 'Keyboard',
256
+ 'LayoutAnimation',
257
+ 'Linking',
258
+ 'LogBox',
259
+ 'NativeDialogManagerAndroid',
260
+ 'NativeEventEmitter',
261
+ 'Networking',
262
+ 'PanResponder',
263
+ 'PermissionsAndroid',
264
+ 'PixelRatio',
265
+ 'Settings',
266
+ 'Share',
267
+ 'StyleSheet',
268
+ 'Systrace',
269
+ 'ToastAndroid',
270
+ 'TurboModuleRegistry',
271
+ 'UIManager',
272
+ 'unstable_batchedUpdates',
273
+ 'useAnimatedValue',
274
+ 'useColorScheme',
275
+ 'useWindowDimensions',
276
+ 'UTFSequence',
277
+ 'Vibration',
278
+ 'YellowBox',
279
+ 'DeviceEventEmitter',
280
+ 'DynamicColorIOS',
281
+ 'NativeAppEventEmitter',
282
+ 'NativeModules',
283
+ 'Platform',
284
+ 'PlatformColor',
285
+ 'processColor',
286
+ 'requireNativeComponent',
287
+ 'RootTagContext',
288
+ 'unstable_enableLogBox',
289
+ ]
290
+
291
+ const RExports = [
292
+ 'Children',
293
+ 'Component',
294
+ 'Fragment',
295
+ 'Profiler',
296
+ 'PureComponent',
297
+ 'StrictMode',
298
+ 'Suspense',
299
+ '__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED',
300
+ 'cloneElement',
301
+ 'createContext',
302
+ 'createElement',
303
+ 'createFactory',
304
+ 'createRef',
305
+ 'forwardRef',
306
+ 'isValidElement',
307
+ 'lazy',
308
+ 'memo',
309
+ 'startTransition',
310
+ 'unstable_act',
311
+ 'useCallback',
312
+ 'useContext',
313
+ 'useDebugValue',
314
+ 'useDeferredValue',
315
+ 'useEffect',
316
+ 'useId',
317
+ 'useImperativeHandle',
318
+ 'useInsertionEffect',
319
+ 'useLayoutEffect',
320
+ 'useMemo',
321
+ 'useReducer',
322
+ 'useRef',
323
+ 'useState',
324
+ 'useSyncExternalStore',
325
+ 'useTransition',
326
+ 'version',
327
+ ]
@@ -0,0 +1,6 @@
1
+ import { type BuildOptions } from 'esbuild';
2
+ export declare function buildAll(): Promise<void>;
3
+ export declare function buildReactJSX(options?: BuildOptions): Promise<void>;
4
+ export declare function buildReact(options?: BuildOptions): Promise<void>;
5
+ export declare function buildReactNative(options?: BuildOptions): Promise<void>;
6
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA,OAAO,EAAS,KAAK,YAAY,EAAE,MAAM,SAAS,CAAA;AAMlD,wBAAsB,QAAQ,kBAQ7B;AAUD,wBAAsB,aAAa,CAAC,OAAO,GAAE,YAAiB,iBAkC7D;AAED,wBAAsB,UAAU,CAAC,OAAO,GAAE,YAAiB,iBAiC1D;AAED,wBAAsB,gBAAgB,CAAC,OAAO,GAAE,YAAiB,iBA2GhE"}
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) Facebook, Inc. and its affiliates.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,37 @@
1
+ # `react`
2
+
3
+ React is a JavaScript library for creating user interfaces.
4
+
5
+ The `react` package contains only the functionality necessary to define React components. It is typically used together with a React renderer like `react-dom` for the web, or `react-native` for the native environments.
6
+
7
+ **Note:** by default, React will be in development mode. The development version includes extra warnings about common mistakes, whereas the production version includes extra performance optimizations and strips all error messages. Don't forget to use the [production build](https://reactjs.org/docs/optimizing-performance.html#use-the-production-build) when deploying your application.
8
+
9
+ ## Usage
10
+
11
+ ```js
12
+ import { useState } from 'react';
13
+ import { createRoot } from 'react-dom/client';
14
+
15
+ function Counter() {
16
+ const [count, setCount] = useState(0);
17
+ return (
18
+ <>
19
+ <h1>{count}</h1>
20
+ <button onClick={() => setCount(count + 1)}>
21
+ Increment
22
+ </button>
23
+ </>
24
+ );
25
+ }
26
+
27
+ const root = createRoot(document.getElementById('root'));
28
+ root.render(<App />);
29
+ ```
30
+
31
+ ## Documentation
32
+
33
+ See https://reactjs.org/
34
+
35
+ ## API
36
+
37
+ See https://reactjs.org/docs/react-api.html