Skip to content

Commit

Permalink
fix(cli): CLI freezes before continuing (#1480)
Browse files Browse the repository at this point in the history
  • Loading branch information
chanceaclark authored Oct 18, 2024
1 parent 0686074 commit eb1707b
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 42 deletions.
5 changes: 5 additions & 0 deletions .changeset/dirty-starfishes-guess.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@bigcommerce/create-catalyst": patch
---

Fix the CLI from hanging while waiting for segment.
74 changes: 32 additions & 42 deletions packages/create-catalyst/src/utils/telemetry/telemetry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,54 +46,44 @@ export class Telemetry {
}

async track(eventName: string, payload: Record<string, unknown>) {
await new Promise((resolve) => {
if (!this.isEnabled()) {
resolve(undefined);
}

this.analytics.track(
{
event: eventName,
anonymousId: this.getAnonymousId(),
properties: {
...payload,
sessionId: this.sessionId,
},
context: {
app: {
name: this.projectName,
version: this.projectVersion,
},
},
if (!this.isEnabled()) {
return Promise.resolve(undefined);
}

this.analytics.track({
event: eventName,
anonymousId: this.getAnonymousId(),
properties: {
...payload,
sessionId: this.sessionId,
},
context: {
app: {
name: this.projectName,
version: this.projectVersion,
},
resolve,
);
},
});
}

async identify(storeHash?: string) {
await new Promise((resolve) => {
if (!this.isEnabled()) {
resolve(undefined);
}

if (!storeHash) {
resolve(undefined);
}

this.analytics.identify(
{
userId: storeHash,
anonymousId: this.getAnonymousId(),
context: {
app: {
name: this.projectName,
version: this.projectVersion,
},
},
if (!this.isEnabled()) {
return Promise.resolve(undefined);
}

if (!storeHash) {
return Promise.resolve(undefined);
}

this.analytics.identify({
userId: storeHash,
anonymousId: this.getAnonymousId(),
context: {
app: {
name: this.projectName,
version: this.projectVersion,
},
resolve,
);
},
});
}

Expand Down

0 comments on commit eb1707b

Please sign in to comment.