Skip to content

Commit 037b7c9

Browse files
committed
fix(project): queue spinner promises on watch
fixes #19 - on fast rebuilds, the change event would be fired quickly enough that it would cause the spinner to succeed before it could be started completely. This ensures the succeed call happens after the start call. It also fixes the timer
1 parent ec736dd commit 037b7c9

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/project.ts

+6-1
Original file line numberDiff line numberDiff line change
@@ -237,16 +237,21 @@ export default class Project {
237237
addonProject.watch({ onBuild: options.onBuild, outputDir: addonDist });
238238
});
239239

240+
let startPromise: Promise<void>;
241+
240242
// Handle watcher events
241243
watcher.on('buildstart', async () => {
242244
debug('changes detected, rebuilding');
243-
await spinner.start(`Building ${ this.pkg.name }`);
244245
timer = startTimer();
246+
startPromise = spinner.start(`Building ${ this.pkg.name }`);
247+
await startPromise;
245248
});
246249
watcher.on('change', async (results: { directory: string, graph: any }) => {
247250
debug('rebuild finished, wrapping up');
248251
this.finishBuild(results, options.outputDir);
252+
await startPromise;
249253
await spinner.succeed(`${ this.pkg.name } build complete (${ timer.stop() }s)`);
254+
startPromise = null;
250255
options.onBuild(this);
251256
});
252257
watcher.on('error', async (error: any) => {

0 commit comments

Comments
 (0)