MCPcopy Index your code
hub / github.com/codeceptjs/CodeceptJS / loadConfigFile

Function loadConfigFile

lib/config.js:213–308  ·  view source on GitHub ↗
(configFile)

Source from the content-addressed store, hash-verified

211export default Config
212
213async function loadConfigFile(configFile) {
214 const require = createRequire(import.meta.url)
215 const extensionName = path.extname(configFile)
216
217 // Populate the in-process registry that packages like @codeceptjs/configure
218 // look up at config-import time (their proxies throw if `globalThis.codeceptjs`
219 // is missing). initCodeceptGlobals sets this too, but only later during
220 // bootstrap — config files are imported here first.
221 if (!globalThis.codeceptjs) {
222 const indexModule = await import('./index.js')
223 globalThis.codeceptjs = indexModule.default || indexModule
224 }
225
226 // .conf.js config file
227 if (extensionName === '.js' || extensionName === '.ts' || extensionName === '.cjs') {
228 let configModule
229 try {
230 // For .ts files, try to compile and load as JavaScript
231 if (extensionName === '.ts') {
232 let transpileError = null
233 let tempFile = null
234 let allTempFiles = null
235 let fileMapping = null
236
237 try {
238 // Use the TypeScript transpilation utility
239 const typescript = require('typescript')
240 const result = await transpileTypeScript(configFile, typescript)
241 tempFile = result.tempFile
242 allTempFiles = result.allTempFiles
243 fileMapping = result.fileMapping
244
245 const resolvedPath = resolveImportModulePath(tempFile)
246 configModule = await import(resolvedPath)
247 cleanupTempFiles(allTempFiles)
248 } catch (err) {
249 transpileError = err
250 if (fileMapping) {
251 fixErrorStack(err, fileMapping)
252 }
253 if (allTempFiles) {
254 cleanupTempFiles(allTempFiles)
255 }
256 // Throw immediately with the actual error - don't fall back to ts-node
257 // as it will mask the real error with "Unexpected token 'export'"
258 throw err
259 }
260 } else {
261 // Try ESM import first for JS files
262 const resolvedPath = resolveImportModulePath(configFile)
263 configModule = await import(resolvedPath)
264 }
265 } catch (importError) {
266 try {
267 // Fall back to CommonJS require for .js/.cjs files
268 if (extensionName !== '.ts') {
269 configModule = require(configFile)
270 } else {

Callers 1

loadMethod · 0.85

Calls 6

transpileTypeScriptFunction · 0.90
resolveImportModulePathFunction · 0.90
cleanupTempFilesFunction · 0.90
fixErrorStackFunction · 0.90
entriesMethod · 0.80
createMethod · 0.45

Tested by

no test coverage detected