mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Refactor generate-artifacts-executor.js: remove configFileDir CLI argument, use node resolution instead (#41557)
Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/41557 The `configFileDir` CLI argument is used to help to find paths to the 3rd party dependencies of the app. Since we only care about dependencies listed in the root `package.json`, we can use `node` resolution instead of having to construct paths manually. In that case `configFileDir` becomes redundant. Changelog: [iOS][Breaking] - Delete configFileDir CLI argument. Reviewed By: cipolleschi Differential Revision: D51303793 fbshipit-source-id: 46cb61197ddf51515af634c8fc6b85a8d218c51e
This commit is contained in:
committed by
Facebook GitHub Bot
parent
1e68e48534
commit
8a62d6135f
+1
-6
@@ -173,12 +173,7 @@ describe('findCodegenEnabledLibraries', () => {
|
||||
},
|
||||
}));
|
||||
|
||||
const libraries = findCodegenEnabledLibraries(
|
||||
`${projectDir}/app`,
|
||||
baseCodegenConfigFileDir,
|
||||
`package.json`,
|
||||
'codegenConfig',
|
||||
);
|
||||
const libraries = findCodegenEnabledLibraries(`${projectDir}/app`);
|
||||
|
||||
expect(libraries).toEqual([
|
||||
{
|
||||
|
||||
@@ -151,32 +151,32 @@ function handleReactNativeCoreLibraries() {
|
||||
);
|
||||
}
|
||||
|
||||
function handleThirdPartyLibraries(baseCodegenConfigFileDir, dependencies) {
|
||||
function handleThirdPartyLibraries(pkgJson) {
|
||||
const dependencies = {...pkgJson.dependencies, ...pkgJson.devDependencies};
|
||||
// Determine which of these are codegen-enabled libraries
|
||||
const configDir =
|
||||
baseCodegenConfigFileDir ||
|
||||
path.join(REACT_NATIVE_PACKAGE_ROOT_FOLDER, '..');
|
||||
console.log(
|
||||
`\n\n[Codegen] >>>>> Searching for codegen-enabled libraries in ${configDir}`,
|
||||
'\n\n[Codegen] >>>>> Searching for codegen-enabled libraries in the project dependencies.',
|
||||
);
|
||||
|
||||
// Handle third-party libraries
|
||||
return Object.keys(dependencies).flatMap(dependency => {
|
||||
if (dependency === REACT_NATIVE) {
|
||||
// react-native should already be added.
|
||||
return [];
|
||||
}
|
||||
let configFile;
|
||||
try {
|
||||
configFile = readPkgJsonInDirectory(codegenConfigFileDir);
|
||||
} catch {
|
||||
const configFilePath = require.resolve(
|
||||
path.join(dependency, 'package.json'),
|
||||
);
|
||||
const configFile = JSON.parse(fs.readFileSync(configFilePath));
|
||||
const codegenConfigFileDir = path.dirname(configFilePath);
|
||||
return extractLibrariesFromJSON(
|
||||
configFile,
|
||||
dependency,
|
||||
codegenConfigFileDir,
|
||||
);
|
||||
} catch (e) {
|
||||
return [];
|
||||
}
|
||||
return extractLibrariesFromJSON(
|
||||
configFile,
|
||||
dependency,
|
||||
codegenConfigFileDir,
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -338,12 +338,11 @@ function createComponentProvider(schemas) {
|
||||
console.log(`Generated provider in: ${outputDir}`);
|
||||
}
|
||||
|
||||
function findCodegenEnabledLibraries(appRootDir, baseCodegenConfigFileDir) {
|
||||
function findCodegenEnabledLibraries(appRootDir) {
|
||||
const pkgJson = readPkgJsonInDirectory(appRootDir);
|
||||
const dependencies = {...pkgJson.dependencies, ...pkgJson.devDependencies};
|
||||
return [
|
||||
...handleReactNativeCoreLibraries(),
|
||||
...handleThirdPartyLibraries(baseCodegenConfigFileDir, dependencies),
|
||||
...handleThirdPartyLibraries(pkgJson),
|
||||
...handleLibrariesFromReactNativeConfig(appRootDir),
|
||||
...handleInAppLibraries(pkgJson, appRootDir),
|
||||
];
|
||||
@@ -393,12 +392,11 @@ function cleanupEmptyFilesAndFolders(filepath) {
|
||||
*
|
||||
* @parameter appRootDir: the directory with the app source code, where the package.json lives.
|
||||
* @parameter outputPath: the base output path for the CodeGen.
|
||||
* @parameter baseCodegenConfigFileDir: the directory of the codeGenConfigFile.
|
||||
* @throws If it can't find a config file for react-native.
|
||||
* @throws If it can't find a CodeGen configuration in the file.
|
||||
* @throws If it can't find a cli for the CodeGen.
|
||||
*/
|
||||
function execute(appRootDir, outputPath, baseCodegenConfigFileDir) {
|
||||
function execute(appRootDir, outputPath) {
|
||||
if (!isAppRootValid(appRootDir)) {
|
||||
return;
|
||||
}
|
||||
@@ -406,10 +404,7 @@ function execute(appRootDir, outputPath, baseCodegenConfigFileDir) {
|
||||
buildCodegenIfNeeded();
|
||||
|
||||
try {
|
||||
const libraries = findCodegenEnabledLibraries(
|
||||
appRootDir,
|
||||
baseCodegenConfigFileDir,
|
||||
);
|
||||
const libraries = findCodegenEnabledLibraries(appRootDir);
|
||||
|
||||
if (libraries.length === 0) {
|
||||
console.log('[Codegen] No codegen-enabled libraries found.');
|
||||
|
||||
@@ -21,13 +21,7 @@ const argv = yargs
|
||||
alias: 'outputPath',
|
||||
description: 'Path where generated artifacts will be output to',
|
||||
})
|
||||
.option('c', {
|
||||
alias: 'configFileDir',
|
||||
default: '',
|
||||
description:
|
||||
'Path where codegen config files are located (e.g. node_modules dir).',
|
||||
})
|
||||
.usage('Usage: $0 -p [path to app]')
|
||||
.demandOption(['p']).argv;
|
||||
|
||||
executor.execute(argv.path, argv.outputPath, argv.configFileDir);
|
||||
executor.execute(argv.path, argv.outputPath);
|
||||
|
||||
@@ -11,7 +11,6 @@ def snap_get_script_phases_with_codegen_discovery_with_config_file_dir()
|
||||
|
||||
export RCT_SCRIPT_RN_DIR=$RCT_SCRIPT_POD_INSTALLATION_ROOT/../..
|
||||
export RCT_SCRIPT_APP_PATH=$RCT_SCRIPT_POD_INSTALLATION_ROOT/
|
||||
export RCT_SCRIPT_CONFIG_FILE_DIR=$RCT_SCRIPT_POD_INSTALLATION_ROOT/node_modules
|
||||
export RCT_SCRIPT_OUTPUT_DIR=$RCT_SCRIPT_POD_INSTALLATION_ROOT
|
||||
export RCT_SCRIPT_TYPE=withCodegenDiscovery
|
||||
|
||||
@@ -29,7 +28,6 @@ def snap_get_script_phases_with_codegen_discovery_without_config_file_dir()
|
||||
|
||||
export RCT_SCRIPT_RN_DIR=$RCT_SCRIPT_POD_INSTALLATION_ROOT/../..
|
||||
export RCT_SCRIPT_APP_PATH=$RCT_SCRIPT_POD_INSTALLATION_ROOT/
|
||||
export RCT_SCRIPT_CONFIG_FILE_DIR=
|
||||
export RCT_SCRIPT_OUTPUT_DIR=$RCT_SCRIPT_POD_INSTALLATION_ROOT
|
||||
export RCT_SCRIPT_TYPE=withCodegenDiscovery
|
||||
|
||||
|
||||
@@ -11,7 +11,6 @@ def get_script_phases_with_codegen_discovery(options)
|
||||
export_vars = {
|
||||
'RCT_SCRIPT_RN_DIR' => "$RCT_SCRIPT_POD_INSTALLATION_ROOT/#{options[:react_native_path]}",
|
||||
'RCT_SCRIPT_APP_PATH' => "$RCT_SCRIPT_POD_INSTALLATION_ROOT/#{options[:relative_app_root]}",
|
||||
'RCT_SCRIPT_CONFIG_FILE_DIR' => "#{options[:relative_config_file_dir] != '' ? "$RCT_SCRIPT_POD_INSTALLATION_ROOT/#{options[:relative_config_file_dir]}" : ''}",
|
||||
'RCT_SCRIPT_OUTPUT_DIR' => "$RCT_SCRIPT_POD_INSTALLATION_ROOT",
|
||||
'RCT_SCRIPT_TYPE' => "withCodegenDiscovery",
|
||||
}
|
||||
|
||||
@@ -96,7 +96,7 @@ generateCodegenArtifactsFromSchema () {
|
||||
generateArtifacts () {
|
||||
describe "Generating codegen artifacts"
|
||||
pushd "$RCT_SCRIPT_RN_DIR" >/dev/null || exit 1
|
||||
"$NODE_BINARY" "scripts/generate-codegen-artifacts.js" --path "$RCT_SCRIPT_APP_PATH" --outputPath "$TEMP_OUTPUT_DIR" --configFileDir "$RCT_SCRIPT_CONFIG_FILE_DIR"
|
||||
"$NODE_BINARY" "scripts/generate-codegen-artifacts.js" --path "$RCT_SCRIPT_APP_PATH" --outputPath "$TEMP_OUTPUT_DIR"
|
||||
popd >/dev/null || exit 1
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user