2022-06-08 00:50:05 +02:00
|
|
|
/**
|
|
|
|
* Metro configuration for React Native
|
|
|
|
* https://github.com/facebook/react-native
|
|
|
|
*
|
|
|
|
* @format
|
|
|
|
*/
|
2022-06-15 03:17:08 +02:00
|
|
|
const metroResolver = require('metro-resolver')
|
|
|
|
const path = require('path')
|
2022-06-08 00:50:05 +02:00
|
|
|
|
|
|
|
module.exports = {
|
2022-06-15 03:17:08 +02:00
|
|
|
resolver: {
|
|
|
|
resolveRequest: (context, moduleName, platform) => {
|
2022-06-16 00:40:18 +02:00
|
|
|
// HACK
|
2022-06-15 03:17:08 +02:00
|
|
|
// 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
|
2022-06-16 00:40:18 +02:00
|
|
|
// -prf
|
2022-06-15 03:17:08 +02:00
|
|
|
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,
|
|
|
|
}
|
|
|
|
}
|
2022-06-16 00:40:18 +02:00
|
|
|
// 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
|
2022-06-15 03:17:08 +02:00
|
|
|
if (moduleName === 'one-webcrypto') {
|
|
|
|
return {
|
|
|
|
type: 'sourceFile',
|
|
|
|
filePath: path.join(
|
|
|
|
context.projectRoot,
|
2022-06-16 00:40:18 +02:00
|
|
|
'src',
|
|
|
|
'platform',
|
|
|
|
'polyfills.native.ts',
|
2022-06-15 03:17:08 +02:00
|
|
|
),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// default resolve
|
|
|
|
delete context.resolveRequest
|
|
|
|
return metroResolver.resolve(context, moduleName, platform)
|
|
|
|
},
|
|
|
|
},
|
2022-06-08 00:50:05 +02:00
|
|
|
transformer: {
|
|
|
|
getTransformOptions: async () => ({
|
|
|
|
transform: {
|
|
|
|
experimentalImportSupport: false,
|
|
|
|
inlineRequires: true,
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
},
|
2022-06-09 20:03:25 +02:00
|
|
|
}
|