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