Skip to content

Commit 8ab9102

Browse files
acburdinedavewasmer
authored andcommitted
fix(project): queue spinner promises on watch (#20)
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 b8b2d01 commit 8ab9102

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 spinnerStart: 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+
spinnerStart = spinner.start(`Building ${ this.pkg.name }`);
247+
await spinnerStart;
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 spinnerStart;
249253
await spinner.succeed(`${ this.pkg.name } build complete (${ timer.stop() }s)`);
254+
spinnerStart = null;
250255
options.onBuild(this);
251256
});
252257
watcher.on('error', async (error: any) => {

0 commit comments

Comments
 (0)