vxrn 0.1.30 → 0.1.32
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/dist/cjs/cli.js +20 -1
- package/dist/cjs/cli.js.map +2 -2
- package/dist/cjs/cli.native.js +43 -1
- package/dist/cjs/cli.native.js.map +2 -2
- package/dist/cjs/constants.js +65 -2
- package/dist/cjs/constants.js.map +1 -1
- package/dist/cjs/constants.native.js +103 -3
- package/dist/cjs/constants.native.js.map +2 -2
- package/dist/cjs/exports/build.js +66 -50
- package/dist/cjs/exports/build.js.map +2 -2
- package/dist/cjs/exports/build.native.js +182 -83
- package/dist/cjs/exports/build.native.js.map +2 -2
- package/dist/cjs/exports/dev.js +292 -293
- package/dist/cjs/exports/dev.js.map +2 -2
- package/dist/cjs/exports/dev.native.js +575 -561
- package/dist/cjs/exports/dev.native.js.map +2 -2
- package/dist/cjs/exports/serve.js +7 -1
- package/dist/cjs/exports/serve.js.map +1 -1
- package/dist/cjs/exports/serve.native.js +76 -81
- package/dist/cjs/exports/serve.native.js.map +2 -2
- package/dist/cjs/plugins/clientBundleTreeShakePlugin.js +25 -11
- package/dist/cjs/plugins/clientBundleTreeShakePlugin.js.map +1 -1
- package/dist/cjs/plugins/clientBundleTreeShakePlugin.native.js +38 -22
- package/dist/cjs/plugins/clientBundleTreeShakePlugin.native.js.map +2 -2
- package/dist/cjs/utils/getBaseViteConfig.js +14 -4
- package/dist/cjs/utils/getBaseViteConfig.js.map +2 -2
- package/dist/cjs/utils/getBaseViteConfig.native.js +16 -4
- package/dist/cjs/utils/getBaseViteConfig.native.js.map +2 -2
- package/dist/cjs/{utils.js → utils/getHtml.js} +16 -12
- package/dist/cjs/utils/getHtml.js.map +6 -0
- package/dist/cjs/{utils.native.js → utils/getHtml.native.js} +11 -16
- package/dist/cjs/utils/getHtml.native.js.map +6 -0
- package/dist/cjs/utils/getVitePath.js.map +1 -1
- package/dist/cjs/utils/getVitePath.native.js.map +1 -1
- package/dist/cjs/utils/readVXRNConfig.js +2 -2
- package/dist/cjs/utils/readVXRNConfig.js.map +1 -1
- package/dist/cjs/utils/readVXRNConfig.native.js +1 -1
- package/dist/cjs/utils/readVXRNConfig.native.js.map +2 -2
- package/dist/esm/cli.js +20 -1
- package/dist/esm/cli.js.map +2 -2
- package/dist/esm/cli.mjs +25 -1
- package/dist/esm/cli.native.js +43 -1
- package/dist/esm/cli.native.js.map +2 -2
- package/dist/esm/constants.js +65 -2
- package/dist/esm/constants.js.map +1 -1
- package/dist/esm/constants.mjs +30 -2
- package/dist/esm/constants.native.js +96 -2
- package/dist/esm/constants.native.js.map +2 -2
- package/dist/esm/exports/build.js +70 -51
- package/dist/esm/exports/build.js.map +1 -1
- package/dist/esm/exports/build.mjs +79 -29
- package/dist/esm/exports/build.native.js +186 -84
- package/dist/esm/exports/build.native.js.map +2 -2
- package/dist/esm/exports/dev.js +291 -295
- package/dist/esm/exports/dev.js.map +1 -1
- package/dist/esm/exports/dev.mjs +298 -283
- package/dist/esm/exports/dev.native.js +575 -561
- package/dist/esm/exports/dev.native.js.map +2 -2
- package/dist/esm/exports/serve.js +8 -1
- package/dist/esm/exports/serve.js.map +1 -1
- package/dist/esm/exports/serve.mjs +8 -1
- package/dist/esm/exports/serve.native.js +77 -81
- package/dist/esm/exports/serve.native.js.map +2 -2
- package/dist/esm/plugins/clientBundleTreeShakePlugin.js +25 -11
- package/dist/esm/plugins/clientBundleTreeShakePlugin.js.map +1 -1
- package/dist/esm/plugins/clientBundleTreeShakePlugin.mjs +29 -13
- package/dist/esm/plugins/clientBundleTreeShakePlugin.native.js +38 -22
- package/dist/esm/plugins/clientBundleTreeShakePlugin.native.js.map +2 -2
- package/dist/esm/utils/getBaseViteConfig.js +4 -2
- package/dist/esm/utils/getBaseViteConfig.js.map +1 -1
- package/dist/esm/utils/getBaseViteConfig.mjs +4 -2
- package/dist/esm/utils/getBaseViteConfig.native.js +6 -2
- package/dist/esm/utils/getBaseViteConfig.native.js.map +2 -2
- package/dist/esm/utils/getHtml.js +16 -0
- package/dist/esm/utils/getHtml.js.map +6 -0
- package/dist/esm/utils/getHtml.mjs +13 -0
- package/dist/esm/utils/getHtml.native.js +10 -0
- package/dist/esm/utils/getHtml.native.js.map +6 -0
- package/dist/esm/utils/getVitePath.js.map +1 -1
- package/dist/esm/utils/getVitePath.native.js.map +1 -1
- package/dist/esm/utils/readVXRNConfig.js +2 -2
- package/dist/esm/utils/readVXRNConfig.js.map +1 -1
- package/dist/esm/utils/readVXRNConfig.mjs +2 -2
- package/dist/esm/utils/readVXRNConfig.native.js +1 -1
- package/dist/esm/utils/readVXRNConfig.native.js.map +2 -2
- package/package.json +10 -8
- package/src/cli.ts +27 -0
- package/src/constants.ts +71 -0
- package/src/exports/build.ts +93 -59
- package/src/exports/dev.ts +408 -398
- package/src/exports/serve.ts +12 -14
- package/src/types.ts +1 -1
- package/src/utils/getBaseViteConfig.ts +8 -2
- package/src/utils/getHtml.ts +12 -0
- package/src/utils/getVitePath.ts +1 -0
- package/src/utils/readVXRNConfig.ts +5 -0
- package/types/constants.d.ts +13 -0
- package/types/exports/dev.d.ts +0 -6
- package/types/types.d.ts +1 -1
- package/types/utils/getHtml.d.ts +8 -0
- package/types/utils/getOptionsFilled.d.ts +1 -1
- package/types/vendor/createExpoServer.d.ts +3 -1
- package/dist/cjs/build.js +0 -145
- package/dist/cjs/build.js.map +0 -6
- package/dist/cjs/build.native.js +0 -409
- package/dist/cjs/build.native.js.map +0 -6
- package/dist/cjs/commands/cli-build.js +0 -36
- package/dist/cjs/commands/cli-build.js.map +0 -6
- package/dist/cjs/commands/cli-build.native.js +0 -171
- package/dist/cjs/commands/cli-build.native.js.map +0 -6
- package/dist/cjs/commands/cli-dev.js +0 -52
- package/dist/cjs/commands/cli-dev.js.map +0 -6
- package/dist/cjs/commands/cli-dev.native.js +0 -217
- package/dist/cjs/commands/cli-dev.native.js.map +0 -6
- package/dist/cjs/commands/index.js +0 -34
- package/dist/cjs/commands/index.js.map +0 -6
- package/dist/cjs/commands/index.native.js +0 -45
- package/dist/cjs/commands/index.native.js.map +0 -6
- package/dist/cjs/create.js +0 -643
- package/dist/cjs/create.js.map +0 -6
- package/dist/cjs/create.native.js +0 -1318
- package/dist/cjs/create.native.js.map +0 -6
- package/dist/cjs/createDevServer.js +0 -601
- package/dist/cjs/createDevServer.js.map +0 -6
- package/dist/cjs/createDevServer.native.js +0 -1220
- package/dist/cjs/createDevServer.native.js.map +0 -6
- package/dist/cjs/createExpoServer.js +0 -34
- package/dist/cjs/createExpoServer.js.map +0 -6
- package/dist/cjs/createExpoServer.native.js +0 -42
- package/dist/cjs/createExpoServer.native.js.map +0 -6
- package/dist/cjs/dev/clientInjectPlugin.js +0 -67
- package/dist/cjs/dev/clientInjectPlugin.js.map +0 -6
- package/dist/cjs/dev/clientInjectPlugin.native.js +0 -191
- package/dist/cjs/dev/clientInjectPlugin.native.js.map +0 -6
- package/dist/cjs/dev/createDevServer.js +0 -1
- package/dist/cjs/dev/createDevServer.js.map +0 -6
- package/dist/cjs/dev/createDevServer.native.js +0 -2
- package/dist/cjs/dev/createDevServer.native.js.map +0 -6
- package/dist/cjs/dispose.js +0 -28
- package/dist/cjs/dispose.js.map +0 -6
- package/dist/cjs/dispose.native.js +0 -36
- package/dist/cjs/dispose.native.js.map +0 -6
- package/dist/cjs/exports/checkPatches.js +0 -62
- package/dist/cjs/exports/checkPatches.js.map +0 -6
- package/dist/cjs/exports/checkPatches.native.js +0 -289
- package/dist/cjs/exports/checkPatches.native.js.map +0 -6
- package/dist/cjs/getVitePath.js +0 -50
- package/dist/cjs/getVitePath.js.map +0 -6
- package/dist/cjs/getVitePath.native.js +0 -197
- package/dist/cjs/getVitePath.native.js.map +0 -6
- package/dist/cjs/nativePlugin.js +0 -89
- package/dist/cjs/nativePlugin.js.map +0 -6
- package/dist/cjs/nativePlugin.native.js +0 -346
- package/dist/cjs/nativePlugin.native.js.map +0 -6
- package/dist/cjs/utils/checkPatches.js +0 -62
- package/dist/cjs/utils/checkPatches.js.map +0 -6
- package/dist/cjs/utils/checkPatches.native.js +0 -289
- package/dist/cjs/utils/checkPatches.native.js.map +0 -6
- package/dist/cjs/utils/constants.js +0 -21
- package/dist/cjs/utils/constants.js.map +0 -6
- package/dist/cjs/utils/constants.native.js +0 -26
- package/dist/cjs/utils/constants.native.js.map +0 -6
- package/dist/cjs/utils/prerender.js +0 -1
- package/dist/cjs/utils/prerender.js.map +0 -6
- package/dist/cjs/utils/prerender.native.js +0 -2
- package/dist/cjs/utils/prerender.native.js.map +0 -6
- package/dist/cjs/utils.js.map +0 -6
- package/dist/cjs/utils.native.js.map +0 -6
- package/dist/esm/build.js +0 -128
- package/dist/esm/build.js.map +0 -6
- package/dist/esm/build.mjs +0 -119
- package/dist/esm/build.native.js +0 -385
- package/dist/esm/build.native.js.map +0 -6
- package/dist/esm/commands/cli-build.js +0 -23
- package/dist/esm/commands/cli-build.js.map +0 -6
- package/dist/esm/commands/cli-build.mjs +0 -22
- package/dist/esm/commands/cli-build.native.js +0 -156
- package/dist/esm/commands/cli-build.native.js.map +0 -6
- package/dist/esm/commands/cli-dev.js +0 -39
- package/dist/esm/commands/cli-dev.js.map +0 -6
- package/dist/esm/commands/cli-dev.mjs +0 -45
- package/dist/esm/commands/cli-dev.native.js +0 -202
- package/dist/esm/commands/cli-dev.native.js.map +0 -6
- package/dist/esm/commands/index.js +0 -10
- package/dist/esm/commands/index.js.map +0 -6
- package/dist/esm/commands/index.mjs +0 -8
- package/dist/esm/commands/index.native.js +0 -16
- package/dist/esm/commands/index.native.js.map +0 -6
- package/dist/esm/create.js +0 -655
- package/dist/esm/create.js.map +0 -6
- package/dist/esm/create.mjs +0 -622
- package/dist/esm/create.native.js +0 -1309
- package/dist/esm/create.native.js.map +0 -6
- package/dist/esm/createDevServer.js +0 -614
- package/dist/esm/createDevServer.js.map +0 -6
- package/dist/esm/createDevServer.mjs +0 -570
- package/dist/esm/createDevServer.native.js +0 -1211
- package/dist/esm/createDevServer.native.js.map +0 -6
- package/dist/esm/createExpoServer.js +0 -20
- package/dist/esm/createExpoServer.js.map +0 -6
- package/dist/esm/createExpoServer.mjs +0 -17
- package/dist/esm/createExpoServer.native.js +0 -22
- package/dist/esm/createExpoServer.native.js.map +0 -6
- package/dist/esm/dev/clientInjectPlugin.js +0 -43
- package/dist/esm/dev/clientInjectPlugin.js.map +0 -6
- package/dist/esm/dev/clientInjectPlugin.mjs +0 -57
- package/dist/esm/dev/clientInjectPlugin.native.js +0 -162
- package/dist/esm/dev/clientInjectPlugin.native.js.map +0 -6
- package/dist/esm/dev/createDevServer.js +0 -1
- package/dist/esm/dev/createDevServer.js.map +0 -6
- package/dist/esm/dev/createDevServer.mjs +0 -0
- package/dist/esm/dev/createDevServer.native.js +0 -1
- package/dist/esm/dev/createDevServer.native.js.map +0 -6
- package/dist/esm/dispose.js +0 -12
- package/dist/esm/dispose.js.map +0 -6
- package/dist/esm/dispose.mjs +0 -8
- package/dist/esm/dispose.native.js +0 -14
- package/dist/esm/dispose.native.js.map +0 -6
- package/dist/esm/exports/checkPatches.js +0 -40
- package/dist/esm/exports/checkPatches.js.map +0 -6
- package/dist/esm/exports/checkPatches.mjs +0 -31
- package/dist/esm/exports/checkPatches.native.js +0 -262
- package/dist/esm/exports/checkPatches.native.js.map +0 -6
- package/dist/esm/getVitePath.js +0 -28
- package/dist/esm/getVitePath.js.map +0 -6
- package/dist/esm/getVitePath.mjs +0 -21
- package/dist/esm/getVitePath.native.js +0 -170
- package/dist/esm/getVitePath.native.js.map +0 -6
- package/dist/esm/nativePlugin.js +0 -75
- package/dist/esm/nativePlugin.js.map +0 -6
- package/dist/esm/nativePlugin.mjs +0 -55
- package/dist/esm/nativePlugin.native.js +0 -327
- package/dist/esm/nativePlugin.native.js.map +0 -6
- package/dist/esm/utils/checkPatches.js +0 -40
- package/dist/esm/utils/checkPatches.js.map +0 -6
- package/dist/esm/utils/checkPatches.mjs +0 -31
- package/dist/esm/utils/checkPatches.native.js +0 -262
- package/dist/esm/utils/checkPatches.native.js.map +0 -6
- package/dist/esm/utils/constants.js +0 -5
- package/dist/esm/utils/constants.js.map +0 -6
- package/dist/esm/utils/constants.mjs +0 -2
- package/dist/esm/utils/constants.native.js +0 -5
- package/dist/esm/utils/constants.native.js.map +0 -6
- package/dist/esm/utils/prerender.js +0 -1
- package/dist/esm/utils/prerender.js.map +0 -6
- package/dist/esm/utils/prerender.mjs +0 -0
- package/dist/esm/utils/prerender.native.js +0 -1
- package/dist/esm/utils/prerender.native.js.map +0 -6
- package/dist/esm/utils.js +0 -12
- package/dist/esm/utils.js.map +0 -6
- package/dist/esm/utils.mjs +0 -8
- package/dist/esm/utils.native.js +0 -14
- package/dist/esm/utils.native.js.map +0 -6
- package/src/plugins/clientBundleTreeShakePlugin.tsx +0 -105
- package/src/vendor/createExpoServer.ts +0 -43
- package/src/vendor/repack/dev-server/src/createServer.ts +0 -128
- package/src/vendor/repack/dev-server/src/img/favicon.ico +0 -0
- package/src/vendor/repack/dev-server/src/index.ts +0 -2
- package/src/vendor/repack/dev-server/src/plugins/api/apiPlugin.ts +0 -50
- package/src/vendor/repack/dev-server/src/plugins/api/index.ts +0 -1
- package/src/vendor/repack/dev-server/src/plugins/compiler/compilerPlugin.ts +0 -84
- package/src/vendor/repack/dev-server/src/plugins/compiler/index.ts +0 -2
- package/src/vendor/repack/dev-server/src/plugins/compiler/types.ts +0 -37
- package/src/vendor/repack/dev-server/src/plugins/devtools/devtoolsPlugin.ts +0 -107
- package/src/vendor/repack/dev-server/src/plugins/devtools/index.ts +0 -1
- package/src/vendor/repack/dev-server/src/plugins/favicon/faviconPlugin.ts +0 -14
- package/src/vendor/repack/dev-server/src/plugins/favicon/index.ts +0 -1
- package/src/vendor/repack/dev-server/src/plugins/multipart/index.ts +0 -2
- package/src/vendor/repack/dev-server/src/plugins/multipart/multipartPlugin.ts +0 -77
- package/src/vendor/repack/dev-server/src/plugins/multipart/types.ts +0 -13
- package/src/vendor/repack/dev-server/src/plugins/symbolicate/Symbolicator.ts +0 -233
- package/src/vendor/repack/dev-server/src/plugins/symbolicate/index.ts +0 -3
- package/src/vendor/repack/dev-server/src/plugins/symbolicate/sybmolicatePlugin.ts +0 -48
- package/src/vendor/repack/dev-server/src/plugins/symbolicate/types.ts +0 -71
- package/src/vendor/repack/dev-server/src/plugins/wss/WebSocketRouter.ts +0 -74
- package/src/vendor/repack/dev-server/src/plugins/wss/WebSocketServer.ts +0 -60
- package/src/vendor/repack/dev-server/src/plugins/wss/index.ts +0 -3
- package/src/vendor/repack/dev-server/src/plugins/wss/servers/HermesInspectorProxy.ts +0 -158
- package/src/vendor/repack/dev-server/src/plugins/wss/servers/WebSocketApiServer.ts +0 -69
- package/src/vendor/repack/dev-server/src/plugins/wss/servers/WebSocketDebuggerServer.ts +0 -134
- package/src/vendor/repack/dev-server/src/plugins/wss/servers/WebSocketDevClientServer.ts +0 -74
- package/src/vendor/repack/dev-server/src/plugins/wss/servers/WebSocketEventsServer.ts +0 -205
- package/src/vendor/repack/dev-server/src/plugins/wss/servers/WebSocketHMRServer.ts +0 -97
- package/src/vendor/repack/dev-server/src/plugins/wss/servers/WebSocketMessageServer.ts +0 -401
- package/src/vendor/repack/dev-server/src/plugins/wss/types.ts +0 -17
- package/src/vendor/repack/dev-server/src/plugins/wss/wssPlugin.ts +0 -73
- package/src/vendor/repack/dev-server/src/types.ts +0 -197
- package/types/VXRNConfigFilled.d.ts +0 -21
- package/types/build.d.ts +0 -4
- package/types/commands/cli-build.d.ts +0 -3
- package/types/commands/cli-dev.d.ts +0 -3
- package/types/commands/index.d.ts +0 -6
- package/types/create.d.ts +0 -13
- package/types/createDevServer.d.ts +0 -13
- package/types/createExpoServer.d.ts +0 -4
- package/types/dev/bindKeypressInput.d.ts +0 -3
- package/types/dev/clientInjectPlugin.d.ts +0 -7
- package/types/dev/createDevServer.d.ts +0 -1
- package/types/dispose.d.ts +0 -3
- package/types/getBaseViteConfig.d.ts +0 -5
- package/types/getOptionsFIlled.d.ts +0 -21
- package/types/getVitePath.d.ts +0 -2
- package/types/nativePlugin.d.ts +0 -7
- package/types/plugins/clientBundleTreeShakePlugni.d.ts +0 -13
- package/types/plugins/server-tree-shake.d.ts +0 -13
- package/types/utils/checkPatches.d.ts +0 -3
- package/types/utils/constants.d.ts +0 -2
- package/types/utils/prerender.d.ts +0 -1
- package/types/utils.d.ts +0 -3
- package/types/vendor/repack/dev-server/src/createServer.d.ts +0 -1
- package/types/vendor/repack/dev-server/src/index.d.ts +0 -1
- package/types/vendor/repack/dev-server/src/plugins/api/apiPlugin.d.ts +0 -1
- package/types/vendor/repack/dev-server/src/plugins/api/index.d.ts +0 -1
- package/types/vendor/repack/dev-server/src/plugins/compiler/compilerPlugin.d.ts +0 -1
- package/types/vendor/repack/dev-server/src/plugins/compiler/index.d.ts +0 -1
- package/types/vendor/repack/dev-server/src/plugins/compiler/types.d.ts +0 -1
- package/types/vendor/repack/dev-server/src/plugins/devtools/devtoolsPlugin.d.ts +0 -1
- package/types/vendor/repack/dev-server/src/plugins/devtools/index.d.ts +0 -1
- package/types/vendor/repack/dev-server/src/plugins/favicon/faviconPlugin.d.ts +0 -1
- package/types/vendor/repack/dev-server/src/plugins/favicon/index.d.ts +0 -1
- package/types/vendor/repack/dev-server/src/plugins/multipart/index.d.ts +0 -1
- package/types/vendor/repack/dev-server/src/plugins/multipart/multipartPlugin.d.ts +0 -1
- package/types/vendor/repack/dev-server/src/plugins/multipart/types.d.ts +0 -1
- package/types/vendor/repack/dev-server/src/plugins/symbolicate/Symbolicator.d.ts +0 -1
- package/types/vendor/repack/dev-server/src/plugins/symbolicate/index.d.ts +0 -1
- package/types/vendor/repack/dev-server/src/plugins/symbolicate/sybmolicatePlugin.d.ts +0 -1
- package/types/vendor/repack/dev-server/src/plugins/symbolicate/types.d.ts +0 -1
- package/types/vendor/repack/dev-server/src/plugins/wss/WebSocketRouter.d.ts +0 -1
- package/types/vendor/repack/dev-server/src/plugins/wss/WebSocketServer.d.ts +0 -1
- package/types/vendor/repack/dev-server/src/plugins/wss/index.d.ts +0 -1
- package/types/vendor/repack/dev-server/src/plugins/wss/servers/HermesInspectorProxy.d.ts +0 -1
- package/types/vendor/repack/dev-server/src/plugins/wss/servers/WebSocketApiServer.d.ts +0 -1
- package/types/vendor/repack/dev-server/src/plugins/wss/servers/WebSocketDebuggerServer.d.ts +0 -1
- package/types/vendor/repack/dev-server/src/plugins/wss/servers/WebSocketDevClientServer.d.ts +0 -1
- package/types/vendor/repack/dev-server/src/plugins/wss/servers/WebSocketEventsServer.d.ts +0 -1
- package/types/vendor/repack/dev-server/src/plugins/wss/servers/WebSocketHMRServer.d.ts +0 -1
- package/types/vendor/repack/dev-server/src/plugins/wss/servers/WebSocketMessageServer.d.ts +0 -1
- package/types/vendor/repack/dev-server/src/plugins/wss/types.d.ts +0 -1
- package/types/vendor/repack/dev-server/src/plugins/wss/wssPlugin.d.ts +0 -1
- package/types/vendor/repack/dev-server/src/types.d.ts +0 -1
package/src/exports/dev.ts
CHANGED
|
@@ -3,7 +3,6 @@ import {
|
|
|
3
3
|
createApp,
|
|
4
4
|
createRouter,
|
|
5
5
|
defineEventHandler,
|
|
6
|
-
defineWebSocketHandler,
|
|
7
6
|
eventHandler,
|
|
8
7
|
getQuery,
|
|
9
8
|
toNodeListener,
|
|
@@ -34,7 +33,7 @@ import {
|
|
|
34
33
|
import createViteFlow from '@vxrn/vite-flow'
|
|
35
34
|
import type { Peer } from 'crossws'
|
|
36
35
|
import { resolve as importMetaResolve } from 'import-meta-resolve'
|
|
37
|
-
import {
|
|
36
|
+
import { depsToOptimize, nativeExtensions, ssrOptimizeDeps, webExtensions } from '../constants'
|
|
38
37
|
import { clientInjectionsPlugin } from '../plugins/clientInjectPlugin'
|
|
39
38
|
import { reactNativeCommonJsPlugin } from '../plugins/reactNativeCommonJsPlugin'
|
|
40
39
|
import type { VXRNConfig } from '../types'
|
|
@@ -42,9 +41,11 @@ import { getBaseViteConfig } from '../utils/getBaseViteConfig'
|
|
|
42
41
|
import { getOptionsFilled, type VXRNConfigFilled } from '../utils/getOptionsFilled'
|
|
43
42
|
import { getVitePath } from '../utils/getVitePath'
|
|
44
43
|
import { checkPatches } from '../utils/patches'
|
|
45
|
-
import { createExpoServer } from '../vendor/createExpoServer'
|
|
46
44
|
|
|
47
|
-
|
|
45
|
+
// sorry for the mess, exploring before abstracting
|
|
46
|
+
|
|
47
|
+
let isBuildingNativeBundle: Promise<string> | null = null
|
|
48
|
+
const hotUpdateCache = new Map<string, string>()
|
|
48
49
|
|
|
49
50
|
export const resolveFile = (path: string) => {
|
|
50
51
|
try {
|
|
@@ -54,30 +55,6 @@ export const resolveFile = (path: string) => {
|
|
|
54
55
|
}
|
|
55
56
|
}
|
|
56
57
|
|
|
57
|
-
const nativeExtensions = [
|
|
58
|
-
'.native.tsx',
|
|
59
|
-
'.native.jsx',
|
|
60
|
-
'.native.js',
|
|
61
|
-
'.tsx',
|
|
62
|
-
'.ts',
|
|
63
|
-
'.js',
|
|
64
|
-
'.css',
|
|
65
|
-
'.json',
|
|
66
|
-
]
|
|
67
|
-
|
|
68
|
-
const extensions = [
|
|
69
|
-
'.web.tsx',
|
|
70
|
-
'.tsx',
|
|
71
|
-
'.web.ts',
|
|
72
|
-
'.ts',
|
|
73
|
-
'.web.jsx',
|
|
74
|
-
'.jsx',
|
|
75
|
-
'.web.js',
|
|
76
|
-
'.js',
|
|
77
|
-
'.css',
|
|
78
|
-
'.json',
|
|
79
|
-
]
|
|
80
|
-
|
|
81
58
|
const { ensureDir, pathExists, pathExistsSync } = FSExtra
|
|
82
59
|
|
|
83
60
|
export const dev = async (optionsIn: VXRNConfig) => {
|
|
@@ -93,124 +70,7 @@ export const dev = async (optionsIn: VXRNConfig) => {
|
|
|
93
70
|
|
|
94
71
|
await ensureDir(cacheDir)
|
|
95
72
|
|
|
96
|
-
const
|
|
97
|
-
reactJSX: join(cacheDir, 'react-jsx-runtime.js'),
|
|
98
|
-
react: join(cacheDir, 'react.js'),
|
|
99
|
-
reactNative: join(cacheDir, 'react-native.js'),
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
if (!(await pathExists(prebuilds.reactNative))) {
|
|
103
|
-
console.info('Pre-building react, react-native react/jsx-runtime (one time cost)...')
|
|
104
|
-
await Promise.all([
|
|
105
|
-
buildReactNative({
|
|
106
|
-
entryPoints: [resolveFile('react-native')],
|
|
107
|
-
outfile: prebuilds.reactNative,
|
|
108
|
-
}),
|
|
109
|
-
buildReact({
|
|
110
|
-
entryPoints: [resolveFile('react')],
|
|
111
|
-
outfile: prebuilds.react,
|
|
112
|
-
}),
|
|
113
|
-
buildReactJSX({
|
|
114
|
-
entryPoints: [resolveFile('react/jsx-dev-runtime')],
|
|
115
|
-
outfile: prebuilds.reactJSX,
|
|
116
|
-
}),
|
|
117
|
-
])
|
|
118
|
-
}
|
|
119
|
-
const viteFlow = options.flow ? createViteFlow(options.flow) : null
|
|
120
|
-
|
|
121
|
-
const templateFile = resolveFile('vxrn/react-native-template.js')
|
|
122
|
-
|
|
123
|
-
// react native port (it scans 19000 +5)
|
|
124
|
-
const jsxRuntime = {
|
|
125
|
-
// alias: 'virtual:react-jsx',
|
|
126
|
-
alias: prebuilds.reactJSX,
|
|
127
|
-
contents: await readFile(prebuilds.reactJSX, 'utf-8'),
|
|
128
|
-
} as const
|
|
129
|
-
|
|
130
|
-
const virtualModules = {
|
|
131
|
-
'react-native': {
|
|
132
|
-
// alias: 'virtual:react-native',
|
|
133
|
-
alias: prebuilds.reactNative,
|
|
134
|
-
contents: await readFile(prebuilds.reactNative, 'utf-8'),
|
|
135
|
-
},
|
|
136
|
-
react: {
|
|
137
|
-
// alias: 'virtual:react',
|
|
138
|
-
alias: prebuilds.react,
|
|
139
|
-
contents: await readFile(prebuilds.react, 'utf-8'),
|
|
140
|
-
},
|
|
141
|
-
'react/jsx-runtime': jsxRuntime,
|
|
142
|
-
'react/jsx-dev-runtime': jsxRuntime,
|
|
143
|
-
} as const
|
|
144
|
-
|
|
145
|
-
const swapRnPlugin: PluginOption = {
|
|
146
|
-
name: `swap-react-native`,
|
|
147
|
-
enforce: 'pre',
|
|
148
|
-
|
|
149
|
-
resolveId(id, importer = '') {
|
|
150
|
-
if (id.startsWith('react-native/Libraries')) {
|
|
151
|
-
return `virtual:rn-internals:${id}`
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
// this will break web support, we need a way to somehow switch between?
|
|
155
|
-
if (id === 'react-native-web') {
|
|
156
|
-
return prebuilds.reactNative
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
for (const targetId in virtualModules) {
|
|
160
|
-
if (id === targetId || id.includes(`node_modules/${targetId}/`)) {
|
|
161
|
-
const info = virtualModules[targetId]
|
|
162
|
-
|
|
163
|
-
return info.alias
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
// TODO this is terrible and slow, we should be able to get extensions working:
|
|
168
|
-
// having trouble getting .native.js to be picked up via vite
|
|
169
|
-
// tried adding packages to optimizeDeps, tried resolveExtensions + extensions...
|
|
170
|
-
// tried this but seems to not be called for node_modules
|
|
171
|
-
if (id[0] === '.') {
|
|
172
|
-
const absolutePath = resolve(dirname(importer), id)
|
|
173
|
-
const nativePath = absolutePath.replace(/(.m?js)/, '.native.js')
|
|
174
|
-
if (nativePath === id) return
|
|
175
|
-
try {
|
|
176
|
-
const directoryPath = absolutePath + '/index.native.js'
|
|
177
|
-
const directoryNonNativePath = absolutePath + '/index.js'
|
|
178
|
-
if (pathExistsSync(directoryPath)) {
|
|
179
|
-
return directoryPath
|
|
180
|
-
}
|
|
181
|
-
if (pathExistsSync(directoryNonNativePath)) {
|
|
182
|
-
return directoryNonNativePath
|
|
183
|
-
}
|
|
184
|
-
if (pathExistsSync(nativePath)) {
|
|
185
|
-
return nativePath
|
|
186
|
-
}
|
|
187
|
-
} catch (err) {
|
|
188
|
-
console.warn(`error probably fine`, err)
|
|
189
|
-
}
|
|
190
|
-
}
|
|
191
|
-
},
|
|
192
|
-
|
|
193
|
-
load(id) {
|
|
194
|
-
if (id.startsWith('virtual:rn-internals')) {
|
|
195
|
-
const idOut = id.replace('virtual:rn-internals:', '')
|
|
196
|
-
let out = `const ___val = __cachedModules["${idOut}"]
|
|
197
|
-
const ___defaultVal = ___val ? ___val.default || ___val : ___val
|
|
198
|
-
export default ___defaultVal`
|
|
199
|
-
// export const PressabilityDebugView = val.PressabilityDebugView
|
|
200
|
-
//
|
|
201
|
-
return out
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
for (const targetId in virtualModules) {
|
|
205
|
-
const info = virtualModules[targetId as keyof typeof virtualModules]
|
|
206
|
-
if (id === info.alias) {
|
|
207
|
-
return info.contents
|
|
208
|
-
}
|
|
209
|
-
}
|
|
210
|
-
},
|
|
211
|
-
} as const
|
|
212
|
-
|
|
213
|
-
const { serverConfig, hotUpdateCache } = await getViteServerConfig(options)
|
|
73
|
+
const serverConfig = await getViteServerConfig(options)
|
|
214
74
|
const viteServer = await createServer(serverConfig)
|
|
215
75
|
|
|
216
76
|
// first resolve config so we can pass into client plugin, then add client plugin:
|
|
@@ -232,25 +92,21 @@ export const dev = async (optionsIn: VXRNConfig) => {
|
|
|
232
92
|
}
|
|
233
93
|
})
|
|
234
94
|
|
|
235
|
-
let isBuilding: Promise<string> | null = null
|
|
236
|
-
|
|
237
95
|
await viteServer.listen()
|
|
238
96
|
const vitePort = viteServer.config.server.port
|
|
239
97
|
|
|
240
|
-
console.info('vite running on', vitePort)
|
|
241
|
-
|
|
242
98
|
const router = createRouter()
|
|
243
99
|
const app = createApp({
|
|
244
100
|
onError: (error) => {
|
|
245
101
|
console.error(error)
|
|
246
102
|
},
|
|
247
103
|
onRequest: (event) => {
|
|
248
|
-
|
|
104
|
+
if (process.env.DEBUG) {
|
|
105
|
+
console.info(' →', event.path)
|
|
106
|
+
}
|
|
249
107
|
},
|
|
250
108
|
})
|
|
251
109
|
|
|
252
|
-
createExpoServer(root, app, viteServer)
|
|
253
|
-
|
|
254
110
|
router.get(
|
|
255
111
|
'/file',
|
|
256
112
|
defineEventHandler((e) => {
|
|
@@ -269,7 +125,7 @@ export const dev = async (optionsIn: VXRNConfig) => {
|
|
|
269
125
|
router.get(
|
|
270
126
|
'/index.bundle',
|
|
271
127
|
defineEventHandler(async (e) => {
|
|
272
|
-
return new Response(await
|
|
128
|
+
return new Response(await getReactNativeBundle(options, viteRNClientPlugin), {
|
|
273
129
|
headers: {
|
|
274
130
|
'content-type': 'text/javascript',
|
|
275
131
|
},
|
|
@@ -306,8 +162,6 @@ export const dev = async (optionsIn: VXRNConfig) => {
|
|
|
306
162
|
|
|
307
163
|
socket.on('message', (msg) => {
|
|
308
164
|
const message = msg.toString()
|
|
309
|
-
console.info(clients.size, 'message', message)
|
|
310
|
-
|
|
311
165
|
for (const listener of [...clients]) {
|
|
312
166
|
listener.send(message)
|
|
313
167
|
}
|
|
@@ -320,23 +174,29 @@ export const dev = async (optionsIn: VXRNConfig) => {
|
|
|
320
174
|
// vite hmr:
|
|
321
175
|
app.use(
|
|
322
176
|
'/__vxrnhmr',
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
clients.add(peer)
|
|
177
|
+
defineEventHandler({
|
|
178
|
+
handler() {
|
|
179
|
+
//
|
|
327
180
|
},
|
|
328
181
|
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
182
|
+
websocket: {
|
|
183
|
+
open(peer) {
|
|
184
|
+
if (process.env.DEBUG) console.debug('[hmr:web] open', peer)
|
|
185
|
+
clients.add(peer)
|
|
186
|
+
},
|
|
332
187
|
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
},
|
|
188
|
+
message(peer, message) {
|
|
189
|
+
socket.send(message.rawData)
|
|
190
|
+
},
|
|
337
191
|
|
|
338
|
-
|
|
339
|
-
|
|
192
|
+
close(peer, event) {
|
|
193
|
+
if (process.env.DEBUG) console.info('[hmr:web] close', peer, event)
|
|
194
|
+
clients.delete(peer)
|
|
195
|
+
},
|
|
196
|
+
|
|
197
|
+
error(peer, error) {
|
|
198
|
+
console.error('[hmr:web] error', peer, error)
|
|
199
|
+
},
|
|
340
200
|
},
|
|
341
201
|
})
|
|
342
202
|
)
|
|
@@ -345,24 +205,30 @@ export const dev = async (optionsIn: VXRNConfig) => {
|
|
|
345
205
|
// react native hmr:
|
|
346
206
|
app.use(
|
|
347
207
|
'/__hmr',
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
208
|
+
defineEventHandler({
|
|
209
|
+
handler() {
|
|
210
|
+
//
|
|
351
211
|
},
|
|
352
212
|
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
}
|
|
358
|
-
},
|
|
213
|
+
websocket: {
|
|
214
|
+
open(peer) {
|
|
215
|
+
console.debug('[hmr] open', peer)
|
|
216
|
+
},
|
|
359
217
|
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
218
|
+
message(peer, message) {
|
|
219
|
+
console.info('[hmr] message', peer, message)
|
|
220
|
+
if (message.text().includes('ping')) {
|
|
221
|
+
peer.send('pong')
|
|
222
|
+
}
|
|
223
|
+
},
|
|
224
|
+
|
|
225
|
+
close(peer, event) {
|
|
226
|
+
console.info('[hmr] close', peer, event)
|
|
227
|
+
},
|
|
363
228
|
|
|
364
|
-
|
|
365
|
-
|
|
229
|
+
error(peer, error) {
|
|
230
|
+
console.error('[hmr] error', peer, error)
|
|
231
|
+
},
|
|
366
232
|
},
|
|
367
233
|
})
|
|
368
234
|
)
|
|
@@ -373,35 +239,49 @@ export const dev = async (optionsIn: VXRNConfig) => {
|
|
|
373
239
|
data: string[]
|
|
374
240
|
}
|
|
375
241
|
|
|
242
|
+
// symbolicate
|
|
243
|
+
app.use(
|
|
244
|
+
'/symbolicate',
|
|
245
|
+
defineEventHandler(() => {
|
|
246
|
+
return 'TODO'
|
|
247
|
+
})
|
|
248
|
+
)
|
|
249
|
+
|
|
376
250
|
// react native log bridge
|
|
377
251
|
app.use(
|
|
378
252
|
'/__client',
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
253
|
+
defineEventHandler({
|
|
254
|
+
handler() {
|
|
255
|
+
// no
|
|
382
256
|
},
|
|
383
257
|
|
|
384
|
-
|
|
385
|
-
|
|
258
|
+
websocket: {
|
|
259
|
+
open(peer) {
|
|
260
|
+
console.info('[client] open', peer)
|
|
261
|
+
},
|
|
262
|
+
|
|
263
|
+
message(peer, messageRaw) {
|
|
264
|
+
const message = JSON.parse(messageRaw.text()) as any as ClientMessage
|
|
386
265
|
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
266
|
+
switch (message.type) {
|
|
267
|
+
case 'client-log': {
|
|
268
|
+
console.info(`🪵 [${message.level}]`, ...message.data)
|
|
269
|
+
return
|
|
270
|
+
}
|
|
392
271
|
|
|
393
|
-
|
|
394
|
-
|
|
272
|
+
default: {
|
|
273
|
+
console.warn(`[client] Unknown message type`, message)
|
|
274
|
+
}
|
|
395
275
|
}
|
|
396
|
-
}
|
|
397
|
-
},
|
|
276
|
+
},
|
|
398
277
|
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
278
|
+
close(peer, event) {
|
|
279
|
+
console.info('[client] close', peer, event)
|
|
280
|
+
},
|
|
402
281
|
|
|
403
|
-
|
|
404
|
-
|
|
282
|
+
error(peer, error) {
|
|
283
|
+
console.error('[client] error', peer, error)
|
|
284
|
+
},
|
|
405
285
|
},
|
|
406
286
|
})
|
|
407
287
|
)
|
|
@@ -435,162 +315,169 @@ export const dev = async (optionsIn: VXRNConfig) => {
|
|
|
435
315
|
await Promise.all([server.close(), viteServer.close()])
|
|
436
316
|
},
|
|
437
317
|
}
|
|
318
|
+
}
|
|
438
319
|
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
// for easier quick testing things:
|
|
442
|
-
const tmpBundle = join(process.cwd(), 'bundle.tmp.js')
|
|
443
|
-
if (await pathExists(tmpBundle)) {
|
|
444
|
-
console.info('⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️ returning temp bundle ⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️', tmpBundle)
|
|
445
|
-
return await readFile(tmpBundle, 'utf-8')
|
|
446
|
-
}
|
|
447
|
-
}
|
|
320
|
+
async function getReactNativeBundle(options: VXRNConfigFilled, viteRNClientPlugin: any) {
|
|
321
|
+
const { root, port, cacheDir } = options
|
|
448
322
|
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
323
|
+
if (process.env.LOAD_TMP_BUNDLE) {
|
|
324
|
+
// for easier quick testing things:
|
|
325
|
+
const tmpBundle = join(process.cwd(), 'bundle.tmp.js')
|
|
326
|
+
if (await pathExists(tmpBundle)) {
|
|
327
|
+
console.info('⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️ returning temp bundle ⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️', tmpBundle)
|
|
328
|
+
return await readFile(tmpBundle, 'utf-8')
|
|
452
329
|
}
|
|
330
|
+
}
|
|
453
331
|
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
async function babelReanimated(input: string, filename: string) {
|
|
460
|
-
return await new Promise<string>((res, rej) => {
|
|
461
|
-
babel.transform(
|
|
462
|
-
input,
|
|
463
|
-
{
|
|
464
|
-
plugins: ['react-native-reanimated/plugin'],
|
|
465
|
-
filename,
|
|
466
|
-
},
|
|
467
|
-
(err: any, result) => {
|
|
468
|
-
if (!result || err) rej(err || 'no res')
|
|
469
|
-
res(result!.code!)
|
|
470
|
-
}
|
|
471
|
-
)
|
|
472
|
-
})
|
|
473
|
-
}
|
|
332
|
+
if (isBuildingNativeBundle) {
|
|
333
|
+
const res = await isBuildingNativeBundle
|
|
334
|
+
return res
|
|
335
|
+
}
|
|
474
336
|
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
swapRnPlugin,
|
|
337
|
+
let done
|
|
338
|
+
isBuildingNativeBundle = new Promise((res) => {
|
|
339
|
+
done = res
|
|
340
|
+
})
|
|
480
341
|
|
|
342
|
+
async function babelReanimated(input: string, filename: string) {
|
|
343
|
+
return await new Promise<string>((res, rej) => {
|
|
344
|
+
babel.transform(
|
|
345
|
+
input,
|
|
481
346
|
{
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
async transform(code, id) {
|
|
485
|
-
if (code.includes('worklet')) {
|
|
486
|
-
const out = await babelReanimated(code, id)
|
|
487
|
-
return out
|
|
488
|
-
}
|
|
489
|
-
},
|
|
347
|
+
plugins: ['react-native-reanimated/plugin'],
|
|
348
|
+
filename,
|
|
490
349
|
},
|
|
350
|
+
(err: any, result) => {
|
|
351
|
+
if (!result || err) rej(err || 'no res')
|
|
352
|
+
res(result!.code!)
|
|
353
|
+
}
|
|
354
|
+
)
|
|
355
|
+
})
|
|
356
|
+
}
|
|
491
357
|
|
|
492
|
-
|
|
493
|
-
viteRNClientPlugin,
|
|
358
|
+
const viteFlow = options.flow ? createViteFlow(options.flow) : null
|
|
494
359
|
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
}),
|
|
360
|
+
// build app
|
|
361
|
+
let nativeBuildConfig = {
|
|
362
|
+
plugins: [
|
|
363
|
+
viteFlow,
|
|
500
364
|
|
|
501
|
-
|
|
502
|
-
tsDecorators: true,
|
|
503
|
-
mode: 'build',
|
|
504
|
-
}),
|
|
365
|
+
swapPrebuiltReactModules(cacheDir),
|
|
505
366
|
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
async transform(code, id) {
|
|
509
|
-
if (!id.match(/expo-status-bar/)) return null
|
|
510
|
-
// Use the exposed transform from vite, instead of directly
|
|
511
|
-
// transforming with esbuild
|
|
512
|
-
return transformWithEsbuild(code, id, {
|
|
513
|
-
loader: 'jsx',
|
|
514
|
-
jsx: 'automatic',
|
|
515
|
-
})
|
|
516
|
-
},
|
|
517
|
-
},
|
|
518
|
-
].filter(Boolean),
|
|
519
|
-
appType: 'custom',
|
|
520
|
-
root,
|
|
521
|
-
clearScreen: false,
|
|
367
|
+
{
|
|
368
|
+
name: 'reanimated',
|
|
522
369
|
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
370
|
+
async transform(code, id) {
|
|
371
|
+
if (code.includes('worklet')) {
|
|
372
|
+
const out = await babelReanimated(code, id)
|
|
373
|
+
return out
|
|
374
|
+
}
|
|
527
375
|
},
|
|
528
376
|
},
|
|
529
377
|
|
|
530
|
-
|
|
531
|
-
|
|
378
|
+
viteRNClientPlugin,
|
|
379
|
+
|
|
380
|
+
reactNativeCommonJsPlugin({
|
|
381
|
+
root,
|
|
382
|
+
port,
|
|
383
|
+
mode: 'build',
|
|
384
|
+
}),
|
|
385
|
+
|
|
386
|
+
viteReactPlugin({
|
|
387
|
+
tsDecorators: true,
|
|
388
|
+
mode: 'build',
|
|
389
|
+
}),
|
|
390
|
+
|
|
391
|
+
{
|
|
392
|
+
name: 'treat-js-files-as-jsx',
|
|
393
|
+
async transform(code, id) {
|
|
394
|
+
if (!id.match(/expo-status-bar/)) return null
|
|
395
|
+
// Use the exposed transform from vite, instead of directly
|
|
396
|
+
// transforming with esbuild
|
|
397
|
+
return transformWithEsbuild(code, id, {
|
|
398
|
+
loader: 'jsx',
|
|
399
|
+
jsx: 'automatic',
|
|
400
|
+
})
|
|
401
|
+
},
|
|
402
|
+
},
|
|
403
|
+
].filter(Boolean),
|
|
404
|
+
appType: 'custom',
|
|
405
|
+
root,
|
|
406
|
+
clearScreen: false,
|
|
407
|
+
|
|
408
|
+
optimizeDeps: {
|
|
409
|
+
include: depsToOptimize,
|
|
410
|
+
esbuildOptions: {
|
|
411
|
+
jsx: 'automatic',
|
|
532
412
|
},
|
|
413
|
+
},
|
|
533
414
|
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
415
|
+
resolve: {
|
|
416
|
+
extensions: nativeExtensions,
|
|
417
|
+
},
|
|
418
|
+
|
|
419
|
+
mode: 'development',
|
|
420
|
+
|
|
421
|
+
define: {
|
|
422
|
+
'process.env.NODE_ENV': `"development"`,
|
|
423
|
+
},
|
|
424
|
+
|
|
425
|
+
build: {
|
|
426
|
+
ssr: false,
|
|
427
|
+
minify: false,
|
|
428
|
+
commonjsOptions: {
|
|
429
|
+
transformMixedEsModules: true,
|
|
537
430
|
},
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
rollupOptions: {
|
|
545
|
-
treeshake: false,
|
|
546
|
-
preserveEntrySignatures: 'strict',
|
|
547
|
-
output: {
|
|
548
|
-
preserveModules: true,
|
|
549
|
-
format: 'cjs',
|
|
550
|
-
},
|
|
431
|
+
rollupOptions: {
|
|
432
|
+
treeshake: false,
|
|
433
|
+
preserveEntrySignatures: 'strict',
|
|
434
|
+
output: {
|
|
435
|
+
preserveModules: true,
|
|
436
|
+
format: 'cjs',
|
|
551
437
|
},
|
|
552
438
|
},
|
|
553
|
-
}
|
|
439
|
+
},
|
|
440
|
+
} satisfies InlineConfig
|
|
554
441
|
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
442
|
+
if (options.nativeConfig) {
|
|
443
|
+
nativeBuildConfig = mergeConfig(nativeBuildConfig, options.nativeConfig) as any
|
|
444
|
+
}
|
|
558
445
|
|
|
559
|
-
|
|
560
|
-
|
|
446
|
+
// this fixes my swap-react-native plugin not being called pre 😳
|
|
447
|
+
await resolveConfig(nativeBuildConfig, 'build')
|
|
561
448
|
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
449
|
+
// seems to be not working but needed to put it after the resolve or else it was cleared
|
|
450
|
+
// @ts-ignore
|
|
451
|
+
// nativeBuildConfig.build.rollupOptions.input = join(root, buildInput)
|
|
565
452
|
|
|
566
|
-
|
|
453
|
+
const buildOutput = await build(nativeBuildConfig)
|
|
567
454
|
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
455
|
+
if (!('output' in buildOutput)) {
|
|
456
|
+
throw `❌`
|
|
457
|
+
}
|
|
571
458
|
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
459
|
+
let appCode = buildOutput.output
|
|
460
|
+
// entry last
|
|
461
|
+
.sort((a, b) => (a['isEntry'] ? 1 : -1))
|
|
462
|
+
.map((outputModule) => {
|
|
463
|
+
if (outputModule.type == 'chunk') {
|
|
464
|
+
const importsMap = {
|
|
465
|
+
currentPath: outputModule.fileName,
|
|
466
|
+
}
|
|
467
|
+
for (const imp of outputModule.imports) {
|
|
468
|
+
const relativePath = relative(dirname(outputModule.fileName), imp)
|
|
469
|
+
importsMap[relativePath[0] === '.' ? relativePath : './' + relativePath] = imp
|
|
470
|
+
}
|
|
584
471
|
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
472
|
+
if (outputModule.isEntry) {
|
|
473
|
+
entryRoot = dirname(outputModule.fileName)
|
|
474
|
+
}
|
|
588
475
|
|
|
589
|
-
|
|
476
|
+
return `
|
|
590
477
|
___modules___["${outputModule.fileName}"] = ((exports, module) => {
|
|
591
|
-
|
|
478
|
+
const require = createRequire(${JSON.stringify(importsMap, null, 2)})
|
|
592
479
|
|
|
593
|
-
|
|
480
|
+
${outputModule.code}
|
|
594
481
|
})
|
|
595
482
|
|
|
596
483
|
${
|
|
@@ -604,38 +491,162 @@ __require("${outputModule.fileName}")
|
|
|
604
491
|
: ''
|
|
605
492
|
}
|
|
606
493
|
`
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
494
|
+
}
|
|
495
|
+
})
|
|
496
|
+
.join('\n')
|
|
610
497
|
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
498
|
+
if (!appCode) {
|
|
499
|
+
throw `❌`
|
|
500
|
+
}
|
|
501
|
+
|
|
502
|
+
appCode = appCode
|
|
503
|
+
// this can be done in the individual file transform
|
|
504
|
+
.replaceAll('undefined.accept(() => {})', '')
|
|
505
|
+
.replaceAll('undefined.accept(function() {});', '')
|
|
506
|
+
.replaceAll('(void 0).accept(() => {})', '')
|
|
507
|
+
.replaceAll('(void 0).accept(function() {});', '')
|
|
508
|
+
// TEMP FIX for expo-router tamagui thing since expo router 3 upgrade
|
|
509
|
+
.replaceAll('dist/esm/index.mjs"', 'dist/esm/index.js"')
|
|
614
510
|
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
.replaceAll('undefined.accept(() => {})', '')
|
|
618
|
-
.replaceAll('undefined.accept(function() {});', '')
|
|
619
|
-
.replaceAll('(void 0).accept(() => {})', '')
|
|
620
|
-
.replaceAll('(void 0).accept(function() {});', '')
|
|
621
|
-
// TEMP FIX for expo-router tamagui thing since expo router 3 upgrade
|
|
622
|
-
.replaceAll('dist/esm/index.mjs"', 'dist/esm/index.js"')
|
|
511
|
+
// TODO this is not stable based on cwd
|
|
512
|
+
const appRootParent = join(root, '..', '..')
|
|
623
513
|
|
|
624
|
-
|
|
625
|
-
|
|
514
|
+
const prebuilds = {
|
|
515
|
+
reactJSX: join(cacheDir, 'react-jsx-runtime.js'),
|
|
516
|
+
react: join(cacheDir, 'react.js'),
|
|
517
|
+
reactNative: join(cacheDir, 'react-native.js'),
|
|
518
|
+
}
|
|
626
519
|
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
520
|
+
const templateFile = resolveFile('vxrn/react-native-template.js')
|
|
521
|
+
const template = (await readFile(templateFile, 'utf-8'))
|
|
522
|
+
.replace('_virtual/virtual_react-native.js', relative(appRootParent, prebuilds.reactNative))
|
|
523
|
+
.replace('_virtual/virtual_react.js', relative(appRootParent, prebuilds.react))
|
|
524
|
+
.replaceAll('_virtual/virtual_react-jsx.js', relative(appRootParent, prebuilds.reactJSX))
|
|
631
525
|
|
|
632
|
-
|
|
526
|
+
const out = template + appCode
|
|
633
527
|
|
|
634
|
-
|
|
635
|
-
|
|
528
|
+
done(out)
|
|
529
|
+
isBuildingNativeBundle = null
|
|
636
530
|
|
|
637
|
-
|
|
531
|
+
return out
|
|
532
|
+
}
|
|
533
|
+
|
|
534
|
+
// we should just detect or whitelist and use flow to convert instead of this but i did a
|
|
535
|
+
// few things to the prebuilts to make them work, we may need to account for
|
|
536
|
+
async function swapPrebuiltReactModules(cacheDir: string) {
|
|
537
|
+
const prebuilds = {
|
|
538
|
+
reactJSX: join(cacheDir, 'react-jsx-runtime.js'),
|
|
539
|
+
react: join(cacheDir, 'react.js'),
|
|
540
|
+
reactNative: join(cacheDir, 'react-native.js'),
|
|
541
|
+
}
|
|
542
|
+
|
|
543
|
+
if (!(await pathExists(prebuilds.reactNative))) {
|
|
544
|
+
console.info('Pre-building react, react-native react/jsx-runtime (one time cost)...')
|
|
545
|
+
await Promise.all([
|
|
546
|
+
buildReactNative({
|
|
547
|
+
entryPoints: [resolveFile('react-native')],
|
|
548
|
+
outfile: prebuilds.reactNative,
|
|
549
|
+
}),
|
|
550
|
+
buildReact({
|
|
551
|
+
entryPoints: [resolveFile('react')],
|
|
552
|
+
outfile: prebuilds.react,
|
|
553
|
+
}),
|
|
554
|
+
buildReactJSX({
|
|
555
|
+
entryPoints: [resolveFile('react/jsx-dev-runtime')],
|
|
556
|
+
outfile: prebuilds.reactJSX,
|
|
557
|
+
}),
|
|
558
|
+
])
|
|
638
559
|
}
|
|
560
|
+
|
|
561
|
+
// react native port (it scans 19000 +5)
|
|
562
|
+
const jsxRuntime = {
|
|
563
|
+
// alias: 'virtual:react-jsx',
|
|
564
|
+
alias: prebuilds.reactJSX,
|
|
565
|
+
contents: await readFile(prebuilds.reactJSX, 'utf-8'),
|
|
566
|
+
} as const
|
|
567
|
+
|
|
568
|
+
const virtualModules = {
|
|
569
|
+
'react-native': {
|
|
570
|
+
// alias: 'virtual:react-native',
|
|
571
|
+
alias: prebuilds.reactNative,
|
|
572
|
+
contents: await readFile(prebuilds.reactNative, 'utf-8'),
|
|
573
|
+
},
|
|
574
|
+
react: {
|
|
575
|
+
// alias: 'virtual:react',
|
|
576
|
+
alias: prebuilds.react,
|
|
577
|
+
contents: await readFile(prebuilds.react, 'utf-8'),
|
|
578
|
+
},
|
|
579
|
+
'react/jsx-runtime': jsxRuntime,
|
|
580
|
+
'react/jsx-dev-runtime': jsxRuntime,
|
|
581
|
+
} as const
|
|
582
|
+
|
|
583
|
+
return {
|
|
584
|
+
name: `swap-react-native`,
|
|
585
|
+
enforce: 'pre',
|
|
586
|
+
|
|
587
|
+
resolveId(id, importer = '') {
|
|
588
|
+
if (id.startsWith('react-native/Libraries')) {
|
|
589
|
+
return `virtual:rn-internals:${id}`
|
|
590
|
+
}
|
|
591
|
+
|
|
592
|
+
// this will break web support, we need a way to somehow switch between?
|
|
593
|
+
if (id === 'react-native-web') {
|
|
594
|
+
return prebuilds.reactNative
|
|
595
|
+
}
|
|
596
|
+
|
|
597
|
+
for (const targetId in virtualModules) {
|
|
598
|
+
if (id === targetId || id.includes(`node_modules/${targetId}/`)) {
|
|
599
|
+
const info = virtualModules[targetId]
|
|
600
|
+
|
|
601
|
+
return info.alias
|
|
602
|
+
}
|
|
603
|
+
}
|
|
604
|
+
|
|
605
|
+
// TODO this is terrible and slow, we should be able to get extensions working:
|
|
606
|
+
// having trouble getting .native.js to be picked up via vite
|
|
607
|
+
// tried adding packages to optimizeDeps, tried resolveExtensions + extensions...
|
|
608
|
+
// tried this but seems to not be called for node_modules
|
|
609
|
+
if (isBuildingNativeBundle) {
|
|
610
|
+
if (id[0] === '.') {
|
|
611
|
+
const absolutePath = resolve(dirname(importer), id)
|
|
612
|
+
const nativePath = absolutePath.replace(/(.m?js)/, '.native.js')
|
|
613
|
+
if (nativePath === id) return
|
|
614
|
+
try {
|
|
615
|
+
const directoryPath = absolutePath + '/index.native.js'
|
|
616
|
+
const directoryNonNativePath = absolutePath + '/index.js'
|
|
617
|
+
if (pathExistsSync(directoryPath)) {
|
|
618
|
+
return directoryPath
|
|
619
|
+
}
|
|
620
|
+
if (pathExistsSync(directoryNonNativePath)) {
|
|
621
|
+
return directoryNonNativePath
|
|
622
|
+
}
|
|
623
|
+
if (pathExistsSync(nativePath)) {
|
|
624
|
+
return nativePath
|
|
625
|
+
}
|
|
626
|
+
} catch (err) {
|
|
627
|
+
console.warn(`error probably fine`, err)
|
|
628
|
+
}
|
|
629
|
+
}
|
|
630
|
+
}
|
|
631
|
+
},
|
|
632
|
+
|
|
633
|
+
load(id) {
|
|
634
|
+
if (id.startsWith('virtual:rn-internals')) {
|
|
635
|
+
const idOut = id.replace('virtual:rn-internals:', '')
|
|
636
|
+
let out = `const ___val = __cachedModules["${idOut}"]
|
|
637
|
+
const ___defaultVal = ___val ? ___val.default || ___val : ___val
|
|
638
|
+
export default ___defaultVal`
|
|
639
|
+
return out
|
|
640
|
+
}
|
|
641
|
+
|
|
642
|
+
for (const targetId in virtualModules) {
|
|
643
|
+
const info = virtualModules[targetId as keyof typeof virtualModules]
|
|
644
|
+
if (id === info.alias) {
|
|
645
|
+
return info.contents
|
|
646
|
+
}
|
|
647
|
+
}
|
|
648
|
+
},
|
|
649
|
+
} satisfies PluginOption
|
|
639
650
|
}
|
|
640
651
|
|
|
641
652
|
function getIndexJsonResponse({ port, root }: { port: number | string; root }) {
|
|
@@ -742,10 +753,53 @@ function isWithin(outer: string, inner: string) {
|
|
|
742
753
|
// used for normalizing hot reloads
|
|
743
754
|
let entryRoot = ''
|
|
744
755
|
|
|
745
|
-
|
|
746
|
-
const
|
|
756
|
+
async function getViteServerConfig(config: VXRNConfigFilled) {
|
|
757
|
+
const { root, host, webConfig, cacheDir } = config
|
|
758
|
+
|
|
759
|
+
let serverConfig: UserConfig = mergeConfig(
|
|
760
|
+
getBaseViteConfig({
|
|
761
|
+
mode: 'development',
|
|
762
|
+
}),
|
|
763
|
+
{
|
|
764
|
+
root,
|
|
765
|
+
clearScreen: false,
|
|
766
|
+
|
|
767
|
+
plugins: [reactNativeHMRPlugin(config)],
|
|
768
|
+
optimizeDeps: {
|
|
769
|
+
include: depsToOptimize,
|
|
770
|
+
exclude: [`${cacheDir}/*`],
|
|
771
|
+
esbuildOptions: {
|
|
772
|
+
resolveExtensions: webExtensions,
|
|
773
|
+
},
|
|
774
|
+
},
|
|
775
|
+
ssr: {
|
|
776
|
+
noExternal: true,
|
|
777
|
+
optimizeDeps: ssrOptimizeDeps,
|
|
778
|
+
},
|
|
779
|
+
server: {
|
|
780
|
+
hmr: {
|
|
781
|
+
path: '/__vxrnhmr',
|
|
782
|
+
},
|
|
783
|
+
cors: true,
|
|
784
|
+
host,
|
|
785
|
+
},
|
|
786
|
+
} satisfies UserConfig
|
|
787
|
+
) satisfies InlineConfig
|
|
747
788
|
|
|
748
|
-
|
|
789
|
+
if (webConfig) {
|
|
790
|
+
serverConfig = mergeConfig(serverConfig, webConfig) as any
|
|
791
|
+
}
|
|
792
|
+
|
|
793
|
+
serverConfig = {
|
|
794
|
+
...serverConfig,
|
|
795
|
+
plugins: [...serverConfig.plugins!],
|
|
796
|
+
}
|
|
797
|
+
|
|
798
|
+
return serverConfig
|
|
799
|
+
}
|
|
800
|
+
|
|
801
|
+
function reactNativeHMRPlugin({ root }: VXRNConfigFilled) {
|
|
802
|
+
return {
|
|
749
803
|
name: 'client-transform',
|
|
750
804
|
|
|
751
805
|
async handleHotUpdate({ read, modules, file }) {
|
|
@@ -836,48 +890,4 @@ export async function getViteServerConfig({ root, host, webConfig, cacheDir }: V
|
|
|
836
890
|
}
|
|
837
891
|
},
|
|
838
892
|
}
|
|
839
|
-
|
|
840
|
-
let serverConfig: UserConfig = mergeConfig(
|
|
841
|
-
getBaseViteConfig({
|
|
842
|
-
mode: 'development',
|
|
843
|
-
}),
|
|
844
|
-
{
|
|
845
|
-
root,
|
|
846
|
-
clearScreen: false,
|
|
847
|
-
plugins: [
|
|
848
|
-
reactNativeHMRPlugin,
|
|
849
|
-
|
|
850
|
-
clientBundleTreeShakePlugin({}),
|
|
851
|
-
],
|
|
852
|
-
optimizeDeps: {
|
|
853
|
-
include: depsToOptimize,
|
|
854
|
-
exclude: [`${cacheDir}/*`],
|
|
855
|
-
force: true,
|
|
856
|
-
esbuildOptions: {
|
|
857
|
-
resolveExtensions: extensions,
|
|
858
|
-
},
|
|
859
|
-
},
|
|
860
|
-
server: {
|
|
861
|
-
hmr: {
|
|
862
|
-
path: '/__vxrnhmr',
|
|
863
|
-
},
|
|
864
|
-
cors: true,
|
|
865
|
-
host,
|
|
866
|
-
},
|
|
867
|
-
} satisfies UserConfig
|
|
868
|
-
) satisfies InlineConfig
|
|
869
|
-
|
|
870
|
-
if (webConfig) {
|
|
871
|
-
serverConfig = mergeConfig(serverConfig, webConfig) as any
|
|
872
|
-
}
|
|
873
|
-
|
|
874
|
-
serverConfig = {
|
|
875
|
-
...serverConfig,
|
|
876
|
-
plugins: [...serverConfig.plugins!],
|
|
877
|
-
}
|
|
878
|
-
|
|
879
|
-
return {
|
|
880
|
-
serverConfig,
|
|
881
|
-
hotUpdateCache,
|
|
882
|
-
}
|
|
883
893
|
}
|