|
1 | 1 | import camelCase from 'camelcase'; |
2 | | -import finder from 'find-package-json'; |
| 2 | +import { findSync } from 'new-find-package-json'; |
3 | 3 | import debug from 'debug'; |
4 | 4 | import * as path from 'path'; |
| 5 | +import { readFileSync } from 'fs'; |
5 | 6 |
|
6 | 7 | const log = debug('MongoMS:ResolveConfig'); |
7 | 8 |
|
@@ -48,16 +49,15 @@ let packageJsonConfig: Record<string, string> = {}; |
48 | 49 | */ |
49 | 50 | export function findPackageJson(directory?: string): Record<string, string> { |
50 | 51 | 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())) { |
54 | 53 | log(`findPackageJson: Found package.json at "${filename}"`); |
| 54 | + const readout: Record<string, any> = JSON.parse(readFileSync(filename).toString()); |
55 | 55 |
|
56 | | - if (Object.keys(found?.config?.mongodbMemoryServer ?? {}).length > 0) { |
| 56 | + if (Object.keys(readout?.config?.mongodbMemoryServer ?? {}).length > 0) { |
57 | 57 | log(`findPackageJson: Found package with non-empty config field at "${filename}"`); |
58 | 58 |
|
59 | 59 | // 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; |
61 | 61 | break; |
62 | 62 | } |
63 | 63 | } |
|
0 commit comments