diff options
author | Paul Frazee <pfrazee@gmail.com> | 2022-06-14 20:17:08 -0500 |
---|---|---|
committer | Paul Frazee <pfrazee@gmail.com> | 2022-06-14 20:17:08 -0500 |
commit | 5066f3ba815d586f7d0f30135166aacf937480d6 (patch) | |
tree | 2711670316b7f50e1cd4b7cbfb0de46a3dd068f2 /metro.config.js | |
parent | fee5317022600e60bed085c5c911078ada9d7774 (diff) | |
download | voidsky-5066f3ba815d586f7d0f30135166aacf937480d6.tar.zst |
Work around lack of 'exports' directive support in metro
Diffstat (limited to 'metro.config.js')
-rw-r--r-- | metro.config.js | 45 |
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: { |