Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fix pnpm related errors when on 0.76 #2301

Merged
merged 1 commit into from
Oct 31, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
14 changes: 10 additions & 4 deletions ios/test_app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,13 @@ def apply_config_plugins(project_root, target_platform)
raise 'Failed to apply config plugins' unless result
end

def autolink_script_path(project_root, target_platform)
react_native = react_native_path(project_root, target_platform)
package_path = resolve_module('@react-native-community/cli-platform-ios', react_native)
def autolink_script_path(project_root, target_platform, react_native_version)
start_dir = if react_native_version >= v(0, 76, 0)
project_root
else
react_native_path(project_root, target_platform)
end
package_path = resolve_module('@react-native-community/cli-platform-ios', start_dir)
File.join(package_path, 'native_modules')
end

Expand Down Expand Up @@ -356,7 +360,9 @@ def use_test_app_internal!(target_platform, options)
install! 'cocoapods', :deterministic_uuids => false
end

require_relative(autolink_script_path(project_root, target_platform))
require_relative(autolink_script_path(project_root,
target_platform,
project_target[:react_native_version]))

begin
platform :ios, platforms[:ios] if target_platform == :ios
Expand Down
38 changes: 26 additions & 12 deletions scripts/configure-projects.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,10 @@ const {
*/
const getRNPackageVersion = (() => {
const isTesting = "NODE_TEST_CONTEXT" in process.env;

/** @type {Record<string, number>} */
let versions = {};

/** @type {(packageName: string) => number} */
return (packageName, fs = nodefs) => {
if (isTesting || !versions[packageName]) {
Expand All @@ -49,7 +51,12 @@ const getRNPackageVersion = (() => {
* @returns {number}
*/
function cliPlatformIOSVersion() {
return getRNPackageVersion("@react-native-community/cli-platform-ios");
try {
return getRNPackageVersion("@react-native-community/cli-platform-ios");
} catch (_) {
// The returned value doesn't matter when we're on 0.76 or later
return Number.MAX_SAFE_INTEGER;
}
}

/**
Expand All @@ -61,17 +68,24 @@ function getAndroidPackageName(manifestPath, fs = nodefs) {
return undefined;
}

const rncliAndroidVersion = getRNPackageVersion(
"@react-native-community/cli-platform-android",
fs
);
if (rncliAndroidVersion < v(12, 3, 7)) {
// TODO: This block can be removed when we drop support for 0.72
return undefined;
}
if (rncliAndroidVersion >= v(13, 0, 0) && rncliAndroidVersion < v(13, 6, 9)) {
// TODO: This block can be removed when we drop support for 0.73
return undefined;
try {
const rncliAndroidVersion = getRNPackageVersion(
"@react-native-community/cli-platform-android",
fs
);
if (rncliAndroidVersion < v(12, 3, 7)) {
// TODO: This block can be removed when we drop support for 0.72
return undefined;
}
if (
rncliAndroidVersion >= v(13, 0, 0) &&
rncliAndroidVersion < v(13, 6, 9)
) {
// TODO: This block can be removed when we drop support for 0.73
return undefined;
}
} catch (_) {
// We're on 0.76 or later
}

/** @type {{ android?: { package?: string }}} */
Expand Down
9 changes: 8 additions & 1 deletion test/test_test_app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,17 @@ def test_app_config_single_app

def test_autolink_script_path
react_native_dir = fixture_path('test_app', 'node_modules', 'react-native')
autolink_path = fixture_path('test_app',
'node_modules',
'@react-native-community',
'cli-platform-ios',
'native_modules').to_s

stub :react_native_path, react_native_dir do
assert(require(autolink_script_path(fixture_path('test_app'), :ios)))
assert_equal(autolink_script_path(fixture_path('test_app'), :ios, v(0, 75, 0)), autolink_path)
end

assert_equal(autolink_script_path(fixture_path('test_app'), :ios, v(0, 76, 0)), autolink_path)
end

def test_react_native_pods
Expand Down
Loading