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
61b8b732
Commit
61b8b732
authored
Sep 04, 2019
by
JJ Kasper
Committed by
Joe Haddad
Sep 04, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update workers for `next export` (#8623)
* Add failing test * Add jest-worker to export
parent
110c83fa
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
17 changed files
with
245 additions
and
227 deletions
+245
-227
index.js
packages/next/export/index.js
+47
-62
worker.js
packages/next/export/worker.js
+152
-165
index copy 10.js
.../integration/handles-export-errors/pages/index copy 10.js
+2
-0
index copy 11.js
.../integration/handles-export-errors/pages/index copy 11.js
+2
-0
index copy 12.js
.../integration/handles-export-errors/pages/index copy 12.js
+2
-0
index copy 13.js
.../integration/handles-export-errors/pages/index copy 13.js
+2
-0
index copy 2.js
test/integration/handles-export-errors/pages/index copy 2.js
+2
-0
index copy 3.js
test/integration/handles-export-errors/pages/index copy 3.js
+2
-0
index copy 4.js
test/integration/handles-export-errors/pages/index copy 4.js
+2
-0
index copy 5.js
test/integration/handles-export-errors/pages/index copy 5.js
+2
-0
index copy 6.js
test/integration/handles-export-errors/pages/index copy 6.js
+2
-0
index copy 7.js
test/integration/handles-export-errors/pages/index copy 7.js
+2
-0
index copy 8.js
test/integration/handles-export-errors/pages/index copy 8.js
+2
-0
index copy 9.js
test/integration/handles-export-errors/pages/index copy 9.js
+2
-0
index copy.js
test/integration/handles-export-errors/pages/index copy.js
+2
-0
index.js
test/integration/handles-export-errors/pages/index.js
+2
-0
index.test.js
test/integration/handles-export-errors/test/index.test.js
+18
-0
No files found.
packages/next/export/index.js
View file @
61b8b732
import
{
cpus
}
from
'os'
import
{
cpus
}
from
'os'
import
{
fork
}
from
'child_process'
import
chalk
from
'chalk'
import
{
recursiveCopy
}
from
'../lib/recursive-copy'
import
Worker
from
'jest-worker'
import
{
promisify
}
from
'util'
import
mkdirpModule
from
'mkdirp'
import
mkdirpModule
from
'mkdirp'
import
{
resolve
,
join
}
from
'path'
import
{
resolve
,
join
}
from
'path'
import
{
API_ROUTE
}
from
'../lib/constants'
import
{
existsSync
,
readFileSync
}
from
'fs'
import
{
existsSync
,
readFileSync
}
from
'fs'
import
chalk
from
'chalk'
import
createProgress
from
'tty-aware-progress'
import
{
recursiveCopy
}
from
'../lib/recursive-copy'
import
{
recursiveDelete
}
from
'../lib/recursive-delete'
import
{
formatAmpMessages
}
from
'../build/output/index'
import
loadConfig
,
{
import
loadConfig
,
{
isTargetLikeServerless
isTargetLikeServerless
}
from
'../next-server/server/config'
}
from
'../next-server/server/config'
...
@@ -17,11 +22,6 @@ import {
...
@@ -17,11 +22,6 @@ import {
CLIENT_PUBLIC_FILES_PATH
,
CLIENT_PUBLIC_FILES_PATH
,
CLIENT_STATIC_FILES_PATH
CLIENT_STATIC_FILES_PATH
}
from
'../next-server/lib/constants'
}
from
'../next-server/lib/constants'
import
createProgress
from
'tty-aware-progress'
import
{
promisify
}
from
'util'
import
{
recursiveDelete
}
from
'../lib/recursive-delete'
import
{
API_ROUTE
}
from
'../lib/constants'
import
{
formatAmpMessages
}
from
'../build/output/index'
const
mkdirp
=
promisify
(
mkdirpModule
)
const
mkdirp
=
promisify
(
mkdirpModule
)
...
@@ -33,7 +33,6 @@ export default async function (dir, options, configuration) {
...
@@ -33,7 +33,6 @@ export default async function (dir, options, configuration) {
dir
=
resolve
(
dir
)
dir
=
resolve
(
dir
)
const
nextConfig
=
configuration
||
loadConfig
(
PHASE_EXPORT
,
dir
)
const
nextConfig
=
configuration
||
loadConfig
(
PHASE_EXPORT
,
dir
)
const
concurrency
=
options
.
concurrency
||
10
const
threads
=
options
.
threads
||
Math
.
max
(
cpus
().
length
-
1
,
1
)
const
threads
=
options
.
threads
||
Math
.
max
(
cpus
().
length
-
1
,
1
)
const
distDir
=
join
(
dir
,
nextConfig
.
distDir
)
const
distDir
=
join
(
dir
,
nextConfig
.
distDir
)
const
subFolders
=
nextConfig
.
exportTrailingSlash
const
subFolders
=
nextConfig
.
exportTrailingSlash
...
@@ -130,9 +129,7 @@ export default async function (dir, options, configuration) {
...
@@ -130,9 +129,7 @@ export default async function (dir, options, configuration) {
nextExport
:
true
nextExport
:
true
}
}
log
(
log
(
` launching
${
threads
}
workers`
)
` launching
${
threads
}
threads with concurrency of
${
concurrency
}
per thread`
)
const
exportPathMap
=
await
nextConfig
.
exportPathMap
(
defaultPathMap
,
{
const
exportPathMap
=
await
nextConfig
.
exportPathMap
(
defaultPathMap
,
{
dev
:
false
,
dev
:
false
,
dir
,
dir
,
...
@@ -163,20 +160,6 @@ export default async function (dir, options, configuration) {
...
@@ -163,20 +160,6 @@ export default async function (dir, options, configuration) {
const
progress
=
!
options
.
silent
&&
createProgress
(
filteredPaths
.
length
)
const
progress
=
!
options
.
silent
&&
createProgress
(
filteredPaths
.
length
)
const
chunks
=
filteredPaths
.
reduce
((
result
,
route
,
i
)
=>
{
const
worker
=
i
%
threads
if
(
!
result
[
worker
])
{
result
[
worker
]
=
{
paths
:
[],
pathMap
:
{}
}
}
result
[
worker
].
pathMap
[
route
]
=
exportPathMap
[
route
]
result
[
worker
].
paths
.
push
(
route
)
if
(
options
.
sprPages
&&
options
.
sprPages
.
has
(
route
))
{
result
[
worker
].
pathMap
[
route
].
sprPage
=
true
}
return
result
},
[])
const
ampValidations
=
{}
const
ampValidations
=
{}
let
hadValidationError
=
false
let
hadValidationError
=
false
...
@@ -195,46 +178,45 @@ export default async function (dir, options, configuration) {
...
@@ -195,46 +178,45 @@ export default async function (dir, options, configuration) {
}
}
})
})
}
}
const
workers
=
new
Set
()
const
worker
=
new
Worker
(
require
.
resolve
(
'./worker'
),
{
maxRetries
:
0
,
numWorkers
:
threads
,
enableWorkerThreads
:
true
,
exposedMethods
:
[
'default'
]
})
worker
.
getStdout
().
pipe
(
process
.
stdout
)
worker
.
getStderr
().
pipe
(
process
.
stderr
)
let
renderError
=
false
await
Promise
.
all
(
await
Promise
.
all
(
chunks
.
map
(
filteredPaths
.
map
(
async
path
=>
{
chunk
=>
const
result
=
await
worker
.
default
({
new
Promise
((
resolve
,
reject
)
=>
{
path
,
const
worker
=
fork
(
require
.
resolve
(
'./worker'
),
[],
{
pathMap
:
exportPathMap
[
path
],
env
:
process
.
env
distDir
,
})
buildId
,
workers
.
add
(
worker
)
outDir
,
worker
.
send
({
renderOpts
,
distDir
,
serverRuntimeConfig
,
buildId
,
subFolders
,
exportPaths
:
chunk
.
paths
,
serverless
:
isTargetLikeServerless
(
nextConfig
.
target
)
exportPathMap
:
chunk
.
pathMap
,
})
outDir
,
renderOpts
,
for
(
const
validation
of
result
.
ampValidations
||
[])
{
serverRuntimeConfig
,
const
{
page
,
result
}
=
validation
concurrency
,
ampValidations
[
page
]
=
result
subFolders
,
hadValidationError
|=
serverless
:
isTargetLikeServerless
(
nextConfig
.
target
)
Array
.
isArray
(
result
&&
result
.
errors
)
&&
result
.
errors
.
length
>
0
})
}
worker
.
on
(
'message'
,
({
type
,
payload
})
=>
{
renderError
|=
result
.
error
if
(
type
===
'progress'
&&
progress
)
{
if
(
progress
)
progress
()
progress
()
})
}
else
if
(
type
===
'error'
)
{
reject
(
payload
)
}
else
if
(
type
===
'done'
)
{
resolve
()
}
else
if
(
type
===
'amp-validation'
)
{
ampValidations
[
payload
.
page
]
=
payload
.
result
hadValidationError
=
hadValidationError
||
payload
.
result
.
errors
.
length
}
})
})
)
)
)
worker
s
.
forEach
(
worker
=>
worker
.
kill
()
)
worker
.
end
(
)
if
(
Object
.
keys
(
ampValidations
).
length
)
{
if
(
Object
.
keys
(
ampValidations
).
length
)
{
console
.
log
(
formatAmpMessages
(
ampValidations
))
console
.
log
(
formatAmpMessages
(
ampValidations
))
...
@@ -245,6 +227,9 @@ export default async function (dir, options, configuration) {
...
@@ -245,6 +227,9 @@ export default async function (dir, options, configuration) {
)
)
}
}
if
(
renderError
)
{
throw
new
Error
(
`Export encountered errors`
)
}
// Add an empty line to the console for the better readability.
// Add an empty line to the console for the better readability.
log
(
''
)
log
(
''
)
}
}
packages/next/export/worker.js
View file @
61b8b732
This diff is collapsed.
Click to expand it.
test/integration/handles-export-errors/pages/index copy 10.js
0 → 100644
View file @
61b8b732
// eslint-disable-next-line
export
default
()
=>
hello
.
world
test/integration/handles-export-errors/pages/index copy 11.js
0 → 100644
View file @
61b8b732
// eslint-disable-next-line
export
default
()
=>
hello
.
world
test/integration/handles-export-errors/pages/index copy 12.js
0 → 100644
View file @
61b8b732
// eslint-disable-next-line
export
default
()
=>
hello
.
world
test/integration/handles-export-errors/pages/index copy 13.js
0 → 100644
View file @
61b8b732
// eslint-disable-next-line
export
default
()
=>
hello
.
world
test/integration/handles-export-errors/pages/index copy 2.js
0 → 100644
View file @
61b8b732
// eslint-disable-next-line
export
default
()
=>
hello
.
world
test/integration/handles-export-errors/pages/index copy 3.js
0 → 100644
View file @
61b8b732
// eslint-disable-next-line
export
default
()
=>
hello
.
world
test/integration/handles-export-errors/pages/index copy 4.js
0 → 100644
View file @
61b8b732
// eslint-disable-next-line
export
default
()
=>
hello
.
world
test/integration/handles-export-errors/pages/index copy 5.js
0 → 100644
View file @
61b8b732
// eslint-disable-next-line
export
default
()
=>
hello
.
world
test/integration/handles-export-errors/pages/index copy 6.js
0 → 100644
View file @
61b8b732
// eslint-disable-next-line
export
default
()
=>
hello
.
world
test/integration/handles-export-errors/pages/index copy 7.js
0 → 100644
View file @
61b8b732
// eslint-disable-next-line
export
default
()
=>
hello
.
world
test/integration/handles-export-errors/pages/index copy 8.js
0 → 100644
View file @
61b8b732
// eslint-disable-next-line
export
default
()
=>
hello
.
world
test/integration/handles-export-errors/pages/index copy 9.js
0 → 100644
View file @
61b8b732
// eslint-disable-next-line
export
default
()
=>
hello
.
world
test/integration/handles-export-errors/pages/index copy.js
0 → 100644
View file @
61b8b732
// eslint-disable-next-line
export
default
()
=>
hello
.
world
test/integration/handles-export-errors/pages/index.js
0 → 100644
View file @
61b8b732
// eslint-disable-next-line
export
default
()
=>
hello
.
world
test/integration/handles-export-errors/test/index.test.js
0 → 100644
View file @
61b8b732
/* eslint-env jest */
/* global jasmine */
import
path
from
'path'
import
{
nextBuild
}
from
'next-test-utils'
jasmine
.
DEFAULT_TIMEOUT_INTERVAL
=
1000
*
60
*
5
const
appDir
=
path
.
join
(
__dirname
,
'..'
)
describe
(
'Handles Errors During Export'
,
()
=>
{
it
(
'Does not crash workers'
,
async
()
=>
{
const
{
stdout
,
stderr
}
=
await
nextBuild
(
appDir
,
[],
{
stdout
:
true
,
stderr
:
true
})
expect
(
stdout
+
stderr
).
not
.
toMatch
(
/ERR_IPC_CHANNEL_CLOSED/
)
})
})
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