Skip to content

Commit

Permalink
Silence deprecation warning for react-native dependency. (#34368)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: #34368

When a user runs `RCT_NEW_ARCH_ENABLED=1 pod install` to install the dependencies for the New Architecture, Cocoapods prints a warning because of React Native is still set up with a legacy configuration.

This diff silences these warnings because they can confuse the final user.

**Note:** We need to keep this legacy configuration to support both the legacy and the New Architecture.

## Changelog

[iOS][Changed] - Silence warning due to react-native internal details.

Reviewed By: cortinico

Differential Revision: D38503405

fbshipit-source-id: b89857aa88435b1c64da52875606003239ff2e05
  • Loading branch information
Riccardo Cipolleschi authored and facebook-github-bot committed Aug 8, 2022
1 parent bd17d83 commit a459922
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 51 deletions.
17 changes: 2 additions & 15 deletions scripts/cocoapods/__tests__/codegen_utils-test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ def testGetCodegenConfigFromFile_whenFileDoesNotExists_returnEmpty
codegen = CodegenUtils.new().get_codegen_config_from_file('package.json', 'codegenConfig')

# Assert
assert_equal(codegen, {'libraries' => []})
assert_equal(codegen, {})
end

def testGetCodegenConfigFromFile_whenFileExistsButHasNoKey_returnEmpty
Expand All @@ -137,7 +137,7 @@ def testGetCodegenConfigFromFile_whenFileExistsButHasNoKey_returnEmpty
codegen = CodegenUtils.new().get_codegen_config_from_file('package.json', 'codegen')

# Assert
assert_equal(codegen, {'libraries' => []})
assert_equal(codegen, {})
end

def testGetCodegenConfigFromFile_whenFileExistsAndHasKey_returnObject
Expand Down Expand Up @@ -213,19 +213,6 @@ def testGetListOfJSSpecs_whenDoesNotUsesLibraries_returnAListOfFiles
])
end

def testGetListOfJSSpecs_whenMisconfigured_aborts
# Arrange
app_codegen_config = {}
app_path = "~/MyApp/"
# Act
assert_raises() {
files = CodegenUtils.new().get_list_of_js_specs(app_codegen_config, app_path)
}
# Assert
assert_equal(Pod::UI.collected_warns , ["[Error] Codegen not properly configured. Please add the `codegenConfig` entry to your `package.json`"])

end

# ================================== #
# Test - GetReactCodegenScriptPhases #
# ================================== #
Expand Down
5 changes: 1 addition & 4 deletions scripts/cocoapods/codegen_utils.rb
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ def get_react_codegen_spec(package_json_file, folly_version: '2021.07.22.00', fa
#
# Returns: the list of dependencies as extracted from the package.json
def get_codegen_config_from_file(config_path, config_key)
empty = {'libraries' => []}
empty = {}
if !File.exist?(config_path)
return empty
end
Expand Down Expand Up @@ -159,9 +159,6 @@ def get_list_of_js_specs(app_codegen_config, app_path)
elsif app_codegen_config['jsSrcsDir'] then
codegen_dir = File.join(app_path, app_codegen_config['jsSrcsDir'])
file_list.concat (Finder.find_codegen_file(codegen_dir))
else
Pod::UI.warn '[Error] Codegen not properly configured. Please add the `codegenConfig` entry to your `package.json`'
abort
end

input_files = file_list.map { |filename| "${PODS_ROOT}/../#{Pathname.new(filename).realpath().relative_path_from(Pod::Config.instance.installation_root)}" }
Expand Down
71 changes: 39 additions & 32 deletions scripts/codegen/generate-artifacts-executor.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,44 @@ function readPackageJSON(appRootDir) {
return JSON.parse(fs.readFileSync(path.join(appRootDir, 'package.json')));
}

function printDeprecationWarningIfNeeded(dependency) {
if (dependency === REACT_NATIVE_DEPENDENCY_NAME) {
return;
}
console.log(`[Codegen] CodegenConfig Deprecated Setup for ${dependency}.
The configuration file still contains the codegen in the libraries array.
If possible, replace it with a single object.
`);
console.debug(`BEFORE:
{
// ...
"codegenConfig": {
"libraries": [
{
"name": "libName1",
"type": "all|components|modules",
"jsSrcsRoot": "libName1/js"
},
{
"name": "libName2",
"type": "all|components|modules",
"jsSrcsRoot": "libName2/src"
}
]
}
}
AFTER:
{
"codegenConfig": {
"name": "libraries",
"type": "all",
"jsSrcsRoot": "."
}
}
`);
}

// Reading Libraries
function extractLibrariesFromConfigurationArray(
configFile,
Expand Down Expand Up @@ -102,38 +140,7 @@ function extractLibrariesFromJSON(
libraryPath: dependencyPath,
});
} else {
console.log(`[Codegen] CodegenConfig Deprecated Setup for ${dependency}.
The configuration file still contains the codegen in the libraries array.
If possible, replace it with a single object.
`);
console.debug(`BEFORE:
{
// ...
"codegenConfig": {
"libraries": [
{
"name": "libName1",
"type": "all|components|modules",
"jsSrcsRoot": "libName1/js"
},
{
"name": "libName2",
"type": "all|components|modules",
"jsSrcsRoot": "libName2/src"
}
]
}
}
AFTER:
{
"codegenConfig": {
"name": "libraries",
"type": "all",
"jsSrcsRoot": "."
}
}
`);
printDeprecationWarningIfNeeded(dependency);
extractLibrariesFromConfigurationArray(
configFile,
codegenConfigKey,
Expand Down

0 comments on commit a459922

Please sign in to comment.