MCPcopy
hub / github.com/prisma/prisma / loadConfigFromFile

Function loadConfigFromFile

packages/config/src/loadConfigFromFile.ts:92–168  ·  packages/config/src/loadConfigFromFile.ts::loadConfigFromFile
({
  configFile,
  configRoot = process.cwd(),
}: LoadConfigFromFileInput)

Source from the content-addressed store, hash-verified

90 */
91
92export async function loadConfigFromFile({
93 configFile,
94 configRoot = process.cwd(),
95}: LoadConfigFromFileInput): Promise<ConfigFromFile> {
96 const start = performance.now()
97 const getTime = () => `${(performance.now() - start).toFixed(2)}ms`
98
99 const diagnostics = [] as ConfigDiagnostic[]
100
101 try {
102 const { configModule, resolvedPath, error } = await loadConfigTsOrJs(configRoot, configFile)
103
104 if (error) {
105 return {
106 resolvedPath,
107 error,
108 diagnostics,
109 }
110 }
111
112 debug(`Config file loaded in %s`, getTime())
113
114 if (resolvedPath === null) {
115 debug(`No config file found in the current working directory %s`, configRoot)
116
117 return { resolvedPath: null, config: defaultConfig(), diagnostics }
118 }
119
120 let parsedConfig: PrismaConfigInternal | undefined
121
122 try {
123 parsedConfig = parseDefaultExport(configModule)
124 } catch (e) {
125 const error = e as Error
126 return {
127 resolvedPath,
128 error: {
129 _tag: class="st">'ConfigFileSyntaxError',
130 error,
131 },
132 diagnostics,
133 }
134 }
135
136 class="cm">// Note: this line fixes https://github.com/prisma/prisma/issues/27609.
137 diagnostics.push({
138 _tag: class="st">'log',
139 value:
140 ({ log, dim }) =>
141 () =>
142 log(dim(`Loaded Prisma config from ${path.relative(configRoot, resolvedPath)}.\n`)),
143 })
144
145 const prismaConfig = transformPathsInConfigToAbsolute(parsedConfig, resolvedPath)
146
147 return {
148 config: {
149 ...prismaConfig,

Callers 5

mainFunction · 0.90
loadConfigFunction · 0.90
runMethod · 0.90

Calls 8

defaultConfigFunction · 0.90
parseDefaultExportFunction · 0.90
loadConfigTsOrJsFunction · 0.85
debugFunction · 0.85
getTimeFunction · 0.85
logFunction · 0.50
pushMethod · 0.45

Tested by

no test coverage detected