Skip to content

Commit dcb9c9c

Browse files
committed
fix(MongoBinary): unwrap deeply nested cache directory
Closes #168
1 parent f37458c commit dcb9c9c

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

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

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,13 @@ export default class MongoBinary {
103103

104104
static async getPath(opts: MongoBinaryOpts = {}): Promise<string> {
105105
const legacyDLDir = path.resolve(os.homedir(), '.cache/mongodb-binaries');
106+
107+
// if we're in postinstall script, npm will set the cwd too deep
108+
let nodeModulesDLDir = process.cwd();
109+
while (new RegExp(`node_modules${path.sep}mongodb-memory-server`).test(nodeModulesDLDir)) {
110+
nodeModulesDLDir = path.resolve(nodeModulesDLDir, '..', '..');
111+
}
112+
106113
const defaultOptions = {
107114
downloadDir:
108115
process.env.MONGOMS_DOWNLOAD_DIR ||
@@ -111,10 +118,7 @@ export default class MongoBinary {
111118
: path.resolve(
112119
findCacheDir({
113120
name: 'mongodb-memory-server',
114-
// if we're in postinstall script, npm will set the cwd too deep
115-
cwd: new RegExp(`node_modules${path.sep}mongodb-memory-server$`).test(process.cwd())
116-
? path.resolve(process.cwd(), '..', '..')
117-
: process.cwd(),
121+
cwd: nodeModulesDLDir,
118122
}) || '',
119123
'mongodb-binaries'
120124
)),

0 commit comments

Comments
 (0)