@slicemachine/init 2.6.4-dev-upgrade-legacy.2 → 2.7.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 (139) hide show
  1. package/dist/SliceMachineInitProcess.cjs +29 -30
  2. package/dist/SliceMachineInitProcess.cjs.map +1 -1
  3. package/dist/SliceMachineInitProcess.d.ts +3 -1
  4. package/dist/SliceMachineInitProcess.js +29 -30
  5. package/dist/SliceMachineInitProcess.js.map +1 -1
  6. package/dist/_node_modules/@babel/code-frame/lib/index.cjs +2 -2
  7. package/dist/_node_modules/@babel/code-frame/lib/index.js +2 -2
  8. package/dist/_node_modules/@babel/helper-validator-identifier/lib/index.cjs +1 -1
  9. package/dist/_node_modules/@babel/helper-validator-identifier/lib/index.js +1 -1
  10. package/dist/_node_modules/@babel/highlight/lib/index.cjs +3 -3
  11. package/dist/_node_modules/@babel/highlight/lib/index.js +3 -3
  12. package/dist/_node_modules/@nodelib/fs.scandir/out/providers/async.cjs +1 -1
  13. package/dist/_node_modules/@nodelib/fs.scandir/out/providers/async.js +1 -1
  14. package/dist/_node_modules/@nodelib/fs.scandir/out/providers/sync.cjs +1 -1
  15. package/dist/_node_modules/@nodelib/fs.scandir/out/providers/sync.js +1 -1
  16. package/dist/_node_modules/@nodelib/fs.scandir/out/settings.cjs +1 -1
  17. package/dist/_node_modules/@nodelib/fs.scandir/out/settings.js +1 -1
  18. package/dist/_node_modules/@nodelib/fs.stat/out/index.cjs +1 -1
  19. package/dist/_node_modules/@nodelib/fs.stat/out/index.js +1 -1
  20. package/dist/_node_modules/@nodelib/fs.walk/out/index.cjs +1 -1
  21. package/dist/_node_modules/@nodelib/fs.walk/out/index.js +1 -1
  22. package/dist/_node_modules/cross-spawn/index.cjs +1 -1
  23. package/dist/_node_modules/cross-spawn/index.js +1 -1
  24. package/dist/_node_modules/dir-glob/index.cjs +2 -2
  25. package/dist/_node_modules/dir-glob/index.js +2 -2
  26. package/dist/_node_modules/fast-glob/out/index.cjs +1 -1
  27. package/dist/_node_modules/fast-glob/out/index.js +1 -1
  28. package/dist/_node_modules/fast-glob/out/managers/tasks.cjs +1 -1
  29. package/dist/_node_modules/fast-glob/out/managers/tasks.js +1 -1
  30. package/dist/_node_modules/fast-glob/out/providers/filters/deep.cjs +1 -1
  31. package/dist/_node_modules/fast-glob/out/providers/filters/deep.js +1 -1
  32. package/dist/_node_modules/fast-glob/out/providers/filters/entry.cjs +1 -1
  33. package/dist/_node_modules/fast-glob/out/providers/filters/entry.js +1 -1
  34. package/dist/_node_modules/fast-glob/out/providers/filters/error.cjs +1 -1
  35. package/dist/_node_modules/fast-glob/out/providers/filters/error.js +1 -1
  36. package/dist/_node_modules/fast-glob/out/providers/matchers/matcher.cjs +1 -1
  37. package/dist/_node_modules/fast-glob/out/providers/matchers/matcher.js +1 -1
  38. package/dist/_node_modules/fast-glob/out/providers/transformers/entry.cjs +1 -1
  39. package/dist/_node_modules/fast-glob/out/providers/transformers/entry.js +1 -1
  40. package/dist/_node_modules/fast-glob/out/readers/async.cjs +1 -1
  41. package/dist/_node_modules/fast-glob/out/readers/async.js +1 -1
  42. package/dist/_node_modules/fast-glob/out/readers/reader.cjs +2 -2
  43. package/dist/_node_modules/fast-glob/out/readers/reader.js +2 -2
  44. package/dist/_node_modules/fast-glob/out/readers/stream.cjs +2 -2
  45. package/dist/_node_modules/fast-glob/out/readers/stream.js +2 -2
  46. package/dist/_node_modules/fast-glob/out/readers/sync.cjs +2 -2
  47. package/dist/_node_modules/fast-glob/out/readers/sync.js +2 -2
  48. package/dist/_node_modules/fast-glob/out/utils/index.cjs +1 -1
  49. package/dist/_node_modules/fast-glob/out/utils/index.js +1 -1
  50. package/dist/_node_modules/get-stream/index.cjs +1 -1
  51. package/dist/_node_modules/get-stream/index.js +1 -1
  52. package/dist/_node_modules/js-tokens/index.cjs +1 -1
  53. package/dist/_node_modules/js-tokens/index.js +1 -1
  54. package/dist/_node_modules/lines-and-columns/build/index.cjs +1 -1
  55. package/dist/_node_modules/lines-and-columns/build/index.js +1 -1
  56. package/dist/_node_modules/map-obj/index.cjs +1 -1
  57. package/dist/_node_modules/map-obj/index.js +1 -1
  58. package/dist/_node_modules/meow/_node_modules/hosted-git-info/lib/index.cjs +1 -1
  59. package/dist/_node_modules/meow/_node_modules/hosted-git-info/lib/index.js +1 -1
  60. package/dist/_node_modules/meow/_node_modules/read-pkg/_node_modules/hosted-git-info/index.cjs +1 -1
  61. package/dist/_node_modules/meow/_node_modules/read-pkg/_node_modules/hosted-git-info/index.js +1 -1
  62. package/dist/_node_modules/parse-json/index.cjs +2 -2
  63. package/dist/_node_modules/parse-json/index.js +2 -2
  64. package/dist/_node_modules/path-key/index.cjs +1 -1
  65. package/dist/_node_modules/path-key/index.js +1 -1
  66. package/dist/_node_modules/path-type/index.cjs +1 -1
  67. package/dist/_node_modules/path-type/index.js +1 -1
  68. package/dist/_node_modules/signal-exit/index.cjs +1 -1
  69. package/dist/_node_modules/signal-exit/index.js +1 -1
  70. package/dist/_virtual/index10.cjs +2 -2
  71. package/dist/_virtual/index10.js +2 -2
  72. package/dist/_virtual/index11.cjs +2 -2
  73. package/dist/_virtual/index11.js +2 -2
  74. package/dist/_virtual/index12.cjs +2 -2
  75. package/dist/_virtual/index12.js +2 -2
  76. package/dist/_virtual/index13.cjs +2 -2
  77. package/dist/_virtual/index13.js +2 -2
  78. package/dist/_virtual/index14.cjs +2 -2
  79. package/dist/_virtual/index14.js +2 -2
  80. package/dist/_virtual/index15.cjs +2 -2
  81. package/dist/_virtual/index15.js +2 -2
  82. package/dist/_virtual/index16.cjs +2 -2
  83. package/dist/_virtual/index16.js +2 -2
  84. package/dist/_virtual/index17.cjs +2 -2
  85. package/dist/_virtual/index17.js +2 -2
  86. package/dist/_virtual/index18.cjs +2 -2
  87. package/dist/_virtual/index18.js +2 -2
  88. package/dist/_virtual/index19.cjs +2 -2
  89. package/dist/_virtual/index19.js +2 -2
  90. package/dist/_virtual/index3.cjs +2 -2
  91. package/dist/_virtual/index3.js +2 -2
  92. package/dist/_virtual/index4.cjs +2 -2
  93. package/dist/_virtual/index4.js +2 -2
  94. package/dist/_virtual/index5.cjs +2 -2
  95. package/dist/_virtual/index5.js +2 -2
  96. package/dist/_virtual/index6.cjs +2 -2
  97. package/dist/_virtual/index6.js +2 -2
  98. package/dist/_virtual/index7.cjs +2 -2
  99. package/dist/_virtual/index7.js +2 -2
  100. package/dist/_virtual/index8.cjs +2 -2
  101. package/dist/_virtual/index8.js +2 -2
  102. package/dist/_virtual/index9.cjs +2 -2
  103. package/dist/_virtual/index9.js +2 -2
  104. package/dist/constants.cjs +2 -0
  105. package/dist/constants.cjs.map +1 -1
  106. package/dist/constants.d.ts +1 -0
  107. package/dist/constants.js +2 -0
  108. package/dist/constants.js.map +1 -1
  109. package/dist/lib/checkIsSentryEnabled.cjs +5 -0
  110. package/dist/lib/checkIsSentryEnabled.cjs.map +1 -0
  111. package/dist/lib/checkIsSentryEnabled.d.ts +9 -0
  112. package/dist/lib/checkIsSentryEnabled.js +5 -0
  113. package/dist/lib/checkIsSentryEnabled.js.map +1 -0
  114. package/dist/lib/sentryErrorHandlers.cjs +31 -0
  115. package/dist/lib/sentryErrorHandlers.cjs.map +1 -0
  116. package/dist/lib/sentryErrorHandlers.d.ts +1 -0
  117. package/dist/lib/sentryErrorHandlers.js +14 -0
  118. package/dist/lib/sentryErrorHandlers.js.map +1 -0
  119. package/dist/lib/setupSentry.cjs +37 -0
  120. package/dist/lib/setupSentry.cjs.map +1 -0
  121. package/dist/lib/setupSentry.d.ts +1 -0
  122. package/dist/lib/setupSentry.js +20 -0
  123. package/dist/lib/setupSentry.js.map +1 -0
  124. package/dist/lib/updateSentryContext.cjs +45 -0
  125. package/dist/lib/updateSentryContext.cjs.map +1 -0
  126. package/dist/lib/updateSentryContext.d.ts +8 -0
  127. package/dist/lib/updateSentryContext.js +28 -0
  128. package/dist/lib/updateSentryContext.js.map +1 -0
  129. package/dist/packages/init/package.json.cjs +6 -5
  130. package/dist/packages/init/package.json.cjs.map +1 -1
  131. package/dist/packages/init/package.json.js +6 -5
  132. package/dist/packages/init/package.json.js.map +1 -1
  133. package/package.json +6 -5
  134. package/src/SliceMachineInitProcess.ts +31 -51
  135. package/src/constants.ts +3 -0
  136. package/src/lib/checkIsSentryEnabled.ts +12 -0
  137. package/src/lib/sentryErrorHandlers.ts +13 -0
  138. package/src/lib/setupSentry.ts +23 -0
  139. package/src/lib/updateSentryContext.ts +42 -0
@@ -41,6 +41,9 @@ 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";
46
+ import { updateSentryContext } from "./lib/updateSentryContext";
44
47
 
45
48
  export type SliceMachineInitProcessOptions = {
46
49
  repository?: string;
@@ -132,6 +135,7 @@ export class SliceMachineInitProcess {
132
135
  appName: pkg.name,
133
136
  appVersion: pkg.version,
134
137
  });
138
+ await setupSentry();
135
139
  await this.manager.telemetry.track({
136
140
  event: "command:init:start",
137
141
  repository: this.options.repository,
@@ -172,7 +176,7 @@ export class SliceMachineInitProcess {
172
176
  await this.createNewRepository();
173
177
  }
174
178
 
175
- await this.syncDataWithPrismic();
179
+ await this.pushDataToPrismic();
176
180
  await this.initializeProject();
177
181
  await this.initializePlugins();
178
182
  } catch (error) {
@@ -299,8 +303,9 @@ export class SliceMachineInitProcess {
299
303
  }
300
304
  }
301
305
  }
302
- } catch {
303
- // Noop, it's only the final convenience messsage
306
+ } catch (error) {
307
+ // Only track this error with Sentry, it's only the final convenience message
308
+ await this.trackSentryError(error);
304
309
  }
305
310
  }
306
311
 
@@ -315,8 +320,6 @@ export class SliceMachineInitProcess {
315
320
  this.manager.customTypes.readCustomTypeLibrary(),
316
321
  this.readDocuments(),
317
322
  ]);
318
-
319
- // If repository exists, and there's anything to push
320
323
  if (
321
324
  slices.length > 0 ||
322
325
  ctLibrary.ids.length > 0 ||
@@ -324,11 +327,6 @@ export class SliceMachineInitProcess {
324
327
  ) {
325
328
  return true;
326
329
  }
327
-
328
- // If repository exists, and there might be things to pull
329
- if (ctLibrary.ids.length === 0) {
330
- return true;
331
- }
332
330
  } catch (e) {
333
331
  return true;
334
332
  }
@@ -336,13 +334,17 @@ export class SliceMachineInitProcess {
336
334
  return false;
337
335
  }
338
336
 
339
- protected trackError = (error: unknown): Promise<void> => {
337
+ protected trackError = async (error: unknown): Promise<void> => {
338
+ await this.trackSentryError(error);
339
+ await this.trackTelemetryError(error);
340
+ };
341
+
342
+ protected trackTelemetryError = async (error: unknown): Promise<void> => {
340
343
  // Transform error to string and prevent hitting Segment 500kb API limit or sending ridiculously long trace
341
344
  const safeError = (
342
345
  error instanceof Error ? error.message : `${error}`
343
346
  ).slice(0, 512);
344
-
345
- return this.manager.telemetry.track({
347
+ await this.manager.telemetry.track({
346
348
  event: "command:init:end",
347
349
  framework: this.context.framework?.sliceMachineTelemetryID ?? "unknown",
348
350
  repository: this.context.repository?.domain || "",
@@ -351,6 +353,15 @@ export class SliceMachineInitProcess {
351
353
  });
352
354
  };
353
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
+
354
365
  protected async copyStarter(): Promise<void> {
355
366
  const dir = await this.getStarterDirectoryName();
356
367
 
@@ -1099,10 +1110,10 @@ ${chalk.cyan("?")} Your Prismic repository name`.replace("\n", ""),
1099
1110
  return { signature, documents, directoryPath: documentsDirectoryPath };
1100
1111
  }
1101
1112
 
1102
- protected syncDataWithPrismic(): Promise<void> {
1113
+ protected pushDataToPrismic(): Promise<void> {
1103
1114
  return listrRun([
1104
1115
  {
1105
- title: "Syncing data with Prismic...",
1116
+ title: "Pushing data to Prismic...",
1106
1117
  task: (_, parentTask) =>
1107
1118
  listr([
1108
1119
  {
@@ -1198,7 +1209,7 @@ ${chalk.cyan("?")} Your Prismic repository name`.replace("\n", ""),
1198
1209
  task: async (_, task) => {
1199
1210
  assertExists(
1200
1211
  this.context.repository,
1201
- "Repository selection must be available through context to run `syncDataWithPrismic`",
1212
+ "Repository selection must be available through context to run `pushDataToPrismic`",
1202
1213
  );
1203
1214
 
1204
1215
  try {
@@ -1208,6 +1219,7 @@ ${chalk.cyan("?")} Your Prismic repository name`.replace("\n", ""),
1208
1219
  documentsRead === undefined ||
1209
1220
  documentsRead.documents.length === 0
1210
1221
  ) {
1222
+ parentTask.title = "Pushed data to Prismic";
1211
1223
  task.skip("No document to push");
1212
1224
 
1213
1225
  return;
@@ -1249,7 +1261,9 @@ ${chalk.cyan("?")} Your Prismic repository name`.replace("\n", ""),
1249
1261
  });
1250
1262
 
1251
1263
  task.title = "Pushed all documents";
1264
+ parentTask.title = "Pushed data to Prismic";
1252
1265
  } catch {
1266
+ parentTask.title = "Pushed data to Prismic";
1253
1267
  task.skip("No document to push");
1254
1268
 
1255
1269
  return;
@@ -1271,41 +1285,7 @@ ${chalk.cyan("?")} Your Prismic repository name`.replace("\n", ""),
1271
1285
  }
1272
1286
 
1273
1287
  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";
1288
+ parentTask.title = "Pushed data to Prismic";
1309
1289
  },
1310
1290
  },
1311
1291
  ]),
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,13 @@
1
+ import * as Sentry from "@sentry/node";
2
+
3
+ import { checkIsSentryEnabled } from "./checkIsSentryEnabled";
4
+
5
+ export function trackSentryError(error: unknown): void {
6
+ if (!checkIsSentryEnabled()) {
7
+ return;
8
+ }
9
+
10
+ Sentry.captureException(error, {
11
+ ...(error instanceof Error ? { extra: { cause: error.cause } } : {}),
12
+ });
13
+ }
@@ -0,0 +1,23 @@
1
+ import * as Sentry from "@sentry/node";
2
+ import semver from "semver";
3
+
4
+ import { SENTRY_EXPRESS_DSN } from "../constants";
5
+ import { checkIsSentryEnabled } from "./checkIsSentryEnabled";
6
+ import { version } from "../../package.json";
7
+
8
+ export function setupSentry(): void {
9
+ if (!checkIsSentryEnabled()) {
10
+ return;
11
+ }
12
+
13
+ const isStableVersion =
14
+ semver.prerelease(version) === null && semver.lte("0.1.0", version);
15
+
16
+ Sentry.init({
17
+ dsn: SENTRY_EXPRESS_DSN,
18
+ release: version,
19
+ environment: isStableVersion
20
+ ? import.meta.env.MODE || "production"
21
+ : "alpha",
22
+ });
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
+ }