Skip to content

Commit 6d2265d

Browse files
committed
switch to promise as await seems to still hold things up
1 parent f0e1b1b commit 6d2265d

File tree

1 file changed

+69
-61
lines changed

1 file changed

+69
-61
lines changed

packages/react-dev-utils/WebpackDevServerUtils.js

+69-61
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ function createCompiler(
166166

167167
// "done" event fires when Webpack has finished recompiling the bundle.
168168
// Whether or not you have warnings or errors, you will get this event.
169-
compiler.hooks.done.tap('done', async stats => {
169+
compiler.hooks.done.tap('done', stats => {
170170
if (useTypeScript) {
171171
if (isInteractive) {
172172
clearConsole();
@@ -188,72 +188,48 @@ function createCompiler(
188188
stats.toJson({ all: false, warnings: true, errors: true })
189189
);
190190

191-
if (useTypeScript) {
192-
const asyncMessages = await tsMessagesPromise;
193-
194-
// Push errors and warnings into compilation result
195-
// to show them after page refresh triggered by user.
196-
// This is important for errors on first run in development.
197-
stats.compilation.errors.push(...asyncMessages.errors);
198-
stats.compilation.warnings.push(...asyncMessages.warnings);
191+
(tsMessagesPromise || Promise.resolve({ errors: [], warnings: [] })).then(
192+
asyncMessages => {
193+
// Push errors and warnings into compilation result
194+
// to show them after page refresh triggered by user.
195+
// This is important for errors on first run in development.
196+
// TODO obvi won't work in async context.
197+
stats.compilation.errors.push(...asyncMessages.errors);
198+
stats.compilation.warnings.push(...asyncMessages.warnings);
199199

200-
messages.errors.push(...asyncMessages.errors);
201-
messages.warnings.push(...asyncMessages.warnings);
200+
// TODO obvi won't work in async context.
201+
messages.errors.push(...asyncMessages.errors);
202+
messages.warnings.push(...asyncMessages.warnings);
202203

203-
if (asyncMessages.errors.length > 0) {
204-
devSocketWrite('errors', asyncMessages.errors);
205-
} else if (asyncMessages.warnings.length > 0) {
206-
devSocketWrite('warnings', asyncMessages.warnings);
207-
} else {
208-
// We have to notify the hot dev client when we are waiting for types
209-
// when `module.hot` is being used.
210-
devSocketWrite('wait-for-types', false);
211-
devSocketWrite('ok');
212-
}
213-
}
204+
if (useTypeScript && isInteractive) {
205+
clearConsole();
206+
}
214207

215-
if (useTypeScript && isInteractive) {
216-
clearConsole();
217-
}
208+
logCompilationMessages(asyncMessages);
218209

219-
const isSuccessful = !messages.errors.length && !messages.warnings.length;
220-
if (isSuccessful) {
221-
console.log(chalk.green('Compiled successfully!'));
222-
}
223-
if (isSuccessful && (isInteractive || isFirstCompile)) {
224-
printInstructions(appName, urls, useYarn);
225-
}
226-
isFirstCompile = false;
227-
228-
// If errors exist, only show errors.
229-
if (messages.errors.length) {
230-
// Only keep the first error. Others are often indicative
231-
// of the same problem, but confuse the reader with noise.
232-
if (messages.errors.length > 1) {
233-
messages.errors.length = 1;
234-
}
235-
console.log(chalk.red('Failed to compile.\n'));
236-
console.log(messages.errors.join('\n\n'));
237-
return;
238-
}
210+
const isSuccessful =
211+
!messages.errors.length && !messages.warnings.length;
212+
if (isSuccessful) {
213+
console.log(chalk.green('Compiled successfully!'));
214+
}
215+
if (isSuccessful && (isInteractive || isFirstCompile)) {
216+
printInstructions(appName, urls, useYarn);
217+
}
239218

240-
// Show warnings if no errors were found.
241-
if (messages.warnings.length) {
242-
console.log(chalk.yellow('Compiled with warnings.\n'));
243-
console.log(messages.warnings.join('\n\n'));
219+
if (asyncMessages.errors.length > 0) {
220+
devSocketWrite('errors', asyncMessages.errors);
221+
} else if (asyncMessages.warnings.length > 0) {
222+
devSocketWrite('warnings', asyncMessages.warnings);
223+
} else {
224+
// We have to notify the hot dev client when we are waiting for types
225+
// when `module.hot` is being used.
226+
devSocketWrite('wait-for-types', false);
227+
devSocketWrite('ok');
228+
}
244229

245-
// Teach some ESLint tricks.
246-
console.log(
247-
'\nSearch for the ' +
248-
chalk.underline(chalk.yellow('keywords')) +
249-
' to learn more about each warning.'
250-
);
251-
console.log(
252-
'To ignore, add ' +
253-
chalk.cyan('// eslint-disable-next-line') +
254-
' to the line before.\n'
255-
);
256-
}
230+
isFirstCompile = false;
231+
}
232+
);
257233
});
258234

259235
// You can safely remove this after ejecting.
@@ -279,6 +255,38 @@ function createCompiler(
279255
return compiler;
280256
}
281257

258+
function logCompilationMessages(messages) {
259+
// If errors exist, only show errors.
260+
if (messages.errors.length) {
261+
// Only keep the first error. Others are often indicative
262+
// of the same problem, but confuse the reader with noise.
263+
if (messages.errors.length > 1) {
264+
messages.errors.length = 1;
265+
}
266+
console.log(chalk.red('Failed to compile.\n'));
267+
console.log(messages.errors.join('\n\n'));
268+
return;
269+
}
270+
271+
// Show warnings if no errors were found.
272+
if (messages.warnings.length) {
273+
console.log(chalk.yellow('Compiled with warnings.\n'));
274+
console.log(messages.warnings.join('\n\n'));
275+
276+
// Teach some ESLint tricks.
277+
console.log(
278+
'\nSearch for the ' +
279+
chalk.underline(chalk.yellow('keywords')) +
280+
' to learn more about each warning.'
281+
);
282+
console.log(
283+
'To ignore, add ' +
284+
chalk.cyan('// eslint-disable-next-line') +
285+
' to the line before.\n'
286+
);
287+
}
288+
}
289+
282290
function resolveLoopback(proxy) {
283291
const o = url.parse(proxy);
284292
o.host = undefined;

0 commit comments

Comments
 (0)