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