Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ function generateReactCodegenPodspec(
appPath /*: string */,
appPkgJson /*: $FlowFixMe */,
outputPath /*: string */,
baseOutputPath /*: string */,
baseOutputPath /*: string | void | null */,
) {
const inputFiles = getInputFiles(appPath, appPkgJson);
const codegenScript = codegenScripts(appPath, baseOutputPath);
Expand Down Expand Up @@ -76,14 +76,24 @@ function getInputFiles(appPath /*: string */, appPkgJson /*: $FlowFixMe */) {
return `[${list}]`;
}

function codegenScripts(appPath /*: string */, outputPath /*: string */) {
const relativeAppPath = path.relative(outputPath, appPath);
function codegenScripts(
appPath /*: string */,
outputPath /*: string | void | null */,
) {
const relativeAppPath =
outputPath != null && outputPath.length > 0
? path.relative(outputPath, appPath)
: '';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So if outputPath is not passed, the relativeAppPath is '.'?
Are we sure it is correct?

const relativeReactNativeRootFolder =
outputPath != null && outputPath.length > 0
? path.relative(outputPath, REACT_NATIVE_PACKAGE_ROOT_FOLDER)
: '';
Comment on lines +87 to +90
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So if outputPath is not passed, the relativeAppPath is '.'?
Are we sure it is correct?

return `<<-SCRIPT
pushd "$PODS_ROOT/../" > /dev/null
RCT_SCRIPT_POD_INSTALLATION_ROOT=$(pwd)
popd >/dev/null

export RCT_SCRIPT_RN_DIR="$RCT_SCRIPT_POD_INSTALLATION_ROOT/${path.relative(outputPath, REACT_NATIVE_PACKAGE_ROOT_FOLDER)}"
export RCT_SCRIPT_RN_DIR="$RCT_SCRIPT_POD_INSTALLATION_ROOT/${relativeReactNativeRootFolder}"
export RCT_SCRIPT_APP_PATH="$RCT_SCRIPT_POD_INSTALLATION_ROOT/${relativeAppPath.length === 0 ? '.' : relativeAppPath}"
export RCT_SCRIPT_OUTPUT_DIR="$RCT_SCRIPT_POD_INSTALLATION_ROOT"
export RCT_SCRIPT_TYPE="withCodegenDiscovery"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ const path = require('path');
function execute(
projectRoot /*: string */,
targetPlatform /*: string */,
baseOutputPath /*: string */,
baseOutputPath /*: string | void | null */,
source /*: string */,
runReactNativeCodegen /*: boolean */ = true,
) {
Expand Down Expand Up @@ -210,29 +210,38 @@ function readOutputDirFromPkgJson(

function computeOutputPath(
projectRoot /*: string */,
baseOutputPath /*: string */,
optionalBaseOutputPath /*: string | void | null */,
pkgJson /*: $FlowFixMe */,
platform /*: string */,
) {
if (baseOutputPath == null) {
) /*: string */ {
let baseOutputPath /*: string */;
if (optionalBaseOutputPath == null) {
const outputDirFromPkgJson = readOutputDirFromPkgJson(pkgJson, platform);
if (outputDirFromPkgJson != null) {
// $FlowFixMe[reassign-const]
baseOutputPath = path.join(projectRoot, outputDirFromPkgJson);
} else {
// $FlowFixMe[reassign-const]
baseOutputPath = projectRoot;
}
} else {
baseOutputPath = optionalBaseOutputPath;
}
if (pkgJsonIncludesGeneratedCode(pkgJson)) {
// Don't create nested directories for libraries to make importing generated headers easier.
return baseOutputPath;
}
if (platform === 'android') {
return defaultOutputPathForAndroid(baseOutputPath);
return defaultOutputPathForAndroid(
baseOutputPath != null && baseOutputPath.length > 0
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

baseOutputPath can't be null anymore here, right?

? baseOutputPath
: projectRoot,
);
}
if (platform === 'ios') {
return defaultOutputPathForIOS(baseOutputPath);
return defaultOutputPathForIOS(
baseOutputPath != null && baseOutputPath.length > 0
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

baseOutputPath can't be null anymore here, right?

? baseOutputPath
: projectRoot,
);
}
return baseOutputPath;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,15 @@ function cleanupEmptyFilesAndFolders(filepath /*: string */) {
}

function readGeneratedAutolinkingOutput(
baseOutputPath /*: string */,
projectRoot /*: string */,
baseOutputPath /*: string | void | null */,
) /*: $FlowFixMe */ {
// NOTE: Generated by scripts/cocoapods/autolinking.rb in list_native_modules (called by use_native_modules)
// The `baseOutputPath` is based on a CLI argument and optional
const autolinkingGeneratedPath = path.resolve(
baseOutputPath,
baseOutputPath != null && baseOutputPath.length > 0
? baseOutputPath
: projectRoot,
'build/generated/autolinking/autolinking.json',
);
if (fs.existsSync(autolinkingGeneratedPath)) {
Expand All @@ -118,9 +122,12 @@ function readGeneratedAutolinkingOutput(

function readReactNativeConfig(
projectRoot /*: string */,
baseOutputPath /*: string */,
baseOutputPath /*: string | void | null */,
) /*: $FlowFixMe */ {
const autolinkingOutput = readGeneratedAutolinkingOutput(baseOutputPath);
const autolinkingOutput = readGeneratedAutolinkingOutput(
projectRoot,
baseOutputPath,
);
const rnConfigFilePath = path.resolve(projectRoot, 'react-native.config.js');
if (autolinkingOutput) {
return autolinkingOutput;
Expand All @@ -139,7 +146,7 @@ function readReactNativeConfig(
function findCodegenEnabledLibraries(
pkgJson /*: $FlowFixMe */,
projectRoot /*: string */,
baseOutputPath /*: string */,
baseOutputPath /*: string | void | null */,
reactNativeConfig /*: $FlowFixMe */,
) /*: Array<$FlowFixMe> */ {
const projectLibraries = findProjectRootLibraries(pkgJson, projectRoot);
Expand All @@ -149,7 +156,7 @@ function findCodegenEnabledLibraries(
const libraries = [...projectLibraries];
// If we ran autolinking, we shouldn't try to run our own "autolinking-like"
// library discovery
if (!readGeneratedAutolinkingOutput(baseOutputPath)) {
if (!readGeneratedAutolinkingOutput(projectRoot, baseOutputPath)) {
libraries.push(...findExternalLibraries(pkgJson, projectRoot));
}
libraries.push(
Expand Down
Loading