@vxrn/vite-plugin-metro 2.0.0-beta.33.1 → 2.0.0-beta.46.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 +55 -57
- package/dist/cjs/env/platformEnv.native.cjs +93 -0
- package/dist/cjs/env/platformEnv.native.js +72 -75
- package/dist/cjs/env/platformEnv.native.js.map +1 -1
- package/dist/cjs/index.cjs +22 -24
- package/dist/cjs/index.native.cjs +41 -0
- package/dist/cjs/index.native.js +22 -23
- package/dist/cjs/index.native.js.map +1 -1
- package/dist/cjs/metro-config/getMetroBabelConfigFromViteConfig.cjs +48 -51
- package/dist/cjs/metro-config/getMetroBabelConfigFromViteConfig.native.cjs +101 -0
- package/dist/cjs/metro-config/getMetroBabelConfigFromViteConfig.native.js +88 -94
- package/dist/cjs/metro-config/getMetroBabelConfigFromViteConfig.native.js.map +1 -1
- package/dist/cjs/metro-config/getMetroConfigFromViteConfig.cjs +249 -256
- package/dist/cjs/metro-config/getMetroConfigFromViteConfig.native.cjs +295 -0
- package/dist/cjs/metro-config/getMetroConfigFromViteConfig.native.js +260 -266
- 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/expoManifestRequestHandlerPlugin.cjs +44 -56
- package/dist/cjs/plugins/expoManifestRequestHandlerPlugin.native.cjs +62 -0
- package/dist/cjs/plugins/expoManifestRequestHandlerPlugin.native.js +45 -63
- package/dist/cjs/plugins/expoManifestRequestHandlerPlugin.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 +101 -152
- package/dist/cjs/transformer/babel-transformer.native.cjs +131 -0
- package/dist/cjs/transformer/babel-transformer.native.js +106 -159
- package/dist/cjs/transformer/babel-transformer.native.js.map +1 -1
- 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 +1442 -1480
- package/dist/cjs/transformer/metroNativeWorker.native.cjs +2536 -0
- package/dist/cjs/transformer/metroNativeWorker.native.js +2416 -2552
- package/dist/cjs/transformer/metroNativeWorker.native.js.map +1 -1
- package/dist/cjs/transformer/transformSync.cjs +47 -63
- package/dist/cjs/transformer/transformSync.native.cjs +74 -0
- package/dist/cjs/transformer/transformSync.native.js +49 -64
- 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/patchExpoGoManifestHandlerMiddlewareWithCustomMainModuleName.cjs +24 -28
- package/dist/cjs/utils/patchExpoGoManifestHandlerMiddlewareWithCustomMainModuleName.native.cjs +37 -0
- package/dist/cjs/utils/patchExpoGoManifestHandlerMiddlewareWithCustomMainModuleName.native.js +24 -27
- package/dist/cjs/utils/patchExpoGoManifestHandlerMiddlewareWithCustomMainModuleName.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 +40 -39
- package/dist/esm/env/platformEnv.mjs.map +1 -1
- package/dist/esm/env/platformEnv.native.js +57 -58
- package/dist/esm/env/platformEnv.native.js.map +1 -1
- package/dist/esm/index.js +3 -3
- package/dist/esm/index.mjs +3 -3
- package/dist/esm/index.native.js +3 -3
- package/dist/esm/metro-config/getMetroBabelConfigFromViteConfig.mjs +35 -33
- package/dist/esm/metro-config/getMetroBabelConfigFromViteConfig.mjs.map +1 -1
- package/dist/esm/metro-config/getMetroBabelConfigFromViteConfig.native.js +75 -77
- package/dist/esm/metro-config/getMetroBabelConfigFromViteConfig.native.js.map +1 -1
- package/dist/esm/metro-config/getMetroConfigFromViteConfig.mjs +233 -231
- package/dist/esm/metro-config/getMetroConfigFromViteConfig.mjs.map +1 -1
- package/dist/esm/metro-config/getMetroConfigFromViteConfig.native.js +244 -242
- 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/expoManifestRequestHandlerPlugin.mjs +32 -38
- package/dist/esm/plugins/expoManifestRequestHandlerPlugin.mjs.map +1 -1
- package/dist/esm/plugins/expoManifestRequestHandlerPlugin.native.js +33 -46
- package/dist/esm/plugins/expoManifestRequestHandlerPlugin.native.js.map +1 -1
- 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 +108 -144
- package/dist/esm/transformer/babel-transformer.mjs.map +1 -1
- package/dist/esm/transformer/babel-transformer.native.js +114 -155
- package/dist/esm/transformer/babel-transformer.native.js.map +1 -1
- 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 +1405 -1434
- package/dist/esm/transformer/metroNativeWorker.mjs.map +1 -1
- package/dist/esm/transformer/metroNativeWorker.native.js +2379 -2507
- package/dist/esm/transformer/metroNativeWorker.native.js.map +1 -1
- package/dist/esm/transformer/transformSync.mjs +32 -37
- package/dist/esm/transformer/transformSync.mjs.map +1 -1
- package/dist/esm/transformer/transformSync.native.js +34 -39
- 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/patchExpoGoManifestHandlerMiddlewareWithCustomMainModuleName.mjs +11 -10
- package/dist/esm/utils/patchExpoGoManifestHandlerMiddlewareWithCustomMainModuleName.mjs.map +1 -1
- package/dist/esm/utils/patchExpoGoManifestHandlerMiddlewareWithCustomMainModuleName.native.js +11 -10
- package/dist/esm/utils/patchExpoGoManifestHandlerMiddlewareWithCustomMainModuleName.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 +17 -18
- package/src/metro-config/getMetroConfigFromViteConfig.ts +46 -10
- package/src/transformer/loadBabelConfig.ts +2 -0
- package/src/transformer/metroNativeWorker.test.ts +267 -35
- package/src/transformer/metroNativeWorker.ts +3 -11
- package/types/babel-plugins/import-meta-env-plugin.d.ts.map +1 -1
- package/types/metro-config/getMetroConfigFromViteConfig.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/loadBabelConfig.d.ts.map +1 -1
- package/types/transformer/metroNativeWorker.d.ts.map +1 -1
- package/dist/cjs/transformer/metroNativeWorker.test.cjs +0 -897
- package/dist/cjs/transformer/metroNativeWorker.test.native.js +0 -1010
- 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/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/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 -861
- package/dist/esm/transformer/metroNativeWorker.test.mjs.map +0 -1
- package/dist/esm/transformer/metroNativeWorker.test.native.js +0 -972
- 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/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
|
@@ -1,972 +0,0 @@
|
|
|
1
|
-
import { beforeEach, describe, expect, it, vi } from "vitest";
|
|
2
|
-
import * as vm from "vm";
|
|
3
|
-
import { parseSync } from "oxc-parser";
|
|
4
|
-
import * as fs from "fs";
|
|
5
|
-
import * as path from "path";
|
|
6
|
-
import { createRequire } from "module";
|
|
7
|
-
import { applyEnvironmentGuard, applyInlineEnvVars, assertNoUnportedBabelPlugins, extractDependencies, getCacheKey, getRemoveServerCodeRouterRoot, transform, wrapModule } from "./metroNativeWorker.native.js";
|
|
8
|
-
import { buildMetroConfigInputFromViteConfig } from "../metro-config/getMetroConfigFromViteConfig.native.js";
|
|
9
|
-
var __require = /* @__PURE__ */(x => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
10
|
-
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
11
|
-
}) : x)(function (x) {
|
|
12
|
-
if (typeof require !== "undefined") return require.apply(this, arguments);
|
|
13
|
-
throw Error("Calling `require` for \"" + x + "\" in an environment that doesn't expose the `require` function. See https://rolldown.rs/in-depth/bundling-cjs#require-external-modules for more details.");
|
|
14
|
-
});
|
|
15
|
-
function _instanceof(left, right) {
|
|
16
|
-
if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) return !!right[Symbol.hasInstance](left);else return left instanceof right;
|
|
17
|
-
}
|
|
18
|
-
function _type_of(obj) {
|
|
19
|
-
"@swc/helpers - typeof";
|
|
20
|
-
|
|
21
|
-
return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
|
|
22
|
-
}
|
|
23
|
-
var babelCalls = {
|
|
24
|
-
transform: 0,
|
|
25
|
-
transformSync: 0,
|
|
26
|
-
transformAsync: 0,
|
|
27
|
-
transformFromAstSync: 0,
|
|
28
|
-
parse: 0,
|
|
29
|
-
parseSync: 0
|
|
30
|
-
};
|
|
31
|
-
vi.mock("@babel/core", async function (importOriginal) {
|
|
32
|
-
var actual = await importOriginal();
|
|
33
|
-
return {
|
|
34
|
-
...actual,
|
|
35
|
-
transform: vi.fn(function () {
|
|
36
|
-
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) args[_key] = arguments[_key];
|
|
37
|
-
babelCalls.transform++;
|
|
38
|
-
return actual.transform(...args);
|
|
39
|
-
}),
|
|
40
|
-
transformSync: vi.fn(function () {
|
|
41
|
-
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) args[_key] = arguments[_key];
|
|
42
|
-
babelCalls.transformSync++;
|
|
43
|
-
return actual.transformSync(...args);
|
|
44
|
-
}),
|
|
45
|
-
transformAsync: vi.fn(function () {
|
|
46
|
-
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) args[_key] = arguments[_key];
|
|
47
|
-
babelCalls.transformAsync++;
|
|
48
|
-
return actual.transformAsync(...args);
|
|
49
|
-
}),
|
|
50
|
-
transformFromAstSync: vi.fn(function () {
|
|
51
|
-
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) args[_key] = arguments[_key];
|
|
52
|
-
babelCalls.transformFromAstSync++;
|
|
53
|
-
return actual.transformFromAstSync(...args);
|
|
54
|
-
}),
|
|
55
|
-
parse: vi.fn(function () {
|
|
56
|
-
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) args[_key] = arguments[_key];
|
|
57
|
-
babelCalls.parse++;
|
|
58
|
-
return actual.parse(...args);
|
|
59
|
-
}),
|
|
60
|
-
parseSync: vi.fn(function () {
|
|
61
|
-
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) args[_key] = arguments[_key];
|
|
62
|
-
babelCalls.parseSync++;
|
|
63
|
-
return actual.parseSync(...args);
|
|
64
|
-
})
|
|
65
|
-
};
|
|
66
|
-
});
|
|
67
|
-
beforeEach(function () {
|
|
68
|
-
babelCalls.transform = 0;
|
|
69
|
-
babelCalls.transformSync = 0;
|
|
70
|
-
babelCalls.transformAsync = 0;
|
|
71
|
-
babelCalls.transformFromAstSync = 0;
|
|
72
|
-
babelCalls.parse = 0;
|
|
73
|
-
babelCalls.parseSync = 0;
|
|
74
|
-
});
|
|
75
|
-
function assertZeroBabelCalls() {
|
|
76
|
-
expect(babelCalls.transform).toBe(0);
|
|
77
|
-
expect(babelCalls.transformSync).toBe(0);
|
|
78
|
-
expect(babelCalls.transformAsync).toBe(0);
|
|
79
|
-
expect(babelCalls.transformFromAstSync).toBe(0);
|
|
80
|
-
expect(babelCalls.parse).toBe(0);
|
|
81
|
-
expect(babelCalls.parseSync).toBe(0);
|
|
82
|
-
}
|
|
83
|
-
describe("metroNativeWorker", function () {
|
|
84
|
-
it.each([["data.json", true], ["data.json", false], ["data.js", false]])("minifies %s with source maps enabled=%s without stale mappings", async function (filename, sourceMap) {
|
|
85
|
-
var result = await transform({
|
|
86
|
-
minifierPath: createRequire(import.meta.url).resolve("metro-minify-terser"),
|
|
87
|
-
minifierConfig: {
|
|
88
|
-
sourceMap
|
|
89
|
-
}
|
|
90
|
-
}, "/project", filename, Buffer.from(filename.endsWith(".json") ? "{\"answer\":42}" : "module.exports = { answer: 42 }"), {
|
|
91
|
-
dev: false,
|
|
92
|
-
minify: true,
|
|
93
|
-
platform: "ios",
|
|
94
|
-
type: "module"
|
|
95
|
-
});
|
|
96
|
-
var module = {
|
|
97
|
-
exports: {}
|
|
98
|
-
};
|
|
99
|
-
var {
|
|
100
|
-
code,
|
|
101
|
-
map
|
|
102
|
-
} = result.output[0].data;
|
|
103
|
-
vm.runInNewContext(code, {
|
|
104
|
-
__d(factory) {
|
|
105
|
-
factory({}, function () {}, function () {}, function () {}, module, module.exports, []);
|
|
106
|
-
}
|
|
107
|
-
});
|
|
108
|
-
expect(module.exports.answer).toBe(42);
|
|
109
|
-
expect(map.every(function (entry) {
|
|
110
|
-
return entry.length === 2;
|
|
111
|
-
})).toBe(true);
|
|
112
|
-
assertZeroBabelCalls();
|
|
113
|
-
});
|
|
114
|
-
it("minifies production modules with executable output and original source locations", async function () {
|
|
115
|
-
var source = "exports.answer = function answer(value) {\n return value + 42\n}\n";
|
|
116
|
-
var {
|
|
117
|
-
code,
|
|
118
|
-
map
|
|
119
|
-
} = (await transform({
|
|
120
|
-
minifierPath: createRequire(import.meta.url).resolve("metro-minify-terser"),
|
|
121
|
-
minifierConfig: {
|
|
122
|
-
mangle: true
|
|
123
|
-
}
|
|
124
|
-
}, "/project", "answer.js", Buffer.from(source), {
|
|
125
|
-
dev: false,
|
|
126
|
-
minify: true,
|
|
127
|
-
platform: "ios",
|
|
128
|
-
type: "module"
|
|
129
|
-
})).output[0].data;
|
|
130
|
-
var module = {
|
|
131
|
-
exports: {}
|
|
132
|
-
};
|
|
133
|
-
vm.runInNewContext(code, {
|
|
134
|
-
__d(factory) {
|
|
135
|
-
factory({}, function () {}, function () {}, function () {}, module, module.exports, []);
|
|
136
|
-
}
|
|
137
|
-
});
|
|
138
|
-
expect(module.exports.answer(8)).toBe(50);
|
|
139
|
-
var msm = await import("metro-source-map");
|
|
140
|
-
var fullMap = msm.fromRawMappings([{
|
|
141
|
-
code,
|
|
142
|
-
path: "answer.js",
|
|
143
|
-
source,
|
|
144
|
-
map
|
|
145
|
-
}]).toMap();
|
|
146
|
-
var offset = code.indexOf("42");
|
|
147
|
-
expect(offset).toBeGreaterThan(-1);
|
|
148
|
-
var prefix = code.slice(0, offset).split("\n");
|
|
149
|
-
var position = new msm.Consumer(fullMap).originalPositionFor({
|
|
150
|
-
line: prefix.length,
|
|
151
|
-
column: prefix.at(-1).length
|
|
152
|
-
});
|
|
153
|
-
expect(position.source).toBe("answer.js");
|
|
154
|
-
expect(position.line).toBe(2);
|
|
155
|
-
expect(position.column).toBe(17);
|
|
156
|
-
assertZeroBabelCalls();
|
|
157
|
-
});
|
|
158
|
-
it("extracts all dependencies with oxc-parser and zero Babel", function () {
|
|
159
|
-
var deps = extractDependencies(`
|
|
160
|
-
import React, { useState } from 'react'
|
|
161
|
-
import * as RN from 'react-native'
|
|
162
|
-
import './global.css'
|
|
163
|
-
import type { UserType } from './user-types'
|
|
164
|
-
export { Button } from './Button'
|
|
165
|
-
export * from './icons'
|
|
166
|
-
export type { ThemeType } from './theme-types'
|
|
167
|
-
const helper = require('./helper')
|
|
168
|
-
async function loadAsync() {
|
|
169
|
-
const dyn = await import('./dynamic-module')
|
|
170
|
-
}
|
|
171
|
-
`, "TestComponent.tsx");
|
|
172
|
-
assertZeroBabelCalls();
|
|
173
|
-
var names = deps.map(function (d) {
|
|
174
|
-
return d.name;
|
|
175
|
-
});
|
|
176
|
-
expect(names).toContain("react");
|
|
177
|
-
expect(names).toContain("react-native");
|
|
178
|
-
expect(names).toContain("./global.css");
|
|
179
|
-
expect(names).toContain("./Button");
|
|
180
|
-
expect(names).toContain("./icons");
|
|
181
|
-
expect(names).toContain("./helper");
|
|
182
|
-
expect(names).toContain("./dynamic-module");
|
|
183
|
-
expect(names).not.toContain("./user-types");
|
|
184
|
-
expect(names).not.toContain("./theme-types");
|
|
185
|
-
var reactDep = deps.find(function (d) {
|
|
186
|
-
return d.name === "react";
|
|
187
|
-
});
|
|
188
|
-
expect(reactDep.data.isESMImportAtSource).toBe(true);
|
|
189
|
-
expect(reactDep.data.asyncType).toBeNull();
|
|
190
|
-
expect(reactDep.data.locs.length).toBeGreaterThan(0);
|
|
191
|
-
var loc = reactDep.data.locs[0];
|
|
192
|
-
expect(loc.start.line).toBeGreaterThan(0);
|
|
193
|
-
expect(loc.start.column).toBeGreaterThanOrEqual(0);
|
|
194
|
-
expect(loc.end.line).toBeGreaterThanOrEqual(loc.start.line);
|
|
195
|
-
expect(loc.end.column).toBeGreaterThanOrEqual(0);
|
|
196
|
-
var helperDep = deps.find(function (d) {
|
|
197
|
-
return d.name === "./helper";
|
|
198
|
-
});
|
|
199
|
-
expect(helperDep.data.isESMImportAtSource).toBe(false);
|
|
200
|
-
expect(helperDep.data.asyncType).toBeNull();
|
|
201
|
-
expect(deps.find(function (d) {
|
|
202
|
-
return d.name === "./dynamic-module";
|
|
203
|
-
}).data.asyncType).toBe("async");
|
|
204
|
-
});
|
|
205
|
-
it("marks requires inside a try block optional", function () {
|
|
206
|
-
var code = `
|
|
207
|
-
let worklets
|
|
208
|
-
try {
|
|
209
|
-
worklets = require('react-native-worklets-core')
|
|
210
|
-
} catch {}
|
|
211
|
-
const always = require('./always-there')
|
|
212
|
-
`;
|
|
213
|
-
expect(extractDependencies(code, "setup.js").find(function (d) {
|
|
214
|
-
return d.name === "react-native-worklets-core";
|
|
215
|
-
}).data.isOptional).toBeUndefined();
|
|
216
|
-
var on = extractDependencies(code, "setup.js", {
|
|
217
|
-
allowOptionalDependencies: true
|
|
218
|
-
});
|
|
219
|
-
expect(on.find(function (d) {
|
|
220
|
-
return d.name === "react-native-worklets-core";
|
|
221
|
-
}).data.isOptional).toBe(true);
|
|
222
|
-
expect(on.find(function (d) {
|
|
223
|
-
return d.name === "./always-there";
|
|
224
|
-
}).data.isOptional).toBeUndefined();
|
|
225
|
-
expect(extractDependencies(code, "setup.js", {
|
|
226
|
-
allowOptionalDependencies: {
|
|
227
|
-
exclude: ["react-native-worklets-core"]
|
|
228
|
-
}
|
|
229
|
-
}).find(function (d) {
|
|
230
|
-
return d.name === "react-native-worklets-core";
|
|
231
|
-
}).data.isOptional).toBeUndefined();
|
|
232
|
-
});
|
|
233
|
-
it("wraps modules in Metro CommonJS format with and without moduleId", function () {
|
|
234
|
-
var code = "exports.val = 123;";
|
|
235
|
-
var wrappedWithoutId = wrapModule(code);
|
|
236
|
-
expect(wrappedWithoutId).toContain("__d(function (global, _$$_REQUIRE, _$$_IMPORT_DEFAULT, _$$_IMPORT_ALL, module, exports, _dependencyMap) {");
|
|
237
|
-
expect(wrappedWithoutId).toContain("var require = _$$_REQUIRE;");
|
|
238
|
-
expect(wrappedWithoutId).toContain("exports.val = 123;");
|
|
239
|
-
expect(wrappedWithoutId.endsWith(");")).toBe(true);
|
|
240
|
-
expect(wrapModule(code, {
|
|
241
|
-
moduleId: 99,
|
|
242
|
-
dependencyIds: [1, 2, 3]
|
|
243
|
-
})).toContain(", 99, [1,2,3]);");
|
|
244
|
-
});
|
|
245
|
-
it("transforms TSX with React JSX, Hermes lowering, and ZERO Babel", async function () {
|
|
246
|
-
var result = await transform({}, "/project", "Greeter.tsx", Buffer.from(`
|
|
247
|
-
import React from 'react'
|
|
248
|
-
import { View, Text } from 'react-native'
|
|
249
|
-
const helper = require('./helper')
|
|
250
|
-
|
|
251
|
-
export class Greeter extends React.Component {
|
|
252
|
-
greeting = 'Hello from Native'
|
|
253
|
-
|
|
254
|
-
async fetchGreeting() {
|
|
255
|
-
return this.greeting
|
|
256
|
-
}
|
|
257
|
-
|
|
258
|
-
render() {
|
|
259
|
-
return (
|
|
260
|
-
<View testID="greeter">
|
|
261
|
-
<Text>{this.greeting}</Text>
|
|
262
|
-
</View>
|
|
263
|
-
)
|
|
264
|
-
}
|
|
265
|
-
}
|
|
266
|
-
`, "utf8"), {
|
|
267
|
-
dev: true,
|
|
268
|
-
platform: "ios",
|
|
269
|
-
type: "module"
|
|
270
|
-
});
|
|
271
|
-
assertZeroBabelCalls();
|
|
272
|
-
expect(result.output).toHaveLength(1);
|
|
273
|
-
var output = result.output[0];
|
|
274
|
-
expect(output.type).toBe("js/module");
|
|
275
|
-
expect(output.data.lineCount).toBeGreaterThan(0);
|
|
276
|
-
expect(output.data.map.length).toBeGreaterThan(0);
|
|
277
|
-
var code = output.data.code;
|
|
278
|
-
expect(code).toContain("__d(function (global, _$$_REQUIRE, _$$_IMPORT_DEFAULT, _$$_IMPORT_ALL, module, exports, _dependencyMap) {");
|
|
279
|
-
expect(code).toContain("var require = _$$_REQUIRE;");
|
|
280
|
-
expect(code).not.toContain("<View");
|
|
281
|
-
expect(code).not.toContain("<Text");
|
|
282
|
-
expect(code).toContain("this.greeting = \"Hello from Native\"");
|
|
283
|
-
var depNames = result.dependencies.map(function (d) {
|
|
284
|
-
return d.name;
|
|
285
|
-
});
|
|
286
|
-
expect(depNames).toContain("react");
|
|
287
|
-
expect(depNames).toContain("react-native");
|
|
288
|
-
expect(depNames).toContain("./helper");
|
|
289
|
-
expect(depNames).toContain("react/jsx-dev-runtime");
|
|
290
|
-
});
|
|
291
|
-
it("lowers async generators, including the method shorthand Hermes also rejects", async function () {
|
|
292
|
-
var sources = {
|
|
293
|
-
"cursor.ts": `
|
|
294
|
-
export class Cursor {
|
|
295
|
-
async *rows() {
|
|
296
|
-
yield await Promise.resolve(1)
|
|
297
|
-
}
|
|
298
|
-
}
|
|
299
|
-
`,
|
|
300
|
-
"stream.ts": `
|
|
301
|
-
export async function* stream() {
|
|
302
|
-
yield 1
|
|
303
|
-
}
|
|
304
|
-
`,
|
|
305
|
-
"drain.ts": `
|
|
306
|
-
export async function drain(src) {
|
|
307
|
-
for await (const x of src) {
|
|
308
|
-
console.log(x)
|
|
309
|
-
}
|
|
310
|
-
}
|
|
311
|
-
`
|
|
312
|
-
};
|
|
313
|
-
var _iteratorNormalCompletion = true,
|
|
314
|
-
_didIteratorError = false,
|
|
315
|
-
_iteratorError = void 0;
|
|
316
|
-
try {
|
|
317
|
-
for (var _iterator = Object.entries(sources)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
|
|
318
|
-
var [filename, sourceCode] = _step.value;
|
|
319
|
-
var result = await transform({}, "/project", filename, Buffer.from(sourceCode, "utf8"), {
|
|
320
|
-
dev: true,
|
|
321
|
-
platform: "ios",
|
|
322
|
-
type: "module"
|
|
323
|
-
});
|
|
324
|
-
assertZeroBabelCalls();
|
|
325
|
-
var code = result.output[0].data.code;
|
|
326
|
-
expect(code, filename).not.toMatch(/\basync\s+function\s*\*/);
|
|
327
|
-
expect(code, filename).not.toMatch(/\basync\s*\*\s*[\w$[]/);
|
|
328
|
-
expect(code, filename).not.toMatch(/\bfor\s+await\s*\(/);
|
|
329
|
-
}
|
|
330
|
-
} catch (err) {
|
|
331
|
-
_didIteratorError = true;
|
|
332
|
-
_iteratorError = err;
|
|
333
|
-
} finally {
|
|
334
|
-
try {
|
|
335
|
-
if (!_iteratorNormalCompletion && _iterator.return != null) _iterator.return();
|
|
336
|
-
} finally {
|
|
337
|
-
if (_didIteratorError) throw _iteratorError;
|
|
338
|
-
}
|
|
339
|
-
}
|
|
340
|
-
});
|
|
341
|
-
it("handles JSON files without Babel", async function () {
|
|
342
|
-
var jsonSource = JSON.stringify({
|
|
343
|
-
name: "my-package",
|
|
344
|
-
version: "1.0.0"
|
|
345
|
-
});
|
|
346
|
-
var result = await transform({}, "/project", "package.json", Buffer.from(jsonSource, "utf8"), {
|
|
347
|
-
dev: true,
|
|
348
|
-
platform: "ios",
|
|
349
|
-
type: "module"
|
|
350
|
-
});
|
|
351
|
-
assertZeroBabelCalls();
|
|
352
|
-
expect(result.dependencies).toEqual([]);
|
|
353
|
-
expect(result.output).toHaveLength(1);
|
|
354
|
-
expect(result.output[0].type).toBe("js/module");
|
|
355
|
-
expect(result.output[0].data.code).toContain("module.exports = {\"name\":\"my-package\",\"version\":\"1.0.0\"}");
|
|
356
|
-
expect(result.output[0].data.code).toContain("__d(function (global, require");
|
|
357
|
-
});
|
|
358
|
-
it("handles Asset files without Babel", async function () {
|
|
359
|
-
var result = await transform({
|
|
360
|
-
assetRegistryPath: "react-native/Libraries/Image/AssetRegistry",
|
|
361
|
-
publicPath: "/assets"
|
|
362
|
-
}, "/project", "logo.png", Buffer.from("fake-png-binary-data", "utf8"), {
|
|
363
|
-
dev: true,
|
|
364
|
-
platform: "ios",
|
|
365
|
-
type: "asset"
|
|
366
|
-
});
|
|
367
|
-
assertZeroBabelCalls();
|
|
368
|
-
expect(result.output[0].type).toBe("js/module/asset");
|
|
369
|
-
expect(result.output[0].data.code).toContain("registerAsset(");
|
|
370
|
-
expect(result.output[0].data.code).toContain("__d(function");
|
|
371
|
-
expect(result.dependencies.map(function (d) {
|
|
372
|
-
return d.name;
|
|
373
|
-
})).toContain("react-native/Libraries/Image/AssetRegistry");
|
|
374
|
-
});
|
|
375
|
-
it("handles Flow files by stripping types without Babel", async function () {
|
|
376
|
-
var result = await transform({}, "/project", "math.js", Buffer.from(`
|
|
377
|
-
// @flow
|
|
378
|
-
function add(a: number, b: number): number {
|
|
379
|
-
return a + b;
|
|
380
|
-
}
|
|
381
|
-
export default add;
|
|
382
|
-
`, "utf8"), {
|
|
383
|
-
dev: false,
|
|
384
|
-
platform: "ios",
|
|
385
|
-
type: "module"
|
|
386
|
-
});
|
|
387
|
-
assertZeroBabelCalls();
|
|
388
|
-
expect(result.output[0].data.code).not.toContain(": number");
|
|
389
|
-
expect(result.output[0].data.code).toContain("function add(a, b)");
|
|
390
|
-
});
|
|
391
|
-
it("generates a deterministic cache key without Babel", function () {
|
|
392
|
-
var key1 = getCacheKey({
|
|
393
|
-
globalPrefix: "__one_",
|
|
394
|
-
minifierPath: "terser"
|
|
395
|
-
}, {
|
|
396
|
-
projectRoot: "/app"
|
|
397
|
-
});
|
|
398
|
-
var key2 = getCacheKey({
|
|
399
|
-
globalPrefix: "__one_",
|
|
400
|
-
minifierPath: "terser"
|
|
401
|
-
}, {
|
|
402
|
-
projectRoot: "/app"
|
|
403
|
-
});
|
|
404
|
-
var key3 = getCacheKey({
|
|
405
|
-
globalPrefix: "__other_"
|
|
406
|
-
}, {
|
|
407
|
-
projectRoot: "/app"
|
|
408
|
-
});
|
|
409
|
-
assertZeroBabelCalls();
|
|
410
|
-
expect(key1).toBe(key2);
|
|
411
|
-
expect(key1).not.toBe(key3);
|
|
412
|
-
expect(typeof key1 === "undefined" ? "undefined" : _type_of(key1)).toBe("string");
|
|
413
|
-
expect(key1.length).toBe(64);
|
|
414
|
-
});
|
|
415
|
-
it("correctly sets transformerPath in buildMetroConfigInputFromViteConfig when active", async function () {
|
|
416
|
-
var mockViteConfig = {
|
|
417
|
-
root: process.cwd()
|
|
418
|
-
};
|
|
419
|
-
delete process.env.ONE_METRO_NATIVE_TRANSFORMS;
|
|
420
|
-
var configDefault = await buildMetroConfigInputFromViteConfig(mockViteConfig, {});
|
|
421
|
-
expect(configDefault.defaultConfig.transformerPath).toContain("metroNativeWorker");
|
|
422
|
-
expect(configDefault.defaultConfig.transformer.transformerPath).toBeUndefined();
|
|
423
|
-
expect((await buildMetroConfigInputFromViteConfig(mockViteConfig, {
|
|
424
|
-
nativeTransforms: false
|
|
425
|
-
})).defaultConfig.transformerPath).not.toContain("metroNativeWorker");
|
|
426
|
-
process.env.ONE_METRO_NATIVE_TRANSFORMS = "0";
|
|
427
|
-
expect((await buildMetroConfigInputFromViteConfig(mockViteConfig, {})).defaultConfig.transformerPath).not.toContain("metroNativeWorker");
|
|
428
|
-
process.env.ONE_METRO_NATIVE_TRANSFORMS = "1";
|
|
429
|
-
expect((await buildMetroConfigInputFromViteConfig(mockViteConfig, {
|
|
430
|
-
nativeTransforms: false
|
|
431
|
-
})).defaultConfig.transformerPath).toContain("metroNativeWorker");
|
|
432
|
-
delete process.env.ONE_METRO_NATIVE_TRANSFORMS;
|
|
433
|
-
});
|
|
434
|
-
it("excludes volatile compiler caches from Metro without hiding package output", async function () {
|
|
435
|
-
var blockList = (await buildMetroConfigInputFromViteConfig({
|
|
436
|
-
root: process.cwd()
|
|
437
|
-
}, {
|
|
438
|
-
watchman: false
|
|
439
|
-
})).defaultConfig.resolver.blockList;
|
|
440
|
-
var isBlocked = function (file) {
|
|
441
|
-
return blockList.some(function (pattern) {
|
|
442
|
-
return pattern.test(file);
|
|
443
|
-
});
|
|
444
|
-
};
|
|
445
|
-
expect(isBlocked("/home/runner/work/one/one/tests/test-app-cases/node_modules/.vxrn/compiler-cache")).toBe(true);
|
|
446
|
-
expect(isBlocked("C:\\workspace\\tests\\test-app-cases\\node_modules\\.vxrn\\compiler-cache")).toBe(true);
|
|
447
|
-
expect(isBlocked("/home/runner/work/one/one/packages/one/dist/esm/index.mjs")).toBe(false);
|
|
448
|
-
});
|
|
449
|
-
it("transforms and executes a real 2-module Metro bundle through metro-runtime require polyfill", async function () {
|
|
450
|
-
var depSource = "exports.value = 42;";
|
|
451
|
-
var aSource = "const dep = require(\"./dep\"); module.exports = { doubled: dep.value * 2 };";
|
|
452
|
-
var depRes = await transform({}, "/project", "dep.js", Buffer.from(depSource, "utf8"), {
|
|
453
|
-
dev: false,
|
|
454
|
-
platform: "ios",
|
|
455
|
-
type: "module",
|
|
456
|
-
moduleId: 2,
|
|
457
|
-
dependencyIds: []
|
|
458
|
-
});
|
|
459
|
-
var aRes = await transform({}, "/project", "a.js", Buffer.from(aSource, "utf8"), {
|
|
460
|
-
dev: false,
|
|
461
|
-
platform: "ios",
|
|
462
|
-
type: "module",
|
|
463
|
-
moduleId: 1,
|
|
464
|
-
dependencyIds: [2]
|
|
465
|
-
});
|
|
466
|
-
assertZeroBabelCalls();
|
|
467
|
-
expect(aRes.dependencies).toHaveLength(1);
|
|
468
|
-
expect(aRes.dependencies[0].name).toBe("./dep");
|
|
469
|
-
var aEmittedCode = aRes.output[0].data.code;
|
|
470
|
-
expect(aEmittedCode).toContain("require(_dependencyMap[0], \"./dep\")");
|
|
471
|
-
var polyfillPath = __require.resolve("metro-runtime/src/polyfills/require.js");
|
|
472
|
-
var polyfillCode = fs.readFileSync(polyfillPath, "utf8");
|
|
473
|
-
var contextObj = {
|
|
474
|
-
__DEV__: false,
|
|
475
|
-
__METRO_GLOBAL_PREFIX__: "",
|
|
476
|
-
console
|
|
477
|
-
};
|
|
478
|
-
contextObj.global = contextObj;
|
|
479
|
-
vm.createContext(contextObj);
|
|
480
|
-
vm.runInContext(polyfillCode, contextObj);
|
|
481
|
-
vm.runInContext(depRes.output[0].data.code, contextObj);
|
|
482
|
-
vm.runInContext(aEmittedCode, contextObj);
|
|
483
|
-
expect(vm.runInContext("global.__r(1)", contextObj)).toEqual({
|
|
484
|
-
doubled: 84
|
|
485
|
-
});
|
|
486
|
-
});
|
|
487
|
-
it("transforms and executes a 2-module Metro bundle with ESM imports in dev mode", async function () {
|
|
488
|
-
var depSource = "export const greeting = \"Hello Metro Native\";";
|
|
489
|
-
var aSource = "import { greeting } from \"./dep\"; export const message = greeting.toUpperCase();";
|
|
490
|
-
var depRes = await transform({}, "/project", "dep.js", Buffer.from(depSource, "utf8"), {
|
|
491
|
-
dev: true,
|
|
492
|
-
platform: "ios",
|
|
493
|
-
type: "module",
|
|
494
|
-
moduleId: 2,
|
|
495
|
-
dependencyIds: []
|
|
496
|
-
});
|
|
497
|
-
var aRes = await transform({}, "/project", "a.js", Buffer.from(aSource, "utf8"), {
|
|
498
|
-
dev: true,
|
|
499
|
-
platform: "ios",
|
|
500
|
-
type: "module",
|
|
501
|
-
moduleId: 1,
|
|
502
|
-
dependencyIds: [2]
|
|
503
|
-
});
|
|
504
|
-
assertZeroBabelCalls();
|
|
505
|
-
var polyfillPath = __require.resolve("metro-runtime/src/polyfills/require.js");
|
|
506
|
-
var polyfillCode = fs.readFileSync(polyfillPath, "utf8");
|
|
507
|
-
var contextObj = {
|
|
508
|
-
__DEV__: true,
|
|
509
|
-
__METRO_GLOBAL_PREFIX__: "",
|
|
510
|
-
console
|
|
511
|
-
};
|
|
512
|
-
contextObj.global = contextObj;
|
|
513
|
-
vm.createContext(contextObj);
|
|
514
|
-
vm.runInContext(polyfillCode, contextObj);
|
|
515
|
-
vm.runInContext(depRes.output[0].data.code, contextObj);
|
|
516
|
-
vm.runInContext(aRes.output[0].data.code, contextObj);
|
|
517
|
-
expect(vm.runInContext("global.__r(1)", contextObj).message).toBe("HELLO METRO NATIVE");
|
|
518
|
-
});
|
|
519
|
-
it("respects lexical scope shadowing for require calls (Astra probe)", async function () {
|
|
520
|
-
var res = await transform({}, "/project", "shadowed.js", Buffer.from("function f(require){return require(\"./local\")}; module.exports=f(x=>x);", "utf8"), {
|
|
521
|
-
dev: false,
|
|
522
|
-
platform: "ios",
|
|
523
|
-
type: "module",
|
|
524
|
-
moduleId: 1,
|
|
525
|
-
dependencyIds: []
|
|
526
|
-
});
|
|
527
|
-
assertZeroBabelCalls();
|
|
528
|
-
expect(res.dependencies).toHaveLength(0);
|
|
529
|
-
var emitted = res.output[0].data.code;
|
|
530
|
-
expect(emitted).not.toContain("_dependencyMap[0]");
|
|
531
|
-
expect(emitted).toMatch(/require\d*\("\.\/local"\)/);
|
|
532
|
-
var polyfillPath = __require.resolve("metro-runtime/src/polyfills/require.js");
|
|
533
|
-
var polyfillCode = fs.readFileSync(polyfillPath, "utf8");
|
|
534
|
-
var contextObj = {
|
|
535
|
-
__DEV__: false,
|
|
536
|
-
__METRO_GLOBAL_PREFIX__: "",
|
|
537
|
-
console
|
|
538
|
-
};
|
|
539
|
-
contextObj.global = contextObj;
|
|
540
|
-
vm.createContext(contextObj);
|
|
541
|
-
vm.runInContext(polyfillCode, contextObj);
|
|
542
|
-
vm.runInContext(emitted, contextObj);
|
|
543
|
-
expect(vm.runInContext("global.__r(1)", contextObj)).toBe("./local");
|
|
544
|
-
});
|
|
545
|
-
it("preserves distinct indexed identity for duplicate and mixed sync/async dependencies", async function () {
|
|
546
|
-
var res = await transform({}, "/project", "index.js", Buffer.from(`
|
|
547
|
-
const a = require('./dep');
|
|
548
|
-
const b = require('./dep');
|
|
549
|
-
async function load() {
|
|
550
|
-
const c = await import('./dep');
|
|
551
|
-
}
|
|
552
|
-
`, "utf8"), {
|
|
553
|
-
dev: false,
|
|
554
|
-
platform: "ios",
|
|
555
|
-
type: "module"
|
|
556
|
-
});
|
|
557
|
-
assertZeroBabelCalls();
|
|
558
|
-
expect(res.dependencies.map(function (d) {
|
|
559
|
-
return d.name;
|
|
560
|
-
})).toContain("./dep");
|
|
561
|
-
var syncDep = res.dependencies.find(function (d) {
|
|
562
|
-
return d.name === "./dep" && d.data.asyncType === null;
|
|
563
|
-
});
|
|
564
|
-
var asyncDep = res.dependencies.find(function (d) {
|
|
565
|
-
return d.name === "./dep" && d.data.asyncType === "async";
|
|
566
|
-
});
|
|
567
|
-
expect(syncDep).toBeDefined();
|
|
568
|
-
expect(asyncDep).toBeDefined();
|
|
569
|
-
expect(syncDep.data.index).not.toEqual(asyncDep.data.index);
|
|
570
|
-
var emitted = res.output[0].data.code;
|
|
571
|
-
var syncIndex = syncDep.data.index;
|
|
572
|
-
expect(emitted).toContain(`require(_dependencyMap[${syncIndex}], "./dep")`);
|
|
573
|
-
});
|
|
574
|
-
it("conforms to Metro map ABI with raw mapping segment tuples and accurate symbolication", async function () {
|
|
575
|
-
var res = await transform({}, "/project", "math.ts", Buffer.from(`
|
|
576
|
-
export function add(a: number, b: number): number {
|
|
577
|
-
return a + b;
|
|
578
|
-
}
|
|
579
|
-
`, "utf8"), {
|
|
580
|
-
dev: false,
|
|
581
|
-
platform: "ios",
|
|
582
|
-
type: "module"
|
|
583
|
-
});
|
|
584
|
-
assertZeroBabelCalls();
|
|
585
|
-
var map = res.output[0].data.map;
|
|
586
|
-
expect(Array.isArray(map)).toBe(true);
|
|
587
|
-
expect(map.length).toBeGreaterThan(0);
|
|
588
|
-
var _iteratorNormalCompletion = true,
|
|
589
|
-
_didIteratorError = false,
|
|
590
|
-
_iteratorError = void 0;
|
|
591
|
-
try {
|
|
592
|
-
for (var _iterator = map[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
|
|
593
|
-
var tuple = _step.value;
|
|
594
|
-
expect(Array.isArray(tuple)).toBe(true);
|
|
595
|
-
expect(_type_of(tuple[0])).toBe("number");
|
|
596
|
-
expect(_type_of(tuple[1])).toBe("number");
|
|
597
|
-
expect(tuple).not.toHaveProperty("version");
|
|
598
|
-
expect(tuple).not.toHaveProperty("mappings");
|
|
599
|
-
}
|
|
600
|
-
} catch (err) {
|
|
601
|
-
_didIteratorError = true;
|
|
602
|
-
_iteratorError = err;
|
|
603
|
-
} finally {
|
|
604
|
-
try {
|
|
605
|
-
if (!_iteratorNormalCompletion && _iterator.return != null) _iterator.return();
|
|
606
|
-
} finally {
|
|
607
|
-
if (_didIteratorError) throw _iteratorError;
|
|
608
|
-
}
|
|
609
|
-
}
|
|
610
|
-
var msm = await import("metro-source-map");
|
|
611
|
-
var fullMap = msm.fromRawMappings([{
|
|
612
|
-
code: res.output[0].data.code,
|
|
613
|
-
source: "math.ts",
|
|
614
|
-
map
|
|
615
|
-
}]).toMap();
|
|
616
|
-
var consumer = new msm.Consumer(fullMap);
|
|
617
|
-
var addLineIndex = res.output[0].data.code.split("\n").findIndex(function (l) {
|
|
618
|
-
return l.includes("function add");
|
|
619
|
-
});
|
|
620
|
-
expect(addLineIndex).toBeGreaterThan(0);
|
|
621
|
-
expect(consumer.originalPositionFor({
|
|
622
|
-
line: addLineIndex + 1,
|
|
623
|
-
column: 16
|
|
624
|
-
}).line).toBe(2);
|
|
625
|
-
});
|
|
626
|
-
it("models JS hoisting in ScopeTracker for functions and vars (Astra probe)", async function () {
|
|
627
|
-
var res = await transform({}, "/project", "hoisted.js", Buffer.from("function f(){const x=require(\"./local\"); function require(x){return x}; return x} module.exports=f();", "utf8"), {
|
|
628
|
-
dev: false,
|
|
629
|
-
platform: "ios",
|
|
630
|
-
type: "module",
|
|
631
|
-
moduleId: 1,
|
|
632
|
-
dependencyIds: []
|
|
633
|
-
});
|
|
634
|
-
assertZeroBabelCalls();
|
|
635
|
-
expect(res.dependencies).toHaveLength(0);
|
|
636
|
-
var emitted = res.output[0].data.code;
|
|
637
|
-
expect(emitted).not.toContain("_dependencyMap[0]");
|
|
638
|
-
expect(emitted).toMatch(/require\d*\("\.\/local"\)/);
|
|
639
|
-
var polyfillPath = __require.resolve("metro-runtime/src/polyfills/require.js");
|
|
640
|
-
var polyfillCode = fs.readFileSync(polyfillPath, "utf8");
|
|
641
|
-
var contextObj = {
|
|
642
|
-
__DEV__: false,
|
|
643
|
-
__METRO_GLOBAL_PREFIX__: "",
|
|
644
|
-
console
|
|
645
|
-
};
|
|
646
|
-
contextObj.global = contextObj;
|
|
647
|
-
vm.createContext(contextObj);
|
|
648
|
-
vm.runInContext(polyfillCode, contextObj);
|
|
649
|
-
vm.runInContext(emitted, contextObj);
|
|
650
|
-
expect(vm.runInContext("global.__r(1)", contextObj)).toBe("./local");
|
|
651
|
-
});
|
|
652
|
-
it("rewrites dynamic import to Metro asyncRequire and executes promise resolution in dev and release", async function () {
|
|
653
|
-
var depSource = "exports.message = \"hello dynamic\";";
|
|
654
|
-
var mainSource = "module.exports = () => import(\"./dep\");";
|
|
655
|
-
var depRes = await transform({}, "/project", "dep.js", Buffer.from(depSource, "utf8"), {
|
|
656
|
-
dev: true,
|
|
657
|
-
platform: "ios",
|
|
658
|
-
type: "module",
|
|
659
|
-
moduleId: 2,
|
|
660
|
-
dependencyIds: []
|
|
661
|
-
});
|
|
662
|
-
var mainRes = await transform({}, "/project", "main.js", Buffer.from(mainSource, "utf8"), {
|
|
663
|
-
dev: true,
|
|
664
|
-
platform: "ios",
|
|
665
|
-
type: "module",
|
|
666
|
-
moduleId: 0,
|
|
667
|
-
dependencyIds: [2, 1]
|
|
668
|
-
});
|
|
669
|
-
assertZeroBabelCalls();
|
|
670
|
-
var depNames = mainRes.dependencies.map(function (d) {
|
|
671
|
-
return d.name;
|
|
672
|
-
});
|
|
673
|
-
expect(depNames).toContain("./dep");
|
|
674
|
-
expect(depNames).toContain("metro-runtime/src/modules/asyncRequire");
|
|
675
|
-
expect(mainRes.dependencies.find(function (d) {
|
|
676
|
-
return d.name === "./dep";
|
|
677
|
-
}).data.asyncType).toBe("async");
|
|
678
|
-
var emittedMain = mainRes.output[0].data.code;
|
|
679
|
-
expect(emittedMain).not.toContain("import(\"./dep\")");
|
|
680
|
-
expect(emittedMain).toContain("require(_dependencyMap[1], \"metro-runtime/src/modules/asyncRequire\")(_dependencyMap[0], _dependencyMap.paths, \"./dep\")");
|
|
681
|
-
var polyfillPath = __require.resolve("metro-runtime/src/polyfills/require.js");
|
|
682
|
-
var polyfillCode = fs.readFileSync(polyfillPath, "utf8");
|
|
683
|
-
var asyncRequirePath = __require.resolve("metro-runtime/src/modules/asyncRequire.js");
|
|
684
|
-
var wrappedAsyncRequire = wrapModule(fs.readFileSync(asyncRequirePath, "utf8"), {
|
|
685
|
-
moduleId: 1,
|
|
686
|
-
dependencyIds: []
|
|
687
|
-
});
|
|
688
|
-
for (var _i = 0, _iter = [true, false]; _i < _iter.length; _i++) {
|
|
689
|
-
var contextObj = {
|
|
690
|
-
__DEV__: _iter[_i],
|
|
691
|
-
__METRO_GLOBAL_PREFIX__: "",
|
|
692
|
-
console
|
|
693
|
-
};
|
|
694
|
-
contextObj.global = contextObj;
|
|
695
|
-
vm.createContext(contextObj);
|
|
696
|
-
vm.runInContext(polyfillCode, contextObj);
|
|
697
|
-
vm.runInContext(wrappedAsyncRequire, contextObj);
|
|
698
|
-
vm.runInContext(depRes.output[0].data.code, contextObj);
|
|
699
|
-
vm.runInContext(emittedMain, contextObj);
|
|
700
|
-
var mainFn = vm.runInContext("global.__r(0)", contextObj);
|
|
701
|
-
expect(typeof mainFn === "undefined" ? "undefined" : _type_of(mainFn)).toBe("function");
|
|
702
|
-
var promise = mainFn();
|
|
703
|
-
expect(_instanceof(promise, Promise) || promise && typeof promise.then === "function").toBe(true);
|
|
704
|
-
var resolved = await promise;
|
|
705
|
-
expect(resolved.message).toBe("hello dynamic");
|
|
706
|
-
expect(resolved.default.message).toBe("hello dynamic");
|
|
707
|
-
}
|
|
708
|
-
});
|
|
709
|
-
it("preserves accurate sourcemap for tokens after rewritten require calls on the same line", async function () {
|
|
710
|
-
var sourceCode = "const a = require(\"./dep\"), b = 42;";
|
|
711
|
-
var resWrapped = await transform({}, "/project", "app.js", Buffer.from(sourceCode, "utf8"), {
|
|
712
|
-
dev: false,
|
|
713
|
-
platform: "ios",
|
|
714
|
-
type: "module"
|
|
715
|
-
});
|
|
716
|
-
assertZeroBabelCalls();
|
|
717
|
-
var msm = await import("metro-source-map");
|
|
718
|
-
var fullMapWrapped = msm.fromRawMappings([{
|
|
719
|
-
code: resWrapped.output[0].data.code,
|
|
720
|
-
source: "app.js",
|
|
721
|
-
map: resWrapped.output[0].data.map
|
|
722
|
-
}]).toMap();
|
|
723
|
-
var consumerWrapped = new msm.Consumer(fullMapWrapped);
|
|
724
|
-
var linesWrapped = resWrapped.output[0].data.code.split("\n");
|
|
725
|
-
var lineIndexWrapped = linesWrapped.findIndex(function (l) {
|
|
726
|
-
return l.includes("b = 42");
|
|
727
|
-
});
|
|
728
|
-
expect(lineIndexWrapped).toBeGreaterThanOrEqual(0);
|
|
729
|
-
var generatedColWrapped = linesWrapped[lineIndexWrapped].indexOf("b = 42");
|
|
730
|
-
expect(generatedColWrapped).toBeGreaterThan(0);
|
|
731
|
-
var posWrapped = consumerWrapped.originalPositionFor({
|
|
732
|
-
line: lineIndexWrapped + 1,
|
|
733
|
-
column: generatedColWrapped
|
|
734
|
-
});
|
|
735
|
-
expect(posWrapped.line).toBe(1);
|
|
736
|
-
expect(posWrapped.column).toBe(28);
|
|
737
|
-
expect(sourceCode.slice(Number(posWrapped.column))).toContain("b = 42;");
|
|
738
|
-
var resUnwrapped = await transform({
|
|
739
|
-
unstable_disableModuleWrapping: true
|
|
740
|
-
}, "/project", "app.js", Buffer.from(sourceCode, "utf8"), {
|
|
741
|
-
dev: false,
|
|
742
|
-
platform: "ios",
|
|
743
|
-
type: "module"
|
|
744
|
-
});
|
|
745
|
-
var fullMapUnwrapped = msm.fromRawMappings([{
|
|
746
|
-
code: resUnwrapped.output[0].data.code,
|
|
747
|
-
source: "app.js",
|
|
748
|
-
map: resUnwrapped.output[0].data.map
|
|
749
|
-
}]).toMap();
|
|
750
|
-
var consumerUnwrapped = new msm.Consumer(fullMapUnwrapped);
|
|
751
|
-
var linesUnwrapped = resUnwrapped.output[0].data.code.split("\n");
|
|
752
|
-
var lineIndexUnwrapped = linesUnwrapped.findIndex(function (l) {
|
|
753
|
-
return l.includes("b = 42");
|
|
754
|
-
});
|
|
755
|
-
expect(lineIndexUnwrapped).toBeGreaterThanOrEqual(0);
|
|
756
|
-
var generatedColUnwrapped = linesUnwrapped[lineIndexUnwrapped].indexOf("b = 42");
|
|
757
|
-
var posUnwrapped = consumerUnwrapped.originalPositionFor({
|
|
758
|
-
line: lineIndexUnwrapped + 1,
|
|
759
|
-
column: generatedColUnwrapped
|
|
760
|
-
});
|
|
761
|
-
expect(posUnwrapped.line).toBe(1);
|
|
762
|
-
expect(posUnwrapped.column).toBe(28);
|
|
763
|
-
});
|
|
764
|
-
it("routes a require.context whose directory is held in a variable through the dependency map", async function () {
|
|
765
|
-
var result = await transform({}, "/project", "entry.js", Buffer.from(`
|
|
766
|
-
const routeRoot = './app'
|
|
767
|
-
export const ctx = require.context(routeRoot, true, /\\.tsx$/)
|
|
768
|
-
`, "utf8"), {
|
|
769
|
-
dev: true,
|
|
770
|
-
platform: "ios",
|
|
771
|
-
type: "module"
|
|
772
|
-
});
|
|
773
|
-
var contextDep = result.dependencies.find(function (d) {
|
|
774
|
-
return d.data.contextParams != null;
|
|
775
|
-
});
|
|
776
|
-
expect(contextDep === null || contextDep === void 0 ? void 0 : contextDep.name).toBe("./app");
|
|
777
|
-
var calls = [];
|
|
778
|
-
var ctx;
|
|
779
|
-
vm.runInNewContext(result.output[0].data.code, {
|
|
780
|
-
__d: function (factory) {
|
|
781
|
-
var module = {
|
|
782
|
-
exports: {}
|
|
783
|
-
};
|
|
784
|
-
var req = function () {
|
|
785
|
-
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) args[_key] = arguments[_key];
|
|
786
|
-
calls.push(args);
|
|
787
|
-
return {
|
|
788
|
-
keys: function () {
|
|
789
|
-
return [];
|
|
790
|
-
}
|
|
791
|
-
};
|
|
792
|
-
};
|
|
793
|
-
req.context = function () {
|
|
794
|
-
throw new Error("fallbackRequireContext reached");
|
|
795
|
-
};
|
|
796
|
-
factory({}, req, function () {
|
|
797
|
-
return {};
|
|
798
|
-
}, function () {
|
|
799
|
-
return {};
|
|
800
|
-
}, module, module.exports, ["./app"]);
|
|
801
|
-
ctx = module.exports.ctx;
|
|
802
|
-
}
|
|
803
|
-
});
|
|
804
|
-
expect(ctx).toBeDefined();
|
|
805
|
-
expect(calls[0][1]).toBe("./app");
|
|
806
|
-
});
|
|
807
|
-
it("gives loop bodies per-iteration bindings that survive a runtime without them", async function () {
|
|
808
|
-
var asHermesWouldSeeIt = (await transform({}, "/project", "loops.ts", Buffer.from(`
|
|
809
|
-
export function collect() {
|
|
810
|
-
const out = []
|
|
811
|
-
for (let i = 0; i < 2; i++) out.push(() => i)
|
|
812
|
-
for (const label of ['a', 'b']) out.push(() => label)
|
|
813
|
-
for (const key in { x: 1, y: 2 }) out.push(() => key)
|
|
814
|
-
return out.map((f) => f())
|
|
815
|
-
}
|
|
816
|
-
`, "utf8"), {
|
|
817
|
-
dev: true,
|
|
818
|
-
platform: "ios",
|
|
819
|
-
type: "module"
|
|
820
|
-
})).output[0].data.code.replace(/\bfor\s*\(\s*(let|const)\b/g, "for (var");
|
|
821
|
-
var collect;
|
|
822
|
-
vm.runInNewContext(asHermesWouldSeeIt, {
|
|
823
|
-
__d: function (factory) {
|
|
824
|
-
var module = {
|
|
825
|
-
exports: {}
|
|
826
|
-
};
|
|
827
|
-
factory({}, function () {
|
|
828
|
-
return {};
|
|
829
|
-
}, function () {
|
|
830
|
-
return {};
|
|
831
|
-
}, function () {
|
|
832
|
-
return {};
|
|
833
|
-
}, module, module.exports, []);
|
|
834
|
-
collect = module.exports.collect;
|
|
835
|
-
}
|
|
836
|
-
});
|
|
837
|
-
expect(collect()).toEqual([0, 1, "a", "b", "x", "y"]);
|
|
838
|
-
});
|
|
839
|
-
});
|
|
840
|
-
describe("one native transform ports", function () {
|
|
841
|
-
it("inlines process.env.ONE_SERVER_URL so a native bundle can find its loaders", function () {
|
|
842
|
-
process.env.ONE_SERVER_URL = "https://example.test";
|
|
843
|
-
try {
|
|
844
|
-
expect(applyInlineEnvVars("export const url = process.env.ONE_SERVER_URL;", "loader.ts", false)).toBe("export const url = \"https://example.test\";");
|
|
845
|
-
} finally {
|
|
846
|
-
process.env.ONE_SERVER_URL = void 0;
|
|
847
|
-
}
|
|
848
|
-
});
|
|
849
|
-
it("leaves ONE_SERVER_URL alone when it is only a string", function () {
|
|
850
|
-
var src = "export const key = \"process.env.ONE_SERVER_URL\";";
|
|
851
|
-
expect(applyInlineEnvVars(src, "a.ts", false)).toBe(src);
|
|
852
|
-
});
|
|
853
|
-
it("inlines import.meta.env reads, which oxc otherwise lowers to an empty object", function () {
|
|
854
|
-
var out = applyInlineEnvVars(`export const key = import.meta.env.VITE_POSTHOG_API_KEY;
|
|
855
|
-
export const target = import.meta.env?.TAMAGUI_TARGET;
|
|
856
|
-
export const missing = import.meta.env.NOT_SET;
|
|
857
|
-
export const all = { ...import.meta.env };`, "env.ts", true, {
|
|
858
|
-
DEV: false,
|
|
859
|
-
VITE_POSTHOG_API_KEY: "pk_live",
|
|
860
|
-
TAMAGUI_TARGET: "native"
|
|
861
|
-
});
|
|
862
|
-
expect(out).toContain("export const key = \"pk_live\";");
|
|
863
|
-
expect(out).toContain("export const target = \"native\";");
|
|
864
|
-
expect(out).toContain("export const missing = undefined;");
|
|
865
|
-
expect(out).toContain("\"VITE_POSTHOG_API_KEY\":\"pk_live\"");
|
|
866
|
-
expect(out).not.toContain("import.meta");
|
|
867
|
-
});
|
|
868
|
-
it("inlines process.env keys the vite env map defines", function () {
|
|
869
|
-
var out = applyInlineEnvVars("export const t = process.env.TAMAGUI_TARGET; export const u = process.env.UNKNOWN_THING;", "env.ts", true, {
|
|
870
|
-
TAMAGUI_TARGET: "native"
|
|
871
|
-
});
|
|
872
|
-
expect(out).toContain("export const t = \"native\";");
|
|
873
|
-
expect(out).toContain("process.env.UNKNOWN_THING");
|
|
874
|
-
});
|
|
875
|
-
it("never rewrites an env read in an assignment target", function () {
|
|
876
|
-
var src = "process.env.VITE_ENVIRONMENT = \"ssr\";";
|
|
877
|
-
expect(applyInlineEnvVars(src, "a.ts", true, {
|
|
878
|
-
VITE_ENVIRONMENT: "ios"
|
|
879
|
-
})).toBe(src);
|
|
880
|
-
});
|
|
881
|
-
it("folds branches the inlining made constant so metro never resolves dead imports", function () {
|
|
882
|
-
var out = applyInlineEnvVars(`if (import.meta.env.SSR) { require('./server-only-thing') } else { load(import.meta.env.API) }`, "branch.ts", true, {
|
|
883
|
-
SSR: false,
|
|
884
|
-
API: "https://api.test"
|
|
885
|
-
});
|
|
886
|
-
expect(out).not.toContain("server-only-thing");
|
|
887
|
-
expect(out).toContain("load(\"https://api.test\")");
|
|
888
|
-
});
|
|
889
|
-
it("folds a ternary and keeps a branch it cannot resolve", function () {
|
|
890
|
-
expect(applyInlineEnvVars("const a = import.meta.env.DEV ? x : y;", "a.ts", true, {
|
|
891
|
-
DEV: false
|
|
892
|
-
})).toContain("const a = y;");
|
|
893
|
-
var dynamic = "const a = flag ? x : y;";
|
|
894
|
-
expect(applyInlineEnvVars(dynamic, "a.ts", true, {
|
|
895
|
-
DEV: false
|
|
896
|
-
})).toBe(dynamic);
|
|
897
|
-
});
|
|
898
|
-
it("runs the user native transforms that stand in for their babel plugins", async function () {
|
|
899
|
-
var result = await transform({}, import.meta.dirname, "ota.ts", Buffer.from("export const id = __EXAMPLE_BUILD_ID; export const from = __EXAMPLE_FILENAME;", "utf8"), {
|
|
900
|
-
dev: true,
|
|
901
|
-
platform: "ios",
|
|
902
|
-
type: "module",
|
|
903
|
-
customTransformOptions: {
|
|
904
|
-
vite: {
|
|
905
|
-
nativeTransformModules: ["./__fixtures__/exampleNativeTransform.cjs"]
|
|
906
|
-
}
|
|
907
|
-
}
|
|
908
|
-
});
|
|
909
|
-
assertZeroBabelCalls();
|
|
910
|
-
expect(result.output[0].data.code).toContain("\"ios-build\"");
|
|
911
|
-
expect(result.output[0].data.code).not.toContain("__EXAMPLE_BUILD_ID");
|
|
912
|
-
expect(result.output[0].data.code).toContain(JSON.stringify(path.join(import.meta.dirname, "ota.ts")));
|
|
913
|
-
});
|
|
914
|
-
it("refuses to build when a user babel plugin has no native port", function () {
|
|
915
|
-
var withPlugins = function (plugins) {
|
|
916
|
-
return {
|
|
917
|
-
customTransformOptions: {
|
|
918
|
-
vite: {
|
|
919
|
-
babelConfig: {
|
|
920
|
-
plugins
|
|
921
|
-
}
|
|
922
|
-
}
|
|
923
|
-
}
|
|
924
|
-
};
|
|
925
|
-
};
|
|
926
|
-
expect(function () {
|
|
927
|
-
return assertNoUnportedBabelPlugins(withPlugins([["@vxrn/vite-plugin-metro/babel-plugins/import-meta-env-plugin", {
|
|
928
|
-
env: {}
|
|
929
|
-
}], "one/babel-plugin-environment-guard", "hot-updater/babel-plugin"]));
|
|
930
|
-
}).toThrow(/hot-updater\/babel-plugin/);
|
|
931
|
-
expect(function () {
|
|
932
|
-
return assertNoUnportedBabelPlugins(withPlugins([["@vxrn/vite-plugin-metro/babel-plugins/import-meta-env-plugin", {
|
|
933
|
-
env: {}
|
|
934
|
-
}], "one/babel-plugin-environment-guard", ["one/babel-plugin-remove-server-code", {
|
|
935
|
-
routerRoot: "app"
|
|
936
|
-
}], ["babel-plugin-module-resolver", {
|
|
937
|
-
alias: {}
|
|
938
|
-
}], ["one/babel-plugin-one-router-metro", {}], "one/babel-plugin-inline-one-server-url", "babel-plugin-react-compiler", "react-native-reanimated/plugin"]));
|
|
939
|
-
}).not.toThrow();
|
|
940
|
-
});
|
|
941
|
-
it("turns a server-only import into a throw and drops native-only", function () {
|
|
942
|
-
var out = applyEnvironmentGuard(`import 'native-only'
|
|
943
|
-
|
|
944
|
-
export const a = 1`, "route.ts");
|
|
945
|
-
expect(out).not.toContain("native-only");
|
|
946
|
-
expect(out).toContain("server-only cannot be imported in a native environment");
|
|
947
|
-
var parsed = parseSync("route.ts", out, {
|
|
948
|
-
lang: "ts"
|
|
949
|
-
});
|
|
950
|
-
expect(parsed.errors).toEqual([]);
|
|
951
|
-
expect(parsed.program.body.map(function (n) {
|
|
952
|
-
return n.type;
|
|
953
|
-
})).toContain("ThrowStatement");
|
|
954
|
-
});
|
|
955
|
-
it("reads the router root off one's remove-server-code plugin entry", function () {
|
|
956
|
-
expect(getRemoveServerCodeRouterRoot({
|
|
957
|
-
customTransformOptions: {
|
|
958
|
-
vite: {
|
|
959
|
-
babelConfig: {
|
|
960
|
-
plugins: [["one/babel-plugin-remove-server-code", {
|
|
961
|
-
routerRoot: "src/app"
|
|
962
|
-
}]]
|
|
963
|
-
}
|
|
964
|
-
}
|
|
965
|
-
}
|
|
966
|
-
})).toBe("src/app");
|
|
967
|
-
expect(getRemoveServerCodeRouterRoot({
|
|
968
|
-
customTransformOptions: {}
|
|
969
|
-
})).toBe(void 0);
|
|
970
|
-
});
|
|
971
|
-
});
|
|
972
|
-
//# sourceMappingURL=metroNativeWorker.test.native.js.map
|