diff --git a/packages/mongodb-memory-server-core/src/util/resolveConfig.ts b/packages/mongodb-memory-server-core/src/util/resolveConfig.ts index 5be557c59..9dfe78ad6 100644 --- a/packages/mongodb-memory-server-core/src/util/resolveConfig.ts +++ b/packages/mongodb-memory-server-core/src/util/resolveConfig.ts @@ -50,7 +50,7 @@ let packageJsonConfig: Record = {}; * @param directory Set an custom directory to search the config in (default: process.cwd()) */ export function findPackageJson(directory?: string): Record { - let filename: string | undefined; + let filepath: string | undefined; for (const filename of findSync(directory || process.cwd())) { log(`findPackageJson: Found package.json at "${filename}"`); const readout: Record = JSON.parse(readFileSync(filename).toString()); @@ -60,29 +60,24 @@ export function findPackageJson(directory?: string): Record { // the optional chaining is needed, because typescript wont accept an "isNullOrUndefined" in the if with "&& Object.keys" packageJsonConfig = readout?.config?.mongodbMemoryServer; + filepath = path.dirname(filename); break; } } // block for all file-path resolving - if (filename) { + if (filepath) { // These are so that "camelCase" doesnt get executed much & de-duplicate code // "cc*" means "camelcase" const ccDownloadDir = camelCase(ResolveConfigVariables.DOWNLOAD_DIR); const ccSystemBinary = camelCase(ResolveConfigVariables.SYSTEM_BINARY); if (ccDownloadDir in packageJsonConfig) { - packageJsonConfig[ccDownloadDir] = path.resolve( - path.dirname(filename), - packageJsonConfig[ccDownloadDir] - ); + packageJsonConfig[ccDownloadDir] = path.resolve(filepath, packageJsonConfig[ccDownloadDir]); } if (ccSystemBinary in packageJsonConfig) { - packageJsonConfig[ccSystemBinary] = path.resolve( - path.dirname(filename), - packageJsonConfig[ccSystemBinary] - ); + packageJsonConfig[ccSystemBinary] = path.resolve(filepath, packageJsonConfig[ccSystemBinary]); } }