create-listening-server
Advanced tools
Comparing version 0.1.2 to 1.0.0
{ | ||
"name": "create-listening-server", | ||
"description": "Promise-based API to create listening `http.Server` instances.", | ||
"version": "0.1.2", | ||
"version": "1.0.0", | ||
"main": "cjs/index.js", | ||
@@ -10,28 +10,28 @@ "types": "cjs/index.d.ts", | ||
"prebuild": "yarn clean", | ||
"build": "tsc -p src --outDir cjs --module commonjs", | ||
"lint": "run-p lint:src lint:test", | ||
"lint:src": "tslint -p src", | ||
"lint:test": "tslint -p test", | ||
"pretest": "yarn lint", | ||
"test": "mocha -r @ts-tools/node/r \"test/**/*.spec.ts\" --watch-extensions ts", | ||
"build": "tsc -p tsconfig.build.json", | ||
"lint": "eslint . --ext .ts,.tsx -f codeframe", | ||
"typecheck": "tsc --noEmit", | ||
"pretest": "yarn typecheck && yarn lint", | ||
"test": "mocha \"test/**/*.spec.ts\"", | ||
"prepack": "yarn build" | ||
}, | ||
"devDependencies": { | ||
"@ts-tools/node": "^0.9.2", | ||
"@types/chai": "^4.1.7", | ||
"@types/chai-as-promised": "^7.1.0", | ||
"@types/mocha": "^5.2.6", | ||
"@ts-tools/node": "^1.0.0", | ||
"@types/chai": "^4.2.3", | ||
"@types/chai-as-promised": "^7.1.2", | ||
"@types/mocha": "^5.2.7", | ||
"@types/node": "8", | ||
"@typescript-eslint/eslint-plugin": "^2.3.2", | ||
"@typescript-eslint/parser": "^2.3.2", | ||
"chai": "^4.2.0", | ||
"chai-as-promised": "^7.1.1", | ||
"mocha": "^5.2.0", | ||
"eslint": "^6.5.1", | ||
"mocha": "^6.2.1", | ||
"npm-run-all": "^4.1.5", | ||
"rimraf": "^2.6.3", | ||
"tslint": "^5.12.1", | ||
"typescript": "~3.3.3" | ||
"rimraf": "^3.0.0", | ||
"typescript": "~3.6.3" | ||
}, | ||
"files": [ | ||
"cjs", | ||
"src", | ||
"!src/tsconfig.json" | ||
"src" | ||
], | ||
@@ -38,0 +38,0 @@ "engines": { |
@@ -1,2 +0,2 @@ | ||
import { Server, IncomingMessage, ServerResponse, createServer } from 'http' | ||
import { Server, IncomingMessage, ServerResponse, createServer } from 'http'; | ||
@@ -15,10 +15,10 @@ /** | ||
return new Promise<Server>((resolve, reject) => { | ||
const httpServer = createServer(requestListener) | ||
httpServer.listen(port) | ||
const httpServer = createServer(requestListener); | ||
httpServer.listen(port); | ||
httpServer.once('listening', () => { | ||
httpServer.removeListener('error', reject) | ||
resolve(httpServer) | ||
}) | ||
httpServer.once('error', reject) | ||
}) | ||
httpServer.removeListener('error', reject); | ||
resolve(httpServer); | ||
}); | ||
httpServer.once('error', reject); | ||
}); | ||
} |
@@ -1,2 +0,2 @@ | ||
export * from './create-listening-server' | ||
export * from './safe-listening-server' | ||
export * from './create-listening-server'; | ||
export * from './safe-listening-server'; |
@@ -1,3 +0,3 @@ | ||
import { Server, IncomingMessage, ServerResponse } from 'http' | ||
import { createListeningHttpServer } from './create-listening-server' | ||
import { Server, IncomingMessage, ServerResponse } from 'http'; | ||
import { createListeningHttpServer } from './create-listening-server'; | ||
@@ -18,20 +18,20 @@ /** | ||
usedPortRetries = 100 | ||
): Promise<{ httpServer: Server, port: number }> { | ||
const lastPort = preferredPort + usedPortRetries | ||
): Promise<{ httpServer: Server; port: number }> { | ||
const lastPort = preferredPort + usedPortRetries; | ||
let port = preferredPort | ||
let port = preferredPort; | ||
do { | ||
try { | ||
const httpServer = await createListeningHttpServer(port, requestListener) | ||
return { httpServer, port } | ||
const httpServer = await createListeningHttpServer(port, requestListener); | ||
return { httpServer, port }; | ||
} catch (e) { | ||
if (!isUsedPortError(e)) { | ||
throw e | ||
throw e; | ||
} | ||
} | ||
} while (++port <= lastPort) | ||
} while (++port <= lastPort); | ||
throw new Error(`HTTP server could not start a listening on ports ${preferredPort}-${lastPort}`) | ||
throw new Error(`HTTP server could not start a listening on ports ${preferredPort}-${lastPort}`); | ||
} | ||
const isUsedPortError = (e: any): e is Error => e && e.code === 'EADDRINUSE' | ||
const isUsedPortError = (e: unknown): e is Error => e && (e as {code: string}).code === 'EADDRINUSE'; |
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
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
12668
1
14