Skip to content

Commit 37624e0

Browse files
committed
Update baseOutputPath input to generate-artifacts-executor to be optional
The argument for the output path was always optional. This wasn't reflected in types, however, so this was missed in two prior changes.
1 parent 4279958 commit 37624e0

File tree

3 files changed

+27
-12
lines changed

3 files changed

+27
-12
lines changed

packages/react-native/scripts/codegen/generate-artifacts-executor/generateReactCodegenPodspec.js

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ function generateReactCodegenPodspec(
2929
appPath /*: string */,
3030
appPkgJson /*: $FlowFixMe */,
3131
outputPath /*: string */,
32-
baseOutputPath /*: string */,
32+
baseOutputPath /*: string | void | null */,
3333
) {
3434
const inputFiles = getInputFiles(appPath, appPkgJson);
3535
const codegenScript = codegenScripts(appPath, baseOutputPath);
@@ -76,14 +76,24 @@ function getInputFiles(appPath /*: string */, appPkgJson /*: $FlowFixMe */) {
7676
return `[${list}]`;
7777
}
7878

79-
function codegenScripts(appPath /*: string */, outputPath /*: string */) {
80-
const relativeAppPath = path.relative(outputPath, appPath);
79+
function codegenScripts(
80+
appPath /*: string */,
81+
outputPath /*: string | void | null */,
82+
) {
83+
const relativeAppPath =
84+
outputPath != null && outputPath.length > 0
85+
? path.relative(outputPath, appPath)
86+
: '';
87+
const relativeReactNativeRootFolder =
88+
outputPath != null && outputPath.length > 0
89+
? path.relative(outputPath, REACT_NATIVE_PACKAGE_ROOT_FOLDER)
90+
: '';
8191
return `<<-SCRIPT
8292
pushd "$PODS_ROOT/../" > /dev/null
8393
RCT_SCRIPT_POD_INSTALLATION_ROOT=$(pwd)
8494
popd >/dev/null
8595
86-
export RCT_SCRIPT_RN_DIR="$RCT_SCRIPT_POD_INSTALLATION_ROOT/${path.relative(outputPath, REACT_NATIVE_PACKAGE_ROOT_FOLDER)}"
96+
export RCT_SCRIPT_RN_DIR="$RCT_SCRIPT_POD_INSTALLATION_ROOT/${relativeReactNativeRootFolder}"
8797
export RCT_SCRIPT_APP_PATH="$RCT_SCRIPT_POD_INSTALLATION_ROOT/${relativeAppPath.length === 0 ? '.' : relativeAppPath}"
8898
export RCT_SCRIPT_OUTPUT_DIR="$RCT_SCRIPT_POD_INSTALLATION_ROOT"
8999
export RCT_SCRIPT_TYPE="withCodegenDiscovery"

packages/react-native/scripts/codegen/generate-artifacts-executor/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ const path = require('path');
6363
function execute(
6464
projectRoot /*: string */,
6565
targetPlatform /*: string */,
66-
baseOutputPath /*: string */,
66+
baseOutputPath /*: string | void | null */,
6767
source /*: string */,
6868
runReactNativeCodegen /*: boolean */ = true,
6969
) {
@@ -210,7 +210,7 @@ function readOutputDirFromPkgJson(
210210

211211
function computeOutputPath(
212212
projectRoot /*: string */,
213-
baseOutputPath /*: string */,
213+
baseOutputPath /*: string | void | null */,
214214
pkgJson /*: $FlowFixMe */,
215215
platform /*: string */,
216216
) {

packages/react-native/scripts/codegen/generate-artifacts-executor/utils.js

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -98,11 +98,13 @@ function cleanupEmptyFilesAndFolders(filepath /*: string */) {
9898
}
9999

100100
function readGeneratedAutolinkingOutput(
101-
baseOutputPath /*: string */,
101+
projectRoot /*: string */,
102+
baseOutputPath /*: string | void | null */,
102103
) /*: $FlowFixMe */ {
103104
// NOTE: Generated by scripts/cocoapods/autolinking.rb in list_native_modules (called by use_native_modules)
105+
// The `baseOutputPath` is based on a CLI argument and optional
104106
const autolinkingGeneratedPath = path.resolve(
105-
baseOutputPath,
107+
baseOutputPath || projectRoot,
106108
'build/generated/autolinking/autolinking.json',
107109
);
108110
if (fs.existsSync(autolinkingGeneratedPath)) {
@@ -118,9 +120,12 @@ function readGeneratedAutolinkingOutput(
118120

119121
function readReactNativeConfig(
120122
projectRoot /*: string */,
121-
baseOutputPath /*: string */,
123+
baseOutputPath /*: string | void | null */,
122124
) /*: $FlowFixMe */ {
123-
const autolinkingOutput = readGeneratedAutolinkingOutput(baseOutputPath);
125+
const autolinkingOutput = readGeneratedAutolinkingOutput(
126+
projectRoot,
127+
baseOutputPath,
128+
);
124129
const rnConfigFilePath = path.resolve(projectRoot, 'react-native.config.js');
125130
if (autolinkingOutput) {
126131
return autolinkingOutput;
@@ -139,7 +144,7 @@ function readReactNativeConfig(
139144
function findCodegenEnabledLibraries(
140145
pkgJson /*: $FlowFixMe */,
141146
projectRoot /*: string */,
142-
baseOutputPath /*: string */,
147+
baseOutputPath /*: string | void | null */,
143148
reactNativeConfig /*: $FlowFixMe */,
144149
) /*: Array<$FlowFixMe> */ {
145150
const projectLibraries = findProjectRootLibraries(pkgJson, projectRoot);
@@ -149,7 +154,7 @@ function findCodegenEnabledLibraries(
149154
const libraries = [...projectLibraries];
150155
// If we ran autolinking, we shouldn't try to run our own "autolinking-like"
151156
// library discovery
152-
if (!readGeneratedAutolinkingOutput(baseOutputPath)) {
157+
if (!readGeneratedAutolinkingOutput(projectRoot, baseOutputPath)) {
153158
libraries.push(...findExternalLibraries(pkgJson, projectRoot));
154159
}
155160
libraries.push(

0 commit comments

Comments
 (0)