1// Copyright 2021-present 650 Industries (Expo). All rights reserved.
2
3export function createModuleMatcher({
4  folders = ['node_modules'],
5  moduleIds,
6}: {
7  folders?: string[];
8  moduleIds: string[];
9}) {
10  const modulePathsGroup = folders.join('|');
11
12  const moduleMatchersGroup = moduleIds.join('|');
13
14  const moduleMatcherId =
15    '^' + [modulePathsGroup, moduleMatchersGroup].map((value) => `(?:${value})`).join('/');
16
17  return new RegExp(moduleMatcherId);
18}
19
20export const createReactNativeMatcher = ({ folders }: { folders?: string[] }) =>
21  createModuleMatcher({
22    folders,
23    moduleIds: ['react-native/'],
24  });
25
26export const createExpoMatcher = ({ folders }: { folders?: string[] }) =>
27  createModuleMatcher({
28    folders,
29    // We'll work to start reducing this.
30    moduleIds: ['expo', '@expo', '@unimodules', '@use-expo'],
31  });
32
33// TODO: Make this list as short as possible before releasing.
34// TODO: Add SDK version compat list.
35export const createKnownCommunityMatcher = ({
36  folders,
37  moduleIds = [],
38}: {
39  folders?: string[];
40  moduleIds?: string[];
41} = {}) =>
42  createModuleMatcher({
43    folders,
44    moduleIds: [
45      ...moduleIds,
46      // The more complex, the longer the entire project takes...
47      // react-native-community, react-native-masked-view, react-native-picker, react-native-segmented-control, react-native
48      '@react-',
49      // @sentry/react-native
50      '@(?:[\\w|-]+)/react-native',
51      'react-native-',
52      'victory-',
53      'native-base',
54      'styled-components',
55      // three.js
56      'three/build/three.module.js',
57      'three/examples/jsm',
58      // Special case for testing expo/expo repo
59      'html-elements/',
60      // shared-element
61      'react-navigation-',
62    ],
63  });
64