summaryrefslogtreecommitdiff
path: root/packages/core/src/utils/getPty.ts
diff options
context:
space:
mode:
authorGal Zahavi <[email protected]>2025-08-19 16:03:51 -0700
committerGitHub <[email protected]>2025-08-19 23:03:51 +0000
commitf1575f6d8de2f4efa0805a2d11a4a421a1a8228f (patch)
tree8977235b9a42983de3e76189f25ff055e9d28a83 /packages/core/src/utils/getPty.ts
parent0cc2a1e7ef904294fff982a4d75bf098b5b262f7 (diff)
feat(core): refactor shell execution to use node-pty (#6491)
Co-authored-by: Jacob Richman <[email protected]>
Diffstat (limited to 'packages/core/src/utils/getPty.ts')
-rw-r--r--packages/core/src/utils/getPty.ts34
1 files changed, 34 insertions, 0 deletions
diff --git a/packages/core/src/utils/getPty.ts b/packages/core/src/utils/getPty.ts
new file mode 100644
index 00000000..2d7cb16f
--- /dev/null
+++ b/packages/core/src/utils/getPty.ts
@@ -0,0 +1,34 @@
+/**
+ * @license
+ * Copyright 2025 Google LLC
+ * SPDX-License-Identifier: Apache-2.0
+ */
+
+export type PtyImplementation = {
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
+ module: any;
+ name: 'lydell-node-pty' | 'node-pty';
+} | null;
+
+export interface PtyProcess {
+ readonly pid: number;
+ onData(callback: (data: string) => void): void;
+ onExit(callback: (e: { exitCode: number; signal?: number }) => void): void;
+ kill(signal?: string): void;
+}
+
+export const getPty = async (): Promise<PtyImplementation> => {
+ try {
+ const lydell = '@lydell/node-pty';
+ const module = await import(lydell);
+ return { module, name: 'lydell-node-pty' };
+ } catch (_e) {
+ try {
+ const nodePty = 'node-pty';
+ const module = await import(nodePty);
+ return { module, name: 'node-pty' };
+ } catch (_e2) {
+ return null;
+ }
+ }
+};