Unverified Commit 841cd6c4 authored by Joe Haddad's avatar Joe Haddad Committed by GitHub

Fix Situation Where Build Can Hang Indefinitely (#11881)

parent 4e6d6d20
...@@ -57,8 +57,16 @@ export default class TaskRunner { ...@@ -57,8 +57,16 @@ export default class TaskRunner {
const done = () => step(index, result) const done = () => step(index, result)
if (cachePath) { if (cachePath) {
writeFileP(cachePath, JSON.stringify(result), 'utf8') writeFileP(cachePath, JSON.stringify(result), 'utf8')
.then(done) // This is important to stay as `.then(fn1, fn2)` and not
.catch(done) // `.then(fn1).catch(fn2)` so that we don't double-invoke `step`
// when `done` emits an error.
.then(done, done)
.catch(err => {
// Abort task on internal error (`done` failed). This can
// happen when users have a bad `package-lock.json` with an
// invalid webpack version, etc:
callback(err)
})
} }
} catch (error) { } catch (error) {
step(index, { error }) step(index, { error })
...@@ -66,9 +74,22 @@ export default class TaskRunner { ...@@ -66,9 +74,22 @@ export default class TaskRunner {
} }
if (this.cacheDir) { if (this.cacheDir) {
readFileP(cachePath, 'utf8') // This is important to stay as `.then(fn1, fn2)` and not
.then(data => step(index, JSON.parse(data))) // `.then(fn1).catch(fn2)` so that we don't double-invoke `step` when
.catch(() => enqueue()) // `step` emits an error.
readFileP(cachePath, 'utf8').then(
data => {
try {
step(index, JSON.parse(data))
} catch (err) {
// Abort task on internal error (`done` failed). This can happen
// when users have a bad `package-lock.json` with an invalid
// webpack version, etc:
callback(err)
}
},
() => enqueue()
)
} else { } else {
enqueue() enqueue()
} }
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
import stringHash from 'next/dist/compiled/string-hash' import stringHash from 'next/dist/compiled/string-hash'
import { SourceMapConsumer } from 'next/dist/compiled/source-map' import { SourceMapConsumer } from 'next/dist/compiled/source-map'
import { SourceMapSource, RawSource } from 'webpack-sources' import { SourceMapSource, RawSource } from 'webpack-sources'
import { RequestShortener } from 'webpack' import RequestShortener from 'webpack/lib/RequestShortener'
import TaskRunner from './TaskRunner' import TaskRunner from './TaskRunner'
const warningRegex = /\[.+:([0-9]+),([0-9]+)\]/ const warningRegex = /\[.+:([0-9]+),([0-9]+)\]/
...@@ -204,8 +204,11 @@ export class TerserPlugin { ...@@ -204,8 +204,11 @@ export class TerserPlugin {
taskRunner.run(tasks, (tasksError, results) => { taskRunner.run(tasks, (tasksError, results) => {
if (tasksError) { if (tasksError) {
compilation.errors.push(tasksError) try {
taskRunner.exit()
} finally {
callback(tasksError)
}
return return
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment