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