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
9dc0afd9
Unverified
Commit
9dc0afd9
authored
Feb 07, 2020
by
JJ Kasper
Committed by
GitHub
Feb 07, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Redesign custom-routes output and show headers in output (#10444)
parent
c0eab7ee
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
64 additions
and
39 deletions
+64
-39
index.ts
packages/next/build/index.ts
+1
-1
utils.ts
packages/next/build/utils.ts
+49
-31
index.test.js
test/integration/custom-routes/test/index.test.js
+14
-7
No files found.
packages/next/build/index.ts
View file @
9dc0afd9
...
@@ -842,7 +842,7 @@ export default async function build(dir: string, conf = null): Promise<void> {
...
@@ -842,7 +842,7 @@ export default async function build(dir: string, conf = null): Promise<void> {
isModern
:
config
.
experimental
.
modern
,
isModern
:
config
.
experimental
.
modern
,
}
}
)
)
printCustomRoutes
({
redirects
,
rewrites
})
printCustomRoutes
({
redirects
,
rewrites
,
headers
})
if
(
tracer
)
{
if
(
tracer
)
{
const
parsedResults
=
await
tracer
.
profiler
.
stopProfiling
()
const
parsedResults
=
await
tracer
.
profiler
.
stopProfiling
()
...
...
packages/next/build/utils.ts
View file @
9dc0afd9
...
@@ -4,11 +4,7 @@ import textTable from 'next/dist/compiled/text-table'
...
@@ -4,11 +4,7 @@ import textTable from 'next/dist/compiled/text-table'
import
path
from
'path'
import
path
from
'path'
import
{
isValidElementType
}
from
'react-is'
import
{
isValidElementType
}
from
'react-is'
import
stripAnsi
from
'strip-ansi'
import
stripAnsi
from
'strip-ansi'
import
{
import
{
Redirect
,
Rewrite
,
Header
}
from
'../lib/check-custom-routes'
Redirect
,
Rewrite
,
getRedirectStatus
,
}
from
'../lib/check-custom-routes'
import
{
import
{
SSG_GET_INITIAL_PROPS_CONFLICT
,
SSG_GET_INITIAL_PROPS_CONFLICT
,
SERVER_PROPS_GET_INIT_PROPS_CONFLICT
,
SERVER_PROPS_GET_INIT_PROPS_CONFLICT
,
...
@@ -232,43 +228,62 @@ export async function printTreeView(
...
@@ -232,43 +228,62 @@ export async function printTreeView(
export function printCustomRoutes({
export function printCustomRoutes({
redirects,
redirects,
rewrites,
rewrites,
headers,
}: {
}: {
redirects: Redirect[]
redirects: Redirect[]
rewrites: Rewrite[]
rewrites: Rewrite[]
headers: Header[]
}) {
}) {
const printRoutes = (
const printRoutes = (
routes: Redirect[] | Rewrite[],
routes: Redirect[] | Rewrite[]
| Header[]
,
type: 'Redirects' | 'Rewrites'
type: 'Redirects' | 'Rewrites'
| 'Headers'
) => {
) => {
const isRedirects = type === 'Redirects'
const isRedirects = type === 'Redirects'
const isHeaders = type === 'Headers'
console.log(chalk.underline(type))
console.log(chalk.underline(type))
console.log()
console.log()
console.log(
/*
textTable(
┌ source
[
├ permanent/statusCode
[
└ destination
'Source',
*/
'Destination',
const routesStr = (routes as any[])
...(isRedirects ? ['statusCode'] : []),
.map((route: { source: string }) => {
].map(str => chalk.bold(str)),
let routeStr = `
┌
source
:
$
{
route
.
source
}
\
n
`
...Object.entries(routes).map(([key, route]) => {
return [
if (!isHeaders) {
route.source,
const r = route as Rewrite
route.destination,
routeStr += `
$
{
isRedirects
?
'├'
:
'└'
}
destination
:
$
{
...(isRedirects
r
.
destination
? [getRedirectStatus(route as Redirect) + '']
}
\
n
`
: []),
]
}),
],
{
align: ['l', 'l', 'l'],
stringLength: str => stripAnsi(str).length,
}
}
)
if (isRedirects) {
)
const r = route as Redirect
console.log()
routeStr += `
└
$
{
r
.
statusCode
?
`status:
${
r
.
statusCode
}
`
:
`permanent:
${
r
.
permanent
}
`
}
\
n
`
}
if (isHeaders) {
const r = route as Header
routeStr += `
└
headers
:
\
n
`
for (let i = 0; i < r.headers.length; i++) {
const header = r.headers[i]
const last = i === headers.length - 1
routeStr += `
$
{
last
?
'└'
:
'├'
}
${
header
.
key
}
:
${
header
.
value
}
\n`
}
}
return
routeStr
})
.
join
(
'
\
n'
)
console
.
log
(
routesStr
,
'
\
n'
)
}
}
if
(
redirects
.
length
)
{
if
(
redirects
.
length
)
{
...
@@ -277,6 +292,9 @@ export function printCustomRoutes({
...
@@ -277,6 +292,9 @@ export function printCustomRoutes({
if
(
rewrites
.
length
)
{
if
(
rewrites
.
length
)
{
printRoutes
(
rewrites
,
'Rewrites'
)
printRoutes
(
rewrites
,
'Rewrites'
)
}
}
if
(
headers
.
length
)
{
printRoutes
(
headers
,
'Headers'
)
}
}
}
type
BuildManifestShape
=
{
pages
:
{
[
k
:
string
]:
string
[]
}
}
type
BuildManifestShape
=
{
pages
:
{
[
k
:
string
]:
string
[]
}
}
...
...
test/integration/custom-routes/test/index.test.js
View file @
9dc0afd9
...
@@ -7,7 +7,6 @@ import fs from 'fs-extra'
...
@@ -7,7 +7,6 @@ import fs from 'fs-extra'
import
{
join
}
from
'path'
import
{
join
}
from
'path'
import
cheerio
from
'cheerio'
import
cheerio
from
'cheerio'
import
webdriver
from
'next-webdriver'
import
webdriver
from
'next-webdriver'
import
escapeRegex
from
'escape-string-regexp'
import
{
import
{
launchApp
,
launchApp
,
killApp
,
killApp
,
...
@@ -548,14 +547,22 @@ const runTests = (isDev = false) => {
...
@@ -548,14 +547,22 @@ const runTests = (isDev = false) => {
const
cleanStdout
=
stripAnsi
(
stdout
)
const
cleanStdout
=
stripAnsi
(
stdout
)
expect
(
cleanStdout
).
toContain
(
'Redirects'
)
expect
(
cleanStdout
).
toContain
(
'Redirects'
)
expect
(
cleanStdout
).
toContain
(
'Rewrites'
)
expect
(
cleanStdout
).
toContain
(
'Rewrites'
)
expect
(
cleanStdout
).
toMatch
(
/Source.*
?
Destination.*
?
statusCode/i
)
expect
(
cleanStdout
).
toContain
(
'Headers'
)
expect
(
cleanStdout
).
toMatch
(
/source.*
?
/i
)
expect
(
cleanStdout
).
toMatch
(
/destination.*
?
/i
)
for
(
const
route
of
[...
manifest
.
redirects
,
...
manifest
.
rewrites
])
{
for
(
const
route
of
[...
manifest
.
redirects
,
...
manifest
.
rewrites
])
{
expect
(
cleanStdout
).
toMatch
(
expect
(
cleanStdout
).
toContain
(
route
.
source
)
new
RegExp
(
expect
(
cleanStdout
).
toContain
(
route
.
destination
)
`
${
escapeRegex
(
route
.
source
)}
.*?
${
escapeRegex
(
route
.
destination
)}
`
}
)
)
for
(
const
route
of
manifest
.
headers
)
{
expect
(
cleanStdout
).
toContain
(
route
.
source
)
for
(
const
header
of
route
.
headers
)
{
expect
(
cleanStdout
).
toContain
(
header
.
key
)
expect
(
cleanStdout
).
toContain
(
header
.
value
)
}
}
}
})
})
}
else
{
}
else
{
...
...
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