Skip to content

Commit 645cf68

Browse files
Riccardo Cipolleschiroryabraham
authored andcommitted
Silence deprecation warning for react-native dependency. (facebook#34368)
Summary: Pull Request resolved: facebook#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
1 parent feddf30 commit 645cf68

File tree

3 files changed

+42
-51
lines changed

3 files changed

+42
-51
lines changed

scripts/cocoapods/__tests__/codegen_utils-test.rb

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ def testGetCodegenConfigFromFile_whenFileDoesNotExists_returnEmpty
125125
codegen = CodegenUtils.new().get_codegen_config_from_file('package.json', 'codegenConfig')
126126

127127
# Assert
128-
assert_equal(codegen, {'libraries' => []})
128+
assert_equal(codegen, {})
129129
end
130130

131131
def testGetCodegenConfigFromFile_whenFileExistsButHasNoKey_returnEmpty
@@ -137,7 +137,7 @@ def testGetCodegenConfigFromFile_whenFileExistsButHasNoKey_returnEmpty
137137
codegen = CodegenUtils.new().get_codegen_config_from_file('package.json', 'codegen')
138138

139139
# Assert
140-
assert_equal(codegen, {'libraries' => []})
140+
assert_equal(codegen, {})
141141
end
142142

143143
def testGetCodegenConfigFromFile_whenFileExistsAndHasKey_returnObject
@@ -213,19 +213,6 @@ def testGetListOfJSSpecs_whenDoesNotUsesLibraries_returnAListOfFiles
213213
])
214214
end
215215

216-
def testGetListOfJSSpecs_whenMisconfigured_aborts
217-
# Arrange
218-
app_codegen_config = {}
219-
app_path = "~/MyApp/"
220-
# Act
221-
assert_raises() {
222-
files = CodegenUtils.new().get_list_of_js_specs(app_codegen_config, app_path)
223-
}
224-
# Assert
225-
assert_equal(Pod::UI.collected_warns , ["[Error] Codegen not properly configured. Please add the `codegenConfig` entry to your `package.json`"])
226-
227-
end
228-
229216
# ================================== #
230217
# Test - GetReactCodegenScriptPhases #
231218
# ================================== #

scripts/cocoapods/codegen_utils.rb

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ def get_react_codegen_spec(package_json_file, folly_version: '2021.07.22.00', fa
131131
#
132132
# Returns: the list of dependencies as extracted from the package.json
133133
def get_codegen_config_from_file(config_path, config_key)
134-
empty = {'libraries' => []}
134+
empty = {}
135135
if !File.exist?(config_path)
136136
return empty
137137
end
@@ -159,9 +159,6 @@ def get_list_of_js_specs(app_codegen_config, app_path)
159159
elsif app_codegen_config['jsSrcsDir'] then
160160
codegen_dir = File.join(app_path, app_codegen_config['jsSrcsDir'])
161161
file_list.concat (Finder.find_codegen_file(codegen_dir))
162-
else
163-
Pod::UI.warn '[Error] Codegen not properly configured. Please add the `codegenConfig` entry to your `package.json`'
164-
abort
165162
end
166163

167164
input_files = file_list.map { |filename| "${PODS_ROOT}/../#{Pathname.new(filename).realpath().relative_path_from(Pod::Config.instance.installation_root)}" }

scripts/codegen/generate-artifacts-executor.js

Lines changed: 39 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,44 @@ function readPackageJSON(appRootDir) {
5151
return JSON.parse(fs.readFileSync(path.join(appRootDir, 'package.json')));
5252
}
5353

54+
function printDeprecationWarningIfNeeded(dependency) {
55+
if (dependency === REACT_NATIVE_DEPENDENCY_NAME) {
56+
return;
57+
}
58+
console.log(`[Codegen] CodegenConfig Deprecated Setup for ${dependency}.
59+
The configuration file still contains the codegen in the libraries array.
60+
If possible, replace it with a single object.
61+
`);
62+
console.debug(`BEFORE:
63+
{
64+
// ...
65+
"codegenConfig": {
66+
"libraries": [
67+
{
68+
"name": "libName1",
69+
"type": "all|components|modules",
70+
"jsSrcsRoot": "libName1/js"
71+
},
72+
{
73+
"name": "libName2",
74+
"type": "all|components|modules",
75+
"jsSrcsRoot": "libName2/src"
76+
}
77+
]
78+
}
79+
}
80+
81+
AFTER:
82+
{
83+
"codegenConfig": {
84+
"name": "libraries",
85+
"type": "all",
86+
"jsSrcsRoot": "."
87+
}
88+
}
89+
`);
90+
}
91+
5492
// Reading Libraries
5593
function extractLibrariesFromConfigurationArray(
5694
configFile,
@@ -102,38 +140,7 @@ function extractLibrariesFromJSON(
102140
libraryPath: dependencyPath,
103141
});
104142
} else {
105-
console.log(`[Codegen] CodegenConfig Deprecated Setup for ${dependency}.
106-
The configuration file still contains the codegen in the libraries array.
107-
If possible, replace it with a single object.
108-
`);
109-
console.debug(`BEFORE:
110-
{
111-
// ...
112-
"codegenConfig": {
113-
"libraries": [
114-
{
115-
"name": "libName1",
116-
"type": "all|components|modules",
117-
"jsSrcsRoot": "libName1/js"
118-
},
119-
{
120-
"name": "libName2",
121-
"type": "all|components|modules",
122-
"jsSrcsRoot": "libName2/src"
123-
}
124-
]
125-
}
126-
}
127-
128-
AFTER:
129-
{
130-
"codegenConfig": {
131-
"name": "libraries",
132-
"type": "all",
133-
"jsSrcsRoot": "."
134-
}
135-
}
136-
`);
143+
printDeprecationWarningIfNeeded(dependency);
137144
extractLibrariesFromConfigurationArray(
138145
configFile,
139146
codegenConfigKey,

0 commit comments

Comments
 (0)