-
-
Notifications
You must be signed in to change notification settings - Fork 359
Expand file tree
/
Copy pathrn.patch.xcode.js
More file actions
executable file
·97 lines (82 loc) · 3.35 KB
/
rn.patch.xcode.js
File metadata and controls
executable file
·97 lines (82 loc) · 3.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#!/usr/bin/env node
const fs = require('fs');
const { argv } = require('process');
const xcode = require('xcode');
const parseArgs = require('minimist');
const semver = require('semver');
const { debug } = require('@sentry/core');
debug.enable();
const args = parseArgs(argv.slice(2));
if (!args.project) {
throw new Error('Missing --project');
}
if (!args['rn-version']) {
throw new Error('Missing --rn-version');
}
debug.log('Patching Xcode project', args.project, 'for RN version', args['rn-version']);
const newBundleScriptRNVersion = '0.69.0-rc.0';
const quotesFixRNVersion = '0.81.1'; // Version where quotes break the script
let bundleScript;
let bundleScriptRegex;
let bundlePatchRegex;
const symbolsScript = `
/bin/sh ../node_modules/@sentry/react-native/scripts/sentry-xcode-debug-files.sh
`;
const symbolsPatchRegex = /sentry-cli\s+(upload-dsym|debug-files upload)/;
if (semver.satisfies(args['rn-version'], `< ${newBundleScriptRNVersion}`, { includePrerelease: true })) {
debug.log('Applying old bundle script patch');
bundleScript = `
export NODE_BINARY=node
../node_modules/@sentry/react-native/scripts/sentry-xcode.sh ../node_modules/react-native/scripts/react-native-xcode.sh
`;
bundleScriptRegex = /(packager|scripts)\/react-native-xcode\.sh\b/;
bundlePatchRegex = /sentry-cli\s+react-native[\s-]xcode/;
} else if (semver.satisfies(args['rn-version'], `>= ${newBundleScriptRNVersion}`, { includePrerelease: true })) {
debug.log('Applying new bundle script patch');
const useQuotes = semver.lt(args['rn-version'], quotesFixRNVersion);
const quoteChar = useQuotes ? '\\"' : '';
bundleScript = `
WITH_ENVIRONMENT="../node_modules/react-native/scripts/xcode/with-environment.sh"
REACT_NATIVE_XCODE="../node_modules/react-native/scripts/react-native-xcode.sh"
/bin/sh -c "$WITH_ENVIRONMENT ${quoteChar}/bin/sh ../node_modules/@sentry/react-native/scripts/sentry-xcode.sh $REACT_NATIVE_XCODE${quoteChar}"
`;
bundleScriptRegex = /\/scripts\/react-native-xcode\.sh/i;
bundlePatchRegex = /sentry-cli\s+react-native\s+xcode/i;
} else {
throw new Error('Unknown RN version');
}
const project = xcode.project(args.project);
project.parseSync();
const buildPhasesRaw = project.hash.project.objects.PBXShellScriptBuildPhase;
const buildPhases = [];
for (const key in buildPhasesRaw) {
if (buildPhasesRaw[key].isa) {
buildPhases.push(buildPhasesRaw[key]);
}
}
buildPhases.forEach(phase => {
const isBundleReactNative = phase.shellScript.match(bundleScriptRegex);
const isPatched = phase.shellScript.match(bundlePatchRegex);
if (!isBundleReactNative) {
return;
}
if (isPatched) {
debug.warn('Xcode project Bundle RN Build phase already patched');
return;
}
phase.shellScript = JSON.stringify(bundleScript);
debug.log('Patched Xcode project Bundle RN Build phase');
});
const isSymbolsPhase = phase => phase.shellScript.match(symbolsPatchRegex);
const areSymbolsPatched = buildPhases.some(isSymbolsPhase);
if (!areSymbolsPatched) {
project.addBuildPhase([], 'PBXShellScriptBuildPhase', 'Upload Debug Symbols to Sentry', null, {
shellPath: '/bin/sh',
shellScript: symbolsScript,
});
debug.log('Added Xcode project Upload Debug Symbols Build phase');
} else {
debug.warn('Xcode project Upload Debug Symbols Build phase already patched');
}
fs.writeFileSync(args.project, project.writeSync());
debug.log('Patched Xcode project successfully!');