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
27c207da
Unverified
Commit
27c207da
authored
Jul 28, 2020
by
Darsh Patel
Committed by
GitHub
Jul 28, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix: UnhandledPromiseRejectionWarning when unknown flag provided for cli commands (#15422)
parent
91242ca6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
162 additions
and
64 deletions
+162
-64
next-dev.ts
packages/next/cli/next-dev.ts
+19
-14
next-export.ts
packages/next/cli/next-export.ts
+20
-15
next-start.ts
packages/next/cli/next-start.ts
+20
-14
next-telemetry.ts
packages/next/cli/next-telemetry.ts
+18
-12
index.test.js
test/integration/build-warnings/test/index.test.js
+0
-9
index.test.js
test/integration/cli/test/index.test.js
+85
-0
No files found.
packages/next/cli/next-dev.ts
View file @
27c207da
...
@@ -8,21 +8,26 @@ import { startedDevelopmentServer } from '../build/output'
...
@@ -8,21 +8,26 @@ import { startedDevelopmentServer } from '../build/output'
import
{
cliCommand
}
from
'../bin/next'
import
{
cliCommand
}
from
'../bin/next'
const
nextDev
:
cliCommand
=
(
argv
)
=>
{
const
nextDev
:
cliCommand
=
(
argv
)
=>
{
const
args
=
arg
(
const
validArgs
:
arg
.
Spec
=
{
{
// Types
// Types
'--help'
:
Boolean
,
'--help'
:
Boolean
,
'--port'
:
Number
,
'--port'
:
Number
,
'--hostname'
:
String
,
'--hostname'
:
String
,
// Aliases
'-h'
:
'--help'
,
'-p'
:
'--port'
,
'-H'
:
'--hostname'
,
},
{
argv
}
)
// Aliases
'-h'
:
'--help'
,
'-p'
:
'--port'
,
'-H'
:
'--hostname'
,
}
let
args
:
arg
.
Result
<
arg
.
Spec
>
try
{
args
=
arg
(
validArgs
,
{
argv
})
}
catch
(
error
)
{
if
(
error
.
code
===
'ARG_UNKNOWN_OPTION'
)
{
return
printAndExit
(
error
.
message
,
1
)
}
throw
error
}
if
(
args
[
'--help'
])
{
if
(
args
[
'--help'
])
{
// tslint:disable-next-line
// tslint:disable-next-line
console
.
log
(
`
console
.
log
(
`
...
...
packages/next/cli/next-export.ts
View file @
27c207da
...
@@ -7,22 +7,27 @@ import { printAndExit } from '../server/lib/utils'
...
@@ -7,22 +7,27 @@ import { printAndExit } from '../server/lib/utils'
import
{
cliCommand
}
from
'../bin/next'
import
{
cliCommand
}
from
'../bin/next'
const
nextExport
:
cliCommand
=
(
argv
)
=>
{
const
nextExport
:
cliCommand
=
(
argv
)
=>
{
const
args
=
arg
(
const
validArgs
:
arg
.
Spec
=
{
{
// Types
// Types
'--help'
:
Boolean
,
'--help'
:
Boolean
,
'--silent'
:
Boolean
,
'--silent'
:
Boolean
,
'--outdir'
:
String
,
'--outdir'
:
String
,
'--threads'
:
Number
,
'--threads'
:
Number
,
// Aliases
'-h'
:
'--help'
,
'-s'
:
'--silent'
,
'-o'
:
'--outdir'
,
},
{
argv
}
)
// Aliases
'-h'
:
'--help'
,
'-s'
:
'--silent'
,
'-o'
:
'--outdir'
,
}
let
args
:
arg
.
Result
<
arg
.
Spec
>
try
{
args
=
arg
(
validArgs
,
{
argv
})
}
catch
(
error
)
{
if
(
error
.
code
===
'ARG_UNKNOWN_OPTION'
)
{
return
printAndExit
(
error
.
message
,
1
)
}
throw
error
}
if
(
args
[
'--help'
])
{
if
(
args
[
'--help'
])
{
// tslint:disable-next-line
// tslint:disable-next-line
console
.
log
(
`
console
.
log
(
`
...
...
packages/next/cli/next-start.ts
View file @
27c207da
...
@@ -3,25 +3,31 @@
...
@@ -3,25 +3,31 @@
import
{
resolve
}
from
'path'
import
{
resolve
}
from
'path'
import
arg
from
'next/dist/compiled/arg/index.js'
import
arg
from
'next/dist/compiled/arg/index.js'
import
startServer
from
'../server/lib/start-server'
import
startServer
from
'../server/lib/start-server'
import
{
printAndExit
}
from
'../server/lib/utils'
import
{
cliCommand
}
from
'../bin/next'
import
{
cliCommand
}
from
'../bin/next'
import
*
as
Log
from
'../build/output/log'
import
*
as
Log
from
'../build/output/log'
const
nextStart
:
cliCommand
=
(
argv
)
=>
{
const
nextStart
:
cliCommand
=
(
argv
)
=>
{
const
args
=
arg
(
const
validArgs
:
arg
.
Spec
=
{
{
// Types
// Types
'--help'
:
Boolean
,
'--help'
:
Boolean
,
'--port'
:
Number
,
'--port'
:
Number
,
'--hostname'
:
String
,
'--hostname'
:
String
,
// Aliases
'-h'
:
'--help'
,
'-p'
:
'--port'
,
'-H'
:
'--hostname'
,
},
{
argv
}
)
// Aliases
'-h'
:
'--help'
,
'-p'
:
'--port'
,
'-H'
:
'--hostname'
,
}
let
args
:
arg
.
Result
<
arg
.
Spec
>
try
{
args
=
arg
(
validArgs
,
{
argv
})
}
catch
(
error
)
{
if
(
error
.
code
===
'ARG_UNKNOWN_OPTION'
)
{
return
printAndExit
(
error
.
message
,
1
)
}
throw
error
}
if
(
args
[
'--help'
])
{
if
(
args
[
'--help'
])
{
// tslint:disable-next-line
// tslint:disable-next-line
console
.
log
(
`
console
.
log
(
`
...
...
packages/next/cli/next-telemetry.ts
View file @
27c207da
#!/usr/bin/env node
#!/usr/bin/env node
import
chalk
from
'next/dist/compiled/chalk'
import
chalk
from
'next/dist/compiled/chalk'
import
arg
from
'next/dist/compiled/arg/index.js'
import
arg
from
'next/dist/compiled/arg/index.js'
import
{
printAndExit
}
from
'../server/lib/utils'
import
{
cliCommand
}
from
'../bin/next'
import
{
cliCommand
}
from
'../bin/next'
import
{
Telemetry
}
from
'../telemetry/storage'
import
{
Telemetry
}
from
'../telemetry/storage'
const
nextTelemetry
:
cliCommand
=
(
argv
)
=>
{
const
nextTelemetry
:
cliCommand
=
(
argv
)
=>
{
const
args
=
arg
(
const
validArgs
:
arg
.
Spec
=
{
{
// Types
// Types
'--help'
:
Boolean
,
'--help'
:
Boolean
,
'--enable'
:
Boolean
,
'--enable'
:
Boolean
,
'--disable'
:
Boolean
,
'--disable'
:
Boolean
,
// Aliases
// Aliases
'-h'
:
'--help'
,
'-h'
:
'--help'
,
}
},
let
args
:
arg
.
Result
<
arg
.
Spec
>
{
argv
}
try
{
)
args
=
arg
(
validArgs
,
{
argv
})
}
catch
(
error
)
{
if
(
error
.
code
===
'ARG_UNKNOWN_OPTION'
)
{
return
printAndExit
(
error
.
message
,
1
)
}
throw
error
}
if
(
args
[
'--help'
])
{
if
(
args
[
'--help'
])
{
console
.
log
(
console
.
log
(
...
...
test/integration/build-warnings/test/index.test.js
View file @
27c207da
...
@@ -87,13 +87,4 @@ describe('Build warnings', () => {
...
@@ -87,13 +87,4 @@ describe('Build warnings', () => {
}))
}))
expect
(
stdout
).
not
.
toContain
(
'no-cache'
)
expect
(
stdout
).
not
.
toContain
(
'no-cache'
)
})
})
it
(
'should warn when unknown argument provided'
,
async
()
=>
{
const
{
stderr
}
=
await
nextBuild
(
appDir
,
[
'--random'
],
{
stderr
:
true
})
expect
(
stderr
).
toEqual
(
'Unknown or unexpected option: --random
\
n'
)
})
it
(
'should not throw UnhandledPromiseRejectionWarning'
,
async
()
=>
{
const
{
stderr
}
=
await
nextBuild
(
appDir
,
[
'--random'
],
{
stderr
:
true
})
expect
(
stderr
).
not
.
toContain
(
'UnhandledPromiseRejectionWarning'
)
})
})
})
test/integration/cli/test/index.test.js
View file @
27c207da
...
@@ -59,6 +59,19 @@ describe('CLI Usage', () => {
...
@@ -59,6 +59,19 @@ describe('CLI Usage', () => {
/Compiles the application for production deployment/
/Compiles the application for production deployment/
)
)
})
})
test
(
'should warn when unknown argument provided'
,
async
()
=>
{
const
{
stderr
}
=
await
runNextCommand
([
'build'
,
'--random'
],
{
stderr
:
true
,
})
expect
(
stderr
).
toEqual
(
'Unknown or unexpected option: --random
\
n'
)
})
test
(
'should not throw UnhandledPromiseRejectionWarning'
,
async
()
=>
{
const
{
stderr
}
=
await
runNextCommand
([
'build'
,
'--random'
],
{
stderr
:
true
,
})
expect
(
stderr
).
not
.
toContain
(
'UnhandledPromiseRejectionWarning'
)
})
})
})
describe
(
'dev'
,
()
=>
{
describe
(
'dev'
,
()
=>
{
...
@@ -121,6 +134,19 @@ describe('CLI Usage', () => {
...
@@ -121,6 +134,19 @@ describe('CLI Usage', () => {
)
)
expect
(
output
).
toMatch
(
new
RegExp
(
`http://0.0.0.0:
${
port
}
`
))
expect
(
output
).
toMatch
(
new
RegExp
(
`http://0.0.0.0:
${
port
}
`
))
})
})
test
(
'should warn when unknown argument provided'
,
async
()
=>
{
const
{
stderr
}
=
await
runNextCommand
([
'dev'
,
'--random'
],
{
stderr
:
true
,
})
expect
(
stderr
).
toEqual
(
'Unknown or unexpected option: --random
\
n'
)
})
test
(
'should not throw UnhandledPromiseRejectionWarning'
,
async
()
=>
{
const
{
stderr
}
=
await
runNextCommand
([
'dev'
,
'--random'
],
{
stderr
:
true
,
})
expect
(
stderr
).
not
.
toContain
(
'UnhandledPromiseRejectionWarning'
)
})
})
})
describe
(
'start'
,
()
=>
{
describe
(
'start'
,
()
=>
{
...
@@ -137,6 +163,19 @@ describe('CLI Usage', () => {
...
@@ -137,6 +163,19 @@ describe('CLI Usage', () => {
})
})
expect
(
help
.
stdout
).
toMatch
(
/Starts the application in production mode/
)
expect
(
help
.
stdout
).
toMatch
(
/Starts the application in production mode/
)
})
})
test
(
'should warn when unknown argument provided'
,
async
()
=>
{
const
{
stderr
}
=
await
runNextCommand
([
'start'
,
'--random'
],
{
stderr
:
true
,
})
expect
(
stderr
).
toEqual
(
'Unknown or unexpected option: --random
\
n'
)
})
test
(
'should not throw UnhandledPromiseRejectionWarning'
,
async
()
=>
{
const
{
stderr
}
=
await
runNextCommand
([
'start'
,
'--random'
],
{
stderr
:
true
,
})
expect
(
stderr
).
not
.
toContain
(
'UnhandledPromiseRejectionWarning'
)
})
})
})
describe
(
'export'
,
()
=>
{
describe
(
'export'
,
()
=>
{
...
@@ -153,5 +192,51 @@ describe('CLI Usage', () => {
...
@@ -153,5 +192,51 @@ describe('CLI Usage', () => {
})
})
expect
(
help
.
stdout
).
toMatch
(
/Exports the application/
)
expect
(
help
.
stdout
).
toMatch
(
/Exports the application/
)
})
})
test
(
'should warn when unknown argument provided'
,
async
()
=>
{
const
{
stderr
}
=
await
runNextCommand
([
'export'
,
'--random'
],
{
stderr
:
true
,
})
expect
(
stderr
).
toEqual
(
'Unknown or unexpected option: --random
\
n'
)
})
test
(
'should not throw UnhandledPromiseRejectionWarning'
,
async
()
=>
{
const
{
stderr
}
=
await
runNextCommand
([
'export'
,
'--random'
],
{
stderr
:
true
,
})
expect
(
stderr
).
not
.
toContain
(
'UnhandledPromiseRejectionWarning'
)
})
})
describe
(
'telemetry'
,
()
=>
{
test
(
'--help'
,
async
()
=>
{
const
help
=
await
runNextCommand
([
'telemetry'
,
'--help'
],
{
stdout
:
true
,
})
expect
(
help
.
stdout
).
toMatch
(
/Allows you to control Next
\.
js' telemetry collection/
)
})
test
(
'-h'
,
async
()
=>
{
const
help
=
await
runNextCommand
([
'telemetry'
,
'-h'
],
{
stdout
:
true
,
})
expect
(
help
.
stdout
).
toMatch
(
/Allows you to control Next
\.
js' telemetry collection/
)
})
test
(
'should warn when unknown argument provided'
,
async
()
=>
{
const
{
stderr
}
=
await
runNextCommand
([
'telemetry'
,
'--random'
],
{
stderr
:
true
,
})
expect
(
stderr
).
toEqual
(
'Unknown or unexpected option: --random
\
n'
)
})
test
(
'should not throw UnhandledPromiseRejectionWarning'
,
async
()
=>
{
const
{
stderr
}
=
await
runNextCommand
([
'telemetry'
,
'--random'
],
{
stderr
:
true
,
})
expect
(
stderr
).
not
.
toContain
(
'UnhandledPromiseRejectionWarning'
)
})
})
})
})
})
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