Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: refactor with typescript to support esm and cjs both
- Loading branch information
hanquliu
authored and
hanquliu
committed
Nov 20, 2023
1 parent
9804ad5
commit a4f7723
Showing
18 changed files
with
420 additions
and
366 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"extends": [ | ||
"eslint-config-egg/typescript", | ||
"eslint-config-egg/lib/rules/enforce-node-prefix" | ||
], | ||
"rules": { | ||
"@typescript-eslint/ban-ts-comment": "off" | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,5 @@ node_modules | |
coverage | ||
*.un~ | ||
*.sw* | ||
.tshy* | ||
dist/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import detectPort from './detect-port.js'; | ||
|
||
export default detectPort; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { debuglog } from 'node:util'; | ||
import detectPort from './detect-port.js'; | ||
|
||
const debug = debuglog('wait-port'); | ||
|
||
const sleep = (ms: number) => new Promise(resolve => setTimeout(resolve, ms)); | ||
|
||
export interface WaitPortOptions { | ||
retryInterval?: number; | ||
retries?: number; | ||
} | ||
|
||
export default async function waitPort(port: number, options: WaitPortOptions = {}) { | ||
const { retryInterval = 1000, retries = Infinity } = options; | ||
let count = 1; | ||
|
||
async function loop() { | ||
debug('retries', retries, 'count', count); | ||
if (count > retries) { | ||
const err = new Error('retries exceeded'); | ||
(err as any).retries = retries; | ||
(err as any).count = count; | ||
throw err; | ||
} | ||
count++; | ||
const freePort = await detectPort(port); | ||
if (freePort === port) { | ||
await sleep(retryInterval); | ||
return loop(); | ||
} | ||
return true; | ||
} | ||
|
||
return await loop(); | ||
} |
Oops, something went wrong.