about summary refs log tree commit diff
path: root/metro.config.js
blob: 9dfaece89e0690299aed537169ae53c9f00b839b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
/**
 * Metro configuration for React Native
 * https://github.com/facebook/react-native
 *
 * @format
 */
const metroResolver = require('metro-resolver')
const path = require('path')
console.log(metroResolver)

module.exports = {
  resolver: {
    resolveRequest: (context, moduleName, platform) => {
      // HACK
      // 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
      // -prf
      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,
        }
      }
      // HACK
      // this module has the same problem with the "exports" module
      // but also we need modules to use our version of webcrypto
      // so here we're routing to a module we define
      // -prf
      if (moduleName === 'one-webcrypto') {
        return {
          type: 'sourceFile',
          filePath: path.join(
            context.projectRoot,
            'src',
            'platform',
            'polyfills.native.ts',
          ),
        }
      }

      // default resolve
      delete context.resolveRequest
      return metroResolver.resolve(context, moduleName, platform)
    },
  },
  transformer: {
    getTransformOptions: async () => ({
      transform: {
        experimentalImportSupport: false,
        inlineRequires: true,
      },
    }),
  },
}