@sentry/wizard 3.40.0 → 3.42.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 (112) hide show
  1. package/CHANGELOG.md +12 -1
  2. package/README.md +19 -19
  3. package/bin.ts +5 -0
  4. package/codecov.yml +15 -0
  5. package/dist/bin.js +4 -0
  6. package/dist/bin.js.map +1 -1
  7. package/dist/e2e-tests/jest.config.d.ts +1 -0
  8. package/dist/e2e-tests/jest.config.js +1 -0
  9. package/dist/e2e-tests/jest.config.js.map +1 -1
  10. package/dist/e2e-tests/tests/remix.test.js +1 -1
  11. package/dist/e2e-tests/tests/remix.test.js.map +1 -1
  12. package/dist/package.json +3 -2
  13. package/dist/src/apple/apple-wizard.js +1 -2
  14. package/dist/src/apple/apple-wizard.js.map +1 -1
  15. package/dist/src/apple/code-tools.d.ts +10 -0
  16. package/dist/src/apple/code-tools.js +16 -12
  17. package/dist/src/apple/code-tools.js.map +1 -1
  18. package/dist/src/apple/fastlane.d.ts +23 -0
  19. package/dist/src/apple/fastlane.js +11 -7
  20. package/dist/src/apple/fastlane.js.map +1 -1
  21. package/dist/src/apple/templates.d.ts +1 -1
  22. package/dist/src/apple/templates.js +0 -2
  23. package/dist/src/apple/templates.js.map +1 -1
  24. package/dist/src/apple/xcode-manager.d.ts +10 -6
  25. package/dist/src/apple/xcode-manager.js +146 -61
  26. package/dist/src/apple/xcode-manager.js.map +1 -1
  27. package/dist/src/nextjs/nextjs-wizard.js +6 -4
  28. package/dist/src/nextjs/nextjs-wizard.js.map +1 -1
  29. package/dist/src/nuxt/nuxt-wizard.js +7 -5
  30. package/dist/src/nuxt/nuxt-wizard.js.map +1 -1
  31. package/dist/src/nuxt/sdk-setup.d.ts +1 -1
  32. package/dist/src/nuxt/sdk-setup.js +2 -1
  33. package/dist/src/nuxt/sdk-setup.js.map +1 -1
  34. package/dist/src/react-native/react-native-wizard.js +5 -3
  35. package/dist/src/react-native/react-native-wizard.js.map +1 -1
  36. package/dist/src/remix/remix-wizard.js +6 -4
  37. package/dist/src/remix/remix-wizard.js.map +1 -1
  38. package/dist/src/remix/sdk-setup.js +0 -4
  39. package/dist/src/remix/sdk-setup.js.map +1 -1
  40. package/dist/src/run.d.ts +1 -0
  41. package/dist/src/run.js +1 -0
  42. package/dist/src/run.js.map +1 -1
  43. package/dist/src/sveltekit/sveltekit-wizard.js +6 -4
  44. package/dist/src/sveltekit/sveltekit-wizard.js.map +1 -1
  45. package/dist/src/utils/clack-utils.d.ts +3 -1
  46. package/dist/src/utils/clack-utils.js +18 -12
  47. package/dist/src/utils/clack-utils.js.map +1 -1
  48. package/dist/src/utils/package-manager.d.ts +1 -0
  49. package/dist/src/utils/package-manager.js +5 -0
  50. package/dist/src/utils/package-manager.js.map +1 -1
  51. package/dist/src/utils/types.d.ts +9 -0
  52. package/dist/src/utils/types.js.map +1 -1
  53. package/dist/test/apple/cocoapod.test.d.ts +1 -0
  54. package/dist/test/apple/cocoapod.test.js +409 -0
  55. package/dist/test/apple/cocoapod.test.js.map +1 -0
  56. package/dist/test/apple/code-tools.test.d.ts +1 -0
  57. package/dist/test/apple/code-tools.test.js +673 -0
  58. package/dist/test/apple/code-tools.test.js.map +1 -0
  59. package/dist/test/apple/fastfile.test.d.ts +1 -0
  60. package/dist/test/apple/fastfile.test.js +431 -0
  61. package/dist/test/apple/fastfile.test.js.map +1 -0
  62. package/dist/test/apple/templates.test.d.ts +1 -0
  63. package/dist/test/apple/templates.test.js +73 -0
  64. package/dist/test/apple/templates.test.js.map +1 -0
  65. package/dist/test/apple/xcode-manager.test.d.ts +1 -0
  66. package/dist/test/apple/xcode-manager.test.js +834 -0
  67. package/dist/test/apple/xcode-manager.test.js.map +1 -0
  68. package/dist/test/remix/server-instrumentation.test.js +2 -2
  69. package/dist/test/remix/server-instrumentation.test.js.map +1 -1
  70. package/dist/test/utils/clack-utils.test.js +89 -0
  71. package/dist/test/utils/clack-utils.test.js.map +1 -1
  72. package/e2e-tests/jest.config.ts +1 -0
  73. package/e2e-tests/test-applications/apple/damaged-missing-configuration-list/Project.xcodeproj/project.pbxproj +52 -0
  74. package/e2e-tests/test-applications/apple/damaged-missing-configuration-list/Project.xcodeproj/xcshareddata/xcschemes/Project1.xcscheme +78 -0
  75. package/e2e-tests/test-applications/apple/no-targets/Project.xcodeproj/project.pbxproj +62 -0
  76. package/e2e-tests/test-applications/apple/no-targets/Project.xcodeproj/xcshareddata/xcschemes/Project1.xcscheme +78 -0
  77. package/e2e-tests/test-applications/apple/spm-swiftui-multi-targets/Project.xcodeproj/project.pbxproj +470 -0
  78. package/e2e-tests/test-applications/apple/spm-swiftui-multi-targets/Project.xcodeproj/xcshareddata/xcschemes/Project1.xcscheme +78 -0
  79. package/e2e-tests/test-applications/apple/spm-swiftui-multi-targets/Project1/ContentView.swift +7 -0
  80. package/e2e-tests/test-applications/apple/spm-swiftui-multi-targets/Project1/Project1App.swift +10 -0
  81. package/e2e-tests/test-applications/apple/spm-swiftui-multi-targets/Project2/ContentView.swift +7 -0
  82. package/e2e-tests/test-applications/apple/spm-swiftui-multi-targets/Project2/Project2App.swift +10 -0
  83. package/e2e-tests/test-applications/apple/spm-swiftui-single-target/Project.xcodeproj/project.pbxproj +382 -0
  84. package/e2e-tests/test-applications/apple/spm-swiftui-single-target/Project.xcodeproj/xcshareddata/xcschemes/Project.xcscheme +78 -0
  85. package/e2e-tests/test-applications/apple/spm-swiftui-single-target/Sources/ContentView.swift +7 -0
  86. package/e2e-tests/test-applications/apple/spm-swiftui-single-target/Sources/MainApp.swift +10 -0
  87. package/e2e-tests/tests/remix.test.ts +1 -2
  88. package/package.json +3 -2
  89. package/src/apple/apple-wizard.ts +1 -2
  90. package/src/apple/code-tools.ts +21 -6
  91. package/src/apple/fastlane.ts +18 -2
  92. package/src/apple/templates.ts +2 -2
  93. package/src/apple/xcode-manager.ts +181 -94
  94. package/src/nextjs/nextjs-wizard.ts +6 -3
  95. package/src/nuxt/nuxt-wizard.ts +7 -4
  96. package/src/nuxt/sdk-setup.ts +2 -0
  97. package/src/react-native/react-native-wizard.ts +5 -2
  98. package/src/remix/remix-wizard.ts +6 -3
  99. package/src/remix/sdk-setup.ts +0 -5
  100. package/src/run.ts +2 -0
  101. package/src/sveltekit/sveltekit-wizard.ts +6 -3
  102. package/src/utils/clack-utils.ts +12 -2
  103. package/src/utils/package-manager.ts +6 -0
  104. package/src/utils/types.ts +10 -0
  105. package/test/apple/cocoapod.test.ts +306 -0
  106. package/test/apple/code-tools.test.ts +1042 -0
  107. package/test/apple/fastfile.test.ts +550 -0
  108. package/test/apple/templates.test.ts +191 -0
  109. package/test/apple/xcode-manager.test.ts +1066 -0
  110. package/test/remix/server-instrumentation.test.ts +2 -4
  111. package/test/utils/clack-utils.test.ts +92 -0
  112. package/types/xcode.d.ts +526 -0
@@ -0,0 +1,1066 @@
1
+ import * as fs from 'fs';
2
+ import * as os from 'os';
3
+ import * as path from 'path';
4
+ import {
5
+ PBXFileReference,
6
+ PBXGroup,
7
+ PBXNativeTarget,
8
+ PBXProject,
9
+ PBXShellScriptBuildPhase,
10
+ XCBuildConfiguration,
11
+ } from 'xcode';
12
+ import { getRunScriptTemplate } from '../../src/apple/templates';
13
+ import { XcodeProject } from '../../src/apple/xcode-manager';
14
+ import { SentryProjectData } from '../../src/utils/types';
15
+
16
+ jest.mock('@clack/prompts', () => ({
17
+ default: {
18
+ log: {
19
+ info: jest.fn(),
20
+ success: jest.fn(),
21
+ step: jest.fn(),
22
+ },
23
+ },
24
+ }));
25
+
26
+ const appleProjectsPath = path.resolve(
27
+ __dirname,
28
+ '../../e2e-tests/test-applications/apple',
29
+ );
30
+ const damagedProjectPath = path.join(
31
+ appleProjectsPath,
32
+ 'damaged-missing-configuration-list/Project.xcodeproj/project.pbxproj',
33
+ );
34
+ const noTargetsProjectPath = path.join(
35
+ appleProjectsPath,
36
+ 'no-targets/Project.xcodeproj/project.pbxproj',
37
+ );
38
+ const singleTargetProjectPath = path.join(
39
+ appleProjectsPath,
40
+ 'spm-swiftui-single-target/Project.xcodeproj/project.pbxproj',
41
+ );
42
+ const multiTargetProjectPath = path.join(
43
+ appleProjectsPath,
44
+ 'spm-swiftui-multi-targets/Project.xcodeproj/project.pbxproj',
45
+ );
46
+ const projectData: SentryProjectData = {
47
+ id: '1234567890',
48
+ slug: 'project',
49
+ organization: {
50
+ id: '1234567890',
51
+ name: 'Sentry',
52
+ slug: 'sentry',
53
+ },
54
+ keys: [{ dsn: { public: 'https://sentry.io/1234567890' } }],
55
+ };
56
+
57
+ describe('XcodeManager', () => {
58
+ afterEach(() => {
59
+ jest.clearAllMocks();
60
+ });
61
+
62
+ describe('XcodeProject', () => {
63
+ describe('getAllTargets', () => {
64
+ describe('single target', () => {
65
+ it('should return all targets', () => {
66
+ // -- Arrange --
67
+ const xcodeProject = new XcodeProject(singleTargetProjectPath);
68
+
69
+ // -- Act --
70
+ const targets = xcodeProject.getAllTargets();
71
+
72
+ // -- Assert --
73
+ expect(targets).toEqual(['Project']);
74
+ });
75
+ });
76
+
77
+ describe('multiple targets', () => {
78
+ it('should return all targets', () => {
79
+ // -- Arrange --
80
+ const xcodeProject = new XcodeProject(multiTargetProjectPath);
81
+
82
+ // -- Act --
83
+ const targets = xcodeProject.getAllTargets();
84
+
85
+ // -- Assert --
86
+ expect(targets).toEqual(['Project1', 'Project2']);
87
+ });
88
+ });
89
+
90
+ describe('no targets', () => {
91
+ it('should return an empty array', () => {
92
+ // -- Arrange --
93
+ const xcodeProject = new XcodeProject(noTargetsProjectPath);
94
+
95
+ // -- Act --
96
+ const targets = xcodeProject.getAllTargets();
97
+
98
+ // -- Assert --
99
+ expect(targets).toEqual([]);
100
+ });
101
+ });
102
+
103
+ describe('project with missing configuration list', () => {
104
+ it('should return an empty array', () => {
105
+ // -- Arrange --
106
+ const xcodeProject = new XcodeProject(damagedProjectPath);
107
+
108
+ // -- Act --
109
+ const targets = xcodeProject.getAllTargets();
110
+
111
+ // -- Assert --
112
+ expect(targets).toEqual([]);
113
+ });
114
+ });
115
+ });
116
+
117
+ describe('updateXcodeProject', () => {
118
+ let sourceProjectPath: string;
119
+ let tempProjectPath: string;
120
+ let xcodeProject: XcodeProject;
121
+
122
+ beforeEach(() => {
123
+ const tempDir = path.join(
124
+ os.tmpdir(),
125
+ fs.mkdtempSync('update-xcode-project'),
126
+ );
127
+ fs.mkdirSync(tempDir);
128
+
129
+ sourceProjectPath = singleTargetProjectPath;
130
+ tempProjectPath = path.resolve(tempDir, 'project.pbxproj');
131
+
132
+ fs.copyFileSync(sourceProjectPath, tempProjectPath);
133
+ xcodeProject = new XcodeProject(tempProjectPath);
134
+ });
135
+
136
+ describe('upload symbols script', () => {
137
+ const scriptVariants: {
138
+ uploadSource: boolean;
139
+ includeHomebrewPath: boolean;
140
+ }[] = [
141
+ {
142
+ uploadSource: true,
143
+ includeHomebrewPath: true,
144
+ },
145
+ {
146
+ uploadSource: true,
147
+ includeHomebrewPath: false,
148
+ },
149
+ {
150
+ uploadSource: false,
151
+ includeHomebrewPath: true,
152
+ },
153
+ {
154
+ uploadSource: false,
155
+ includeHomebrewPath: false,
156
+ },
157
+ ];
158
+
159
+ for (const variant of scriptVariants) {
160
+ describe(`upload source = ${variant.uploadSource?.toString()} and include homebrew path = ${variant.includeHomebrewPath.toString()}`, () => {
161
+ beforeEach(() => {
162
+ jest
163
+ .spyOn(fs, 'existsSync')
164
+ .mockReturnValue(variant.includeHomebrewPath);
165
+ });
166
+
167
+ afterEach(() => {
168
+ jest.restoreAllMocks();
169
+ });
170
+
171
+ it('should add the upload symbols script to the target', () => {
172
+ // -- Arrange --
173
+ const generatedShellScript = getRunScriptTemplate(
174
+ projectData.organization.slug,
175
+ projectData.slug,
176
+ variant.uploadSource,
177
+ variant.includeHomebrewPath,
178
+ );
179
+ const expectedShellScript = `"${generatedShellScript.replace(
180
+ /"/g,
181
+ '\\"',
182
+ )}"`;
183
+
184
+ // -- Act --
185
+ xcodeProject.updateXcodeProject(
186
+ projectData,
187
+ 'Project',
188
+ false, // Ignore SPM reference
189
+ variant.uploadSource,
190
+ );
191
+
192
+ // -- Assert --
193
+ const updatedXcodeProject = new XcodeProject(tempProjectPath);
194
+
195
+ // Expect the upload symbols script to be added
196
+ const scriptObjects =
197
+ updatedXcodeProject.objects.PBXShellScriptBuildPhase;
198
+ expect(scriptObjects).toBeDefined();
199
+ if (!scriptObjects) {
200
+ throw new Error('Script objects not found');
201
+ }
202
+ const scriptKeys = Object.keys(scriptObjects);
203
+ expect(scriptKeys).toHaveLength(2);
204
+
205
+ // Find the script ID
206
+ const scriptId = scriptKeys.find(
207
+ (key) => !key.endsWith('_comment'),
208
+ );
209
+ expect(scriptId).toBeDefined();
210
+ if (!scriptId) {
211
+ throw new Error('Script ID not found');
212
+ }
213
+ expect(scriptId).toMatch(/^[A-F0-9]{24}$/i);
214
+
215
+ // Expect the script to be added
216
+ const script = scriptObjects[
217
+ scriptId
218
+ ] as PBXShellScriptBuildPhase;
219
+ expect(script).toBeDefined();
220
+ expect(typeof script).not.toBe('string');
221
+ expect(script.inputPaths).toEqual([
222
+ '"${DWARF_DSYM_FOLDER_PATH}/${DWARF_DSYM_FILE_NAME}/Contents/Resources/DWARF/${TARGET_NAME}"',
223
+ ]);
224
+ expect(script.outputPaths).toEqual([]);
225
+ expect(script.shellPath).toBe('/bin/sh');
226
+ expect(script.shellScript).toEqual(expectedShellScript);
227
+
228
+ const commentKey = `${scriptId}_comment`;
229
+ expect(scriptKeys).toContain(commentKey);
230
+ expect(scriptObjects[commentKey]).toBe(
231
+ 'Upload Debug Symbols to Sentry',
232
+ );
233
+ });
234
+ });
235
+ }
236
+ });
237
+
238
+ describe('debug information format and sandbox', () => {
239
+ describe('upload source is false', () => {
240
+ it('should not update the Xcode project', () => {
241
+ // -- Act --
242
+ xcodeProject.updateXcodeProject(
243
+ projectData,
244
+ 'Project',
245
+ false, // Ignore SPM reference
246
+ false,
247
+ );
248
+
249
+ // -- Assert --
250
+ const expectedXcodeProject = new XcodeProject(sourceProjectPath);
251
+ expect(xcodeProject.objects.XCBuildConfiguration).toEqual(
252
+ expectedXcodeProject.objects.XCBuildConfiguration,
253
+ );
254
+ });
255
+ });
256
+
257
+ describe('upload source is true', () => {
258
+ const uploadSource = true;
259
+
260
+ describe('named target not found', () => {
261
+ it('should not update the flags in the Xcode project', () => {
262
+ // -- Act --
263
+ xcodeProject.updateXcodeProject(
264
+ projectData,
265
+ 'Invalid Target Name',
266
+ false, // Ignore SPM reference
267
+ uploadSource,
268
+ );
269
+
270
+ // -- Assert --
271
+ const originalXcodeProject = new XcodeProject(sourceProjectPath);
272
+ expect(xcodeProject.objects.XCBuildConfiguration).toEqual(
273
+ originalXcodeProject.objects.XCBuildConfiguration,
274
+ );
275
+ });
276
+ });
277
+
278
+ describe('named target found', () => {
279
+ describe('build configurations is undefined', () => {
280
+ it('should not update the Xcode project', () => {
281
+ // -- Act --
282
+ xcodeProject.updateXcodeProject(
283
+ projectData,
284
+ 'Invalid Target Name',
285
+ false, // Ignore SPM reference
286
+ uploadSource,
287
+ );
288
+
289
+ // -- Assert --
290
+ const originalXcodeProject = new XcodeProject(
291
+ sourceProjectPath,
292
+ );
293
+ expect(xcodeProject.objects.XCBuildConfiguration).toEqual(
294
+ originalXcodeProject.objects.XCBuildConfiguration,
295
+ );
296
+ });
297
+ });
298
+
299
+ describe('no build configurations found', () => {
300
+ it('should not update the Xcode project', () => {
301
+ // -- Arrange --
302
+ xcodeProject.objects.XCBuildConfiguration = {};
303
+
304
+ // -- Act --
305
+ xcodeProject.updateXcodeProject(
306
+ projectData,
307
+ 'Invalid Target Name',
308
+ false, // Ignore SPM reference
309
+ uploadSource,
310
+ );
311
+
312
+ // -- Assert --
313
+ expect(xcodeProject.objects.XCBuildConfiguration).toEqual({});
314
+ });
315
+ });
316
+
317
+ describe('build configurations found', () => {
318
+ const debugProjectBuildConfigurationListId =
319
+ 'D4E604DA2D50CEEE00CAB00F';
320
+ const releaseProjectBuildConfigurationListId =
321
+ 'D4E604DB2D50CEEE00CAB00F';
322
+ const debugTargetBuildConfigurationListId =
323
+ 'D4E604DD2D50CEEE00CAB00F';
324
+ const releaseTargetBuildConfigurationListId =
325
+ 'D4E604DE2D50CEEE00CAB00F';
326
+
327
+ it('should update the target configuration lists', () => {
328
+ // -- Act --
329
+ xcodeProject.updateXcodeProject(
330
+ projectData,
331
+ 'Project',
332
+ false, // Ignore SPM reference
333
+ uploadSource,
334
+ );
335
+
336
+ // -- Assert --
337
+ expect(xcodeProject.objects.XCBuildConfiguration).toBeDefined();
338
+ // Both Debug and Release are configured equally
339
+ const expectedConfigKeys = [
340
+ debugTargetBuildConfigurationListId, // Debug
341
+ releaseTargetBuildConfigurationListId, // Release
342
+ ];
343
+ for (const key of expectedConfigKeys) {
344
+ const buildConfiguration = xcodeProject.objects
345
+ .XCBuildConfiguration?.[key] as XCBuildConfiguration;
346
+ expect(buildConfiguration).toBeDefined();
347
+ expect(typeof buildConfiguration).not.toBe('string');
348
+ const buildSettings = buildConfiguration.buildSettings ?? {};
349
+ expect(buildSettings.DEBUG_INFORMATION_FORMAT).toBe(
350
+ '"dwarf-with-dsym"',
351
+ );
352
+ expect(buildSettings.ENABLE_USER_SCRIPT_SANDBOXING).toBe(
353
+ '"NO"',
354
+ );
355
+ }
356
+ });
357
+
358
+ it('should not update the project configuration lists', () => {
359
+ // -- Act --
360
+ xcodeProject.updateXcodeProject(
361
+ projectData,
362
+ 'Project',
363
+ false, // Ignore SPM reference
364
+ uploadSource,
365
+ );
366
+
367
+ // -- Assert --
368
+ expect(xcodeProject.objects.XCBuildConfiguration).toBeDefined();
369
+
370
+ // Check project build configurations 'Debug'
371
+ const debugBuildConfiguration = xcodeProject.objects
372
+ .XCBuildConfiguration?.[
373
+ debugProjectBuildConfigurationListId
374
+ ] as XCBuildConfiguration;
375
+ expect(debugBuildConfiguration).toBeDefined();
376
+ expect(typeof debugBuildConfiguration).not.toBe('string');
377
+ expect(
378
+ debugBuildConfiguration.buildSettings
379
+ ?.DEBUG_INFORMATION_FORMAT,
380
+ ).toBe('dwarf');
381
+ expect(
382
+ debugBuildConfiguration.buildSettings
383
+ ?.ENABLE_USER_SCRIPT_SANDBOXING,
384
+ ).toBe('YES');
385
+
386
+ // Check project build configurations 'Release'
387
+ const releaseBuildConfiguration = xcodeProject.objects
388
+ .XCBuildConfiguration?.[
389
+ releaseProjectBuildConfigurationListId
390
+ ] as XCBuildConfiguration;
391
+ expect(releaseBuildConfiguration).toBeDefined();
392
+ expect(typeof releaseBuildConfiguration).not.toBe('string');
393
+ expect(
394
+ releaseBuildConfiguration.buildSettings
395
+ ?.DEBUG_INFORMATION_FORMAT,
396
+ ).toBe('"dwarf-with-dsym"');
397
+ expect(
398
+ releaseBuildConfiguration.buildSettings
399
+ ?.ENABLE_USER_SCRIPT_SANDBOXING,
400
+ ).toBe('YES');
401
+ });
402
+ });
403
+ });
404
+ });
405
+ });
406
+
407
+ describe('add SPM reference', () => {
408
+ const addSPMReference = true;
409
+
410
+ describe('framework build phase already contains Sentry', () => {
411
+ it('should not update the Xcode project', () => {
412
+ // -- Arrange --
413
+ xcodeProject.objects.PBXFrameworksBuildPhase = {
414
+ 'framework-id': {
415
+ files: [
416
+ {
417
+ value: '123',
418
+ comment: 'Sentry in Frameworks',
419
+ },
420
+ ],
421
+ },
422
+ };
423
+
424
+ // -- Act --
425
+ xcodeProject.updateXcodeProject(
426
+ projectData,
427
+ 'Project',
428
+ addSPMReference,
429
+ );
430
+
431
+ // -- Assert --
432
+ const expectedXcodeProject = new XcodeProject(sourceProjectPath);
433
+ expectedXcodeProject.objects.PBXFrameworksBuildPhase = {
434
+ 'framework-id': {
435
+ files: [
436
+ {
437
+ value: '123',
438
+ comment: 'Sentry in Frameworks',
439
+ },
440
+ ],
441
+ },
442
+ };
443
+ expect(xcodeProject.objects.PBXFrameworksBuildPhase).toEqual(
444
+ expectedXcodeProject.objects.PBXFrameworksBuildPhase,
445
+ );
446
+ expect(xcodeProject.objects.XCRemoteSwiftPackageReference).toEqual(
447
+ expectedXcodeProject.objects.XCRemoteSwiftPackageReference,
448
+ );
449
+ expect(
450
+ xcodeProject.objects.XCSwiftPackageProductDependency,
451
+ ).toEqual(
452
+ expectedXcodeProject.objects.XCSwiftPackageProductDependency,
453
+ );
454
+ });
455
+ });
456
+
457
+ it('should add the SPM reference to the target', () => {
458
+ // -- Act --
459
+ xcodeProject.updateXcodeProject(
460
+ projectData,
461
+ 'Project',
462
+ addSPMReference,
463
+ );
464
+
465
+ // -- Assert --
466
+ // Get the target
467
+ const target = xcodeProject.objects.PBXNativeTarget?.[
468
+ 'D4E604CC2D50CEEC00CAB00F'
469
+ ] as PBXNativeTarget;
470
+ expect(target).toBeDefined();
471
+ if (!target) {
472
+ throw new Error('Target is undefined');
473
+ }
474
+
475
+ // Check the SPM dependency is added to the target
476
+ expect(target.packageProductDependencies).toEqual([
477
+ expect.objectContaining({
478
+ value: expect.any(String) as string,
479
+ comment: 'Sentry',
480
+ }),
481
+ ]);
482
+
483
+ // Check the SPM package reference object is added to the project
484
+ const remoteSwiftPackageReferences =
485
+ xcodeProject.objects.XCRemoteSwiftPackageReference;
486
+ expect(remoteSwiftPackageReferences).toBeDefined();
487
+ if (!remoteSwiftPackageReferences) {
488
+ throw new Error('XCRemoteSwiftPackageReference is undefined');
489
+ }
490
+ const rspRefKeys = Object.keys(remoteSwiftPackageReferences);
491
+ expect(rspRefKeys).toHaveLength(2);
492
+ // First key is expected to be the UUID of the SPM package reference
493
+ expect(rspRefKeys[0]).toMatch(/^[A-F0-9]{24}$/i);
494
+ // Second key is expected to be the UUID of the SPM package reference with _comment suffix
495
+ expect(rspRefKeys[1]).toMatch(/^[A-F0-9]{24}_comment$/i);
496
+
497
+ expect(remoteSwiftPackageReferences?.[rspRefKeys[0]]).toEqual({
498
+ isa: 'XCRemoteSwiftPackageReference',
499
+ repositoryURL: '"https://github.com/getsentry/sentry-cocoa/"',
500
+ requirement: {
501
+ kind: 'upToNextMajorVersion',
502
+ minimumVersion: '8.0.0',
503
+ },
504
+ });
505
+ expect(remoteSwiftPackageReferences?.[rspRefKeys[1]]).toBe(
506
+ 'XCRemoteSwiftPackageReference "sentry-cocoa"',
507
+ );
508
+
509
+ // Check the SPM package is a dependency of the target
510
+ const packageProductDependencies =
511
+ xcodeProject.objects.XCSwiftPackageProductDependency;
512
+ expect(packageProductDependencies).toBeDefined();
513
+ if (!packageProductDependencies) {
514
+ throw new Error('XCSwiftPackageProductDependency is undefined');
515
+ }
516
+ const ppDepKeys = Object.keys(packageProductDependencies);
517
+ expect(ppDepKeys).toHaveLength(2);
518
+ // First key is expected to be the UUID of the SPM package dependency
519
+ expect(ppDepKeys[0]).toMatch(/^[A-F0-9]{24}$/i);
520
+ // Second key is expected to be the UUID of the SPM package dependency with _comment suffix
521
+ expect(ppDepKeys[1]).toMatch(/^[A-F0-9]{24}_comment$/i);
522
+ expect(packageProductDependencies?.[ppDepKeys[0]]).toEqual({
523
+ isa: 'XCSwiftPackageProductDependency',
524
+ package: rspRefKeys[0],
525
+ package_comment: 'XCRemoteSwiftPackageReference "sentry-cocoa"',
526
+ productName: 'Sentry',
527
+ });
528
+ });
529
+ });
530
+ });
531
+ });
532
+
533
+ describe('filesForTarget', () => {
534
+ describe('targets are undefined', () => {
535
+ it('should return undefined', () => {
536
+ // -- Arrange --
537
+ const xcodeProject = new XcodeProject(singleTargetProjectPath);
538
+ xcodeProject.objects.PBXNativeTarget = undefined;
539
+
540
+ // -- Act --
541
+ const files = xcodeProject.filesForTarget('Project');
542
+
543
+ // -- Assert --
544
+ expect(files).toBeUndefined();
545
+ });
546
+ });
547
+
548
+ describe('target not found', () => {
549
+ it('should return undefined', () => {
550
+ // -- Arrange --
551
+ const xcodeProject = new XcodeProject(singleTargetProjectPath);
552
+
553
+ // -- Act --
554
+ const files = xcodeProject.filesForTarget('NonExistentTarget');
555
+
556
+ // -- Assert --
557
+ expect(files).toBeUndefined();
558
+ });
559
+ });
560
+
561
+ describe('target build phases are undefined', () => {
562
+ it('should return undefined', () => {
563
+ // -- Arrange --
564
+ const xcodeProject = new XcodeProject(singleTargetProjectPath);
565
+ xcodeProject.objects.PBXNativeTarget = {
566
+ Project: {
567
+ name: 'Project',
568
+ buildPhases: undefined,
569
+ },
570
+ };
571
+
572
+ // -- Act --
573
+ const files = xcodeProject.filesForTarget('Project');
574
+
575
+ // -- Assert --
576
+ expect(files).toBeUndefined();
577
+ });
578
+ });
579
+
580
+ describe('build phases are undefined', () => {
581
+ it('should return undefined', () => {
582
+ // -- Arrange --
583
+ const xcodeProject = new XcodeProject(singleTargetProjectPath);
584
+ xcodeProject.objects.PBXNativeTarget = {
585
+ Project: {
586
+ name: 'Project',
587
+ buildPhases: undefined,
588
+ },
589
+ };
590
+ xcodeProject.objects.PBXSourcesBuildPhase = undefined;
591
+
592
+ // -- Act --
593
+ const files = xcodeProject.filesForTarget('Project');
594
+
595
+ // -- Assert --
596
+ expect(files).toBeUndefined();
597
+ });
598
+ });
599
+
600
+ describe('referenced build phase is undefined', () => {
601
+ it('should return undefined', () => {
602
+ // -- Arrange --
603
+ const xcodeProject = new XcodeProject(singleTargetProjectPath);
604
+ xcodeProject.objects.PBXNativeTarget = {
605
+ Project: {
606
+ name: 'Project',
607
+ buildPhases: [
608
+ {
609
+ value: 'random-build-phase',
610
+ },
611
+ ],
612
+ },
613
+ };
614
+
615
+ // -- Act --
616
+ const files = xcodeProject.filesForTarget('Project');
617
+
618
+ // -- Assert --
619
+ expect(files).toBeUndefined();
620
+ });
621
+ });
622
+
623
+ describe('build phase files are undefined', () => {
624
+ it('should return empty array', () => {
625
+ // -- Arrange --
626
+ const xcodeProject = new XcodeProject(singleTargetProjectPath);
627
+ xcodeProject.objects.PBXNativeTarget = {
628
+ Project: {
629
+ name: 'Project',
630
+ buildPhases: [
631
+ {
632
+ value: 'build-phase-key',
633
+ },
634
+ ],
635
+ },
636
+ };
637
+ xcodeProject.objects.PBXSourcesBuildPhase = {
638
+ 'build-phase-key': {
639
+ files: undefined,
640
+ },
641
+ };
642
+
643
+ // -- Act --
644
+ const files = xcodeProject.filesForTarget('Project');
645
+
646
+ // -- Assert --
647
+ expect(files).toEqual([]);
648
+ });
649
+ });
650
+
651
+ describe('build phase has no files', () => {
652
+ it('should return empty array', () => {
653
+ // -- Arrange --
654
+ const xcodeProject = new XcodeProject(singleTargetProjectPath);
655
+
656
+ // -- Act --
657
+ const files = xcodeProject.filesForTarget('Project');
658
+
659
+ // -- Assert --
660
+ expect(files).toEqual([]);
661
+ });
662
+ });
663
+
664
+ describe('build phase with files', () => {
665
+ let xcodeProject: XcodeProject;
666
+
667
+ beforeEach(() => {
668
+ xcodeProject = new XcodeProject(singleTargetProjectPath);
669
+ xcodeProject.objects.PBXNativeTarget = {
670
+ 'some-target': {
671
+ name: 'some-target',
672
+ buildPhases: [
673
+ {
674
+ value: 'build-phase-key',
675
+ },
676
+ ],
677
+ },
678
+ };
679
+ xcodeProject.objects.PBXSourcesBuildPhase = {
680
+ 'build-phase-key': {
681
+ files: [
682
+ {
683
+ value: 'file-key',
684
+ },
685
+ ],
686
+ },
687
+ };
688
+ xcodeProject.objects.PBXBuildFile = {
689
+ 'file-key': {
690
+ isa: 'PBXBuildFile',
691
+ fileRef: 'file-ref-key',
692
+ },
693
+ };
694
+ xcodeProject.files = [
695
+ {
696
+ key: 'file-ref-key',
697
+ path: 'file-path',
698
+ },
699
+ ];
700
+ });
701
+
702
+ describe('build file objects are not defined', () => {
703
+ it('should return empty array', () => {
704
+ // -- Arrange --
705
+ xcodeProject.objects.PBXBuildFile = undefined;
706
+
707
+ // -- Act --
708
+ const files = xcodeProject.filesForTarget('some-target');
709
+
710
+ // -- Assert --
711
+ expect(files).toEqual([]);
712
+ });
713
+ });
714
+
715
+ describe('build file object is not found', () => {
716
+ it('should return empty array', () => {
717
+ // -- Arrange --
718
+ xcodeProject.objects.PBXBuildFile = {};
719
+
720
+ // -- Act --
721
+ const files = xcodeProject.filesForTarget('some-target');
722
+
723
+ // -- Assert --
724
+ expect(files).toEqual([]);
725
+ });
726
+ });
727
+
728
+ describe('build file object exists', () => {
729
+ describe('file reference is undefined', () => {
730
+ it('should ignore the file', () => {
731
+ // -- Arrange --
732
+ xcodeProject.files = [];
733
+
734
+ // -- Act --
735
+ const files = xcodeProject.filesForTarget('some-target');
736
+
737
+ // -- Assert --
738
+ expect(files).toEqual([]);
739
+ });
740
+ });
741
+
742
+ it('should return array of file paths', () => {
743
+ // -- Act --
744
+ const files = xcodeProject.filesForTarget('some-target');
745
+
746
+ // -- Assert --
747
+ expect(files).toEqual([
748
+ path.join(
749
+ appleProjectsPath,
750
+ 'spm-swiftui-single-target',
751
+ 'file-path',
752
+ ),
753
+ ]);
754
+ });
755
+ });
756
+ });
757
+ });
758
+
759
+ describe('projectFiles', () => {
760
+ describe('no groups in project', () => {
761
+ it('should return empty array', () => {
762
+ // -- Arrange --
763
+ const xcodeProject = new XcodeProject(singleTargetProjectPath);
764
+ xcodeProject.objects.PBXGroup = undefined;
765
+
766
+ // -- Act --
767
+ const files = xcodeProject.projectFiles();
768
+
769
+ // -- Assert --
770
+ expect(files).toEqual([]);
771
+ });
772
+ });
773
+
774
+ describe('main group not found', () => {
775
+ it('should return empty array', () => {
776
+ // -- Arrange --
777
+ const xcodeProject = new XcodeProject(singleTargetProjectPath);
778
+ const project = xcodeProject.objects.PBXProject?.[
779
+ 'D4E604C52D50CEEC00CAB00F'
780
+ ] as PBXProject;
781
+ if (project) {
782
+ delete project.mainGroup;
783
+ }
784
+
785
+ // -- Act --
786
+ const files = xcodeProject.projectFiles();
787
+
788
+ // -- Assert --
789
+ expect(files).toEqual([]);
790
+ });
791
+ });
792
+
793
+ describe('main group found', () => {
794
+ it('should return array of file paths', () => {
795
+ // -- Arrange --
796
+ const xcodeProject = new XcodeProject(singleTargetProjectPath);
797
+
798
+ // -- Act --
799
+ const files = xcodeProject.projectFiles();
800
+
801
+ // -- Assert --
802
+ expect(files).toEqual([
803
+ {
804
+ key: 'D4E604CD2D50CEEC00CAB00F',
805
+ path: 'Project.app',
806
+ },
807
+ ]);
808
+ });
809
+
810
+ it('should cache the result', () => {
811
+ // -- Arrange --
812
+ const xcodeProject = new XcodeProject(singleTargetProjectPath);
813
+
814
+ // Smoke test
815
+ expect(xcodeProject.files).toBeUndefined();
816
+
817
+ // -- Act --
818
+ const files = xcodeProject.projectFiles();
819
+
820
+ // -- Assert --
821
+ expect(xcodeProject.files).toBeDefined();
822
+ expect(xcodeProject.files).toEqual(files);
823
+ });
824
+ });
825
+ });
826
+
827
+ describe('buildGroup', () => {
828
+ describe('group has undefined children', () => {
829
+ it('should return empty array', () => {
830
+ // -- Arrange --
831
+ const xcodeProject = new XcodeProject(singleTargetProjectPath);
832
+ const group: PBXGroup = {
833
+ children: undefined,
834
+ path: '',
835
+ };
836
+
837
+ // -- Act --
838
+ const files = xcodeProject.buildGroup(group);
839
+
840
+ // -- Assert --
841
+ expect(files).toEqual([]);
842
+ });
843
+ });
844
+
845
+ describe('group has no children', () => {
846
+ it('should return empty array', () => {
847
+ // -- Arrange --
848
+ const xcodeProject = new XcodeProject(singleTargetProjectPath);
849
+ const group: PBXGroup = {};
850
+
851
+ // -- Act --
852
+ const files = xcodeProject.buildGroup(group);
853
+
854
+ // -- Assert --
855
+ expect(files).toEqual([]);
856
+ });
857
+ });
858
+
859
+ describe('group child is file reference', () => {
860
+ const group: PBXGroup = {
861
+ children: [
862
+ {
863
+ value: 'D4E604CD2D50CEEC00CAB00F',
864
+ },
865
+ ],
866
+ path: '',
867
+ };
868
+
869
+ describe('file references are undefined', () => {
870
+ it('should return empty array', () => {
871
+ // -- Arrange --
872
+ const xcodeProject = new XcodeProject(singleTargetProjectPath);
873
+ xcodeProject.objects.PBXFileReference = undefined;
874
+
875
+ // -- Act --
876
+ const files = xcodeProject.buildGroup(group);
877
+
878
+ // -- Assert --
879
+ expect(files).toEqual([]);
880
+ });
881
+ });
882
+
883
+ describe('file reference is string', () => {
884
+ it('should be ignored', () => {
885
+ // -- Arrange --
886
+ const xcodeProject = new XcodeProject(singleTargetProjectPath);
887
+ const group: PBXGroup = {
888
+ children: [
889
+ {
890
+ value: 'D4E604CD2D50CEEC00CAB00F_comment',
891
+ },
892
+ ],
893
+ path: '',
894
+ };
895
+
896
+ // -- Act --
897
+ const files = xcodeProject.buildGroup(group);
898
+
899
+ // -- Assert --
900
+ expect(files).toEqual([]);
901
+ });
902
+ });
903
+
904
+ describe('file reference is valid', () => {
905
+ it('should return array of escaped paths', () => {
906
+ // -- Arrange --
907
+ const xcodeProject = new XcodeProject(singleTargetProjectPath);
908
+ xcodeProject.objects.PBXFileReference = {
909
+ D4E604CD2D50CEEC00CAB00F: {
910
+ path: '"some/path/to/file.swift"',
911
+ },
912
+ };
913
+ const group: PBXGroup = {
914
+ children: [
915
+ {
916
+ value: 'D4E604CD2D50CEEC00CAB00F',
917
+ },
918
+ ],
919
+ path: '',
920
+ };
921
+
922
+ // -- Act --
923
+ const files = xcodeProject.buildGroup(group);
924
+
925
+ // -- Assert --
926
+ expect(files).toEqual([
927
+ {
928
+ key: 'D4E604CD2D50CEEC00CAB00F',
929
+ path: 'some/path/to/file.swift',
930
+ },
931
+ ]);
932
+ });
933
+ });
934
+ });
935
+
936
+ describe('group child is group reference', () => {
937
+ const group: PBXGroup = {
938
+ children: [
939
+ {
940
+ value: 'D4E604C42D50CEEC00CAB00F',
941
+ },
942
+ ],
943
+ path: '',
944
+ };
945
+
946
+ describe('groups are undefined', () => {
947
+ it('should return empty array', () => {
948
+ // -- Arrange --
949
+ const xcodeProject = new XcodeProject(singleTargetProjectPath);
950
+ xcodeProject.objects.PBXGroup = undefined;
951
+
952
+ // -- Act --
953
+ const files = xcodeProject.buildGroup(group);
954
+
955
+ // -- Assert --
956
+ expect(files).toEqual([]);
957
+ });
958
+ });
959
+
960
+ describe('group reference is string', () => {
961
+ it('should return array of file paths', () => {
962
+ // -- Arrange --
963
+ const xcodeProject = new XcodeProject(singleTargetProjectPath);
964
+ const group: PBXGroup = {
965
+ children: [
966
+ {
967
+ value: 'D4E604CE2D50CEEC00CAB00F_comment',
968
+ },
969
+ ],
970
+ path: '',
971
+ };
972
+
973
+ // -- Act --
974
+ const files = xcodeProject.buildGroup(group);
975
+
976
+ // -- Assert --
977
+ expect(files).toEqual([]);
978
+ });
979
+ });
980
+
981
+ describe('group reference is valid', () => {
982
+ it('should return array of file paths', () => {
983
+ // -- Arrange --
984
+ const xcodeProject = new XcodeProject(singleTargetProjectPath);
985
+
986
+ // -- Act --
987
+ const files = xcodeProject.buildGroup(group);
988
+
989
+ // -- Assert --
990
+ expect(files).toEqual([
991
+ {
992
+ key: 'D4E604CD2D50CEEC00CAB00F',
993
+ path: 'Project.app',
994
+ },
995
+ ]);
996
+ });
997
+ });
998
+
999
+ describe('group reference has path', () => {
1000
+ it('should append the path to the file paths', () => {
1001
+ // -- Arrange --
1002
+ const xcodeProject = new XcodeProject(singleTargetProjectPath);
1003
+ const group: PBXGroup = {
1004
+ children: [
1005
+ {
1006
+ value: 'sub-group',
1007
+ },
1008
+ ],
1009
+ path: '"some/path/to/group"',
1010
+ };
1011
+ const subgroup: PBXGroup = {
1012
+ children: [
1013
+ {
1014
+ value: 'file-at-path',
1015
+ },
1016
+ ],
1017
+ };
1018
+ const file: PBXFileReference = {
1019
+ path: '"some/file/at/path.swift"',
1020
+ };
1021
+ xcodeProject.objects.PBXGroup = {
1022
+ 'main-group': group,
1023
+ 'sub-group': subgroup,
1024
+ };
1025
+ xcodeProject.objects.PBXFileReference = {
1026
+ 'file-at-path': file,
1027
+ };
1028
+
1029
+ // -- Act --
1030
+ const files = xcodeProject.buildGroup(group);
1031
+
1032
+ // -- Assert --
1033
+ expect(files).toEqual([
1034
+ {
1035
+ key: 'file-at-path',
1036
+ path: 'some/file/at/path.swift',
1037
+ },
1038
+ ]);
1039
+ });
1040
+ });
1041
+ });
1042
+
1043
+ describe('group child is not a file reference or group', () => {
1044
+ it('should be ignored', () => {
1045
+ // -- Arrange --
1046
+ const xcodeProject = new XcodeProject(singleTargetProjectPath);
1047
+ xcodeProject.objects.PBXGroup = {};
1048
+ xcodeProject.objects.PBXFileReference = {};
1049
+ const group: PBXGroup = {
1050
+ children: [
1051
+ {
1052
+ value: 'random-key',
1053
+ },
1054
+ ],
1055
+ path: '',
1056
+ };
1057
+
1058
+ // -- Act --
1059
+ const files = xcodeProject.buildGroup(group);
1060
+
1061
+ // -- Assert --
1062
+ expect(files).toEqual([]);
1063
+ });
1064
+ });
1065
+ });
1066
+ });