MCPcopy
hub / github.com/prisma/prisma / handleNpsSurvey

Function handleNpsSurvey

packages/cli/src/utils/nps/survey.ts:36–73  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

34const debug = Debug('prisma:cli:nps')
35
36export 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.

Callers

nothing calls this directly

Calls 11

isInteractiveFunction · 0.90
debugFunction · 0.85
handleNpsSurveyImplFunction · 0.85
createSafeReadlineProxyFunction · 0.85
closeMethod · 0.80
finallyMethod · 0.80
catchMethod · 0.80
onMethod · 0.65
writeMethod · 0.65
thenMethod · 0.65

Tested by

no test coverage detected