Skip to content

Commit

Permalink
feat(resolveConfig): replace "find-package-json" with "new-find-packa…
Browse files Browse the repository at this point in the history
…ge-json"

fixes #495
fixes #494
  • Loading branch information
hasezoey committed Jul 5, 2021
1 parent fce6a07 commit 90b6d1b
Show file tree
Hide file tree
Showing 3 changed files with 161 additions and 328 deletions.
3 changes: 1 addition & 2 deletions packages/mongodb-memory-server-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
"devDependencies": {
"@types/debug": "^4.1.6",
"@types/find-cache-dir": "^3.2.0",
"@types/find-package-json": "^1.2.1",
"@types/mkdirp": "^1.0.1",
"@types/mongodb": "^3.6.19",
"@types/semver": "^7.3.6",
Expand All @@ -48,7 +47,7 @@
"camelcase": "^6.1.0",
"debug": "^4.2.0",
"find-cache-dir": "^3.3.1",
"find-package-json": "^1.2.0",
"new-find-package-json": "^1.1.0",
"get-port": "^5.1.1",
"https-proxy-agent": "^5.0.0",
"md5-file": "^5.0.0",
Expand Down
12 changes: 6 additions & 6 deletions packages/mongodb-memory-server-core/src/util/resolveConfig.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import camelCase from 'camelcase';
import finder from 'find-package-json';
import { findSync } from 'new-find-package-json';
import debug from 'debug';
import * as path from 'path';
import { readFileSync } from 'fs';

const log = debug('MongoMS:ResolveConfig');

Expand Down Expand Up @@ -48,16 +49,15 @@ let packageJsonConfig: Record<string, string> = {};
*/
export function findPackageJson(directory?: string): Record<string, string> {
let filename: string | undefined;
for (const found of finder(directory || process.cwd())) {
// 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
filename = found.__path as string;
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());

if (Object.keys(found?.config?.mongodbMemoryServer ?? {}).length > 0) {
if (Object.keys(readout?.config?.mongodbMemoryServer ?? {}).length > 0) {
log(`findPackageJson: Found package with non-empty config field at "${filename}"`);

// the optional chaining is needed, because typescript wont accept an "isNullOrUndefined" in the if with "&& Object.keys"
packageJsonConfig = found?.config?.mongodbMemoryServer;
packageJsonConfig = readout?.config?.mongodbMemoryServer;
break;
}
}
Expand Down

0 comments on commit 90b6d1b

Please sign in to comment.