()
| 34 | const debug = Debug('prisma:cli:nps') |
| 35 | |
| 36 | export async function handleNpsSurvey() { |
| 37 | if (!isInteractive()) { |
| 38 | // no point in running the NPS survey if there's no TTY |
| 39 | return |
| 40 | } |
| 41 | |
| 42 | if ('Deno' in globalThis) { |
| 43 | // For some reason merely creating the readline interface on Deno |
| 44 | // doesn't allow `prisma generate` to finish until Enter is pressed. |
| 45 | return |
| 46 | } |
| 47 | |
| 48 | const now = new Date() |
| 49 | |
| 50 | const rl = readline.promises.createInterface({ |
| 51 | input: process.stdin, |
| 52 | output: process.stdout, |
| 53 | }) |
| 54 | |
| 55 | rl.on('error', (err) => { |
| 56 | debug(`A readline error occurred while handling NPS survey: ${err}`) |
| 57 | }) |
| 58 | rl.on('SIGINT', () => { |
| 59 | rl.write('Received SIGINT, closing the survey.\n') |
| 60 | rl.close() |
| 61 | }) |
| 62 | |
| 63 | const status = new ProdNpsStatusLookup() |
| 64 | const eventCapture = new PosthogEventCapture(PUBLIC_POSTHOG_NPS_PROJECT_KEY) |
| 65 | |
| 66 | await loadOrInitializeCommandState() |
| 67 | .then((state) => handleNpsSurveyImpl(now, status, createSafeReadlineProxy(rl), eventCapture, state)) |
| 68 | .catch((err) => { |
| 69 | // we don't want to propagate NPS survey errors, so we catch them here and log them |
| 70 | debug(`An error occurred while handling NPS survey: ${err}`) |
| 71 | }) |
| 72 | .finally(() => rl.close()) |
| 73 | } |
| 74 | |
| 75 | /** |
| 76 | * Creates a proxy that aborts the readline interface when the underlying stream closes. |
nothing calls this directly
no test coverage detected