module_graph.ts

view source

Declarations
#

5 declarations

FileChange
#

FileChangeCallback
#

FileChangeType
#

ModuleGraph
#

module_graph.ts view source

ModuleGraph import type {ModuleGraph} from '@fuzdev/gro/module_graph.js';

The project's module graph: which files exist under the watched directory and which import which. Tasks and plugins get one on their context. Queries load the graph on first use, and close tears it down for good. A load that fails stays failed: later queries reject with the same error.

modules

Gets the ids of the project modules that exist on disk.

type (filter?: ((id: PathId) => boolean) | undefined): Promise<PathId[]>

filter?

narrows the results

type (id: PathId) => boolean
optional
returns Promise<PathId[]>

dependents

Gets every module that imports id, directly or transitively. The filter narrows the results, not the traversal. A package's file is never read, so its imports aren't edges: one a bare specifier reaches, even when linked, and one whose path from the watched directory passes through a node_modules directory, both from the directory as named and from its real path.

type (id: PathId, filter?: ((id: PathId) => boolean) | undefined): Promise<Set<PathId>>

id

the module whose dependents to find

type PathId

filter?

narrows the results

type (id: PathId) => boolean
optional
returns Promise<Set<PathId>>

the dependents, including of an imported path that doesn't exist yet; empty when nothing imports id

watch

Subscribes to changes of project modules, first calling on_change with an add for each module already in the graph. Changes are content-based, so saving a file unchanged emits nothing.

type (on_change: FileChangeCallback): Promise<() => Promise<void>>

on_change

called for each change

returns Promise<() => Promise<void>>

a function that unsubscribes

close

Stops watching and drops the graph. A graph that never loaded closes without loading. Closing is permanent: later queries and watches reject, as do any pending when it's called. A watch pending when it's called may already have delivered its initial adds before rejecting. Every call returns the same teardown, so an awaited close means fully closed.

type (): Promise<void>

returns Promise<void>

WatchOptions
#

module_graph.ts view source

WatchOptions import type {WatchOptions} from '@fuzdev/gro/module_graph.js';

What a ModuleGraph watches, from GroConfig.watch.

dir

The directory to watch, which holds the project modules. Files outside it enter the graph only when a project module imports them.

type PathId

filter

Excludes the paths it rejects from the change events and from the project modules. It's called with absolute paths, unlike GroConfig.search_filters, which get paths relative to the project root. It filters events, not the directory walk: a rejected directory is still watched, so each path below it is filtered on its own.

type (PathFilter) | null

Imported by
#