Skip to content

Commit 323db75

Browse files
Riccardo Cipolleschifacebook-github-bot
Riccardo Cipolleschi
authored andcommitted
Pass node executable to codegen (#33672)
Summary: Pull Request resolved: #33672 This pr adds a parameter to the `create-artifacts.js` script to accept the path to a node executable, falling back to `node` in case the parameter has not been passed. Then, it passes the NODE_BINARY to the script in the `script_phases.sh` script. This PR decouples the `node` environment from the system one and fixes a build issue in the new architecture when the environment has no `node` ## Changelog [iOS][Changed] - Update CodeGen scripts to accept custom node executable Reviewed By: cortinico, dmitryrykun Differential Revision: D35748497 fbshipit-source-id: 41b102de6427d6ef0ba1f8725f4b939d3b8c63db
1 parent 705c6f5 commit 323db75

File tree

2 files changed

+17
-7
lines changed

2 files changed

+17
-7
lines changed

scripts/generate-artifacts.js

+16-6
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,11 @@ const argv = yargs
5454
description:
5555
'Path where codegen config files are located (e.g. node_modules dir).',
5656
})
57+
.option('n', {
58+
alias: 'nodeBinary',
59+
default: 'node',
60+
description: 'Path to the node executable.',
61+
})
5762
.usage('Usage: $0 -p [path to app]')
5863
.demandOption(['p']).argv;
5964

@@ -62,6 +67,7 @@ const CODEGEN_CONFIG_FILENAME = argv.f;
6267
const CODEGEN_CONFIG_FILE_DIR = argv.c;
6368
const CODEGEN_CONFIG_KEY = argv.k;
6469
const CODEGEN_FABRIC_ENABLED = argv.e;
70+
const NODE = argv.n;
6571
const CODEGEN_REPO_PATH = `${RN_ROOT}/packages/react-native-codegen`;
6672
const CODEGEN_NPM_PATH = `${RN_ROOT}/../react-native-codegen`;
6773
const CORE_LIBRARIES = new Set(['rncore', 'FBReactNativeSpec']);
@@ -71,6 +77,10 @@ function isReactNativeCoreLibrary(libraryName) {
7177
return CORE_LIBRARIES.has(libraryName);
7278
}
7379

80+
function executeNodeScript(script) {
81+
execSync(`${NODE} ${script}`);
82+
}
83+
7484
function main(appRootDir, outputPath) {
7585
if (appRootDir == null) {
7686
console.error('Missing path to React Native application');
@@ -234,8 +244,8 @@ function main(appRootDir, outputPath) {
234244

235245
console.log(`\n\n[Codegen] >>>>> Processing ${library.config.name}`);
236246
// Generate one schema for the entire library...
237-
execSync(
238-
`node ${path.join(
247+
executeNodeScript(
248+
`${path.join(
239249
codegenCliPath,
240250
'lib',
241251
'cli',
@@ -250,8 +260,8 @@ function main(appRootDir, outputPath) {
250260
? `--libraryType ${library.config.type}`
251261
: '';
252262
fs.mkdirSync(pathToTempOutputDir, {recursive: true});
253-
execSync(
254-
`node ${path.join(
263+
executeNodeScript(
264+
`${path.join(
255265
RN_ROOT,
256266
'scripts',
257267
'generate-specs-cli.js',
@@ -284,8 +294,8 @@ function main(appRootDir, outputPath) {
284294

285295
// Generate FabricComponentProvider.
286296
// Only for iOS at this moment.
287-
execSync(
288-
`node ${path.join(
297+
executeNodeScript(
298+
`${path.join(
289299
RN_ROOT,
290300
'scripts',
291301
'generate-provider-cli.js',

scripts/react_native_pods_utils/script_phases.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ generateCodegenArtifactsFromSchema () {
100100
generateArtifacts () {
101101
describe "Generating codegen artifacts"
102102
pushd "$RCT_SCRIPT_RN_DIR" >/dev/null || exit 1
103-
"$NODE_BINARY" "scripts/generate-artifacts.js" --path "$RCT_SCRIPT_APP_PATH" --outputPath "$TEMP_OUTPUT_DIR" --fabricEnabled "$RCT_SCRIPT_FABRIC_ENABLED" --configFileDir "$RCT_SCRIPT_CONFIG_FILE_DIR"
103+
"$NODE_BINARY" "scripts/generate-artifacts.js" --path "$RCT_SCRIPT_APP_PATH" --outputPath "$TEMP_OUTPUT_DIR" --fabricEnabled "$RCT_SCRIPT_FABRIC_ENABLED" --configFileDir "$RCT_SCRIPT_CONFIG_FILE_DIR" --nodeBinary "$NODE_BINARY"
104104
popd >/dev/null || exit 1
105105
}
106106

0 commit comments

Comments
 (0)