Repository navigation
Expand file tree
/
Copy pathmetro.config.js
More file actions
62 lines (55 loc) · 2.07 KB
/
Copy pathmetro.config.js
File metadata and controls
62 lines (55 loc) · 2.07 KB
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
const { getDefaultConfig, mergeConfig } = require('@react-native/metro-config')
const path = require('path')
const pak = require('../../package.json')
const root = path.resolve(__dirname, '../..')
const modules = Object.keys({ ...pak.peerDependencies })
const corePath = path
.join(root, 'packages/react-native-nitro-modules/nitro')
.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')
function escapeRegExp(string) {
return string.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')
}
// Metro blocks every `__tests__` directory by default. The in-app test runner
// bundles this app's Harness tests, so only block the other ones.
const appTestsDirectory = path.join(__dirname, '__tests__') + path.sep
const otherTestDirectories = new RegExp(
`^(?!${escapeRegExp(appTestsDirectory)}).*[/\\\\]__tests__[/\\\\].*`
)
/**
* Metro configuration
* https://facebook.github.io/metro/docs/configuration
*
* @type {import('@react-native/metro-config').MetroConfig}
*/
const config = {
watchFolders: [root],
// We need to make sure that only one version is loaded for peerDependencies
// So we block them at the root, and alias them to the versions in example's node_modules
resolver: {
// Native sources are staged in the RN package. Only nitro-core is a JS workspace.
blockList: [
otherTestDirectories,
new RegExp(
`^${corePath}[/\\\\](?!packages(?:[/\\\\]nitro-core(?:[/\\\\]|$)|$)).*`
),
],
extraNodeModules: modules.reduce((acc, name) => {
acc[name] = path.join(__dirname, 'node_modules', name)
return acc
}, {}),
// Test files can only be evaluated while Harness collects tests, so a
// Fast Refresh of one must reload the whole app.
unstable_forceFullRefreshPatterns: [/\.harness\.[jt]sx?$/],
},
transformer: {
// The in-app test runner finds the test files with `require.context`.
unstable_allowRequireContext: true,
getTransformOptions: async () => ({
transform: {
experimentalImportSupport: false,
inlineRequires: true,
},
}),
},
}
module.exports = mergeConfig(getDefaultConfig(__dirname), config)