@vxrn/vite-plugin-metro 1.27.1 → 2.0.0-beta.101.1
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/babel-plugins/import-meta-env-plugin.cjs +84 -102
- package/dist/cjs/babel-plugins/import-meta-env-plugin.native.cjs +108 -0
- package/dist/cjs/babel-plugins/import-meta-env-plugin.native.js +90 -107
- package/dist/cjs/babel-plugins/import-meta-env-plugin.native.js.map +1 -1
- package/dist/cjs/env/platformEnv.cjs +57 -57
- package/dist/cjs/env/platformEnv.native.cjs +95 -0
- package/dist/cjs/env/platformEnv.native.js +74 -75
- package/dist/cjs/env/platformEnv.native.js.map +1 -1
- package/dist/cjs/index.cjs +21 -25
- package/dist/cjs/index.native.cjs +39 -0
- package/dist/cjs/index.native.js +21 -24
- package/dist/cjs/index.native.js.map +1 -1
- package/dist/cjs/metro-config/getMetroBabelConfigFromViteConfig.cjs +54 -51
- package/dist/cjs/metro-config/getMetroBabelConfigFromViteConfig.native.cjs +108 -0
- package/dist/cjs/metro-config/getMetroBabelConfigFromViteConfig.native.js +95 -94
- package/dist/cjs/metro-config/getMetroBabelConfigFromViteConfig.native.js.map +1 -1
- package/dist/cjs/metro-config/getMetroConfigFromViteConfig.cjs +287 -272
- package/dist/cjs/metro-config/getMetroConfigFromViteConfig.native.cjs +346 -0
- package/dist/cjs/metro-config/getMetroConfigFromViteConfig.native.js +309 -282
- package/dist/cjs/metro-config/getMetroConfigFromViteConfig.native.js.map +1 -1
- package/dist/cjs/metro-config/patchMetroServerWithViteConfigAndMetroPluginOptions.cjs +38 -44
- package/dist/cjs/metro-config/patchMetroServerWithViteConfigAndMetroPluginOptions.native.cjs +53 -0
- package/dist/cjs/metro-config/patchMetroServerWithViteConfigAndMetroPluginOptions.native.js +39 -44
- package/dist/cjs/metro-config/patchMetroServerWithViteConfigAndMetroPluginOptions.native.js.map +1 -1
- package/dist/cjs/metro-config/types.cjs +9 -11
- package/dist/cjs/metro-config/types.native.cjs +18 -0
- package/dist/cjs/metro-config/types.native.js +9 -10
- package/dist/cjs/metro-config/types.native.js.map +1 -1
- package/dist/cjs/plugins/metroPlugin.cjs +210 -248
- package/dist/cjs/plugins/metroPlugin.native.cjs +242 -0
- package/dist/cjs/plugins/metroPlugin.native.js +216 -253
- package/dist/cjs/plugins/metroPlugin.native.js.map +1 -1
- package/dist/cjs/rn-commands/bundle/assetCatalogIOS.cjs +56 -65
- package/dist/cjs/rn-commands/bundle/assetCatalogIOS.native.cjs +121 -0
- package/dist/cjs/rn-commands/bundle/assetCatalogIOS.native.js +94 -106
- package/dist/cjs/rn-commands/bundle/assetCatalogIOS.native.js.map +1 -1
- package/dist/cjs/rn-commands/bundle/assetPathUtils.cjs +51 -55
- package/dist/cjs/rn-commands/bundle/assetPathUtils.native.cjs +72 -0
- package/dist/cjs/rn-commands/bundle/assetPathUtils.native.js +51 -54
- package/dist/cjs/rn-commands/bundle/assetPathUtils.native.js.map +1 -1
- package/dist/cjs/rn-commands/bundle/buildBundle.cjs +37 -46
- package/dist/cjs/rn-commands/bundle/buildBundle.native.cjs +57 -0
- package/dist/cjs/rn-commands/bundle/buildBundle.native.js +39 -47
- package/dist/cjs/rn-commands/bundle/buildBundle.native.js.map +1 -1
- package/dist/cjs/rn-commands/bundle/buildBundleWithConfig.cjs +57 -68
- package/dist/cjs/rn-commands/bundle/buildBundleWithConfig.native.cjs +81 -0
- package/dist/cjs/rn-commands/bundle/buildBundleWithConfig.native.js +59 -70
- package/dist/cjs/rn-commands/bundle/buildBundleWithConfig.native.js.map +1 -1
- package/dist/cjs/rn-commands/bundle/filterPlatformAssetScales.cjs +37 -39
- package/dist/cjs/rn-commands/bundle/filterPlatformAssetScales.native.cjs +70 -0
- package/dist/cjs/rn-commands/bundle/filterPlatformAssetScales.native.js +56 -59
- package/dist/cjs/rn-commands/bundle/filterPlatformAssetScales.native.js.map +1 -1
- package/dist/cjs/rn-commands/bundle/getAssetDestPathAndroid.cjs +20 -29
- package/dist/cjs/rn-commands/bundle/getAssetDestPathAndroid.native.cjs +39 -0
- package/dist/cjs/rn-commands/bundle/getAssetDestPathAndroid.native.js +20 -28
- package/dist/cjs/rn-commands/bundle/getAssetDestPathAndroid.native.js.map +1 -1
- package/dist/cjs/rn-commands/bundle/getAssetDestPathIOS.cjs +20 -33
- package/dist/cjs/rn-commands/bundle/getAssetDestPathIOS.native.cjs +38 -0
- package/dist/cjs/rn-commands/bundle/getAssetDestPathIOS.native.js +20 -32
- package/dist/cjs/rn-commands/bundle/getAssetDestPathIOS.native.js.map +1 -1
- package/dist/cjs/rn-commands/bundle/getBuildBundleFn.cjs +23 -32
- package/dist/cjs/rn-commands/bundle/getBuildBundleFn.native.cjs +38 -0
- package/dist/cjs/rn-commands/bundle/getBuildBundleFn.native.js +23 -31
- package/dist/cjs/rn-commands/bundle/getBuildBundleFn.native.js.map +1 -1
- package/dist/cjs/rn-commands/bundle/index.cjs +15 -17
- package/dist/cjs/rn-commands/bundle/index.native.cjs +30 -0
- package/dist/cjs/rn-commands/bundle/index.native.js +15 -16
- package/dist/cjs/rn-commands/bundle/index.native.js.map +1 -1
- package/dist/cjs/rn-commands/bundle/saveAssets.cjs +85 -96
- package/dist/cjs/rn-commands/bundle/saveAssets.native.cjs +129 -0
- package/dist/cjs/rn-commands/bundle/saveAssets.native.js +102 -114
- package/dist/cjs/rn-commands/bundle/saveAssets.native.js.map +1 -1
- package/dist/cjs/rn-commands/bundle/types.cjs +9 -11
- package/dist/cjs/rn-commands/bundle/types.native.cjs +18 -0
- package/dist/cjs/rn-commands/bundle/types.native.js +9 -10
- package/dist/cjs/rn-commands/bundle/types.native.js.map +1 -1
- package/dist/cjs/rn-commands/index.cjs +17 -26
- package/dist/cjs/rn-commands/index.native.cjs +32 -0
- package/dist/cjs/rn-commands/index.native.js +17 -25
- package/dist/cjs/rn-commands/index.native.js.map +1 -1
- package/dist/cjs/transformer/babel-core.cjs +16 -18
- package/dist/cjs/transformer/babel-core.native.cjs +30 -0
- package/dist/cjs/transformer/babel-core.native.js +16 -17
- package/dist/cjs/transformer/babel-core.native.js.map +1 -1
- package/dist/cjs/transformer/babel-transformer.cjs +149 -151
- package/dist/cjs/transformer/babel-transformer.native.cjs +190 -0
- package/dist/cjs/transformer/babel-transformer.native.js +164 -158
- package/dist/cjs/transformer/babel-transformer.native.js.map +1 -1
- package/dist/cjs/transformer/expoVirtualEnv.cjs +92 -0
- package/dist/cjs/transformer/expoVirtualEnv.native.cjs +113 -0
- package/dist/cjs/transformer/expoVirtualEnv.native.js +115 -0
- package/dist/cjs/transformer/expoVirtualEnv.native.js.map +1 -0
- package/dist/cjs/transformer/loadBabelConfig.cjs +44 -49
- package/dist/cjs/transformer/loadBabelConfig.native.cjs +64 -0
- package/dist/cjs/transformer/loadBabelConfig.native.js +48 -52
- package/dist/cjs/transformer/loadBabelConfig.native.js.map +1 -1
- package/dist/cjs/transformer/metroNativeWorker.cjs +1430 -1488
- package/dist/cjs/transformer/metroNativeWorker.native.cjs +2519 -0
- package/dist/cjs/transformer/metroNativeWorker.native.js +2407 -2560
- package/dist/cjs/transformer/metroNativeWorker.native.js.map +1 -1
- package/dist/cjs/transformer/transformSync.cjs +48 -64
- package/dist/cjs/transformer/transformSync.native.cjs +74 -0
- package/dist/cjs/transformer/transformSync.native.js +50 -65
- package/dist/cjs/transformer/transformSync.native.js.map +1 -1
- package/dist/cjs/transformer/types.cjs +9 -11
- package/dist/cjs/transformer/types.native.cjs +18 -0
- package/dist/cjs/transformer/types.native.js +9 -10
- package/dist/cjs/transformer/types.native.js.map +1 -1
- package/dist/cjs/utils/exit.cjs +141 -139
- package/dist/cjs/utils/exit.native.cjs +266 -0
- package/dist/cjs/utils/exit.native.js +228 -241
- package/dist/cjs/utils/exit.native.js.map +1 -1
- package/dist/cjs/utils/getTerminalReporter.cjs +35 -47
- package/dist/cjs/utils/getTerminalReporter.native.cjs +57 -0
- package/dist/cjs/utils/getTerminalReporter.native.js +38 -49
- package/dist/cjs/utils/getTerminalReporter.native.js.map +1 -1
- package/dist/cjs/utils/metroCacheManager.cjs +84 -99
- package/dist/cjs/utils/metroCacheManager.native.cjs +130 -0
- package/dist/cjs/utils/metroCacheManager.native.js +102 -118
- package/dist/cjs/utils/metroCacheManager.native.js.map +1 -1
- package/dist/cjs/utils/projectImport.cjs +40 -51
- package/dist/cjs/utils/projectImport.native.cjs +64 -0
- package/dist/cjs/utils/projectImport.native.js +41 -58
- package/dist/cjs/utils/projectImport.native.js.map +1 -1
- package/dist/esm/babel-plugins/import-meta-env-plugin.mjs +72 -86
- package/dist/esm/babel-plugins/import-meta-env-plugin.mjs.map +1 -1
- package/dist/esm/babel-plugins/import-meta-env-plugin.native.js +78 -92
- package/dist/esm/babel-plugins/import-meta-env-plugin.native.js.map +1 -1
- package/dist/esm/env/platformEnv.mjs +42 -39
- package/dist/esm/env/platformEnv.mjs.map +1 -1
- package/dist/esm/env/platformEnv.native.js +59 -58
- package/dist/esm/env/platformEnv.native.js.map +1 -1
- package/dist/esm/index.js +3 -4
- package/dist/esm/index.mjs +3 -4
- package/dist/esm/index.native.js +3 -4
- package/dist/esm/metro-config/getMetroBabelConfigFromViteConfig.mjs +42 -33
- package/dist/esm/metro-config/getMetroBabelConfigFromViteConfig.mjs.map +1 -1
- package/dist/esm/metro-config/getMetroBabelConfigFromViteConfig.native.js +83 -77
- package/dist/esm/metro-config/getMetroBabelConfigFromViteConfig.native.js.map +1 -1
- package/dist/esm/metro-config/getMetroConfigFromViteConfig.mjs +271 -247
- package/dist/esm/metro-config/getMetroConfigFromViteConfig.mjs.map +1 -1
- package/dist/esm/metro-config/getMetroConfigFromViteConfig.native.js +293 -258
- package/dist/esm/metro-config/getMetroConfigFromViteConfig.native.js.map +1 -1
- package/dist/esm/metro-config/patchMetroServerWithViteConfigAndMetroPluginOptions.mjs +26 -26
- package/dist/esm/metro-config/patchMetroServerWithViteConfigAndMetroPluginOptions.mjs.map +1 -1
- package/dist/esm/metro-config/patchMetroServerWithViteConfigAndMetroPluginOptions.native.js +27 -27
- package/dist/esm/metro-config/patchMetroServerWithViteConfigAndMetroPluginOptions.native.js.map +1 -1
- package/dist/esm/metro-config/types.mjs +0 -2
- package/dist/esm/metro-config/types.native.js +0 -2
- package/dist/esm/plugins/metroPlugin.mjs +195 -222
- package/dist/esm/plugins/metroPlugin.mjs.map +1 -1
- package/dist/esm/plugins/metroPlugin.native.js +201 -228
- package/dist/esm/plugins/metroPlugin.native.js.map +1 -1
- package/dist/esm/rn-commands/bundle/assetCatalogIOS.mjs +38 -38
- package/dist/esm/rn-commands/bundle/assetCatalogIOS.mjs.map +1 -1
- package/dist/esm/rn-commands/bundle/assetCatalogIOS.native.js +76 -80
- package/dist/esm/rn-commands/bundle/assetCatalogIOS.native.js.map +1 -1
- package/dist/esm/rn-commands/bundle/assetPathUtils.mjs +38 -37
- package/dist/esm/rn-commands/bundle/assetPathUtils.mjs.map +1 -1
- package/dist/esm/rn-commands/bundle/assetPathUtils.native.js +38 -37
- package/dist/esm/rn-commands/bundle/assetPathUtils.native.js.map +1 -1
- package/dist/esm/rn-commands/bundle/buildBundle.mjs +25 -28
- package/dist/esm/rn-commands/bundle/buildBundle.mjs.map +1 -1
- package/dist/esm/rn-commands/bundle/buildBundle.native.js +27 -30
- package/dist/esm/rn-commands/bundle/buildBundle.native.js.map +1 -1
- package/dist/esm/rn-commands/bundle/buildBundleWithConfig.mjs +43 -43
- package/dist/esm/rn-commands/bundle/buildBundleWithConfig.mjs.map +1 -1
- package/dist/esm/rn-commands/bundle/buildBundleWithConfig.native.js +45 -46
- package/dist/esm/rn-commands/bundle/buildBundleWithConfig.native.js.map +1 -1
- package/dist/esm/rn-commands/bundle/filterPlatformAssetScales.mjs +24 -21
- package/dist/esm/rn-commands/bundle/filterPlatformAssetScales.mjs.map +1 -1
- package/dist/esm/rn-commands/bundle/filterPlatformAssetScales.native.js +43 -42
- package/dist/esm/rn-commands/bundle/filterPlatformAssetScales.native.js.map +1 -1
- package/dist/esm/rn-commands/bundle/getAssetDestPathAndroid.mjs +5 -3
- package/dist/esm/rn-commands/bundle/getAssetDestPathAndroid.mjs.map +1 -1
- package/dist/esm/rn-commands/bundle/getAssetDestPathAndroid.native.js +5 -3
- package/dist/esm/rn-commands/bundle/getAssetDestPathAndroid.native.js.map +1 -1
- package/dist/esm/rn-commands/bundle/getAssetDestPathIOS.mjs +5 -7
- package/dist/esm/rn-commands/bundle/getAssetDestPathIOS.mjs.map +1 -1
- package/dist/esm/rn-commands/bundle/getAssetDestPathIOS.native.js +5 -7
- package/dist/esm/rn-commands/bundle/getAssetDestPathIOS.native.js.map +1 -1
- package/dist/esm/rn-commands/bundle/getBuildBundleFn.mjs +11 -14
- package/dist/esm/rn-commands/bundle/getBuildBundleFn.mjs.map +1 -1
- package/dist/esm/rn-commands/bundle/getBuildBundleFn.native.js +11 -14
- package/dist/esm/rn-commands/bundle/getBuildBundleFn.native.js.map +1 -1
- package/dist/esm/rn-commands/bundle/index.mjs +2 -2
- package/dist/esm/rn-commands/bundle/index.native.js +2 -2
- package/dist/esm/rn-commands/bundle/saveAssets.mjs +70 -70
- package/dist/esm/rn-commands/bundle/saveAssets.mjs.map +1 -1
- package/dist/esm/rn-commands/bundle/saveAssets.native.js +87 -89
- package/dist/esm/rn-commands/bundle/saveAssets.native.js.map +1 -1
- package/dist/esm/rn-commands/bundle/types.mjs +0 -2
- package/dist/esm/rn-commands/bundle/types.native.js +0 -2
- package/dist/esm/rn-commands/index.mjs +2 -2
- package/dist/esm/rn-commands/index.native.js +2 -2
- package/dist/esm/transformer/babel-core.mjs +2 -2
- package/dist/esm/transformer/babel-core.native.js +2 -2
- package/dist/esm/transformer/babel-transformer.mjs +133 -132
- package/dist/esm/transformer/babel-transformer.mjs.map +1 -1
- package/dist/esm/transformer/babel-transformer.native.js +145 -142
- package/dist/esm/transformer/babel-transformer.native.js.map +1 -1
- package/dist/esm/transformer/expoVirtualEnv.mjs +67 -0
- package/dist/esm/transformer/expoVirtualEnv.mjs.map +1 -0
- package/dist/esm/transformer/expoVirtualEnv.native.js +86 -0
- package/dist/esm/transformer/expoVirtualEnv.native.js.map +1 -0
- package/dist/esm/transformer/loadBabelConfig.mjs +29 -23
- package/dist/esm/transformer/loadBabelConfig.mjs.map +1 -1
- package/dist/esm/transformer/loadBabelConfig.native.js +33 -27
- package/dist/esm/transformer/loadBabelConfig.native.js.map +1 -1
- package/dist/esm/transformer/metroNativeWorker.mjs +1393 -1442
- package/dist/esm/transformer/metroNativeWorker.mjs.map +1 -1
- package/dist/esm/transformer/metroNativeWorker.native.js +2370 -2515
- package/dist/esm/transformer/metroNativeWorker.native.js.map +1 -1
- package/dist/esm/transformer/transformSync.mjs +33 -38
- package/dist/esm/transformer/transformSync.mjs.map +1 -1
- package/dist/esm/transformer/transformSync.native.js +35 -40
- package/dist/esm/transformer/transformSync.native.js.map +1 -1
- package/dist/esm/transformer/types.mjs +0 -2
- package/dist/esm/transformer/types.native.js +0 -2
- package/dist/esm/utils/exit.mjs +123 -112
- package/dist/esm/utils/exit.mjs.map +1 -1
- package/dist/esm/utils/exit.native.js +210 -215
- package/dist/esm/utils/exit.native.js.map +1 -1
- package/dist/esm/utils/getTerminalReporter.mjs +20 -21
- package/dist/esm/utils/getTerminalReporter.mjs.map +1 -1
- package/dist/esm/utils/getTerminalReporter.native.js +23 -24
- package/dist/esm/utils/getTerminalReporter.native.js.map +1 -1
- package/dist/esm/utils/metroCacheManager.mjs +73 -82
- package/dist/esm/utils/metroCacheManager.mjs.map +1 -1
- package/dist/esm/utils/metroCacheManager.native.js +91 -102
- package/dist/esm/utils/metroCacheManager.native.js.map +1 -1
- package/dist/esm/utils/projectImport.mjs +23 -25
- package/dist/esm/utils/projectImport.mjs.map +1 -1
- package/dist/esm/utils/projectImport.native.js +24 -33
- package/dist/esm/utils/projectImport.native.js.map +1 -1
- package/package.json +15 -18
- package/src/babel-plugins/import-meta-env-plugin.ts +1 -1
- package/src/env/platformEnv.test.ts +44 -0
- package/src/env/platformEnv.ts +6 -3
- package/src/index.ts +0 -2
- package/src/metro-config/getMetroBabelConfigFromViteConfig.test.ts +52 -0
- package/src/metro-config/getMetroBabelConfigFromViteConfig.ts +8 -7
- package/src/metro-config/getMetroConfigFromViteConfig.test.ts +60 -0
- package/src/metro-config/getMetroConfigFromViteConfig.ts +150 -113
- package/src/plugins/metroPlugin.ts +3 -6
- package/src/transformer/babel-transformer.test.ts +118 -0
- package/src/transformer/babel-transformer.ts +82 -15
- package/src/transformer/expoVirtualEnv.integration.test.ts +106 -0
- package/src/transformer/expoVirtualEnv.test.ts +72 -0
- package/src/transformer/expoVirtualEnv.ts +115 -0
- package/src/transformer/loadBabelConfig.ts +1 -1
- package/src/transformer/metroNativeWorker.test.ts +268 -50
- package/src/transformer/metroNativeWorker.ts +53 -71
- package/src/transformer/transformSync.test.ts +22 -0
- package/src/transformer/transformSync.ts +4 -4
- package/src/utils/exit.ts +2 -2
- package/src/utils/getTerminalReporter.ts +1 -1
- package/src/utils/projectImport.ts +2 -2
- package/types/babel-plugins/import-meta-env-plugin.d.ts +1 -1
- package/types/babel-plugins/import-meta-env-plugin.d.ts.map +1 -1
- package/types/env/platformEnv.d.ts +2 -1
- package/types/env/platformEnv.d.ts.map +1 -1
- package/types/index.d.ts +0 -2
- package/types/index.d.ts.map +1 -1
- package/types/metro-config/getMetroBabelConfigFromViteConfig.d.ts +1 -1
- package/types/metro-config/getMetroBabelConfigFromViteConfig.d.ts.map +1 -1
- package/types/metro-config/getMetroConfigFromViteConfig.d.ts +2 -2
- package/types/metro-config/getMetroConfigFromViteConfig.d.ts.map +1 -1
- package/types/plugins/metroPlugin.d.ts +2 -4
- package/types/plugins/metroPlugin.d.ts.map +1 -1
- package/types/rn-commands/bundle/assetPathUtils.d.ts.map +1 -1
- package/types/rn-commands/bundle/filterPlatformAssetScales.d.ts.map +1 -1
- package/types/rn-commands/bundle/getAssetDestPathAndroid.d.ts.map +1 -1
- package/types/rn-commands/bundle/getAssetDestPathIOS.d.ts.map +1 -1
- package/types/rn-commands/bundle/saveAssets.d.ts.map +1 -1
- package/types/transformer/babel-transformer.d.ts +10 -1
- package/types/transformer/babel-transformer.d.ts.map +1 -1
- package/types/transformer/expoVirtualEnv.d.ts +8 -0
- package/types/transformer/expoVirtualEnv.d.ts.map +1 -0
- package/types/transformer/metroNativeWorker.d.ts +7 -8
- package/types/transformer/metroNativeWorker.d.ts.map +1 -1
- package/types/utils/projectImport.d.ts +2 -2
- package/dist/cjs/plugins/expoManifestRequestHandlerPlugin.cjs +0 -71
- package/dist/cjs/plugins/expoManifestRequestHandlerPlugin.native.js +0 -82
- package/dist/cjs/plugins/expoManifestRequestHandlerPlugin.native.js.map +0 -1
- package/dist/cjs/transformer/metroNativeWorker.test.cjs +0 -1054
- package/dist/cjs/transformer/metroNativeWorker.test.native.js +0 -1170
- package/dist/cjs/transformer/metroNativeWorker.test.native.js.map +0 -1
- package/dist/cjs/transformer/transformSync.test.cjs +0 -36
- package/dist/cjs/transformer/transformSync.test.native.js +0 -49
- package/dist/cjs/transformer/transformSync.test.native.js.map +0 -1
- package/dist/cjs/utils/patchExpoGoManifestHandlerMiddlewareWithCustomMainModuleName.cjs +0 -39
- package/dist/cjs/utils/patchExpoGoManifestHandlerMiddlewareWithCustomMainModuleName.native.js +0 -42
- package/dist/cjs/utils/patchExpoGoManifestHandlerMiddlewareWithCustomMainModuleName.native.js.map +0 -1
- package/dist/esm/index.js.map +0 -1
- package/dist/esm/index.mjs.map +0 -1
- package/dist/esm/index.native.js.map +0 -1
- package/dist/esm/metro-config/types.mjs.map +0 -1
- package/dist/esm/metro-config/types.native.js.map +0 -1
- package/dist/esm/plugins/expoManifestRequestHandlerPlugin.mjs +0 -46
- package/dist/esm/plugins/expoManifestRequestHandlerPlugin.mjs.map +0 -1
- package/dist/esm/plugins/expoManifestRequestHandlerPlugin.native.js +0 -54
- package/dist/esm/plugins/expoManifestRequestHandlerPlugin.native.js.map +0 -1
- package/dist/esm/rn-commands/bundle/index.mjs.map +0 -1
- package/dist/esm/rn-commands/bundle/index.native.js.map +0 -1
- package/dist/esm/rn-commands/bundle/types.mjs.map +0 -1
- package/dist/esm/rn-commands/bundle/types.native.js.map +0 -1
- package/dist/esm/rn-commands/index.mjs.map +0 -1
- package/dist/esm/rn-commands/index.native.js.map +0 -1
- package/dist/esm/transformer/babel-core.mjs.map +0 -1
- package/dist/esm/transformer/babel-core.native.js.map +0 -1
- package/dist/esm/transformer/metroNativeWorker.test.mjs +0 -1010
- package/dist/esm/transformer/metroNativeWorker.test.mjs.map +0 -1
- package/dist/esm/transformer/metroNativeWorker.test.native.js +0 -1124
- package/dist/esm/transformer/metroNativeWorker.test.native.js.map +0 -1
- package/dist/esm/transformer/transformSync.test.mjs +0 -37
- package/dist/esm/transformer/transformSync.test.mjs.map +0 -1
- package/dist/esm/transformer/transformSync.test.native.js +0 -47
- package/dist/esm/transformer/transformSync.test.native.js.map +0 -1
- package/dist/esm/transformer/types.mjs.map +0 -1
- package/dist/esm/transformer/types.native.js.map +0 -1
- package/dist/esm/utils/patchExpoGoManifestHandlerMiddlewareWithCustomMainModuleName.mjs +0 -14
- package/dist/esm/utils/patchExpoGoManifestHandlerMiddlewareWithCustomMainModuleName.mjs.map +0 -1
- package/dist/esm/utils/patchExpoGoManifestHandlerMiddlewareWithCustomMainModuleName.native.js +0 -14
- package/dist/esm/utils/patchExpoGoManifestHandlerMiddlewareWithCustomMainModuleName.native.js.map +0 -1
- package/src/plugins/expoManifestRequestHandlerPlugin.ts +0 -88
- package/src/utils/patchExpoGoManifestHandlerMiddlewareWithCustomMainModuleName.ts +0 -28
- package/types/plugins/expoManifestRequestHandlerPlugin.d.ts +0 -14
- package/types/plugins/expoManifestRequestHandlerPlugin.d.ts.map +0 -1
- package/types/transformer/metroNativeWorker.test.d.ts +0 -2
- package/types/transformer/metroNativeWorker.test.d.ts.map +0 -1
- package/types/transformer/transformSync.test.d.ts +0 -2
- package/types/transformer/transformSync.test.d.ts.map +0 -1
- package/types/utils/patchExpoGoManifestHandlerMiddlewareWithCustomMainModuleName.d.ts +0 -5
- package/types/utils/patchExpoGoManifestHandlerMiddlewareWithCustomMainModuleName.d.ts.map +0 -1
|
@@ -5,58 +5,51 @@ var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
|
5
5
|
var __getProtoOf = Object.getPrototypeOf;
|
|
6
6
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
7
|
var __export = (target, all) => {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
8
|
+
for (var name in all) __defProp(target, name, {
|
|
9
|
+
get: all[name],
|
|
10
|
+
enumerable: true
|
|
11
|
+
});
|
|
12
12
|
};
|
|
13
13
|
var __copyProps = (to, from, except, desc) => {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
14
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
15
|
+
for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
16
|
+
get: () => from[key],
|
|
17
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
return to;
|
|
21
21
|
};
|
|
22
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
26
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
27
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
28
|
-
value: mod,
|
|
29
|
-
enumerable: true
|
|
22
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
23
|
+
value: mod,
|
|
24
|
+
enumerable: true
|
|
30
25
|
}) : target, mod));
|
|
31
|
-
var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
32
|
-
value: true
|
|
33
|
-
}), mod);
|
|
26
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
34
27
|
var metroNativeWorker_exports = {};
|
|
35
28
|
__export(metroNativeWorker_exports, {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
29
|
+
ScopeTracker: () => ScopeTracker,
|
|
30
|
+
applyEnvironmentGuard: () => applyEnvironmentGuard,
|
|
31
|
+
applyInlineEnvVars: () => applyInlineEnvVars,
|
|
32
|
+
applyModuleResolverAliases: () => applyModuleResolverAliases,
|
|
33
|
+
applyOneRouterMetro: () => applyOneRouterMetro,
|
|
34
|
+
assertNoUnportedBabelPlugins: () => assertNoUnportedBabelPlugins,
|
|
35
|
+
collectBlockBindings: () => collectBlockBindings,
|
|
36
|
+
collectHoistedBindings: () => collectHoistedBindings,
|
|
37
|
+
collectPatternNames: () => collectPatternNames,
|
|
38
|
+
convertSourceMapToMetroRawMappings: () => convertSourceMapToMetroRawMappings,
|
|
39
|
+
countLinesAndTerminateMap: () => countLinesAndTerminateMap,
|
|
40
|
+
default: () => metroNativeWorker_default,
|
|
41
|
+
extractDependencies: () => extractDependencies,
|
|
42
|
+
getCacheKey: () => getCacheKey,
|
|
43
|
+
getDependencyKey: () => getDependencyKey,
|
|
44
|
+
getImportMetaEnv: () => getImportMetaEnv,
|
|
45
|
+
getModuleResolverAliases: () => getModuleResolverAliases,
|
|
46
|
+
getOneRouterMetroOptions: () => getOneRouterMetroOptions,
|
|
47
|
+
getRemoveServerCodeRouterRoot: () => getRemoveServerCodeRouterRoot,
|
|
48
|
+
resolveAliasSpecifier: () => resolveAliasSpecifier,
|
|
49
|
+
rewriteDependencyCalls: () => rewriteDependencyCalls,
|
|
50
|
+
transform: () => transform,
|
|
51
|
+
wrapJson: () => wrapJson,
|
|
52
|
+
wrapModule: () => wrapModule
|
|
60
53
|
});
|
|
61
54
|
module.exports = __toCommonJS(metroNativeWorker_exports);
|
|
62
55
|
var import_node_crypto = __toESM(require("node:crypto"), 1);
|
|
@@ -68,1523 +61,1472 @@ var import_magic_string = __toESM(require("magic-string"), 1);
|
|
|
68
61
|
var import_remapping = __toESM(require("@jridgewell/remapping"), 1);
|
|
69
62
|
var import_trace_mapping = require("@jridgewell/trace-mapping");
|
|
70
63
|
var import_compiler = require("@vxrn/compiler");
|
|
64
|
+
var import_publicEnv = require("@vxrn/utils/publicEnv");
|
|
65
|
+
var import_expoVirtualEnv = require("./expoVirtualEnv.cjs");
|
|
71
66
|
var import_platformEnv = require("../env/platformEnv.cjs");
|
|
72
67
|
function collectModuleLiteralBindings(program) {
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
68
|
+
const reassigned = /* @__PURE__ */ new Set();
|
|
69
|
+
const declCount = /* @__PURE__ */ new Map();
|
|
70
|
+
(function findReassignments(node) {
|
|
71
|
+
if (!node || typeof node !== "object") return;
|
|
72
|
+
if (Array.isArray(node)) {
|
|
73
|
+
for (const child of node) findReassignments(child);
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
if (node.type === "AssignmentExpression" && node.left?.type === "Identifier") {
|
|
77
|
+
reassigned.add(node.left.name);
|
|
78
|
+
} else if (node.type === "UpdateExpression" && node.argument?.type === "Identifier") {
|
|
79
|
+
reassigned.add(node.argument.name);
|
|
80
|
+
}
|
|
81
|
+
for (const key in node) {
|
|
82
|
+
if (key === "type" || key === "start" || key === "end") continue;
|
|
83
|
+
findReassignments(node[key]);
|
|
84
|
+
}
|
|
85
|
+
})(program);
|
|
86
|
+
for (const stmt of program.body || []) {
|
|
87
|
+
if (stmt.type !== "VariableDeclaration") continue;
|
|
88
|
+
for (const decl of stmt.declarations || []) {
|
|
89
|
+
if (decl.id?.type === "Identifier") {
|
|
90
|
+
declCount.set(decl.id.name, (declCount.get(decl.id.name) || 0) + 1);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
const bindings = /* @__PURE__ */ new Map();
|
|
95
|
+
for (const stmt of program.body || []) {
|
|
96
|
+
if (stmt.type !== "VariableDeclaration") continue;
|
|
97
|
+
for (const decl of stmt.declarations || []) {
|
|
98
|
+
if (decl.id?.type === "Identifier" && decl.init?.type === "Literal" && !reassigned.has(decl.id.name) && declCount.get(decl.id.name) === 1) {
|
|
99
|
+
bindings.set(decl.id.name, decl.init);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
return bindings;
|
|
109
104
|
}
|
|
110
105
|
const WORKER_CACHE_KEY_VERSION = "5";
|
|
111
106
|
function langForFilename(filename) {
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
107
|
+
if (filename.endsWith(".tsx")) return "tsx";
|
|
108
|
+
if (filename.endsWith(".ts")) return "ts";
|
|
109
|
+
return "jsx";
|
|
115
110
|
}
|
|
116
111
|
function getOneRouterMetroOptions(options) {
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
112
|
+
const plugins = options.customTransformOptions?.vite?.babelConfig?.plugins;
|
|
113
|
+
if (!Array.isArray(plugins)) return void 0;
|
|
114
|
+
for (const plugin of plugins) {
|
|
115
|
+
if (Array.isArray(plugin) && typeof plugin[0] === "string" && plugin[0].includes("one-router-metro")) {
|
|
116
|
+
return plugin[1];
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
return void 0;
|
|
125
120
|
}
|
|
126
121
|
function getRemoveServerCodeRouterRoot(options) {
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
122
|
+
const plugins = options.customTransformOptions?.vite?.babelConfig?.plugins;
|
|
123
|
+
if (!Array.isArray(plugins)) return void 0;
|
|
124
|
+
for (const plugin of plugins) {
|
|
125
|
+
if (Array.isArray(plugin) && typeof plugin[0] === "string" && plugin[0].includes("remove-server-code")) {
|
|
126
|
+
return plugin[1]?.routerRoot ?? "app";
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
return void 0;
|
|
135
130
|
}
|
|
136
|
-
const importMetaEnvCache = /* @__PURE__ */new WeakMap();
|
|
131
|
+
const importMetaEnvCache = /* @__PURE__ */ new WeakMap();
|
|
137
132
|
function getImportMetaEnv(options) {
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
133
|
+
const plugins = options.customTransformOptions?.vite?.babelConfig?.plugins;
|
|
134
|
+
const platform = options.platform ?? "";
|
|
135
|
+
let byPlatform = Array.isArray(plugins) ? importMetaEnvCache.get(plugins) : void 0;
|
|
136
|
+
const cached = byPlatform?.get(platform);
|
|
137
|
+
if (cached) return cached;
|
|
138
|
+
let env = {};
|
|
139
|
+
if (Array.isArray(plugins)) {
|
|
140
|
+
for (const plugin of plugins) {
|
|
141
|
+
if (Array.isArray(plugin) && typeof plugin[0] === "string" && plugin[0].includes("import-meta-env-plugin")) {
|
|
142
|
+
const found = plugin[1]?.env;
|
|
143
|
+
if (found && typeof found === "object") env = found;
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
const merged = {
|
|
148
|
+
...env,
|
|
149
|
+
...(0, import_platformEnv.getPlatformEnv)((0, import_platformEnv.metroPlatformToViteEnvironment)(options.platform))
|
|
150
|
+
};
|
|
151
|
+
if (Array.isArray(plugins)) {
|
|
152
|
+
if (!byPlatform) {
|
|
153
|
+
byPlatform = /* @__PURE__ */ new Map();
|
|
154
|
+
importMetaEnvCache.set(plugins, byPlatform);
|
|
155
|
+
}
|
|
156
|
+
byPlatform.set(platform, merged);
|
|
157
|
+
}
|
|
158
|
+
return merged;
|
|
164
159
|
}
|
|
165
|
-
const PORTED_BABEL_PLUGINS = [
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
"
|
|
169
|
-
|
|
170
|
-
|
|
160
|
+
const PORTED_BABEL_PLUGINS = [
|
|
161
|
+
"import-meta-env-plugin",
|
|
162
|
+
"one-router-metro",
|
|
163
|
+
"remove-server-code",
|
|
164
|
+
"module-resolver",
|
|
165
|
+
"environment-guard",
|
|
166
|
+
"inline-one-server-url",
|
|
167
|
+
"react-native-worklets/plugin",
|
|
168
|
+
"react-native-reanimated/plugin",
|
|
169
|
+
"babel-plugin-react-compiler"
|
|
170
|
+
];
|
|
171
|
+
const unportedPluginCache = /* @__PURE__ */ new WeakMap();
|
|
172
|
+
const loadedNativeTransforms = /* @__PURE__ */ new Map();
|
|
171
173
|
function getNativeTransforms(options, projectRoot) {
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
174
|
+
const ids = options.customTransformOptions?.vite?.nativeTransformModules;
|
|
175
|
+
if (!Array.isArray(ids) || !ids.length) return [];
|
|
176
|
+
const req = (0, import_node_module.createRequire)(import_node_path.default.join(projectRoot, "package.json"));
|
|
177
|
+
return ids.map((id) => {
|
|
178
|
+
const cached = loadedNativeTransforms.get(id);
|
|
179
|
+
if (cached) return cached;
|
|
180
|
+
let mod;
|
|
181
|
+
try {
|
|
182
|
+
mod = req(id);
|
|
183
|
+
} catch (err) {
|
|
184
|
+
throw new Error(`[vxrn/metro] Could not load the native transform "${id}" from ${projectRoot}: ${err.message}`);
|
|
185
|
+
}
|
|
186
|
+
const fn = mod?.default ?? mod;
|
|
187
|
+
if (typeof fn !== "function") {
|
|
188
|
+
throw new Error(`[vxrn/metro] The native transform "${id}" must default-export a function (code, ctx) => string.`);
|
|
189
|
+
}
|
|
190
|
+
loadedNativeTransforms.set(id, fn);
|
|
191
|
+
return fn;
|
|
192
|
+
});
|
|
191
193
|
}
|
|
192
194
|
function isReactCompilerCandidate(filename) {
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
195
|
+
if (!/\.tsx?$/.test(filename)) return false;
|
|
196
|
+
if (filename.includes("node_modules")) return false;
|
|
197
|
+
if (filename.includes("+api.")) return false;
|
|
198
|
+
return true;
|
|
197
199
|
}
|
|
198
200
|
function hasBabelPlugin(options, id) {
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
201
|
+
const plugins = options.customTransformOptions?.vite?.babelConfig?.plugins;
|
|
202
|
+
if (!Array.isArray(plugins)) return false;
|
|
203
|
+
return plugins.some((plugin) => (Array.isArray(plugin) ? plugin[0] : plugin) === id);
|
|
202
204
|
}
|
|
203
205
|
function assertNoUnportedBabelPlugins(options) {
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
` + unported.map(id => ` - ${id}`).join("\n") + `
|
|
206
|
+
const plugins = options.customTransformOptions?.vite?.babelConfig?.plugins;
|
|
207
|
+
if (!Array.isArray(plugins)) return;
|
|
208
|
+
let unported = unportedPluginCache.get(plugins);
|
|
209
|
+
if (!unported) {
|
|
210
|
+
unported = [];
|
|
211
|
+
for (const plugin of plugins) {
|
|
212
|
+
const id = Array.isArray(plugin) ? plugin[0] : plugin;
|
|
213
|
+
if (typeof id !== "string") {
|
|
214
|
+
unported.push("(a function or object plugin, which cannot be ported)");
|
|
215
|
+
continue;
|
|
216
|
+
}
|
|
217
|
+
if (!PORTED_BABEL_PLUGINS.some((ported) => id.includes(ported))) {
|
|
218
|
+
unported.push(id);
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
unportedPluginCache.set(plugins, unported);
|
|
222
|
+
}
|
|
223
|
+
if (unported.length) {
|
|
224
|
+
throw new Error(`[vxrn/metro] the native transform path runs no babel, so these babel plugins would be silently ignored:
|
|
225
|
+
` + unported.map((id) => ` - ${id}`).join("\n") + `
|
|
224
226
|
|
|
225
227
|
Port each one to a native transform and list it in bundlerOptions.nativeTransformModules, remove it from bundlerOptions.babelConfigOverrides, or set bundlerOptions.nativeTransforms: false (or ONE_METRO_NATIVE_TRANSFORMS=0) to go back to the babel transformer.`);
|
|
226
|
-
|
|
228
|
+
}
|
|
227
229
|
}
|
|
228
230
|
function getModuleResolverAliases(options) {
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
231
|
+
const plugins = options.customTransformOptions?.vite?.babelConfig?.plugins;
|
|
232
|
+
if (!Array.isArray(plugins)) return void 0;
|
|
233
|
+
for (const plugin of plugins) {
|
|
234
|
+
if (Array.isArray(plugin) && typeof plugin[0] === "string" && plugin[0].includes("module-resolver")) {
|
|
235
|
+
const alias = plugin[1]?.alias;
|
|
236
|
+
if (alias && typeof alias === "object") return alias;
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
return void 0;
|
|
238
240
|
}
|
|
239
241
|
function resolveAliasSpecifier(specifier, filename, projectRoot, aliases) {
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
242
|
+
for (const [rawKey, value] of Object.entries(aliases)) {
|
|
243
|
+
let target;
|
|
244
|
+
if (rawKey.endsWith("$")) {
|
|
245
|
+
if (specifier === rawKey.slice(0, -1)) target = value;
|
|
246
|
+
} else if (specifier === rawKey || specifier.startsWith(`${rawKey}/`)) {
|
|
247
|
+
target = value + specifier.slice(rawKey.length);
|
|
248
|
+
}
|
|
249
|
+
if (target === void 0) continue;
|
|
250
|
+
const abs = import_node_path.default.resolve(projectRoot, target);
|
|
251
|
+
let rel = import_node_path.default.relative(import_node_path.default.dirname(filename), abs).split(import_node_path.default.sep).join("/");
|
|
252
|
+
if (!rel.startsWith(".")) rel = `./${rel}`;
|
|
253
|
+
return rel;
|
|
254
|
+
}
|
|
255
|
+
return void 0;
|
|
254
256
|
}
|
|
255
257
|
function applyModuleResolverAliases(code, filename, projectRoot, aliases) {
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
walk(parsed.program);
|
|
290
|
-
return changed ? ms.toString() : code;
|
|
258
|
+
const parsed = (0, import_oxc_parser.parseSync)(filename, code, { lang: langForFilename(filename) });
|
|
259
|
+
if (parsed?.errors?.length) {
|
|
260
|
+
throw new Error(`[vxrn/metro] Failed to parse ${filename} for alias resolution: ${parsed.errors[0].message}`);
|
|
261
|
+
}
|
|
262
|
+
if (!parsed?.program) return code;
|
|
263
|
+
const ms = new import_magic_string.default(code);
|
|
264
|
+
let changed = false;
|
|
265
|
+
function rewrite(sourceNode) {
|
|
266
|
+
if (sourceNode?.type !== "Literal" || typeof sourceNode.value !== "string") return;
|
|
267
|
+
const resolved = resolveAliasSpecifier(sourceNode.value, filename, projectRoot, aliases);
|
|
268
|
+
if (resolved === void 0) return;
|
|
269
|
+
ms.overwrite(sourceNode.start, sourceNode.end, JSON.stringify(resolved));
|
|
270
|
+
changed = true;
|
|
271
|
+
}
|
|
272
|
+
function walk(node) {
|
|
273
|
+
if (!node || typeof node !== "object") return;
|
|
274
|
+
if (node.type === "ImportDeclaration" || node.type === "ExportNamedDeclaration" || node.type === "ExportAllDeclaration" || node.type === "ImportExpression") {
|
|
275
|
+
rewrite(node.source);
|
|
276
|
+
} else if (node.type === "CallExpression" && node.callee?.type === "Identifier" && node.callee.name === "require") {
|
|
277
|
+
rewrite(node.arguments?.[0]);
|
|
278
|
+
}
|
|
279
|
+
for (const k of Object.keys(node)) {
|
|
280
|
+
if (k === "start" || k === "end" || k === "loc" || k === "range" || k === "parent" || k === "comments") continue;
|
|
281
|
+
const child = node[k];
|
|
282
|
+
if (Array.isArray(child)) {
|
|
283
|
+
for (const item of child) walk(item);
|
|
284
|
+
} else if (child && typeof child === "object") {
|
|
285
|
+
walk(child);
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
walk(parsed.program);
|
|
290
|
+
return changed ? ms.toString() : code;
|
|
291
291
|
}
|
|
292
292
|
function applyInlineEnvVars(code, filename, isProduction, env = {}) {
|
|
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
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
ms.overwrite(range.start, range.end, range.text);
|
|
430
|
-
}
|
|
431
|
-
for (const edit of edits) {
|
|
432
|
-
if (dead.some(d => edit.start >= d.start && edit.end <= d.end)) continue;
|
|
433
|
-
ms.overwrite(edit.start, edit.end, edit.text);
|
|
434
|
-
}
|
|
435
|
-
if (needsEnvImport) {
|
|
436
|
-
ms.prepend(`import { env as _$$_EXPO_ENV } from "expo/virtual/env";
|
|
437
|
-
`);
|
|
438
|
-
}
|
|
439
|
-
return ms.hasChanged() ? ms.toString() : code;
|
|
293
|
+
const parsed = (0, import_oxc_parser.parseSync)(filename, code, { lang: langForFilename(filename) });
|
|
294
|
+
if (parsed?.errors?.length) {
|
|
295
|
+
throw new Error(`[vxrn/metro] Failed to parse ${filename} for env inlining: ${parsed.errors[0].message}`);
|
|
296
|
+
}
|
|
297
|
+
if (!parsed?.program) return code;
|
|
298
|
+
const processPublicEnv = Object.fromEntries(Object.entries(process.env).filter(([key]) => key.startsWith("ONE_PUBLIC_") || key.startsWith("EXPO_PUBLIC_")));
|
|
299
|
+
const effectiveEnv = (0, import_publicEnv.withExpoPublicEnvAliases)({
|
|
300
|
+
...processPublicEnv,
|
|
301
|
+
...env
|
|
302
|
+
});
|
|
303
|
+
const ms = new import_magic_string.default(code);
|
|
304
|
+
const edits = [];
|
|
305
|
+
const known = /* @__PURE__ */ new Map();
|
|
306
|
+
function replace(node, value) {
|
|
307
|
+
const text = value === void 0 ? "undefined" : JSON.stringify(value);
|
|
308
|
+
edits.push({
|
|
309
|
+
start: node.start,
|
|
310
|
+
end: node.end,
|
|
311
|
+
text
|
|
312
|
+
});
|
|
313
|
+
known.set(node, value);
|
|
314
|
+
}
|
|
315
|
+
function keyOf(prop, computed) {
|
|
316
|
+
if (!computed && prop?.type === "Identifier") return prop.name;
|
|
317
|
+
if (prop?.type === "Literal" && typeof prop.value === "string") return prop.value;
|
|
318
|
+
return void 0;
|
|
319
|
+
}
|
|
320
|
+
function isImportMeta(node) {
|
|
321
|
+
return node?.type === "MetaProperty" && node.meta?.name === "import" && node.property?.name === "meta";
|
|
322
|
+
}
|
|
323
|
+
function walk(node, parent) {
|
|
324
|
+
if (!node || typeof node !== "object") return;
|
|
325
|
+
if (node.type === "MemberExpression" || node.type === "OptionalMemberExpression") {
|
|
326
|
+
const obj = node.object;
|
|
327
|
+
const isMember = obj?.type === "MemberExpression" || obj?.type === "OptionalMemberExpression";
|
|
328
|
+
const isProcessEnv = isMember && obj.object?.type === "Identifier" && obj.object.name === "process" && keyOf(obj.property, obj.computed) === "env";
|
|
329
|
+
const isAssignmentTarget = parent?.type === "AssignmentExpression" && parent.left === node;
|
|
330
|
+
const key = keyOf(node.property, node.computed);
|
|
331
|
+
if (isProcessEnv && !isAssignmentTarget && key === "ONE_SERVER_URL") {
|
|
332
|
+
replace(node, process.env.ONE_SERVER_URL || "");
|
|
333
|
+
return;
|
|
334
|
+
}
|
|
335
|
+
if (isProcessEnv && !isAssignmentTarget && (key?.startsWith("ONE_PUBLIC_") || key?.startsWith("EXPO_PUBLIC_"))) {
|
|
336
|
+
replace(node, effectiveEnv[key] ?? void 0);
|
|
337
|
+
return;
|
|
338
|
+
}
|
|
339
|
+
if (!isAssignmentTarget && isMember && isImportMeta(obj.object) && keyOf(obj.property, obj.computed) === "env" && key !== void 0) {
|
|
340
|
+
replace(node, effectiveEnv[key]);
|
|
341
|
+
return;
|
|
342
|
+
}
|
|
343
|
+
if (!isAssignmentTarget && isImportMeta(obj) && key === "env") {
|
|
344
|
+
edits.push({
|
|
345
|
+
start: node.start,
|
|
346
|
+
end: node.end,
|
|
347
|
+
text: JSON.stringify(effectiveEnv)
|
|
348
|
+
});
|
|
349
|
+
return;
|
|
350
|
+
}
|
|
351
|
+
if (isProcessEnv && !isAssignmentTarget && key !== void 0 && key in effectiveEnv) {
|
|
352
|
+
replace(node, effectiveEnv[key]);
|
|
353
|
+
return;
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
for (const k of Object.keys(node)) {
|
|
357
|
+
if (k === "start" || k === "end" || k === "loc" || k === "range" || k === "parent" || k === "comments") continue;
|
|
358
|
+
const child = node[k];
|
|
359
|
+
if (Array.isArray(child)) {
|
|
360
|
+
for (const item of child) walk(item, node);
|
|
361
|
+
} else if (child && typeof child === "object") {
|
|
362
|
+
walk(child, node);
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
walk(parsed.program, null);
|
|
367
|
+
function testValue(node) {
|
|
368
|
+
if (known.has(node)) return !!known.get(node);
|
|
369
|
+
if (node?.type === "UnaryExpression" && node.operator === "!") {
|
|
370
|
+
const inner = testValue(node.argument);
|
|
371
|
+
return inner === void 0 ? void 0 : !inner;
|
|
372
|
+
}
|
|
373
|
+
if (node?.type === "BinaryExpression" && (node.operator === "===" || node.operator === "!==")) {
|
|
374
|
+
const left = known.has(node.left) ? known.get(node.left) : void 0;
|
|
375
|
+
const right = node.right?.type === "Literal" ? node.right.value : void 0;
|
|
376
|
+
if (!known.has(node.left) || node.right?.type !== "Literal") return void 0;
|
|
377
|
+
return node.operator === "===" ? left === right : left !== right;
|
|
378
|
+
}
|
|
379
|
+
return void 0;
|
|
380
|
+
}
|
|
381
|
+
const dead = [];
|
|
382
|
+
(function foldWalk(node) {
|
|
383
|
+
if (!node || typeof node !== "object") return;
|
|
384
|
+
if (Array.isArray(node)) {
|
|
385
|
+
for (const child of node) foldWalk(child);
|
|
386
|
+
return;
|
|
387
|
+
}
|
|
388
|
+
if (node.type === "IfStatement" || node.type === "ConditionalExpression") {
|
|
389
|
+
const value = testValue(node.test);
|
|
390
|
+
if (value !== void 0) {
|
|
391
|
+
const kept = value ? node.consequent : node.alternate;
|
|
392
|
+
if (!kept) {
|
|
393
|
+
dead.push({
|
|
394
|
+
start: node.start,
|
|
395
|
+
end: node.end,
|
|
396
|
+
text: ";"
|
|
397
|
+
});
|
|
398
|
+
return;
|
|
399
|
+
}
|
|
400
|
+
dead.push({
|
|
401
|
+
start: node.start,
|
|
402
|
+
end: kept.start,
|
|
403
|
+
text: ""
|
|
404
|
+
});
|
|
405
|
+
if (kept.end < node.end) {
|
|
406
|
+
dead.push({
|
|
407
|
+
start: kept.end,
|
|
408
|
+
end: node.end,
|
|
409
|
+
text: ""
|
|
410
|
+
});
|
|
411
|
+
}
|
|
412
|
+
foldWalk(kept);
|
|
413
|
+
return;
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
for (const k of Object.keys(node)) {
|
|
417
|
+
if (k === "start" || k === "end" || k === "loc" || k === "range" || k === "parent" || k === "comments") continue;
|
|
418
|
+
foldWalk(node[k]);
|
|
419
|
+
}
|
|
420
|
+
})(parsed.program);
|
|
421
|
+
for (const range of dead) {
|
|
422
|
+
ms.overwrite(range.start, range.end, range.text);
|
|
423
|
+
}
|
|
424
|
+
for (const edit of edits) {
|
|
425
|
+
if (dead.some((d) => edit.start >= d.start && edit.end <= d.end)) continue;
|
|
426
|
+
ms.overwrite(edit.start, edit.end, edit.text);
|
|
427
|
+
}
|
|
428
|
+
return ms.hasChanged() ? ms.toString() : code;
|
|
440
429
|
}
|
|
441
|
-
const GUARD_SPECIFIERS = /* @__PURE__ */new Set([
|
|
430
|
+
const GUARD_SPECIFIERS = /* @__PURE__ */ new Set([
|
|
431
|
+
"server-only",
|
|
432
|
+
"client-only",
|
|
433
|
+
"web-only"
|
|
434
|
+
]);
|
|
442
435
|
function applyEnvironmentGuard(code, filename) {
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
}
|
|
464
|
-
return changed ? ms.toString() : code;
|
|
436
|
+
const parsed = (0, import_oxc_parser.parseSync)(filename, code, { lang: langForFilename(filename) });
|
|
437
|
+
if (parsed?.errors?.length) {
|
|
438
|
+
throw new Error(`[vxrn/metro] Failed to parse ${filename} for environment guards: ${parsed.errors[0].message}`);
|
|
439
|
+
}
|
|
440
|
+
const body = parsed?.program?.body;
|
|
441
|
+
if (!body) return code;
|
|
442
|
+
const ms = new import_magic_string.default(code);
|
|
443
|
+
let changed = false;
|
|
444
|
+
for (const node of body) {
|
|
445
|
+
if (node.type !== "ImportDeclaration") continue;
|
|
446
|
+
const source = node.source?.value;
|
|
447
|
+
if (source === "native-only") {
|
|
448
|
+
ms.remove(node.start, node.end);
|
|
449
|
+
changed = true;
|
|
450
|
+
} else if (GUARD_SPECIFIERS.has(source)) {
|
|
451
|
+
ms.overwrite(node.start, node.end, `throw new Error(${JSON.stringify(`${source} cannot be imported in a native environment`)});`);
|
|
452
|
+
changed = true;
|
|
453
|
+
}
|
|
454
|
+
}
|
|
455
|
+
return changed ? ms.toString() : code;
|
|
465
456
|
}
|
|
466
457
|
function applyOneRouterMetro(code, filename, options) {
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
if (isMetroEntry && options.ONE_SETUP_FILE_NATIVE) {
|
|
524
|
-
const stmt = `
|
|
458
|
+
const isMetroEntry = filename.endsWith("metro-entry.js");
|
|
459
|
+
const isEntryCtx = filename.endsWith("metro-entry-ctx.js");
|
|
460
|
+
if (!isMetroEntry && !isEntryCtx) return code;
|
|
461
|
+
const parsed = (0, import_oxc_parser.parseSync)(filename, code, { lang: langForFilename(filename) });
|
|
462
|
+
if (parsed?.errors?.length) {
|
|
463
|
+
throw new Error(`[vxrn/metro] Failed to parse ${filename} for one-router-metro: ${parsed.errors[0].message}`);
|
|
464
|
+
}
|
|
465
|
+
if (!parsed?.program) return code;
|
|
466
|
+
const ms = new import_magic_string.default(code);
|
|
467
|
+
let lastImportEnd = -1;
|
|
468
|
+
function replacementFor(key) {
|
|
469
|
+
if (key.startsWith("ONE_ROUTER_APP_ROOT_RELATIVE_TO_ENTRY")) {
|
|
470
|
+
return JSON.stringify(options.ONE_ROUTER_APP_ROOT_RELATIVE_TO_ENTRY);
|
|
471
|
+
}
|
|
472
|
+
if (key.startsWith("ONE_ROUTER_ROOT_FOLDER_NAME")) {
|
|
473
|
+
return JSON.stringify(options.ONE_ROUTER_ROOT_FOLDER_NAME);
|
|
474
|
+
}
|
|
475
|
+
if (key.startsWith("ONE_ROUTER_REQUIRE_CONTEXT_REGEX")) {
|
|
476
|
+
return `/${options.ONE_ROUTER_REQUIRE_CONTEXT_REGEX_STRING}/`;
|
|
477
|
+
}
|
|
478
|
+
if (key === "ONE_ROUTER_LINKING_CONFIG") {
|
|
479
|
+
return isMetroEntry ? JSON.stringify(options.ONE_ROUTER_LINKING_CONFIG ?? null) : void 0;
|
|
480
|
+
}
|
|
481
|
+
if (key === "ONE_SETUP_FILE_NATIVE") {
|
|
482
|
+
return options.ONE_SETUP_FILE_NATIVE ? JSON.stringify(options.ONE_SETUP_FILE_NATIVE) : "undefined";
|
|
483
|
+
}
|
|
484
|
+
return void 0;
|
|
485
|
+
}
|
|
486
|
+
function walk(node, parent) {
|
|
487
|
+
if (!node || typeof node !== "object") return;
|
|
488
|
+
if (node.type === "ImportDeclaration" && parent === parsed.program) {
|
|
489
|
+
lastImportEnd = Math.max(lastImportEnd, node.end);
|
|
490
|
+
}
|
|
491
|
+
if (node.type === "MemberExpression" && node.object?.type === "MemberExpression" && !node.object.computed && node.object.object?.type === "Identifier" && node.object.object.name === "process" && node.object.property?.type === "Identifier" && node.object.property.name === "env") {
|
|
492
|
+
const key = node.computed ? node.property?.type === "Literal" && typeof node.property.value === "string" ? node.property.value : void 0 : node.property?.type === "Identifier" ? node.property.name : void 0;
|
|
493
|
+
const isAssignTarget = parent?.type === "AssignmentExpression" && parent.left === node;
|
|
494
|
+
if (key && !isAssignTarget) {
|
|
495
|
+
const replacement = replacementFor(key);
|
|
496
|
+
if (replacement !== void 0) {
|
|
497
|
+
ms.overwrite(node.start, node.end, replacement);
|
|
498
|
+
}
|
|
499
|
+
}
|
|
500
|
+
}
|
|
501
|
+
for (const k of Object.keys(node)) {
|
|
502
|
+
if (k === "start" || k === "end" || k === "loc" || k === "range" || k === "parent" || k === "comments") continue;
|
|
503
|
+
const child = node[k];
|
|
504
|
+
if (Array.isArray(child)) {
|
|
505
|
+
for (const item of child) walk(item, node);
|
|
506
|
+
} else if (child && typeof child === "object") {
|
|
507
|
+
walk(child, node);
|
|
508
|
+
}
|
|
509
|
+
}
|
|
510
|
+
}
|
|
511
|
+
walk(parsed.program, parsed.program);
|
|
512
|
+
if (isMetroEntry && options.ONE_SETUP_FILE_NATIVE) {
|
|
513
|
+
const stmt = `
|
|
525
514
|
import ${JSON.stringify(options.ONE_SETUP_FILE_NATIVE)};`;
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
515
|
+
if (lastImportEnd >= 0) {
|
|
516
|
+
ms.appendRight(lastImportEnd, stmt);
|
|
517
|
+
} else {
|
|
518
|
+
ms.prepend(`${stmt}
|
|
530
519
|
`);
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
520
|
+
}
|
|
521
|
+
}
|
|
522
|
+
return ms.toString();
|
|
534
523
|
}
|
|
535
524
|
function collectPatternNames(pattern, names) {
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
525
|
+
if (!pattern) return;
|
|
526
|
+
if (pattern.type === "Identifier") {
|
|
527
|
+
names.add(pattern.name);
|
|
528
|
+
} else if (pattern.type === "AssignmentPattern") {
|
|
529
|
+
collectPatternNames(pattern.left, names);
|
|
530
|
+
} else if (pattern.type === "ObjectPattern") {
|
|
531
|
+
for (const prop of pattern.properties || []) {
|
|
532
|
+
if (prop.type === "Property") collectPatternNames(prop.value, names);
|
|
533
|
+
else if (prop.type === "RestElement") collectPatternNames(prop.argument, names);
|
|
534
|
+
}
|
|
535
|
+
} else if (pattern.type === "ArrayPattern") {
|
|
536
|
+
for (const elem of pattern.elements || []) {
|
|
537
|
+
if (elem) collectPatternNames(elem, names);
|
|
538
|
+
}
|
|
539
|
+
} else if (pattern.type === "RestElement") {
|
|
540
|
+
collectPatternNames(pattern.argument, names);
|
|
541
|
+
}
|
|
552
542
|
}
|
|
553
543
|
function collectHoistedBindings(node, names) {
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
544
|
+
function traverse(n) {
|
|
545
|
+
if (!n || typeof n !== "object") return;
|
|
546
|
+
if (n === node) {} else if (n.type === "FunctionDeclaration" || n.type === "FunctionExpression" || n.type === "ArrowFunctionExpression") {
|
|
547
|
+
if (n.type === "FunctionDeclaration" && n.id?.name) {
|
|
548
|
+
names.add(n.id.name);
|
|
549
|
+
}
|
|
550
|
+
return;
|
|
551
|
+
}
|
|
552
|
+
if (n.type === "VariableDeclaration" && n.kind === "var") {
|
|
553
|
+
for (const decl of n.declarations || []) {
|
|
554
|
+
collectPatternNames(decl.id, names);
|
|
555
|
+
}
|
|
556
|
+
}
|
|
557
|
+
for (const key of Object.keys(n)) {
|
|
558
|
+
if (key === "start" || key === "end" || key === "loc" || key === "range" || key === "parent" || key === "comments") continue;
|
|
559
|
+
const child = n[key];
|
|
560
|
+
if (Array.isArray(child)) {
|
|
561
|
+
for (const item of child) traverse(item);
|
|
562
|
+
} else if (child && typeof child === "object") {
|
|
563
|
+
traverse(child);
|
|
564
|
+
}
|
|
565
|
+
}
|
|
566
|
+
}
|
|
567
|
+
traverse(node);
|
|
578
568
|
}
|
|
579
569
|
function collectBlockBindings(statements, names) {
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
}
|
|
594
|
-
class ScopeTracker {
|
|
595
|
-
stack = [/* @__PURE__ */new Set()];
|
|
596
|
-
enter(initialBindings) {
|
|
597
|
-
this.stack.push(new Set(initialBindings));
|
|
598
|
-
}
|
|
599
|
-
exit() {
|
|
600
|
-
if (this.stack.length > 1) {
|
|
601
|
-
this.stack.pop();
|
|
602
|
-
}
|
|
603
|
-
}
|
|
604
|
-
add(name) {
|
|
605
|
-
this.stack[this.stack.length - 1].add(name);
|
|
606
|
-
}
|
|
607
|
-
currentScope() {
|
|
608
|
-
return this.stack[this.stack.length - 1];
|
|
609
|
-
}
|
|
610
|
-
addPattern(pattern) {
|
|
611
|
-
collectPatternNames(pattern, this.currentScope());
|
|
612
|
-
}
|
|
613
|
-
isShadowed(name) {
|
|
614
|
-
for (let i = this.stack.length - 1; i >= 0; i--) {
|
|
615
|
-
if (this.stack[i].has(name)) return true;
|
|
616
|
-
}
|
|
617
|
-
return false;
|
|
618
|
-
}
|
|
570
|
+
if (!Array.isArray(statements)) return;
|
|
571
|
+
for (const stmt of statements) {
|
|
572
|
+
if (!stmt) continue;
|
|
573
|
+
if (stmt.type === "VariableDeclaration" && stmt.kind !== "var") {
|
|
574
|
+
for (const decl of stmt.declarations || []) {
|
|
575
|
+
collectPatternNames(decl.id, names);
|
|
576
|
+
}
|
|
577
|
+
} else if (stmt.type === "ClassDeclaration" && stmt.id?.name) {
|
|
578
|
+
names.add(stmt.id.name);
|
|
579
|
+
} else if (stmt.type === "FunctionDeclaration" && stmt.id?.name) {
|
|
580
|
+
names.add(stmt.id.name);
|
|
581
|
+
}
|
|
582
|
+
}
|
|
619
583
|
}
|
|
584
|
+
var ScopeTracker = class {
|
|
585
|
+
stack = [/* @__PURE__ */ new Set()];
|
|
586
|
+
enter(initialBindings) {
|
|
587
|
+
this.stack.push(new Set(initialBindings));
|
|
588
|
+
}
|
|
589
|
+
exit() {
|
|
590
|
+
if (this.stack.length > 1) {
|
|
591
|
+
this.stack.pop();
|
|
592
|
+
}
|
|
593
|
+
}
|
|
594
|
+
add(name) {
|
|
595
|
+
this.stack[this.stack.length - 1].add(name);
|
|
596
|
+
}
|
|
597
|
+
currentScope() {
|
|
598
|
+
return this.stack[this.stack.length - 1];
|
|
599
|
+
}
|
|
600
|
+
addPattern(pattern) {
|
|
601
|
+
collectPatternNames(pattern, this.currentScope());
|
|
602
|
+
}
|
|
603
|
+
isShadowed(name) {
|
|
604
|
+
for (let i = this.stack.length - 1; i >= 0; i--) {
|
|
605
|
+
if (this.stack[i].has(name)) return true;
|
|
606
|
+
}
|
|
607
|
+
return false;
|
|
608
|
+
}
|
|
609
|
+
};
|
|
620
610
|
function getCacheKey(config = {}, opts) {
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
611
|
+
const hash = import_node_crypto.default.createHash("sha256");
|
|
612
|
+
hash.update("metroNativeWorker");
|
|
613
|
+
hash.update(WORKER_CACHE_KEY_VERSION);
|
|
614
|
+
if (config.globalPrefix) {
|
|
615
|
+
hash.update(config.globalPrefix);
|
|
616
|
+
}
|
|
617
|
+
if (config.unstable_dependencyMapReservedName) {
|
|
618
|
+
hash.update(config.unstable_dependencyMapReservedName);
|
|
619
|
+
}
|
|
620
|
+
if (config.minifierPath) {
|
|
621
|
+
hash.update(config.minifierPath);
|
|
622
|
+
}
|
|
623
|
+
if (opts?.projectRoot) {
|
|
624
|
+
hash.update(opts.projectRoot);
|
|
625
|
+
}
|
|
626
|
+
return hash.digest("hex");
|
|
637
627
|
}
|
|
638
628
|
function convertSourceMapToMetroRawMappings(composedMap) {
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
629
|
+
if (!composedMap) return [];
|
|
630
|
+
const tracer = new import_trace_mapping.TraceMap(composedMap);
|
|
631
|
+
const rawMappings = [];
|
|
632
|
+
(0, import_trace_mapping.eachMapping)(tracer, (m) => {
|
|
633
|
+
if (m.originalLine == null) {
|
|
634
|
+
rawMappings.push([m.generatedLine, m.generatedColumn]);
|
|
635
|
+
} else if (m.name == null) {
|
|
636
|
+
rawMappings.push([
|
|
637
|
+
m.generatedLine,
|
|
638
|
+
m.generatedColumn,
|
|
639
|
+
m.originalLine,
|
|
640
|
+
m.originalColumn
|
|
641
|
+
]);
|
|
642
|
+
} else {
|
|
643
|
+
rawMappings.push([
|
|
644
|
+
m.generatedLine,
|
|
645
|
+
m.generatedColumn,
|
|
646
|
+
m.originalLine,
|
|
647
|
+
m.originalColumn,
|
|
648
|
+
m.name
|
|
649
|
+
]);
|
|
650
|
+
}
|
|
651
|
+
});
|
|
652
|
+
rawMappings.sort((a, b) => {
|
|
653
|
+
if (a[0] !== b[0]) return a[0] - b[0];
|
|
654
|
+
return a[1] - b[1];
|
|
655
|
+
});
|
|
656
|
+
const deduped = [];
|
|
657
|
+
for (const mapping of rawMappings) {
|
|
658
|
+
const prev = deduped[deduped.length - 1];
|
|
659
|
+
if (prev && prev[0] === mapping[0] && prev[1] === mapping[1]) {
|
|
660
|
+
continue;
|
|
661
|
+
}
|
|
662
|
+
deduped.push(mapping);
|
|
663
|
+
}
|
|
664
|
+
return deduped;
|
|
664
665
|
}
|
|
665
666
|
function countLinesAndTerminateMap(code, map = []) {
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
667
|
+
const NEWLINE = /\r\n?|\n|\u2028|\u2029/g;
|
|
668
|
+
let lineCount = 1;
|
|
669
|
+
let lastLineStart = 0;
|
|
670
|
+
for (const match of code.matchAll(NEWLINE)) {
|
|
671
|
+
lineCount++;
|
|
672
|
+
lastLineStart = match.index + match[0].length;
|
|
673
|
+
}
|
|
674
|
+
const lastLineLength = code.length - lastLineStart;
|
|
675
|
+
const lastLineIndex1Based = lineCount;
|
|
676
|
+
const lastLineNextColumn0Based = lastLineLength;
|
|
677
|
+
const lastMapping = map[map.length - 1];
|
|
678
|
+
const terminatingMapping = [lastLineIndex1Based, lastLineNextColumn0Based];
|
|
679
|
+
if (!lastMapping || lastMapping[0] !== terminatingMapping[0] || lastMapping[1] !== terminatingMapping[1]) {
|
|
680
|
+
return {
|
|
681
|
+
lineCount,
|
|
682
|
+
map: map.concat([terminatingMapping])
|
|
683
|
+
};
|
|
684
|
+
}
|
|
685
|
+
return {
|
|
686
|
+
lineCount,
|
|
687
|
+
map: [...map]
|
|
688
|
+
};
|
|
688
689
|
}
|
|
689
690
|
function wrapJson(source, options) {
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
691
|
+
const globalPrefix = options?.globalPrefix || "";
|
|
692
|
+
const factory = [
|
|
693
|
+
"function (global, require, _importDefaultUnused, _importAllUnused, module, exports, _dependencyMapUnused) {",
|
|
694
|
+
` module.exports = ${source};`,
|
|
695
|
+
"}"
|
|
696
|
+
].join("\n");
|
|
697
|
+
if (options?.moduleId !== void 0) {
|
|
698
|
+
const depIds = options.dependencyIds ? JSON.stringify(options.dependencyIds) : "[]";
|
|
699
|
+
return `${globalPrefix}__d(${factory}, ${JSON.stringify(options.moduleId)}, ${depIds});`;
|
|
700
|
+
}
|
|
701
|
+
return `${globalPrefix}__d(${factory});`;
|
|
697
702
|
}
|
|
698
703
|
function wrapModule(code, options) {
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
704
|
+
const globalPrefix = options?.globalPrefix || "";
|
|
705
|
+
const depMap = options?.dependencyMapName || "_dependencyMap";
|
|
706
|
+
const header = `function (global, _$$_REQUIRE, _$$_IMPORT_DEFAULT, _$$_IMPORT_ALL, module, exports, ${depMap}) {`;
|
|
707
|
+
const requireAlias = options?.requireAlias !== false ? "var require = _$$_REQUIRE;\n" : "";
|
|
708
|
+
const footer = `}`;
|
|
709
|
+
if (options?.moduleId !== void 0) {
|
|
710
|
+
const depIds = options.dependencyIds ? JSON.stringify(options.dependencyIds) : "[]";
|
|
711
|
+
return `${globalPrefix}__d(${header}
|
|
707
712
|
${requireAlias}${code}
|
|
708
713
|
${footer}, ${JSON.stringify(options.moduleId)}, ${depIds});`;
|
|
709
|
-
|
|
710
|
-
|
|
714
|
+
}
|
|
715
|
+
return `${globalPrefix}__d(${header}
|
|
711
716
|
${requireAlias}${code}
|
|
712
717
|
${footer});`;
|
|
713
718
|
}
|
|
714
719
|
function getDependencyKey(name, isESM, asyncType = null, contextParams) {
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
720
|
+
let key = `${name}\0${isESM ? "import" : "require"}`;
|
|
721
|
+
if (asyncType != null) {
|
|
722
|
+
key += `\0${asyncType}`;
|
|
723
|
+
}
|
|
724
|
+
if (contextParams) {
|
|
725
|
+
key += [
|
|
726
|
+
"",
|
|
727
|
+
"context",
|
|
728
|
+
String(contextParams.recursive),
|
|
729
|
+
String(contextParams.filter.pattern),
|
|
730
|
+
String(contextParams.filter.flags),
|
|
731
|
+
contextParams.mode
|
|
732
|
+
].join("\0");
|
|
733
|
+
}
|
|
734
|
+
return key;
|
|
723
735
|
}
|
|
724
736
|
function rewriteDependencyCalls(code, dependencies, depMapName = "_dependencyMap", filename = "module.js", asyncRequirePath = "metro-runtime/src/modules/asyncRequire") {
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
map,
|
|
855
|
-
toString() {
|
|
856
|
-
return resultString;
|
|
857
|
-
}
|
|
858
|
-
};
|
|
737
|
+
const ms = new import_magic_string.default(code);
|
|
738
|
+
const emptyResult = {
|
|
739
|
+
code,
|
|
740
|
+
map: ms.generateMap({
|
|
741
|
+
source: filename,
|
|
742
|
+
hires: true,
|
|
743
|
+
includeContent: true
|
|
744
|
+
}),
|
|
745
|
+
toString() {
|
|
746
|
+
return code;
|
|
747
|
+
}
|
|
748
|
+
};
|
|
749
|
+
if (dependencies.length === 0) return emptyResult;
|
|
750
|
+
let parsed;
|
|
751
|
+
try {
|
|
752
|
+
parsed = (0, import_oxc_parser.parseSync)(filename, code, { lang: langForFilename(filename) });
|
|
753
|
+
} catch (err) {
|
|
754
|
+
throw new Error(`[vxrn/metro] Failed to parse ${filename} for dependency rewriting: ${err.message || err}`);
|
|
755
|
+
}
|
|
756
|
+
if (parsed?.errors?.length) {
|
|
757
|
+
throw new Error(`[vxrn/metro] Failed to parse ${filename} for dependency rewriting: ${parsed.errors[0].message}`);
|
|
758
|
+
}
|
|
759
|
+
if (!parsed?.program) return emptyResult;
|
|
760
|
+
const contextLiteralBindings = collectModuleLiteralBindings(parsed.program);
|
|
761
|
+
const scopeTracker = new ScopeTracker();
|
|
762
|
+
collectHoistedBindings(parsed.program, scopeTracker.currentScope());
|
|
763
|
+
collectBlockBindings(parsed.program.body, scopeTracker.currentScope());
|
|
764
|
+
for (const stmt of parsed.program.body || []) {
|
|
765
|
+
if (stmt.type === "ImportDeclaration") {
|
|
766
|
+
for (const spec of stmt.specifiers || []) {
|
|
767
|
+
if (spec.local?.name) {
|
|
768
|
+
scopeTracker.add(spec.local.name);
|
|
769
|
+
}
|
|
770
|
+
}
|
|
771
|
+
}
|
|
772
|
+
}
|
|
773
|
+
function walk(node) {
|
|
774
|
+
if (!node || typeof node !== "object") return;
|
|
775
|
+
let pushedScope = false;
|
|
776
|
+
if (node.type === "FunctionDeclaration" || node.type === "FunctionExpression" || node.type === "ArrowFunctionExpression") {
|
|
777
|
+
scopeTracker.enter();
|
|
778
|
+
pushedScope = true;
|
|
779
|
+
for (const param of node.params || []) {
|
|
780
|
+
scopeTracker.addPattern(param);
|
|
781
|
+
}
|
|
782
|
+
if (node.type === "FunctionExpression" && node.id?.name) {
|
|
783
|
+
scopeTracker.add(node.id.name);
|
|
784
|
+
}
|
|
785
|
+
if (node.body) {
|
|
786
|
+
collectHoistedBindings(node.body, scopeTracker.currentScope());
|
|
787
|
+
}
|
|
788
|
+
} else if (node.type === "BlockStatement") {
|
|
789
|
+
scopeTracker.enter();
|
|
790
|
+
pushedScope = true;
|
|
791
|
+
collectBlockBindings(node.body, scopeTracker.currentScope());
|
|
792
|
+
} else if (node.type === "CatchClause") {
|
|
793
|
+
scopeTracker.enter();
|
|
794
|
+
pushedScope = true;
|
|
795
|
+
if (node.param) {
|
|
796
|
+
scopeTracker.addPattern(node.param);
|
|
797
|
+
}
|
|
798
|
+
} else if (node.type === "ForStatement" || node.type === "ForInStatement" || node.type === "ForOfStatement") {
|
|
799
|
+
const decl = node.type === "ForStatement" ? node.init : node.left;
|
|
800
|
+
if (decl?.type === "VariableDeclaration" && decl.kind !== "var") {
|
|
801
|
+
scopeTracker.enter();
|
|
802
|
+
pushedScope = true;
|
|
803
|
+
for (const d of decl.declarations || []) {
|
|
804
|
+
scopeTracker.addPattern(d.id);
|
|
805
|
+
}
|
|
806
|
+
}
|
|
807
|
+
}
|
|
808
|
+
if (node.type === "ImportExpression" && node.source?.type === "Literal" && typeof node.source.value === "string") {
|
|
809
|
+
const depName = node.source.value;
|
|
810
|
+
const depKey = getDependencyKey(depName, true, "async");
|
|
811
|
+
const dep = dependencies.find((d) => d.data.key === depKey) || dependencies.find((d) => d.name === depName && d.data.asyncType === "async");
|
|
812
|
+
const asyncKey = getDependencyKey(asyncRequirePath, false, null);
|
|
813
|
+
const asyncDep = dependencies.find((d) => d.data.key === asyncKey) || dependencies.find((d) => d.name === asyncRequirePath && d.data.asyncType == null);
|
|
814
|
+
if (dep && asyncDep) {
|
|
815
|
+
const depIndex = dep.data.index ?? dependencies.indexOf(dep);
|
|
816
|
+
const asyncIndex = asyncDep.data.index ?? dependencies.indexOf(asyncDep);
|
|
817
|
+
ms.overwrite(node.start, node.end, `require(${depMapName}[${asyncIndex}], ${JSON.stringify(asyncRequirePath)})(${depMapName}[${depIndex}], ${depMapName}.paths, ${JSON.stringify(depName)})`);
|
|
818
|
+
}
|
|
819
|
+
} else if (node.type === "CallExpression" && node.callee?.type === "Identifier" && node.callee.name === "require" && !scopeTracker.isShadowed("require") && node.arguments?.length >= 1) {
|
|
820
|
+
const arg = node.arguments[0];
|
|
821
|
+
if (arg.type === "Literal" && typeof arg.value === "string") {
|
|
822
|
+
const depKey = getDependencyKey(arg.value, false, null);
|
|
823
|
+
const dep = dependencies.find((d) => d.data.key === depKey) || dependencies.find((d) => d.name === arg.value && d.data.asyncType == null);
|
|
824
|
+
if (dep) {
|
|
825
|
+
const index = dep.data.index ?? dependencies.indexOf(dep);
|
|
826
|
+
ms.overwrite(arg.start, arg.end, `${depMapName}[${index}], ${JSON.stringify(arg.value)}`);
|
|
827
|
+
}
|
|
828
|
+
}
|
|
829
|
+
} else if (node.type === "CallExpression" && node.callee?.type === "MemberExpression" && !node.callee.computed && node.callee.object?.type === "Identifier" && node.callee.object.name === "require" && node.callee.property?.type === "Identifier" && node.callee.property.name === "context" && !scopeTracker.isShadowed("require") && node.arguments?.length >= 1) {
|
|
830
|
+
const arg = node.arguments[0]?.type === "Identifier" ? contextLiteralBindings.get(node.arguments[0].name) : node.arguments[0];
|
|
831
|
+
if (arg?.type === "Literal" && typeof arg.value === "string") {
|
|
832
|
+
const dep = dependencies.find((d) => d.name === arg.value && d.data.contextParams != null);
|
|
833
|
+
if (dep) {
|
|
834
|
+
const index = dep.data.index ?? dependencies.indexOf(dep);
|
|
835
|
+
ms.overwrite(node.start, node.end, `require(${depMapName}[${index}], ${JSON.stringify(arg.value)})`);
|
|
836
|
+
}
|
|
837
|
+
}
|
|
838
|
+
}
|
|
839
|
+
for (const key of Object.keys(node)) {
|
|
840
|
+
if (key === "start" || key === "end" || key === "loc" || key === "range" || key === "parent" || key === "comments") continue;
|
|
841
|
+
const child = node[key];
|
|
842
|
+
if (Array.isArray(child)) {
|
|
843
|
+
for (const item of child) walk(item);
|
|
844
|
+
} else if (child && typeof child === "object") {
|
|
845
|
+
walk(child);
|
|
846
|
+
}
|
|
847
|
+
}
|
|
848
|
+
if (pushedScope) {
|
|
849
|
+
scopeTracker.exit();
|
|
850
|
+
}
|
|
851
|
+
}
|
|
852
|
+
walk(parsed.program);
|
|
853
|
+
const resultString = ms.toString();
|
|
854
|
+
const map = ms.generateMap({
|
|
855
|
+
source: filename,
|
|
856
|
+
hires: true,
|
|
857
|
+
includeContent: true
|
|
858
|
+
});
|
|
859
|
+
return {
|
|
860
|
+
code: resultString,
|
|
861
|
+
map,
|
|
862
|
+
toString() {
|
|
863
|
+
return resultString;
|
|
864
|
+
}
|
|
865
|
+
};
|
|
859
866
|
}
|
|
860
867
|
function extractDependencies(code, filename, options) {
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
walk(child);
|
|
1083
|
-
}
|
|
1084
|
-
}
|
|
1085
|
-
ancestors.pop();
|
|
1086
|
-
if (pushedScope) {
|
|
1087
|
-
scopeTracker.exit();
|
|
1088
|
-
}
|
|
1089
|
-
}
|
|
1090
|
-
walk(parseResult.program);
|
|
1091
|
-
return Array.from(depMap.values());
|
|
868
|
+
const asyncRequirePath = options?.asyncRequireModulePath || "metro-runtime/src/modules/asyncRequire";
|
|
869
|
+
const allowOptionalDependencies = options?.allowOptionalDependencies;
|
|
870
|
+
const lineOffsets = [0];
|
|
871
|
+
for (let i = 0; i < code.length; i++) {
|
|
872
|
+
if (code[i] === "\n") {
|
|
873
|
+
lineOffsets.push(i + 1);
|
|
874
|
+
}
|
|
875
|
+
}
|
|
876
|
+
function offsetToLoc(pos) {
|
|
877
|
+
let low = 0;
|
|
878
|
+
let high = lineOffsets.length - 1;
|
|
879
|
+
while (low <= high) {
|
|
880
|
+
const mid = low + high >> 1;
|
|
881
|
+
if (lineOffsets[mid] <= pos) {
|
|
882
|
+
low = mid + 1;
|
|
883
|
+
} else {
|
|
884
|
+
high = mid - 1;
|
|
885
|
+
}
|
|
886
|
+
}
|
|
887
|
+
const line = high + 1;
|
|
888
|
+
const column = pos - lineOffsets[high];
|
|
889
|
+
return {
|
|
890
|
+
line,
|
|
891
|
+
column
|
|
892
|
+
};
|
|
893
|
+
}
|
|
894
|
+
let parseResult;
|
|
895
|
+
try {
|
|
896
|
+
parseResult = (0, import_oxc_parser.parseSync)(filename, code, { lang: langForFilename(filename) });
|
|
897
|
+
} catch (err) {
|
|
898
|
+
throw new Error(`[vxrn/metro] Failed to parse ${filename} for dependency extraction: ${err.message || err}`);
|
|
899
|
+
}
|
|
900
|
+
if (parseResult?.errors?.length) {
|
|
901
|
+
throw new Error(`[vxrn/metro] Failed to parse ${filename} for dependency extraction: ${parseResult.errors[0].message}`);
|
|
902
|
+
}
|
|
903
|
+
if (!parseResult?.program) {
|
|
904
|
+
return [];
|
|
905
|
+
}
|
|
906
|
+
const depMap = /* @__PURE__ */ new Map();
|
|
907
|
+
function addDep(name, isESM, asyncType, start, end, contextParams, isOptional) {
|
|
908
|
+
const key = getDependencyKey(name, isESM, asyncType, contextParams);
|
|
909
|
+
let entry = depMap.get(key);
|
|
910
|
+
const loc = {
|
|
911
|
+
start: offsetToLoc(start),
|
|
912
|
+
end: offsetToLoc(end)
|
|
913
|
+
};
|
|
914
|
+
if (!entry) {
|
|
915
|
+
entry = {
|
|
916
|
+
name,
|
|
917
|
+
data: {
|
|
918
|
+
key,
|
|
919
|
+
asyncType,
|
|
920
|
+
locs: [loc],
|
|
921
|
+
isESMImportAtSource: isESM,
|
|
922
|
+
isESMImport: isESM,
|
|
923
|
+
index: depMap.size,
|
|
924
|
+
...contextParams ? { contextParams } : {},
|
|
925
|
+
...isOptional ? { isOptional: true } : {}
|
|
926
|
+
}
|
|
927
|
+
};
|
|
928
|
+
depMap.set(key, entry);
|
|
929
|
+
} else {
|
|
930
|
+
entry.data.locs.push(loc);
|
|
931
|
+
}
|
|
932
|
+
}
|
|
933
|
+
const moduleConsts = collectModuleLiteralBindings(parseResult.program);
|
|
934
|
+
function resolveConst(node) {
|
|
935
|
+
if (node?.type === "Identifier") return moduleConsts.get(node.name);
|
|
936
|
+
return node;
|
|
937
|
+
}
|
|
938
|
+
const ancestors = [];
|
|
939
|
+
function isOptionalHere(name) {
|
|
940
|
+
if (!allowOptionalDependencies) return false;
|
|
941
|
+
if (Array.isArray(allowOptionalDependencies.exclude)) {
|
|
942
|
+
if (allowOptionalDependencies.exclude.includes(name)) return false;
|
|
943
|
+
}
|
|
944
|
+
let sCount = 0;
|
|
945
|
+
for (let i = ancestors.length - 1; i >= 0 && sCount < 3; i--) {
|
|
946
|
+
const n = ancestors[i];
|
|
947
|
+
const isStatement = /(?:Statement|Declaration)$/.test(n.type);
|
|
948
|
+
if (!isStatement) continue;
|
|
949
|
+
if (n.type === "BlockStatement") {
|
|
950
|
+
const parent = ancestors[i - 1];
|
|
951
|
+
return parent?.type === "TryStatement" && parent.block === n;
|
|
952
|
+
}
|
|
953
|
+
sCount += 1;
|
|
954
|
+
}
|
|
955
|
+
return false;
|
|
956
|
+
}
|
|
957
|
+
const scopeTracker = new ScopeTracker();
|
|
958
|
+
collectHoistedBindings(parseResult.program, scopeTracker.currentScope());
|
|
959
|
+
collectBlockBindings(parseResult.program.body, scopeTracker.currentScope());
|
|
960
|
+
for (const stmt of parseResult.program.body || []) {
|
|
961
|
+
if (stmt.type === "ImportDeclaration") {
|
|
962
|
+
for (const spec of stmt.specifiers || []) {
|
|
963
|
+
if (spec.local?.name) {
|
|
964
|
+
scopeTracker.add(spec.local.name);
|
|
965
|
+
}
|
|
966
|
+
}
|
|
967
|
+
}
|
|
968
|
+
}
|
|
969
|
+
function walk(node) {
|
|
970
|
+
if (!node || typeof node !== "object") return;
|
|
971
|
+
let pushedScope = false;
|
|
972
|
+
ancestors.push(node);
|
|
973
|
+
if (node.type === "FunctionDeclaration" || node.type === "FunctionExpression" || node.type === "ArrowFunctionExpression") {
|
|
974
|
+
scopeTracker.enter();
|
|
975
|
+
pushedScope = true;
|
|
976
|
+
for (const param of node.params || []) {
|
|
977
|
+
scopeTracker.addPattern(param);
|
|
978
|
+
}
|
|
979
|
+
if (node.type === "FunctionExpression" && node.id?.name) {
|
|
980
|
+
scopeTracker.add(node.id.name);
|
|
981
|
+
}
|
|
982
|
+
if (node.body) {
|
|
983
|
+
collectHoistedBindings(node.body, scopeTracker.currentScope());
|
|
984
|
+
}
|
|
985
|
+
} else if (node.type === "BlockStatement") {
|
|
986
|
+
scopeTracker.enter();
|
|
987
|
+
pushedScope = true;
|
|
988
|
+
collectBlockBindings(node.body, scopeTracker.currentScope());
|
|
989
|
+
} else if (node.type === "CatchClause") {
|
|
990
|
+
scopeTracker.enter();
|
|
991
|
+
pushedScope = true;
|
|
992
|
+
if (node.param) {
|
|
993
|
+
scopeTracker.addPattern(node.param);
|
|
994
|
+
}
|
|
995
|
+
} else if (node.type === "ForStatement" || node.type === "ForInStatement" || node.type === "ForOfStatement") {
|
|
996
|
+
const decl = node.type === "ForStatement" ? node.init : node.left;
|
|
997
|
+
if (decl?.type === "VariableDeclaration" && decl.kind !== "var") {
|
|
998
|
+
scopeTracker.enter();
|
|
999
|
+
pushedScope = true;
|
|
1000
|
+
for (const d of decl.declarations || []) {
|
|
1001
|
+
scopeTracker.addPattern(d.id);
|
|
1002
|
+
}
|
|
1003
|
+
}
|
|
1004
|
+
}
|
|
1005
|
+
if (node.type === "ImportDeclaration" && node.source?.value) {
|
|
1006
|
+
if (node.importKind !== "type") {
|
|
1007
|
+
const hasValueSpecifier = !node.specifiers?.length || node.specifiers.some((s) => s.importKind !== "type");
|
|
1008
|
+
if (hasValueSpecifier) {
|
|
1009
|
+
addDep(node.source.value, true, null, node.start, node.end);
|
|
1010
|
+
}
|
|
1011
|
+
}
|
|
1012
|
+
} else if ((node.type === "ExportNamedDeclaration" || node.type === "ExportAllDeclaration") && node.source?.value) {
|
|
1013
|
+
if (node.exportKind !== "type") {
|
|
1014
|
+
addDep(node.source.value, true, null, node.start, node.end);
|
|
1015
|
+
}
|
|
1016
|
+
} else if (node.type === "ImportExpression") {
|
|
1017
|
+
if (node.source?.type === "Literal" && typeof node.source.value === "string") {
|
|
1018
|
+
addDep(node.source.value, true, "async", node.start, node.end);
|
|
1019
|
+
addDep(asyncRequirePath, false, null, node.start, node.end);
|
|
1020
|
+
} else {
|
|
1021
|
+
throw new Error(`[vxrn/metro] Dynamic import with non-string literal is not supported by Metro in ${filename}`);
|
|
1022
|
+
}
|
|
1023
|
+
} else if (node.type === "CallExpression" && node.callee?.type === "Identifier" && node.callee.name === "require" && !scopeTracker.isShadowed("require")) {
|
|
1024
|
+
if (node.arguments?.[0]?.type === "Literal" && typeof node.arguments[0].value === "string") {
|
|
1025
|
+
addDep(node.arguments[0].value, false, null, node.start, node.end, void 0, node.arguments[0].value !== asyncRequirePath && isOptionalHere(node.arguments[0].value));
|
|
1026
|
+
}
|
|
1027
|
+
} else if (node.type === "CallExpression" && node.callee?.type === "MemberExpression" && !node.callee.computed && node.callee.object?.type === "Identifier" && node.callee.object.name === "require" && node.callee.property?.type === "Identifier" && node.callee.property.name === "context" && !scopeTracker.isShadowed("require")) {
|
|
1028
|
+
const args = node.arguments || [];
|
|
1029
|
+
const dir = resolveConst(args[0]);
|
|
1030
|
+
if (dir?.type !== "Literal" || typeof dir.value !== "string") {
|
|
1031
|
+
throw new Error(`[vxrn/metro] First argument of require.context must be a string literal in ${filename}`);
|
|
1032
|
+
}
|
|
1033
|
+
if (args.length > 4) {
|
|
1034
|
+
throw new Error(`[vxrn/metro] Too many arguments provided to require.context in ${filename}. Expected 4, got: ${args.length}`);
|
|
1035
|
+
}
|
|
1036
|
+
let recursive = true;
|
|
1037
|
+
const recursiveArg = resolveConst(args[1]);
|
|
1038
|
+
if (recursiveArg) {
|
|
1039
|
+
if (recursiveArg.type !== "Literal" || typeof recursiveArg.value !== "boolean") {
|
|
1040
|
+
throw new Error(`[vxrn/metro] Second argument of require.context must be an optional boolean literal in ${filename}`);
|
|
1041
|
+
}
|
|
1042
|
+
recursive = recursiveArg.value;
|
|
1043
|
+
}
|
|
1044
|
+
let filter = {
|
|
1045
|
+
pattern: ".*",
|
|
1046
|
+
flags: ""
|
|
1047
|
+
};
|
|
1048
|
+
const filterArg = resolveConst(args[2]);
|
|
1049
|
+
if (filterArg) {
|
|
1050
|
+
if (filterArg.type !== "Literal" || !filterArg.regex) {
|
|
1051
|
+
throw new Error(`[vxrn/metro] Third argument of require.context must be an optional RegExp literal in ${filename}, instead found node of type: ${filterArg.type}`);
|
|
1052
|
+
}
|
|
1053
|
+
filter = {
|
|
1054
|
+
pattern: filterArg.regex.pattern,
|
|
1055
|
+
flags: filterArg.regex.flags || ""
|
|
1056
|
+
};
|
|
1057
|
+
}
|
|
1058
|
+
let mode = "sync";
|
|
1059
|
+
const modeArg = resolveConst(args[3]);
|
|
1060
|
+
if (modeArg) {
|
|
1061
|
+
const m = modeArg.type === "Literal" ? modeArg.value : void 0;
|
|
1062
|
+
if (m !== "sync" && m !== "eager" && m !== "lazy" && m !== "lazy-once") {
|
|
1063
|
+
throw new Error(`[vxrn/metro] require.context mode must be one of sync, eager, lazy, lazy-once in ${filename}`);
|
|
1064
|
+
}
|
|
1065
|
+
mode = m;
|
|
1066
|
+
}
|
|
1067
|
+
addDep(dir.value, false, null, node.start, node.end, {
|
|
1068
|
+
recursive,
|
|
1069
|
+
filter,
|
|
1070
|
+
mode
|
|
1071
|
+
});
|
|
1072
|
+
}
|
|
1073
|
+
for (const key of Object.keys(node)) {
|
|
1074
|
+
if (key === "start" || key === "end" || key === "loc" || key === "range" || key === "parent" || key === "comments") continue;
|
|
1075
|
+
const child = node[key];
|
|
1076
|
+
if (Array.isArray(child)) {
|
|
1077
|
+
for (const item of child) walk(item);
|
|
1078
|
+
} else if (child && typeof child === "object") {
|
|
1079
|
+
walk(child);
|
|
1080
|
+
}
|
|
1081
|
+
}
|
|
1082
|
+
ancestors.pop();
|
|
1083
|
+
if (pushedScope) {
|
|
1084
|
+
scopeTracker.exit();
|
|
1085
|
+
}
|
|
1086
|
+
}
|
|
1087
|
+
walk(parseResult.program);
|
|
1088
|
+
return Array.from(depMap.values());
|
|
1092
1089
|
}
|
|
1093
1090
|
function checkReservedStrings(sourceCode, config, options) {
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1091
|
+
const reservedStrings = [];
|
|
1092
|
+
if (options.customTransformOptions?.unstable_staticHermesOptimizedRequire === true) {
|
|
1093
|
+
reservedStrings.push("_$$_METRO_MODULE_ID");
|
|
1094
|
+
}
|
|
1095
|
+
if (config.unstable_dependencyMapReservedName != null) {
|
|
1096
|
+
reservedStrings.push(config.unstable_dependencyMapReservedName);
|
|
1097
|
+
}
|
|
1098
|
+
for (const reservedString of reservedStrings) {
|
|
1099
|
+
const position = sourceCode.indexOf(reservedString);
|
|
1100
|
+
if (position > -1) {
|
|
1101
|
+
throw new SyntaxError("Source code contains the reserved string `" + reservedString + "` at character offset " + position);
|
|
1102
|
+
}
|
|
1103
|
+
}
|
|
1107
1104
|
}
|
|
1108
1105
|
let workletsConfigured = false;
|
|
1109
1106
|
let oneNativeTransforms;
|
|
1110
1107
|
function loadOneNativeTransforms(projectRoot) {
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1108
|
+
if (oneNativeTransforms !== void 0) return oneNativeTransforms;
|
|
1109
|
+
try {
|
|
1110
|
+
const req = (0, import_node_module.createRequire)(import_node_path.default.resolve(projectRoot, "package.json"));
|
|
1111
|
+
oneNativeTransforms = req("one/native-transforms");
|
|
1112
|
+
} catch {
|
|
1113
|
+
oneNativeTransforms = null;
|
|
1114
|
+
}
|
|
1115
|
+
return oneNativeTransforms;
|
|
1119
1116
|
}
|
|
1120
1117
|
async function configureWorkletsForWorker(projectRoot) {
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
} = await import("@vxrn/compiler");
|
|
1138
|
-
configureVXRNCompilerPlugin({
|
|
1139
|
-
enableReanimated: hasReanimated
|
|
1140
|
-
});
|
|
1118
|
+
if (workletsConfigured) return;
|
|
1119
|
+
workletsConfigured = true;
|
|
1120
|
+
if (!projectRoot) return;
|
|
1121
|
+
const req = (0, import_node_module.createRequire)(import_node_path.default.resolve(projectRoot, "package.json"));
|
|
1122
|
+
let hasReanimated = false;
|
|
1123
|
+
try {
|
|
1124
|
+
req.resolve("react-native-reanimated/package.json");
|
|
1125
|
+
hasReanimated = true;
|
|
1126
|
+
} catch {
|
|
1127
|
+
try {
|
|
1128
|
+
req.resolve("react-native-worklets/package.json");
|
|
1129
|
+
hasReanimated = true;
|
|
1130
|
+
} catch {}
|
|
1131
|
+
}
|
|
1132
|
+
const { configureVXRNCompilerPlugin } = await import("@vxrn/compiler");
|
|
1133
|
+
configureVXRNCompilerPlugin({ enableReanimated: hasReanimated });
|
|
1141
1134
|
}
|
|
1142
1135
|
async function transform(config, projectRoot, filename, data, options) {
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
}
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
|
|
1398
|
-
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
|
|
1403
|
-
|
|
1404
|
-
|
|
1405
|
-
|
|
1406
|
-
|
|
1407
|
-
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
|
|
1411
|
-
|
|
1412
|
-
|
|
1413
|
-
|
|
1414
|
-
|
|
1415
|
-
|
|
1416
|
-
|
|
1417
|
-
|
|
1418
|
-
|
|
1419
|
-
|
|
1420
|
-
|
|
1421
|
-
|
|
1422
|
-
|
|
1423
|
-
|
|
1424
|
-
|
|
1425
|
-
|
|
1426
|
-
|
|
1427
|
-
|
|
1428
|
-
|
|
1429
|
-
|
|
1430
|
-
|
|
1431
|
-
|
|
1432
|
-
|
|
1433
|
-
|
|
1434
|
-
|
|
1435
|
-
|
|
1436
|
-
|
|
1437
|
-
|
|
1438
|
-
|
|
1439
|
-
|
|
1440
|
-
|
|
1441
|
-
|
|
1442
|
-
|
|
1443
|
-
|
|
1444
|
-
|
|
1445
|
-
intermediateMaps.push(typeof oxcRes.map === "string" ? JSON.parse(oxcRes.map) : oxcRes.map);
|
|
1446
|
-
}
|
|
1447
|
-
try {
|
|
1448
|
-
const esbuildRes = await (0, import_compiler.transformHermesAsync)(code, filename, true, options.type === "script" ? void 0 : "cjs");
|
|
1449
|
-
if (esbuildRes) {
|
|
1450
|
-
code = esbuildRes.code;
|
|
1451
|
-
if (esbuildRes.map) {
|
|
1452
|
-
intermediateMaps.push(esbuildRes.map);
|
|
1453
|
-
}
|
|
1454
|
-
}
|
|
1455
|
-
} catch (err) {
|
|
1456
|
-
throw new Error(`[vxrn/metro] native async/CJS lowering failed for ${filename}: ${err.message || err}`);
|
|
1457
|
-
}
|
|
1458
|
-
try {
|
|
1459
|
-
const loopsRes = (0, import_compiler.transformHermesLoops)(code, filename);
|
|
1460
|
-
if (loopsRes) {
|
|
1461
|
-
code = loopsRes.code;
|
|
1462
|
-
for (const map2 of loopsRes.maps) {
|
|
1463
|
-
intermediateMaps.push(map2);
|
|
1464
|
-
}
|
|
1465
|
-
}
|
|
1466
|
-
} catch (err) {
|
|
1467
|
-
throw new Error(`[vxrn/metro] Hermes loop-binding transform failed for ${filename}: ${err.message || err}`);
|
|
1468
|
-
}
|
|
1469
|
-
const finalDeps = extractDependencies(code, filename, {
|
|
1470
|
-
asyncRequireModulePath: asyncRequirePath,
|
|
1471
|
-
allowOptionalDependencies: config.allowOptionalDependencies
|
|
1472
|
-
});
|
|
1473
|
-
const finalNames = new Set(finalDeps.map(d => d.name));
|
|
1474
|
-
const reconciled = dependencies.filter(d => finalNames.has(d.name));
|
|
1475
|
-
for (const injected of finalDeps) {
|
|
1476
|
-
if (reconciled.some(d => d.name === injected.name)) continue;
|
|
1477
|
-
reconciled.push(injected);
|
|
1478
|
-
}
|
|
1479
|
-
dependencies.length = 0;
|
|
1480
|
-
for (const dep of reconciled) {
|
|
1481
|
-
dependencies.push({
|
|
1482
|
-
...dep,
|
|
1483
|
-
data: {
|
|
1484
|
-
...dep.data,
|
|
1485
|
-
index: dependencies.length
|
|
1486
|
-
}
|
|
1487
|
-
});
|
|
1488
|
-
}
|
|
1489
|
-
const depMapName = config.unstable_dependencyMapReservedName || "_dependencyMap";
|
|
1490
|
-
if (options.type === "script") {
|
|
1491
|
-
const msScript = new import_magic_string.default(code);
|
|
1492
|
-
msScript.prepend(`(function (global) {
|
|
1136
|
+
assertNoUnportedBabelPlugins(options);
|
|
1137
|
+
let sourceCode = typeof data === "string" ? data : data.toString("utf8");
|
|
1138
|
+
sourceCode = (0, import_expoVirtualEnv.substituteExpoVirtualEnvSource)({
|
|
1139
|
+
filename,
|
|
1140
|
+
src: sourceCode,
|
|
1141
|
+
projectRoot,
|
|
1142
|
+
dev: options.dev,
|
|
1143
|
+
environment: options.customTransformOptions?.environment
|
|
1144
|
+
});
|
|
1145
|
+
checkReservedStrings(sourceCode, config, options);
|
|
1146
|
+
if (filename.endsWith(".json")) {
|
|
1147
|
+
try {
|
|
1148
|
+
JSON.parse(sourceCode);
|
|
1149
|
+
} catch (err) {
|
|
1150
|
+
throw new Error(`[vxrn/metro] JSON parse error in ${filename}: ${err.message || err}`);
|
|
1151
|
+
}
|
|
1152
|
+
let code2 = config.unstable_disableModuleWrapping === true ? `module.exports = ${sourceCode};` : wrapJson(sourceCode, {
|
|
1153
|
+
globalPrefix: config.globalPrefix,
|
|
1154
|
+
moduleId: options.moduleId,
|
|
1155
|
+
dependencyIds: options.dependencyIds
|
|
1156
|
+
});
|
|
1157
|
+
if (options.minify && options.unstable_transformProfile !== "hermes-canary" && options.unstable_transformProfile !== "hermes-stable" && config.minifierPath) {
|
|
1158
|
+
try {
|
|
1159
|
+
const minifier = require(config.minifierPath);
|
|
1160
|
+
const minified = await minifier({
|
|
1161
|
+
code: code2,
|
|
1162
|
+
config: config.minifierConfig,
|
|
1163
|
+
filename
|
|
1164
|
+
});
|
|
1165
|
+
code2 = minified.code;
|
|
1166
|
+
} catch (err) {
|
|
1167
|
+
throw new Error(`[vxrn/metro] Minifier failed for ${filename}: ${err.message || err}`);
|
|
1168
|
+
}
|
|
1169
|
+
}
|
|
1170
|
+
const { lineCount: lineCount2, map: map2 } = countLinesAndTerminateMap(code2, []);
|
|
1171
|
+
const outputType = options.type === "asset" ? "js/module/asset" : options.type === "script" ? "js/script" : "js/module";
|
|
1172
|
+
return {
|
|
1173
|
+
dependencies: [],
|
|
1174
|
+
output: [{
|
|
1175
|
+
data: {
|
|
1176
|
+
code: code2,
|
|
1177
|
+
lineCount: lineCount2,
|
|
1178
|
+
map: map2,
|
|
1179
|
+
functionMap: null
|
|
1180
|
+
},
|
|
1181
|
+
type: outputType
|
|
1182
|
+
}]
|
|
1183
|
+
};
|
|
1184
|
+
}
|
|
1185
|
+
if (options.type === "asset") {
|
|
1186
|
+
const assetRegistryPath = config.assetRegistryPath || "react-native/asset-registry";
|
|
1187
|
+
let properDescriptor = null;
|
|
1188
|
+
const absolutePath = import_node_path.default.resolve(projectRoot, filename);
|
|
1189
|
+
if (import_node_fs.default.existsSync(absolutePath)) {
|
|
1190
|
+
try {
|
|
1191
|
+
let getAssetData;
|
|
1192
|
+
try {
|
|
1193
|
+
getAssetData = require("metro/private/Assets").getAssetData;
|
|
1194
|
+
} catch {
|
|
1195
|
+
getAssetData = require("metro/src/Assets").getAssetData;
|
|
1196
|
+
}
|
|
1197
|
+
if (typeof getAssetData === "function") {
|
|
1198
|
+
const rawData = await getAssetData(absolutePath, filename, config.assetPlugins || [], options.platform || "", config.publicPath || "/assets");
|
|
1199
|
+
const copied = { ...rawData };
|
|
1200
|
+
delete copied.files;
|
|
1201
|
+
delete copied.fileSystemLocation;
|
|
1202
|
+
delete copied.path;
|
|
1203
|
+
properDescriptor = copied;
|
|
1204
|
+
}
|
|
1205
|
+
} catch (err) {
|
|
1206
|
+
throw new Error(`[vxrn/metro] Asset resolution failed for ${filename}: ${err.message || err}`);
|
|
1207
|
+
}
|
|
1208
|
+
}
|
|
1209
|
+
if (!properDescriptor) {
|
|
1210
|
+
const ext = import_node_path.default.extname(filename).slice(1);
|
|
1211
|
+
const name = import_node_path.default.basename(filename, "." + ext);
|
|
1212
|
+
properDescriptor = {
|
|
1213
|
+
__packager_asset: true,
|
|
1214
|
+
httpServerLocation: config.publicPath || "/assets",
|
|
1215
|
+
width: void 0,
|
|
1216
|
+
height: void 0,
|
|
1217
|
+
scales: [1],
|
|
1218
|
+
hash: import_node_crypto.default.createHash("md5").update(sourceCode).digest("hex"),
|
|
1219
|
+
name,
|
|
1220
|
+
type: ext
|
|
1221
|
+
};
|
|
1222
|
+
}
|
|
1223
|
+
const assetDepMapName = config.unstable_dependencyMapReservedName || "_dependencyMap";
|
|
1224
|
+
const assetCode = `module.exports = require(${assetDepMapName}[0], ${JSON.stringify(assetRegistryPath)}).registerAsset(${JSON.stringify(properDescriptor)});`;
|
|
1225
|
+
let code2 = config.unstable_disableModuleWrapping === true ? assetCode : wrapModule(assetCode, {
|
|
1226
|
+
globalPrefix: config.globalPrefix,
|
|
1227
|
+
moduleId: options.moduleId,
|
|
1228
|
+
dependencyIds: options.dependencyIds,
|
|
1229
|
+
dependencyMapName: config.unstable_dependencyMapReservedName
|
|
1230
|
+
});
|
|
1231
|
+
const dependencies2 = [{
|
|
1232
|
+
name: assetRegistryPath,
|
|
1233
|
+
data: {
|
|
1234
|
+
key: getDependencyKey(assetRegistryPath, false, null),
|
|
1235
|
+
asyncType: null,
|
|
1236
|
+
locs: [],
|
|
1237
|
+
isESMImportAtSource: false,
|
|
1238
|
+
isESMImport: false,
|
|
1239
|
+
index: 0
|
|
1240
|
+
}
|
|
1241
|
+
}];
|
|
1242
|
+
const { lineCount: lineCount2, map: map2 } = countLinesAndTerminateMap(code2, []);
|
|
1243
|
+
return {
|
|
1244
|
+
dependencies: dependencies2,
|
|
1245
|
+
output: [{
|
|
1246
|
+
data: {
|
|
1247
|
+
code: code2,
|
|
1248
|
+
lineCount: lineCount2,
|
|
1249
|
+
map: map2,
|
|
1250
|
+
functionMap: null
|
|
1251
|
+
},
|
|
1252
|
+
type: "js/module/asset"
|
|
1253
|
+
}]
|
|
1254
|
+
};
|
|
1255
|
+
}
|
|
1256
|
+
let code = sourceCode;
|
|
1257
|
+
const intermediateMaps = [];
|
|
1258
|
+
for (const nativeTransform of getNativeTransforms(options, projectRoot)) {
|
|
1259
|
+
const out = nativeTransform(code, {
|
|
1260
|
+
filename: import_node_path.default.isAbsolute(filename) ? filename : import_node_path.default.resolve(projectRoot, filename),
|
|
1261
|
+
platform: options.platform,
|
|
1262
|
+
dev: options.dev,
|
|
1263
|
+
projectRoot
|
|
1264
|
+
});
|
|
1265
|
+
if (typeof out === "string") code = out;
|
|
1266
|
+
}
|
|
1267
|
+
const oneRouterOptions = getOneRouterMetroOptions(options);
|
|
1268
|
+
if (oneRouterOptions) {
|
|
1269
|
+
code = applyOneRouterMetro(code, filename, oneRouterOptions);
|
|
1270
|
+
}
|
|
1271
|
+
try {
|
|
1272
|
+
const codegenRes = (0, import_compiler.transformReactNativeCodegen)(code, filename, projectRoot);
|
|
1273
|
+
if (codegenRes?.code) {
|
|
1274
|
+
code = codegenRes.code;
|
|
1275
|
+
if (codegenRes.map) {
|
|
1276
|
+
intermediateMaps.push(codegenRes.map);
|
|
1277
|
+
}
|
|
1278
|
+
}
|
|
1279
|
+
} catch (err) {
|
|
1280
|
+
throw new Error(`[vxrn/metro] React Native codegen failed for ${filename}: ${err.message || err}`);
|
|
1281
|
+
}
|
|
1282
|
+
if ((0, import_compiler.shouldStripFlow)(filename, code)) {
|
|
1283
|
+
try {
|
|
1284
|
+
const flowResult = await (0, import_compiler.stripFlowTypes)(filename, code);
|
|
1285
|
+
if (flowResult?.code) {
|
|
1286
|
+
code = flowResult.code;
|
|
1287
|
+
if (flowResult.map) {
|
|
1288
|
+
intermediateMaps.push(typeof flowResult.map === "string" ? JSON.parse(flowResult.map) : flowResult.map);
|
|
1289
|
+
}
|
|
1290
|
+
}
|
|
1291
|
+
} catch (err) {
|
|
1292
|
+
throw new Error(`[vxrn/metro] Flow transform failed for ${filename}: ${err.message || err}`);
|
|
1293
|
+
}
|
|
1294
|
+
}
|
|
1295
|
+
const asyncRequirePath = config.asyncRequireModulePath || "metro-runtime/src/modules/asyncRequire";
|
|
1296
|
+
const aliases = getModuleResolverAliases(options);
|
|
1297
|
+
if (aliases && projectRoot) {
|
|
1298
|
+
const aliasKeys = Object.keys(aliases);
|
|
1299
|
+
if (aliasKeys.some((k) => code.includes(k.endsWith("$") ? k.slice(0, -1) : k))) {
|
|
1300
|
+
code = applyModuleResolverAliases(code, filename, projectRoot, aliases);
|
|
1301
|
+
}
|
|
1302
|
+
}
|
|
1303
|
+
if (code.includes("process.env") || code.includes("import.meta")) {
|
|
1304
|
+
code = applyInlineEnvVars(code, filename, !options.dev, getImportMetaEnv(options));
|
|
1305
|
+
}
|
|
1306
|
+
if (code.includes("-only")) {
|
|
1307
|
+
code = applyEnvironmentGuard(code, filename);
|
|
1308
|
+
}
|
|
1309
|
+
const serverCodeRouterRoot = getRemoveServerCodeRouterRoot(options);
|
|
1310
|
+
if (serverCodeRouterRoot && projectRoot && !filename.includes("node_modules")) {
|
|
1311
|
+
const oneNativeTransforms2 = loadOneNativeTransforms(projectRoot);
|
|
1312
|
+
if (oneNativeTransforms2) {
|
|
1313
|
+
const shaken = await oneNativeTransforms2.transformTreeShakeClient(code, filename, projectRoot, serverCodeRouterRoot);
|
|
1314
|
+
if (shaken?.code) {
|
|
1315
|
+
code = shaken.code;
|
|
1316
|
+
}
|
|
1317
|
+
}
|
|
1318
|
+
}
|
|
1319
|
+
const dependencies = extractDependencies(code, filename, {
|
|
1320
|
+
asyncRequireModulePath: asyncRequirePath,
|
|
1321
|
+
allowOptionalDependencies: config.allowOptionalDependencies
|
|
1322
|
+
});
|
|
1323
|
+
await configureWorkletsForWorker(projectRoot);
|
|
1324
|
+
let shouldRunWorklets = Boolean(options.customTransformOptions?.worklets);
|
|
1325
|
+
if (!shouldRunWorklets) {
|
|
1326
|
+
const { shouldTransformWorklets } = await import("@vxrn/compiler");
|
|
1327
|
+
shouldRunWorklets = shouldTransformWorklets({
|
|
1328
|
+
id: filename,
|
|
1329
|
+
code
|
|
1330
|
+
});
|
|
1331
|
+
}
|
|
1332
|
+
const shouldRunReactCompiler = Boolean(options.customTransformOptions?.reactCompiler) || hasBabelPlugin(options, "babel-plugin-react-compiler") && isReactCompilerCandidate(filename) || code.includes("\"use memo\"") || code.includes("'use memo'");
|
|
1333
|
+
if (shouldRunReactCompiler) {
|
|
1334
|
+
try {
|
|
1335
|
+
const { prepareWorkletsForReactCompiler, transformOxcReactCompiler } = await import("@vxrn/compiler");
|
|
1336
|
+
if (shouldRunWorklets) {
|
|
1337
|
+
const prepared = prepareWorkletsForReactCompiler(filename, code, true);
|
|
1338
|
+
if (prepared) {
|
|
1339
|
+
code = prepared.code;
|
|
1340
|
+
if (prepared.map) intermediateMaps.push(prepared.map);
|
|
1341
|
+
}
|
|
1342
|
+
}
|
|
1343
|
+
const compilerRes = await transformOxcReactCompiler(filename, code, "19", true);
|
|
1344
|
+
if (compilerRes?.code) {
|
|
1345
|
+
code = compilerRes.code;
|
|
1346
|
+
if (compilerRes.map) {
|
|
1347
|
+
intermediateMaps.push(typeof compilerRes.map === "string" ? JSON.parse(compilerRes.map) : compilerRes.map);
|
|
1348
|
+
}
|
|
1349
|
+
}
|
|
1350
|
+
} catch (err) {
|
|
1351
|
+
throw new Error(`[vxrn/metro] React Compiler failed for ${filename}: ${err.message || err}`);
|
|
1352
|
+
}
|
|
1353
|
+
}
|
|
1354
|
+
if (shouldRunWorklets) {
|
|
1355
|
+
try {
|
|
1356
|
+
const { transformWorklets } = await import("@vxrn/compiler");
|
|
1357
|
+
const workletRes = await transformWorklets(filename, code, true, { projectRoot });
|
|
1358
|
+
if (workletRes?.code) {
|
|
1359
|
+
code = workletRes.code;
|
|
1360
|
+
if (workletRes.map) {
|
|
1361
|
+
intermediateMaps.push(typeof workletRes.map === "string" ? JSON.parse(workletRes.map) : workletRes.map);
|
|
1362
|
+
}
|
|
1363
|
+
}
|
|
1364
|
+
} catch (err) {
|
|
1365
|
+
throw new Error(`[vxrn/metro] Worklets transform failed for ${filename}: ${err.message || err}`);
|
|
1366
|
+
}
|
|
1367
|
+
}
|
|
1368
|
+
const lang = langForFilename(filename);
|
|
1369
|
+
const { transformSync: oxcTransform } = await import("oxc-transform");
|
|
1370
|
+
let oxcRes;
|
|
1371
|
+
try {
|
|
1372
|
+
oxcRes = oxcTransform(filename, code, {
|
|
1373
|
+
lang,
|
|
1374
|
+
target: "es2020",
|
|
1375
|
+
assumptions: { setPublicClassFields: true },
|
|
1376
|
+
jsx: {
|
|
1377
|
+
runtime: "automatic",
|
|
1378
|
+
development: Boolean(options.dev)
|
|
1379
|
+
},
|
|
1380
|
+
sourcemap: true
|
|
1381
|
+
});
|
|
1382
|
+
} catch (err) {
|
|
1383
|
+
throw new Error(`[vxrn/metro] Oxc transform failed for ${filename}: ${err.message || err}`);
|
|
1384
|
+
}
|
|
1385
|
+
if (oxcRes.errors?.length) {
|
|
1386
|
+
throw new Error(`[vxrn/metro] Oxc transform failed for ${filename}: ${oxcRes.errors[0].message || oxcRes.errors[0]}`);
|
|
1387
|
+
}
|
|
1388
|
+
code = oxcRes.code || code;
|
|
1389
|
+
if (oxcRes.map) {
|
|
1390
|
+
intermediateMaps.push(typeof oxcRes.map === "string" ? JSON.parse(oxcRes.map) : oxcRes.map);
|
|
1391
|
+
}
|
|
1392
|
+
try {
|
|
1393
|
+
const esbuildRes = await (0, import_compiler.transformHermesAsync)(code, filename, true, options.type === "script" ? void 0 : "cjs");
|
|
1394
|
+
if (esbuildRes) {
|
|
1395
|
+
code = esbuildRes.code;
|
|
1396
|
+
if (esbuildRes.map) {
|
|
1397
|
+
intermediateMaps.push(esbuildRes.map);
|
|
1398
|
+
}
|
|
1399
|
+
}
|
|
1400
|
+
} catch (err) {
|
|
1401
|
+
throw new Error(`[vxrn/metro] native async/CJS lowering failed for ${filename}: ${err.message || err}`);
|
|
1402
|
+
}
|
|
1403
|
+
try {
|
|
1404
|
+
const loopsRes = (0, import_compiler.transformHermesLoops)(code, filename);
|
|
1405
|
+
if (loopsRes) {
|
|
1406
|
+
code = loopsRes.code;
|
|
1407
|
+
for (const map2 of loopsRes.maps) {
|
|
1408
|
+
intermediateMaps.push(map2);
|
|
1409
|
+
}
|
|
1410
|
+
}
|
|
1411
|
+
} catch (err) {
|
|
1412
|
+
throw new Error(`[vxrn/metro] Hermes loop-binding transform failed for ${filename}: ${err.message || err}`);
|
|
1413
|
+
}
|
|
1414
|
+
const finalDeps = extractDependencies(code, filename, {
|
|
1415
|
+
asyncRequireModulePath: asyncRequirePath,
|
|
1416
|
+
allowOptionalDependencies: config.allowOptionalDependencies
|
|
1417
|
+
});
|
|
1418
|
+
const finalNames = new Set(finalDeps.map((d) => d.name));
|
|
1419
|
+
const reconciled = dependencies.filter((d) => finalNames.has(d.name));
|
|
1420
|
+
for (const injected of finalDeps) {
|
|
1421
|
+
if (reconciled.some((d) => d.name === injected.name)) continue;
|
|
1422
|
+
reconciled.push(injected);
|
|
1423
|
+
}
|
|
1424
|
+
dependencies.length = 0;
|
|
1425
|
+
for (const dep of reconciled) {
|
|
1426
|
+
dependencies.push({
|
|
1427
|
+
...dep,
|
|
1428
|
+
data: {
|
|
1429
|
+
...dep.data,
|
|
1430
|
+
index: dependencies.length
|
|
1431
|
+
}
|
|
1432
|
+
});
|
|
1433
|
+
}
|
|
1434
|
+
const depMapName = config.unstable_dependencyMapReservedName || "_dependencyMap";
|
|
1435
|
+
if (options.type === "script") {
|
|
1436
|
+
const msScript = new import_magic_string.default(code);
|
|
1437
|
+
msScript.prepend(`(function (global) {
|
|
1493
1438
|
`);
|
|
1494
|
-
|
|
1439
|
+
msScript.append(`
|
|
1495
1440
|
})(typeof globalThis !== 'undefined' ? globalThis : typeof global !== 'undefined' ? global : typeof window !== 'undefined' ? window : this);`);
|
|
1496
|
-
|
|
1497
|
-
|
|
1498
|
-
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
|
|
1504
|
-
|
|
1505
|
-
|
|
1506
|
-
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
|
|
1512
|
-
|
|
1513
|
-
|
|
1514
|
-
|
|
1515
|
-
|
|
1441
|
+
code = msScript.toString();
|
|
1442
|
+
intermediateMaps.push(msScript.generateMap({
|
|
1443
|
+
source: filename,
|
|
1444
|
+
hires: true,
|
|
1445
|
+
includeContent: true
|
|
1446
|
+
}));
|
|
1447
|
+
} else if (config.unstable_disableModuleWrapping === true) {
|
|
1448
|
+
const rewriteRes = rewriteDependencyCalls(code, dependencies, depMapName, filename, asyncRequirePath);
|
|
1449
|
+
code = rewriteRes.code;
|
|
1450
|
+
if (rewriteRes.map) {
|
|
1451
|
+
intermediateMaps.push(rewriteRes.map);
|
|
1452
|
+
}
|
|
1453
|
+
} else {
|
|
1454
|
+
const rewriteRes = rewriteDependencyCalls(code, dependencies, depMapName, filename, asyncRequirePath);
|
|
1455
|
+
if (rewriteRes.map) {
|
|
1456
|
+
intermediateMaps.push(rewriteRes.map);
|
|
1457
|
+
}
|
|
1458
|
+
const msWrap = new import_magic_string.default(rewriteRes.code);
|
|
1459
|
+
const globalPrefix = config.globalPrefix || "";
|
|
1460
|
+
const header = `function (global, _$$_REQUIRE, _$$_IMPORT_DEFAULT, _$$_IMPORT_ALL, module, exports, ${depMapName}) {
|
|
1516
1461
|
var require = _$$_REQUIRE;
|
|
1517
1462
|
`;
|
|
1518
|
-
|
|
1463
|
+
const footer = `
|
|
1519
1464
|
}`;
|
|
1520
|
-
|
|
1521
|
-
|
|
1522
|
-
|
|
1523
|
-
|
|
1524
|
-
|
|
1525
|
-
|
|
1526
|
-
|
|
1527
|
-
|
|
1528
|
-
|
|
1529
|
-
|
|
1530
|
-
|
|
1531
|
-
|
|
1532
|
-
|
|
1533
|
-
|
|
1534
|
-
|
|
1535
|
-
|
|
1536
|
-
|
|
1537
|
-
|
|
1538
|
-
|
|
1539
|
-
|
|
1540
|
-
|
|
1541
|
-
|
|
1542
|
-
|
|
1543
|
-
|
|
1544
|
-
|
|
1545
|
-
|
|
1546
|
-
|
|
1547
|
-
|
|
1548
|
-
|
|
1549
|
-
|
|
1550
|
-
|
|
1551
|
-
|
|
1552
|
-
|
|
1553
|
-
|
|
1554
|
-
|
|
1555
|
-
|
|
1556
|
-
|
|
1557
|
-
|
|
1558
|
-
|
|
1559
|
-
|
|
1560
|
-
|
|
1561
|
-
|
|
1562
|
-
|
|
1563
|
-
|
|
1564
|
-
|
|
1565
|
-
|
|
1566
|
-
|
|
1567
|
-
|
|
1568
|
-
|
|
1569
|
-
|
|
1570
|
-
|
|
1571
|
-
|
|
1572
|
-
|
|
1573
|
-
|
|
1574
|
-
|
|
1575
|
-
|
|
1576
|
-
|
|
1577
|
-
|
|
1578
|
-
type: options.type === "script" ? "js/script" : "js/module"
|
|
1579
|
-
}]
|
|
1580
|
-
};
|
|
1465
|
+
msWrap.prepend(`${globalPrefix}__d(${header}`);
|
|
1466
|
+
if (options.moduleId !== void 0) {
|
|
1467
|
+
const depIds = options.dependencyIds ? JSON.stringify(options.dependencyIds) : "[]";
|
|
1468
|
+
msWrap.append(`${footer}, ${JSON.stringify(options.moduleId)}, ${depIds});`);
|
|
1469
|
+
} else {
|
|
1470
|
+
msWrap.append(`${footer});`);
|
|
1471
|
+
}
|
|
1472
|
+
code = msWrap.toString();
|
|
1473
|
+
intermediateMaps.push(msWrap.generateMap({
|
|
1474
|
+
source: filename,
|
|
1475
|
+
hires: true,
|
|
1476
|
+
includeContent: true
|
|
1477
|
+
}));
|
|
1478
|
+
}
|
|
1479
|
+
if (options.minify && options.unstable_transformProfile !== "hermes-canary" && options.unstable_transformProfile !== "hermes-stable" && config.minifierPath) {
|
|
1480
|
+
try {
|
|
1481
|
+
const minifier = require(config.minifierPath);
|
|
1482
|
+
const minified = await minifier({
|
|
1483
|
+
code,
|
|
1484
|
+
config: config.minifierConfig,
|
|
1485
|
+
filename,
|
|
1486
|
+
map: new import_magic_string.default(code).generateMap({
|
|
1487
|
+
source: filename,
|
|
1488
|
+
hires: true,
|
|
1489
|
+
includeContent: true
|
|
1490
|
+
})
|
|
1491
|
+
});
|
|
1492
|
+
code = minified.code;
|
|
1493
|
+
if (minified.map) {
|
|
1494
|
+
intermediateMaps.push(typeof minified.map === "string" ? JSON.parse(minified.map) : minified.map);
|
|
1495
|
+
} else {
|
|
1496
|
+
intermediateMaps.length = 0;
|
|
1497
|
+
}
|
|
1498
|
+
} catch (err) {
|
|
1499
|
+
throw new Error(`[vxrn/metro] Minifier failed for ${filename}: ${err.message || err}`);
|
|
1500
|
+
}
|
|
1501
|
+
}
|
|
1502
|
+
let rawMappings = [];
|
|
1503
|
+
if (intermediateMaps.length > 0) {
|
|
1504
|
+
const cleanMaps = intermediateMaps.map((m) => typeof m === "string" ? JSON.parse(m) : m).filter(Boolean);
|
|
1505
|
+
if (cleanMaps.length > 0) {
|
|
1506
|
+
const composed = cleanMaps.length === 1 ? cleanMaps[0] : (0, import_remapping.default)(cleanMaps.slice().reverse(), () => null);
|
|
1507
|
+
rawMappings = convertSourceMapToMetroRawMappings(composed);
|
|
1508
|
+
}
|
|
1509
|
+
}
|
|
1510
|
+
const { lineCount, map } = countLinesAndTerminateMap(code, rawMappings);
|
|
1511
|
+
return {
|
|
1512
|
+
dependencies,
|
|
1513
|
+
output: [{
|
|
1514
|
+
data: {
|
|
1515
|
+
code,
|
|
1516
|
+
lineCount,
|
|
1517
|
+
map,
|
|
1518
|
+
functionMap: null
|
|
1519
|
+
},
|
|
1520
|
+
type: options.type === "script" ? "js/script" : "js/module"
|
|
1521
|
+
}]
|
|
1522
|
+
};
|
|
1581
1523
|
}
|
|
1582
1524
|
var metroNativeWorker_default = {
|
|
1583
|
-
|
|
1584
|
-
|
|
1585
|
-
|
|
1586
|
-
|
|
1587
|
-
|
|
1588
|
-
|
|
1589
|
-
|
|
1590
|
-
};
|
|
1525
|
+
transform,
|
|
1526
|
+
getCacheKey,
|
|
1527
|
+
wrapModule,
|
|
1528
|
+
wrapJson,
|
|
1529
|
+
extractDependencies,
|
|
1530
|
+
rewriteDependencyCalls,
|
|
1531
|
+
convertSourceMapToMetroRawMappings
|
|
1532
|
+
};
|