Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Do not abort watch mode on errors in watchChange (#4427)
* Recovers from errors in the watchChange hook * Also emit END event * Fix direct npm install * Await watchChange and closeWatcher hooks * Extract emitter and improve coverage * Update docs
- Loading branch information
1 parent
6881753
commit cf75d71
Showing
12 changed files
with
249 additions
and
127 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
const { execSync } = require('child_process'); | ||
const { writeFileSync } = require('fs'); | ||
const { join } = require('path'); | ||
|
||
let revision; | ||
try { | ||
revision = execSync('git rev-parse HEAD').toString().trim(); | ||
} catch (e) { | ||
console.warn('Could not determine git commit when building Rollup.'); | ||
revision = '(could not be determined)'; | ||
} | ||
writeFileSync(join(__dirname, '../.commithash'), revision); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import { EventEmitter } from 'events'; | ||
|
||
type PromiseReturn<T extends (...args: any) => any> = ( | ||
...args: Parameters<T> | ||
) => Promise<ReturnType<T>>; | ||
|
||
export class WatchEmitter< | ||
T extends { [event: string]: (...args: any) => any } | ||
> extends EventEmitter { | ||
private awaitedHandlers: { | ||
[K in keyof T]?: PromiseReturn<T[K]>[]; | ||
} = Object.create(null); | ||
|
||
constructor() { | ||
super(); | ||
// Allows more than 10 bundles to be watched without | ||
// showing the `MaxListenersExceededWarning` to the user. | ||
this.setMaxListeners(Infinity); | ||
} | ||
|
||
// Will be overwritten by Rollup | ||
async close(): Promise<void> {} | ||
|
||
emitAndAwait<K extends keyof T>( | ||
event: K, | ||
...args: Parameters<T[K]> | ||
): Promise<ReturnType<T[K]>[]> { | ||
this.emit(event as string, ...(args as any[])); | ||
return Promise.all(this.getHandlers(event).map(handler => handler(...args))); | ||
} | ||
|
||
onCurrentAwaited<K extends keyof T>( | ||
event: K, | ||
listener: (...args: Parameters<T[K]>) => Promise<ReturnType<T[K]>> | ||
): this { | ||
this.getHandlers(event).push(listener); | ||
return this; | ||
} | ||
|
||
removeAwaited(): this { | ||
this.awaitedHandlers = {}; | ||
return this; | ||
} | ||
|
||
private getHandlers<K extends keyof T>(event: K): PromiseReturn<T[K]>[] { | ||
return this.awaitedHandlers[event] || (this.awaitedHandlers[event] = []); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.