diff --git a/package.json b/package.json index d82d07d..751ad2f 100644 --- a/package.json +++ b/package.json @@ -72,10 +72,10 @@ "extract-zip": "^2.0.1", "find-cache-dir": "^3.3.2", "find-package-json": "^1.2.0", + "get-port": "^5.1.1", "https-proxy-agent": "^7.0.0", "lockfile": "^1.0.4", "lodash.defaultsdeep": "^4.6.1", - "portfinder": "^1.0.32", "rimraf": "^5.0.1", "semver": "^7.5.3", "tar": "^6.1.15", diff --git a/src/RedisMemoryServer.ts b/src/RedisMemoryServer.ts index cdbf0bf..c930a5e 100644 --- a/src/RedisMemoryServer.ts +++ b/src/RedisMemoryServer.ts @@ -1,6 +1,6 @@ import { ChildProcess } from 'child_process'; import * as tmp from 'tmp'; -import { getPortPromise as getPort } from 'portfinder'; +import getPort from 'get-port'; import { isNullOrUndefined } from './util/db_util'; import RedisInstance from './util/RedisInstance'; import { RedisBinaryOpts } from './util/RedisBinary'; @@ -42,6 +42,12 @@ export default class RedisMemoryServer { runningInstance: Promise | null = null; instanceInfoSync: RedisInstanceDataT | null = null; opts: RedisMemoryServerOptsT; + /** + * @private + */ + _previousInstanceConfig?: { + port: number; + }; /** * Create an Redis-Memory-Sever Instance @@ -119,7 +125,8 @@ export default class RedisMemoryServer { /** Shortcut to this.opts.instance */ const instOpts = this.opts.instance ?? {}; const data: StartupInstanceData = { - port: await getPort({ port: instOpts.port ?? undefined }), // do (null or undefined) to undefined + port: + this._previousInstanceConfig?.port ?? (await getPort({ port: instOpts.port ?? undefined })), // do (null or undefined) to undefined ip: instOpts.ip ?? '127.0.0.1', tmpDir: undefined, }; @@ -168,6 +175,7 @@ export default class RedisMemoryServer { this.runningInstance = null; this.instanceInfoSync = null; + this._previousInstanceConfig = { port }; if (tmpDir) { log(`Removing tmpDir ${tmpDir.name}`); diff --git a/yarn.lock b/yarn.lock index e8a7b2e..f20ad88 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1864,15 +1864,6 @@ __metadata: languageName: node linkType: hard -"async@npm:^2.6.4": - version: 2.6.4 - resolution: "async@npm:2.6.4" - dependencies: - lodash: "npm:^4.17.14" - checksum: 0ebb3273ef96513389520adc88e0d3c45e523d03653cc9b66f5c46f4239444294899bfd13d2b569e7dbfde7da2235c35cf5fd3ece9524f935d41bbe4efccdad0 - languageName: node - linkType: hard - "babel-jest@npm:^29.6.0": version: 29.6.0 resolution: "babel-jest@npm:29.6.0" @@ -2649,15 +2640,6 @@ __metadata: languageName: node linkType: hard -"debug@npm:^3.2.7": - version: 3.2.7 - resolution: "debug@npm:3.2.7" - dependencies: - ms: "npm:^2.1.1" - checksum: 37d96ae42cbc71c14844d2ae3ba55adf462ec89fd3a999459dec3833944cd999af6007ff29c780f1c61153bcaaf2c842d1e4ce1ec621e4fc4923244942e4a02a - languageName: node - linkType: hard - "decamelize-keys@npm:^1.1.0": version: 1.1.1 resolution: "decamelize-keys@npm:1.1.1" @@ -3418,6 +3400,13 @@ __metadata: languageName: node linkType: hard +"get-port@npm:^5.1.1": + version: 5.1.1 + resolution: "get-port@npm:5.1.1" + checksum: 2873877a469b24e6d5e0be490724a17edb39fafc795d1d662e7bea951ca649713b4a50117a473f9d162312cb0e946597bd0e049ed2f866e79e576e8e213d3d1c + languageName: node + linkType: hard + "get-stream@npm:^5.1.0": version: 5.2.0 resolution: "get-stream@npm:5.2.0" @@ -4831,7 +4820,7 @@ __metadata: languageName: node linkType: hard -"lodash@npm:^4.17.14, lodash@npm:^4.17.15": +"lodash@npm:^4.17.15": version: 4.17.21 resolution: "lodash@npm:4.17.21" checksum: d8cbea072bb08655bb4c989da418994b073a608dffa608b09ac04b43a791b12aeae7cd7ad919aa4c925f33b48490b5cfe6c1f71d827956071dae2e7bb3a6b74c @@ -5135,17 +5124,6 @@ __metadata: languageName: node linkType: hard -"mkdirp@npm:^0.5.6": - version: 0.5.6 - resolution: "mkdirp@npm:0.5.6" - dependencies: - minimist: "npm:^1.2.6" - bin: - mkdirp: bin/cmd.js - checksum: e2e2be789218807b58abced04e7b49851d9e46e88a2f9539242cc8a92c9b5c3a0b9bab360bd3014e02a140fc4fbc58e31176c408b493f8a2a6f4986bd7527b01 - languageName: node - linkType: hard - "mkdirp@npm:^1.0.3": version: 1.0.4 resolution: "mkdirp@npm:1.0.4" @@ -5169,7 +5147,7 @@ __metadata: languageName: node linkType: hard -"ms@npm:^2.0.0, ms@npm:^2.1.1": +"ms@npm:^2.0.0": version: 2.1.3 resolution: "ms@npm:2.1.3" checksum: d924b57e7312b3b63ad21fc5b3dc0af5e78d61a1fc7cfb5457edaf26326bf62be5307cc87ffb6862ef1c2b33b0233cdb5d4f01c4c958cc0d660948b65a287a48 @@ -5604,17 +5582,6 @@ __metadata: languageName: node linkType: hard -"portfinder@npm:^1.0.32": - version: 1.0.32 - resolution: "portfinder@npm:1.0.32" - dependencies: - async: "npm:^2.6.4" - debug: "npm:^3.2.7" - mkdirp: "npm:^0.5.6" - checksum: cef8b567b78aabccc59fe8e103bac8b394bb45a6a69be626608f099f454124c775aaf47b274c006332c07ab3f501cde55e49aaeb9d49d78d90362d776a565cbf - languageName: node - linkType: hard - "prelude-ls@npm:^1.2.1": version: 1.2.1 resolution: "prelude-ls@npm:1.2.1" @@ -5850,6 +5817,7 @@ __metadata: extract-zip: "npm:^2.0.1" find-cache-dir: "npm:^3.3.2" find-package-json: "npm:^1.2.0" + get-port: "npm:^5.1.1" https-proxy-agent: "npm:^7.0.0" husky: "npm:^8.0.3" ioredis: "npm:^5.3.2" @@ -5857,7 +5825,6 @@ __metadata: lint-staged: "npm:^13.2.3" lockfile: "npm:^1.0.4" lodash.defaultsdeep: "npm:^4.6.1" - portfinder: "npm:^1.0.32" prettier: "npm:^2.8.8" rimraf: "npm:^5.0.1" semver: "npm:^7.5.3"