({
configFile,
configRoot = process.cwd(),
}: LoadConfigFromFileInput)
| 90 | */ |
| 91 | |
| 92 | export 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, |
no test coverage detected