@slicemachine/init 2.6.4-dev-upgrade-legacy.1 → 2.6.4-dev-next-hotfix.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 (35) hide show
  1. package/dist/SliceMachineInitProcess.cjs +21 -33
  2. package/dist/SliceMachineInitProcess.cjs.map +1 -1
  3. package/dist/SliceMachineInitProcess.d.ts +1 -1
  4. package/dist/SliceMachineInitProcess.js +21 -33
  5. package/dist/SliceMachineInitProcess.js.map +1 -1
  6. package/dist/constants.cjs +2 -0
  7. package/dist/constants.cjs.map +1 -1
  8. package/dist/constants.d.ts +1 -0
  9. package/dist/constants.js +2 -0
  10. package/dist/constants.js.map +1 -1
  11. package/dist/lib/checkIsSentryEnabled.cjs +5 -0
  12. package/dist/lib/checkIsSentryEnabled.cjs.map +1 -0
  13. package/dist/lib/checkIsSentryEnabled.d.ts +9 -0
  14. package/dist/lib/checkIsSentryEnabled.js +5 -0
  15. package/dist/lib/checkIsSentryEnabled.js.map +1 -0
  16. package/dist/lib/sentryErrorHandlers.cjs +38 -0
  17. package/dist/lib/sentryErrorHandlers.cjs.map +1 -0
  18. package/dist/lib/sentryErrorHandlers.d.ts +1 -0
  19. package/dist/lib/sentryErrorHandlers.js +21 -0
  20. package/dist/lib/sentryErrorHandlers.js.map +1 -0
  21. package/dist/lib/setupSentry.cjs +54 -0
  22. package/dist/lib/setupSentry.cjs.map +1 -0
  23. package/dist/lib/setupSentry.d.ts +8 -0
  24. package/dist/lib/setupSentry.js +37 -0
  25. package/dist/lib/setupSentry.js.map +1 -0
  26. package/dist/packages/init/package.json.cjs +5 -4
  27. package/dist/packages/init/package.json.cjs.map +1 -1
  28. package/dist/packages/init/package.json.js +5 -4
  29. package/dist/packages/init/package.json.js.map +1 -1
  30. package/package.json +5 -4
  31. package/src/SliceMachineInitProcess.ts +22 -52
  32. package/src/constants.ts +3 -0
  33. package/src/lib/checkIsSentryEnabled.ts +12 -0
  34. package/src/lib/sentryErrorHandlers.ts +27 -0
  35. package/src/lib/setupSentry.ts +56 -0
@@ -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-upgrade-legacy.1";
4
+ const version = "2.6.4-dev-next-hotfix.1";
5
5
  const description = "Init Prismic Slice Machine in your project";
6
6
  const keywords = [
7
7
  "typescript",
@@ -54,7 +54,8 @@ const scripts = {
54
54
  const dependencies = {
55
55
  "@antfu/ni": "^0.20.0",
56
56
  "@lihbr/listr-update-renderer": "^0.5.3",
57
- "@slicemachine/manager": "^0.11.3-dev-upgrade-legacy.1",
57
+ "@sentry/node": "^7.70.0",
58
+ "@slicemachine/manager": "^0.11.3-dev-next-hotfix.1",
58
59
  chalk: "^4.1.2",
59
60
  giget: "^1.1.2",
60
61
  globby: "^13.1.3",
@@ -67,7 +68,7 @@ const dependencies = {
67
68
  };
68
69
  const devDependencies = {
69
70
  "@size-limit/preset-small-lib": "8.2.4",
70
- "@slicemachine/plugin-kit": "0.4.17-dev-upgrade-legacy.1",
71
+ "@slicemachine/plugin-kit": "0.4.17-dev-next-hotfix.1",
71
72
  "@types/listr": "0.14.4",
72
73
  "@types/prompts": "2.4.3",
73
74
  "@types/semver": "7.3.13",
@@ -93,7 +94,7 @@ const devDependencies = {
93
94
  "vite-plugin-sdk": "0.1.1",
94
95
  vitest: "0.32.0"
95
96
  };
96
- const gitHead = "e04b22de4c8d6caf8aa4fba598f399678bec18bc";
97
+ const gitHead = "798fa094325092bf4497633a6e124896b8d1d90e";
97
98
  const pkg = {
98
99
  name,
99
100
  version,
@@ -1 +1 @@
1
- {"version":3,"file":"package.json.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"package.json.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -1,5 +1,5 @@
1
1
  const name = "@slicemachine/init";
2
- const version = "2.6.4-dev-upgrade-legacy.1";
2
+ const version = "2.6.4-dev-next-hotfix.1";
3
3
  const description = "Init Prismic Slice Machine in your project";
4
4
  const keywords = [
5
5
  "typescript",
@@ -52,7 +52,8 @@ const scripts = {
52
52
  const dependencies = {
53
53
  "@antfu/ni": "^0.20.0",
54
54
  "@lihbr/listr-update-renderer": "^0.5.3",
55
- "@slicemachine/manager": "^0.11.3-dev-upgrade-legacy.1",
55
+ "@sentry/node": "^7.70.0",
56
+ "@slicemachine/manager": "^0.11.3-dev-next-hotfix.1",
56
57
  chalk: "^4.1.2",
57
58
  giget: "^1.1.2",
58
59
  globby: "^13.1.3",
@@ -65,7 +66,7 @@ const dependencies = {
65
66
  };
66
67
  const devDependencies = {
67
68
  "@size-limit/preset-small-lib": "8.2.4",
68
- "@slicemachine/plugin-kit": "0.4.17-dev-upgrade-legacy.1",
69
+ "@slicemachine/plugin-kit": "0.4.17-dev-next-hotfix.1",
69
70
  "@types/listr": "0.14.4",
70
71
  "@types/prompts": "2.4.3",
71
72
  "@types/semver": "7.3.13",
@@ -91,7 +92,7 @@ const devDependencies = {
91
92
  "vite-plugin-sdk": "0.1.1",
92
93
  vitest: "0.32.0"
93
94
  };
94
- const gitHead = "e04b22de4c8d6caf8aa4fba598f399678bec18bc";
95
+ const gitHead = "798fa094325092bf4497633a6e124896b8d1d90e";
95
96
  const pkg = {
96
97
  name,
97
98
  version,
@@ -1 +1 @@
1
- {"version":3,"file":"package.json.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"package.json.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@slicemachine/init",
3
- "version": "2.6.4-dev-upgrade-legacy.1",
3
+ "version": "2.6.4-dev-next-hotfix.1",
4
4
  "description": "Init Prismic Slice Machine in your project",
5
5
  "keywords": [
6
6
  "typescript",
@@ -53,7 +53,8 @@
53
53
  "dependencies": {
54
54
  "@antfu/ni": "^0.20.0",
55
55
  "@lihbr/listr-update-renderer": "^0.5.3",
56
- "@slicemachine/manager": "^0.11.3-dev-upgrade-legacy.1",
56
+ "@sentry/node": "^7.70.0",
57
+ "@slicemachine/manager": "^0.11.3-dev-next-hotfix.1",
57
58
  "chalk": "^4.1.2",
58
59
  "giget": "^1.1.2",
59
60
  "globby": "^13.1.3",
@@ -66,7 +67,7 @@
66
67
  },
67
68
  "devDependencies": {
68
69
  "@size-limit/preset-small-lib": "8.2.4",
69
- "@slicemachine/plugin-kit": "0.4.17-dev-upgrade-legacy.1",
70
+ "@slicemachine/plugin-kit": "0.4.17-dev-next-hotfix.1",
70
71
  "@types/listr": "0.14.4",
71
72
  "@types/prompts": "2.4.3",
72
73
  "@types/semver": "7.3.13",
@@ -92,5 +93,5 @@
92
93
  "vite-plugin-sdk": "0.1.1",
93
94
  "vitest": "0.32.0"
94
95
  },
95
- "gitHead": "e04b22de4c8d6caf8aa4fba598f399678bec18bc"
96
+ "gitHead": "798fa094325092bf4497633a6e124896b8d1d90e"
96
97
  }
@@ -41,6 +41,8 @@ import {
41
41
  START_SCRIPT_VALUE,
42
42
  } from "./constants";
43
43
  import { detectStarterId } from "./lib/starters";
44
+ import { setupSentry } from "./lib/setupSentry";
45
+ import { trackSentryError } from "./lib/sentryErrorHandlers";
44
46
 
45
47
  export type SliceMachineInitProcessOptions = {
46
48
  repository?: string;
@@ -172,7 +174,7 @@ export class SliceMachineInitProcess {
172
174
  await this.createNewRepository();
173
175
  }
174
176
 
175
- await this.syncDataWithPrismic();
177
+ await this.pushDataToPrismic();
176
178
  await this.initializeProject();
177
179
  await this.initializePlugins();
178
180
  } catch (error) {
@@ -299,8 +301,8 @@ export class SliceMachineInitProcess {
299
301
  }
300
302
  }
301
303
  }
302
- } catch {
303
- // Noop, it's only the final convenience messsage
304
+ } catch (error) {
305
+ await this.trackError(error);
304
306
  }
305
307
  }
306
308
 
@@ -315,8 +317,6 @@ export class SliceMachineInitProcess {
315
317
  this.manager.customTypes.readCustomTypeLibrary(),
316
318
  this.readDocuments(),
317
319
  ]);
318
-
319
- // If repository exists, and there's anything to push
320
320
  if (
321
321
  slices.length > 0 ||
322
322
  ctLibrary.ids.length > 0 ||
@@ -324,11 +324,6 @@ export class SliceMachineInitProcess {
324
324
  ) {
325
325
  return true;
326
326
  }
327
-
328
- // If repository exists, and there might be things to pull
329
- if (ctLibrary.ids.length === 0) {
330
- return true;
331
- }
332
327
  } catch (e) {
333
328
  return true;
334
329
  }
@@ -336,16 +331,22 @@ export class SliceMachineInitProcess {
336
331
  return false;
337
332
  }
338
333
 
339
- protected trackError = (error: unknown): Promise<void> => {
334
+ 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);
341
+
340
342
  // Transform error to string and prevent hitting Segment 500kb API limit or sending ridiculously long trace
341
343
  const safeError = (
342
344
  error instanceof Error ? error.message : `${error}`
343
345
  ).slice(0, 512);
344
-
345
- return this.manager.telemetry.track({
346
+ await this.manager.telemetry.track({
346
347
  event: "command:init:end",
347
348
  framework: this.context.framework?.sliceMachineTelemetryID ?? "unknown",
348
- repository: this.context.repository?.domain || "",
349
+ repository: repositoryName,
349
350
  success: false,
350
351
  error: safeError,
351
352
  });
@@ -1099,10 +1100,10 @@ ${chalk.cyan("?")} Your Prismic repository name`.replace("\n", ""),
1099
1100
  return { signature, documents, directoryPath: documentsDirectoryPath };
1100
1101
  }
1101
1102
 
1102
- protected syncDataWithPrismic(): Promise<void> {
1103
+ protected pushDataToPrismic(): Promise<void> {
1103
1104
  return listrRun([
1104
1105
  {
1105
- title: "Syncing data with Prismic...",
1106
+ title: "Pushing data to Prismic...",
1106
1107
  task: (_, parentTask) =>
1107
1108
  listr([
1108
1109
  {
@@ -1198,7 +1199,7 @@ ${chalk.cyan("?")} Your Prismic repository name`.replace("\n", ""),
1198
1199
  task: async (_, task) => {
1199
1200
  assertExists(
1200
1201
  this.context.repository,
1201
- "Repository selection must be available through context to run `syncDataWithPrismic`",
1202
+ "Repository selection must be available through context to run `pushDataToPrismic`",
1202
1203
  );
1203
1204
 
1204
1205
  try {
@@ -1208,6 +1209,7 @@ ${chalk.cyan("?")} Your Prismic repository name`.replace("\n", ""),
1208
1209
  documentsRead === undefined ||
1209
1210
  documentsRead.documents.length === 0
1210
1211
  ) {
1212
+ parentTask.title = "Pushed data to Prismic";
1211
1213
  task.skip("No document to push");
1212
1214
 
1213
1215
  return;
@@ -1249,7 +1251,9 @@ ${chalk.cyan("?")} Your Prismic repository name`.replace("\n", ""),
1249
1251
  });
1250
1252
 
1251
1253
  task.title = "Pushed all documents";
1254
+ parentTask.title = "Pushed data to Prismic";
1252
1255
  } catch {
1256
+ parentTask.title = "Pushed data to Prismic";
1253
1257
  task.skip("No document to push");
1254
1258
 
1255
1259
  return;
@@ -1271,41 +1275,7 @@ ${chalk.cyan("?")} Your Prismic repository name`.replace("\n", ""),
1271
1275
  }
1272
1276
 
1273
1277
  task.title = "Cleaned up data push artifacts";
1274
- },
1275
- },
1276
- {
1277
- title: "Pulling existing types...",
1278
- task: async (_, task) => {
1279
- const { ids, errors } =
1280
- await this.manager.customTypes.readCustomTypeLibrary();
1281
-
1282
- if (errors.length > 0) {
1283
- // TODO: Provide better error message.
1284
- throw new Error(
1285
- `Failed to read custom type libraries: ${errors.join(
1286
- ", ",
1287
- )}`,
1288
- );
1289
- }
1290
-
1291
- if (ids && ids.length > 0) {
1292
- task.skip("Types already exists");
1293
- parentTask.title = "Synced data with Prismic";
1294
-
1295
- return;
1296
- }
1297
-
1298
- const remoteTypes =
1299
- await this.manager.customTypes.fetchRemoteCustomTypes();
1300
-
1301
- await Promise.all(
1302
- remoteTypes.map(async (model) => {
1303
- await this.manager.customTypes.createCustomType({ model });
1304
- }),
1305
- );
1306
-
1307
- task.title = "Pulled existing types";
1308
- parentTask.title = "Synced data with Prismic";
1278
+ parentTask.title = "Pushed data to Prismic";
1309
1279
  },
1310
1280
  },
1311
1281
  ]),
package/src/constants.ts CHANGED
@@ -4,3 +4,6 @@ export const START_SCRIPT_VALUE = "start-slicemachine";
4
4
  export const GIGET_PROVIDER = "github";
5
5
  export const GIGET_ORGANIZATION = "prismicio-community";
6
6
  export const SLICE_MACHINE_INIT_USER_AGENT = "slice-machine-init";
7
+ export const SENTRY_EXPRESS_DSN =
8
+ import.meta.env.VITE_SENTRY_EXPRESS_DSN ||
9
+ "https://d3e69d5189266d8d7f60f71ccc9353fc@o146123.ingest.sentry.io/4505917981982720";
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Checks whether or not Sentry is enabled.
3
+ *
4
+ * Sentry is enabled automatically in production but can be disabled by setting
5
+ * `VITE_ENABLE_SENTRY` to `false`.
6
+ *
7
+ * @returns Whether or not Sentry is enabled.
8
+ */
9
+ export const checkIsSentryEnabled = (): boolean =>
10
+ import.meta.env.VITE_ENABLE_SENTRY === undefined
11
+ ? import.meta.env.PROD
12
+ : import.meta.env.VITE_ENABLE_SENTRY === "true";
@@ -0,0 +1,27 @@
1
+ import * as Sentry from "@sentry/node";
2
+
3
+ import { checkIsSentryEnabled } from "./checkIsSentryEnabled";
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
+ 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
+ });
26
+ }
27
+ }
@@ -0,0 +1,56 @@
1
+ import * as Sentry from "@sentry/node";
2
+ import semver from "semver";
3
+
4
+ import { PrismicUserProfile, SliceMachineManager } from "@slicemachine/manager";
5
+ import { SENTRY_EXPRESS_DSN } from "../constants";
6
+ import { checkIsSentryEnabled } from "./checkIsSentryEnabled";
7
+ import { version } from "../../package.json";
8
+
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> => {
20
+ if (!checkIsSentryEnabled()) {
21
+ return;
22
+ }
23
+
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
+ const isStableVersion =
32
+ semver.prerelease(version) === null && semver.lte("0.1.0", version);
33
+
34
+ Sentry.init({
35
+ dsn: SENTRY_EXPRESS_DSN,
36
+ release: version,
37
+ environment: isStableVersion
38
+ ? import.meta.env.MODE || "production"
39
+ : "alpha",
40
+ });
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
+ };