Skip to content

Commit 3709425

Browse files
authored
feat: prevent users from running wizard in non tty env (#114)
1 parent 86a0086 commit 3709425

2 files changed

Lines changed: 30 additions & 1 deletion

File tree

bin.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { red } from './src/utils/logging';
44

55
import yargs from 'yargs';
66
import { hideBin } from 'yargs/helpers';
7+
import chalk from 'chalk';
78

89
const NODE_VERSION_RANGE = '>=18.17.0';
910

@@ -20,8 +21,23 @@ import { runMCPInstall, runMCPRemove } from './src/mcp';
2021
import type { CloudRegion, WizardOptions } from './src/utils/types';
2122
import { runWizard } from './src/run';
2223
import { runEventSetupWizard } from './src/nextjs/event-setup';
23-
import { readEnvironment } from './src/utils/environment';
24+
import {
25+
readEnvironment,
26+
isNonInteractiveEnvironment,
27+
} from './src/utils/environment';
2428
import path from 'path';
29+
import clack from './src/utils/clack';
30+
31+
if (isNonInteractiveEnvironment()) {
32+
clack.intro(chalk.inverse(`PostHog Wizard`));
33+
34+
clack.log.error(
35+
'This installer requires an interactive terminal (TTY) to run.\n' +
36+
'It appears you are running in a non-interactive environment.\n' +
37+
'Please run the wizard in an interactive terminal.',
38+
);
39+
process.exit(1);
40+
}
2541

2642
if (process.env.NODE_ENV === 'test') {
2743
void (async () => {

src/utils/environment.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,19 @@ import readEnv from 'read-env';
22
import { getPackageDotJson } from './clack-utils';
33
import type { WizardOptions } from './types';
44
import fg from 'fast-glob';
5+
import { IS_DEV } from '../lib/constants';
6+
7+
export function isNonInteractiveEnvironment(): boolean {
8+
if (IS_DEV) {
9+
return false;
10+
}
11+
12+
if (!process.stdout.isTTY || !process.stderr.isTTY) {
13+
return true;
14+
}
15+
16+
return false;
17+
}
518

619
export function readEnvironment(): Record<string, unknown> {
720
const result = readEnv('POSTHOG_WIZARD');

0 commit comments

Comments
 (0)