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/dist/esm/exports/dev.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import wsAdapter from "crossws/adapters/node";
|
|
2
|
-
import { createApp, createRouter, defineEventHandler,
|
|
2
|
+
import { createApp, createRouter, defineEventHandler, eventHandler, getQuery, toNodeListener } from "h3";
|
|
3
3
|
import { createProxyEventHandler } from "h3-proxy";
|
|
4
4
|
import { readFile } from "node:fs/promises";
|
|
5
5
|
import { createServer as nodeCreateServer } from "node:http";
|
|
@@ -14,15 +14,15 @@ import FSExtra from "fs-extra";
|
|
|
14
14
|
import { build, createServer, mergeConfig, resolveConfig, transformWithEsbuild } from "vite";
|
|
15
15
|
import createViteFlow from "@vxrn/vite-flow";
|
|
16
16
|
import { resolve as importMetaResolve } from "import-meta-resolve";
|
|
17
|
-
import {
|
|
17
|
+
import { depsToOptimize, nativeExtensions, ssrOptimizeDeps, webExtensions } from "../constants.mjs";
|
|
18
18
|
import { clientInjectionsPlugin } from "../plugins/clientInjectPlugin.mjs";
|
|
19
19
|
import { reactNativeCommonJsPlugin } from "../plugins/reactNativeCommonJsPlugin.mjs";
|
|
20
20
|
import { getBaseViteConfig } from "../utils/getBaseViteConfig.mjs";
|
|
21
21
|
import { getOptionsFilled } from "../utils/getOptionsFilled.mjs";
|
|
22
22
|
import { getVitePath } from "../utils/getVitePath.mjs";
|
|
23
23
|
import { checkPatches } from "../utils/patches.mjs";
|
|
24
|
-
|
|
25
|
-
const
|
|
24
|
+
let isBuildingNativeBundle = null;
|
|
25
|
+
const hotUpdateCache = /* @__PURE__ */new Map(),
|
|
26
26
|
resolveFile = path => {
|
|
27
27
|
try {
|
|
28
28
|
return importMetaResolve(path, import.meta.url).replace("file://", "");
|
|
@@ -30,8 +30,6 @@ const depsToOptimize = ["react", "react-dom", "@react-native/normalize-color"],
|
|
|
30
30
|
return require.resolve(path);
|
|
31
31
|
}
|
|
32
32
|
},
|
|
33
|
-
nativeExtensions = [".native.tsx", ".native.jsx", ".native.js", ".tsx", ".ts", ".js", ".css", ".json"],
|
|
34
|
-
extensions = [".web.tsx", ".tsx", ".web.ts", ".ts", ".web.jsx", ".jsx", ".web.js", ".js", ".css", ".json"],
|
|
35
33
|
{
|
|
36
34
|
ensureDir,
|
|
37
35
|
pathExists,
|
|
@@ -49,78 +47,7 @@ const depsToOptimize = ["react", "react-dom", "@react-native/normalize-color"],
|
|
|
49
47
|
console.error(`
|
|
50
48
|
\u{1F97A} couldn't patch`, err);
|
|
51
49
|
}), await ensureDir(cacheDir);
|
|
52
|
-
const
|
|
53
|
-
reactJSX: join(cacheDir, "react-jsx-runtime.js"),
|
|
54
|
-
react: join(cacheDir, "react.js"),
|
|
55
|
-
reactNative: join(cacheDir, "react-native.js")
|
|
56
|
-
};
|
|
57
|
-
(await pathExists(prebuilds.reactNative)) || (console.info("Pre-building react, react-native react/jsx-runtime (one time cost)..."), await Promise.all([buildReactNative({
|
|
58
|
-
entryPoints: [resolveFile("react-native")],
|
|
59
|
-
outfile: prebuilds.reactNative
|
|
60
|
-
}), buildReact({
|
|
61
|
-
entryPoints: [resolveFile("react")],
|
|
62
|
-
outfile: prebuilds.react
|
|
63
|
-
}), buildReactJSX({
|
|
64
|
-
entryPoints: [resolveFile("react/jsx-dev-runtime")],
|
|
65
|
-
outfile: prebuilds.reactJSX
|
|
66
|
-
})]));
|
|
67
|
-
const viteFlow = options.flow ? createViteFlow(options.flow) : null,
|
|
68
|
-
templateFile = resolveFile("vxrn/react-native-template.js"),
|
|
69
|
-
jsxRuntime = {
|
|
70
|
-
// alias: 'virtual:react-jsx',
|
|
71
|
-
alias: prebuilds.reactJSX,
|
|
72
|
-
contents: await readFile(prebuilds.reactJSX, "utf-8")
|
|
73
|
-
},
|
|
74
|
-
virtualModules = {
|
|
75
|
-
"react-native": {
|
|
76
|
-
// alias: 'virtual:react-native',
|
|
77
|
-
alias: prebuilds.reactNative,
|
|
78
|
-
contents: await readFile(prebuilds.reactNative, "utf-8")
|
|
79
|
-
},
|
|
80
|
-
react: {
|
|
81
|
-
// alias: 'virtual:react',
|
|
82
|
-
alias: prebuilds.react,
|
|
83
|
-
contents: await readFile(prebuilds.react, "utf-8")
|
|
84
|
-
},
|
|
85
|
-
"react/jsx-runtime": jsxRuntime,
|
|
86
|
-
"react/jsx-dev-runtime": jsxRuntime
|
|
87
|
-
},
|
|
88
|
-
swapRnPlugin = {
|
|
89
|
-
name: "swap-react-native",
|
|
90
|
-
enforce: "pre",
|
|
91
|
-
resolveId(id, importer = "") {
|
|
92
|
-
if (id.startsWith("react-native/Libraries")) return `virtual:rn-internals:${id}`;
|
|
93
|
-
if (id === "react-native-web") return prebuilds.reactNative;
|
|
94
|
-
for (const targetId in virtualModules) if (id === targetId || id.includes(`node_modules/${targetId}/`)) return virtualModules[targetId].alias;
|
|
95
|
-
if (id[0] === ".") {
|
|
96
|
-
const absolutePath = resolve(dirname(importer), id),
|
|
97
|
-
nativePath = absolutePath.replace(/(.m?js)/, ".native.js");
|
|
98
|
-
if (nativePath === id) return;
|
|
99
|
-
try {
|
|
100
|
-
const directoryPath = absolutePath + "/index.native.js",
|
|
101
|
-
directoryNonNativePath = absolutePath + "/index.js";
|
|
102
|
-
if (pathExistsSync(directoryPath)) return directoryPath;
|
|
103
|
-
if (pathExistsSync(directoryNonNativePath)) return directoryNonNativePath;
|
|
104
|
-
if (pathExistsSync(nativePath)) return nativePath;
|
|
105
|
-
} catch (err) {
|
|
106
|
-
console.warn("error probably fine", err);
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
},
|
|
110
|
-
load(id) {
|
|
111
|
-
if (id.startsWith("virtual:rn-internals")) return `const ___val = __cachedModules["${id.replace("virtual:rn-internals:", "")}"]
|
|
112
|
-
const ___defaultVal = ___val ? ___val.default || ___val : ___val
|
|
113
|
-
export default ___defaultVal`;
|
|
114
|
-
for (const targetId in virtualModules) {
|
|
115
|
-
const info = virtualModules[targetId];
|
|
116
|
-
if (id === info.alias) return info.contents;
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
},
|
|
120
|
-
{
|
|
121
|
-
serverConfig,
|
|
122
|
-
hotUpdateCache
|
|
123
|
-
} = await getViteServerConfig(options),
|
|
50
|
+
const serverConfig = await getViteServerConfig(options),
|
|
124
51
|
viteServer = await createServer(serverConfig),
|
|
125
52
|
resolvedConfig = await resolveConfig(serverConfig, "serve"),
|
|
126
53
|
viteRNClientPlugin = clientInjectionsPlugin(resolvedConfig);
|
|
@@ -131,21 +58,18 @@ const depsToOptimize = ["react", "react-dom", "@react-native/normalize-color"],
|
|
|
131
58
|
} catch (err) {
|
|
132
59
|
console.info("err", err);
|
|
133
60
|
}
|
|
134
|
-
});
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
const vitePort = viteServer.config.server.port;
|
|
138
|
-
console.info("vite running on", vitePort);
|
|
139
|
-
const router = createRouter(),
|
|
61
|
+
}), await viteServer.listen();
|
|
62
|
+
const vitePort = viteServer.config.server.port,
|
|
63
|
+
router = createRouter(),
|
|
140
64
|
app = createApp({
|
|
141
65
|
onError: error => {
|
|
142
66
|
console.error(error);
|
|
143
67
|
},
|
|
144
68
|
onRequest: event => {
|
|
145
|
-
console.info(" \u2192", event.path);
|
|
69
|
+
process.env.DEBUG && console.info(" \u2192", event.path);
|
|
146
70
|
}
|
|
147
71
|
});
|
|
148
|
-
|
|
72
|
+
router.get("/file", defineEventHandler(e => {
|
|
149
73
|
const query = getQuery(e);
|
|
150
74
|
if (typeof query.file == "string") {
|
|
151
75
|
const source = hotUpdateCache.get(query.file);
|
|
@@ -155,7 +79,7 @@ const depsToOptimize = ["react", "react-dom", "@react-native/normalize-color"],
|
|
|
155
79
|
}
|
|
156
80
|
});
|
|
157
81
|
}
|
|
158
|
-
})), router.get("/index.bundle", defineEventHandler(async e => new Response(await
|
|
82
|
+
})), router.get("/index.bundle", defineEventHandler(async e => new Response(await getReactNativeBundle(options, viteRNClientPlugin), {
|
|
159
83
|
headers: {
|
|
160
84
|
"content-type": "text/javascript"
|
|
161
85
|
}
|
|
@@ -177,59 +101,67 @@ const depsToOptimize = ["react", "react-dom", "@react-native/normalize-color"],
|
|
|
177
101
|
socket = new WebSocket(`ws://localhost:${vitePort}/__vxrnhmr`, "vite-hmr");
|
|
178
102
|
socket.on("message", msg => {
|
|
179
103
|
const message = msg.toString();
|
|
180
|
-
console.info(clients.size, "message", message);
|
|
181
104
|
for (const listener of [...clients]) listener.send(message);
|
|
182
105
|
}), socket.on("error", err => {
|
|
183
106
|
console.info("error bridging socket to vite", err);
|
|
184
|
-
}), app.use("/__vxrnhmr",
|
|
107
|
+
}), app.use("/__vxrnhmr", defineEventHandler({
|
|
108
|
+
handler() {},
|
|
109
|
+
websocket: {
|
|
110
|
+
open(peer) {
|
|
111
|
+
process.env.DEBUG && console.debug("[hmr:web] open", peer), clients.add(peer);
|
|
112
|
+
},
|
|
113
|
+
message(peer, message) {
|
|
114
|
+
socket.send(message.rawData);
|
|
115
|
+
},
|
|
116
|
+
close(peer, event) {
|
|
117
|
+
process.env.DEBUG && console.info("[hmr:web] close", peer, event), clients.delete(peer);
|
|
118
|
+
},
|
|
119
|
+
error(peer, error) {
|
|
120
|
+
console.error("[hmr:web] error", peer, error);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
}));
|
|
124
|
+
}
|
|
125
|
+
app.use("/__hmr", defineEventHandler({
|
|
126
|
+
handler() {},
|
|
127
|
+
websocket: {
|
|
185
128
|
open(peer) {
|
|
186
|
-
console.debug("[hmr
|
|
129
|
+
console.debug("[hmr] open", peer);
|
|
187
130
|
},
|
|
188
131
|
message(peer, message) {
|
|
189
|
-
|
|
132
|
+
console.info("[hmr] message", peer, message), message.text().includes("ping") && peer.send("pong");
|
|
190
133
|
},
|
|
191
134
|
close(peer, event) {
|
|
192
|
-
console.info("[hmr
|
|
135
|
+
console.info("[hmr] close", peer, event);
|
|
193
136
|
},
|
|
194
137
|
error(peer, error) {
|
|
195
|
-
console.error("[hmr
|
|
138
|
+
console.error("[hmr] error", peer, error);
|
|
196
139
|
}
|
|
197
|
-
}));
|
|
198
|
-
}
|
|
199
|
-
app.use("/__hmr", defineWebSocketHandler({
|
|
200
|
-
open(peer) {
|
|
201
|
-
console.debug("[hmr] open", peer);
|
|
202
|
-
},
|
|
203
|
-
message(peer, message) {
|
|
204
|
-
console.info("[hmr] message", peer, message), message.text().includes("ping") && peer.send("pong");
|
|
205
|
-
},
|
|
206
|
-
close(peer, event) {
|
|
207
|
-
console.info("[hmr] close", peer, event);
|
|
208
|
-
},
|
|
209
|
-
error(peer, error) {
|
|
210
|
-
console.error("[hmr] error", peer, error);
|
|
211
140
|
}
|
|
212
|
-
})), app.use("/__client",
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
141
|
+
})), app.use("/symbolicate", defineEventHandler(() => "TODO")), app.use("/__client", defineEventHandler({
|
|
142
|
+
handler() {},
|
|
143
|
+
websocket: {
|
|
144
|
+
open(peer) {
|
|
145
|
+
console.info("[client] open", peer);
|
|
146
|
+
},
|
|
147
|
+
message(peer, messageRaw) {
|
|
148
|
+
const message = JSON.parse(messageRaw.text());
|
|
149
|
+
switch (message.type) {
|
|
150
|
+
case "client-log":
|
|
151
|
+
{
|
|
152
|
+
console.info(`\u{1FAB5} [${message.level}]`, ...message.data);
|
|
153
|
+
return;
|
|
154
|
+
}
|
|
155
|
+
default:
|
|
156
|
+
console.warn("[client] Unknown message type", message);
|
|
157
|
+
}
|
|
158
|
+
},
|
|
159
|
+
close(peer, event) {
|
|
160
|
+
console.info("[client] close", peer, event);
|
|
161
|
+
},
|
|
162
|
+
error(peer, error) {
|
|
163
|
+
console.error("[client] error", peer, error);
|
|
226
164
|
}
|
|
227
|
-
},
|
|
228
|
-
close(peer, event) {
|
|
229
|
-
console.info("[client] close", peer, event);
|
|
230
|
-
},
|
|
231
|
-
error(peer, error) {
|
|
232
|
-
console.error("[client] error", peer, error);
|
|
233
165
|
}
|
|
234
166
|
}));
|
|
235
167
|
const proxyEventHandler = createProxyEventHandler({
|
|
@@ -250,97 +182,103 @@ const depsToOptimize = ["react", "react-dom", "@react-native/normalize-color"],
|
|
|
250
182
|
await Promise.all([server.close(), viteServer.close()]);
|
|
251
183
|
}
|
|
252
184
|
};
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
185
|
+
};
|
|
186
|
+
async function getReactNativeBundle(options, viteRNClientPlugin) {
|
|
187
|
+
const {
|
|
188
|
+
root,
|
|
189
|
+
port,
|
|
190
|
+
cacheDir
|
|
191
|
+
} = options;
|
|
192
|
+
if (process.env.LOAD_TMP_BUNDLE) {
|
|
193
|
+
const tmpBundle = join(process.cwd(), "bundle.tmp.js");
|
|
194
|
+
if (await pathExists(tmpBundle)) return console.info("\u26A0\uFE0F\u26A0\uFE0F\u26A0\uFE0F\u26A0\uFE0F\u26A0\uFE0F\u26A0\uFE0F\u26A0\uFE0F\u26A0\uFE0F\u26A0\uFE0F\u26A0\uFE0F\u26A0\uFE0F\u26A0\uFE0F returning temp bundle \u26A0\uFE0F\u26A0\uFE0F\u26A0\uFE0F\u26A0\uFE0F\u26A0\uFE0F\u26A0\uFE0F\u26A0\uFE0F\u26A0\uFE0F\u26A0\uFE0F\u26A0\uFE0F", tmpBundle), await readFile(tmpBundle, "utf-8");
|
|
195
|
+
}
|
|
196
|
+
if (isBuildingNativeBundle) return await isBuildingNativeBundle;
|
|
197
|
+
let done;
|
|
198
|
+
isBuildingNativeBundle = new Promise(res => {
|
|
199
|
+
done = res;
|
|
200
|
+
});
|
|
201
|
+
async function babelReanimated(input, filename) {
|
|
202
|
+
return await new Promise((res, rej) => {
|
|
203
|
+
babel.transform(input, {
|
|
204
|
+
plugins: ["react-native-reanimated/plugin"],
|
|
205
|
+
filename
|
|
206
|
+
}, (err, result) => {
|
|
207
|
+
(!result || err) && rej(err || "no res"), res(result.code);
|
|
262
208
|
});
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
});
|
|
271
|
-
});
|
|
209
|
+
});
|
|
210
|
+
}
|
|
211
|
+
let nativeBuildConfig = {
|
|
212
|
+
plugins: [options.flow ? createViteFlow(options.flow) : null, swapPrebuiltReactModules(cacheDir), {
|
|
213
|
+
name: "reanimated",
|
|
214
|
+
async transform(code, id) {
|
|
215
|
+
if (code.includes("worklet")) return await babelReanimated(code, id);
|
|
272
216
|
}
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
})
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
rollupOptions: {
|
|
318
|
-
treeshake: !1,
|
|
319
|
-
preserveEntrySignatures: "strict",
|
|
320
|
-
output: {
|
|
321
|
-
preserveModules: !0,
|
|
322
|
-
format: "cjs"
|
|
323
|
-
}
|
|
324
|
-
}
|
|
217
|
+
}, viteRNClientPlugin, reactNativeCommonJsPlugin({
|
|
218
|
+
root,
|
|
219
|
+
port,
|
|
220
|
+
mode: "build"
|
|
221
|
+
}), viteReactPlugin({
|
|
222
|
+
tsDecorators: !0,
|
|
223
|
+
mode: "build"
|
|
224
|
+
}), {
|
|
225
|
+
name: "treat-js-files-as-jsx",
|
|
226
|
+
async transform(code, id) {
|
|
227
|
+
return id.match(/expo-status-bar/) ? transformWithEsbuild(code, id, {
|
|
228
|
+
loader: "jsx",
|
|
229
|
+
jsx: "automatic"
|
|
230
|
+
}) : null;
|
|
231
|
+
}
|
|
232
|
+
}].filter(Boolean),
|
|
233
|
+
appType: "custom",
|
|
234
|
+
root,
|
|
235
|
+
clearScreen: !1,
|
|
236
|
+
optimizeDeps: {
|
|
237
|
+
include: depsToOptimize,
|
|
238
|
+
esbuildOptions: {
|
|
239
|
+
jsx: "automatic"
|
|
240
|
+
}
|
|
241
|
+
},
|
|
242
|
+
resolve: {
|
|
243
|
+
extensions: nativeExtensions
|
|
244
|
+
},
|
|
245
|
+
mode: "development",
|
|
246
|
+
define: {
|
|
247
|
+
"process.env.NODE_ENV": '"development"'
|
|
248
|
+
},
|
|
249
|
+
build: {
|
|
250
|
+
ssr: !1,
|
|
251
|
+
minify: !1,
|
|
252
|
+
commonjsOptions: {
|
|
253
|
+
transformMixedEsModules: !0
|
|
254
|
+
},
|
|
255
|
+
rollupOptions: {
|
|
256
|
+
treeshake: !1,
|
|
257
|
+
preserveEntrySignatures: "strict",
|
|
258
|
+
output: {
|
|
259
|
+
preserveModules: !0,
|
|
260
|
+
format: "cjs"
|
|
325
261
|
}
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
};
|
|
265
|
+
options.nativeConfig && (nativeBuildConfig = mergeConfig(nativeBuildConfig, options.nativeConfig)), await resolveConfig(nativeBuildConfig, "build");
|
|
266
|
+
const buildOutput = await build(nativeBuildConfig);
|
|
267
|
+
if (!("output" in buildOutput)) throw "\u274C";
|
|
268
|
+
let appCode = buildOutput.output.sort((a, b) => a.isEntry ? 1 : -1).map(outputModule => {
|
|
269
|
+
if (outputModule.type == "chunk") {
|
|
270
|
+
const importsMap = {
|
|
271
|
+
currentPath: outputModule.fileName
|
|
326
272
|
};
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
const importsMap = {
|
|
333
|
-
currentPath: outputModule.fileName
|
|
334
|
-
};
|
|
335
|
-
for (const imp of outputModule.imports) {
|
|
336
|
-
const relativePath = relative(dirname(outputModule.fileName), imp);
|
|
337
|
-
importsMap[relativePath[0] === "." ? relativePath : "./" + relativePath] = imp;
|
|
338
|
-
}
|
|
339
|
-
return outputModule.isEntry && (entryRoot = dirname(outputModule.fileName)), `
|
|
273
|
+
for (const imp of outputModule.imports) {
|
|
274
|
+
const relativePath = relative(dirname(outputModule.fileName), imp);
|
|
275
|
+
importsMap[relativePath[0] === "." ? relativePath : "./" + relativePath] = imp;
|
|
276
|
+
}
|
|
277
|
+
return outputModule.isEntry && (entryRoot = dirname(outputModule.fileName)), `
|
|
340
278
|
___modules___["${outputModule.fileName}"] = ((exports, module) => {
|
|
341
|
-
|
|
279
|
+
const require = createRequire(${JSON.stringify(importsMap, null, 2)})
|
|
342
280
|
|
|
343
|
-
|
|
281
|
+
${outputModule.code}
|
|
344
282
|
})
|
|
345
283
|
|
|
346
284
|
${outputModule.isEntry ? `
|
|
@@ -350,16 +288,89 @@ __require("react-native")
|
|
|
350
288
|
__require("${outputModule.fileName}")
|
|
351
289
|
` : ""}
|
|
352
290
|
`;
|
|
353
|
-
|
|
354
|
-
|
|
291
|
+
}
|
|
292
|
+
}).join(`
|
|
355
293
|
`);
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
294
|
+
if (!appCode) throw "\u274C";
|
|
295
|
+
appCode = appCode.replaceAll("undefined.accept(() => {})", "").replaceAll("undefined.accept(function() {});", "").replaceAll("(void 0).accept(() => {})", "").replaceAll("(void 0).accept(function() {});", "").replaceAll('dist/esm/index.mjs"', 'dist/esm/index.js"');
|
|
296
|
+
const appRootParent = join(root, "..", ".."),
|
|
297
|
+
prebuilds = {
|
|
298
|
+
reactJSX: join(cacheDir, "react-jsx-runtime.js"),
|
|
299
|
+
react: join(cacheDir, "react.js"),
|
|
300
|
+
reactNative: join(cacheDir, "react-native.js")
|
|
301
|
+
},
|
|
302
|
+
templateFile = resolveFile("vxrn/react-native-template.js"),
|
|
303
|
+
out = (await readFile(templateFile, "utf-8")).replace("_virtual/virtual_react-native.js", relative(appRootParent, prebuilds.reactNative)).replace("_virtual/virtual_react.js", relative(appRootParent, prebuilds.react)).replaceAll("_virtual/virtual_react-jsx.js", relative(appRootParent, prebuilds.reactJSX)) + appCode;
|
|
304
|
+
return done(out), isBuildingNativeBundle = null, out;
|
|
305
|
+
}
|
|
306
|
+
async function swapPrebuiltReactModules(cacheDir) {
|
|
307
|
+
const prebuilds = {
|
|
308
|
+
reactJSX: join(cacheDir, "react-jsx-runtime.js"),
|
|
309
|
+
react: join(cacheDir, "react.js"),
|
|
310
|
+
reactNative: join(cacheDir, "react-native.js")
|
|
311
|
+
};
|
|
312
|
+
(await pathExists(prebuilds.reactNative)) || (console.info("Pre-building react, react-native react/jsx-runtime (one time cost)..."), await Promise.all([buildReactNative({
|
|
313
|
+
entryPoints: [resolveFile("react-native")],
|
|
314
|
+
outfile: prebuilds.reactNative
|
|
315
|
+
}), buildReact({
|
|
316
|
+
entryPoints: [resolveFile("react")],
|
|
317
|
+
outfile: prebuilds.react
|
|
318
|
+
}), buildReactJSX({
|
|
319
|
+
entryPoints: [resolveFile("react/jsx-dev-runtime")],
|
|
320
|
+
outfile: prebuilds.reactJSX
|
|
321
|
+
})]));
|
|
322
|
+
const jsxRuntime = {
|
|
323
|
+
// alias: 'virtual:react-jsx',
|
|
324
|
+
alias: prebuilds.reactJSX,
|
|
325
|
+
contents: await readFile(prebuilds.reactJSX, "utf-8")
|
|
326
|
+
},
|
|
327
|
+
virtualModules = {
|
|
328
|
+
"react-native": {
|
|
329
|
+
// alias: 'virtual:react-native',
|
|
330
|
+
alias: prebuilds.reactNative,
|
|
331
|
+
contents: await readFile(prebuilds.reactNative, "utf-8")
|
|
332
|
+
},
|
|
333
|
+
react: {
|
|
334
|
+
// alias: 'virtual:react',
|
|
335
|
+
alias: prebuilds.react,
|
|
336
|
+
contents: await readFile(prebuilds.react, "utf-8")
|
|
337
|
+
},
|
|
338
|
+
"react/jsx-runtime": jsxRuntime,
|
|
339
|
+
"react/jsx-dev-runtime": jsxRuntime
|
|
340
|
+
};
|
|
341
|
+
return {
|
|
342
|
+
name: "swap-react-native",
|
|
343
|
+
enforce: "pre",
|
|
344
|
+
resolveId(id, importer = "") {
|
|
345
|
+
if (id.startsWith("react-native/Libraries")) return `virtual:rn-internals:${id}`;
|
|
346
|
+
if (id === "react-native-web") return prebuilds.reactNative;
|
|
347
|
+
for (const targetId in virtualModules) if (id === targetId || id.includes(`node_modules/${targetId}/`)) return virtualModules[targetId].alias;
|
|
348
|
+
if (isBuildingNativeBundle && id[0] === ".") {
|
|
349
|
+
const absolutePath = resolve(dirname(importer), id),
|
|
350
|
+
nativePath = absolutePath.replace(/(.m?js)/, ".native.js");
|
|
351
|
+
if (nativePath === id) return;
|
|
352
|
+
try {
|
|
353
|
+
const directoryPath = absolutePath + "/index.native.js",
|
|
354
|
+
directoryNonNativePath = absolutePath + "/index.js";
|
|
355
|
+
if (pathExistsSync(directoryPath)) return directoryPath;
|
|
356
|
+
if (pathExistsSync(directoryNonNativePath)) return directoryNonNativePath;
|
|
357
|
+
if (pathExistsSync(nativePath)) return nativePath;
|
|
358
|
+
} catch (err) {
|
|
359
|
+
console.warn("error probably fine", err);
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
},
|
|
363
|
+
load(id) {
|
|
364
|
+
if (id.startsWith("virtual:rn-internals")) return `const ___val = __cachedModules["${id.replace("virtual:rn-internals:", "")}"]
|
|
365
|
+
const ___defaultVal = ___val ? ___val.default || ___val : ___val
|
|
366
|
+
export default ___defaultVal`;
|
|
367
|
+
for (const targetId in virtualModules) {
|
|
368
|
+
const info = virtualModules[targetId];
|
|
369
|
+
if (id === info.alias) return info.contents;
|
|
370
|
+
}
|
|
361
371
|
}
|
|
362
372
|
};
|
|
373
|
+
}
|
|
363
374
|
function getIndexJsonResponse({
|
|
364
375
|
port,
|
|
365
376
|
root
|
|
@@ -463,77 +474,30 @@ function isWithin(outer, inner) {
|
|
|
463
474
|
return !rel.startsWith("../") && rel !== "..";
|
|
464
475
|
}
|
|
465
476
|
let entryRoot = "";
|
|
466
|
-
async function getViteServerConfig({
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
reactNativeHMRPlugin = {
|
|
474
|
-
name: "client-transform",
|
|
475
|
-
async handleHotUpdate({
|
|
476
|
-
read,
|
|
477
|
-
modules,
|
|
478
|
-
file
|
|
479
|
-
}) {
|
|
480
|
-
try {
|
|
481
|
-
if (!isWithin(root, file)) return;
|
|
482
|
-
const [module] = modules;
|
|
483
|
-
if (!module) return;
|
|
484
|
-
const id = module?.url || file.replace(root, ""),
|
|
485
|
-
code = await read();
|
|
486
|
-
if (code.startsWith("'use strict';") || !code) return;
|
|
487
|
-
let source = code;
|
|
488
|
-
source = (await transformForBuild(id, source))?.code || "";
|
|
489
|
-
const importsMap = {},
|
|
490
|
-
[imports] = parse(source);
|
|
491
|
-
let accumulatedSliceOffset = 0;
|
|
492
|
-
for (const specifier of imports) {
|
|
493
|
-
const {
|
|
494
|
-
n: importName,
|
|
495
|
-
s: start
|
|
496
|
-
} = specifier;
|
|
497
|
-
if (importName) {
|
|
498
|
-
const id2 = await getVitePath(entryRoot, file, importName);
|
|
499
|
-
if (!id2) {
|
|
500
|
-
console.warn("???");
|
|
501
|
-
continue;
|
|
502
|
-
}
|
|
503
|
-
importsMap[id2] = id2.replace(/^(\.\.\/)+/, "");
|
|
504
|
-
const len = importName.length,
|
|
505
|
-
extraLen = id2.length - len;
|
|
506
|
-
source = source.slice(0, start + accumulatedSliceOffset) + id2 + source.slice(start + accumulatedSliceOffset + len), accumulatedSliceOffset += extraLen;
|
|
507
|
-
}
|
|
508
|
-
}
|
|
509
|
-
if (source = (await swcTransform(id, source, {
|
|
510
|
-
mode: "serve-cjs"
|
|
511
|
-
}))?.code || "", !source) throw "\u274C no source";
|
|
512
|
-
importsMap.currentPath = id;
|
|
513
|
-
const hotUpdateSource = `exports = ((exports) => {
|
|
514
|
-
const require = createRequire(${JSON.stringify(importsMap, null, 2)})
|
|
515
|
-
${source.replace("import.meta.hot.accept(() => {})", "").replaceAll(/import.meta.glob\(.*\)/gi, "globalThis['__importMetaGlobbed'] || {}")};
|
|
516
|
-
return exports })({})`;
|
|
517
|
-
process.env.DEBUG && console.info("Sending hot update", hotUpdateSource), hotUpdateCache.set(id, hotUpdateSource);
|
|
518
|
-
} catch (err) {
|
|
519
|
-
console.error("Error processing hmr update:", err);
|
|
520
|
-
}
|
|
521
|
-
}
|
|
522
|
-
};
|
|
477
|
+
async function getViteServerConfig(config) {
|
|
478
|
+
const {
|
|
479
|
+
root,
|
|
480
|
+
host,
|
|
481
|
+
webConfig,
|
|
482
|
+
cacheDir
|
|
483
|
+
} = config;
|
|
523
484
|
let serverConfig = mergeConfig(getBaseViteConfig({
|
|
524
485
|
mode: "development"
|
|
525
486
|
}), {
|
|
526
487
|
root,
|
|
527
488
|
clearScreen: !1,
|
|
528
|
-
plugins: [reactNativeHMRPlugin
|
|
489
|
+
plugins: [reactNativeHMRPlugin(config)],
|
|
529
490
|
optimizeDeps: {
|
|
530
491
|
include: depsToOptimize,
|
|
531
492
|
exclude: [`${cacheDir}/*`],
|
|
532
|
-
force: !0,
|
|
533
493
|
esbuildOptions: {
|
|
534
|
-
resolveExtensions:
|
|
494
|
+
resolveExtensions: webExtensions
|
|
535
495
|
}
|
|
536
496
|
},
|
|
497
|
+
ssr: {
|
|
498
|
+
noExternal: !0,
|
|
499
|
+
optimizeDeps: ssrOptimizeDeps
|
|
500
|
+
},
|
|
537
501
|
server: {
|
|
538
502
|
hmr: {
|
|
539
503
|
path: "/__vxrnhmr"
|
|
@@ -545,9 +509,60 @@ async function getViteServerConfig({
|
|
|
545
509
|
return webConfig && (serverConfig = mergeConfig(serverConfig, webConfig)), serverConfig = {
|
|
546
510
|
...serverConfig,
|
|
547
511
|
plugins: [...serverConfig.plugins]
|
|
548
|
-
},
|
|
549
|
-
|
|
550
|
-
|
|
512
|
+
}, serverConfig;
|
|
513
|
+
}
|
|
514
|
+
function reactNativeHMRPlugin({
|
|
515
|
+
root
|
|
516
|
+
}) {
|
|
517
|
+
return {
|
|
518
|
+
name: "client-transform",
|
|
519
|
+
async handleHotUpdate({
|
|
520
|
+
read,
|
|
521
|
+
modules,
|
|
522
|
+
file
|
|
523
|
+
}) {
|
|
524
|
+
try {
|
|
525
|
+
if (!isWithin(root, file)) return;
|
|
526
|
+
const [module] = modules;
|
|
527
|
+
if (!module) return;
|
|
528
|
+
const id = module?.url || file.replace(root, ""),
|
|
529
|
+
code = await read();
|
|
530
|
+
if (code.startsWith("'use strict';") || !code) return;
|
|
531
|
+
let source = code;
|
|
532
|
+
source = (await transformForBuild(id, source))?.code || "";
|
|
533
|
+
const importsMap = {},
|
|
534
|
+
[imports] = parse(source);
|
|
535
|
+
let accumulatedSliceOffset = 0;
|
|
536
|
+
for (const specifier of imports) {
|
|
537
|
+
const {
|
|
538
|
+
n: importName,
|
|
539
|
+
s: start
|
|
540
|
+
} = specifier;
|
|
541
|
+
if (importName) {
|
|
542
|
+
const id2 = await getVitePath(entryRoot, file, importName);
|
|
543
|
+
if (!id2) {
|
|
544
|
+
console.warn("???");
|
|
545
|
+
continue;
|
|
546
|
+
}
|
|
547
|
+
importsMap[id2] = id2.replace(/^(\.\.\/)+/, "");
|
|
548
|
+
const len = importName.length,
|
|
549
|
+
extraLen = id2.length - len;
|
|
550
|
+
source = source.slice(0, start + accumulatedSliceOffset) + id2 + source.slice(start + accumulatedSliceOffset + len), accumulatedSliceOffset += extraLen;
|
|
551
|
+
}
|
|
552
|
+
}
|
|
553
|
+
if (source = (await swcTransform(id, source, {
|
|
554
|
+
mode: "serve-cjs"
|
|
555
|
+
}))?.code || "", !source) throw "\u274C no source";
|
|
556
|
+
importsMap.currentPath = id;
|
|
557
|
+
const hotUpdateSource = `exports = ((exports) => {
|
|
558
|
+
const require = createRequire(${JSON.stringify(importsMap, null, 2)})
|
|
559
|
+
${source.replace("import.meta.hot.accept(() => {})", "").replaceAll(/import.meta.glob\(.*\)/gi, "globalThis['__importMetaGlobbed'] || {}")};
|
|
560
|
+
return exports })({})`;
|
|
561
|
+
process.env.DEBUG && console.info("Sending hot update", hotUpdateSource), hotUpdateCache.set(id, hotUpdateSource);
|
|
562
|
+
} catch (err) {
|
|
563
|
+
console.error("Error processing hmr update:", err);
|
|
564
|
+
}
|
|
565
|
+
}
|
|
551
566
|
};
|
|
552
567
|
}
|
|
553
|
-
export { bindKeypressInput, dev,
|
|
568
|
+
export { bindKeypressInput, dev, resolveFile };
|