Skip to content

Commit

Permalink
fix: Remove unnecessary dependency @types/bluebird (also removed blue…
Browse files Browse the repository at this point in the history
…bird internally)
  • Loading branch information
TimothyJones committed Dec 5, 2022
1 parent 98530cd commit 56efeb3
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 40 deletions.
16 changes: 0 additions & 16 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,8 @@
},
"dependencies": {
"@pact-foundation/pact-core": "^13.13.0",
"@types/bluebird": "^3.5.20",
"@types/express": "^4.17.11",
"axios": "^0.27.2",
"bluebird": "~3.5.1",
"body-parser": "^1.20.0",
"cli-color": "^2.0.1",
"express": "^4.18.1",
Expand Down
34 changes: 12 additions & 22 deletions src/common/net.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
*/

import * as net from 'net';
import { Promise as bluebird } from 'bluebird';

export const localAddresses = ['127.0.0.1', 'localhost', '0.0.0.0', '::1'];

Expand All @@ -27,28 +26,19 @@ export const portCheck = (port: number, host: string): Promise<void> =>
});

export const isPortAvailable = (port: number, host: string): Promise<void> =>
Promise.resolve(
bluebird
.map(
localAddresses,
// we meed to wrap the built-in Promise with bluebird.reflect() so we can
// test the result of the promise without failing bluebird.map()
(h) => bluebird.resolve(portCheck(port, h)).reflect(),
// do each port check sequentially (as localhost & 127.0.0.1 will conflict on most default environments)
{ concurrency: 1 }
)
.then((inspections) => {
// if every port check failed, then fail the `isPortAvailable` check
if (inspections.every((inspection) => !inspection.isFulfilled())) {
return Promise.reject(
new Error(`Cannot open port ${port} on ipv4 or ipv6 interfaces`)
);
}
Promise.allSettled(
localAddresses.map((localHost) => portCheck(port, localHost))
).then((settledPortChecks) => {
// if every port check failed, then fail the `isPortAvailable` check
if (settledPortChecks.every((result) => result.status === 'rejected')) {
return Promise.reject(
new Error(`Cannot open port ${port} on ipv4 or ipv6 interfaces`)
);
}

// the local addresses passed - now check the host that the user has specified
return portCheck(port, host);
})
);
// the local addresses passed - now check the host that the user has specified
return portCheck(port, host);
});

export const freePort = (): Promise<number> => {
return new Promise((res) => {
Expand Down

0 comments on commit 56efeb3

Please sign in to comment.