Skip to content

Commit bd3f69d

Browse files
fix(cli): fix CI command hanging due to process.exit calls (#1149)
* fix(cli): remove posthog shutdown to prevent hanging - Extract createPosthogClient() as a reusable function - Remove posthog.shutdown() call that was causing process to hang - PostHog with flushAt:1 sends events immediately, shutdown not needed * chore(cli): upgrade posthog-node to 5.8.1 - Upgrade from 5.5.1 to 5.8.1 for better stability - Latest version may have improved handling of process exits * fix(cli): replace process.exit with exceptions in commands - Replace process.exit(1) with throw new Error() in i18n command - Replace process.exit(1) with throw error in run command - Remove exitGracefully() calls as no longer needed - This fixes CI command integration where process.exit() was terminating the parent process instead of returning control * style: apply prettier formatting * docs: add changeset for CI command fix * chore: prettier
1 parent aba7db1 commit bd3f69d

File tree

7 files changed

+55
-30
lines changed

7 files changed

+55
-30
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
"lingo.dev": patch
3+
---
4+
5+
Fix CI command hanging due to process.exit calls
6+
7+
- Remove PostHog shutdown() call that was causing process to hang
8+
- Replace process.exit() with proper exception throwing in i18n and run commands
9+
- Upgrade posthog-node from 5.5.1 to 5.8.1 for better stability
10+
- This fixes the CI command integration where process.exit() was terminating the parent process instead of returning control

packages/cli/README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535
</a>
3636
</p>
3737

38-
3938
---
4039

4140
## Meet the Compiler 🆕

packages/cli/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@
182182
"p-limit": "^6.2.0",
183183
"php-array-reader": "^2.1.2",
184184
"plist": "^3.1.0",
185-
"posthog-node": "^5.5.1",
185+
"posthog-node": "^5.8.1",
186186
"prettier": "^3.4.2",
187187
"react": "^18.3.1",
188188
"rehype-stringify": "^10.0.1",

packages/cli/src/cli/cmd/i18n.ts

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ import createProcessor from "../processor";
2424
import { withExponentialBackoff } from "../utils/exp-backoff";
2525
import trackEvent from "../utils/observability";
2626
import { createDeltaProcessor } from "../utils/delta";
27-
import { exitGracefully } from "../utils/exit-gracefully";
2827

2928
export default new Command()
3029
.command("i18n")
@@ -117,7 +116,7 @@ export default new Command()
117116
ora.succeed(`Authenticated as ${auth.email}`);
118117
}
119118

120-
trackEvent(authId, "cmd.i18n.start", {
119+
await trackEvent(authId, "cmd.i18n.start", {
121120
i18nConfig,
122121
flags,
123122
});
@@ -143,7 +142,9 @@ export default new Command()
143142
ora.fail(
144143
"No buckets found. All buckets were filtered out by --file option.",
145144
);
146-
process.exit(1);
145+
throw new Error(
146+
"No buckets found. All buckets were filtered out by --file option.",
147+
);
147148
} else {
148149
ora.info(`\x1b[36mProcessing only filtered buckets:\x1b[0m`);
149150
buckets.map((bucket: any) => {
@@ -296,7 +297,9 @@ export default new Command()
296297
`Localization data has changed; please update i18n.lock or run without --frozen.`,
297298
);
298299
ora.fail(` Details: ${message}`);
299-
process.exit(1);
300+
throw new Error(
301+
`Localization data has changed; please update i18n.lock or run without --frozen. Details: ${message}`,
302+
);
300303
} else {
301304
ora.succeed("No lockfile updates required.");
302305
}
@@ -499,25 +502,23 @@ export default new Command()
499502
console.log();
500503
if (!hasErrors) {
501504
ora.succeed("Localization completed.");
502-
trackEvent(authId, "cmd.i18n.success", {
505+
await trackEvent(authId, "cmd.i18n.success", {
503506
i18nConfig,
504507
flags,
505508
});
506509
} else {
507510
ora.warn("Localization completed with errors.");
508-
trackEvent(authId || "unknown", "cmd.i18n.error", {
511+
await trackEvent(authId || "unknown", "cmd.i18n.error", {
509512
flags,
510513
});
511514
}
512-
exitGracefully();
513515
} catch (error: any) {
514516
ora.fail(error.message);
515517

516-
trackEvent(authId || "unknown", "cmd.i18n.error", {
518+
await trackEvent(authId || "unknown", "cmd.i18n.error", {
517519
flags,
518520
error,
519521
});
520-
process.exit(1);
521522
}
522523
});
523524

packages/cli/src/cli/cmd/run/index.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import {
1414
} from "../../utils/ui";
1515
import trackEvent from "../../utils/observability";
1616
import { determineAuthId } from "./_utils";
17-
import { exitGracefully } from "../../utils/exit-gracefully";
1817

1918
export default new Command()
2019
.command("run")
@@ -92,7 +91,7 @@ export default new Command()
9291

9392
authId = await determineAuthId(ctx);
9493

95-
trackEvent(authId, "cmd.run.start", {
94+
await trackEvent(authId, "cmd.run.start", {
9695
config: ctx.config,
9796
flags: ctx.flags,
9897
});
@@ -113,13 +112,12 @@ export default new Command()
113112
await watch(ctx);
114113
}
115114

116-
trackEvent(authId, "cmd.run.success", {
115+
await trackEvent(authId, "cmd.run.success", {
117116
config: ctx.config,
118117
flags: ctx.flags,
119118
});
120-
exitGracefully();
121119
} catch (error: any) {
122-
trackEvent(authId || "unknown", "cmd.run.error", {});
123-
process.exit(1);
120+
await trackEvent(authId || "unknown", "cmd.run.error", {});
121+
throw error;
124122
}
125123
});

packages/cli/src/cli/utils/observability.ts

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,20 @@
11
import pkg from "node-machine-id";
22
const { machineIdSync } = pkg;
33

4+
export async function createPosthogClient() {
5+
const { PostHog } = await import("posthog-node");
6+
const posthog = new PostHog(
7+
"phc_eR0iSoQufBxNY36k0f0T15UvHJdTfHlh8rJcxsfhfXk",
8+
{
9+
host: "https://eu.i.posthog.com",
10+
flushAt: 1,
11+
flushInterval: 0,
12+
},
13+
);
14+
15+
return posthog;
16+
}
17+
418
export default async function trackEvent(
519
distinctId: string | null | undefined,
620
event: string,
@@ -13,15 +27,7 @@ export default async function trackEvent(
1327
try {
1428
const actualId = distinctId || `device-${machineIdSync()}`;
1529

16-
const { PostHog } = await import("posthog-node");
17-
const posthog = new PostHog(
18-
"phc_eR0iSoQufBxNY36k0f0T15UvHJdTfHlh8rJcxsfhfXk",
19-
{
20-
host: "https://eu.i.posthog.com",
21-
flushAt: 1,
22-
flushInterval: 0,
23-
},
24-
);
30+
const posthog = await createPosthogClient();
2531

2632
await posthog.capture({
2733
distinctId: actualId,
@@ -34,8 +40,6 @@ export default async function trackEvent(
3440
},
3541
},
3642
});
37-
38-
await posthog.shutdown();
3943
} catch (error) {
4044
if (process.env.DEBUG) {
4145
console.error(error);

pnpm-lock.yaml

Lines changed: 15 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)