mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-10-03 22:37:03 +00:00
added watch api typings
See documentation: for details https://rollupjs.org/#rollup-watch Source code has more details on event data: https://github.com/rollup/rollup/blob/e11a2fdf7e6f619cc66d28cfc1edc2f54aab4cce/src/watch/index.js
This commit is contained in:
Vendored
+51
@@ -164,3 +164,54 @@ export interface TransformContext {
|
||||
|
||||
/** Returns a Promise that resolves with a bundle */
|
||||
export function rollup(options: Options): Promise<Bundle>
|
||||
|
||||
export interface WatchOptions extends ConfigFileOptions {
|
||||
watch?: {
|
||||
/**
|
||||
* If set to true, will use chokidar for file watching (requires installation).
|
||||
* If set to object, the settings are passed on to chokidar
|
||||
*/
|
||||
chokidar?: boolean | { [key: string]: any };
|
||||
/** Limit the file-watching to certain files, e.g. 'src/**' */
|
||||
include?: string;
|
||||
/** Prevent files from being watched, e.g. 'node_modules/**' */
|
||||
exclude?: string;
|
||||
}
|
||||
}
|
||||
|
||||
export interface StartEvent {
|
||||
code: 'START'
|
||||
}
|
||||
export interface EndEvent {
|
||||
code: 'END'
|
||||
}
|
||||
export interface ErrorEvent {
|
||||
code: 'ERROR'
|
||||
error: Error
|
||||
}
|
||||
export interface FatalEvent {
|
||||
code: 'FATAL'
|
||||
error: Error
|
||||
}
|
||||
export interface BundleStartEvent {
|
||||
code: 'BUNDLE_START'
|
||||
input: string
|
||||
output: string[]
|
||||
}
|
||||
export interface BundleEndEvent {
|
||||
code: 'BUNDLE_END'
|
||||
input: string
|
||||
output: string[]
|
||||
duration: number
|
||||
}
|
||||
export type WatchEvent = StartEvent | EndEvent | ErrorEvent | FatalEvent | BundleStartEvent | BundleEndEvent
|
||||
|
||||
export class Watcher {
|
||||
/** Listen to the events that are emitted by rollup during watching */
|
||||
on(type: 'event', callback: (e: WatchEvent) => void): void
|
||||
/** Stop watching for file changes */
|
||||
close(): void
|
||||
}
|
||||
|
||||
/** Starts rollup in watch mode. Returns a watcher instance for closing or listening to events */
|
||||
export function watch(options: WatchOptions): Watcher
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { rollup, Bundle, Plugin, ConfigFileOptions } from 'rollup'
|
||||
import { rollup, watch, Bundle, Plugin, ConfigFileOptions } from 'rollup'
|
||||
|
||||
declare const console: { log(...messages: any[]): void, warn(message: string): void }
|
||||
|
||||
@@ -69,6 +69,42 @@ async function main() {
|
||||
sourcemapFile: 'bundle.js.map',
|
||||
strict: true,
|
||||
})
|
||||
|
||||
const watcher = watch({
|
||||
input: 'main.js',
|
||||
output: {
|
||||
file: 'bundle.js',
|
||||
format: 'es'
|
||||
},
|
||||
watch: {
|
||||
chokidar: true
|
||||
}
|
||||
})
|
||||
|
||||
watcher.on('event', e => {
|
||||
switch (e.code) {
|
||||
case 'START':
|
||||
console.log(`We're rolling!`)
|
||||
return
|
||||
case 'END':
|
||||
console.log(`We're all rolled up!`)
|
||||
return
|
||||
case 'ERROR':
|
||||
case 'FATAL':
|
||||
console.log(e.error.message)
|
||||
return
|
||||
case 'BUNDLE_START':
|
||||
console.log(`Bundling: ${e.input}`)
|
||||
return
|
||||
case 'BUNDLE_END':
|
||||
console.log(`Bundling: ${e.input}`)
|
||||
return
|
||||
}
|
||||
|
||||
assertNever(e)
|
||||
})
|
||||
|
||||
watcher.close()
|
||||
}
|
||||
|
||||
main()
|
||||
@@ -94,3 +130,7 @@ export const multiConfig: ConfigFileOptions = {
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
function assertNever(nope: never) {
|
||||
throw new Error('Oh no!')
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user