Skip to content

Commit

Permalink
refactor!: drop memo support
Browse files Browse the repository at this point in the history
  • Loading branch information
pi0 committed Nov 14, 2022
1 parent 8a8bbb2 commit bc6f5c5
Show file tree
Hide file tree
Showing 4 changed files with 1 addition and 34 deletions.
9 changes: 1 addition & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ checkPort(port: number, host?: string): Promise<number | false>
waitForPort(port: number, options): Promise<number | false>
```

Try sequence is: port > ports > memo > random
Try sequence is: port > ports > random

## Options

Expand Down Expand Up @@ -74,13 +74,6 @@ Alternative port range to check. Default is `[3000, 3100]`

The host to check. Default is `process.env.HOST` otherwise all available hosts will be checked.

### `memoDir` / `memoName`

Options passed to [fs-memo](https://github.com/unjs/fs-memo)

- Default dir: `node_modules/get-port/dist`
- Default name: `.get-port`

## License

MIT
3 changes: 0 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,6 @@
"release": "pnpm test && pnpm build && standard-version && pnpm publish && git push --follow-tags",
"test": "pnpm lint && vitest run"
},
"dependencies": {
"fs-memo": "^1.2.0"
},
"devDependencies": {
"@types/node": "^18.11.9",
"c8": "^7.12.0",
Expand Down
8 changes: 0 additions & 8 deletions pnpm-lock.yaml

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

15 changes: 0 additions & 15 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { createServer, AddressInfo } from "node:net";
import { networkInterfaces } from "node:os";
import { getMemo, setMemo } from "fs-memo";
import { isSafePort } from "./unsafe-ports";

export { isUnsafePort, isSafePort } from "./unsafe-ports";
Expand All @@ -13,8 +12,6 @@ export interface GetPortOptions {
portRange: [from: number, to: number]
alternativePortRange: [from: number, to: number]
host: string
memoDir: string
memoName: string
verbose?: boolean
}

Expand All @@ -40,7 +37,6 @@ export async function getPort (config: GetPortInput = {}): Promise<PortNumber> {
portRange: [],
alternativePortRange: [3000, 3100],
host: undefined,
memoName: "port",
verbose: false,
...config,
port: Number.parseInt(process.env.PORT || "") || config.port || 3000
Expand Down Expand Up @@ -69,14 +65,6 @@ export async function getPort (config: GetPortInput = {}): Promise<PortNumber> {
return true;
});

// Memo
const memoOptions = { name: options.memoName, dir: options.memoDir! };
const memoKey = "port_" + options.name;
const memo = await getMemo(memoOptions);
if (memo[memoKey]) {
portsToCheck.push(memo[memoKey]);
}

// Try to find a port
let availablePort = await findPort(portsToCheck, options.host, options.verbose, false);

Expand All @@ -88,9 +76,6 @@ export async function getPort (config: GetPortInput = {}): Promise<PortNumber> {
}
}

// Persist
await setMemo({ [memoKey]: availablePort }, memoOptions);

return availablePort;
}

Expand Down

0 comments on commit bc6f5c5

Please sign in to comment.