1/**
2 * Copyright (c) Meta Platforms, Inc. and affiliates.
3 *
4 * This source code is licensed under the MIT license found in the
5 * LICENSE file in the root directory of this source tree.
6 *
7 * @format
8 */
9
10'use strict';
11
12/**
13 * Wrapper required to abstract away from the actual codegen.
14 * This is needed because, when running tests in Sandcastle, not everything is setup as usually.
15 * For example, the `@react-native/codegen` lib is not present.
16 *
17 * Thanks to this wrapper, we are able to mock the getter for the codegen in a way that allow us to return
18 * a custom object which mimics the Codegen interface.
19 *
20 * @return an object that can generate the code for the New Architecture.
21 */
22function getCodegen() {
23  let RNCodegen;
24  try {
25    RNCodegen = require('../../packages/react-native-codegen/lib/generators/RNCodegen.js');
26  } catch (e) {
27    RNCodegen = require('@react-native/codegen/lib/generators/RNCodegen.js');
28  }
29  if (!RNCodegen) {
30    throw 'RNCodegen not found.';
31  }
32  return RNCodegen;
33}
34
35module.exports = {
36  getCodegen: getCodegen,
37};
38