Skip to content

Commit 3b74e9a

Browse files
committed
update scripts
1 parent 1d16653 commit 3b74e9a

2 files changed

Lines changed: 56 additions & 10 deletions

File tree

autolink/postlink/__helpers__/generate_version_header.js

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,36 @@ const fs = require('fs');
33
const path = require('path');
44
const { getReactNativeVersion, findProjectPackageJson } = require('./reactNativeVersion');
55

6+
// Logging helper that writes to both stderr and a log file
7+
function log(message) {
8+
console.error(message);
9+
10+
// Also write to a log file for debugging if stderr is suppressed
11+
try {
12+
const logFile = path.join(__dirname, '../../../ios/rnn_version_detection.log');
13+
const timestamp = new Date().toISOString();
14+
fs.appendFileSync(logFile, `[${timestamp}] ${message}\n`, 'utf8');
15+
} catch (e) {
16+
// Ignore log file errors
17+
}
18+
}
19+
620
function generateVersionHeader() {
721
const startDir = __dirname;
822

9-
console.error(`[RNN] Searching for project package.json from: ${startDir}`);
10-
console.error(`[RNN] process.cwd(): ${process.cwd()}`);
23+
log(`[RNN] === React Native Version Detection ===`);
24+
log(`[RNN] Script location (__dirname): ${startDir}`);
25+
log(`[RNN] Working directory (cwd): ${process.cwd()}`);
1126

1227
const packageJsonPath = findProjectPackageJson();
1328

1429
if (!packageJsonPath) {
15-
console.error('[RNN] ERROR: Project package.json not found');
30+
log('[RNN] ❌ ERROR: Project package.json not found');
31+
log('[RNN] This usually means the script could not locate your React Native project.');
1632
return;
1733
}
1834

19-
console.error(`[RNN] Using package.json: ${packageJsonPath}`);
35+
log(`[RNN] ✓ Found package.json: ${packageJsonPath}`);
2036

2137
// Determine actual source of version
2238
const projectRoot = path.dirname(packageJsonPath);
@@ -32,11 +48,12 @@ function generateVersionHeader() {
3248
const versionInfo = getReactNativeVersion();
3349

3450
if (!versionInfo) {
35-
console.error('[RNN] ERROR: react-native not found in package.json');
51+
log('[RNN] ❌ ERROR: react-native not found in package.json or node_modules');
52+
log('[RNN] Make sure react-native is installed and listed as a dependency.');
3653
return;
3754
}
3855

39-
console.error(`[RNN] Found React Native version: ${versionInfo.raw} from ${versionSourceType}`);
56+
log(`[RNN] React Native ${versionInfo.raw} (source: ${versionSourceType})`);
4057

4158
const { major, minor, patch } = versionInfo;
4259

@@ -80,15 +97,16 @@ function generateVersionHeader() {
8097
}
8198

8299
if (!rnnPackageJson) {
83-
console.error('[RNN] ERROR: Could not find react-native-navigation root');
100+
log('[RNN] ERROR: Could not find react-native-navigation root directory');
84101
return;
85102
}
86103

87104
const outputFile = path.join(rnnPackageJson, 'ios/ReactNativeVersionExtracted.h');
88105

89106
fs.writeFileSync(outputFile, headerContent, 'utf8');
90-
console.error(`[RNN] ✅ Generated ${outputFile}`);
91-
console.error(`[RNN] Version: ${major}.${minor}.${patch}`);
107+
log(`[RNN] ✅ Generated header: ${outputFile}`);
108+
log(`[RNN] ✅ Version constants: ${major}.${minor}.${patch}`);
109+
log(`[RNN] === Completed Successfully ===`);
92110
}
93111

94112
// Run if called directly

autolink/postlink/__helpers__/reactNativeVersion.js

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,37 @@ var { warnn } = require('../log');
1010
function findProjectPackageJson() {
1111
var searchDirs = [process.cwd(), __dirname];
1212

13+
// PRIORITY: Check if we're in RNN's own directory structure (workspace/CI scenario)
14+
// In this case, __dirname would be like: /path/to/rnn/autolink/postlink/__helpers__
15+
// And we want to find: /path/to/rnn/playground/package.json
16+
var currentPath = __dirname;
17+
18+
// Walk up to find RNN root (containing this autolink folder)
19+
for (var k = 0; k < 5; k++) {
20+
// Check if this looks like RNN root by checking for playground subdirectory
21+
var playgroundPath = nodePath.join(currentPath, 'playground');
22+
var playgroundPackageJson = nodePath.join(playgroundPath, 'package.json');
23+
24+
if (fs.existsSync(playgroundPackageJson)) {
25+
try {
26+
var pkg = JSON.parse(fs.readFileSync(playgroundPackageJson, 'utf8'));
27+
if ((pkg.dependencies && pkg.dependencies['react-native']) ||
28+
(pkg.devDependencies && pkg.devDependencies['react-native'])) {
29+
// Found it! Prioritize this path
30+
searchDirs.unshift(playgroundPath);
31+
break;
32+
}
33+
} catch (e) { }
34+
}
35+
36+
var parent = nodePath.dirname(currentPath);
37+
if (parent === currentPath) break;
38+
currentPath = parent;
39+
}
40+
1341
// If we're inside a package (like in node_modules or a workspace),
1442
// also try searching from common project locations
15-
var currentPath = __dirname;
43+
currentPath = __dirname;
1644
for (var k = 0; k < 10; k++) {
1745
var basename = nodePath.basename(currentPath);
1846

0 commit comments

Comments
 (0)