@expo/metro-config 0.5.2 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (29) hide show
  1. package/build/ExpoMetroConfig.d.ts +1 -4
  2. package/build/ExpoMetroConfig.js +61 -145
  3. package/build/ExpoMetroConfig.js.map +1 -1
  4. package/build/getModulesPaths.js +3 -14
  5. package/build/getModulesPaths.js.map +1 -1
  6. package/build/getWatchFolders.js +32 -48
  7. package/build/getWatchFolders.js.map +1 -1
  8. package/build/importMetroFromProject.js +0 -13
  9. package/build/importMetroFromProject.js.map +1 -1
  10. package/build/transformer/createExoticTransformer.js +21 -24
  11. package/build/transformer/createExoticTransformer.js.map +1 -1
  12. package/build/transformer/createMatcher.js +14 -14
  13. package/build/transformer/createMatcher.js.map +1 -1
  14. package/build/transformer/createMultiRuleTransformer.d.ts +1 -1
  15. package/build/transformer/createMultiRuleTransformer.js +78 -101
  16. package/build/transformer/createMultiRuleTransformer.js.map +1 -1
  17. package/build/transformer/generateFunctionMap.js +0 -5
  18. package/build/transformer/generateFunctionMap.js.map +1 -1
  19. package/build/transformer/getBabelConfig.js +26 -40
  20. package/build/transformer/getBabelConfig.js.map +1 -1
  21. package/build/transformer/getCacheKey.js +6 -13
  22. package/build/transformer/getCacheKey.js.map +1 -1
  23. package/build/transformer/index.js +0 -12
  24. package/build/transformer/index.js.map +1 -1
  25. package/build/transformer/metro-expo-babel-transformer.js +2 -14
  26. package/build/transformer/metro-expo-babel-transformer.js.map +1 -1
  27. package/build/transformer/metro-expo-exotic-babel-transformer.js +1 -3
  28. package/build/transformer/metro-expo-exotic-babel-transformer.js.map +1 -1
  29. package/package.json +3 -4
@@ -5,77 +5,57 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.createMultiRuleTransformer = createMultiRuleTransformer;
7
7
  exports.loaders = void 0;
8
-
9
8
  function _chalk() {
10
9
  const data = _interopRequireDefault(require("chalk"));
11
-
12
10
  _chalk = function () {
13
11
  return data;
14
12
  };
15
-
16
13
  return data;
17
14
  }
18
-
19
15
  function _debug() {
20
16
  const data = _interopRequireDefault(require("debug"));
21
-
22
17
  _debug = function () {
23
18
  return data;
24
19
  };
25
-
26
20
  return data;
27
21
  }
28
-
29
22
  function _resolveFrom() {
30
23
  const data = _interopRequireDefault(require("resolve-from"));
31
-
32
24
  _resolveFrom = function () {
33
25
  return data;
34
26
  };
35
-
36
27
  return data;
37
28
  }
38
-
39
29
  function _generateFunctionMap() {
40
30
  const data = require("./generateFunctionMap");
41
-
42
31
  _generateFunctionMap = function () {
43
32
  return data;
44
33
  };
45
-
46
34
  return data;
47
35
  }
48
-
49
36
  function _getBabelConfig() {
50
37
  const data = require("./getBabelConfig");
51
-
52
38
  _getBabelConfig = function () {
53
39
  return data;
54
40
  };
55
-
56
41
  return data;
57
42
  }
58
-
59
43
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
60
-
61
44
  // Copyright 2021-present 650 Industries (Expo). All rights reserved.
45
+
62
46
  const debug = (0, _debug().default)('expo:metro:exotic-babel-transformer');
63
47
  let babelCore;
64
-
65
48
  function getBabelCoreFromProject(projectRoot) {
66
49
  if (babelCore) return babelCore;
67
50
  babelCore = require((0, _resolveFrom().default)(projectRoot, '@babel/core'));
68
51
  return babelCore;
69
52
  }
70
-
71
53
  let babelParser;
72
-
73
54
  function getBabelParserFromProject(projectRoot) {
74
55
  if (babelParser) return babelParser;
75
56
  babelParser = require((0, _resolveFrom().default)(projectRoot, '@babel/parser'));
76
57
  return babelParser;
77
58
  }
78
-
79
59
  function sucrase(args, {
80
60
  transforms
81
61
  }) {
@@ -86,11 +66,9 @@ function sucrase(args, {
86
66
  dev
87
67
  }
88
68
  } = args;
89
-
90
69
  const {
91
70
  transform
92
71
  } = require('sucrase');
93
-
94
72
  const results = transform(src, {
95
73
  filePath: filename,
96
74
  production: !dev,
@@ -101,16 +79,13 @@ function sucrase(args, {
101
79
  functionMap: null
102
80
  };
103
81
  }
104
-
105
82
  const getExpensiveSucraseTransforms = filename => ['jsx', 'imports', /\.tsx?$/.test(filename) ? 'typescript' : 'flow'];
106
-
107
83
  function parseAst(projectRoot, sourceCode) {
108
84
  const babylon = getBabelParserFromProject(projectRoot);
109
85
  return babylon.parse(sourceCode, {
110
86
  sourceType: 'unambiguous'
111
87
  });
112
88
  }
113
-
114
89
  /** Create a transformer that emulates Webpack's loader system. */
115
90
  function createMultiRuleTransformer({
116
91
  getRuleType,
@@ -124,27 +99,25 @@ function createMultiRuleTransformer({
124
99
  } = args;
125
100
  const OLD_BABEL_ENV = process.env.BABEL_ENV;
126
101
  process.env.BABEL_ENV = options !== null && options !== void 0 && options.dev ? 'development' : process.env.BABEL_ENV || 'production';
127
-
128
102
  try {
129
103
  const ruleType = getRuleType(args);
130
-
131
104
  for (const rule of rules) {
132
105
  // optimization for checking node modules
133
106
  if (rule.type && rule.type !== ruleType) {
134
107
  continue;
135
108
  }
136
-
137
109
  const isMatched = typeof rule.test === 'function' ? rule.test(args) : rule.test.test(args.filename);
138
-
139
110
  if (isMatched) {
140
- const results = rule.transform(args); // @ts-ignore: Add extra property for testing
141
-
142
- results._ruleName = rule.name; // Perform a basic parse if none exists, this enables us to control the output, but only if it changed.
143
-
111
+ const results = rule.transform(args);
112
+ // @ts-ignore: Add extra property for testing
113
+ results._ruleName = rule.name;
114
+ // Perform a basic parse if none exists, this enables us to control the output, but only if it changed.
144
115
  if (results.code && !results.ast) {
145
116
  // Parse AST with babel otherwise Metro transformer will throw away the returned results.
146
117
  results.ast = parseAst(options === null || options === void 0 ? void 0 : options.projectRoot, results.code);
147
- } // TODO: Suboptimal warnings
118
+ }
119
+
120
+ // TODO: Suboptimal warnings
148
121
  // if (rule.warn) {
149
122
  // const matchName =
150
123
  // filename.match(/node_modules\/((:?@[\w\d-]+\/[\w\d-]+)|(:?[\w\d-]+))\/?/)?.[1] ??
@@ -158,11 +131,9 @@ function createMultiRuleTransformer({
158
131
  // }
159
132
  // }
160
133
 
161
-
162
134
  return results;
163
135
  }
164
136
  }
165
-
166
137
  throw new Error('no loader rule to handle file: ' + filename);
167
138
  } finally {
168
139
  if (OLD_BABEL_ENV) {
@@ -171,85 +142,91 @@ function createMultiRuleTransformer({
171
142
  }
172
143
  };
173
144
  }
145
+ function app(args) {
146
+ debug('app:', args.filename);
147
+ const {
148
+ filename,
149
+ options,
150
+ src,
151
+ plugins
152
+ } = args;
153
+ const babelConfig = {
154
+ // ES modules require sourceType='module' but OSS may not always want that
155
+ sourceType: 'unambiguous',
156
+ ...(0, _getBabelConfig().getBabelConfig)(filename, options, plugins),
157
+ // Variables that are exposed to the user's babel preset.
158
+ caller: {
159
+ name: 'metro',
160
+ platform: options.platform
161
+ },
162
+ ast: true
163
+ };
174
164
 
175
- const loaders = {
176
- // Perform the standard, and most expensive transpilation sequence.
177
- app(args) {
178
- debug('app:', args.filename);
179
- const {
180
- filename,
181
- options,
182
- src,
183
- plugins
184
- } = args;
185
- const babelConfig = {
186
- // ES modules require sourceType='module' but OSS may not always want that
187
- sourceType: 'unambiguous',
188
- ...(0, _getBabelConfig().getBabelConfig)(filename, options, plugins),
189
- // Variables that are exposed to the user's babel preset.
190
- caller: {
191
- name: 'metro',
192
- platform: options.platform
193
- },
194
- ast: true
195
- }; // Surface a warning function so babel linters can be used.
196
-
197
- Object.defineProperty(babelConfig.caller, 'onWarning', {
198
- enumerable: false,
199
- writable: false,
200
- value: babelConfig.caller.onWarning = function (msg) {
201
- // Format the file path first so users know where the warning came from.
202
- console.warn(_chalk().default.bold.yellow`warn ` + args.filename);
203
- console.warn(msg);
204
- }
205
- });
206
- const {
207
- parseSync,
208
- transformFromAstSync
209
- } = getBabelCoreFromProject(options.projectRoot);
210
- const sourceAst = parseSync(src, babelConfig); // Should never happen.
211
-
212
- if (!sourceAst) return {
213
- ast: null
214
- };
215
- const result = transformFromAstSync(sourceAst, src, babelConfig); // TODO: Disable by default
216
-
217
- const functionMap = (0, _generateFunctionMap().generateFunctionMap)(options.projectRoot, sourceAst, {
218
- filename
219
- }); // The result from `transformFromAstSync` can be null (if the file is ignored)
220
-
221
- if (!result) {
222
- return {
223
- ast: null,
224
- functionMap
225
- };
165
+ // Surface a warning function so babel linters can be used.
166
+ Object.defineProperty(babelConfig.caller, 'onWarning', {
167
+ enumerable: false,
168
+ writable: false,
169
+ value: babelConfig.caller.onWarning = function (msg) {
170
+ // Format the file path first so users know where the warning came from.
171
+ console.warn(_chalk().default.bold.yellow`warn ` + args.filename);
172
+ console.warn(msg);
226
173
  }
174
+ });
175
+ const {
176
+ parseSync,
177
+ transformFromAstSync
178
+ } = getBabelCoreFromProject(options.projectRoot);
179
+ const sourceAst = parseSync(src, babelConfig);
180
+
181
+ // Should never happen.
182
+ if (!sourceAst) return {
183
+ ast: null
184
+ };
185
+ const result = transformFromAstSync(sourceAst, src, babelConfig);
227
186
 
187
+ // TODO: Disable by default
188
+ const functionMap = (0, _generateFunctionMap().generateFunctionMap)(options.projectRoot, sourceAst, {
189
+ filename
190
+ });
191
+ // The result from `transformFromAstSync` can be null (if the file is ignored)
192
+ if (!result) {
228
193
  return {
229
- ast: result.ast,
194
+ ast: null,
230
195
  functionMap
231
196
  };
232
- },
233
-
197
+ }
198
+ return {
199
+ ast: result.ast,
200
+ functionMap
201
+ };
202
+ }
203
+ const loaders = {
204
+ // Perform the standard, and most expensive transpilation sequence.
205
+ app,
234
206
  // Transpile react-native with sucrase.
235
207
  reactNativeModule(args) {
208
+ // Special file needs full transpilation.
209
+ if (args.filename.includes('react-native/Libraries/Events/EventPolyfill.js')) {
210
+ // Match React Native modules which use non-standard flow features, convert them using babel (most expensive).
211
+ return app(args);
212
+ }
236
213
  debug('rn:', args.filename);
237
214
  return sucrase(args, {
238
215
  transforms: ['jsx', 'flow', 'imports']
239
216
  });
240
217
  },
241
-
242
218
  // Transpile expo modules with sucrase.
243
219
  expoModule(args) {
244
- debug('expo:', args.filename); // TODO: Fix all expo packages
245
-
220
+ debug('expo:', args.filename);
221
+ // TODO: Fix all expo packages
246
222
  return sucrase(args, {
247
- transforms: ['imports', // TODO: fix expo-processing, expo/vector-icons
248
- /(expo-processing|expo\/vector-icons)/.test(args.filename) && 'jsx', // TODO: fix expo-asset-utils
223
+ transforms: ['imports',
224
+ // TODO: fix expo-processing, expo/vector-icons
225
+ /(expo-processing|expo\/vector-icons)/.test(args.filename) && 'jsx',
226
+ // TODO: fix expo-asset-utils
249
227
  /(expo-asset-utils)/.test(args.filename) && 'flow'].filter(Boolean)
250
228
  });
251
229
  },
252
-
253
230
  // Transpile known community modules with the most expensive sucrase
254
231
  untranspiledModule(args) {
255
232
  debug('known issues:', args.filename);
@@ -257,7 +234,6 @@ const loaders = {
257
234
  transforms: getExpensiveSucraseTransforms(args.filename)
258
235
  });
259
236
  },
260
-
261
237
  // Pass all modules through without transpiling them.
262
238
  passthroughModule(args) {
263
239
  const {
@@ -265,10 +241,12 @@ const loaders = {
265
241
  options,
266
242
  src
267
243
  } = args;
268
- debug('passthrough:', filename); // Perform a basic ast parse, this doesn't matter since the worker will parse and ignore anyways.
244
+ debug('passthrough:', filename);
269
245
 
270
- const ast = parseAst(options.projectRoot, src); // TODO: Disable by default
246
+ // Perform a basic ast parse, this doesn't matter since the worker will parse and ignore anyways.
247
+ const ast = parseAst(options.projectRoot, src);
271
248
 
249
+ // TODO: Disable by default
272
250
  const functionMap = (0, _generateFunctionMap().generateFunctionMap)(options.projectRoot, ast, {
273
251
  filename
274
252
  });
@@ -278,7 +256,6 @@ const loaders = {
278
256
  ast
279
257
  };
280
258
  }
281
-
282
259
  };
283
260
  exports.loaders = loaders;
284
261
  //# sourceMappingURL=createMultiRuleTransformer.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"createMultiRuleTransformer.js","names":["debug","Debug","babelCore","getBabelCoreFromProject","projectRoot","require","resolveFrom","babelParser","getBabelParserFromProject","sucrase","args","transforms","src","filename","options","dev","transform","results","filePath","production","code","functionMap","getExpensiveSucraseTransforms","test","parseAst","sourceCode","babylon","parse","sourceType","createMultiRuleTransformer","getRuleType","rules","OLD_BABEL_ENV","process","env","BABEL_ENV","ruleType","rule","type","isMatched","_ruleName","name","ast","Error","loaders","app","plugins","babelConfig","getBabelConfig","caller","platform","Object","defineProperty","enumerable","writable","value","onWarning","msg","console","warn","chalk","bold","yellow","parseSync","transformFromAstSync","sourceAst","result","generateFunctionMap","reactNativeModule","expoModule","filter","Boolean","untranspiledModule","passthroughModule"],"sources":["../../src/transformer/createMultiRuleTransformer.ts"],"sourcesContent":["// Copyright 2021-present 650 Industries (Expo). All rights reserved.\n\nimport chalk from 'chalk';\nimport Debug from 'debug';\nimport type { BabelTransformer, BabelTransformerArgs } from 'metro-babel-transformer';\nimport resolveFrom from 'resolve-from';\n\nimport { generateFunctionMap } from './generateFunctionMap';\nimport { getBabelConfig } from './getBabelConfig';\n\nconst debug = Debug('expo:metro:exotic-babel-transformer');\n\nlet babelCore: typeof import('@babel/core') | undefined;\n\nfunction getBabelCoreFromProject(projectRoot: string) {\n if (babelCore) return babelCore;\n babelCore = require(resolveFrom(projectRoot, '@babel/core'));\n return babelCore!;\n}\n\nlet babelParser: typeof import('@babel/parser') | undefined;\n\nfunction getBabelParserFromProject(projectRoot: string) {\n if (babelParser) return babelParser;\n babelParser = require(resolveFrom(projectRoot, '@babel/parser'));\n return babelParser!;\n}\n\nfunction sucrase(\n args: BabelTransformerArgs,\n {\n transforms,\n }: {\n transforms: string[];\n }\n): Partial<ReturnType<BabelTransformer['transform']>> {\n const {\n src,\n filename,\n options: { dev },\n } = args;\n const { transform } = require('sucrase');\n\n const results = transform(src, {\n filePath: filename,\n production: !dev,\n transforms,\n });\n\n return {\n code: results.code,\n functionMap: null,\n };\n}\n\nconst getExpensiveSucraseTransforms = (filename: string) => [\n 'jsx',\n 'imports',\n /\\.tsx?$/.test(filename) ? 'typescript' : 'flow',\n];\n\nfunction parseAst(projectRoot: string, sourceCode: string) {\n const babylon = getBabelParserFromProject(projectRoot);\n\n return babylon.parse(sourceCode, {\n sourceType: 'unambiguous',\n });\n}\n\nexport type Rule = {\n warn?: boolean;\n type?: 'module' | 'app';\n name?: string;\n test: ((args: BabelTransformerArgs) => boolean) | RegExp;\n transform: BabelTransformer['transform'];\n};\n\n/** Create a transformer that emulates Webpack's loader system. */\nexport function createMultiRuleTransformer({\n getRuleType,\n rules,\n}: {\n getRuleType: (args: BabelTransformerArgs) => string;\n rules: Rule[];\n}): BabelTransformer['transform'] {\n // const warnings: string[] = [];\n return function transform(args: BabelTransformerArgs) {\n const { filename, options } = args;\n const OLD_BABEL_ENV = process.env.BABEL_ENV;\n process.env.BABEL_ENV = options?.dev ? 'development' : process.env.BABEL_ENV || 'production';\n\n try {\n const ruleType = getRuleType(args);\n\n for (const rule of rules) {\n // optimization for checking node modules\n if (rule.type && rule.type !== ruleType) {\n continue;\n }\n\n const isMatched =\n typeof rule.test === 'function' ? rule.test(args) : rule.test.test(args.filename);\n if (isMatched) {\n const results = rule.transform(args);\n // @ts-ignore: Add extra property for testing\n results._ruleName = rule.name;\n // Perform a basic parse if none exists, this enables us to control the output, but only if it changed.\n if (results.code && !results.ast) {\n // Parse AST with babel otherwise Metro transformer will throw away the returned results.\n results.ast = parseAst(options?.projectRoot, results.code);\n }\n\n // TODO: Suboptimal warnings\n // if (rule.warn) {\n // const matchName =\n // filename.match(/node_modules\\/((:?@[\\w\\d-]+\\/[\\w\\d-]+)|(:?[\\w\\d-]+))\\/?/)?.[1] ??\n // filename;\n // if (matchName && !warnings.includes(matchName)) {\n // warnings.push(matchName);\n // console.warn(chalk.yellow.bold`warn `, matchName);\n // console.warn(\n // chalk.yellow`untranspiled module is potentially causing bundler slowdown, using modules that support commonjs will make your dev server much faster.`\n // );\n // }\n // }\n\n return results;\n }\n }\n throw new Error('no loader rule to handle file: ' + filename);\n } finally {\n if (OLD_BABEL_ENV) {\n process.env.BABEL_ENV = OLD_BABEL_ENV;\n }\n }\n };\n}\n\nexport const loaders: Record<string, (args: BabelTransformerArgs) => any> = {\n // Perform the standard, and most expensive transpilation sequence.\n app(args) {\n debug('app:', args.filename);\n\n const { filename, options, src, plugins } = args;\n const babelConfig = {\n // ES modules require sourceType='module' but OSS may not always want that\n sourceType: 'unambiguous',\n ...getBabelConfig(filename, options, plugins),\n // Variables that are exposed to the user's babel preset.\n caller: {\n name: 'metro',\n\n platform: options.platform,\n },\n ast: true,\n };\n\n // Surface a warning function so babel linters can be used.\n Object.defineProperty(babelConfig.caller, 'onWarning', {\n enumerable: false,\n writable: false,\n value: (babelConfig.caller.onWarning = function (msg: any) {\n // Format the file path first so users know where the warning came from.\n console.warn(chalk.bold.yellow`warn ` + args.filename);\n console.warn(msg);\n }),\n });\n\n const { parseSync, transformFromAstSync } = getBabelCoreFromProject(options.projectRoot);\n const sourceAst = parseSync(src, babelConfig);\n\n // Should never happen.\n if (!sourceAst) return { ast: null };\n\n const result = transformFromAstSync(sourceAst, src, babelConfig);\n\n // TODO: Disable by default\n const functionMap = generateFunctionMap(options.projectRoot, sourceAst, { filename });\n // The result from `transformFromAstSync` can be null (if the file is ignored)\n if (!result) {\n return { ast: null, functionMap };\n }\n\n return { ast: result.ast, functionMap };\n },\n\n // Transpile react-native with sucrase.\n reactNativeModule(args) {\n debug('rn:', args.filename);\n return sucrase(args, {\n transforms: ['jsx', 'flow', 'imports'],\n });\n },\n\n // Transpile expo modules with sucrase.\n expoModule(args) {\n debug('expo:', args.filename);\n // TODO: Fix all expo packages\n return sucrase(args, {\n transforms: [\n 'imports',\n // TODO: fix expo-processing, expo/vector-icons\n /(expo-processing|expo\\/vector-icons)/.test(args.filename) && 'jsx',\n // TODO: fix expo-asset-utils\n /(expo-asset-utils)/.test(args.filename) && 'flow',\n ].filter(Boolean) as string[],\n });\n },\n\n // Transpile known community modules with the most expensive sucrase\n untranspiledModule(args) {\n debug('known issues:', args.filename);\n return sucrase(args, {\n transforms: getExpensiveSucraseTransforms(args.filename),\n });\n },\n\n // Pass all modules through without transpiling them.\n passthroughModule(args) {\n const { filename, options, src } = args;\n debug('passthrough:', filename);\n\n // Perform a basic ast parse, this doesn't matter since the worker will parse and ignore anyways.\n const ast = parseAst(options.projectRoot, src);\n\n // TODO: Disable by default\n const functionMap = generateFunctionMap(options.projectRoot, ast, { filename });\n\n return {\n code: src,\n functionMap,\n ast,\n };\n },\n};\n"],"mappings":";;;;;;;;AAEA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AAEA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AAEA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;;;AARA;AAUA,MAAMA,KAAK,GAAG,IAAAC,gBAAA,EAAM,qCAAN,CAAd;AAEA,IAAIC,SAAJ;;AAEA,SAASC,uBAAT,CAAiCC,WAAjC,EAAsD;EACpD,IAAIF,SAAJ,EAAe,OAAOA,SAAP;EACfA,SAAS,GAAGG,OAAO,CAAC,IAAAC,sBAAA,EAAYF,WAAZ,EAAyB,aAAzB,CAAD,CAAnB;EACA,OAAOF,SAAP;AACD;;AAED,IAAIK,WAAJ;;AAEA,SAASC,yBAAT,CAAmCJ,WAAnC,EAAwD;EACtD,IAAIG,WAAJ,EAAiB,OAAOA,WAAP;EACjBA,WAAW,GAAGF,OAAO,CAAC,IAAAC,sBAAA,EAAYF,WAAZ,EAAyB,eAAzB,CAAD,CAArB;EACA,OAAOG,WAAP;AACD;;AAED,SAASE,OAAT,CACEC,IADF,EAEE;EACEC;AADF,CAFF,EAOsD;EACpD,MAAM;IACJC,GADI;IAEJC,QAFI;IAGJC,OAAO,EAAE;MAAEC;IAAF;EAHL,IAIFL,IAJJ;;EAKA,MAAM;IAAEM;EAAF,IAAgBX,OAAO,CAAC,SAAD,CAA7B;;EAEA,MAAMY,OAAO,GAAGD,SAAS,CAACJ,GAAD,EAAM;IAC7BM,QAAQ,EAAEL,QADmB;IAE7BM,UAAU,E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;IADO,CAAP,CAAd;EAGD,CAtDyE;;EAwD1E;EACA0D,UAAU,CAAC3D,IAAD,EAAO;IACfV,KAAK,CAAC,OAAD,EAAUU,IAAI,CAACG,QAAf,CAAL,CADe,CAEf;;IACA,OAAOJ,OAAO,CAACC,IAAD,EAAO;MACnBC,UAAU,EAAE,CACV,SADU,EAEV;MACA,uCAAuCY,IAAvC,CAA4Cb,IAAI,CAACG,QAAjD,KAA8D,KAHpD,EAIV;MACA,qBAAqBU,IAArB,CAA0Bb,IAAI,CAACG,QAA/B,KAA4C,MALlC,EAMVyD,MANU,CAMHC,OANG;IADO,CAAP,CAAd;EASD,CArEyE;;EAuE1E;EACAC,kBAAkB,CAAC9D,IAAD,EAAO;IACvBV,KAAK,CAAC,eAAD,EAAkBU,IAAI,CAACG,QAAvB,CAAL;IACA,OAAOJ,OAAO,CAACC,IAAD,EAAO;MACnBC,UAAU,EAAEW,6BAA6B,CAACZ,IAAI,CAACG,QAAN;IADtB,CAAP,CAAd;EAGD,CA7EyE;;EA+E1E;EACA4D,iBAAiB,CAAC/D,IAAD,EAAO;IACtB,MAAM;MAAEG,QAAF;MAAYC,OAAZ;MAAqBF;IAArB,IAA6BF,IAAnC;IACAV,KAAK,CAAC,cAAD,EAAiBa,QAAjB,CAAL,CAFsB,CAItB;;IACA,MAAM6B,GAAG,GAAGlB,QAAQ,CAACV,OAAO,CAACV,WAAT,EAAsBQ,GAAtB,CAApB,CALsB,CAOtB;;IACA,MAAMS,WAAW,GAAG,IAAA8C,0CAAA,EAAoBrD,OAAO,CAACV,WAA5B,EAAyCsC,GAAzC,EAA8C;MAAE7B;IAAF,CAA9C,CAApB;IAEA,OAAO;MACLO,IAAI,EAAER,GADD;MAELS,WAFK;MAGLqB;IAHK,CAAP;EAKD;;AA/FyE,CAArE"}
1
+ {"version":3,"file":"createMultiRuleTransformer.js","names":["debug","Debug","babelCore","getBabelCoreFromProject","projectRoot","require","resolveFrom","babelParser","getBabelParserFromProject","sucrase","args","transforms","src","filename","options","dev","transform","results","filePath","production","code","functionMap","getExpensiveSucraseTransforms","test","parseAst","sourceCode","babylon","parse","sourceType","createMultiRuleTransformer","getRuleType","rules","OLD_BABEL_ENV","process","env","BABEL_ENV","ruleType","rule","type","isMatched","_ruleName","name","ast","Error","app","plugins","babelConfig","getBabelConfig","caller","platform","Object","defineProperty","enumerable","writable","value","onWarning","msg","console","warn","chalk","bold","yellow","parseSync","transformFromAstSync","sourceAst","result","generateFunctionMap","loaders","reactNativeModule","includes","expoModule","filter","Boolean","untranspiledModule","passthroughModule"],"sources":["../../src/transformer/createMultiRuleTransformer.ts"],"sourcesContent":["// Copyright 2021-present 650 Industries (Expo). All rights reserved.\n\nimport chalk from 'chalk';\nimport Debug from 'debug';\nimport type { BabelTransformer, BabelTransformerArgs } from 'metro-babel-transformer';\nimport resolveFrom from 'resolve-from';\n\nimport { generateFunctionMap } from './generateFunctionMap';\nimport { getBabelConfig } from './getBabelConfig';\n\nconst debug = Debug('expo:metro:exotic-babel-transformer');\n\nlet babelCore: typeof import('@babel/core') | undefined;\n\nfunction getBabelCoreFromProject(projectRoot: string) {\n if (babelCore) return babelCore;\n babelCore = require(resolveFrom(projectRoot, '@babel/core'));\n return babelCore!;\n}\n\nlet babelParser: typeof import('@babel/parser') | undefined;\n\nfunction getBabelParserFromProject(projectRoot: string) {\n if (babelParser) return babelParser;\n babelParser = require(resolveFrom(projectRoot, '@babel/parser'));\n return babelParser!;\n}\n\nfunction sucrase(\n args: BabelTransformerArgs,\n {\n transforms,\n }: {\n transforms: string[];\n }\n): Partial<ReturnType<BabelTransformer['transform']>> {\n const {\n src,\n filename,\n options: { dev },\n } = args;\n const { transform } = require('sucrase');\n\n const results = transform(src, {\n filePath: filename,\n production: !dev,\n transforms,\n });\n\n return {\n code: results.code,\n functionMap: null,\n };\n}\n\nconst getExpensiveSucraseTransforms = (filename: string) => [\n 'jsx',\n 'imports',\n /\\.tsx?$/.test(filename) ? 'typescript' : 'flow',\n];\n\nfunction parseAst(projectRoot: string, sourceCode: string) {\n const babylon = getBabelParserFromProject(projectRoot);\n\n return babylon.parse(sourceCode, {\n sourceType: 'unambiguous',\n });\n}\n\nexport type Rule = {\n warn?: boolean;\n type?: 'module' | 'app';\n name?: string;\n test: ((args: BabelTransformerArgs) => boolean) | RegExp;\n transform: BabelTransformer['transform'];\n};\n\n/** Create a transformer that emulates Webpack's loader system. */\nexport function createMultiRuleTransformer({\n getRuleType,\n rules,\n}: {\n getRuleType: (args: BabelTransformerArgs) => string;\n rules: Rule[];\n}): BabelTransformer['transform'] {\n // const warnings: string[] = [];\n return function transform(args: BabelTransformerArgs) {\n const { filename, options } = args;\n const OLD_BABEL_ENV = process.env.BABEL_ENV;\n process.env.BABEL_ENV = options?.dev ? 'development' : process.env.BABEL_ENV || 'production';\n\n try {\n const ruleType = getRuleType(args);\n\n for (const rule of rules) {\n // optimization for checking node modules\n if (rule.type && rule.type !== ruleType) {\n continue;\n }\n\n const isMatched =\n typeof rule.test === 'function' ? rule.test(args) : rule.test.test(args.filename);\n if (isMatched) {\n const results = rule.transform(args);\n // @ts-ignore: Add extra property for testing\n results._ruleName = rule.name;\n // Perform a basic parse if none exists, this enables us to control the output, but only if it changed.\n if (results.code && !results.ast) {\n // Parse AST with babel otherwise Metro transformer will throw away the returned results.\n results.ast = parseAst(options?.projectRoot, results.code);\n }\n\n // TODO: Suboptimal warnings\n // if (rule.warn) {\n // const matchName =\n // filename.match(/node_modules\\/((:?@[\\w\\d-]+\\/[\\w\\d-]+)|(:?[\\w\\d-]+))\\/?/)?.[1] ??\n // filename;\n // if (matchName && !warnings.includes(matchName)) {\n // warnings.push(matchName);\n // console.warn(chalk.yellow.bold`warn `, matchName);\n // console.warn(\n // chalk.yellow`untranspiled module is potentially causing bundler slowdown, using modules that support commonjs will make your dev server much faster.`\n // );\n // }\n // }\n\n return results;\n }\n }\n throw new Error('no loader rule to handle file: ' + filename);\n } finally {\n if (OLD_BABEL_ENV) {\n process.env.BABEL_ENV = OLD_BABEL_ENV;\n }\n }\n };\n}\n\nfunction app(args: BabelTransformerArgs) {\n debug('app:', args.filename);\n\n const { filename, options, src, plugins } = args;\n const babelConfig = {\n // ES modules require sourceType='module' but OSS may not always want that\n sourceType: 'unambiguous',\n ...getBabelConfig(filename, options, plugins),\n // Variables that are exposed to the user's babel preset.\n caller: {\n name: 'metro',\n\n platform: options.platform,\n },\n ast: true,\n };\n\n // Surface a warning function so babel linters can be used.\n Object.defineProperty(babelConfig.caller, 'onWarning', {\n enumerable: false,\n writable: false,\n value: (babelConfig.caller.onWarning = function (msg: any) {\n // Format the file path first so users know where the warning came from.\n console.warn(chalk.bold.yellow`warn ` + args.filename);\n console.warn(msg);\n }),\n });\n\n const { parseSync, transformFromAstSync } = getBabelCoreFromProject(options.projectRoot);\n const sourceAst = parseSync(src, babelConfig);\n\n // Should never happen.\n if (!sourceAst) return { ast: null };\n\n const result = transformFromAstSync(sourceAst, src, babelConfig);\n\n // TODO: Disable by default\n const functionMap = generateFunctionMap(options.projectRoot, sourceAst, { filename });\n // The result from `transformFromAstSync` can be null (if the file is ignored)\n if (!result) {\n return { ast: null, functionMap };\n }\n\n return { ast: result.ast, functionMap };\n}\n\nexport const loaders: Record<string, (args: BabelTransformerArgs) => any> = {\n // Perform the standard, and most expensive transpilation sequence.\n app,\n\n // Transpile react-native with sucrase.\n reactNativeModule(args) {\n // Special file needs full transpilation.\n if (args.filename.includes('react-native/Libraries/Events/EventPolyfill.js')) {\n // Match React Native modules which use non-standard flow features, convert them using babel (most expensive).\n return app(args);\n }\n\n debug('rn:', args.filename);\n return sucrase(args, {\n transforms: ['jsx', 'flow', 'imports'],\n });\n },\n\n // Transpile expo modules with sucrase.\n expoModule(args) {\n debug('expo:', args.filename);\n // TODO: Fix all expo packages\n return sucrase(args, {\n transforms: [\n 'imports',\n // TODO: fix expo-processing, expo/vector-icons\n /(expo-processing|expo\\/vector-icons)/.test(args.filename) && 'jsx',\n // TODO: fix expo-asset-utils\n /(expo-asset-utils)/.test(args.filename) && 'flow',\n ].filter(Boolean) as string[],\n });\n },\n\n // Transpile known community modules with the most expensive sucrase\n untranspiledModule(args) {\n debug('known issues:', args.filename);\n return sucrase(args, {\n transforms: getExpensiveSucraseTransforms(args.filename),\n });\n },\n\n // Pass all modules through without transpiling them.\n passthroughModule(args) {\n const { filename, options, src } = args;\n debug('passthrough:', filename);\n\n // Perform a basic ast parse, this doesn't matter since the worker will parse and ignore anyways.\n const ast = parseAst(options.projectRoot, src);\n\n // TODO: Disable by default\n const functionMap = generateFunctionMap(options.projectRoot, ast, { filename });\n\n return {\n code: src,\n functionMap,\n ast,\n };\n },\n};\n"],"mappings":";;;;;;;AAEA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AAEA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AAEA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AAAkD;AARlD;;AAUA,MAAMA,KAAK,GAAG,IAAAC,gBAAK,EAAC,qCAAqC,CAAC;AAE1D,IAAIC,SAAmD;AAEvD,SAASC,uBAAuB,CAACC,WAAmB,EAAE;EACpD,IAAIF,SAAS,EAAE,OAAOA,SAAS;EAC/BA,SAAS,GAAGG,OAAO,CAAC,IAAAC,sBAAW,EAACF,WAAW,EAAE,aAAa,CAAC,CAAC;EAC5D,OAAOF,SAAS;AAClB;AAEA,IAAIK,WAAuD;AAE3D,SAASC,yBAAyB,CAACJ,WAAmB,EAAE;EACtD,IAAIG,WAAW,EAAE,OAAOA,WAAW;EACnCA,WAAW,GAAGF,OAAO,CAAC,IAAAC,sBAAW,EAACF,WAAW,EAAE,eAAe,CAAC,CAAC;EAChE,OAAOG,WAAW;AACpB;AAEA,SAASE,OAAO,CACdC,IAA0B,EAC1B;EACEC;AAGF,CAAC,EACmD;EACpD,MAAM;IACJC,GAAG;IACHC,QAAQ;IACRC,OAAO,EAAE;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G;MACTS,WAAW;MACXqB;IACF,CAAC;EACH;AACF,CAAC;AAAC"}
@@ -4,17 +4,13 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.generateFunctionMap = generateFunctionMap;
7
-
8
7
  function _importMetroFromProject() {
9
8
  const data = require("../importMetroFromProject");
10
-
11
9
  _importMetroFromProject = function () {
12
10
  return data;
13
11
  };
14
-
15
12
  return data;
16
13
  }
17
-
18
14
  function generateFunctionMap(projectRoot, ast, context) {
19
15
  // `x_facebook_sources` is a source map feature that we disable by default since it isn't documented
20
16
  // and doesn't appear to add much value to the DX, it also increases bundle time, and source map size.
@@ -37,7 +33,6 @@ function generateFunctionMap(projectRoot, ast, context) {
37
33
  if (process.env.EXPO_USE_FB_SOURCES) {
38
34
  return (0, _importMetroFromProject().importMetroSourceMapFromProject)(projectRoot).generateFunctionMap(ast, context);
39
35
  }
40
-
41
36
  return null;
42
37
  }
43
38
  //# sourceMappingURL=generateFunctionMap.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"generateFunctionMap.js","names":["generateFunctionMap","projectRoot","ast","context","process","env","EXPO_USE_FB_SOURCES","importMetroSourceMapFromProject"],"sources":["../../src/transformer/generateFunctionMap.ts"],"sourcesContent":["import type { generateFunctionMap as generateFunctionMapType } from 'metro-source-map';\n\nimport { importMetroSourceMapFromProject } from '../importMetroFromProject';\n\nexport function generateFunctionMap(\n projectRoot: string,\n ast: Parameters<typeof generateFunctionMapType>[0],\n context: Parameters<typeof generateFunctionMapType>[1]\n): ReturnType<typeof generateFunctionMapType> | null {\n // `x_facebook_sources` is a source map feature that we disable by default since it isn't documented\n // and doesn't appear to add much value to the DX, it also increases bundle time, and source map size.\n // The feature supposedly provides improved function names for anonymous functions, but we will opt towards\n // linting to prevent users from adding anonymous functions for important features like React components.\n //\n // Here is an example stack trace for a component that throws an error\n // in the root component (which is an anonymous function):\n //\n // Before:\n // - <anonymous> App.js:5:9\n // - renderApplication renderApplication.js:54:5\n // - runnables.appKey.run AppRegistry.js:117:26\n //\n // After:\n // - _default App.js:5:9\n // - renderApplication renderApplication.js:54:5\n // - run AppRegistry.js:117:26\n //\n if (process.env.EXPO_USE_FB_SOURCES) {\n return importMetroSourceMapFromProject(projectRoot).generateFunctionMap(ast, context);\n }\n return null;\n}\n"],"mappings":";;;;;;;AAEA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AAEO,SAASA,mBAAT,CACLC,WADK,EAELC,GAFK,EAGLC,OAHK,EAI8C;EACnD;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA,IAAIC,OAAO,CAACC,GAAR,CAAYC,mBAAhB,EAAqC;IACnC,OAAO,IAAAC,yDAAA,EAAgCN,WAAhC,EAA6CD,mBAA7C,CAAiEE,GAAjE,EAAsEC,OAAtE,CAAP;EACD;;EACD,OAAO,IAAP;AACD"}
1
+ {"version":3,"file":"generateFunctionMap.js","names":["generateFunctionMap","projectRoot","ast","context","process","env","EXPO_USE_FB_SOURCES","importMetroSourceMapFromProject"],"sources":["../../src/transformer/generateFunctionMap.ts"],"sourcesContent":["import type { generateFunctionMap as generateFunctionMapType } from 'metro-source-map';\n\nimport { importMetroSourceMapFromProject } from '../importMetroFromProject';\n\nexport function generateFunctionMap(\n projectRoot: string,\n ast: Parameters<typeof generateFunctionMapType>[0],\n context: Parameters<typeof generateFunctionMapType>[1]\n): ReturnType<typeof generateFunctionMapType> | null {\n // `x_facebook_sources` is a source map feature that we disable by default since it isn't documented\n // and doesn't appear to add much value to the DX, it also increases bundle time, and source map size.\n // The feature supposedly provides improved function names for anonymous functions, but we will opt towards\n // linting to prevent users from adding anonymous functions for important features like React components.\n //\n // Here is an example stack trace for a component that throws an error\n // in the root component (which is an anonymous function):\n //\n // Before:\n // - <anonymous> App.js:5:9\n // - renderApplication renderApplication.js:54:5\n // - runnables.appKey.run AppRegistry.js:117:26\n //\n // After:\n // - _default App.js:5:9\n // - renderApplication renderApplication.js:54:5\n // - run AppRegistry.js:117:26\n //\n if (process.env.EXPO_USE_FB_SOURCES) {\n return importMetroSourceMapFromProject(projectRoot).generateFunctionMap(ast, context);\n }\n return null;\n}\n"],"mappings":";;;;;;AAEA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AAEO,SAASA,mBAAmB,CACjCC,WAAmB,EACnBC,GAAkD,EAClDC,OAAsD,EACH;EACnD;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA,IAAIC,OAAO,CAACC,GAAG,CAACC,mBAAmB,EAAE;IACnC,OAAO,IAAAC,yDAA+B,EAACN,WAAW,CAAC,CAACD,mBAAmB,CAACE,GAAG,EAAEC,OAAO,CAAC;EACvF;EACA,OAAO,IAAI;AACb"}
@@ -4,39 +4,28 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.getBabelConfig = getBabelConfig;
7
-
8
7
  function _fs() {
9
8
  const data = _interopRequireDefault(require("fs"));
10
-
11
9
  _fs = function () {
12
10
  return data;
13
11
  };
14
-
15
12
  return data;
16
13
  }
17
-
18
14
  function _path() {
19
15
  const data = _interopRequireDefault(require("path"));
20
-
21
16
  _path = function () {
22
17
  return data;
23
18
  };
24
-
25
19
  return data;
26
20
  }
27
-
28
21
  function _resolveFrom() {
29
22
  const data = _interopRequireDefault(require("resolve-from"));
30
-
31
23
  _resolveFrom = function () {
32
24
  return data;
33
25
  };
34
-
35
26
  return data;
36
27
  }
37
-
38
28
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
39
-
40
29
  /**
41
30
  * Copyright (c) Expo.
42
31
  * Copyright (c) Facebook, Inc. and its affiliates.
@@ -58,46 +47,46 @@ const getBabelRC = function () {
58
47
  if (babelRC != null) {
59
48
  return babelRC;
60
49
  }
61
-
62
50
  babelRC = {
63
51
  plugins: []
64
- }; // Let's look for a babel config file in the project root.
65
- // TODO look into adding a command line option to specify this location
52
+ };
66
53
 
67
- let projectBabelRCPath; // .babelrc
54
+ // Let's look for a babel config file in the project root.
55
+ // TODO look into adding a command line option to specify this location
56
+ let projectBabelRCPath;
68
57
 
58
+ // .babelrc
69
59
  if (projectRoot) {
70
60
  projectBabelRCPath = _path().default.resolve(projectRoot, '.babelrc');
71
61
  }
72
-
73
62
  if (projectBabelRCPath) {
74
63
  // .babelrc.js
75
64
  if (!_fs().default.existsSync(projectBabelRCPath)) {
76
65
  projectBabelRCPath = _path().default.resolve(projectRoot, '.babelrc.js');
77
- } // babel.config.js
78
-
66
+ }
79
67
 
68
+ // babel.config.js
80
69
  if (!_fs().default.existsSync(projectBabelRCPath)) {
81
70
  projectBabelRCPath = _path().default.resolve(projectRoot, 'babel.config.js');
82
- } // If we found a babel config file, extend our config off of it
83
- // otherwise the default config will be used
84
-
71
+ }
85
72
 
73
+ // If we found a babel config file, extend our config off of it
74
+ // otherwise the default config will be used
86
75
  if (_fs().default.existsSync(projectBabelRCPath)) {
87
76
  babelRC.extends = projectBabelRCPath;
88
77
  }
89
- } // If a babel config file doesn't exist in the project then
90
- // the default preset for react-native will be used instead.
91
-
78
+ }
92
79
 
80
+ // If a babel config file doesn't exist in the project then
81
+ // the default preset for react-native will be used instead.
93
82
  if (!babelRC.extends) {
94
83
  var _ref, _resolveFrom$silent;
95
-
96
84
  const {
97
85
  experimentalImportSupport,
98
86
  ...presetOptions
99
- } = options; // Use `babel-preset-expo` instead of `metro-react-native-babel-preset`.
87
+ } = options;
100
88
 
89
+ // Use `babel-preset-expo` instead of `metro-react-native-babel-preset`.
101
90
  const presetPath = (_ref = (_resolveFrom$silent = _resolveFrom().default.silent(projectRoot, 'babel-preset-expo')) !== null && _resolveFrom$silent !== void 0 ? _resolveFrom$silent : _resolveFrom().default.silent(projectRoot, 'metro-react-native-babel-preset')) !== null && _ref !== void 0 ? _ref : require.resolve('babel-preset-expo');
102
91
  babelRC.presets = [[require(presetPath), {
103
92
  // Default to React 17 automatic JSX transform.
@@ -107,16 +96,14 @@ const getBabelRC = function () {
107
96
  enableBabelRuntime: options.enableBabelRuntime
108
97
  }]];
109
98
  }
110
-
111
99
  return babelRC;
112
100
  };
113
101
  }();
102
+
114
103
  /**
115
104
  * Given a filename and options, build a Babel
116
105
  * config object with the appropriate plugins.
117
106
  */
118
-
119
-
120
107
  function getBabelConfig(filename, options, plugins = []) {
121
108
  const babelRC = getBabelRC(options.projectRoot, options);
122
109
  const extraConfig = {
@@ -125,19 +112,20 @@ function getBabelConfig(filename, options, plugins = []) {
125
112
  filename,
126
113
  highlightCode: true
127
114
  };
128
- const config = { ...babelRC,
115
+ const config = {
116
+ ...babelRC,
129
117
  ...extraConfig
130
- }; // Add extra plugins
118
+ };
131
119
 
132
- const extraPlugins = []; // TODO: This probably can be removed
120
+ // Add extra plugins
121
+ const extraPlugins = [];
133
122
 
123
+ // TODO: This probably can be removed
134
124
  if (options.inlineRequires) {
135
125
  const inlineRequiresPlugin = (0, _resolveFrom().default)(options.projectRoot, 'babel-preset-fbjs/plugins/inline-requires');
136
126
  extraPlugins.push(inlineRequiresPlugin);
137
127
  }
138
-
139
128
  config.plugins = extraPlugins.concat(config.plugins, plugins);
140
-
141
129
  if (options.dev && options.hot) {
142
130
  // Note: this intentionally doesn't include the path separator because
143
131
  // I'm not sure which one it should use on Windows, and false positives
@@ -146,19 +134,17 @@ function getBabelConfig(filename, options, plugins = []) {
146
134
  // the first one often won't be there.
147
135
  // TODO: Support monorepos
148
136
  const mayContainEditableReactComponents = filename.indexOf('node_modules') === -1;
149
-
150
137
  if (mayContainEditableReactComponents) {
151
138
  if (!config.plugins) {
152
139
  config.plugins = [];
153
- } // Add react refresh runtime.
140
+ }
141
+ // Add react refresh runtime.
154
142
  // NOTICE: keep in sync with 'metro-react-native-babel-preset/src/configs/hmr'.
155
-
156
-
157
143
  config.plugins.push(_resolveFrom().default.silent(options.projectRoot, 'react-refresh/babel'));
158
144
  }
159
145
  }
160
-
161
- return { ...babelRC,
146
+ return {
147
+ ...babelRC,
162
148
  ...config
163
149
  };
164
150
  }