UNPKG

4.11 kBJavaScriptView Raw
1"use strict";
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6exports.default = load;
7exports.getDefaultConfig = void 0;
8
9function _path() {
10 const data = _interopRequireDefault(require("path"));
11
12 _path = function () {
13 return data;
14 };
15
16 return data;
17}
18
19function _metro() {
20 const data = require("metro");
21
22 _metro = function () {
23 return data;
24 };
25
26 return data;
27}
28
29function _metroConfig() {
30 const data = require("metro-config");
31
32 _metroConfig = function () {
33 return data;
34 };
35
36 return data;
37}
38
39function _fs() {
40 const data = require("fs");
41
42 _fs = function () {
43 return data;
44 };
45
46 return data;
47}
48
49var _findSymlinkedModules = _interopRequireDefault(require("./findSymlinkedModules"));
50
51function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
52
53function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; var ownKeys = Object.keys(source); if (typeof Object.getOwnPropertySymbols === 'function') { ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function (sym) { return Object.getOwnPropertyDescriptor(source, sym).enumerable; })); } ownKeys.forEach(function (key) { _defineProperty(target, key, source[key]); }); } return target; }
54
55function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
56
57function resolveSymlinksForRoots(roots) {
58 return roots.reduce((arr, rootPath) => arr.concat((0, _findSymlinkedModules.default)(rootPath, roots)), [...roots]);
59}
60
61function getWatchFolders() {
62 const root = process.env.REACT_NATIVE_APP_ROOT;
63 return root ? resolveSymlinksForRoots([_path().default.resolve(root)]) : [];
64}
65
66const getBlacklistRE = () => (0, _metro().createBlacklist)([/.*\/__fixtures__\/.*/]);
67
68const INTERNAL_CALLSITES_REGEX = new RegExp(['/Libraries/Renderer/implementations/.+\\.js$', '/Libraries/BatchedBridge/MessageQueue\\.js$', '/Libraries/YellowBox/.+\\.js$', '/node_modules/react-devtools-core/.+\\.js$'].join('|'));
69
70/**
71 * Default configuration
72 *
73 * @todo(grabbou): As a separate PR, haste.platforms should be added before "native".
74 * Otherwise, a.native.js will not load on Windows or other platforms
75 */
76const getDefaultConfig = ctx => {
77 const hasteImplPath = _path().default.join(ctx.reactNativePath, 'jest/hasteImpl.js');
78
79 return {
80 resolver: {
81 resolverMainFields: ['react-native', 'browser', 'main'],
82 blacklistRE: getBlacklistRE(),
83 platforms: [...ctx.haste.platforms, 'native'],
84 providesModuleNodeModules: ctx.haste.providesModuleNodeModules,
85 hasteImplModulePath: (0, _fs().existsSync)(hasteImplPath) ? hasteImplPath : undefined
86 },
87 serializer: {
88 getModulesRunBeforeMainModule: () => [require.resolve(_path().default.join(ctx.reactNativePath, 'Libraries/Core/InitializeCore'))],
89 getPolyfills: () => require(_path().default.join(ctx.reactNativePath, 'rn-get-polyfills'))()
90 },
91 server: {
92 port: Number(process.env.RCT_METRO_PORT) || 8081
93 },
94 symbolicator: {
95 customizeFrame: frame => {
96 const collapse = Boolean(frame.file && INTERNAL_CALLSITES_REGEX.test(frame.file));
97 return {
98 collapse
99 };
100 }
101 },
102 transformer: {
103 babelTransformerPath: require.resolve('metro-react-native-babel-transformer'),
104 assetRegistryPath: _path().default.join(ctx.reactNativePath, 'Libraries/Image/AssetRegistry')
105 },
106 watchFolders: getWatchFolders()
107 };
108};
109
110exports.getDefaultConfig = getDefaultConfig;
111
112/**
113 * Loads Metro Config and applies `options` on top of the resolved config.
114 *
115 * This allows the CLI to always overwrite the file settings.
116 */
117function load(ctx, options) {
118 const defaultConfig = getDefaultConfig(ctx);
119
120 if (options && options.reporter) {
121 defaultConfig.reporter = options.reporter;
122 }
123
124 return (0, _metroConfig().loadConfig)(_objectSpread({
125 cwd: ctx.root
126 }, options), defaultConfig);
127}
\No newline at end of file