Skip to content
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

Fix/follow up 25863 #25915

Merged
merged 4 commits into from
Jul 21, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions packages/gatsby/src/commands/develop.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,9 @@ let isRestarting
const REGEX_IP = /^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])$/

module.exports = async (program: IProgram): Promise<void> => {
// In some cases, port can actually be a string. But our codebase is expecting it to be a number.
// So we want to early just force it to a number to ensure we always act on a correct type.
program.port = parseInt(program.port + ``, 10)
const developProcessPath = slash(require.resolve(`./develop-process`))

try {
Expand Down
9 changes: 4 additions & 5 deletions packages/gatsby/src/utils/detect-port-in-use-and-prompt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@ import prompts from "prompts"
export const detectPortInUseAndPrompt = async (
port: number
): Promise<number> => {
let foundPort = typeof port === `string` ? parseInt(port, 10) : port
const detectedPort = await detectPort(foundPort).catch((err: Error) =>
const detectedPort = await detectPort(port).catch((err: Error) =>
report.panic(err)
)
if (foundPort !== detectedPort) {
if (port !== detectedPort) {
report.log(`\nSomething is already running at port ${port}`)
const response = await prompts({
type: `confirm`,
Expand All @@ -18,11 +17,11 @@ export const detectPortInUseAndPrompt = async (
initial: true,
})
if (response.newPort) {
foundPort = detectedPort
port = detectedPort
} else {
throw new Error(`USER_REJECTED`)
}
}

return foundPort
return port
}