|
7 | 7 |
|
8 | 8 | const path = require('path');
|
9 | 9 | const { exclusionList, makeMetroConfig, resolveUniqueModule } = require('@rnx-kit/metro-config');
|
| 10 | +const MetroSymlinksResolver = require('@rnx-kit/metro-resolver-symlinks'); |
10 | 11 |
|
11 |
| -const [reactIs, reactIsExcludePattern] = resolveUniqueModule('react-is'); |
| 12 | +// ensure regex paths are merged, normalized, use forward slashes and end with a / |
| 13 | +function pathForRegex(...parts) { |
| 14 | + let result = path.normalize(path.join(...parts)); |
| 15 | + if (!result.endsWith(path.sep)) { |
| 16 | + result += path.sep; |
| 17 | + } |
| 18 | + return result.replace(/[/\\]+/g, '/'); |
| 19 | +} |
12 | 20 |
|
13 |
| -const blockList = exclusionList([ |
14 |
| - /node_modules\/.*\/node_modules\/react-native\/.*/, |
| 21 | +const excludeMixins = []; |
| 22 | +const extraNodeModules = {}; |
| 23 | +function ensureUniqueModule(moduleName, excludeList, nodeModules) { |
| 24 | + const [nmEntry, excludePattern] = resolveUniqueModule(moduleName); |
| 25 | + excludeMixins.push(excludePattern); |
| 26 | + extraNodeModules[moduleName] = nmEntry; |
| 27 | +} |
| 28 | + |
| 29 | +// build up the added excludes and extraNodeModules |
| 30 | +['react-is', 'invariant', '@babel/runtime', 'base64-js'].forEach((moduleName) => ensureUniqueModule(moduleName)); |
15 | 31 |
|
| 32 | +const blockList = exclusionList([ |
16 | 33 | // This stops "react-native run-windows" from causing the metro server to
|
17 |
| - // crash if its already running |
18 |
| - new RegExp(`${path.join(__dirname, 'windows').replace(/[/\\]+/g, '/')}.*`), |
| 34 | + // crash if its already running. This should also cover /.*\/.vs\/.*/, as .vs folders go next to the .sln file |
| 35 | + new RegExp(`${pathForRegex(__dirname, 'windows')}.*`), |
19 | 36 |
|
20 | 37 | // Workaround for `EPERM: operation not permitted, lstat '~\midl-MIDLRT-cl.read.1.tlog'`
|
21 |
| - /.*\.tlog/, |
22 |
| - |
23 |
| - // Prevent Metro from watching temporary files generated by Visual Studio |
24 |
| - // otherwise it may crash when they are removed when closing a project. |
25 |
| - /.*\/.vs\/.*/, |
| 38 | + /.*\.tlog$/, |
26 | 39 |
|
27 | 40 | // Workaround for `EBUSY: resource busy or locked, open '~\msbuild.ProjectImports.zip'`
|
28 |
| - /.*\.ProjectImports\.zip/, |
| 41 | + /.*\.ProjectImports\.zip$/, |
29 | 42 |
|
30 | 43 | // Exclude other test apps
|
31 |
| - /.*\/apps\/(?:win32)\/.*/, |
| 44 | + new RegExp(`${pathForRegex(__dirname, '../win32')}.*`), |
32 | 45 |
|
33 | 46 | // Exclude build output directory
|
34 |
| - /.*\/apps\/fluent-tester\/dist\/.*/, |
| 47 | + new RegExp(`${pathForRegex(__dirname, 'dist')}.*`), |
35 | 48 |
|
36 |
| - reactIsExcludePattern, |
| 49 | + ...excludeMixins, |
37 | 50 | ]);
|
38 | 51 |
|
39 | 52 | let config = makeMetroConfig({
|
40 | 53 | resolver: {
|
41 | 54 | blockList,
|
42 | 55 | extraNodeModules: {
|
43 |
| - 'react-is': reactIs, |
| 56 | + ...extraNodeModules, |
44 | 57 | },
|
| 58 | + resolveRequest: MetroSymlinksResolver(), |
45 | 59 | },
|
46 | 60 | transformer: {
|
47 | 61 | // This transformer selects between the regular transformer and svg transformer depending on the file type
|
|
0 commit comments