@slicemachine/init 2.6.4-dev-next-hotfix.1 → 2.6.4-dev-next-hotfix.3

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.
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
3
3
  const name = "@slicemachine/init";
4
- const version = "2.6.4-dev-next-hotfix.1";
4
+ const version = "2.6.4-dev-next-hotfix.3";
5
5
  const description = "Init Prismic Slice Machine in your project";
6
6
  const keywords = [
7
7
  "typescript",
@@ -55,7 +55,7 @@ const dependencies = {
55
55
  "@antfu/ni": "^0.20.0",
56
56
  "@lihbr/listr-update-renderer": "^0.5.3",
57
57
  "@sentry/node": "^7.70.0",
58
- "@slicemachine/manager": "^0.11.3-dev-next-hotfix.1",
58
+ "@slicemachine/manager": "^0.11.3-dev-next-hotfix.3",
59
59
  chalk: "^4.1.2",
60
60
  giget: "^1.1.2",
61
61
  globby: "^13.1.3",
@@ -68,7 +68,7 @@ const dependencies = {
68
68
  };
69
69
  const devDependencies = {
70
70
  "@size-limit/preset-small-lib": "8.2.4",
71
- "@slicemachine/plugin-kit": "0.4.17-dev-next-hotfix.1",
71
+ "@slicemachine/plugin-kit": "0.4.17-dev-next-hotfix.3",
72
72
  "@types/listr": "0.14.4",
73
73
  "@types/prompts": "2.4.3",
74
74
  "@types/semver": "7.3.13",
@@ -94,7 +94,7 @@ const devDependencies = {
94
94
  "vite-plugin-sdk": "0.1.1",
95
95
  vitest: "0.32.0"
96
96
  };
97
- const gitHead = "798fa094325092bf4497633a6e124896b8d1d90e";
97
+ const gitHead = "aff2adcfa5539fb8cd3c566b009ab2cfa98bb29c";
98
98
  const pkg = {
99
99
  name,
100
100
  version,
@@ -1,5 +1,5 @@
1
1
  const name = "@slicemachine/init";
2
- const version = "2.6.4-dev-next-hotfix.1";
2
+ const version = "2.6.4-dev-next-hotfix.3";
3
3
  const description = "Init Prismic Slice Machine in your project";
4
4
  const keywords = [
5
5
  "typescript",
@@ -53,7 +53,7 @@ const dependencies = {
53
53
  "@antfu/ni": "^0.20.0",
54
54
  "@lihbr/listr-update-renderer": "^0.5.3",
55
55
  "@sentry/node": "^7.70.0",
56
- "@slicemachine/manager": "^0.11.3-dev-next-hotfix.1",
56
+ "@slicemachine/manager": "^0.11.3-dev-next-hotfix.3",
57
57
  chalk: "^4.1.2",
58
58
  giget: "^1.1.2",
59
59
  globby: "^13.1.3",
@@ -66,7 +66,7 @@ const dependencies = {
66
66
  };
67
67
  const devDependencies = {
68
68
  "@size-limit/preset-small-lib": "8.2.4",
69
- "@slicemachine/plugin-kit": "0.4.17-dev-next-hotfix.1",
69
+ "@slicemachine/plugin-kit": "0.4.17-dev-next-hotfix.3",
70
70
  "@types/listr": "0.14.4",
71
71
  "@types/prompts": "2.4.3",
72
72
  "@types/semver": "7.3.13",
@@ -92,7 +92,7 @@ const devDependencies = {
92
92
  "vite-plugin-sdk": "0.1.1",
93
93
  vitest: "0.32.0"
94
94
  };
95
- const gitHead = "798fa094325092bf4497633a6e124896b8d1d90e";
95
+ const gitHead = "aff2adcfa5539fb8cd3c566b009ab2cfa98bb29c";
96
96
  const pkg = {
97
97
  name,
98
98
  version,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@slicemachine/init",
3
- "version": "2.6.4-dev-next-hotfix.1",
3
+ "version": "2.6.4-dev-next-hotfix.3",
4
4
  "description": "Init Prismic Slice Machine in your project",
5
5
  "keywords": [
6
6
  "typescript",
@@ -54,7 +54,7 @@
54
54
  "@antfu/ni": "^0.20.0",
55
55
  "@lihbr/listr-update-renderer": "^0.5.3",
56
56
  "@sentry/node": "^7.70.0",
57
- "@slicemachine/manager": "^0.11.3-dev-next-hotfix.1",
57
+ "@slicemachine/manager": "^0.11.3-dev-next-hotfix.3",
58
58
  "chalk": "^4.1.2",
59
59
  "giget": "^1.1.2",
60
60
  "globby": "^13.1.3",
@@ -67,7 +67,7 @@
67
67
  },
68
68
  "devDependencies": {
69
69
  "@size-limit/preset-small-lib": "8.2.4",
70
- "@slicemachine/plugin-kit": "0.4.17-dev-next-hotfix.1",
70
+ "@slicemachine/plugin-kit": "0.4.17-dev-next-hotfix.3",
71
71
  "@types/listr": "0.14.4",
72
72
  "@types/prompts": "2.4.3",
73
73
  "@types/semver": "7.3.13",
@@ -93,5 +93,5 @@
93
93
  "vite-plugin-sdk": "0.1.1",
94
94
  "vitest": "0.32.0"
95
95
  },
96
- "gitHead": "798fa094325092bf4497633a6e124896b8d1d90e"
96
+ "gitHead": "aff2adcfa5539fb8cd3c566b009ab2cfa98bb29c"
97
97
  }
@@ -43,6 +43,7 @@ import {
43
43
  import { detectStarterId } from "./lib/starters";
44
44
  import { setupSentry } from "./lib/setupSentry";
45
45
  import { trackSentryError } from "./lib/sentryErrorHandlers";
46
+ import { updateSentryContext } from "./lib/updateSentryContext";
46
47
 
47
48
  export type SliceMachineInitProcessOptions = {
48
49
  repository?: string;
@@ -134,6 +135,7 @@ export class SliceMachineInitProcess {
134
135
  appName: pkg.name,
135
136
  appVersion: pkg.version,
136
137
  });
138
+ await setupSentry();
137
139
  await this.manager.telemetry.track({
138
140
  event: "command:init:start",
139
141
  repository: this.options.repository,
@@ -302,7 +304,8 @@ export class SliceMachineInitProcess {
302
304
  }
303
305
  }
304
306
  } catch (error) {
305
- await this.trackError(error);
307
+ // Only track this error with Sentry, it's only the final convenience message
308
+ await this.trackSentryError(error);
306
309
  }
307
310
  }
308
311
 
@@ -332,13 +335,11 @@ export class SliceMachineInitProcess {
332
335
  }
333
336
 
334
337
  protected trackError = async (error: unknown): Promise<void> => {
335
- const repositoryName = this.context.repository?.domain || "";
336
- const framework =
337
- this.context.framework?.sliceMachineTelemetryID ?? "unknown";
338
-
339
- await setupSentry({ manager: this.manager, repositoryName, framework });
340
- trackSentryError(error);
338
+ await this.trackSentryError(error);
339
+ await this.trackTelemetryError(error);
340
+ };
341
341
 
342
+ protected trackTelemetryError = async (error: unknown): Promise<void> => {
342
343
  // Transform error to string and prevent hitting Segment 500kb API limit or sending ridiculously long trace
343
344
  const safeError = (
344
345
  error instanceof Error ? error.message : `${error}`
@@ -346,12 +347,21 @@ export class SliceMachineInitProcess {
346
347
  await this.manager.telemetry.track({
347
348
  event: "command:init:end",
348
349
  framework: this.context.framework?.sliceMachineTelemetryID ?? "unknown",
349
- repository: repositoryName,
350
+ repository: this.context.repository?.domain || "",
350
351
  success: false,
351
352
  error: safeError,
352
353
  });
353
354
  };
354
355
 
356
+ protected trackSentryError = async (error: unknown): Promise<void> => {
357
+ await updateSentryContext({
358
+ manager: this.manager,
359
+ repositoryName: this.context.repository?.domain || "",
360
+ framework: this.context.framework?.sliceMachineTelemetryID ?? "unknown",
361
+ });
362
+ trackSentryError(error);
363
+ };
364
+
355
365
  protected async copyStarter(): Promise<void> {
356
366
  const dir = await this.getStarterDirectoryName();
357
367
 
@@ -2,26 +2,12 @@ import * as Sentry from "@sentry/node";
2
2
 
3
3
  import { checkIsSentryEnabled } from "./checkIsSentryEnabled";
4
4
 
5
- type ErrorWithCause = Error & {
6
- cause?: unknown;
7
- };
8
-
9
- function hasCause(error: unknown): error is ErrorWithCause {
10
- return error instanceof Error && "cause" in error;
11
- }
12
-
13
5
  export function trackSentryError(error: unknown): void {
14
- if (checkIsSentryEnabled()) {
15
- Sentry.withScope(function (scope) {
16
- scope.setTransactionName("init");
17
- Sentry.captureException(error, {
18
- extra: {
19
- cause:
20
- hasCause(error) && error.cause !== undefined
21
- ? (error.cause as string)
22
- : "",
23
- },
24
- });
25
- });
6
+ if (!checkIsSentryEnabled()) {
7
+ return;
26
8
  }
9
+
10
+ Sentry.captureException(error, {
11
+ ...(error instanceof Error ? { extra: { cause: error.cause } } : {}),
12
+ });
27
13
  }
@@ -1,33 +1,15 @@
1
1
  import * as Sentry from "@sentry/node";
2
2
  import semver from "semver";
3
3
 
4
- import { PrismicUserProfile, SliceMachineManager } from "@slicemachine/manager";
5
4
  import { SENTRY_EXPRESS_DSN } from "../constants";
6
5
  import { checkIsSentryEnabled } from "./checkIsSentryEnabled";
7
6
  import { version } from "../../package.json";
8
7
 
9
- type SetupSentryArgs = {
10
- manager: SliceMachineManager;
11
- repositoryName: string;
12
- framework: string;
13
- };
14
-
15
- export const setupSentry = async ({
16
- manager,
17
- repositoryName,
18
- framework,
19
- }: SetupSentryArgs): Promise<void> => {
8
+ export function setupSentry(): void {
20
9
  if (!checkIsSentryEnabled()) {
21
10
  return;
22
11
  }
23
12
 
24
- let userProfile: PrismicUserProfile | undefined;
25
- try {
26
- userProfile = await manager.user.getProfile();
27
- } catch {
28
- // User is not logged in, it doesn't matter
29
- }
30
-
31
13
  const isStableVersion =
32
14
  semver.prerelease(version) === null && semver.lte("0.1.0", version);
33
15
 
@@ -38,19 +20,4 @@ export const setupSentry = async ({
38
20
  ? import.meta.env.MODE || "production"
39
21
  : "alpha",
40
22
  });
41
-
42
- if (userProfile) {
43
- Sentry.setUser({ id: userProfile.shortId });
44
- }
45
-
46
- if (repositoryName) {
47
- Sentry.setTag("repository", repositoryName);
48
- Sentry.setContext("Repository Data", {
49
- name: repositoryName,
50
- });
51
- }
52
-
53
- if (framework) {
54
- Sentry.setTag("framework", framework);
55
- }
56
- };
23
+ }
@@ -0,0 +1,42 @@
1
+ import * as Sentry from "@sentry/node";
2
+
3
+ import { PrismicUserProfile, SliceMachineManager } from "@slicemachine/manager";
4
+ import { checkIsSentryEnabled } from "./checkIsSentryEnabled";
5
+
6
+ type UpdateSentryContextArgs = {
7
+ manager: SliceMachineManager;
8
+ repositoryName: string;
9
+ framework: string;
10
+ };
11
+
12
+ export async function updateSentryContext({
13
+ manager,
14
+ repositoryName,
15
+ framework,
16
+ }: UpdateSentryContextArgs): Promise<void> {
17
+ if (!checkIsSentryEnabled()) {
18
+ return;
19
+ }
20
+
21
+ let userProfile: PrismicUserProfile | undefined;
22
+ try {
23
+ userProfile = await manager.user.getProfile();
24
+ } catch {
25
+ // User is not logged in, it doesn't matter
26
+ }
27
+
28
+ if (userProfile) {
29
+ Sentry.setUser({ id: userProfile.shortId });
30
+ }
31
+
32
+ if (repositoryName) {
33
+ Sentry.setTag("repository", repositoryName);
34
+ Sentry.setContext("Repository Data", {
35
+ name: repositoryName,
36
+ });
37
+ }
38
+
39
+ if (framework) {
40
+ Sentry.setTag("framework", framework);
41
+ }
42
+ }