Skip to content

Commit 5e93cf6

Browse files
sota000facebook-github-bot
authored andcommitted
Support monorepo/custom configuration where node_modules may not be located under app_root
Summary: This diff supports monorepo/custom configuration where node_modules may not be located under app_root. The default (RN_root, '..') should support most cases, but I also added an option to provide a custom location for users to set. Changelog: [internal] Reviewed By: ShikaSD Differential Revision: D32469957 fbshipit-source-id: 6b8a6c775c21bde72ef542e34973701d698f678f
1 parent 9822464 commit 5e93cf6

File tree

2 files changed

+24
-7
lines changed

2 files changed

+24
-7
lines changed

scripts/generate-artifacts.js

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,18 @@ const argv = yargs
4848
description: 'A flag to control whether to generate fabric components.',
4949
boolean: 'e',
5050
})
51+
.option('c', {
52+
alias: 'configFileDir',
53+
default: '',
54+
description:
55+
'Path where codegen config files are located (e.g. node_modules dir).',
56+
})
5157
.usage('Usage: $0 -p [path to app]')
5258
.demandOption(['p']).argv;
5359

5460
const RN_ROOT = path.join(__dirname, '..');
5561
const CODEGEN_CONFIG_FILENAME = argv.f;
62+
const CODEGEN_CONFIG_FILE_DIR = argv.c;
5663
const CODEGEN_CONFIG_KEY = argv.k;
5764
const CODEGEN_FABRIC_ENABLED = argv.e;
5865
const CODEGEN_REPO_PATH = `${RN_ROOT}/packages/react-native-codegen`;
@@ -80,18 +87,15 @@ function main(appRootDir, outputPath) {
8087
const dependencies = {...pkgJson.dependencies, ...pkgJson.devDependencies};
8188

8289
// 3. Determine which of these are codegen-enabled libraries
90+
const confifDir = CODEGEN_CONFIG_FILE_DIR || path.join(RN_ROOT, '..');
8391
console.log(
84-
`\n\n[Codegen] >>>>> Searching for codegen-enabled libraries in ${appRootDir}`,
92+
`\n\n[Codegen] >>>>> Searching for codegen-enabled libraries in ${confifDir}`,
8593
);
8694
const libraries = [];
8795

8896
// Handle react-native and third-party libraries
8997
Object.keys(dependencies).forEach(dependency => {
90-
const codegenConfigFileDir = path.join(
91-
appRootDir,
92-
'node_modules',
93-
dependency,
94-
);
98+
const codegenConfigFileDir = path.join(confifDir, dependency);
9599
const configFilePath = path.join(
96100
codegenConfigFileDir,
97101
CODEGEN_CONFIG_FILENAME,
@@ -165,6 +169,9 @@ function main(appRootDir, outputPath) {
165169
// 5. For each codegen-enabled library, generate the native code spec files
166170
libraries.forEach(library => {
167171
if (!CODEGEN_FABRIC_ENABLED && library.config.type === 'components') {
172+
console.log(
173+
`[Codegen] ${library.config.name} skipped because fabric is not enabled.`,
174+
);
168175
return;
169176
}
170177
const tmpDir = fs.mkdtempSync(

scripts/react_native_pods.rb

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -319,8 +319,18 @@ def use_react_native_codegen_discovery!(options={})
319319
react_native_path = options[:react_native_path] ||= "../node_modules/react-native"
320320
app_path = options[:app_path]
321321
fabric_enabled = options[:fabric_enabled] ||= false
322+
config_file_dir = options[:config_file_dir] ||= ''
322323
if app_path
323-
Pod::Executable.execute_command('node', ["#{react_native_path}/scripts/generate-artifacts.js", "-p", "#{app_path}", "-o", Pod::Config.instance.installation_root, "-e", "#{fabric_enabled}"])
324+
out = Pod::Executable.execute_command(
325+
'node',
326+
[
327+
"#{react_native_path}/scripts/generate-artifacts.js",
328+
"-p", "#{app_path}",
329+
"-o", Pod::Config.instance.installation_root,
330+
"-e", "#{fabric_enabled}",
331+
"-c", "#{config_file_dir}",
332+
])
333+
Pod::UI.puts out;
324334
else
325335
Pod::UI.warn '[Codegen] error: no app_path was provided'
326336
exit 1

0 commit comments

Comments
 (0)