Fix metro failing to resolve @ipld/dag-cbor in dev mode
This commit is contained in:
+7
-1
@@ -35,7 +35,13 @@ module.exports = function (api) {
|
||||
// cannot use `env` field because it will put them after
|
||||
// the `react-native-worklets/plugin` plugin
|
||||
...(api.env('test')
|
||||
? ['@babel/plugin-transform-class-static-block']
|
||||
? [
|
||||
'@babel/plugin-transform-class-static-block',
|
||||
// Compile `import()` to require so jest (which runs without
|
||||
// `--experimental-vm-modules`) can execute lazily-loaded modules
|
||||
// like `@ipld/dag-cbor` via its moduleNameMapper.
|
||||
'@babel/plugin-transform-dynamic-import',
|
||||
]
|
||||
: []),
|
||||
...(api.env('production') ? ['transform-remove-console'] : []),
|
||||
|
||||
|
||||
@@ -123,14 +123,9 @@ function isPlainObject(v: any): boolean {
|
||||
/**
|
||||
* Load `@ipld/dag-cbor` on demand. The dynamic `import()` lets web bundlers
|
||||
* emit it (and its ~190KB `cborg` dependency) as a separate chunk that only
|
||||
* loads when posting a thread. Under jest (which runs without
|
||||
* `--experimental-vm-modules`) dynamic import throws, so we fall back to a
|
||||
* lazy `require`, which resolves through the test moduleNameMapper.
|
||||
* loads when posting a thread. Under jest this compiles down to a require
|
||||
* that resolves through the test moduleNameMapper.
|
||||
*/
|
||||
function importDagCbor(): Promise<typeof import('@ipld/dag-cbor')> {
|
||||
if (process.env.NODE_ENV === 'test') {
|
||||
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
||||
return Promise.resolve(require('@ipld/dag-cbor'))
|
||||
}
|
||||
return import('@ipld/dag-cbor')
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user