mongodb-memory-server-core
Advanced tools
Comparing version 8.11.5 to 8.12.0
@@ -8,3 +8,2 @@ /// <reference types="node" /> | ||
import { SpawnOptions } from 'child_process'; | ||
import * as tmp from 'tmp'; | ||
/** | ||
@@ -123,3 +122,3 @@ * Replica set specific options. | ||
/** TMPDIR for the keyfile, when auth is used */ | ||
protected _keyfiletmp?: tmp.DirResult; | ||
protected _keyfiletmp?: string; | ||
protected _state: MongoMemoryReplSetStates; | ||
@@ -195,3 +194,3 @@ protected _ranCreateAuth: boolean; | ||
*/ | ||
protected ensureKeyFile(): Promise<tmp.DirResult>; | ||
protected ensureKeyFile(): Promise<string>; | ||
/** | ||
@@ -198,0 +197,0 @@ * Stop the underlying `mongod` instance(s). |
@@ -12,7 +12,5 @@ "use strict"; | ||
const errors_1 = require("./util/errors"); | ||
const tmp = (0, tslib_1.__importStar)(require("tmp")); | ||
const fs_1 = require("fs"); | ||
const path_1 = require("path"); | ||
const log = (0, debug_1.default)('MongoMS:MongoMemoryReplSet'); | ||
tmp.setGracefulCleanup(); | ||
/** | ||
@@ -255,3 +253,3 @@ * Enum for "_state" inside "MongoMemoryReplSet" | ||
log('initAllServers: "_ranCreateAuth" is true, re-using auth'); | ||
const keyfilepath = (0, path_1.resolve)((yield this.ensureKeyFile()).name, 'keyfile'); | ||
const keyfilepath = (0, path_1.resolve)(yield this.ensureKeyFile(), 'keyfile'); | ||
for (const server of this.servers) { | ||
@@ -278,3 +276,3 @@ (0, utils_1.assertion)(!(0, utils_1.isNullOrUndefined)(server.instanceInfo), new errors_1.InstanceInfoError('MongoMemoryReplSet.initAllServers')); | ||
if (this.enableAuth()) { | ||
keyfilePath = (0, path_1.resolve)((yield this.ensureKeyFile()).name, 'keyfile'); | ||
keyfilePath = (0, path_1.resolve)(yield this.ensureKeyFile(), 'keyfile'); | ||
} | ||
@@ -307,9 +305,5 @@ // Any servers defined within `_instanceOpts` should be started first as | ||
if ((0, utils_1.isNullOrUndefined)(this._keyfiletmp)) { | ||
this._keyfiletmp = tmp.dirSync({ | ||
mode: 0o766, | ||
prefix: 'mongo-mem-keyfile-', | ||
unsafeCleanup: true, | ||
}); | ||
this._keyfiletmp = yield (0, utils_1.createTmpDir)('mongo-mem-keyfile-'); | ||
} | ||
const keyfilepath = (0, path_1.resolve)(this._keyfiletmp.name, 'keyfile'); | ||
const keyfilepath = (0, path_1.resolve)(this._keyfiletmp, 'keyfile'); | ||
// if path does not exist or have no access, create it (or fail) | ||
@@ -319,3 +313,3 @@ if (!(yield (0, utils_1.statPath)(keyfilepath))) { | ||
(0, utils_1.assertion)(typeof this._replSetOpts.auth === 'object', new errors_1.AuthNotObjectError()); | ||
yield fs_1.promises.writeFile((0, path_1.resolve)(this._keyfiletmp.name, 'keyfile'), (_a = this._replSetOpts.auth.keyfileContent) !== null && _a !== void 0 ? _a : '0123456789', { mode: 0o700 } // this is because otherwise mongodb errors with "permissions are too open" on unix systems | ||
yield fs_1.promises.writeFile((0, path_1.resolve)(this._keyfiletmp, 'keyfile'), (_a = this._replSetOpts.auth.keyfileContent) !== null && _a !== void 0 ? _a : '0123456789', { mode: 0o700 } // this is because otherwise mongodb errors with "permissions are too open" on unix systems | ||
); | ||
@@ -387,3 +381,3 @@ } | ||
if (!(0, utils_1.isNullOrUndefined)(this._keyfiletmp)) { | ||
this._keyfiletmp.removeCallback(); | ||
yield (0, utils_1.removeDir)(this._keyfiletmp); | ||
this._keyfiletmp = undefined; | ||
@@ -390,0 +384,0 @@ } |
/// <reference types="node" /> | ||
import { SpawnOptions } from 'child_process'; | ||
import * as tmp from 'tmp'; | ||
import { ManagerAdvanced, Cleanup } from './util/utils'; | ||
@@ -63,3 +62,3 @@ import { MongoInstance, MongodOpts, MongoMemoryInstanceOpts } from './util/MongoInstance'; | ||
replSet?: NonNullable<MongoMemoryInstanceOpts['replSet']>; | ||
tmpDir?: tmp.DirResult; | ||
tmpDir?: string; | ||
keyfileLocation?: NonNullable<MongoMemoryInstanceOpts['keyfileLocation']>; | ||
@@ -66,0 +65,0 @@ launchTimeout?: NonNullable<MongoMemoryInstanceOpts['launchTimeout']>; |
@@ -5,3 +5,2 @@ "use strict"; | ||
const tslib_1 = require("tslib"); | ||
const tmp = (0, tslib_1.__importStar)(require("tmp")); | ||
const get_port_1 = (0, tslib_1.__importDefault)(require("get-port")); | ||
@@ -14,7 +13,5 @@ const utils_1 = require("./util/utils"); | ||
const mongodb_1 = require("mongodb"); | ||
const semver_1 = require("semver"); | ||
const errors_1 = require("./util/errors"); | ||
const os = (0, tslib_1.__importStar)(require("os")); | ||
const log = (0, debug_1.default)('MongoMS:MongoMemoryServer'); | ||
tmp.setGracefulCleanup(); | ||
/** | ||
@@ -172,8 +169,4 @@ * All Events for "MongoMemoryServer" | ||
if (!data.dbPath) { | ||
data.tmpDir = tmp.dirSync({ | ||
mode: 0o755, | ||
prefix: 'mongo-mem-', | ||
unsafeCleanup: true, | ||
}); | ||
data.dbPath = data.tmpDir.name; | ||
data.tmpDir = yield (0, utils_1.createTmpDir)('mongo-mem-'); | ||
data.dbPath = data.tmpDir; | ||
isNew = true; // just to ensure "isNew" is "true" because an new temporary directory got created | ||
@@ -319,4 +312,4 @@ } | ||
if (!(0, utils_1.isNullOrUndefined)(tmpDir)) { | ||
this.debug(`cleanup: removing tmpDir at ${tmpDir.name}`); | ||
tmpDir.removeCallback(); | ||
this.debug(`cleanup: removing tmpDir at ${tmpDir}`); | ||
yield (0, utils_1.removeDir)(tmpDir); | ||
} | ||
@@ -331,10 +324,3 @@ if (cleanup.force) { | ||
(0, utils_1.assertion)(res.isDirectory(), new Error('Defined dbPath is not an directory')); | ||
if ((0, semver_1.lt)(process.version, '14.14.0')) { | ||
// this has to be used for 12.10 - 14.13 (inclusive) because ".rm" did not exist yet | ||
yield fs_1.promises.rmdir(dbPath, { recursive: true, maxRetries: 1 }); | ||
} | ||
else { | ||
// this has to be used for 14.14+ (inclusive) because ".rmdir" and "recursive" got deprecated (DEP0147) | ||
yield fs_1.promises.rm(dbPath, { recursive: true, maxRetries: 1 }); | ||
} | ||
yield (0, utils_1.removeDir)(dbPath); | ||
} | ||
@@ -341,0 +327,0 @@ } |
@@ -135,3 +135,16 @@ /// <reference types="node" /> | ||
export declare function mkdir(path: string): Promise<void>; | ||
/** | ||
* Create a Temporary directory with prefix, and optionally at "atPath" | ||
* @param prefix The prefix to use to create the tmpdir | ||
* @param atPath Optionally set a custom path other than "os.tmpdir" | ||
* @returns The created Path | ||
*/ | ||
export declare function createTmpDir(prefix: string, atPath?: string): Promise<string>; | ||
/** | ||
* Removes the given "path", if it is a directory, and does not throw a error if not existing | ||
* @param dirPath The Directory Path to delete | ||
* @returns "true" if deleted, otherwise "false" | ||
*/ | ||
export declare function removeDir(dirPath: string): Promise<void>; | ||
export {}; | ||
//# sourceMappingURL=utils.d.ts.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.mkdir = exports.checkBinaryPermissions = exports.ManagerAdvanced = exports.ManagerBase = exports.tryReleaseFile = exports.pathExists = exports.statPath = exports.authDefault = exports.ensureAsync = exports.isAlive = exports.killProcess = exports.assertion = exports.isNullOrUndefined = exports.uriTemplate = exports.getHost = exports.generateDbName = exports.errorWithCode = void 0; | ||
exports.removeDir = exports.createTmpDir = exports.mkdir = exports.checkBinaryPermissions = exports.ManagerAdvanced = exports.ManagerBase = exports.tryReleaseFile = exports.pathExists = exports.statPath = exports.authDefault = exports.ensureAsync = exports.isAlive = exports.killProcess = exports.assertion = exports.isNullOrUndefined = exports.uriTemplate = exports.getHost = exports.generateDbName = exports.errorWithCode = void 0; | ||
const tslib_1 = require("tslib"); | ||
@@ -8,2 +8,4 @@ const debug_1 = (0, tslib_1.__importDefault)(require("debug")); | ||
const errors_1 = require("./errors"); | ||
const os_1 = require("os"); | ||
const path = (0, tslib_1.__importStar)(require("path")); | ||
const log = (0, debug_1.default)('MongoMS:utils'); | ||
@@ -252,2 +254,43 @@ /** | ||
exports.mkdir = mkdir; | ||
/** | ||
* Create a Temporary directory with prefix, and optionally at "atPath" | ||
* @param prefix The prefix to use to create the tmpdir | ||
* @param atPath Optionally set a custom path other than "os.tmpdir" | ||
* @returns The created Path | ||
*/ | ||
function createTmpDir(prefix, atPath) { | ||
return (0, tslib_1.__awaiter)(this, void 0, void 0, function* () { | ||
const tmpPath = atPath !== null && atPath !== void 0 ? atPath : (0, os_1.tmpdir)(); | ||
return fs_1.promises.mkdtemp(path.join(tmpPath, prefix)); | ||
}); | ||
} | ||
exports.createTmpDir = createTmpDir; | ||
/** | ||
* Removes the given "path", if it is a directory, and does not throw a error if not existing | ||
* @param dirPath The Directory Path to delete | ||
* @returns "true" if deleted, otherwise "false" | ||
*/ | ||
function removeDir(dirPath) { | ||
return (0, tslib_1.__awaiter)(this, void 0, void 0, function* () { | ||
const stat = yield statPath(dirPath); | ||
if (isNullOrUndefined(stat)) { | ||
return; | ||
} | ||
if (!stat.isDirectory()) { | ||
throw new Error(`Given Path is not a directory! (Path: "${dirPath}")`); | ||
} | ||
if ('rm' in fs_1.promises) { | ||
// only since NodeJS 14 | ||
yield fs_1.promises.rm(dirPath, { force: true, recursive: true }); | ||
} | ||
else { | ||
// before NodeJS 14 | ||
// needs the bridge via the interface, because we are using @types/node 14, where this if evaluates to a always "true" in typescript's eyes | ||
yield fs_1.promises.rmdir(dirPath, { | ||
recursive: true, | ||
}); | ||
} | ||
}); | ||
} | ||
exports.removeDir = removeDir; | ||
//# sourceMappingURL=utils.js.map |
{ | ||
"name": "mongodb-memory-server-core", | ||
"version": "8.11.5", | ||
"version": "8.12.0", | ||
"description": "MongoDB Server for testing (core package, without autodownload). The server will allow you to connect your favourite ODM or client library to the MongoDB Server and run parallel integration tests isolated from each other.", | ||
@@ -38,3 +38,3 @@ "main": "lib/index", | ||
"@types/tar-stream": "^2.2.2", | ||
"@types/uuid": "^8.3.4", | ||
"@types/uuid": "^9.0.1", | ||
"@types/yauzl": "^2.10.0", | ||
@@ -46,3 +46,2 @@ "@types/yazl": "^2.4.2", | ||
"dependencies": { | ||
"@types/tmp": "^0.2.3", | ||
"async-mutex": "^0.3.2", | ||
@@ -59,4 +58,3 @@ "camelcase": "^6.3.0", | ||
"tar-stream": "^2.1.4", | ||
"tmp": "^0.2.1", | ||
"tslib": "^2.4.1", | ||
"tslib": "^2.5.0", | ||
"uuid": "^9.0.0", | ||
@@ -63,0 +61,0 @@ "yauzl": "^2.10.0" |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
379810
14
5485
- Removed@types/tmp@^0.2.3
- Removedtmp@^0.2.1
- Removed@types/tmp@0.2.6(transitive)
- Removedtmp@0.2.3(transitive)
Updatedtslib@^2.5.0