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