@sentry/wizard 3.1.0 → 3.2.1

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 (106) hide show
  1. package/CHANGELOG.md +19 -0
  2. package/bin.ts +5 -1
  3. package/dist/bin.js +6 -1
  4. package/dist/bin.js.map +1 -1
  5. package/dist/lib/Constants.d.ts +2 -1
  6. package/dist/lib/Constants.js +5 -0
  7. package/dist/lib/Constants.js.map +1 -1
  8. package/dist/lib/Helper/File.js +25 -2
  9. package/dist/lib/Helper/File.js.map +1 -1
  10. package/dist/lib/Helper/Git.d.ts +7 -0
  11. package/dist/lib/Helper/Git.js +94 -0
  12. package/dist/lib/Helper/Git.js.map +1 -0
  13. package/dist/lib/Helper/Logging.d.ts +1 -0
  14. package/dist/lib/Helper/Logging.js +9 -2
  15. package/dist/lib/Helper/Logging.js.map +1 -1
  16. package/dist/lib/Helper/MergeConfig.js +24 -1
  17. package/dist/lib/Helper/MergeConfig.js.map +1 -1
  18. package/dist/lib/Helper/Package.d.ts +9 -0
  19. package/dist/lib/Helper/Package.js +39 -2
  20. package/dist/lib/Helper/Package.js.map +1 -1
  21. package/dist/lib/Helper/PackageManager.d.ts +1 -1
  22. package/dist/lib/Helper/PackageManager.js +32 -11
  23. package/dist/lib/Helper/PackageManager.js.map +1 -1
  24. package/dist/lib/Helper/SentryCli.d.ts +11 -0
  25. package/dist/lib/Helper/SentryCli.js +141 -2
  26. package/dist/lib/Helper/SentryCli.js.map +1 -1
  27. package/dist/lib/Helper/Wizard.js +24 -1
  28. package/dist/lib/Helper/Wizard.js.map +1 -1
  29. package/dist/lib/Helper/__tests__/MergeConfig.js +25 -2
  30. package/dist/lib/Helper/__tests__/MergeConfig.js.map +1 -1
  31. package/dist/lib/Setup.js +25 -2
  32. package/dist/lib/Setup.js.map +1 -1
  33. package/dist/lib/Steps/ChooseIntegration.js +28 -1
  34. package/dist/lib/Steps/ChooseIntegration.js.map +1 -1
  35. package/dist/lib/Steps/Initial.js +25 -2
  36. package/dist/lib/Steps/Initial.js.map +1 -1
  37. package/dist/lib/Steps/Integrations/BaseIntegration.js +24 -1
  38. package/dist/lib/Steps/Integrations/BaseIntegration.js.map +1 -1
  39. package/dist/lib/Steps/Integrations/Cordova.js +25 -2
  40. package/dist/lib/Steps/Integrations/Cordova.js.map +1 -1
  41. package/dist/lib/Steps/Integrations/Electron.js +26 -3
  42. package/dist/lib/Steps/Integrations/Electron.js.map +1 -1
  43. package/dist/lib/Steps/Integrations/MobileProject.js +24 -1
  44. package/dist/lib/Steps/Integrations/MobileProject.js.map +1 -1
  45. package/dist/lib/Steps/Integrations/NextJs.d.ts +5 -11
  46. package/dist/lib/Steps/Integrations/NextJs.js +14 -343
  47. package/dist/lib/Steps/Integrations/NextJs.js.map +1 -1
  48. package/dist/lib/Steps/Integrations/ReactNative.d.ts +1 -0
  49. package/dist/lib/Steps/Integrations/ReactNative.js +67 -6
  50. package/dist/lib/Steps/Integrations/ReactNative.js.map +1 -1
  51. package/dist/lib/Steps/Integrations/SvelteKit.d.ts +13 -0
  52. package/dist/lib/Steps/Integrations/SvelteKit.js +95 -0
  53. package/dist/lib/Steps/Integrations/SvelteKit.js.map +1 -0
  54. package/dist/lib/Steps/Integrations/__tests__/ReactNative.js +28 -5
  55. package/dist/lib/Steps/Integrations/__tests__/ReactNative.js.map +1 -1
  56. package/dist/lib/Steps/PromptForParameters.js +24 -1
  57. package/dist/lib/Steps/PromptForParameters.js.map +1 -1
  58. package/dist/lib/Steps/SentryProjectSelector.js +25 -1
  59. package/dist/lib/Steps/SentryProjectSelector.js.map +1 -1
  60. package/dist/lib/__tests__/Setup.js +24 -1
  61. package/dist/lib/__tests__/Setup.js.map +1 -1
  62. package/dist/src/{nextjs-wizard.js → nextjs/nextjs-wizard.js} +113 -108
  63. package/dist/src/nextjs/nextjs-wizard.js.map +1 -0
  64. package/dist/src/sveltekit/sdk-example.d.ts +10 -0
  65. package/dist/src/sveltekit/sdk-example.js +106 -0
  66. package/dist/src/sveltekit/sdk-example.js.map +1 -0
  67. package/dist/src/sveltekit/sdk-setup.d.ts +13 -0
  68. package/dist/src/sveltekit/sdk-setup.js +452 -0
  69. package/dist/src/sveltekit/sdk-setup.js.map +1 -0
  70. package/dist/src/sveltekit/sentry-cli-setup.d.ts +2 -0
  71. package/dist/src/sveltekit/sentry-cli-setup.js +71 -0
  72. package/dist/src/sveltekit/sentry-cli-setup.js.map +1 -0
  73. package/dist/src/sveltekit/sveltekit-wizard.d.ts +5 -0
  74. package/dist/src/sveltekit/sveltekit-wizard.js +147 -0
  75. package/dist/src/sveltekit/sveltekit-wizard.js.map +1 -0
  76. package/dist/src/templates/nextjs-templates.js +2 -2
  77. package/dist/src/templates/nextjs-templates.js.map +1 -1
  78. package/dist/src/templates/sveltekit-templates.d.ts +12 -0
  79. package/dist/src/templates/sveltekit-templates.js +26 -0
  80. package/dist/src/templates/sveltekit-templates.js.map +1 -0
  81. package/dist/src/{clack-utils.d.ts → utils/clack-utils.d.ts} +7 -0
  82. package/dist/src/{clack-utils.js → utils/clack-utils.js} +127 -42
  83. package/dist/src/utils/clack-utils.js.map +1 -0
  84. package/lib/Constants.ts +5 -0
  85. package/lib/Helper/Git.ts +39 -0
  86. package/lib/Helper/Logging.ts +4 -0
  87. package/lib/Helper/Package.ts +17 -0
  88. package/lib/Helper/PackageManager.ts +4 -9
  89. package/lib/Helper/SentryCli.ts +74 -0
  90. package/lib/Steps/ChooseIntegration.ts +4 -0
  91. package/lib/Steps/Integrations/NextJs.ts +7 -397
  92. package/lib/Steps/Integrations/ReactNative.ts +49 -3
  93. package/lib/Steps/Integrations/SvelteKit.ts +29 -0
  94. package/lib/Steps/SentryProjectSelector.ts +1 -0
  95. package/package.json +2 -2
  96. package/src/{nextjs-wizard.ts → nextjs/nextjs-wizard.ts} +13 -44
  97. package/src/sveltekit/sdk-example.ts +56 -0
  98. package/src/sveltekit/sdk-setup.ts +431 -0
  99. package/src/sveltekit/sentry-cli-setup.ts +27 -0
  100. package/src/sveltekit/sveltekit-wizard.ts +116 -0
  101. package/src/templates/nextjs-templates.ts +2 -2
  102. package/src/templates/sveltekit-templates.ts +172 -0
  103. package/src/{clack-utils.ts → utils/clack-utils.ts} +73 -11
  104. package/dist/src/clack-utils.js.map +0 -1
  105. package/dist/src/nextjs-wizard.js.map +0 -1
  106. /package/dist/src/{nextjs-wizard.d.ts → nextjs/nextjs-wizard.d.ts} +0 -0
@@ -0,0 +1,452 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
26
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
27
+ return new (P || (P = Promise))(function (resolve, reject) {
28
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
29
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
30
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
31
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
32
+ });
33
+ };
34
+ var __generator = (this && this.__generator) || function (thisArg, body) {
35
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
36
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
37
+ function verb(n) { return function (v) { return step([n, v]); }; }
38
+ function step(op) {
39
+ if (f) throw new TypeError("Generator is already executing.");
40
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
41
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
42
+ if (y = 0, t) op = [op[0] & 2, t.value];
43
+ switch (op[0]) {
44
+ case 0: case 1: t = op; break;
45
+ case 4: _.label++; return { value: op[1], done: false };
46
+ case 5: _.label++; y = op[1]; op = [0]; continue;
47
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
48
+ default:
49
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
50
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
51
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
52
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
53
+ if (t[2]) _.ops.pop();
54
+ _.trys.pop(); continue;
55
+ }
56
+ op = body.call(thisArg, _);
57
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
58
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
59
+ }
60
+ };
61
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
62
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
63
+ if (ar || !(i in from)) {
64
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
65
+ ar[i] = from[i];
66
+ }
67
+ }
68
+ return to.concat(ar || Array.prototype.slice.call(from));
69
+ };
70
+ var __importDefault = (this && this.__importDefault) || function (mod) {
71
+ return (mod && mod.__esModule) ? mod : { "default": mod };
72
+ };
73
+ Object.defineProperty(exports, "__esModule", { value: true });
74
+ exports.loadSvelteConfig = exports.createOrMergeSvelteKitFiles = void 0;
75
+ var fs = __importStar(require("fs"));
76
+ var path = __importStar(require("path"));
77
+ var url = __importStar(require("url"));
78
+ var chalk_1 = __importDefault(require("chalk"));
79
+ // @ts-ignore - clack is ESM and TS complains about that. It works though
80
+ var prompts_1 = __importDefault(require("@clack/prompts"));
81
+ // @ts-ignore - magicast is ESM and TS complains about that. It works though
82
+ var magicast_1 = require("magicast");
83
+ // @ts-ignore - magicast is ESM and TS complains about that. It works though
84
+ var helpers_1 = require("magicast/helpers");
85
+ var sveltekit_templates_1 = require("../templates/sveltekit-templates");
86
+ var SVELTE_CONFIG_FILE = 'svelte.config.js';
87
+ function createOrMergeSvelteKitFiles(dsn, svelteConfig) {
88
+ return __awaiter(this, void 0, void 0, function () {
89
+ var _a, clientHooksPath, serverHooksPath, originalClientHooksFile, originalServerHooksFile, viteConfig;
90
+ return __generator(this, function (_b) {
91
+ switch (_b.label) {
92
+ case 0:
93
+ _a = getHooksConfigDirs(svelteConfig), clientHooksPath = _a.clientHooksPath, serverHooksPath = _a.serverHooksPath;
94
+ originalClientHooksFile = findHooksFile(clientHooksPath);
95
+ originalServerHooksFile = findHooksFile(serverHooksPath);
96
+ viteConfig = findHooksFile(path.resolve(process.cwd(), 'vite.config'));
97
+ if (!!originalClientHooksFile) return [3 /*break*/, 2];
98
+ prompts_1.default.log.info('No client hooks file found, creating a new one.');
99
+ return [4 /*yield*/, createNewHooksFile("".concat(clientHooksPath, ".js"), 'client', dsn)];
100
+ case 1:
101
+ _b.sent();
102
+ _b.label = 2;
103
+ case 2:
104
+ if (!!originalServerHooksFile) return [3 /*break*/, 4];
105
+ prompts_1.default.log.info('No server hooks file found, creating a new one.');
106
+ return [4 /*yield*/, createNewHooksFile("".concat(serverHooksPath, ".js"), 'client', dsn)];
107
+ case 3:
108
+ _b.sent();
109
+ _b.label = 4;
110
+ case 4:
111
+ if (!originalClientHooksFile) return [3 /*break*/, 6];
112
+ return [4 /*yield*/, mergeHooksFile(originalClientHooksFile, 'client', dsn)];
113
+ case 5:
114
+ _b.sent();
115
+ _b.label = 6;
116
+ case 6:
117
+ if (!originalServerHooksFile) return [3 /*break*/, 8];
118
+ return [4 /*yield*/, mergeHooksFile(originalServerHooksFile, 'server', dsn)];
119
+ case 7:
120
+ _b.sent();
121
+ _b.label = 8;
122
+ case 8:
123
+ if (!viteConfig) return [3 /*break*/, 10];
124
+ return [4 /*yield*/, modifyViteConfig(viteConfig)];
125
+ case 9:
126
+ _b.sent();
127
+ _b.label = 10;
128
+ case 10: return [2 /*return*/];
129
+ }
130
+ });
131
+ });
132
+ }
133
+ exports.createOrMergeSvelteKitFiles = createOrMergeSvelteKitFiles;
134
+ /**
135
+ * Attempts to read the svelte.config.js file to find the location of the hooks files.
136
+ * If users specified a custom location, we'll use that. Otherwise, we'll use the default.
137
+ */
138
+ function getHooksConfigDirs(svelteConfig) {
139
+ var _a, _b, _c, _d, _e, _f;
140
+ var relativeUserClientHooksPath = (_c = (_b = (_a = svelteConfig === null || svelteConfig === void 0 ? void 0 : svelteConfig.kit) === null || _a === void 0 ? void 0 : _a.files) === null || _b === void 0 ? void 0 : _b.hooks) === null || _c === void 0 ? void 0 : _c.client;
141
+ var relativeUserServerHooksPath = (_f = (_e = (_d = svelteConfig === null || svelteConfig === void 0 ? void 0 : svelteConfig.kit) === null || _d === void 0 ? void 0 : _d.files) === null || _e === void 0 ? void 0 : _e.hooks) === null || _f === void 0 ? void 0 : _f.server;
142
+ var userClientHooksPath = relativeUserClientHooksPath &&
143
+ path.resolve(process.cwd(), relativeUserClientHooksPath);
144
+ var userServerHooksPath = relativeUserServerHooksPath &&
145
+ path.resolve(process.cwd(), relativeUserServerHooksPath);
146
+ var defaulHooksDir = path.resolve(process.cwd(), 'src');
147
+ var defaultClientHooksPath = path.resolve(defaulHooksDir, 'hooks.client'); // file ending missing on purpose
148
+ var defaultServerHooksPath = path.resolve(defaulHooksDir, 'hooks.server'); // same here
149
+ return {
150
+ clientHooksPath: userClientHooksPath || defaultClientHooksPath,
151
+ serverHooksPath: userServerHooksPath || defaultServerHooksPath,
152
+ };
153
+ }
154
+ /**
155
+ * Checks if a hooks file exists and returns the full path to the file with the correct file type.
156
+ */
157
+ function findHooksFile(hooksFile) {
158
+ var possibleFileTypes = ['.js', '.ts', '.mjs'];
159
+ return possibleFileTypes
160
+ .map(function (type) { return "".concat(hooksFile).concat(type); })
161
+ .find(function (file) { return fs.existsSync(file); });
162
+ }
163
+ /**
164
+ * Reads the template, replaces the dsn placeholder with the actual dsn and writes the file to @param hooksFileDest
165
+ */
166
+ function createNewHooksFile(hooksFileDest, hooktype, dsn) {
167
+ return __awaiter(this, void 0, void 0, function () {
168
+ var filledTemplate;
169
+ return __generator(this, function (_a) {
170
+ switch (_a.label) {
171
+ case 0:
172
+ filledTemplate = hooktype === 'client'
173
+ ? (0, sveltekit_templates_1.getClientHooksTemplate)(dsn)
174
+ : (0, sveltekit_templates_1.getServerHooksTemplate)(dsn);
175
+ return [4 /*yield*/, fs.promises.mkdir(path.dirname(hooksFileDest), { recursive: true })];
176
+ case 1:
177
+ _a.sent();
178
+ return [4 /*yield*/, fs.promises.writeFile(hooksFileDest, filledTemplate)];
179
+ case 2:
180
+ _a.sent();
181
+ prompts_1.default.log.success("Created ".concat(hooksFileDest));
182
+ return [2 /*return*/];
183
+ }
184
+ });
185
+ });
186
+ }
187
+ /**
188
+ * Merges the users' hooks file with Sentry-related code.
189
+ *
190
+ * Both hooks:
191
+ * - add import * as Sentry
192
+ * - add Sentry.init
193
+ * - add handleError hook wrapper
194
+ *
195
+ * Additionally in Server hook:
196
+ * - add handle hook handler
197
+ */
198
+ function mergeHooksFile(hooksFile, hookType, dsn) {
199
+ return __awaiter(this, void 0, void 0, function () {
200
+ var originalHooksMod, modifiedCode;
201
+ return __generator(this, function (_a) {
202
+ switch (_a.label) {
203
+ case 0: return [4 /*yield*/, (0, magicast_1.loadFile)(hooksFile)];
204
+ case 1:
205
+ originalHooksMod = _a.sent();
206
+ if (hasSentryContent(path.basename(hooksFile), originalHooksMod.$code)) {
207
+ // We don't want to mess with files that already have Sentry content.
208
+ // Let's just bail out at this point.
209
+ return [2 /*return*/];
210
+ }
211
+ originalHooksMod.imports.$add({
212
+ from: '@sentry/sveltekit',
213
+ imported: '*',
214
+ local: 'Sentry',
215
+ });
216
+ if (hookType === 'client') {
217
+ insertClientInitCall(dsn, originalHooksMod);
218
+ }
219
+ else {
220
+ insertServerInitCall(dsn, originalHooksMod);
221
+ }
222
+ wrapHandleError(originalHooksMod);
223
+ if (hookType === 'server') {
224
+ wrapHandle(originalHooksMod);
225
+ }
226
+ modifiedCode = originalHooksMod.generate().code;
227
+ return [4 /*yield*/, fs.promises.writeFile(hooksFile, modifiedCode)];
228
+ case 2:
229
+ _a.sent();
230
+ prompts_1.default.log.success("Added Sentry code to ".concat(hooksFile));
231
+ return [2 /*return*/];
232
+ }
233
+ });
234
+ });
235
+ }
236
+ function insertClientInitCall(dsn,
237
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
238
+ originalHooksMod) {
239
+ var initCallComment = "\n // If you don't want to use Session Replay, remove the `Replay` integration, \n // `replaysSessionSampleRate` and `replaysOnErrorSampleRate` options.";
240
+ // This assignment of any values is fine because we're just creating a function call in magicast
241
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
242
+ var initCall = magicast_1.builders.functionCall('Sentry.init', {
243
+ dsn: dsn,
244
+ tracesSampleRate: 1.0,
245
+ replaysSessionSampleRate: 0.1,
246
+ replaysOnErrorSampleRate: 1.0,
247
+ integrations: [magicast_1.builders.newExpression('Sentry.Replay')],
248
+ });
249
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
250
+ var initCallWithComment = magicast_1.builders.raw(
251
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
252
+ "".concat(initCallComment, "\n").concat((0, magicast_1.generateCode)(initCall).code));
253
+ var originalHooksModAST = originalHooksMod.$ast;
254
+ var initCallInsertionIndex = getInitCallInsertionIndex(originalHooksModAST);
255
+ originalHooksModAST.body.splice(initCallInsertionIndex, 0,
256
+ // @ts-ignore - string works here because the AST is proxified by magicast
257
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
258
+ (0, magicast_1.generateCode)(initCallWithComment).code);
259
+ }
260
+ function insertServerInitCall(dsn,
261
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
262
+ originalHooksMod) {
263
+ // This assignment of any values is fine because we're just creating a function call in magicast
264
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
265
+ var initCall = magicast_1.builders.functionCall('Sentry.init', {
266
+ dsn: dsn,
267
+ tracesSampleRate: 1.0,
268
+ });
269
+ var originalHooksModAST = originalHooksMod.$ast;
270
+ var initCallInsertionIndex = getInitCallInsertionIndex(originalHooksModAST);
271
+ originalHooksModAST.body.splice(initCallInsertionIndex, 0,
272
+ // @ts-ignore - string works here because the AST is proxified by magicast
273
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
274
+ (0, magicast_1.generateCode)(initCall).code);
275
+ }
276
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
277
+ function wrapHandleError(mod) {
278
+ var modAst = mod.exports.$ast;
279
+ var namedExports = modAst.body.filter(function (node) { return node.type === 'ExportNamedDeclaration'; });
280
+ var foundHandleError = false;
281
+ namedExports.forEach(function (modExport) {
282
+ var declaration = modExport.declaration;
283
+ if (!declaration) {
284
+ return;
285
+ }
286
+ if (declaration.type === 'FunctionDeclaration') {
287
+ if (!declaration.id || declaration.id.name !== 'handleError') {
288
+ return;
289
+ }
290
+ foundHandleError = true;
291
+ var userCode = (0, magicast_1.generateCode)(declaration).code;
292
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
293
+ mod.exports.handleError = magicast_1.builders.raw("Sentry.handleErrorWithSentry(".concat(userCode.replace('handleError', '_handleError'), ")"));
294
+ // because magicast doesn't overwrite the original function export, we need to remove it manually
295
+ modAst.body = modAst.body.filter(function (node) { return node !== modExport; });
296
+ }
297
+ else if (declaration.type === 'VariableDeclaration') {
298
+ var declarations = declaration.declarations;
299
+ declarations.forEach(function (declaration) {
300
+ // @ts-ignore - id should always have a name in this case
301
+ if (!declaration.id || declaration.id.name !== 'handleError') {
302
+ return;
303
+ }
304
+ foundHandleError = true;
305
+ var userCode = declaration.init;
306
+ var stringifiedUserCode = userCode ? (0, magicast_1.generateCode)(userCode).code : '';
307
+ // @ts-ignore - we can just place a string here, magicast will convert it to a node
308
+ declaration.init = "Sentry.handleErrorWithSentry(".concat(stringifiedUserCode, ")");
309
+ });
310
+ }
311
+ });
312
+ if (!foundHandleError) {
313
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
314
+ mod.exports.handleError = magicast_1.builders.functionCall('Sentry.handleErrorWithSentry');
315
+ }
316
+ }
317
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
318
+ function wrapHandle(mod) {
319
+ var modAst = mod.exports.$ast;
320
+ var namedExports = modAst.body.filter(function (node) { return node.type === 'ExportNamedDeclaration'; });
321
+ var foundHandle = false;
322
+ namedExports.forEach(function (modExport) {
323
+ var declaration = modExport.declaration;
324
+ if (!declaration) {
325
+ return;
326
+ }
327
+ if (declaration.type === 'FunctionDeclaration') {
328
+ if (!declaration.id || declaration.id.name !== 'handle') {
329
+ return;
330
+ }
331
+ foundHandle = true;
332
+ var userCode = (0, magicast_1.generateCode)(declaration).code;
333
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
334
+ mod.exports.handle = magicast_1.builders.raw("sequence(Sentry.sentryHandle(), ".concat(userCode.replace('handle', '_handle'), ")"));
335
+ // because of an issue with magicast, we need to remove the original export
336
+ modAst.body = modAst.body.filter(function (node) { return node !== modExport; });
337
+ }
338
+ else if (declaration.type === 'VariableDeclaration') {
339
+ var declarations = declaration.declarations;
340
+ declarations.forEach(function (declaration) {
341
+ // @ts-ignore - id should always have a name in this case
342
+ if (!declaration.id || declaration.id.name !== 'handle') {
343
+ return;
344
+ }
345
+ var userCode = declaration.init;
346
+ var stringifiedUserCode = userCode ? (0, magicast_1.generateCode)(userCode).code : '';
347
+ // @ts-ignore - we can just place a string here, magicast will convert it to a node
348
+ declaration.init = "sequence(Sentry.sentryHandle(), ".concat(stringifiedUserCode, ")");
349
+ foundHandle = true;
350
+ });
351
+ }
352
+ });
353
+ if (!foundHandle) {
354
+ // can't use builders.functionCall here because it doesn't yet
355
+ // support member expressions (Sentry.sentryHandle()) in args
356
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
357
+ mod.exports.handle = magicast_1.builders.raw('sequence(Sentry.sentryHandle())');
358
+ }
359
+ try {
360
+ mod.imports.$add({
361
+ from: '@sveltejs/kit/hooks',
362
+ imported: 'sequence',
363
+ local: 'sequence',
364
+ });
365
+ }
366
+ catch (_) {
367
+ // It's possible sequence is already imported. in this case, magicast throws but that's fine.
368
+ }
369
+ }
370
+ /** Checks if the Sentry SvelteKit SDK is already mentioned in the file */
371
+ function hasSentryContent(fileName, fileContent) {
372
+ if (fileContent.includes('@sentry/sveltekit')) {
373
+ prompts_1.default.log.warn("File ".concat(chalk_1.default.cyan(path.basename(fileName)), " already contains Sentry code.\nSkipping adding Sentry functionality to ").concat(chalk_1.default.cyan(path.basename(fileName)), "."));
374
+ return true;
375
+ }
376
+ return false;
377
+ }
378
+ function loadSvelteConfig() {
379
+ return __awaiter(this, void 0, void 0, function () {
380
+ var configFilePath, configUrl, svelteConfigModule, e_1;
381
+ return __generator(this, function (_a) {
382
+ switch (_a.label) {
383
+ case 0:
384
+ configFilePath = path.join(process.cwd(), SVELTE_CONFIG_FILE);
385
+ _a.label = 1;
386
+ case 1:
387
+ _a.trys.push([1, 3, , 4]);
388
+ if (!fs.existsSync(configFilePath)) {
389
+ return [2 /*return*/, {}];
390
+ }
391
+ configUrl = url.pathToFileURL(configFilePath).href;
392
+ return [4 /*yield*/, import(configUrl)];
393
+ case 2:
394
+ svelteConfigModule = (_a.sent());
395
+ return [2 /*return*/, (svelteConfigModule === null || svelteConfigModule === void 0 ? void 0 : svelteConfigModule.default) || {}];
396
+ case 3:
397
+ e_1 = _a.sent();
398
+ prompts_1.default.log.error("Couldn't load ".concat(SVELTE_CONFIG_FILE, ".\nPlease make sure, you're running this wizard with Node 16 or newer"));
399
+ prompts_1.default.log.info(chalk_1.default.dim(typeof e_1 === 'object' && e_1 != null && 'toString' in e_1
400
+ ? e_1.toString()
401
+ : typeof e_1 === 'string'
402
+ ? e_1
403
+ : 'Unknown error'));
404
+ return [2 /*return*/, {}];
405
+ case 4: return [2 /*return*/];
406
+ }
407
+ });
408
+ });
409
+ }
410
+ exports.loadSvelteConfig = loadSvelteConfig;
411
+ function modifyViteConfig(viteConfigPath) {
412
+ return __awaiter(this, void 0, void 0, function () {
413
+ var viteConfigContent, viteModule, code;
414
+ return __generator(this, function (_a) {
415
+ switch (_a.label) {
416
+ case 0: return [4 /*yield*/, fs.promises.readFile(viteConfigPath, 'utf-8')];
417
+ case 1:
418
+ viteConfigContent = (_a.sent()).toString();
419
+ if (hasSentryContent(viteConfigPath, viteConfigContent)) {
420
+ return [2 /*return*/];
421
+ }
422
+ viteModule = (0, magicast_1.parseModule)(viteConfigContent);
423
+ (0, helpers_1.addVitePlugin)(viteModule, {
424
+ imported: 'sentrySvelteKit',
425
+ from: '@sentry/sveltekit',
426
+ constructor: 'sentrySvelteKit',
427
+ index: 0,
428
+ });
429
+ code = (0, magicast_1.generateCode)(viteModule.$ast).code;
430
+ return [4 /*yield*/, fs.promises.writeFile(viteConfigPath, code)];
431
+ case 2:
432
+ _a.sent();
433
+ return [2 /*return*/];
434
+ }
435
+ });
436
+ });
437
+ }
438
+ /**
439
+ * We want to insert the init call on top of the file but after all import statements
440
+ */
441
+ function getInitCallInsertionIndex(originalHooksModAST) {
442
+ // We need to deep-copy here because reverse mutates in place
443
+ var copiedBodyNodes = __spreadArray([], originalHooksModAST.body, true);
444
+ var lastImportDeclaration = copiedBodyNodes
445
+ .reverse()
446
+ .find(function (node) { return node.type === 'ImportDeclaration'; });
447
+ var initCallInsertionIndex = lastImportDeclaration
448
+ ? originalHooksModAST.body.indexOf(lastImportDeclaration) + 1
449
+ : 0;
450
+ return initCallInsertionIndex;
451
+ }
452
+ //# sourceMappingURL=sdk-setup.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sdk-setup.js","sourceRoot":"","sources":["../../../src/sveltekit/sdk-setup.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,qCAAyB;AACzB,yCAA6B;AAC7B,uCAA2B;AAC3B,gDAA0B;AAE1B,yEAAyE;AACzE,2DAAmC;AAGnC,4EAA4E;AAC5E,qCAAyE;AACzE,4EAA4E;AAC5E,4CAAiD;AACjD,wEAG0C;AAE1C,IAAM,kBAAkB,GAAG,kBAAkB,CAAC;AAc9C,SAAsB,2BAA2B,CAC/C,GAAW,EACX,YAAiC;;;;;;oBAE3B,KAAuC,kBAAkB,CAAC,YAAY,CAAC,EAArE,eAAe,qBAAA,EAAE,eAAe,qBAAA,CAAsC;oBAGxE,uBAAuB,GAAG,aAAa,CAAC,eAAe,CAAC,CAAC;oBACzD,uBAAuB,GAAG,aAAa,CAAC,eAAe,CAAC,CAAC;oBAEzD,UAAU,GAAG,aAAa,CAAC,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,aAAa,CAAC,CAAC,CAAC;yBAEzE,CAAC,uBAAuB,EAAxB,wBAAwB;oBAC1B,iBAAK,CAAC,GAAG,CAAC,IAAI,CAAC,iDAAiD,CAAC,CAAC;oBAClE,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AC;QAC7D,CAAC,CAAC,CAAC,CAAC;IACN,OAAO,sBAAsB,CAAC;AAChC,CAAC","sourcesContent":["import type { ExportNamedDeclaration, Program } from '@babel/types';\nimport * as fs from 'fs';\nimport * as path from 'path';\nimport * as url from 'url';\nimport chalk from 'chalk';\n\n// @ts-ignore - clack is ESM and TS complains about that. It works though\nimport clack from '@clack/prompts';\n// @ts-ignore - magicast is ESM and TS complains about that. It works though\nimport type { ProxifiedModule } from 'magicast';\n// @ts-ignore - magicast is ESM and TS complains about that. It works though\nimport { builders, generateCode, loadFile, parseModule } from 'magicast';\n// @ts-ignore - magicast is ESM and TS complains about that. It works though\nimport { addVitePlugin } from 'magicast/helpers';\nimport {\n getClientHooksTemplate,\n getServerHooksTemplate,\n} from '../templates/sveltekit-templates';\n\nconst SVELTE_CONFIG_FILE = 'svelte.config.js';\n\nexport type PartialSvelteConfig = {\n kit?: {\n files?: {\n hooks?: {\n client?: string;\n server?: string;\n };\n routes?: string;\n };\n };\n};\n\nexport async function createOrMergeSvelteKitFiles(\n dsn: string,\n svelteConfig: PartialSvelteConfig,\n): Promise<void> {\n const { clientHooksPath, serverHooksPath } = getHooksConfigDirs(svelteConfig);\n\n // full file paths with correct file ending (or undefined if not found)\n const originalClientHooksFile = findHooksFile(clientHooksPath);\n const originalServerHooksFile = findHooksFile(serverHooksPath);\n\n const viteConfig = findHooksFile(path.resolve(process.cwd(), 'vite.config'));\n\n if (!originalClientHooksFile) {\n clack.log.info('No client hooks file found, creating a new one.');\n await createNewHooksFile(`${clientHooksPath}.js`, 'client', dsn);\n }\n if (!originalServerHooksFile) {\n clack.log.info('No server hooks file found, creating a new one.');\n await createNewHooksFile(`${serverHooksPath}.js`, 'client', dsn);\n }\n\n if (originalClientHooksFile) {\n await mergeHooksFile(originalClientHooksFile, 'client', dsn);\n }\n if (originalServerHooksFile) {\n await mergeHooksFile(originalServerHooksFile, 'server', dsn);\n }\n\n if (viteConfig) {\n await modifyViteConfig(viteConfig);\n }\n}\n\n/**\n * Attempts to read the svelte.config.js file to find the location of the hooks files.\n * If users specified a custom location, we'll use that. Otherwise, we'll use the default.\n */\nfunction getHooksConfigDirs(svelteConfig: PartialSvelteConfig): {\n clientHooksPath: string;\n serverHooksPath: string;\n} {\n const relativeUserClientHooksPath = svelteConfig?.kit?.files?.hooks?.client;\n const relativeUserServerHooksPath = svelteConfig?.kit?.files?.hooks?.server;\n const userClientHooksPath =\n relativeUserClientHooksPath &&\n path.resolve(process.cwd(), relativeUserClientHooksPath);\n const userServerHooksPath =\n relativeUserServerHooksPath &&\n path.resolve(process.cwd(), relativeUserServerHooksPath);\n\n const defaulHooksDir = path.resolve(process.cwd(), 'src');\n const defaultClientHooksPath = path.resolve(defaulHooksDir, 'hooks.client'); // file ending missing on purpose\n const defaultServerHooksPath = path.resolve(defaulHooksDir, 'hooks.server'); // same here\n\n return {\n clientHooksPath: userClientHooksPath || defaultClientHooksPath,\n serverHooksPath: userServerHooksPath || defaultServerHooksPath,\n };\n}\n\n/**\n * Checks if a hooks file exists and returns the full path to the file with the correct file type.\n */\nfunction findHooksFile(hooksFile: string): string | undefined {\n const possibleFileTypes = ['.js', '.ts', '.mjs'];\n return possibleFileTypes\n .map((type) => `${hooksFile}${type}`)\n .find((file) => fs.existsSync(file));\n}\n\n/**\n * Reads the template, replaces the dsn placeholder with the actual dsn and writes the file to @param hooksFileDest\n */\nasync function createNewHooksFile(\n hooksFileDest: string,\n hooktype: 'client' | 'server',\n dsn: string,\n): Promise<void> {\n const filledTemplate =\n hooktype === 'client'\n ? getClientHooksTemplate(dsn)\n : getServerHooksTemplate(dsn);\n\n await fs.promises.mkdir(path.dirname(hooksFileDest), { recursive: true });\n await fs.promises.writeFile(hooksFileDest, filledTemplate);\n\n clack.log.success(`Created ${hooksFileDest}`);\n}\n\n/**\n * Merges the users' hooks file with Sentry-related code.\n *\n * Both hooks:\n * - add import * as Sentry\n * - add Sentry.init\n * - add handleError hook wrapper\n *\n * Additionally in Server hook:\n * - add handle hook handler\n */\nasync function mergeHooksFile(\n hooksFile: string,\n hookType: 'client' | 'server',\n dsn: string,\n): Promise<void> {\n const originalHooksMod = await loadFile(hooksFile);\n if (hasSentryContent(path.basename(hooksFile), originalHooksMod.$code)) {\n // We don't want to mess with files that already have Sentry content.\n // Let's just bail out at this point.\n return;\n }\n\n originalHooksMod.imports.$add({\n from: '@sentry/sveltekit',\n imported: '*',\n local: 'Sentry',\n });\n\n if (hookType === 'client') {\n insertClientInitCall(dsn, originalHooksMod);\n } else {\n insertServerInitCall(dsn, originalHooksMod);\n }\n\n wrapHandleError(originalHooksMod);\n\n if (hookType === 'server') {\n wrapHandle(originalHooksMod);\n }\n\n const modifiedCode = originalHooksMod.generate().code;\n\n await fs.promises.writeFile(hooksFile, modifiedCode);\n\n clack.log.success(`Added Sentry code to ${hooksFile}`);\n}\n\nfunction insertClientInitCall(\n dsn: string,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n originalHooksMod: ProxifiedModule<any>,\n): void {\n const initCallComment = `\n // If you don't want to use Session Replay, remove the \\`Replay\\` integration, \n // \\`replaysSessionSampleRate\\` and \\`replaysOnErrorSampleRate\\` options.`;\n\n // This assignment of any values is fine because we're just creating a function call in magicast\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\n const initCall = builders.functionCall('Sentry.init', {\n dsn,\n tracesSampleRate: 1.0,\n replaysSessionSampleRate: 0.1,\n replaysOnErrorSampleRate: 1.0,\n integrations: [builders.newExpression('Sentry.Replay')],\n });\n\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\n const initCallWithComment = builders.raw(\n // eslint-disable-next-line @typescript-eslint/no-unsafe-argument\n `${initCallComment}\\n${generateCode(initCall).code}`,\n );\n\n const originalHooksModAST = originalHooksMod.$ast as Program;\n\n const initCallInsertionIndex = getInitCallInsertionIndex(originalHooksModAST);\n\n originalHooksModAST.body.splice(\n initCallInsertionIndex,\n 0,\n // @ts-ignore - string works here because the AST is proxified by magicast\n // eslint-disable-next-line @typescript-eslint/no-unsafe-argument\n generateCode(initCallWithComment).code,\n );\n}\n\nfunction insertServerInitCall(\n dsn: string,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n originalHooksMod: ProxifiedModule<any>,\n): void {\n // This assignment of any values is fine because we're just creating a function call in magicast\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\n const initCall = builders.functionCall('Sentry.init', {\n dsn,\n tracesSampleRate: 1.0,\n });\n\n const originalHooksModAST = originalHooksMod.$ast as Program;\n\n const initCallInsertionIndex = getInitCallInsertionIndex(originalHooksModAST);\n\n originalHooksModAST.body.splice(\n initCallInsertionIndex,\n 0,\n // @ts-ignore - string works here because the AST is proxified by magicast\n // eslint-disable-next-line @typescript-eslint/no-unsafe-argument\n generateCode(initCall).code,\n );\n}\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nfunction wrapHandleError(mod: ProxifiedModule<any>): void {\n const modAst = mod.exports.$ast as Program;\n const namedExports = modAst.body.filter(\n (node) => node.type === 'ExportNamedDeclaration',\n ) as ExportNamedDeclaration[];\n\n let foundHandleError = false;\n\n namedExports.forEach((modExport) => {\n const declaration = modExport.declaration;\n if (!declaration) {\n return;\n }\n if (declaration.type === 'FunctionDeclaration') {\n if (!declaration.id || declaration.id.name !== 'handleError') {\n return;\n }\n foundHandleError = true;\n const userCode = generateCode(declaration).code;\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\n mod.exports.handleError = builders.raw(\n `Sentry.handleErrorWithSentry(${userCode.replace(\n 'handleError',\n '_handleError',\n )})`,\n );\n // because magicast doesn't overwrite the original function export, we need to remove it manually\n modAst.body = modAst.body.filter((node) => node !== modExport);\n } else if (declaration.type === 'VariableDeclaration') {\n const declarations = declaration.declarations;\n declarations.forEach((declaration) => {\n // @ts-ignore - id should always have a name in this case\n if (!declaration.id || declaration.id.name !== 'handleError') {\n return;\n }\n foundHandleError = true;\n const userCode = declaration.init;\n const stringifiedUserCode = userCode ? generateCode(userCode).code : '';\n // @ts-ignore - we can just place a string here, magicast will convert it to a node\n declaration.init = `Sentry.handleErrorWithSentry(${stringifiedUserCode})`;\n });\n }\n });\n\n if (!foundHandleError) {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\n mod.exports.handleError = builders.functionCall(\n 'Sentry.handleErrorWithSentry',\n );\n }\n}\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nfunction wrapHandle(mod: ProxifiedModule<any>): void {\n const modAst = mod.exports.$ast as Program;\n const namedExports = modAst.body.filter(\n (node) => node.type === 'ExportNamedDeclaration',\n ) as ExportNamedDeclaration[];\n\n let foundHandle = false;\n\n namedExports.forEach((modExport) => {\n const declaration = modExport.declaration;\n if (!declaration) {\n return;\n }\n if (declaration.type === 'FunctionDeclaration') {\n if (!declaration.id || declaration.id.name !== 'handle') {\n return;\n }\n foundHandle = true;\n const userCode = generateCode(declaration).code;\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\n mod.exports.handle = builders.raw(\n `sequence(Sentry.sentryHandle(), ${userCode.replace(\n 'handle',\n '_handle',\n )})`,\n );\n // because of an issue with magicast, we need to remove the original export\n modAst.body = modAst.body.filter((node) => node !== modExport);\n } else if (declaration.type === 'VariableDeclaration') {\n const declarations = declaration.declarations;\n declarations.forEach((declaration) => {\n // @ts-ignore - id should always have a name in this case\n if (!declaration.id || declaration.id.name !== 'handle') {\n return;\n }\n const userCode = declaration.init;\n const stringifiedUserCode = userCode ? generateCode(userCode).code : '';\n // @ts-ignore - we can just place a string here, magicast will convert it to a node\n declaration.init = `sequence(Sentry.sentryHandle(), ${stringifiedUserCode})`;\n foundHandle = true;\n });\n }\n });\n\n if (!foundHandle) {\n // can't use builders.functionCall here because it doesn't yet\n // support member expressions (Sentry.sentryHandle()) in args\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\n mod.exports.handle = builders.raw('sequence(Sentry.sentryHandle())');\n }\n\n try {\n mod.imports.$add({\n from: '@sveltejs/kit/hooks',\n imported: 'sequence',\n local: 'sequence',\n });\n } catch (_) {\n // It's possible sequence is already imported. in this case, magicast throws but that's fine.\n }\n}\n\n/** Checks if the Sentry SvelteKit SDK is already mentioned in the file */\nfunction hasSentryContent(fileName: string, fileContent: string): boolean {\n if (fileContent.includes('@sentry/sveltekit')) {\n clack.log.warn(\n `File ${chalk.cyan(path.basename(fileName))} already contains Sentry code.\nSkipping adding Sentry functionality to ${chalk.cyan(\n path.basename(fileName),\n )}.`,\n );\n return true;\n }\n return false;\n}\n\nexport async function loadSvelteConfig(): Promise<PartialSvelteConfig> {\n const configFilePath = path.join(process.cwd(), SVELTE_CONFIG_FILE);\n\n try {\n if (!fs.existsSync(configFilePath)) {\n return {};\n }\n\n const configUrl = url.pathToFileURL(configFilePath).href;\n const svelteConfigModule = (await import(configUrl)) as {\n default: PartialSvelteConfig;\n };\n\n return svelteConfigModule?.default || {};\n } catch (e: unknown) {\n clack.log.error(`Couldn't load ${SVELTE_CONFIG_FILE}.\nPlease make sure, you're running this wizard with Node 16 or newer`);\n clack.log.info(\n chalk.dim(\n typeof e === 'object' && e != null && 'toString' in e\n ? e.toString()\n : typeof e === 'string'\n ? e\n : 'Unknown error',\n ),\n );\n\n return {};\n }\n}\n\nasync function modifyViteConfig(viteConfigPath: string): Promise<void> {\n const viteConfigContent = (\n await fs.promises.readFile(viteConfigPath, 'utf-8')\n ).toString();\n\n if (hasSentryContent(viteConfigPath, viteConfigContent)) {\n return;\n }\n\n const viteModule = parseModule(viteConfigContent);\n\n addVitePlugin(viteModule, {\n imported: 'sentrySvelteKit',\n from: '@sentry/sveltekit',\n constructor: 'sentrySvelteKit',\n index: 0,\n });\n\n const code = generateCode(viteModule.$ast).code;\n await fs.promises.writeFile(viteConfigPath, code);\n}\n\n/**\n * We want to insert the init call on top of the file but after all import statements\n */\nfunction getInitCallInsertionIndex(originalHooksModAST: Program): number {\n // We need to deep-copy here because reverse mutates in place\n const copiedBodyNodes = [...originalHooksModAST.body];\n const lastImportDeclaration = copiedBodyNodes\n .reverse()\n .find((node) => node.type === 'ImportDeclaration');\n\n const initCallInsertionIndex = lastImportDeclaration\n ? originalHooksModAST.body.indexOf(lastImportDeclaration) + 1\n : 0;\n return initCallInsertionIndex;\n}\n"]}
@@ -0,0 +1,2 @@
1
+ import { SentryProjectData } from '../utils/clack-utils';
2
+ export declare function setupCLIConfig(authToken: string, selectedProject: SentryProjectData, sentryUrl: string): Promise<void>;
@@ -0,0 +1,71 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __generator = (this && this.__generator) || function (thisArg, body) {
12
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
+ function verb(n) { return function (v) { return step([n, v]); }; }
15
+ function step(op) {
16
+ if (f) throw new TypeError("Generator is already executing.");
17
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
18
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
+ if (y = 0, t) op = [op[0] & 2, t.value];
20
+ switch (op[0]) {
21
+ case 0: case 1: t = op; break;
22
+ case 4: _.label++; return { value: op[1], done: false };
23
+ case 5: _.label++; y = op[1]; op = [0]; continue;
24
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
+ default:
26
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
+ if (t[2]) _.ops.pop();
31
+ _.trys.pop(); continue;
32
+ }
33
+ op = body.call(thisArg, _);
34
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
+ }
37
+ };
38
+ Object.defineProperty(exports, "__esModule", { value: true });
39
+ exports.setupCLIConfig = void 0;
40
+ var SentryCli_1 = require("../../lib/Helper/SentryCli");
41
+ function setupCLIConfig(authToken, selectedProject, sentryUrl) {
42
+ return __awaiter(this, void 0, void 0, function () {
43
+ var cli, answers, props;
44
+ return __generator(this, function (_a) {
45
+ switch (_a.label) {
46
+ case 0:
47
+ cli = new SentryCli_1.SentryCli({ url: sentryUrl });
48
+ answers = {
49
+ config: {
50
+ organization: {
51
+ slug: selectedProject.organization.slug,
52
+ },
53
+ project: {
54
+ slug: selectedProject.slug,
55
+ },
56
+ auth: {
57
+ token: authToken,
58
+ },
59
+ },
60
+ };
61
+ props = cli.convertAnswersToProperties(answers);
62
+ return [4 /*yield*/, cli.createSentryCliConfig(props)];
63
+ case 1:
64
+ _a.sent();
65
+ return [2 /*return*/];
66
+ }
67
+ });
68
+ });
69
+ }
70
+ exports.setupCLIConfig = setupCLIConfig;
71
+ //# sourceMappingURL=sentry-cli-setup.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sentry-cli-setup.js","sourceRoot":"","sources":["../../../src/sveltekit/sentry-cli-setup.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,wDAAuD;AAGvD,SAAsB,cAAc,CAClC,SAAiB,EACjB,eAAkC,EAClC,SAAiB;;;;;;oBAEX,GAAG,GAAG,IAAI,qBAAS,CAAC,EAAE,GAAG,EAAE,SAAS,EAAU,CAAC,CAAC;oBAEhD,OAAO,GAAG;wBACd,MAAM,EAAE;4BACN,YAAY,EAAE;gCACZ,IAAI,EAAE,eAAe,CAAC,YAAY,CAAC,IAAI;6BACxC;4BACD,OAAO,EAAE;gCACP,IAAI,EAAE,eAAe,CAAC,IAAI;6BAC3B;4BACD,IAAI,EAAE;gCACJ,KAAK,EAAE,SAAS;6BACjB;yBACF;qBACF,CAAC;oBACI,KAAK,GAAG,GAAG,CAAC,0BAA0B,CAAC,OAAO,CAAC,CAAC;oBACtD,qBAAM,GAAG,CAAC,qBAAqB,CAAC,KAAK,CAAC,EAAA;;oBAAtC,SAAsC,CAAC;;;;;CACxC;AAtBD,wCAsBC","sourcesContent":["import { Args } from '../../lib/Constants';\nimport { SentryCli } from '../../lib/Helper/SentryCli';\nimport { SentryProjectData } from '../utils/clack-utils';\n\nexport async function setupCLIConfig(\n authToken: string,\n selectedProject: SentryProjectData,\n sentryUrl: string,\n): Promise<void> {\n const cli = new SentryCli({ url: sentryUrl } as Args);\n\n const answers = {\n config: {\n organization: {\n slug: selectedProject.organization.slug,\n },\n project: {\n slug: selectedProject.slug,\n },\n auth: {\n token: authToken,\n },\n },\n };\n const props = cli.convertAnswersToProperties(answers);\n await cli.createSentryCliConfig(props);\n}\n"]}
@@ -0,0 +1,5 @@
1
+ interface SvelteKitWizardOptions {
2
+ promoCode?: string;
3
+ }
4
+ export declare function runSvelteKitWizard(options: SvelteKitWizardOptions): Promise<void>;
5
+ export {};