|
1 | 1 | import camelCase from 'camelcase'; |
2 | | -import finder from 'find-package-json'; |
| 2 | +import finder, { FinderIterator, Package } from 'find-package-json'; |
3 | 3 | import debug from 'debug'; |
4 | 4 | import * as path from 'path'; |
5 | 5 |
|
6 | 6 | const log = debug('MongoMS:ResolveConfig'); |
7 | 7 |
|
| 8 | +// Workaround, because that package dosnt implement the default iterator |
| 9 | +interface CustomFinderIterator extends FinderIterator { |
| 10 | + [Symbol.iterator](): Iterator<Package>; |
| 11 | +} |
| 12 | + |
8 | 13 | export enum ResolveConfigVariables { |
9 | 14 | DOWNLOAD_DIR = 'DOWNLOAD_DIR', |
10 | 15 | PLATFORM = 'PLATFORM', |
@@ -41,9 +46,17 @@ let packageJsonConfig: Record<string, string> = {}; |
41 | 46 | * @param directory Set an custom directory to search the config in (default: process.cwd()) |
42 | 47 | */ |
43 | 48 | export function findPackageJson(directory?: string): Record<string, string> { |
44 | | - const finderIterator = finder(directory || process.cwd()).next(); |
45 | | - log(`Using package.json at "${finderIterator.filename}"`); |
46 | | - packageJsonConfig = finderIterator.value?.config?.mongodbMemoryServer ?? {}; |
| 49 | + for (const found of finder(directory || process.cwd()) as CustomFinderIterator) { |
| 50 | + log(`findPackageJson: Found package.json"`); |
| 51 | + |
| 52 | + if (Object.keys(found?.config?.mongodbMemoryServer ?? {}).length > 0) { |
| 53 | + log(`findPackageJson: Found package with non-empty config field"`); |
| 54 | + |
| 55 | + // the optional chaining is needed, because typescript wont accept an "isNullOrUndefined" in the if with "&& Object.keys" |
| 56 | + packageJsonConfig = found?.config?.mongodbMemoryServer; |
| 57 | + break; |
| 58 | + } |
| 59 | + } |
47 | 60 |
|
48 | 61 | // block for all file-path resolving |
49 | 62 | { |
|
0 commit comments