CodeVetter · Repo Unpack · Behavior traces
istanbuljs/nyc
The source supports ordered walkthroughs of command startup, child instrumentation, persistence and reporting, and offline instrumentation. These traces describe execution order and conditional branches rather than observed runs. Threshold checks and reporting differ in order between normal execution and the standalone report command. The --all and merge branches reuse core collection machinery while changing their input and output boundaries.
- Startup: cliWrapper(main) → configUtil()/processConfig() → guessCWD() → setupOptions() → argument separation → loadNycConfig() → final yargs parse; recognized subcommands return from main, while missing commands set exitCode 1 and show help.
- Wrapped execution: main() selects Istanbul or noop → new NYC(argv) → reset() or createTempDirectory() → establishes preload modules or spawn-wrap → optionally addAllFiles() → foregroundChild(childArgs).
- Child instrumentation: lib/wrap.js constructs NYC → wrap() publishes NYC_PROCESS_ID → installs require/VM hooks → registers the exit handler → loads additional spawn-wrap modules; hooked source then passes _handleJs() → _maybeInstrumentSource() → _transform() → instrumentSync().
- Persistence: the alwaysLast signal-exit callback calls writeCoverageFile() → coverageFinder() → exclusion cleanup → optional contentHash attachment → synchronous UUID JSON write → ProcessInfo.saveSync().
- Parent completion: foregroundChild callback combines exit status → removes watchdog artifacts → writeProcessIndex() → maybePurgeSourceMapCache() → optional checkCoverage() → report() unless silent; caught completion errors force a nonzero result.
- Offline instrumentation: command handler validates input/output and deletion conditions → selects instrumenter → adjusts in-place settings → preloads modules → instrumentAllFiles(); directory mode globs eligible files, optionally copies the remaining tree, then transforms and writes files with original modes.
- --all: addAllFiles() loads additional modules → enables fakeRequire → globs eligible sources → directly instruments ESM or reads other files through Module._extensions → stores lastFileCoverage with all:true → disables fakeRequire → writes coverage.
- Stored-result commands: report handler calls report() before optional checkCoverage(); merge handler validates the input directory, creates the output parent, loads/merges/remaps coverage through getCoverageMapFromAllCoverageFiles(), then writes JSON.