@sentry/wizard 3.14.1 → 3.16.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (120) hide show
  1. package/CHANGELOG.md +19 -4
  2. package/dist/lib/Steps/ChooseIntegration.js +1 -1
  3. package/dist/lib/Steps/ChooseIntegration.js.map +1 -1
  4. package/dist/lib/Steps/Integrations/ReactNative.d.ts +7 -32
  5. package/dist/lib/Steps/Integrations/ReactNative.js +17 -485
  6. package/dist/lib/Steps/Integrations/ReactNative.js.map +1 -1
  7. package/dist/package.json +1 -1
  8. package/dist/src/android/android-wizard.js +13 -18
  9. package/dist/src/android/android-wizard.js.map +1 -1
  10. package/dist/src/apple/apple-wizard.js +11 -4
  11. package/dist/src/apple/apple-wizard.js.map +1 -1
  12. package/dist/src/apple/cocoapod.d.ts +1 -0
  13. package/dist/src/apple/cocoapod.js +36 -13
  14. package/dist/src/apple/cocoapod.js.map +1 -1
  15. package/dist/src/nextjs/nextjs-wizard.js +1 -1
  16. package/dist/src/nextjs/nextjs-wizard.js.map +1 -1
  17. package/dist/src/react-native/glob.d.ts +3 -0
  18. package/dist/src/react-native/glob.js +18 -0
  19. package/dist/src/react-native/glob.js.map +1 -0
  20. package/dist/src/react-native/gradle.d.ts +4 -0
  21. package/dist/src/react-native/gradle.js +49 -0
  22. package/dist/src/react-native/gradle.js.map +1 -0
  23. package/dist/src/react-native/javascript.d.ts +8 -0
  24. package/dist/src/react-native/javascript.js +25 -0
  25. package/dist/src/react-native/javascript.js.map +1 -0
  26. package/dist/src/react-native/options.d.ts +4 -0
  27. package/dist/src/react-native/options.js +3 -0
  28. package/dist/src/react-native/options.js.map +1 -0
  29. package/dist/src/react-native/react-native-wizard.d.ts +9 -0
  30. package/dist/src/react-native/react-native-wizard.js +356 -0
  31. package/dist/src/react-native/react-native-wizard.js.map +1 -0
  32. package/dist/src/react-native/uninstall.d.ts +2 -0
  33. package/dist/src/react-native/uninstall.js +130 -0
  34. package/dist/src/react-native/uninstall.js.map +1 -0
  35. package/dist/src/react-native/xcode.d.ts +18 -0
  36. package/dist/src/react-native/xcode.js +170 -0
  37. package/dist/src/react-native/xcode.js.map +1 -0
  38. package/dist/src/remix/codemods/handle-error.js +28 -0
  39. package/dist/src/remix/codemods/handle-error.js.map +1 -1
  40. package/dist/src/remix/codemods/root-common.d.ts +2 -0
  41. package/dist/src/remix/codemods/root-common.js +70 -0
  42. package/dist/src/remix/codemods/root-common.js.map +1 -0
  43. package/dist/src/remix/codemods/root-v1.js +5 -36
  44. package/dist/src/remix/codemods/root-v1.js.map +1 -1
  45. package/dist/src/remix/codemods/root-v2.js +53 -4
  46. package/dist/src/remix/codemods/root-v2.js.map +1 -1
  47. package/dist/src/remix/remix-wizard.js +8 -5
  48. package/dist/src/remix/remix-wizard.js.map +1 -1
  49. package/dist/src/remix/sdk-setup.d.ts +1 -0
  50. package/dist/src/remix/sdk-setup.js +10 -6
  51. package/dist/src/remix/sdk-setup.js.map +1 -1
  52. package/dist/src/remix/templates.d.ts +1 -1
  53. package/dist/src/remix/templates.js +1 -1
  54. package/dist/src/remix/templates.js.map +1 -1
  55. package/dist/src/remix/utils.d.ts +2 -0
  56. package/dist/src/remix/utils.js +6 -1
  57. package/dist/src/remix/utils.js.map +1 -1
  58. package/dist/src/sourcemaps/tools/nextjs.js +3 -3
  59. package/dist/src/sourcemaps/tools/nextjs.js.map +1 -1
  60. package/dist/src/sourcemaps/tools/sentry-cli.js +1 -1
  61. package/dist/src/sourcemaps/tools/sentry-cli.js.map +1 -1
  62. package/dist/src/sveltekit/sveltekit-wizard.js +1 -1
  63. package/dist/src/sveltekit/sveltekit-wizard.js.map +1 -1
  64. package/dist/src/utils/clack-utils.d.ts +19 -3
  65. package/dist/src/utils/clack-utils.js +141 -39
  66. package/dist/src/utils/clack-utils.js.map +1 -1
  67. package/dist/src/utils/semver.d.ts +5 -0
  68. package/dist/src/utils/semver.js +27 -0
  69. package/dist/src/utils/semver.js.map +1 -0
  70. package/dist/src/utils/sentrycli-utils.js +4 -1
  71. package/dist/src/utils/sentrycli-utils.js.map +1 -1
  72. package/dist/src/utils/types.d.ts +3 -0
  73. package/dist/src/utils/types.js.map +1 -1
  74. package/dist/test/react-native/gradle.test.js +57 -0
  75. package/dist/test/react-native/gradle.test.js.map +1 -0
  76. package/dist/test/react-native/javascript.test.js +47 -0
  77. package/dist/test/react-native/javascript.test.js.map +1 -0
  78. package/dist/test/react-native/xcode.test.d.ts +1 -0
  79. package/dist/test/react-native/xcode.test.js +144 -0
  80. package/dist/test/react-native/xcode.test.js.map +1 -0
  81. package/lib/Steps/ChooseIntegration.ts +1 -1
  82. package/lib/Steps/Integrations/ReactNative.ts +17 -573
  83. package/package.json +1 -1
  84. package/src/android/android-wizard.ts +3 -18
  85. package/src/apple/apple-wizard.ts +12 -3
  86. package/src/apple/cocoapod.ts +20 -9
  87. package/src/nextjs/nextjs-wizard.ts +1 -1
  88. package/src/react-native/glob.ts +13 -0
  89. package/src/react-native/gradle.ts +26 -0
  90. package/src/react-native/javascript.ts +33 -0
  91. package/src/react-native/options.ts +5 -0
  92. package/src/react-native/react-native-wizard.ts +369 -0
  93. package/src/react-native/uninstall.ts +107 -0
  94. package/src/react-native/xcode.ts +228 -0
  95. package/src/remix/codemods/handle-error.ts +30 -0
  96. package/src/remix/codemods/root-common.ts +63 -0
  97. package/src/remix/codemods/root-v1.ts +3 -53
  98. package/src/remix/codemods/root-v2.ts +71 -2
  99. package/src/remix/remix-wizard.ts +9 -6
  100. package/src/remix/sdk-setup.ts +14 -6
  101. package/src/remix/templates.ts +2 -6
  102. package/src/remix/utils.ts +5 -0
  103. package/src/sourcemaps/tools/nextjs.ts +6 -6
  104. package/src/sourcemaps/tools/sentry-cli.ts +1 -1
  105. package/src/sveltekit/sveltekit-wizard.ts +1 -1
  106. package/src/utils/clack-utils.ts +229 -74
  107. package/src/utils/semver.ts +33 -0
  108. package/src/utils/sentrycli-utils.ts +3 -1
  109. package/src/utils/types.ts +3 -0
  110. package/test/react-native/gradle.test.ts +310 -0
  111. package/test/react-native/javascript.test.ts +131 -0
  112. package/test/react-native/xcode.test.ts +238 -0
  113. package/dist/lib/Steps/Integrations/__tests__/ReactNative.js +0 -198
  114. package/dist/lib/Steps/Integrations/__tests__/ReactNative.js.map +0 -1
  115. package/dist/lib/__tests__/Setup.js +0 -57
  116. package/dist/lib/__tests__/Setup.js.map +0 -1
  117. package/lib/Steps/Integrations/__tests__/ReactNative.ts +0 -136
  118. package/lib/__tests__/Setup.ts +0 -42
  119. /package/dist/{lib/Steps/Integrations/__tests__/ReactNative.d.ts → test/react-native/gradle.test.d.ts} +0 -0
  120. /package/dist/{lib/__tests__/Setup.d.ts → test/react-native/javascript.test.d.ts} +0 -0
@@ -0,0 +1,310 @@
1
+ import {
2
+ addRNSentryGradlePlugin,
3
+ doesAppBuildGradleIncludeRNSentryGradlePlugin,
4
+ removeRNSentryGradlePlugin,
5
+ } from '../../src/react-native/gradle';
6
+
7
+ describe('react-native gradle', () => {
8
+ describe('doesAppBuildGradleIncludeSentry', () => {
9
+ it('returns false for empty file', () => {
10
+ expect(doesAppBuildGradleIncludeRNSentryGradlePlugin('')).toBe(false);
11
+ });
12
+
13
+ it('returns false for minimal app/build.gradle', () => {
14
+ const appBuildGradle = `apply plugin: "com.android.application"
15
+
16
+ android {
17
+ ndkVersion rootProject.ext.ndkVersion
18
+
19
+ compileSdkVersion rootProject.ext.compileSdkVersion
20
+
21
+ namespace "com.samplenewarchitecture"
22
+ defaultConfig {
23
+ applicationId "com.samplenewarchitecture"
24
+ minSdkVersion rootProject.ext.minSdkVersion
25
+ targetSdkVersion rootProject.ext.targetSdkVersion
26
+ versionCode 1
27
+ versionName "1.0"
28
+ }
29
+ }
30
+ `;
31
+ expect(
32
+ doesAppBuildGradleIncludeRNSentryGradlePlugin(appBuildGradle),
33
+ ).toBe(false);
34
+ });
35
+
36
+ it('returns false for app/build.gradle with SAGP', () => {
37
+ const appBuildGradle = `apply plugin: "com.android.application"
38
+ apply plugin: "io.sentry.android.gradle"
39
+
40
+ sentry {
41
+ }
42
+
43
+ android {
44
+ ndkVersion rootProject.ext.ndkVersion
45
+
46
+ compileSdkVersion rootProject.ext.compileSdkVersion
47
+
48
+ namespace "com.samplenewarchitecture"
49
+ defaultConfig {
50
+ applicationId "com.samplenewarchitecture"
51
+ minSdkVersion rootProject.ext.minSdkVersion
52
+ targetSdkVersion rootProject.ext.targetSdkVersion
53
+ versionCode 1
54
+ versionName "1.0"
55
+ }
56
+ }
57
+ `;
58
+ expect(
59
+ doesAppBuildGradleIncludeRNSentryGradlePlugin(appBuildGradle),
60
+ ).toBe(false);
61
+ });
62
+
63
+ it('returns true for app/build.gradle with RN SAGP', () => {
64
+ const appBuildGradle = `apply plugin: "com.android.application"
65
+ apply plugin: "io.sentry.android.gradle"
66
+
67
+ sentry {
68
+ }
69
+
70
+ apply from: new File(["node", "--print", "require.resolve('@sentry/react-native/package.json')"].execute().text.trim(), "../sentry.gradle")
71
+
72
+ android {
73
+ ndkVersion rootProject.ext.ndkVersion
74
+
75
+ compileSdkVersion rootProject.ext.compileSdkVersion
76
+
77
+ namespace "com.samplenewarchitecture"
78
+ defaultConfig {
79
+ applicationId "com.samplenewarchitecture"
80
+ minSdkVersion rootProject.ext.minSdkVersion
81
+ targetSdkVersion rootProject.ext.targetSdkVersion
82
+ versionCode 1
83
+ versionName "1.0"
84
+ }
85
+ }
86
+ `;
87
+ expect(
88
+ doesAppBuildGradleIncludeRNSentryGradlePlugin(appBuildGradle),
89
+ ).toBe(true);
90
+ });
91
+ });
92
+
93
+ describe('addRNSentryGradlePlugin', () => {
94
+ it('does not add nothing to empty file', () => {
95
+ expect(addRNSentryGradlePlugin('')).toBe('');
96
+ });
97
+
98
+ it('does add RN SAGP', () => {
99
+ const input = `apply plugin: "com.android.application"
100
+
101
+ android {
102
+ ndkVersion rootProject.ext.ndkVersion
103
+
104
+ compileSdkVersion rootProject.ext.compileSdkVersion
105
+
106
+ namespace "com.samplenewarchitecture"
107
+ defaultConfig {
108
+ applicationId "com.samplenewarchitecture"
109
+ minSdkVersion rootProject.ext.minSdkVersion
110
+ targetSdkVersion rootProject.ext.targetSdkVersion
111
+ versionCode 1
112
+ versionName "1.0"
113
+ }
114
+ }
115
+ `;
116
+ const expectedOutput = `apply plugin: "com.android.application"
117
+
118
+ apply from: new File(["node", "--print", "require.resolve('@sentry/react-native/package.json')"].execute().text.trim(), "../sentry.gradle")
119
+ android {
120
+ ndkVersion rootProject.ext.ndkVersion
121
+
122
+ compileSdkVersion rootProject.ext.compileSdkVersion
123
+
124
+ namespace "com.samplenewarchitecture"
125
+ defaultConfig {
126
+ applicationId "com.samplenewarchitecture"
127
+ minSdkVersion rootProject.ext.minSdkVersion
128
+ targetSdkVersion rootProject.ext.targetSdkVersion
129
+ versionCode 1
130
+ versionName "1.0"
131
+ }
132
+ }
133
+ `;
134
+ expect(addRNSentryGradlePlugin(input)).toBe(expectedOutput);
135
+ });
136
+
137
+ it('does add RN SAGP to build gradle with SAGP', () => {
138
+ const input = `apply plugin: "com.android.application"
139
+ apply plugin: "io.sentry.android.gradle"
140
+
141
+ sentry {
142
+ }
143
+
144
+ android {
145
+ ndkVersion rootProject.ext.ndkVersion
146
+
147
+ compileSdkVersion rootProject.ext.compileSdkVersion
148
+
149
+ namespace "com.samplenewarchitecture"
150
+ defaultConfig {
151
+ applicationId "com.samplenewarchitecture"
152
+ minSdkVersion rootProject.ext.minSdkVersion
153
+ targetSdkVersion rootProject.ext.targetSdkVersion
154
+ versionCode 1
155
+ versionName "1.0"
156
+ }
157
+ }
158
+ `;
159
+ const expectedOutput = `apply plugin: "com.android.application"
160
+ apply plugin: "io.sentry.android.gradle"
161
+
162
+ sentry {
163
+ }
164
+
165
+ apply from: new File(["node", "--print", "require.resolve('@sentry/react-native/package.json')"].execute().text.trim(), "../sentry.gradle")
166
+ android {
167
+ ndkVersion rootProject.ext.ndkVersion
168
+
169
+ compileSdkVersion rootProject.ext.compileSdkVersion
170
+
171
+ namespace "com.samplenewarchitecture"
172
+ defaultConfig {
173
+ applicationId "com.samplenewarchitecture"
174
+ minSdkVersion rootProject.ext.minSdkVersion
175
+ targetSdkVersion rootProject.ext.targetSdkVersion
176
+ versionCode 1
177
+ versionName "1.0"
178
+ }
179
+ }
180
+ `;
181
+ expect(addRNSentryGradlePlugin(input)).toBe(expectedOutput);
182
+ });
183
+ });
184
+
185
+ describe('removeRNSentryGradlePlugin', () => {
186
+ it('does not add nothing to empty file', () => {
187
+ expect(removeRNSentryGradlePlugin('')).toBe('');
188
+ });
189
+
190
+ it('does not change build gradle without RN SAGP', () => {
191
+ const input = `apply plugin: "com.android.application"
192
+ apply plugin: "io.sentry.android.gradle"
193
+
194
+ sentry {
195
+ }
196
+
197
+ android {
198
+ ndkVersion rootProject.ext.ndkVersion
199
+
200
+ compileSdkVersion rootProject.ext.compileSdkVersion
201
+
202
+ namespace "com.samplenewarchitecture"
203
+ defaultConfig {
204
+ applicationId "com.samplenewarchitecture"
205
+ minSdkVersion rootProject.ext.minSdkVersion
206
+ targetSdkVersion rootProject.ext.targetSdkVersion
207
+ versionCode 1
208
+ versionName "1.0"
209
+ }
210
+ }
211
+ `;
212
+
213
+ expect(removeRNSentryGradlePlugin(input)).toBe(input);
214
+ });
215
+
216
+ it('does remove RN SAGP referenced by node resolved path', () => {
217
+ const input = `apply plugin: "com.android.application"
218
+ apply plugin: "io.sentry.android.gradle"
219
+
220
+ sentry {
221
+ }
222
+
223
+ apply from: new File(["node", "--print", "require.resolve('@sentry/react-native/package.json')"].execute().text.trim(), "../sentry.gradle")
224
+ android {
225
+ ndkVersion rootProject.ext.ndkVersion
226
+
227
+ compileSdkVersion rootProject.ext.compileSdkVersion
228
+
229
+ namespace "com.samplenewarchitecture"
230
+ defaultConfig {
231
+ applicationId "com.samplenewarchitecture"
232
+ minSdkVersion rootProject.ext.minSdkVersion
233
+ targetSdkVersion rootProject.ext.targetSdkVersion
234
+ versionCode 1
235
+ versionName "1.0"
236
+ }
237
+ }
238
+ `;
239
+ const output = `apply plugin: "com.android.application"
240
+ apply plugin: "io.sentry.android.gradle"
241
+
242
+ sentry {
243
+ }
244
+ android {
245
+ ndkVersion rootProject.ext.ndkVersion
246
+
247
+ compileSdkVersion rootProject.ext.compileSdkVersion
248
+
249
+ namespace "com.samplenewarchitecture"
250
+ defaultConfig {
251
+ applicationId "com.samplenewarchitecture"
252
+ minSdkVersion rootProject.ext.minSdkVersion
253
+ targetSdkVersion rootProject.ext.targetSdkVersion
254
+ versionCode 1
255
+ versionName "1.0"
256
+ }
257
+ }
258
+ `;
259
+
260
+ expect(removeRNSentryGradlePlugin(input)).toBe(output);
261
+ });
262
+
263
+ it('does remove RN SAGP reference by relative path', () => {
264
+ const input = `apply plugin: "com.android.application"
265
+ apply plugin: "io.sentry.android.gradle"
266
+
267
+ sentry {
268
+ }
269
+
270
+ apply from: "../../node_modules/@sentry/react-native/sentry.gradle"
271
+ android {
272
+ ndkVersion rootProject.ext.ndkVersion
273
+
274
+ compileSdkVersion rootProject.ext.compileSdkVersion
275
+
276
+ namespace "com.samplenewarchitecture"
277
+ defaultConfig {
278
+ applicationId "com.samplenewarchitecture"
279
+ minSdkVersion rootProject.ext.minSdkVersion
280
+ targetSdkVersion rootProject.ext.targetSdkVersion
281
+ versionCode 1
282
+ versionName "1.0"
283
+ }
284
+ }
285
+ `;
286
+ const output = `apply plugin: "com.android.application"
287
+ apply plugin: "io.sentry.android.gradle"
288
+
289
+ sentry {
290
+ }
291
+ android {
292
+ ndkVersion rootProject.ext.ndkVersion
293
+
294
+ compileSdkVersion rootProject.ext.compileSdkVersion
295
+
296
+ namespace "com.samplenewarchitecture"
297
+ defaultConfig {
298
+ applicationId "com.samplenewarchitecture"
299
+ minSdkVersion rootProject.ext.minSdkVersion
300
+ targetSdkVersion rootProject.ext.targetSdkVersion
301
+ versionCode 1
302
+ versionName "1.0"
303
+ }
304
+ }
305
+ `;
306
+
307
+ expect(removeRNSentryGradlePlugin(input)).toBe(output);
308
+ });
309
+ });
310
+ });
@@ -0,0 +1,131 @@
1
+ import {
2
+ addSentryInitWithSdkImport,
3
+ doesJsCodeIncludeSdkSentryImport,
4
+ } from '../../src/react-native/javascript';
5
+
6
+ describe('react-native javascript', () => {
7
+ describe('addSentryInitWithSdkImport', () => {
8
+ it('adds sdk import and sentry init under last import in the file', () => {
9
+ const input = `import * as React from 'react';
10
+
11
+ const test = 'test';
12
+
13
+ import { View } from 'react-native';
14
+
15
+ const App = () => {
16
+ return (
17
+ <View>
18
+ Test App
19
+ </View>
20
+ );
21
+ };
22
+
23
+ export default App;`;
24
+
25
+ const expectedOutput = `import * as React from 'react';
26
+
27
+ const test = 'test';
28
+
29
+ import { View } from 'react-native';
30
+ import * as Sentry from '@sentry/react-native';
31
+
32
+ Sentry.init({
33
+ dsn: 'dsn',
34
+ });
35
+
36
+ const App = () => {
37
+ return (
38
+ <View>
39
+ Test App
40
+ </View>
41
+ );
42
+ };
43
+
44
+ export default App;`;
45
+
46
+ expect(addSentryInitWithSdkImport(input, { dsn: 'dsn' })).toBe(
47
+ expectedOutput,
48
+ );
49
+ });
50
+
51
+ it('does not add sdk import and sentry init in the file without imports', () => {
52
+ const input = `export const test = 'test';`;
53
+ expect(addSentryInitWithSdkImport(input, { dsn: 'dsn' })).toBe(input);
54
+ });
55
+
56
+ it('does not add sdk import and sentry init in the empty file', () => {
57
+ const input = '';
58
+ expect(addSentryInitWithSdkImport(input, { dsn: 'dsn' })).toBe(input);
59
+ });
60
+ });
61
+
62
+ describe('doesJsCodeIncludeSdkSentryImport', () => {
63
+ it('returns true if code has sdk import', () => {
64
+ const input = `import * as React from 'react';
65
+
66
+ const test = 'test';
67
+
68
+ import { View } from 'react-native';
69
+ import * as Sentry from '@sentry/react-native';
70
+
71
+ const App = () => {
72
+ return (
73
+ <View>
74
+ Test App
75
+ </View>
76
+ );
77
+ };
78
+
79
+ export default App;`;
80
+
81
+ expect(
82
+ doesJsCodeIncludeSdkSentryImport(input, {
83
+ sdkPackageName: '@sentry/react-native',
84
+ }),
85
+ ).toBe(true);
86
+ });
87
+
88
+ it('returns true if code has sdk require', () => {
89
+ const input = `import * as React from 'react';
90
+
91
+ const test = 'test';
92
+
93
+ import { View } from 'react-native';
94
+ const Sentry = require('@sentry/react-native');
95
+
96
+ const App = () => {
97
+ return (
98
+ <View>
99
+ Test App
100
+ </View>
101
+ );
102
+ };
103
+
104
+ export default App;`;
105
+
106
+ expect(
107
+ doesJsCodeIncludeSdkSentryImport(input, {
108
+ sdkPackageName: '@sentry/react-native',
109
+ }),
110
+ ).toBe(true);
111
+ });
112
+
113
+ it('returns false if code does not have sdk import', () => {
114
+ const input = `export const test = 'test';`;
115
+ expect(
116
+ doesJsCodeIncludeSdkSentryImport(input, {
117
+ sdkPackageName: '@sentry/react-native',
118
+ }),
119
+ ).toBe(false);
120
+ });
121
+
122
+ it('returns false for empty file', () => {
123
+ const input = '';
124
+ expect(
125
+ doesJsCodeIncludeSdkSentryImport(input, {
126
+ sdkPackageName: '@sentry/react-native',
127
+ }),
128
+ ).toBe(false);
129
+ });
130
+ });
131
+ });
@@ -0,0 +1,238 @@
1
+ /* eslint-disable no-useless-escape */
2
+ import {
3
+ addSentryToBundleShellScript,
4
+ doesBundlePhaseIncludeSentry,
5
+ findBundlePhase,
6
+ findDebugFilesUploadPhase,
7
+ removeSentryFromBundleShellScript,
8
+ } from '../../src/react-native/xcode';
9
+
10
+ describe('react-native xcode', () => {
11
+ describe('addSentryToBundleShellScript', () => {
12
+ it('adds sentry cli to rn bundle build phase', () => {
13
+ const input = `set -e
14
+
15
+ WITH_ENVIRONMENT="../node_modules/react-native/scripts/xcode/with-environment.sh"
16
+ REACT_NATIVE_XCODE="../node_modules/react-native/scripts/react-native-xcode.sh"
17
+
18
+ /bin/sh -c "$WITH_ENVIRONMENT $REACT_NATIVE_XCODE"`;
19
+ // actual shell script looks like this:
20
+ // /bin/sh -c "$WITH_ENVIRONMENT \"$REACT_NATIVE_XCODE\""
21
+ // but during parsing xcode library removes the quotes
22
+ const expectedOutput = `export SENTRY_PROPERTIES=sentry.properties
23
+ export EXTRA_PACKAGER_ARGS="--sourcemap-output $DERIVED_FILE_DIR/main.jsbundle.map"
24
+ set -e
25
+
26
+ WITH_ENVIRONMENT="../node_modules/react-native/scripts/xcode/with-environment.sh"
27
+ REACT_NATIVE_XCODE="../node_modules/react-native/scripts/react-native-xcode.sh"
28
+
29
+ /bin/sh -c "$WITH_ENVIRONMENT \\"../node_modules/@sentry/cli/bin/sentry-cli react-native xcode $REACT_NATIVE_XCODE\\""
30
+ /bin/sh -c "$WITH_ENVIRONMENT ../node_modules/@sentry/react-native/scripts/collect-modules.sh"
31
+ `;
32
+
33
+ expect(addSentryToBundleShellScript(input)).toBe(expectedOutput);
34
+ });
35
+ });
36
+
37
+ describe('removeSentryFromBundleShellScript', () => {
38
+ it('removes sentry cli from rn bundle build phase', () => {
39
+ const input = `export SENTRY_PROPERTIES=sentry.properties
40
+ export EXTRA_PACKAGER_ARGS="--sourcemap-output $DERIVED_FILE_DIR/main.jsbundle.map"
41
+ set -e
42
+
43
+ WITH_ENVIRONMENT="../node_modules/react-native/scripts/xcode/with-environment.sh"
44
+ REACT_NATIVE_XCODE="../node_modules/react-native/scripts/react-native-xcode.sh"
45
+
46
+ /bin/sh -c "$WITH_ENVIRONMENT \"../node_modules/@sentry/cli/bin/sentry-cli react-native xcode $REACT_NATIVE_XCODE\""
47
+
48
+ /bin/sh -c "$WITH_ENVIRONMENT ../node_modules/@sentry/react-native/scripts/collect-modules.sh"
49
+ `;
50
+ const expectedOutput = `export EXTRA_PACKAGER_ARGS="--sourcemap-output $DERIVED_FILE_DIR/main.jsbundle.map"
51
+ set -e
52
+
53
+ WITH_ENVIRONMENT="../node_modules/react-native/scripts/xcode/with-environment.sh"
54
+ REACT_NATIVE_XCODE="../node_modules/react-native/scripts/react-native-xcode.sh"
55
+
56
+ /bin/sh -c "$WITH_ENVIRONMENT \"$REACT_NATIVE_XCODE\""
57
+
58
+ `;
59
+
60
+ expect(removeSentryFromBundleShellScript(input)).toBe(expectedOutput);
61
+ });
62
+ });
63
+
64
+ describe('findBundlePhase', () => {
65
+ it('returns build phase with react native xcode shell script', () => {
66
+ const inputMap = {
67
+ 1: {
68
+ shellScript: 'foo',
69
+ },
70
+ 2: {
71
+ shellScript: 'bar',
72
+ },
73
+ 3: {
74
+ shellScript: `set -e
75
+ WITH_ENVIRONMENT="../node_modules/react-native/scripts/xcode/with-environment.sh"
76
+ REACT_NATIVE_XCODE="../node_modules/react-native/scripts/react-native-xcode.sh"
77
+
78
+ /bin/sh -c "$WITH_ENVIRONMENT \"$REACT_NATIVE_XCODE\""
79
+
80
+ `,
81
+ },
82
+ 4: {
83
+ shellScript: 'qux',
84
+ },
85
+ };
86
+
87
+ const expected = {
88
+ shellScript: `set -e
89
+ WITH_ENVIRONMENT="../node_modules/react-native/scripts/xcode/with-environment.sh"
90
+ REACT_NATIVE_XCODE="../node_modules/react-native/scripts/react-native-xcode.sh"
91
+
92
+ /bin/sh -c "$WITH_ENVIRONMENT \"$REACT_NATIVE_XCODE\""
93
+
94
+ `,
95
+ };
96
+
97
+ expect(findBundlePhase(inputMap)).toEqual(expected);
98
+ });
99
+
100
+ it('returns undefined if bundle phase not present', () => {
101
+ const inputMap = {
102
+ 1: {
103
+ shellScript: 'foo',
104
+ },
105
+ 2: {
106
+ shellScript: 'bar',
107
+ },
108
+ 3: {
109
+ // note different path to the script
110
+ shellScript: `set -e
111
+ WITH_ENVIRONMENT="../node_modules/react-native/scripts/xcode/with-environment.sh"
112
+ REACT_NATIVE_XCODE="../node_modules/react-native/unknown/react-native-xcode.sh"
113
+
114
+ /bin/sh -c "$WITH_ENVIRONMENT \"$REACT_NATIVE_XCODE\""
115
+
116
+ `,
117
+ },
118
+ 4: {
119
+ shellScript: 'qux',
120
+ },
121
+ };
122
+
123
+ expect(findBundlePhase(inputMap)).toBeUndefined();
124
+ });
125
+ });
126
+
127
+ describe('doesBundlePhaseIncludeSentry', () => {
128
+ it('returns true for script containing sentry cli calling react native xcode command', () => {
129
+ const input = {
130
+ shellScript: `set -e
131
+ WITH_ENVIRONMENT="../node_modules/react-native/scripts/xcode/with-environment.sh"
132
+ REACT_NATIVE_XCODE="../node_modules/react-native/scripts/react-native-xcode.sh"
133
+ SENTRY_CLI="sentry-cli react-native xcode"
134
+
135
+ /bin/sh -c "$WITH_ENVIRONMENT \"$SENTRY_CLI $REACT_NATIVE_XCODE\""
136
+ `,
137
+ };
138
+ expect(doesBundlePhaseIncludeSentry(input)).toBeTruthy();
139
+ });
140
+
141
+ it('returns false', () => {
142
+ const input = {
143
+ // note sentry-cli can be part of the script but doesn't call react native xcode script
144
+ shellScript: `set -e
145
+ WITH_ENVIRONMENT="../node_modules/react-native/scripts/xcode/with-environment.sh"
146
+ REACT_NATIVE_XCODE="../node_modules/react-native/scripts/react-native-xcode.sh"
147
+
148
+ /bin/sh -c "$WITH_ENVIRONMENT \"$REACT_NATIVE_XCODE\""
149
+
150
+ sentry-cli --version
151
+ `,
152
+ };
153
+ expect(doesBundlePhaseIncludeSentry(input)).toBeFalsy();
154
+ });
155
+ });
156
+
157
+ describe('findDebugFilesUploadPhase', () => {
158
+ it('returns debug files build phase using debug files command', () => {
159
+ const input = {
160
+ 1: {
161
+ shellScript: 'foo',
162
+ },
163
+ 2: {
164
+ shellScript: `set -e
165
+ sentry-cli debug-files upload path/to/dsym --include-sources
166
+ `,
167
+ },
168
+ };
169
+ const expected = [
170
+ '2',
171
+ {
172
+ shellScript: `set -e
173
+ sentry-cli debug-files upload path/to/dsym --include-sources
174
+ `,
175
+ },
176
+ ];
177
+ expect(findDebugFilesUploadPhase(input)).toEqual(expected);
178
+ });
179
+
180
+ it('returns debug files build phase with sentry-cli absolute path', () => {
181
+ const input = {
182
+ 1: {
183
+ shellScript: 'foo',
184
+ },
185
+ 2: {
186
+ shellScript: `set -e
187
+ /path/to/bin/sentry-cli debug-files upload path/to/dsym --include-sources
188
+ `,
189
+ },
190
+ };
191
+ const expected = [
192
+ '2',
193
+ {
194
+ shellScript: `set -e
195
+ /path/to/bin/sentry-cli debug-files upload path/to/dsym --include-sources
196
+ `,
197
+ },
198
+ ];
199
+ expect(findDebugFilesUploadPhase(input)).toEqual(expected);
200
+ });
201
+
202
+ it('returns debug files build phase using dsym command', () => {
203
+ const input = {
204
+ 1: {
205
+ shellScript: 'foo',
206
+ },
207
+ 2: {
208
+ shellScript: `set -e
209
+ sentry-cli upload-dsym path/to/dsym --include-sources
210
+ `,
211
+ },
212
+ };
213
+ const expected = [
214
+ '2',
215
+ {
216
+ shellScript: `set -e
217
+ sentry-cli upload-dsym path/to/dsym --include-sources
218
+ `,
219
+ },
220
+ ];
221
+ expect(findDebugFilesUploadPhase(input)).toEqual(expected);
222
+ });
223
+
224
+ it('returns undefined if build phase not present', () => {
225
+ const input = {
226
+ 1: {
227
+ shellScript: 'foo',
228
+ },
229
+ 2: {
230
+ // sentry-cli present but with different command
231
+ shellScript: 'sentry-cli sourcempas upload',
232
+ },
233
+ };
234
+
235
+ expect(findDebugFilesUploadPhase(input)).toBeUndefined();
236
+ });
237
+ });
238
+ });