about summary refs log tree commit diff
path: root/metro.config.js
diff options
context:
space:
mode:
authorPaul Frazee <pfrazee@gmail.com>2022-06-14 20:17:08 -0500
committerPaul Frazee <pfrazee@gmail.com>2022-06-14 20:17:08 -0500
commit5066f3ba815d586f7d0f30135166aacf937480d6 (patch)
tree2711670316b7f50e1cd4b7cbfb0de46a3dd068f2 /metro.config.js
parentfee5317022600e60bed085c5c911078ada9d7774 (diff)
downloadvoidsky-5066f3ba815d586f7d0f30135166aacf937480d6.tar.zst
Work around lack of 'exports' directive support in metro
Diffstat (limited to 'metro.config.js')
-rw-r--r--metro.config.js45
1 files changed, 45 insertions, 0 deletions
diff --git a/metro.config.js b/metro.config.js
index c81b3ca13..9c99c9e98 100644
--- a/metro.config.js
+++ b/metro.config.js
@@ -4,8 +4,53 @@
  *
  * @format
  */
+const metroResolver = require('metro-resolver')
+const path = require('path')
+console.log(metroResolver)
 
 module.exports = {
+  resolver: {
+    resolveRequest: (context, moduleName, platform) => {
+      // metro doesn't support the "exports" directive in package.json
+      // so we have to manually fix some imports
+      // see https://github.com/facebook/metro/issues/670
+      if (moduleName.startsWith('ucans')) {
+        const subpath = moduleName.split('/').slice(1)
+        if (subpath.length === 0) {
+          subpath.push('index.js')
+        } else {
+          subpath[subpath.length - 1] = `${subpath[subpath.length - 1]}.js`
+        }
+        const filePath = path.join(
+          context.projectRoot,
+          'node_modules',
+          'ucans',
+          'dist',
+          'cjs',
+          ...subpath,
+        )
+        return {
+          type: 'sourceFile',
+          filePath,
+        }
+      }
+      if (moduleName === 'one-webcrypto') {
+        return {
+          type: 'sourceFile',
+          filePath: path.join(
+            context.projectRoot,
+            'node_modules',
+            'one-webcrypto',
+            'browser.mjs',
+          ),
+        }
+      }
+
+      // default resolve
+      delete context.resolveRequest
+      return metroResolver.resolve(context, moduleName, platform)
+    },
+  },
   transformer: {
     getTransformOptions: async () => ({
       transform: {