Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
N
next.js
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Alex
next.js
Commits
bdfe247b
Unverified
Commit
bdfe247b
authored
Mar 06, 2024
by
Sam Ko
Committed by
GitHub
Mar 06, 2024
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
chore(cli): fix allowRetry when using port 3000 (#62840)
parent
6045048b
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
34 additions
and
6 deletions
+34
-6
next.ts
packages/next/src/bin/next.ts
+6
-3
next-dev.ts
packages/next/src/cli/next-dev.ts
+8
-3
index.test.js
test/integration/cli/test/index.test.js
+20
-0
No files found.
packages/next/src/bin/next.ts
View file @
bdfe247b
...
@@ -170,9 +170,12 @@ program
...
@@ -170,9 +170,12 @@ program
'Reports a subset of the debugging trace to a remote HTTP URL. Includes sensitive data.'
'Reports a subset of the debugging trace to a remote HTTP URL. Includes sensitive data.'
)
)
.
addOption
(
new
Option
(
'--experimental-test-proxy'
).
hideHelp
())
.
addOption
(
new
Option
(
'--experimental-test-proxy'
).
hideHelp
())
.
action
((
directory
,
options
)
=>
.
action
((
directory
,
options
,
{
_optionValueSources
})
=>
{
import
(
'../cli/next-dev.js'
).
then
((
mod
)
=>
mod
.
nextDev
(
options
,
directory
))
const
portSource
=
_optionValueSources
.
port
)
import
(
'../cli/next-dev.js'
).
then
((
mod
)
=>
mod
.
nextDev
(
options
,
portSource
,
directory
)
)
})
.
usage
(
'[directory] [options]'
)
.
usage
(
'[directory] [options]'
)
program
program
...
...
packages/next/src/cli/next-dev.ts
View file @
bdfe247b
...
@@ -46,6 +46,8 @@ type NextDevOptions = {
...
@@ -46,6 +46,8 @@ type NextDevOptions = {
experimentalTestProxy
?:
boolean
experimentalTestProxy
?:
boolean
}
}
type
PortSource
=
'cli'
|
'default'
|
'env'
let
dir
:
string
let
dir
:
string
let
child
:
undefined
|
ChildProcess
let
child
:
undefined
|
ChildProcess
let
config
:
NextConfigComplete
let
config
:
NextConfigComplete
...
@@ -127,7 +129,11 @@ process.on('SIGTERM', () => handleSessionStop('SIGKILL'))
...
@@ -127,7 +129,11 @@ process.on('SIGTERM', () => handleSessionStop('SIGKILL'))
// exit event must be synchronous
// exit event must be synchronous
process
.
on
(
'exit'
,
()
=>
child
?.
kill
(
'SIGKILL'
))
process
.
on
(
'exit'
,
()
=>
child
?.
kill
(
'SIGKILL'
))
const
nextDev
=
async
(
options
:
NextDevOptions
,
directory
?:
string
)
=>
{
const
nextDev
=
async
(
options
:
NextDevOptions
,
portSource
:
PortSource
,
directory
?:
string
)
=>
{
dir
=
getProjectDir
(
process
.
env
.
NEXT_PRIVATE_DEV_DIR
||
directory
)
dir
=
getProjectDir
(
process
.
env
.
NEXT_PRIVATE_DEV_DIR
||
directory
)
// Check if pages dir exists and warn if not
// Check if pages dir exists and warn if not
...
@@ -180,8 +186,7 @@ const nextDev = async (options: NextDevOptions, directory?: string) => {
...
@@ -180,8 +186,7 @@ const nextDev = async (options: NextDevOptions, directory?: string) => {
}
}
// If neither --port nor PORT were specified, it's okay to retry new ports.
// If neither --port nor PORT were specified, it's okay to retry new ports.
const
allowRetry
=
const
allowRetry
=
portSource
===
'default'
options
.
port
===
undefined
&&
process
.
env
.
PORT
===
undefined
// We do not set a default host value here to prevent breaking
// We do not set a default host value here to prevent breaking
// some set-ups that rely on listening on other interfaces
// some set-ups that rely on listening on other interfaces
...
...
test/integration/cli/test/index.test.js
View file @
bdfe247b
...
@@ -579,6 +579,26 @@ describe('CLI Usage', () => {
...
@@ -579,6 +579,26 @@ describe('CLI Usage', () => {
expect
(
stripAnsi
(
stdout
).
trim
()).
toBeFalsy
()
expect
(
stripAnsi
(
stdout
).
trim
()).
toBeFalsy
()
})
})
test
(
'Allow retry if port 3000 is already in use'
,
async
()
=>
{
let
output
=
''
let
appOne
let
appTwo
try
{
appOne
=
await
runNextCommandDev
([
dirBasic
],
undefined
,
{})
appTwo
=
await
runNextCommandDev
([
dirBasic
],
undefined
,
{
onStderr
(
msg
)
{
output
+=
stripAnsi
(
msg
)
},
})
}
finally
{
await
killApp
(
appOne
).
catch
(
console
.
error
)
await
killApp
(
appTwo
).
catch
(
console
.
error
)
}
expect
(
output
).
toMatch
(
'⚠ Port 3000 is in use, trying 3001 instead.'
)
})
test
(
'-p reserved'
,
async
()
=>
{
test
(
'-p reserved'
,
async
()
=>
{
const
TCP_MUX_PORT
=
1
const
TCP_MUX_PORT
=
1
const
{
stderr
,
stdout
}
=
await
runAndCaptureOutput
({
const
{
stderr
,
stdout
}
=
await
runAndCaptureOutput
({
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment