Skip to content

Commit

Permalink
fix(resolveConfig::findPackageJson): actually apply processing to pat…
Browse files Browse the repository at this point in the history
…h options

fixes #548
  • Loading branch information
hasezoey committed Oct 5, 2021
1 parent 8933f39 commit 25c4119
Showing 1 changed file with 5 additions and 10 deletions.
15 changes: 5 additions & 10 deletions packages/mongodb-memory-server-core/src/util/resolveConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ let packageJsonConfig: Record<string, string> = {};
* @param directory Set an custom directory to search the config in (default: process.cwd())
*/
export function findPackageJson(directory?: string): Record<string, string> {
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<string, any> = JSON.parse(readFileSync(filename).toString());
Expand All @@ -60,29 +60,24 @@ export function findPackageJson(directory?: string): Record<string, string> {

// 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]);
}
}

Expand Down

0 comments on commit 25c4119

Please sign in to comment.