forked from prisma/prisma
-
Notifications
You must be signed in to change notification settings - Fork 0
/
DebugInfo.ts
159 lines (127 loc) · 4.15 KB
/
DebugInfo.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
import type { Command } from '@prisma/internals'
import {
arg,
format,
getSchemaPath,
HelpError,
isCi,
isError,
isInteractive,
link,
loadEnvFile,
} from '@prisma/internals'
import { bold, dim, red, underline } from 'kleur/colors'
import { getRootCacheDir } from '../../fetch-engine/src/utils'
/**
* $ prisma debug
*/
export class DebugInfo implements Command {
static new(): DebugInfo {
return new DebugInfo()
}
private static help = format(`
Print information helpful for debugging and bug reports
${bold('Usage')}
${dim('$')} prisma debug [options]
${bold('Options')}
-h, --help Display this help message
--schema Custom path to your Prisma schema
`)
async parse(argv: string[]): Promise<string | Error> {
const args = arg(argv, {
'--help': Boolean,
'-h': '--help',
'--schema': String,
'--telemetry-information': String,
})
if (isError(args)) {
return this.help(args.message)
}
if (args['--help']) {
return this.help()
}
loadEnvFile({ schemaPath: args['--schema'], printMessage: true })
const formatEnvValue = (name: string, text?: string) => {
const value = process.env[name]
const line = `- ${name}${text ? ` ${text}` : ''}`
if (value === undefined) {
return dim(line + ':')
}
return bold(line + `: \`${value}\``)
}
let schemaPath
try {
schemaPath = link(await getSchemaPath(args['--schema']))
} catch (e) {
schemaPath = e.message
}
const rootCacheDir = link(await getRootCacheDir())
return `${underline('-- Prisma schema --')}
Path: ${schemaPath}
${underline('-- Local cache directory for engines files --')}
Path: ${rootCacheDir}
${underline('-- Environment variables --')}
When not set, the line is dimmed and no value is displayed.
When set, the line is bold and the value is inside the \`\` backticks.
For general debugging
${formatEnvValue('CI')}
${formatEnvValue('DEBUG')}
${formatEnvValue('NODE_ENV')}
${formatEnvValue('RUST_LOG')}
${formatEnvValue('RUST_BACKTRACE')}
${formatEnvValue('NO_COLOR')}
${formatEnvValue('TERM')}
${formatEnvValue('NODE_TLS_REJECT_UNAUTHORIZED')}
${formatEnvValue('NO_PROXY')}
${formatEnvValue('http_proxy')}
${formatEnvValue('HTTP_PROXY')}
${formatEnvValue('https_proxy')}
${formatEnvValue('HTTPS_PROXY')}
For more information about Prisma environment variables:
See ${link('https://www.prisma.io/docs/reference/api-reference/environment-variables-reference')}
For hiding messages
${formatEnvValue('PRISMA_DISABLE_WARNINGS')}
${formatEnvValue('PRISMA_HIDE_PREVIEW_FLAG_WARNINGS')}
${formatEnvValue('PRISMA_HIDE_UPDATE_MESSAGE')}
For downloading engines
${formatEnvValue('PRISMA_ENGINES_MIRROR')}
${formatEnvValue('PRISMA_BINARIES_MIRROR', '(deprecated)')}
${formatEnvValue('PRISMA_ENGINES_CHECKSUM_IGNORE_MISSING')}
${formatEnvValue('BINARY_DOWNLOAD_VERSION')}
For configuring the Query Engine Type
${formatEnvValue('PRISMA_CLI_QUERY_ENGINE_TYPE')}
${formatEnvValue('PRISMA_CLIENT_ENGINE_TYPE')}
For custom engines
${formatEnvValue('PRISMA_QUERY_ENGINE_BINARY')}
${formatEnvValue('PRISMA_QUERY_ENGINE_LIBRARY')}
${formatEnvValue('PRISMA_SCHEMA_ENGINE_BINARY')}
${formatEnvValue('PRISMA_MIGRATION_ENGINE_BINARY')}
For the "postinstall" npm hook
${formatEnvValue('PRISMA_GENERATE_SKIP_AUTOINSTALL')}
${formatEnvValue('PRISMA_SKIP_POSTINSTALL_GENERATE')}
${formatEnvValue('PRISMA_GENERATE_IN_POSTINSTALL')}
For "prisma generate"
${formatEnvValue('PRISMA_GENERATE_DATAPROXY')}
${formatEnvValue('PRISMA_GENERATE_NO_ENGINE')}
For Prisma Client
${formatEnvValue('PRISMA_SHOW_ALL_TRACES')}
${formatEnvValue('PRISMA_CLIENT_NO_RETRY', '(Binary engine only)')}
For Prisma Migrate
${formatEnvValue('PRISMA_SCHEMA_DISABLE_ADVISORY_LOCK')}
${formatEnvValue('PRISMA_MIGRATE_SKIP_GENERATE')}
${formatEnvValue('PRISMA_MIGRATE_SKIP_SEED')}
For Prisma Studio
${formatEnvValue('BROWSER')}
${underline('-- Terminal is interactive? --')}
${isInteractive()}
${underline('-- CI detected? --')}
${isCi()}
`
}
public help(error?: string): string | HelpError {
if (error) {
return new HelpError(`\n${bold(red(`!`))} ${error}\n${DebugInfo.help}`)
}
return DebugInfo.help
}
}