Options
All
  • Public
  • Public/Protected
  • All
Menu

watch-load

Index

Type aliases

LoadedModuleFilter

LoadedModuleFilter: { coreModules: boolean; nodeModules: boolean; userModules: boolean }

Specifies for which modules a match event should be emitted by the respective {@link ModuleWatcher}. One or more of the below properties can be true, but it is invalid if all are false

property

coreModules: if true matches are emitted for Node.js core modules

property

nodeModules: if true matches are emitted for modules loaded from the node_modules folder

property

userModules: if true matches are emitted for modules that are neither core nor node_modules, but found inside the user's project folder

Type declaration

  • coreModules: boolean
  • nodeModules: boolean
  • userModules: boolean

LoadedModuleInfo

LoadedModuleInfo: { isCoreModule: boolean; isNodeModule: boolean; moduleUri: string; parentUri: string }

The information about a module that was loaded and matched a {@link ModuleWatcher} filter.

property

moduleUri: the string under which this module was required or imported

property

parentUri: path to the module that requested to load the module

property

isCoreModule: if true the loaded module is one of the Node.js core modules

property

isNodeModule: if true the loaded module is loaded from the node_modules folder

Type declaration

  • isCoreModule: boolean
  • isNodeModule: boolean
  • moduleUri: string
  • parentUri: string

ModuleWatcherConfig

ModuleWatcherConfig: { restore: boolean }

The globally used {@link ModuleWatcher} config.

property

restore: if true the Module._load function will be restored when the watcher count goes to zero

Type declaration

  • restore: boolean

Functions

_reset

  • _reset(): void
  • Resets global state of {@link ModuleWatcher} as well as [Module._load]. Only call this when testing.

    Returns void

addWatcher

  • Adds a module load watcher for the desired configuration. By default only userModules are watched. The watcher will emit('match', loadedModuleInfo) for each loaded module that matches the filter.

    Parameters

    • partialFilter: Partial<LoadedModuleFilter> = {}

      the filter to use when matching loaded modules

    Returns ModuleWatcher

configure

removeWatcher

  • removeWatcher(moduleWatcher: ModuleWatcher): boolean
  • Removes a watcher that has been added before via addWatcher. Once removed it will no longer receive any module load 'match' events.

    Parameters

    • moduleWatcher: ModuleWatcher

      the watcher to remove

    Returns boolean

watcherStats

  • watcherStats(): { watchers: number }
  • Provides stats about added {@link ModuleWatcher}s.

    Returns { watchers: number }

    • watchers: number

Generated using TypeDoc