@sentry/wizard 3.13.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 (40) hide show
  1. package/CHANGELOG.md +7 -1
  2. package/dist/package.json +2 -2
  3. package/dist/src/android/android-wizard.js +2 -4
  4. package/dist/src/android/android-wizard.js.map +1 -1
  5. package/dist/src/apple/apple-wizard.js +1 -1
  6. package/dist/src/apple/apple-wizard.js.map +1 -1
  7. package/dist/src/nextjs/nextjs-wizard.d.ts +1 -0
  8. package/dist/src/nextjs/nextjs-wizard.js +252 -161
  9. package/dist/src/nextjs/nextjs-wizard.js.map +1 -1
  10. package/dist/src/nextjs/utils.d.ts +1 -0
  11. package/dist/src/nextjs/utils.js +25 -0
  12. package/dist/src/nextjs/utils.js.map +1 -0
  13. package/dist/src/remix/remix-wizard.js +5 -7
  14. package/dist/src/remix/remix-wizard.js.map +1 -1
  15. package/dist/src/remix/sdk-setup.js +10 -4
  16. package/dist/src/remix/sdk-setup.js.map +1 -1
  17. package/dist/src/sourcemaps/sourcemaps-wizard.js +1 -1
  18. package/dist/src/sourcemaps/sourcemaps-wizard.js.map +1 -1
  19. package/dist/src/sveltekit/sveltekit-wizard.js +6 -10
  20. package/dist/src/sveltekit/sveltekit-wizard.js.map +1 -1
  21. package/dist/src/telemetry.d.ts +1 -0
  22. package/dist/src/telemetry.js +27 -12
  23. package/dist/src/telemetry.js.map +1 -1
  24. package/dist/src/utils/clack-utils.d.ts +11 -1
  25. package/dist/src/utils/clack-utils.js +190 -126
  26. package/dist/src/utils/clack-utils.js.map +1 -1
  27. package/dist/src/utils/package-manager.js +12 -7
  28. package/dist/src/utils/package-manager.js.map +1 -1
  29. package/package.json +2 -2
  30. package/src/android/android-wizard.ts +4 -5
  31. package/src/apple/apple-wizard.ts +2 -2
  32. package/src/nextjs/nextjs-wizard.ts +262 -195
  33. package/src/nextjs/utils.ts +21 -0
  34. package/src/remix/remix-wizard.ts +7 -9
  35. package/src/remix/sdk-setup.ts +12 -3
  36. package/src/sourcemaps/sourcemaps-wizard.ts +2 -2
  37. package/src/sveltekit/sveltekit-wizard.ts +9 -12
  38. package/src/telemetry.ts +22 -11
  39. package/src/utils/clack-utils.ts +177 -107
  40. package/src/utils/package-manager.ts +12 -6
@@ -39,38 +39,48 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
39
39
  return (mod && mod.__esModule) ? mod : { "default": mod };
40
40
  };
41
41
  Object.defineProperty(exports, "__esModule", { value: true });
42
- exports.traceStep = exports.withTelemetry = void 0;
42
+ exports.updateProgress = exports.traceStep = exports.withTelemetry = void 0;
43
43
  var node_1 = require("@sentry/node");
44
44
  var package_json_1 = __importDefault(require("../package.json"));
45
45
  function withTelemetry(options, callback) {
46
46
  return __awaiter(this, void 0, void 0, function () {
47
- var _a, sentryHub, sentryClient, transaction, sentrySession, e_1;
47
+ var _a, sentryHub, sentryClient, sentrySession, e_1;
48
+ var _this = this;
48
49
  return __generator(this, function (_b) {
49
50
  switch (_b.label) {
50
51
  case 0:
51
52
  _a = createSentryInstance(options.enabled, options.integration), sentryHub = _a.sentryHub, sentryClient = _a.sentryClient;
52
53
  (0, node_1.makeMain)(sentryHub);
53
- transaction = sentryHub.startTransaction({
54
- name: 'sentry-wizard-execution',
55
- status: 'ok',
56
- op: 'wizard.flow',
57
- });
58
- sentryHub.getScope().setSpan(transaction);
59
54
  sentrySession = sentryHub.startSession();
60
55
  sentryHub.captureSession();
61
56
  _b.label = 1;
62
57
  case 1:
63
58
  _b.trys.push([1, 3, 4, 6]);
64
- return [4 /*yield*/, (0, node_1.runWithAsyncContext)(function () { return callback(); })];
59
+ return [4 /*yield*/, (0, node_1.startSpan)({
60
+ name: 'sentry-wizard-execution',
61
+ status: 'ok',
62
+ op: 'wizard.flow',
63
+ }, function () { return __awaiter(_this, void 0, void 0, function () {
64
+ var res;
65
+ return __generator(this, function (_a) {
66
+ switch (_a.label) {
67
+ case 0:
68
+ updateProgress('start');
69
+ return [4 /*yield*/, (0, node_1.runWithAsyncContext)(callback)];
70
+ case 1:
71
+ res = _a.sent();
72
+ updateProgress('finished');
73
+ return [2 /*return*/, res];
74
+ }
75
+ });
76
+ }); })];
65
77
  case 2: return [2 /*return*/, _b.sent()];
66
78
  case 3:
67
79
  e_1 = _b.sent();
68
80
  sentryHub.captureException('Error during wizard execution.');
69
- transaction.setStatus('internal_error');
70
81
  sentrySession.status = 'crashed';
71
82
  throw e_1;
72
83
  case 4:
73
- transaction.finish();
74
84
  sentryHub.endSession();
75
85
  return [4 /*yield*/, sentryClient.flush(3000)];
76
86
  case 5:
@@ -115,7 +125,12 @@ function createSentryInstance(enabled, integration) {
115
125
  return { sentryHub: hub, sentryClient: client };
116
126
  }
117
127
  function traceStep(step, callback) {
118
- return (0, node_1.trace)({ name: step, op: 'wizard.step' }, function () { return callback(); });
128
+ updateProgress(step);
129
+ return (0, node_1.startSpan)({ name: step, op: 'wizard.step' }, function () { return callback(); });
119
130
  }
120
131
  exports.traceStep = traceStep;
132
+ function updateProgress(step) {
133
+ (0, node_1.setTag)('progress', step);
134
+ }
135
+ exports.updateProgress = updateProgress;
121
136
  //# sourceMappingURL=telemetry.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"telemetry.js","sourceRoot":"","sources":["../../src/telemetry.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,qCASsB;AACtB,iEAA0C;AAE1C,SAAsB,aAAa,CACjC,OAGC,EACD,QAA8B;;;;;;oBAExB,KAA8B,oBAAoB,CACtD,OAAO,CAAC,OAAO,EACf,OAAO,CAAC,WAAW,CACpB,EAHO,SAAS,eAAA,EAAE,YAAY,kBAAA,CAG7B;oBAEF,IAAA,eAAQ,EAAC,SAAS,CAAC,CAAC;oBAEd,WAAW,GAAG,SAAS,CAAC,gBAAgB,CAAC;wBAC7C,IAAI,EAAE,yBAAyB;wBAC/B,MAAM,EAAE,IAAI;wBACZ,EAAE,EAAE,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,CAAC,SAAS,0CAAE,MAAM,0CAAE,OAAO,CAAC,UAAC,SAAS;gBACzC,OAAO,SAAS,CAAC,UAAU,CAAC;YAC9B,CAAC,CAAC,CAAC;YAEH,OAAO,KAAK,CAAC,WAAW,CAAC,CAAC,gCAAgC;YAC1D,OAAO,KAAK,CAAC;QACf,CAAC;QAED,SAAS,EAAE,wBAAiB;QAE5B,KAAK,EAAE,IAAI;KACZ,CAAC,CAAC;IAEH,IAAM,GAAG,GAAG,IAAI,UAAG,CAAC,MAAM,CAAC,CAAC;IAE5B,GAAG,CAAC,MAAM,CAAC,aAAa,EAAE,WAAW,CAAC,CAAC;IACvC,GAAG,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,OAAO,CAAC,CAAC;IACpC,GAAG,CAAC,MAAM,CAAC,UAAU,EAAE,OAAO,CAAC,QAAQ,CAAC,CAAC;IAEzC,OAAO,EAAE,SAAS,EAAE,GAAG,EAAE,YAAY,EAAE,MAAM,EAAE,CAAC;AAClD,CAAC;AAED,SAAgB,SAAS,CAAI,IAAY,EAAE,QAAiB;IAC1D,OAAO,IAAA,YAAK,EAAC,EAAE,IAAI,EAAE,IAAI,EAAE,EAAE,EAAE,aAAa,EAAE,EAAE,cAAM,OAAA,QAAQ,EAAE,EAAV,CAAU,CAAC,CAAC;AACpE,CAAC;AAFD,8BAEC","sourcesContent":["import {\n defaultStackParser,\n Hub,\n Integrations,\n makeMain,\n makeNodeTransport,\n NodeClient,\n runWithAsyncContext,\n trace,\n} from '@sentry/node';\nimport packageJson from '../package.json';\n\nexport async function withTelemetry<F>(\n options: {\n enabled: boolean;\n integration: string;\n },\n callback: () => F | Promise<F>,\n): Promise<F> {\n const { sentryHub, sentryClient } = createSentryInstance(\n options.enabled,\n options.integration,\n );\n\n makeMain(sentryHub);\n\n const transaction = sentryHub.startTransaction({\n name: 'sentry-wizard-execution',\n status: 'ok',\n op: 'wizard.flow',\n });\n sentryHub.getScope().setSpan(transaction);\n const sentrySession = sentryHub.startSession();\n sentryHub.captureSession();\n\n try {\n return await runWithAsyncContext(() => callback());\n } catch (e) {\n sentryHub.captureException('Error during wizard execution.');\n transaction.setStatus('internal_error');\n sentrySession.status = 'crashed';\n throw e;\n } finally {\n transaction.finish();\n sentryHub.endSession();\n await sentryClient.flush(3000);\n }\n}\n\nfunction createSentryInstance(enabled: boolean, integration: string) {\n const client = new NodeClient({\n dsn: 'https://8871d3ff64814ed8960c96d1fcc98a27@o1.ingest.sentry.io/4505425820712960',\n enabled: enabled,\n\n environment: `production-${integration}`,\n\n tracesSampleRate: 1,\n sampleRate: 1,\n\n release: packageJson.version,\n integrations: [new Integrations.Http()],\n tracePropagationTargets: [/^https:\\/\\/sentry.io\\//],\n\n stackParser: defaultStackParser,\n\n beforeSendTransaction: (event) => {\n delete event.server_name; // Server name might contain PII\n return event;\n },\n\n beforeSend: (event) => {\n event.exception?.values?.forEach((exception) => {\n delete exception.stacktrace;\n });\n\n delete event.server_name; // Server name might contain PII\n return event;\n },\n\n transport: makeNodeTransport,\n\n debug: true,\n });\n\n const hub = new Hub(client);\n\n hub.setTag('integration', integration);\n hub.setTag('node', process.version);\n hub.setTag('platform', process.platform);\n\n return { sentryHub: hub, sentryClient: client };\n}\n\nexport function traceStep<T>(step: string, callback: () => T): T {\n return trace({ name: step, op: 'wizard.step' }, () => callback());\n}\n"]}
1
+ {"version":3,"file":"telemetry.js","sourceRoot":"","sources":["../../src/telemetry.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,qCAUsB;AACtB,iEAA0C;AAE1C,SAAsB,aAAa,CACjC,OAGC,EACD,QAA8B;;;;;;;oBAExB,KAA8B,oBAAoB,CACtD,OAAO,CAAC,OAAO,EACf,OAAO,CAAC,WAAW,CACpB,EAHO,SAAS,eAAA,EAAE,YAAY,kBAAA,CAG7B;oBAEF,IAAA,eAAQ,EAAC,SAAS,CAAC,CAAC;oBAEd,aAAa,GAAG,SAAS,CAAC,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AC,KAAK;;YAChB,MAAA,MAAA,KAAK,CAAC,SAAS,0CAAE,MAAM,0CAAE,OAAO,CAAC,UAAC,SAAS;gBACzC,OAAO,SAAS,CAAC,UAAU,CAAC;YAC9B,CAAC,CAAC,CAAC;YAEH,OAAO,KAAK,CAAC,WAAW,CAAC,CAAC,gCAAgC;YAC1D,OAAO,KAAK,CAAC;QACf,CAAC;QAED,SAAS,EAAE,wBAAiB;QAE5B,KAAK,EAAE,IAAI;KACZ,CAAC,CAAC;IAEH,IAAM,GAAG,GAAG,IAAI,UAAG,CAAC,MAAM,CAAC,CAAC;IAE5B,GAAG,CAAC,MAAM,CAAC,aAAa,EAAE,WAAW,CAAC,CAAC;IACvC,GAAG,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,OAAO,CAAC,CAAC;IACpC,GAAG,CAAC,MAAM,CAAC,UAAU,EAAE,OAAO,CAAC,QAAQ,CAAC,CAAC;IAEzC,OAAO,EAAE,SAAS,EAAE,GAAG,EAAE,YAAY,EAAE,MAAM,EAAE,CAAC;AAClD,CAAC;AAED,SAAgB,SAAS,CAAI,IAAY,EAAE,QAAiB;IAC1D,cAAc,CAAC,IAAI,CAAC,CAAC;IACrB,OAAO,IAAA,gBAAS,EAAC,EAAE,IAAI,EAAE,IAAI,EAAE,EAAE,EAAE,aAAa,EAAE,EAAE,cAAM,OAAA,QAAQ,EAAE,EAAV,CAAU,CAAC,CAAC;AACxE,CAAC;AAHD,8BAGC;AAED,SAAgB,cAAc,CAAC,IAAY;IACzC,IAAA,aAAM,EAAC,UAAU,EAAE,IAAI,CAAC,CAAC;AAC3B,CAAC;AAFD,wCAEC","sourcesContent":["import {\n defaultStackParser,\n Hub,\n Integrations,\n makeMain,\n makeNodeTransport,\n NodeClient,\n runWithAsyncContext,\n setTag,\n startSpan,\n} from '@sentry/node';\nimport packageJson from '../package.json';\n\nexport async function withTelemetry<F>(\n options: {\n enabled: boolean;\n integration: string;\n },\n callback: () => F | Promise<F>,\n): Promise<F> {\n const { sentryHub, sentryClient } = createSentryInstance(\n options.enabled,\n options.integration,\n );\n\n makeMain(sentryHub);\n\n const sentrySession = sentryHub.startSession();\n sentryHub.captureSession();\n\n try {\n return await startSpan(\n {\n name: 'sentry-wizard-execution',\n status: 'ok',\n op: 'wizard.flow',\n },\n async () => {\n updateProgress('start');\n const res = await runWithAsyncContext(callback);\n updateProgress('finished');\n\n return res;\n },\n );\n } catch (e) {\n sentryHub.captureException('Error during wizard execution.');\n sentrySession.status = 'crashed';\n throw e;\n } finally {\n sentryHub.endSession();\n await sentryClient.flush(3000);\n }\n}\n\nfunction createSentryInstance(enabled: boolean, integration: string) {\n const client = new NodeClient({\n dsn: 'https://8871d3ff64814ed8960c96d1fcc98a27@o1.ingest.sentry.io/4505425820712960',\n enabled: enabled,\n\n environment: `production-${integration}`,\n\n tracesSampleRate: 1,\n sampleRate: 1,\n\n release: packageJson.version,\n integrations: [new Integrations.Http()],\n tracePropagationTargets: [/^https:\\/\\/sentry.io\\//],\n\n stackParser: defaultStackParser,\n\n beforeSendTransaction: (event) => {\n delete event.server_name; // Server name might contain PII\n return event;\n },\n\n beforeSend: (event) => {\n event.exception?.values?.forEach((exception) => {\n delete exception.stacktrace;\n });\n\n delete event.server_name; // Server name might contain PII\n return event;\n },\n\n transport: makeNodeTransport,\n\n debug: true,\n });\n\n const hub = new Hub(client);\n\n hub.setTag('integration', integration);\n hub.setTag('node', process.version);\n hub.setTag('platform', process.platform);\n\n return { sentryHub: hub, sentryClient: client };\n}\n\nexport function traceStep<T>(step: string, callback: () => T): T {\n updateProgress(step);\n return startSpan({ name: step, op: 'wizard.step' }, () => callback());\n}\n\nexport function updateProgress(step: string) {\n setTag('progress', step);\n}\n"]}
@@ -20,7 +20,7 @@ export declare function printWelcome(options: {
20
20
  message?: string;
21
21
  telemetryEnabled?: boolean;
22
22
  }): void;
23
- export declare function confirmContinueEvenThoughNoGitRepo(): Promise<void>;
23
+ export declare function confirmContinueIfNoOrDirtyGitRepo(): Promise<void>;
24
24
  export declare function askToInstallSentryCLI(): Promise<boolean>;
25
25
  export declare function askForItemSelection(items: string[], message: string): Promise<{
26
26
  value: string;
@@ -33,6 +33,16 @@ export declare function installPackage({ packageName, alreadyInstalled, askBefor
33
33
  }): Promise<void>;
34
34
  export declare function addSentryCliConfig(authToken: string, setupConfig?: CliSetupConfig): Promise<void>;
35
35
  export declare function addDotEnvSentryBuildPluginFile(authToken: string): Promise<void>;
36
+ /**
37
+ * Checks if @param packageId is listed as a dependency in @param packageJson.
38
+ * If not, it will ask users if they want to continue without the package.
39
+ *
40
+ * Use this function to check if e.g. a the framework of the SDK is installed
41
+ *
42
+ * @param packageJson the package.json object
43
+ * @param packageId the npm name of the package
44
+ * @param packageName a human readable name of the package
45
+ */
36
46
  export declare function ensurePackageIsInstalled(packageJson: PackageDotJson, packageId: string, packageName: string): Promise<void>;
37
47
  export declare function getPackageDotJson(): Promise<PackageDotJson>;
38
48
  export declare function isUsingTypeScript(): boolean;
@@ -71,7 +71,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
71
71
  return (mod && mod.__esModule) ? mod : { "default": mod };
72
72
  };
73
73
  Object.defineProperty(exports, "__esModule", { value: true });
74
- exports.createNewConfigFile = exports.makeCodeSnippet = exports.showCopyPasteInstructions = exports.askForToolConfigPath = exports.getOrAskForProjectData = exports.isUsingTypeScript = exports.getPackageDotJson = exports.ensurePackageIsInstalled = exports.addDotEnvSentryBuildPluginFile = exports.addSentryCliConfig = exports.installPackage = exports.askForItemSelection = exports.askToInstallSentryCLI = exports.confirmContinueEvenThoughNoGitRepo = exports.printWelcome = exports.abortIfCancelled = exports.abort = exports.sourceMapsCliSetupConfig = exports.SENTRY_PROPERTIES_FILE = exports.SENTRY_CLI_RC_FILE = exports.SENTRY_DOT_ENV_FILE = void 0;
74
+ exports.createNewConfigFile = exports.makeCodeSnippet = exports.showCopyPasteInstructions = exports.askForToolConfigPath = exports.getOrAskForProjectData = exports.isUsingTypeScript = exports.getPackageDotJson = exports.ensurePackageIsInstalled = exports.addDotEnvSentryBuildPluginFile = exports.addSentryCliConfig = exports.installPackage = exports.askForItemSelection = exports.askToInstallSentryCLI = exports.confirmContinueIfNoOrDirtyGitRepo = exports.printWelcome = exports.abortIfCancelled = exports.abort = exports.sourceMapsCliSetupConfig = exports.SENTRY_PROPERTIES_FILE = exports.SENTRY_CLI_RC_FILE = exports.SENTRY_DOT_ENV_FILE = void 0;
75
75
  // @ts-ignore - clack is ESM and TS complains about that. It works though
76
76
  var clack = __importStar(require("@clack/prompts"));
77
77
  var axios_1 = __importDefault(require("axios"));
@@ -79,6 +79,7 @@ var chalk_1 = __importDefault(require("chalk"));
79
79
  var childProcess = __importStar(require("child_process"));
80
80
  var fs = __importStar(require("fs"));
81
81
  var path = __importStar(require("path"));
82
+ var os = __importStar(require("os"));
82
83
  var timers_1 = require("timers");
83
84
  var url_1 = require("url");
84
85
  var Sentry = __importStar(require("@sentry/node"));
@@ -188,37 +189,77 @@ function printWelcome(options) {
188
189
  clack.note(welcomeText);
189
190
  }
190
191
  exports.printWelcome = printWelcome;
191
- function confirmContinueEvenThoughNoGitRepo() {
192
+ function confirmContinueIfNoOrDirtyGitRepo() {
192
193
  return __awaiter(this, void 0, void 0, function () {
193
- var _a, continueWithoutGit;
194
- return __generator(this, function (_b) {
195
- switch (_b.label) {
196
- case 0:
197
- _b.trys.push([0, 1, , 5]);
198
- childProcess.execSync('git rev-parse --is-inside-work-tree', {
199
- stdio: 'ignore',
194
+ var _this = this;
195
+ return __generator(this, function (_a) {
196
+ return [2 /*return*/, (0, telemetry_1.traceStep)('check-git-status', function () { return __awaiter(_this, void 0, void 0, function () {
197
+ var continueWithoutGit, uncommittedOrUntrackedFiles, continueWithDirtyRepo;
198
+ return __generator(this, function (_a) {
199
+ switch (_a.label) {
200
+ case 0:
201
+ if (!!isInGitRepo()) return [3 /*break*/, 3];
202
+ return [4 /*yield*/, abortIfCancelled(clack.confirm({
203
+ message: 'You are not inside a git repository. The wizard will create and update files. Do you want to continue anyway?',
204
+ }))];
205
+ case 1:
206
+ continueWithoutGit = _a.sent();
207
+ Sentry.setTag('continue-without-git', continueWithoutGit);
208
+ if (!!continueWithoutGit) return [3 /*break*/, 3];
209
+ return [4 /*yield*/, abort(undefined, 0)];
210
+ case 2:
211
+ _a.sent();
212
+ _a.label = 3;
213
+ case 3:
214
+ uncommittedOrUntrackedFiles = getUncommittedOrUntrackedFiles();
215
+ if (!uncommittedOrUntrackedFiles.length) return [3 /*break*/, 6];
216
+ clack.log.warn("You have uncommitted or untracked files in your repo:\n\n".concat(uncommittedOrUntrackedFiles.join('\n'), "\n\nThe wizard will create and update files."));
217
+ return [4 /*yield*/, abortIfCancelled(clack.confirm({
218
+ message: 'Do you want to continue anyway?',
219
+ }))];
220
+ case 4:
221
+ continueWithDirtyRepo = _a.sent();
222
+ Sentry.setTag('continue-with-dirty-repo', continueWithDirtyRepo);
223
+ if (!!continueWithDirtyRepo) return [3 /*break*/, 6];
224
+ return [4 /*yield*/, abort(undefined, 0)];
225
+ case 5:
226
+ _a.sent();
227
+ _a.label = 6;
228
+ case 6: return [2 /*return*/];
229
+ }
200
230
  });
201
- return [3 /*break*/, 5];
202
- case 1:
203
- _a = _b.sent();
204
- return [4 /*yield*/, abortIfCancelled(clack.confirm({
205
- message: 'You are not inside a git repository. The wizard will create and update files. Do you still want to continue?',
206
- }))];
207
- case 2:
208
- continueWithoutGit = _b.sent();
209
- Sentry.setTag('continue-without-git', continueWithoutGit);
210
- if (!!continueWithoutGit) return [3 /*break*/, 4];
211
- return [4 /*yield*/, abort(undefined, 0)];
212
- case 3:
213
- _b.sent();
214
- _b.label = 4;
215
- case 4: return [3 /*break*/, 5];
216
- case 5: return [2 /*return*/];
217
- }
231
+ }); })];
218
232
  });
219
233
  });
220
234
  }
221
- exports.confirmContinueEvenThoughNoGitRepo = confirmContinueEvenThoughNoGitRepo;
235
+ exports.confirmContinueIfNoOrDirtyGitRepo = confirmContinueIfNoOrDirtyGitRepo;
236
+ function isInGitRepo() {
237
+ try {
238
+ childProcess.execSync('git rev-parse --is-inside-work-tree', {
239
+ stdio: 'ignore',
240
+ });
241
+ return true;
242
+ }
243
+ catch (_a) {
244
+ return false;
245
+ }
246
+ }
247
+ function getUncommittedOrUntrackedFiles() {
248
+ try {
249
+ var gitStatus = childProcess
250
+ .execSync('git status --porcelain=v1')
251
+ .toString();
252
+ var files = gitStatus
253
+ .split(os.EOL)
254
+ .map(function (line) { return line.trim(); })
255
+ .filter(Boolean)
256
+ .map(function (f) { return "- ".concat(f.split(/\s+/)[1]); });
257
+ return files;
258
+ }
259
+ catch (_a) {
260
+ return [];
261
+ }
262
+ }
222
263
  function askToInstallSentryCLI() {
223
264
  return __awaiter(this, void 0, void 0, function () {
224
265
  return __generator(this, function (_a) {
@@ -258,45 +299,50 @@ exports.askForItemSelection = askForItemSelection;
258
299
  function installPackage(_a) {
259
300
  var packageName = _a.packageName, alreadyInstalled = _a.alreadyInstalled, _b = _a.askBeforeUpdating, askBeforeUpdating = _b === void 0 ? true : _b;
260
301
  return __awaiter(this, void 0, void 0, function () {
261
- var shouldUpdatePackage, sdkInstallSpinner, packageManager, e_1;
302
+ var _this = this;
262
303
  return __generator(this, function (_c) {
263
- switch (_c.label) {
264
- case 0:
265
- if (!(alreadyInstalled && askBeforeUpdating)) return [3 /*break*/, 2];
266
- return [4 /*yield*/, abortIfCancelled(clack.confirm({
267
- message: "The ".concat(chalk_1.default.bold.cyan(packageName), " package is already installed. Do you want to update it to the latest version?"),
268
- }))];
269
- case 1:
270
- shouldUpdatePackage = _c.sent();
271
- if (!shouldUpdatePackage) {
272
- return [2 /*return*/];
273
- }
274
- _c.label = 2;
275
- case 2:
276
- sdkInstallSpinner = clack.spinner();
277
- return [4 /*yield*/, getPackageManager()];
278
- case 3:
279
- packageManager = _c.sent();
280
- sdkInstallSpinner.start("".concat(alreadyInstalled ? 'Updating' : 'Installing', " ").concat(chalk_1.default.bold.cyan(packageName), " with ").concat(chalk_1.default.bold(packageManager.label), "."));
281
- _c.label = 4;
282
- case 4:
283
- _c.trys.push([4, 6, , 8]);
284
- return [4 /*yield*/, (0, package_manager_1.installPackageWithPackageManager)(packageManager, packageName)];
285
- case 5:
286
- _c.sent();
287
- return [3 /*break*/, 8];
288
- case 6:
289
- e_1 = _c.sent();
290
- sdkInstallSpinner.stop('Installation failed.');
291
- clack.log.error("".concat(chalk_1.default.red('Encountered the following error during installation:'), "\n\n").concat(e_1, "\n\n").concat(chalk_1.default.dim('If you think this issue is caused by the Sentry wizard, let us know here:\nhttps://github.com/getsentry/sentry-wizard/issues')));
292
- return [4 /*yield*/, abort()];
293
- case 7:
294
- _c.sent();
295
- return [3 /*break*/, 8];
296
- case 8:
297
- sdkInstallSpinner.stop("".concat(alreadyInstalled ? 'Updated' : 'Installed', " ").concat(chalk_1.default.bold.cyan(packageName), " with ").concat(chalk_1.default.bold(packageManager.label), "."));
298
- return [2 /*return*/];
299
- }
304
+ return [2 /*return*/, (0, telemetry_1.traceStep)('install-package', function () { return __awaiter(_this, void 0, void 0, function () {
305
+ var shouldUpdatePackage, sdkInstallSpinner, packageManager, e_1;
306
+ return __generator(this, function (_a) {
307
+ switch (_a.label) {
308
+ case 0:
309
+ if (!(alreadyInstalled && askBeforeUpdating)) return [3 /*break*/, 2];
310
+ return [4 /*yield*/, abortIfCancelled(clack.confirm({
311
+ message: "The ".concat(chalk_1.default.bold.cyan(packageName), " package is already installed. Do you want to update it to the latest version?"),
312
+ }))];
313
+ case 1:
314
+ shouldUpdatePackage = _a.sent();
315
+ if (!shouldUpdatePackage) {
316
+ return [2 /*return*/];
317
+ }
318
+ _a.label = 2;
319
+ case 2:
320
+ sdkInstallSpinner = clack.spinner();
321
+ return [4 /*yield*/, getPackageManager()];
322
+ case 3:
323
+ packageManager = _a.sent();
324
+ sdkInstallSpinner.start("".concat(alreadyInstalled ? 'Updating' : 'Installing', " ").concat(chalk_1.default.bold.cyan(packageName), " with ").concat(chalk_1.default.bold(packageManager.label), "."));
325
+ _a.label = 4;
326
+ case 4:
327
+ _a.trys.push([4, 6, , 8]);
328
+ return [4 /*yield*/, (0, package_manager_1.installPackageWithPackageManager)(packageManager, packageName)];
329
+ case 5:
330
+ _a.sent();
331
+ return [3 /*break*/, 8];
332
+ case 6:
333
+ e_1 = _a.sent();
334
+ sdkInstallSpinner.stop('Installation failed.');
335
+ clack.log.error("".concat(chalk_1.default.red('Encountered the following error during installation:'), "\n\n").concat(e_1, "\n\n").concat(chalk_1.default.dim('If you think this issue is caused by the Sentry wizard, let us know here:\nhttps://github.com/getsentry/sentry-wizard/issues')));
336
+ return [4 /*yield*/, abort()];
337
+ case 7:
338
+ _a.sent();
339
+ return [3 /*break*/, 8];
340
+ case 8:
341
+ sdkInstallSpinner.stop("".concat(alreadyInstalled ? 'Updated' : 'Installed', " ").concat(chalk_1.default.bold.cyan(packageName), " with ").concat(chalk_1.default.bold(packageManager.label), "."));
342
+ return [2 /*return*/];
343
+ }
344
+ });
345
+ }); })];
300
346
  });
301
347
  });
302
348
  }
@@ -304,44 +350,49 @@ exports.installPackage = installPackage;
304
350
  function addSentryCliConfig(authToken, setupConfig) {
305
351
  if (setupConfig === void 0) { setupConfig = exports.sourceMapsCliSetupConfig; }
306
352
  return __awaiter(this, void 0, void 0, function () {
307
- var configExists, configContents, _a, _b;
308
- return __generator(this, function (_c) {
309
- switch (_c.label) {
310
- case 0:
311
- configExists = fs.existsSync(path.join(process.cwd(), setupConfig.filename));
312
- if (!configExists) return [3 /*break*/, 5];
313
- configContents = fs.readFileSync(path.join(process.cwd(), setupConfig.filename), 'utf8');
314
- if (!setupConfig.likelyAlreadyHasAuthToken(configContents)) return [3 /*break*/, 1];
315
- clack.log.warn("".concat(chalk_1.default.bold(setupConfig.filename), " already has auth token. Will not add one."));
316
- return [3 /*break*/, 4];
317
- case 1:
318
- _c.trys.push([1, 3, , 4]);
319
- return [4 /*yield*/, fs.promises.writeFile(path.join(process.cwd(), setupConfig.filename), "".concat(configContents, "\n").concat(setupConfig.tokenContent(authToken), "\n"), { encoding: 'utf8', flag: 'w' })];
320
- case 2:
321
- _c.sent();
322
- clack.log.success(chalk_1.default.greenBright("Added auth token to ".concat(chalk_1.default.bold(setupConfig.filename), " for you to test uploading ").concat(setupConfig.name, " locally.")));
323
- return [3 /*break*/, 4];
324
- case 3:
325
- _a = _c.sent();
326
- clack.log.warning("Failed to add auth token to ".concat(chalk_1.default.bold(setupConfig.filename), ". Uploading ").concat(setupConfig.name, " during build will likely not work locally."));
327
- return [3 /*break*/, 4];
328
- case 4: return [3 /*break*/, 8];
329
- case 5:
330
- _c.trys.push([5, 7, , 8]);
331
- return [4 /*yield*/, fs.promises.writeFile(path.join(process.cwd(), setupConfig.filename), "".concat(setupConfig.tokenContent(authToken), "\n"), { encoding: 'utf8', flag: 'w' })];
332
- case 6:
333
- _c.sent();
334
- clack.log.success(chalk_1.default.greenBright("Created ".concat(chalk_1.default.bold(setupConfig.filename), " with auth token for you to test uploading ").concat(setupConfig.name, " locally.")));
335
- return [3 /*break*/, 8];
336
- case 7:
337
- _b = _c.sent();
338
- clack.log.warning("Failed to create ".concat(chalk_1.default.bold(setupConfig.filename), " with auth token. Uploading ").concat(setupConfig.name, " during build will likely not work locally."));
339
- return [3 /*break*/, 8];
340
- case 8: return [4 /*yield*/, addAuthTokenFileToGitIgnore(setupConfig.filename)];
341
- case 9:
342
- _c.sent();
343
- return [2 /*return*/];
344
- }
353
+ var _this = this;
354
+ return __generator(this, function (_a) {
355
+ return [2 /*return*/, (0, telemetry_1.traceStep)('add-sentry-cli-config', function () { return __awaiter(_this, void 0, void 0, function () {
356
+ var configExists, configContents, _a, _b;
357
+ return __generator(this, function (_c) {
358
+ switch (_c.label) {
359
+ case 0:
360
+ configExists = fs.existsSync(path.join(process.cwd(), setupConfig.filename));
361
+ if (!configExists) return [3 /*break*/, 5];
362
+ configContents = fs.readFileSync(path.join(process.cwd(), setupConfig.filename), 'utf8');
363
+ if (!setupConfig.likelyAlreadyHasAuthToken(configContents)) return [3 /*break*/, 1];
364
+ clack.log.warn("".concat(chalk_1.default.bold(setupConfig.filename), " already has auth token. Will not add one."));
365
+ return [3 /*break*/, 4];
366
+ case 1:
367
+ _c.trys.push([1, 3, , 4]);
368
+ return [4 /*yield*/, fs.promises.writeFile(path.join(process.cwd(), setupConfig.filename), "".concat(configContents, "\n").concat(setupConfig.tokenContent(authToken), "\n"), { encoding: 'utf8', flag: 'w' })];
369
+ case 2:
370
+ _c.sent();
371
+ clack.log.success(chalk_1.default.greenBright("Added auth token to ".concat(chalk_1.default.bold(setupConfig.filename), " for you to test uploading ").concat(setupConfig.name, " locally.")));
372
+ return [3 /*break*/, 4];
373
+ case 3:
374
+ _a = _c.sent();
375
+ clack.log.warning("Failed to add auth token to ".concat(chalk_1.default.bold(setupConfig.filename), ". Uploading ").concat(setupConfig.name, " during build will likely not work locally."));
376
+ return [3 /*break*/, 4];
377
+ case 4: return [3 /*break*/, 8];
378
+ case 5:
379
+ _c.trys.push([5, 7, , 8]);
380
+ return [4 /*yield*/, fs.promises.writeFile(path.join(process.cwd(), setupConfig.filename), "".concat(setupConfig.tokenContent(authToken), "\n"), { encoding: 'utf8', flag: 'w' })];
381
+ case 6:
382
+ _c.sent();
383
+ clack.log.success(chalk_1.default.greenBright("Created ".concat(chalk_1.default.bold(setupConfig.filename), " with auth token for you to test uploading ").concat(setupConfig.name, " locally.")));
384
+ return [3 /*break*/, 8];
385
+ case 7:
386
+ _b = _c.sent();
387
+ clack.log.warning("Failed to create ".concat(chalk_1.default.bold(setupConfig.filename), " with auth token. Uploading ").concat(setupConfig.name, " during build will likely not work locally."));
388
+ return [3 /*break*/, 8];
389
+ case 8: return [4 /*yield*/, addAuthTokenFileToGitIgnore(setupConfig.filename)];
390
+ case 9:
391
+ _c.sent();
392
+ return [2 /*return*/];
393
+ }
394
+ });
395
+ }); })];
345
396
  });
346
397
  });
347
398
  }
@@ -420,31 +471,44 @@ function addAuthTokenFileToGitIgnore(filename) {
420
471
  });
421
472
  });
422
473
  }
474
+ /**
475
+ * Checks if @param packageId is listed as a dependency in @param packageJson.
476
+ * If not, it will ask users if they want to continue without the package.
477
+ *
478
+ * Use this function to check if e.g. a the framework of the SDK is installed
479
+ *
480
+ * @param packageJson the package.json object
481
+ * @param packageId the npm name of the package
482
+ * @param packageName a human readable name of the package
483
+ */
423
484
  function ensurePackageIsInstalled(packageJson, packageId, packageName) {
424
485
  return __awaiter(this, void 0, void 0, function () {
425
- var continueWithoutPackage;
486
+ var _this = this;
426
487
  return __generator(this, function (_a) {
427
- switch (_a.label) {
428
- case 0:
429
- if (!!(0, package_json_1.hasPackageInstalled)(packageId, packageJson)) return [3 /*break*/, 4];
430
- Sentry.setTag('package-installed', false);
431
- return [4 /*yield*/, abortIfCancelled(clack.confirm({
432
- message: "".concat(packageName, " does not seem to be installed. Do you still want to continue?"),
433
- initialValue: false,
434
- }))];
435
- case 1:
436
- continueWithoutPackage = _a.sent();
437
- if (!!continueWithoutPackage) return [3 /*break*/, 3];
438
- return [4 /*yield*/, abort(undefined, 0)];
439
- case 2:
440
- _a.sent();
441
- _a.label = 3;
442
- case 3: return [3 /*break*/, 5];
443
- case 4:
444
- Sentry.setTag('package-installed', true);
445
- _a.label = 5;
446
- case 5: return [2 /*return*/];
447
- }
488
+ return [2 /*return*/, (0, telemetry_1.traceStep)('ensure-package-installed', function () { return __awaiter(_this, void 0, void 0, function () {
489
+ var installed, continueWithoutPackage;
490
+ return __generator(this, function (_a) {
491
+ switch (_a.label) {
492
+ case 0:
493
+ installed = (0, package_json_1.hasPackageInstalled)(packageId, packageJson);
494
+ Sentry.setTag("".concat(packageName.toLowerCase(), "-installed"), installed);
495
+ if (!!installed) return [3 /*break*/, 3];
496
+ Sentry.setTag("".concat(packageName.toLowerCase(), "-installed"), false);
497
+ return [4 /*yield*/, abortIfCancelled(clack.confirm({
498
+ message: "".concat(packageName, " does not seem to be installed. Do you still want to continue?"),
499
+ initialValue: false,
500
+ }))];
501
+ case 1:
502
+ continueWithoutPackage = _a.sent();
503
+ if (!!continueWithoutPackage) return [3 /*break*/, 3];
504
+ return [4 /*yield*/, abort(undefined, 0)];
505
+ case 2:
506
+ _a.sent();
507
+ _a.label = 3;
508
+ case 3: return [2 /*return*/];
509
+ }
510
+ });
511
+ }); })];
448
512
  });
449
513
  });
450
514
  }
@@ -471,7 +535,7 @@ function getPackageDotJson() {
471
535
  return [3 /*break*/, 5];
472
536
  case 3:
473
537
  _a = _b.sent();
474
- clack.log.error('Unable to parse your package.json. Make sure it has a valid format!');
538
+ clack.log.error("Unable to parse your ".concat(chalk_1.default.cyan('package.json'), ". Make sure it has a valid format!"));
475
539
  return [4 /*yield*/, abort()];
476
540
  case 4:
477
541
  _b.sent();