Repository navigation
chore(swingset): fall back to the next free port when 6006 is taken #10499
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| --- | ||
| --- |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| import { spawn } from 'node:child_process'; | ||
|
|
||
| import getPort from 'get-port'; | ||
|
|
||
| const start = Number(process.env.PORT) || 6006; | ||
| const port = await getPort({ port: getPort.makeRange(start, start + 100) }); | ||
|
|
||
| const child = spawn('next', ['dev', '--port', String(port), ...process.argv.slice(2)], { stdio: 'inherit' }); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Start Next.js through Node on Windows. On Windows, the package executable is a
|
||
|
|
||
| for (const signal of ['SIGINT', 'SIGTERM']) { | ||
| process.on(signal, () => child.kill(signal)); | ||
| } | ||
|
|
||
| child.on('exit', (code, signal) => { | ||
| if (signal) { | ||
| process.removeAllListeners(signal); | ||
| process.kill(process.pid, signal); | ||
| } else { | ||
| process.exit(code ?? 0); | ||
| } | ||
| }); | ||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Skip ports that Next.js rejects.
If
PORT=6565is occupied and 6566 is free,getPortselects 6566. Next.js rejects that reserved port instead of starting on 6567. Filter reserved ports from the candidates. (raw.githubusercontent.com)Keep the port range within valid bounds.
PORT=65535makesgetPort.makeRangethrow before Next.js starts, even if that port is free. Cap the upper bound at 65535 and handle valid starting ports below 1024. (raw.githubusercontent.com)