diff --git a/babel.config.js b/babel.config.js index 96a3472dea..43e7eb54f3 100644 --- a/babel.config.js +++ b/babel.config.js @@ -37,10 +37,6 @@ module.exports = function (api) { alias: { // This needs to be mirrored in tsconfig.json '#': './src', - lib: './src/lib', - platform: './src/platform', - state: './src/state', - view: './src/view', crypto: './src/platform/crypto.ts', }, }, diff --git a/metro.config.js b/metro.config.js index 15afb59ada..dcdead3f5d 100644 --- a/metro.config.js +++ b/metro.config.js @@ -16,7 +16,25 @@ if (process.env.BSKY_PROFILE) { cfg.resolver.assetExts = [...cfg.resolver.assetExts, 'woff2'] +// Enabled by default in RN 0.79+, but this breaks Lingui + others +cfg.resolver.unstable_enablePackageExports = false + cfg.resolver.resolveRequest = (context, moduleName, platform) => { + // HACK: manually resolve a few packages that use `exports` in `package.json`. + // A proper solution is to enable `unstable_enablePackageExports` but this needs careful testing. + if (moduleName.startsWith('multiformats/hashes/hasher')) { + return context.resolveRequest( + context, + 'multiformats/cjs/src/hashes/hasher', + platform, + ) + } + if (moduleName.startsWith('multiformats/cid')) { + return context.resolveRequest(context, 'multiformats/cjs/src/cid', platform) + } + if (moduleName === '@ipld/dag-cbor') { + return context.resolveRequest(context, '@ipld/dag-cbor/src', platform) + } if (process.env.BSKY_PROFILE) { if (moduleName.endsWith('ReactNativeRenderer-prod')) { return context.resolveRequest( diff --git a/src/lib/api/index.ts b/src/lib/api/index.ts index d437570c9d..7621fbb4cc 100644 --- a/src/lib/api/index.ts +++ b/src/lib/api/index.ts @@ -19,7 +19,8 @@ import * as dcbor from '@ipld/dag-cbor' import {t} from '@lingui/macro' import {type QueryClient} from '@tanstack/react-query' import {sha256} from 'js-sha256' -import {CID, hasher} from 'multiformats' +import {CID} from 'multiformats/cid' +import * as Hasher from 'multiformats/hashes/hasher' import {isNetworkError} from '#/lib/strings/errors' import {shortenLinks, stripInvalidMentions} from '#/lib/strings/rich-text-manip' @@ -409,7 +410,7 @@ async function resolveRecord( // The built-in hashing functions from multiformats (`multiformats/hashes/sha2`) // are meant for Node.js, this is the cross-platform equivalent. -const mf_sha256 = hasher.from({ +const mf_sha256 = Hasher.from({ name: 'sha2-256', code: 0x12, encode: input => { diff --git a/tsconfig.json b/tsconfig.json index b64b587aae..c75a30b05f 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -7,12 +7,9 @@ "baseUrl": ".", "paths": { "#/*": ["./src/*"], - "lib/*": ["./src/lib/*"], - "platform/*": ["./src/platform/*"], - "state/*": ["./src/state/*"], - "view/*": ["./src/view/*"], "crypto": ["./src/platform/crypto.ts"], - "multiformats": ["node_modules/multiformats/types/src/index.d.ts"] + "multiformats/cid": ["node_modules/multiformats/types/src/cid.d.ts"], + "multiformats/hashes/hasher": ["node_modules/multiformats/types/src/hashes/hasher.d.ts"] } }, "exclude": ["bskyweb", "bskyembed", "web-build"]