@sentry/wizard 3.12.0 → 3.14.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 (86) hide show
  1. package/CHANGELOG.md +19 -0
  2. package/dist/lib/Steps/ChooseIntegration.js +1 -0
  3. package/dist/lib/Steps/ChooseIntegration.js.map +1 -1
  4. package/dist/package.json +2 -2
  5. package/dist/src/android/android-wizard.js +8 -8
  6. package/dist/src/android/android-wizard.js.map +1 -1
  7. package/dist/src/apple/apple-wizard.js +1 -1
  8. package/dist/src/apple/apple-wizard.js.map +1 -1
  9. package/dist/src/nextjs/nextjs-wizard.d.ts +1 -0
  10. package/dist/src/nextjs/nextjs-wizard.js +257 -163
  11. package/dist/src/nextjs/nextjs-wizard.js.map +1 -1
  12. package/dist/src/nextjs/templates.d.ts +1 -1
  13. package/dist/src/nextjs/templates.js +2 -2
  14. package/dist/src/nextjs/templates.js.map +1 -1
  15. package/dist/src/nextjs/utils.d.ts +1 -0
  16. package/dist/src/nextjs/utils.js +25 -0
  17. package/dist/src/nextjs/utils.js.map +1 -0
  18. package/dist/src/remix/remix-wizard.js +13 -11
  19. package/dist/src/remix/remix-wizard.js.map +1 -1
  20. package/dist/src/remix/sdk-setup.d.ts +5 -1
  21. package/dist/src/remix/sdk-setup.js +13 -6
  22. package/dist/src/remix/sdk-setup.js.map +1 -1
  23. package/dist/src/sourcemaps/sourcemaps-wizard.js +1 -1
  24. package/dist/src/sourcemaps/sourcemaps-wizard.js.map +1 -1
  25. package/dist/src/sourcemaps/tools/sentry-cli.d.ts +9 -0
  26. package/dist/src/sourcemaps/tools/sentry-cli.js +26 -22
  27. package/dist/src/sourcemaps/tools/sentry-cli.js.map +1 -1
  28. package/dist/src/sourcemaps/tools/tsc.d.ts +6 -0
  29. package/dist/src/sourcemaps/tools/tsc.js +98 -17
  30. package/dist/src/sourcemaps/tools/tsc.js.map +1 -1
  31. package/dist/src/sourcemaps/tools/vite.js +3 -13
  32. package/dist/src/sourcemaps/tools/vite.js.map +1 -1
  33. package/dist/src/sourcemaps/tools/webpack.js +3 -13
  34. package/dist/src/sourcemaps/tools/webpack.js.map +1 -1
  35. package/dist/src/sveltekit/sdk-setup.js +122 -48
  36. package/dist/src/sveltekit/sdk-setup.js.map +1 -1
  37. package/dist/src/sveltekit/sveltekit-wizard.d.ts +1 -0
  38. package/dist/src/sveltekit/sveltekit-wizard.js +113 -42
  39. package/dist/src/sveltekit/sveltekit-wizard.js.map +1 -1
  40. package/dist/src/sveltekit/utils.d.ts +2 -0
  41. package/dist/src/sveltekit/utils.js +48 -0
  42. package/dist/src/sveltekit/utils.js.map +1 -0
  43. package/dist/src/telemetry.d.ts +1 -0
  44. package/dist/src/telemetry.js +27 -12
  45. package/dist/src/telemetry.js.map +1 -1
  46. package/dist/src/utils/ast-utils.d.ts +70 -0
  47. package/dist/src/utils/ast-utils.js +152 -1
  48. package/dist/src/utils/ast-utils.js.map +1 -1
  49. package/dist/src/utils/clack-utils.d.ts +49 -7
  50. package/dist/src/utils/clack-utils.js +238 -168
  51. package/dist/src/utils/clack-utils.js.map +1 -1
  52. package/dist/src/utils/package-manager.d.ts +5 -0
  53. package/dist/src/utils/package-manager.js +23 -14
  54. package/dist/src/utils/package-manager.js.map +1 -1
  55. package/dist/test/sourcemaps/tools/sentry-cli.test.d.ts +1 -0
  56. package/dist/test/sourcemaps/tools/sentry-cli.test.js +112 -0
  57. package/dist/test/sourcemaps/tools/sentry-cli.test.js.map +1 -0
  58. package/dist/test/sourcemaps/tools/tsc.test.d.ts +1 -0
  59. package/dist/test/sourcemaps/tools/tsc.test.js +121 -0
  60. package/dist/test/sourcemaps/tools/tsc.test.js.map +1 -0
  61. package/dist/test/utils/ast-utils.test.js +157 -26
  62. package/dist/test/utils/ast-utils.test.js.map +1 -1
  63. package/lib/Steps/ChooseIntegration.ts +1 -0
  64. package/package.json +2 -2
  65. package/src/android/android-wizard.ts +12 -10
  66. package/src/apple/apple-wizard.ts +2 -2
  67. package/src/nextjs/nextjs-wizard.ts +277 -198
  68. package/src/nextjs/templates.ts +3 -2
  69. package/src/nextjs/utils.ts +21 -0
  70. package/src/remix/remix-wizard.ts +15 -20
  71. package/src/remix/sdk-setup.ts +20 -5
  72. package/src/sourcemaps/sourcemaps-wizard.ts +2 -2
  73. package/src/sourcemaps/tools/sentry-cli.ts +16 -9
  74. package/src/sourcemaps/tools/tsc.ts +133 -28
  75. package/src/sourcemaps/tools/vite.ts +15 -39
  76. package/src/sourcemaps/tools/webpack.ts +16 -39
  77. package/src/sveltekit/sdk-setup.ts +109 -37
  78. package/src/sveltekit/sveltekit-wizard.ts +86 -21
  79. package/src/sveltekit/utils.ts +50 -0
  80. package/src/telemetry.ts +22 -11
  81. package/src/utils/ast-utils.ts +180 -0
  82. package/src/utils/clack-utils.ts +238 -149
  83. package/src/utils/package-manager.ts +24 -12
  84. package/test/sourcemaps/tools/sentry-cli.test.ts +51 -0
  85. package/test/sourcemaps/tools/tsc.test.ts +181 -0
  86. package/test/utils/ast-utils.test.ts +233 -32
@@ -0,0 +1,181 @@
1
+ import * as fs from 'fs';
2
+ import { enableSourcemaps } from '../../../src/sourcemaps/tools/tsc';
3
+
4
+ function updateFileContent(content: string): void {
5
+ fileContent = content;
6
+ }
7
+
8
+ let fileContent = '';
9
+
10
+ jest.mock('@clack/prompts', () => {
11
+ return {
12
+ log: {
13
+ info: jest.fn(),
14
+ success: jest.fn(),
15
+ },
16
+ };
17
+ });
18
+
19
+ jest
20
+ .spyOn(fs.promises, 'readFile')
21
+ .mockImplementation(() => Promise.resolve(fileContent));
22
+
23
+ const writeFileSpy = jest
24
+ .spyOn(fs.promises, 'writeFile')
25
+ .mockImplementation(() => Promise.resolve(void 0));
26
+
27
+ describe('enableSourcemaps', () => {
28
+ afterEach(() => {
29
+ fileContent = '';
30
+ jest.clearAllMocks();
31
+ });
32
+
33
+ it.each([
34
+ [
35
+ 'no sourcemaps options',
36
+ `
37
+ /**
38
+ * My TS config with comments
39
+ */
40
+ {
41
+ "extends": "./tsconfig.build.json",
42
+
43
+ "compilerOptions": {
44
+ // line comment which should stay
45
+ "moduleResolution": "node16",
46
+ "outDir": "dist" // another inline comment
47
+ },
48
+
49
+ "include": [
50
+ "src/**/*",
51
+ "test/**/*"
52
+ ]
53
+ }
54
+ `,
55
+ `
56
+ /**
57
+ * My TS config with comments
58
+ */
59
+ {
60
+ "extends": "./tsconfig.build.json",
61
+
62
+ "compilerOptions": {
63
+ // line comment which should stay
64
+ "moduleResolution": "node16",
65
+
66
+ // another inline comment
67
+ "outDir": "dist",
68
+
69
+ "sourceMap": true,
70
+ "inlineSources": true,
71
+
72
+ // Set \`sourceRoot\` to "/" to strip the build path prefix
73
+ // from generated source code references.
74
+ // This improves issue grouping in Sentry.
75
+ "sourceRoot": "/"
76
+ },
77
+
78
+ "include": [
79
+ "src/**/*",
80
+ "test/**/*"
81
+ ]
82
+ }
83
+ `,
84
+ ],
85
+ [
86
+ 'a few sourcemaps options',
87
+ `
88
+ /**
89
+ * My TS config with comments
90
+ */
91
+ {
92
+ "extends": "./tsconfig.build.json",
93
+
94
+ "compilerOptions": {
95
+ // line comment which should stay
96
+ "moduleResolution": "node16",
97
+ "outDir": "dist", // another inline comment
98
+ "sourceMap": false,
99
+ "sourceRoot": "/src"
100
+ },
101
+
102
+ "include": [
103
+ "src/**/*",
104
+ "test/**/*"
105
+ ]
106
+ }
107
+ `,
108
+ `
109
+ /**
110
+ * My TS config with comments
111
+ */
112
+ {
113
+ "extends": "./tsconfig.build.json",
114
+
115
+ "compilerOptions": {
116
+ // line comment which should stay
117
+ "moduleResolution": "node16",
118
+
119
+ // another inline comment
120
+ "outDir": "dist",
121
+
122
+ "sourceMap": true,
123
+
124
+ // Set \`sourceRoot\` to "/" to strip the build path prefix
125
+ // from generated source code references.
126
+ // This improves issue grouping in Sentry.
127
+ "sourceRoot": "/",
128
+
129
+ "inlineSources": true
130
+ },
131
+
132
+ "include": [
133
+ "src/**/*",
134
+ "test/**/*"
135
+ ]
136
+ }
137
+ `,
138
+ ],
139
+ [
140
+ 'no compiler options',
141
+ `
142
+ {
143
+ "include": [
144
+ "src/**/*",
145
+ "test/**/*"
146
+ ]
147
+ }
148
+ `,
149
+ `
150
+ {
151
+ "include": [
152
+ "src/**/*",
153
+ "test/**/*"
154
+ ],
155
+
156
+ "compilerOptions": {
157
+ "sourceMap": true,
158
+ "inlineSources": true,
159
+
160
+ // Set \`sourceRoot\` to "/" to strip the build path prefix
161
+ // from generated source code references.
162
+ // This improves issue grouping in Sentry.
163
+ "sourceRoot": "/"
164
+ }
165
+ }
166
+ `,
167
+ ],
168
+ ])(
169
+ 'adds the plugin and enables source maps generation (%s)',
170
+ async (_, originalCode, expectedCode) => {
171
+ updateFileContent(originalCode);
172
+
173
+ const addedCode = await enableSourcemaps('');
174
+
175
+ expect(writeFileSpy).toHaveBeenCalledTimes(1);
176
+ const [[, fileContent]] = writeFileSpy.mock.calls;
177
+ expect(fileContent).toBe(expectedCode);
178
+ expect(addedCode).toBe(true);
179
+ },
180
+ );
181
+ });
@@ -1,15 +1,22 @@
1
- import { hasSentryContent } from '../../src/utils/ast-utils';
1
+ import {
2
+ getObjectProperty,
3
+ getOrSetObjectProperty,
4
+ hasSentryContent,
5
+ parseJsonC,
6
+ printJsonC,
7
+ setOrUpdateObjectProperty,
8
+ } from '../../src/utils/ast-utils';
2
9
 
3
10
  import * as recast from 'recast';
11
+ const b = recast.types.builders;
4
12
 
5
- describe('AST utils', () => {
6
- describe('hasSentryContent', () => {
7
- it.each([
8
- `
13
+ describe('hasSentryContent', () => {
14
+ it.each([
15
+ `
9
16
  const { sentryVitePlugin } = require("@sentry/vite-plugin");
10
17
  const somethingelse = require('gs');
11
18
  `,
12
- `
19
+ `
13
20
  import { sentryVitePlugin } from "@sentry/vite-plugin";
14
21
  import * as somethingelse from 'gs';
15
22
 
@@ -17,47 +24,241 @@ describe('AST utils', () => {
17
24
  plugins: [sentryVitePlugin()]
18
25
  }
19
26
  `,
20
- ])(
21
- "returns true if a require('@sentry/') call was found in the parsed module",
22
- (code) => {
23
- // recast.parse returns a Program node (or fails) but it's badly typed as any
24
- // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
25
- const program = recast.parse(code)
26
- .program as recast.types.namedTypes.Program;
27
- expect(hasSentryContent(program)).toBe(true);
28
- },
29
- );
27
+ ])(
28
+ "returns true if a require('@sentry/') call was found in the parsed module",
29
+ (code) => {
30
+ // recast.parse returns a Program node (or fails) but it's badly typed as any
31
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
32
+ const program = recast.parse(code)
33
+ .program as recast.types.namedTypes.Program;
34
+ expect(hasSentryContent(program)).toBe(true);
35
+ },
36
+ );
30
37
 
31
- it.each([
32
- `const whatever = require('something')`,
33
- `// const {sentryWebpackPlugin} = require('@sentry/webpack-plugin')`,
34
- `const {sAntryWebpackPlugin} = require('webpack-plugin-@sentry')`,
35
- `
38
+ it.each([
39
+ `const whatever = require('something')`,
40
+ `// const {sentryWebpackPlugin} = require('@sentry/webpack-plugin')`,
41
+ `const {sAntryWebpackPlugin} = require('webpack-plugin-@sentry')`,
42
+ `
36
43
  import * as somethingelse from 'gs';
37
44
  export default {
38
45
  plugins: []
39
46
  }
40
47
  `,
41
- `import * as somethingelse from 'gs';
48
+ `import * as somethingelse from 'gs';
42
49
  // import { sentryVitePlugin } from "@sentry/vite-plugin"
43
50
  export default {
44
51
  plugins: []
45
52
  }
46
53
  `,
47
- `import * as thirdPartyVitePlugin from "vite-plugin-@sentry"
54
+ `import * as thirdPartyVitePlugin from "vite-plugin-@sentry"
48
55
  export default {
49
56
  plugins: [thirdPartyVitePlugin()]
50
57
  }
51
58
  `,
52
- ])(
53
- "returns false if the file doesn't contain any require('@sentry/') calls",
54
- (code) => {
55
- // recast.parse returns a Program node (or fails) but it's badly typed as any
56
- // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
57
- const program = recast.parse(code)
58
- .program as recast.types.namedTypes.Program;
59
- expect(hasSentryContent(program)).toBe(false);
60
- },
59
+ ])(
60
+ "returns false if the file doesn't contain any require('@sentry/') calls",
61
+ (code) => {
62
+ // recast.parse returns a Program node (or fails) but it's badly typed as any
63
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
64
+ const program = recast.parse(code)
65
+ .program as recast.types.namedTypes.Program;
66
+ expect(hasSentryContent(program)).toBe(false);
67
+ },
68
+ );
69
+ });
70
+
71
+ describe('getObjectProperty', () => {
72
+ it.each([
73
+ [
74
+ 'literal',
75
+ b.objectExpression([
76
+ b.objectProperty(b.identifier('foo'), b.stringLiteral('bar')),
77
+ b.objectProperty(
78
+ b.stringLiteral('needle'),
79
+ b.stringLiteral('haystack'),
80
+ ),
81
+ ]),
82
+ ],
83
+ [
84
+ 'stringLiteral',
85
+ b.objectExpression([
86
+ b.objectProperty(b.identifier('foo'), b.stringLiteral('bar')),
87
+ b.objectProperty(b.literal('needle'), b.stringLiteral('haystack')),
88
+ ]),
89
+ ],
90
+ [
91
+ 'identifier',
92
+ b.objectExpression([
93
+ b.objectProperty(b.identifier('foo'), b.stringLiteral('bar')),
94
+ b.objectProperty(b.identifier('needle'), b.stringLiteral('haystack')),
95
+ ]),
96
+ ],
97
+ ])('returns the poperty (%s) if it exists', (_, object) => {
98
+ const property = getObjectProperty(object, 'needle');
99
+ expect(property).toBeDefined();
100
+ // @ts-expect-error we know it's defined due to the expect above
101
+ expect(recast.print(property).code).toEqual(
102
+ expect.stringContaining('needle'),
61
103
  );
62
104
  });
105
+
106
+ it('returns undefined if the property does not exist', () => {
107
+ const object = b.objectExpression([
108
+ b.objectProperty(b.identifier('foo'), b.stringLiteral('bar')),
109
+ ]);
110
+ const property = getObjectProperty(object, 'needle');
111
+ expect(property).toBeUndefined();
112
+ });
113
+
114
+ it('handles objects without simple properties', () => {
115
+ const object = b.objectExpression([b.spreadElement(b.identifier('foo'))]);
116
+ const property = getObjectProperty(object, 'needle');
117
+ expect(property).toBeUndefined();
118
+ });
119
+ });
120
+
121
+ describe('getOrSetObjectProperty', () => {
122
+ it('returns the property if it exists', () => {
123
+ const object = b.objectExpression([
124
+ b.objectProperty(b.identifier('needle'), b.stringLiteral('haystack')),
125
+ ]);
126
+
127
+ const property = getOrSetObjectProperty(
128
+ object,
129
+ 'needle',
130
+ b.stringLiteral('nope'),
131
+ );
132
+
133
+ expect(property).toBeDefined();
134
+ expect(property.type).toBe('ObjectProperty');
135
+ // @ts-expect-error we know its type
136
+ expect(property.key.name).toBe('needle');
137
+ // @ts-expect-error we know its type
138
+ expect(property.value.value).toBe('haystack');
139
+ });
140
+
141
+ it('adds the property if it does not exist', () => {
142
+ const object = b.objectExpression([
143
+ b.objectProperty(b.identifier('foo'), b.stringLiteral('bar')),
144
+ ]);
145
+
146
+ const property = getOrSetObjectProperty(
147
+ object,
148
+ 'needle',
149
+ b.stringLiteral('haystack'),
150
+ );
151
+
152
+ expect(property).toBeDefined();
153
+ expect(property.type).toBe('Property');
154
+ // @ts-expect-error we know its type
155
+ expect(property.key.value).toBe('needle');
156
+ // @ts-expect-error we know its type
157
+ expect(property.value.value).toBe('haystack');
158
+ });
159
+ });
160
+
161
+ describe('setOrUpdateObjectProperty', () => {
162
+ it('sets a new property if it does not exist yet', () => {
163
+ const object = b.objectExpression([
164
+ b.objectProperty(b.identifier('foo'), b.stringLiteral('bar')),
165
+ ]);
166
+
167
+ setOrUpdateObjectProperty(object, 'needle', b.stringLiteral('haystack'));
168
+
169
+ expect(getObjectProperty(object, 'needle')).toBeDefined();
170
+ });
171
+
172
+ it('updates an existing property if it exists', () => {
173
+ const object = b.objectExpression([
174
+ b.objectProperty(b.identifier('foo'), b.stringLiteral('bar')),
175
+ b.objectProperty(b.identifier('needle'), b.stringLiteral('haystack')),
176
+ ]);
177
+
178
+ setOrUpdateObjectProperty(object, 'needle', b.stringLiteral('haystack2'));
179
+
180
+ const property = getObjectProperty(object, 'needle');
181
+ // @ts-expect-error it must be defiend, otherwise we fail anyway
182
+ expect(property?.value.value).toBe('haystack2');
183
+ });
184
+
185
+ it('adds a comment to the existing property if provided', () => {
186
+ const object = b.objectExpression([
187
+ b.objectProperty(b.identifier('foo'), b.stringLiteral('bar')),
188
+ ]);
189
+
190
+ setOrUpdateObjectProperty(
191
+ object,
192
+ 'needle',
193
+ b.stringLiteral('haystack'),
194
+ 'This is a comment',
195
+ );
196
+
197
+ const property = getObjectProperty(object, 'needle');
198
+ expect(property?.comments).toHaveLength(1);
199
+ // @ts-expect-error it must be defiend, otherwise we fail anyway
200
+ expect(property?.comments[0].value).toBe(' This is a comment');
201
+ });
202
+
203
+ it('adds a comment to the new property if provided', () => {
204
+ const object = b.objectExpression([
205
+ b.objectProperty(b.identifier('foo'), b.stringLiteral('bar')),
206
+ ]);
207
+
208
+ setOrUpdateObjectProperty(
209
+ object,
210
+ 'needle',
211
+ b.stringLiteral('haystack'),
212
+ 'This is a comment',
213
+ );
214
+
215
+ const property = getObjectProperty(object, 'needle');
216
+ expect(property?.comments).toHaveLength(1);
217
+ // @ts-expect-error it must be defiend, otherwise we fail anyway
218
+ expect(property?.comments[0].value).toBe(' This is a comment');
219
+ });
220
+ });
221
+
222
+ describe('parse and print JSON-C', () => {
223
+ it.each([
224
+ ['simple JSON', "{'foo': 'bar'}"],
225
+ [
226
+ 'JSON-C with inline comment',
227
+ `
228
+ {
229
+ "foo": "bar" // with an inline comment
230
+ }
231
+ `,
232
+ ],
233
+ [
234
+ 'JSON-C with multiple comments',
235
+ `
236
+ /*
237
+ * let's throw in a block comment for good measure
238
+ */
239
+ {
240
+ // one line comment
241
+ "foo": "bar", // another inline comment
242
+ /* one more here */
243
+ "dogs": /* and here */ "awesome",
244
+ }
245
+ /* and here */
246
+ `,
247
+ ],
248
+ ])(`parses and prints JSON-C (%s)`, (_, json) => {
249
+ const { ast, jsonObject } = parseJsonC(json);
250
+ expect(ast?.type).toBe('Program');
251
+ expect(jsonObject).toBeDefined();
252
+ expect(jsonObject?.type).toBe('ObjectExpression');
253
+ // @ts-expect-error we know it's defined due to the expect above
254
+ expect(printJsonC(ast)).toEqual(json);
255
+ });
256
+
257
+ it('returns undefined if the input is not valid JSON-C', () => {
258
+ const { ast, jsonObject } = parseJsonC(`{
259
+ "invalid": // "json"
260
+ }`);
261
+ expect(ast).toBeUndefined();
262
+ expect(jsonObject).toBeUndefined();
263
+ });
63
264
  });