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
3205aedf
Unverified
Commit
3205aedf
authored
Oct 21, 2024
by
Jiachi Liu
Committed by
GitHub
Oct 21, 2024
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: handle terminal color in chrome console (#71581)
parent
2b860fdf
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
67 additions
and
7 deletions
+67
-7
index.ts
packages/next/src/build/index.ts
+11
-3
progress.ts
packages/next/src/build/progress.ts
+19
-1
spinner.ts
packages/next/src/build/spinner.ts
+13
-2
worker.ts
packages/next/src/export/worker.ts
+1
-1
worker.ts
packages/next/src/lib/worker.ts
+23
-0
No files found.
packages/next/src/build/index.ts
View file @
3205aedf
...
@@ -649,12 +649,20 @@ const staticWorkerExposedMethods = [
...
@@ -649,12 +649,20 @@ const staticWorkerExposedMethods = [
type
StaticWorker
=
typeof
import
(
'./worker'
)
&
Worker
type
StaticWorker
=
typeof
import
(
'./worker'
)
&
Worker
export
function
createStaticWorker
(
export
function
createStaticWorker
(
config
:
NextConfigComplete
,
config
:
NextConfigComplete
,
onActivity
?:
()
=>
void
progress
?:
{
run
:
()
=>
void
clear
:
()
=>
void
}
):
StaticWorker
{
):
StaticWorker
{
return
new
Worker
(
staticWorkerPath
,
{
return
new
Worker
(
staticWorkerPath
,
{
logger
:
Log
,
logger
:
Log
,
numWorkers
:
getNumberOfWorkers
(
config
),
numWorkers
:
getNumberOfWorkers
(
config
),
onActivity
,
onActivity
:
()
=>
{
progress
?.
run
()
},
onActivityAbort
:
()
=>
{
progress
?.
clear
()
},
forkOptions
:
{
forkOptions
:
{
env
:
process
.
env
,
env
:
process
.
env
,
},
},
...
@@ -1516,7 +1524,7 @@ export default async function build(
...
@@ -1516,7 +1524,7 @@ export default async function build(
remainingRampup
--
remainingRampup
--
sema
.
release
()
sema
.
release
()
}
}
progress
()
progress
.
run
()
}
}
})()
})()
)
)
...
...
packages/next/src/build/progress.ts
View file @
3205aedf
...
@@ -47,7 +47,7 @@ export const createProgress = (total: number, label: string) => {
...
@@ -47,7 +47,7 @@ export const createProgress = (total: number, label: string) => {
},
},
})
})
return
()
=>
{
const
run
=
()
=>
{
curProgress
++
curProgress
++
// Make sure we only log once
// Make sure we only log once
...
@@ -80,4 +80,22 @@ export const createProgress = (total: number, label: string) => {
...
@@ -80,4 +80,22 @@ export const createProgress = (total: number, label: string) => {
}
}
}
}
}
}
const
clear
=
()
=>
{
if
(
progressSpinner
&&
// Ensure only reset and clear once to avoid set operation overflow in ora
progressSpinner
.
isSpinning
)
{
progressSpinner
.
prefixText
=
'
\
r'
progressSpinner
.
text
=
'
\
r'
progressSpinner
.
clear
()
progressSpinner
.
stop
()
}
}
return
{
run
,
clear
,
}
}
}
packages/next/src/build/spinner.ts
View file @
3205aedf
...
@@ -33,9 +33,20 @@ export default function createSpinner(
...
@@ -33,9 +33,20 @@ export default function createSpinner(
const
origStopAndPersist
=
spinner
.
stopAndPersist
.
bind
(
spinner
)
const
origStopAndPersist
=
spinner
.
stopAndPersist
.
bind
(
spinner
)
const
logHandle
=
(
method
:
any
,
args
:
any
[])
=>
{
const
logHandle
=
(
method
:
any
,
args
:
any
[])
=>
{
origStop
()
// Enter a new line before logging new message, to avoid
// the new message shows up right after the spinner in the same line.
const
isInProgress
=
spinner
?.
isSpinning
if
(
spinner
&&
isInProgress
)
{
// Reset the current running spinner to empty line by `\r`
spinner
.
prefixText
=
'
\
r'
spinner
.
text
=
'
\
r'
spinner
.
clear
()
origStop
()
}
method
(...
args
)
method
(...
args
)
spinner
!
.
start
()
if
(
spinner
&&
isInProgress
)
{
spinner
.
start
()
}
}
}
console
.
log
=
(...
args
:
any
)
=>
logHandle
(
origLog
,
args
)
console
.
log
=
(...
args
:
any
)
=>
logHandle
(
origLog
,
args
)
...
...
packages/next/src/export/worker.ts
View file @
3205aedf
...
@@ -539,7 +539,7 @@ async function exportPage(
...
@@ -539,7 +539,7 @@ async function exportPage(
}
}
}
catch
(
err
)
{
}
catch
(
err
)
{
console
.
error
(
console
.
error
(
`
\nError occurred prerendering page "
${
input
.
path
}
". Read more: https://nextjs.org/docs/messages/prerender-error\n
`
`
Error occurred prerendering page "
${
input
.
path
}
". Read more: https://nextjs.org/docs/messages/prerender-error
`
)
)
// bailoutToCSRError errors should not leak to the user as they are not actionable; they're
// bailoutToCSRError errors should not leak to the user as they are not actionable; they're
...
...
packages/next/src/lib/worker.ts
View file @
3205aedf
...
@@ -4,6 +4,8 @@ import {
...
@@ -4,6 +4,8 @@ import {
getParsedNodeOptionsWithoutInspect
,
getParsedNodeOptionsWithoutInspect
,
formatNodeOptions
,
formatNodeOptions
,
}
from
'../server/lib/utils'
}
from
'../server/lib/utils'
import
{
Transform
}
from
'stream'
type
FarmOptions
=
ConstructorParameters
<
typeof
JestWorker
>
[
1
]
type
FarmOptions
=
ConstructorParameters
<
typeof
JestWorker
>
[
1
]
const
RESTARTED
=
Symbol
(
'restarted'
)
const
RESTARTED
=
Symbol
(
'restarted'
)
...
@@ -24,6 +26,7 @@ export class Worker {
...
@@ -24,6 +26,7 @@ export class Worker {
options
:
FarmOptions
&
{
options
:
FarmOptions
&
{
timeout
?:
number
timeout
?:
number
onActivity
?:
()
=>
void
onActivity
?:
()
=>
void
onActivityAbort
?:
()
=>
void
onRestart
?:
(
method
:
string
,
args
:
any
[],
attempts
:
number
)
=>
void
onRestart
?:
(
method
:
string
,
args
:
any
[],
attempts
:
number
)
=>
void
logger
?:
Pick
<
typeof
console
,
'error'
|
'info'
|
'warn'
>
logger
?:
Pick
<
typeof
console
,
'error'
|
'info'
|
'warn'
>
exposedMethods
:
ReadonlyArray
<
string
>
exposedMethods
:
ReadonlyArray
<
string
>
...
@@ -106,6 +109,26 @@ export class Worker {
...
@@ -106,6 +109,26 @@ export class Worker {
}
}
}
}
let
aborted
=
false
const
onActivityAbort
=
()
=>
{
if
(
!
aborted
)
{
options
.
onActivityAbort
?.()
aborted
=
true
}
}
// Listen to the worker's stdout and stderr, if there's any thing logged, abort the activity first
const
abortActivityStreamOnLog
=
new
Transform
({
transform
(
_chunk
,
_encoding
,
callback
)
{
onActivityAbort
()
callback
()
},
})
// Stop the activity if there's any output from the worker
this
.
_worker
.
getStdout
().
pipe
(
abortActivityStreamOnLog
)
this
.
_worker
.
getStderr
().
pipe
(
abortActivityStreamOnLog
)
// Pipe the worker's stdout and stderr to the parent process
this
.
_worker
.
getStdout
().
pipe
(
process
.
stdout
)
this
.
_worker
.
getStdout
().
pipe
(
process
.
stdout
)
this
.
_worker
.
getStderr
().
pipe
(
process
.
stderr
)
this
.
_worker
.
getStderr
().
pipe
(
process
.
stderr
)
}
}
...
...
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