MCPcopy
hub / github.com/prisma/prisma / loadConfigTsOrJs

Function loadConfigTsOrJs

packages/config/src/loadConfigFromFile.ts:170–257  ·  view source on GitHub ↗
(configRoot: string, configFile: string | undefined)

Source from the content-addressed store, hash-verified

168}
169
170async function loadConfigTsOrJs(configRoot: string, configFile: string | undefined) {
171 const { loadConfig: loadConfigWithC12 } = await import('c12')
172 const { deepmerge } = await import('deepmerge-ts')
173
174 try {
175 const {
176 config,
177 configFile: _resolvedPath,
178 meta,
179 } = await loadConfigWithC12({
180 cwd: configRoot,
181 // configuration base name
182 name: 'prisma',
183 // the config file to load (without file extensions), defaulting to `${cwd}.${name}`
184 configFile,
185 // do not load .env files
186 dotenv: false,
187 // do not load RC config
188 rcFile: false,
189 // do not extend remote config files
190 giget: false,
191 // do not extend the default config
192 extend: false,
193 // do not load from nearest package.json
194 packageJson: false,
195
196 // @ts-expect-error: this is a type-error in `c12` itself
197 merger: deepmerge,
198
199 jitiOptions: {
200 interopDefault: true,
201 moduleCache: false,
202 extensions: SUPPORTED_EXTENSIONS,
203 },
204 })
205
206 // Note: c12 apparently doesn't normalize paths on Windows, causing issues with Windows tests.
207 const resolvedPath = _resolvedPath ? path.normalize(_resolvedPath) : undefined
208 const doesConfigFileExist = resolvedPath !== undefined && meta !== undefined
209
210 if (configFile && !doesConfigFileExist) {
211 debug(`The given config file was not found at %s`, resolvedPath)
212 return {
213 require: null,
214 resolvedPath: path.join(configRoot, configFile),
215 error: { _tag: 'ConfigFileNotFound' } as const,
216 } as const
217 }
218
219 if (doesConfigFileExist) {
220 const extension = path.extname(path.basename(resolvedPath))
221
222 if (!(SUPPORTED_EXTENSIONS as string[]).includes(extension)) {
223 return {
224 configModule: config,
225 resolvedPath,
226 error: {
227 _tag: 'ConfigLoadError',

Callers 1

loadConfigFromFileFunction · 0.85

Calls 2

debugFunction · 0.85
includesMethod · 0.80

Tested by

no test coverage detected