Skip to content

Commit 90b6d1b

Browse files
committed
feat(resolveConfig): replace "find-package-json" with "new-find-package-json"
fixes #495 fixes #494
1 parent fce6a07 commit 90b6d1b

File tree

3 files changed

+161
-328
lines changed

3 files changed

+161
-328
lines changed

packages/mongodb-memory-server-core/package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333
"devDependencies": {
3434
"@types/debug": "^4.1.6",
3535
"@types/find-cache-dir": "^3.2.0",
36-
"@types/find-package-json": "^1.2.1",
3736
"@types/mkdirp": "^1.0.1",
3837
"@types/mongodb": "^3.6.19",
3938
"@types/semver": "^7.3.6",
@@ -48,7 +47,7 @@
4847
"camelcase": "^6.1.0",
4948
"debug": "^4.2.0",
5049
"find-cache-dir": "^3.3.1",
51-
"find-package-json": "^1.2.0",
50+
"new-find-package-json": "^1.1.0",
5251
"get-port": "^5.1.1",
5352
"https-proxy-agent": "^5.0.0",
5453
"md5-file": "^5.0.0",

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import camelCase from 'camelcase';
2-
import finder from 'find-package-json';
2+
import { findSync } from 'new-find-package-json';
33
import debug from 'debug';
44
import * as path from 'path';
5+
import { readFileSync } from 'fs';
56

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

@@ -48,16 +49,15 @@ let packageJsonConfig: Record<string, string> = {};
4849
*/
4950
export function findPackageJson(directory?: string): Record<string, string> {
5051
let filename: string | undefined;
51-
for (const found of finder(directory || process.cwd())) {
52-
// 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
53-
filename = found.__path as string;
52+
for (const filename of findSync(directory || process.cwd())) {
5453
log(`findPackageJson: Found package.json at "${filename}"`);
54+
const readout: Record<string, any> = JSON.parse(readFileSync(filename).toString());
5555

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

5959
// the optional chaining is needed, because typescript wont accept an "isNullOrUndefined" in the if with "&& Object.keys"
60-
packageJsonConfig = found?.config?.mongodbMemoryServer;
60+
packageJsonConfig = readout?.config?.mongodbMemoryServer;
6161
break;
6262
}
6363
}

0 commit comments

Comments
 (0)