未验证 提交 841cd6c4 编写于 作者: J Joe Haddad 提交者: GitHub

Fix Situation Where Build Can Hang Indefinitely (#11881)

上级 4e6d6d20
......@@ -57,8 +57,16 @@ export default class TaskRunner {
const done = () => step(index, result)
if (cachePath) {
writeFileP(cachePath, JSON.stringify(result), 'utf8')
.then(done)
.catch(done)
// This is important to stay as `.then(fn1, fn2)` and not
// `.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) {
step(index, { error })
......@@ -66,9 +74,22 @@ export default class TaskRunner {
}
if (this.cacheDir) {
readFileP(cachePath, 'utf8')
.then(data => step(index, JSON.parse(data)))
.catch(() => enqueue())
// This is important to stay as `.then(fn1, fn2)` and not
// `.then(fn1).catch(fn2)` so that we don't double-invoke `step` when
// `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 {
enqueue()
}
......
......@@ -4,7 +4,7 @@
import stringHash from 'next/dist/compiled/string-hash'
import { SourceMapConsumer } from 'next/dist/compiled/source-map'
import { SourceMapSource, RawSource } from 'webpack-sources'
import { RequestShortener } from 'webpack'
import RequestShortener from 'webpack/lib/RequestShortener'
import TaskRunner from './TaskRunner'
const warningRegex = /\[.+:([0-9]+),([0-9]+)\]/
......@@ -204,8 +204,11 @@ export class TerserPlugin {
taskRunner.run(tasks, (tasksError, results) => {
if (tasksError) {
compilation.errors.push(tasksError)
try {
taskRunner.exit()
} finally {
callback(tasksError)
}
return
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册