Skip to content

Commit bc6ee8e

Browse files
committed
fix(resolveConfig): resolve download dir and system binary relative to found package.json
1 parent 06efcf1 commit bc6ee8e

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

packages/mongodb-memory-server-core/src/util/resolveConfig.ts

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,10 @@ let packageJsonConfig: Record<string, string> = {};
4747
* @param directory Set an custom directory to search the config in (default: process.cwd())
4848
*/
4949
export function findPackageJson(directory?: string): Record<string, string> {
50+
let filename: string | undefined;
5051
for (const found of finder(directory || process.cwd())) {
5152
// This is an hidden property, using this because an "for..of" loop dosnt return the "filename" value that is besides the "done" and "value" value
52-
const filename = found.__path as string;
53+
filename = found.__path as string;
5354
log(`findPackageJson: Found package.json at "${filename}"`);
5455

5556
if (Object.keys(found?.config?.mongodbMemoryServer ?? {}).length > 0) {
@@ -62,18 +63,24 @@ export function findPackageJson(directory?: string): Record<string, string> {
6263
}
6364

6465
// block for all file-path resolving
65-
{
66-
// These are so that "camelCase" dosnt get executed much & de-duplicate code
66+
if (filename) {
67+
// These are so that "camelCase" doesnt get executed much & de-duplicate code
6768
// "cc*" means "camelcase"
6869
const ccDownloadDir = camelCase(ResolveConfigVariables.DOWNLOAD_DIR);
6970
const ccSystemBinary = camelCase(ResolveConfigVariables.SYSTEM_BINARY);
7071

7172
if (ccDownloadDir in packageJsonConfig) {
72-
packageJsonConfig[ccDownloadDir] = path.resolve(packageJsonConfig[ccDownloadDir]);
73+
packageJsonConfig[ccDownloadDir] = path.resolve(
74+
path.dirname(filename),
75+
packageJsonConfig[ccDownloadDir]
76+
);
7377
}
7478

7579
if (ccSystemBinary in packageJsonConfig) {
76-
packageJsonConfig[ccSystemBinary] = path.resolve(packageJsonConfig[ccSystemBinary]);
80+
packageJsonConfig[ccSystemBinary] = path.resolve(
81+
path.dirname(filename),
82+
packageJsonConfig[ccSystemBinary]
83+
);
7784
}
7885
}
7986

0 commit comments

Comments
 (0)