@tapjs/processinfo
A Node.js loader to track processes and which JavaScript files they load.
Last updated a year ago by isaacs .
ISC · Repository · Bugs · Original npm · Tarball · package.json
$ gnpm install @tapjs/processinfo 
SYNC missed versions from official npm registry.

@tapjs/processinfo

A Node.js loader to track processes and which JavaScript files they load.

After the process has run, all wrapped process info is dumped to .tap/processinfo.

The exported object can also be used to spawn processes, clear the processinfo data, or load the processinfo data.

USAGE

Run the top level process with a --loader or --require argument to track all Node.js child processes.

# wrap both CommonJS and ESM, node versions less than 20.6
node --loader=@tapjs/processinfo/loader file.js

# for node versions 20.6 and higher:
node --import=@tapjs/processinfo/import

To spawn a wrapped process from JavaScript, you can run:

import {
  spawn,
  exec,
  execFile,
  execSync,
  execFileSync,
  fork,
} from '@tapjs/processinfo'
// any of these will work
const childProcess = spawn(cmd, args, options)
const childProcess = exec(cmd, options, callback)
const childProcess = execFile(cmd, options, callback)
const childProcess = spawnSync(cmd, args, options)
const childProcess = execSync(cmd, options)
const childProcess = execFileSync(cmd, options)
const childProcess = fork(cmd, options)

The cmd and args parameters are identical to the methods from the Node.js child_process module. The options parameter is also identical, but may also include an externalID field, which if set to a string, will be used as the processinfo externalID.

If you just use the normal spawn/exec methods from the Node.js child_process module, then the relevant environment variables will still be tracked, unless explicitly set to '' or some other value.

Important

In order to properly track lineLengths (required for coverage reporting on source mapped files), @tapjs/processinfo must be the last loader specified on the command line, so that it can get access to the transpiled source that Node.js actually executes.

Interacting with Process Info

To load the process info data, use the exported ProcessInfo class.

import { ProcessInfo } from '@tapjs/processinfo'

// returns
// {
//   roots: Set([ProcessInfo.Node, ...]) for each root process group
//   files: Map({ filename => Set([ProcessInfo.Node, ...]) }),
//   externalIDs: Map({ externalID => ProcessInfo.Node }),
//   uuids: Map({ uuid => ProcessInfo.Node }),
// }
// A ProcessInfo.Node looks like:
// {
//   date: iso date string,
//   argv,
//   execArgv,
//   cwd,
//   pid,
//   ppid,
//   uuid,
//   externalID,
//   parent: <ProcessInfo.Node or null for root node>,
//   root: <ProcessInfo.Node>,
//   children: [ProcessInfo.Node, ...],
//   descendants: [ProcessInfo.Node, ...],
//   files: [ filename, ... ],
//   code: unix exit code,
//   signal: terminating signal or null,
//   runtime: high resolution run time in ms,
// }
const processInfoDB = await ProcessInfo.load()
// say we wanted to find all the files loaded by the process 'foo'
const proc = processInfoDB.externalIDs.get('foo')
console.error(`Files loaded by process named 'foo':`, proc.files)

// now let's find all any other named processes that loaded them
for (const f of proc.files) {
  for (const otherProc of processInfoDB.files.get(f)) {
    // walk up the tree looking for a named process
    for (let parent = otherProc; parent; parent = parent.parent) {
      if (parent.externalID && parent !== proc) {
        console.error(`Also loaded by process ${parent.externalID}`)
      }
    }
  }
}

Note: unless there has been a previous wrapped process run, nothing will be present in the data. That is, data.root will be null, and all the maps will be empty.

Controlling Coverage

To disable coverage entirely, set _TAPJS_PROCESSINFO_COVERAGE_=0 in the environment.

To exclude certain file paths from coverage with a pattern, set the _TAPJS_PROCESSINFO_COV_EXCLUDE_ to a regular expression string. Note that processinfo will never provide coverage for a file that's excluded from process file tracking.

To exclude specific individual file paths from coverage, set the _TAPJS_PROCESSINFO_COV_EXCLUDE_FILES_ to a \n delimited set of file paths.

To include only a specific set of files for coverage (as with node-tap's coverage-map option), set _TAPJS_PROCESSINFO_COV_FILES_ to a \n delimited list of the files to include. These will have their coverage reported even if they would be excluded by the _TAPJS_PROCESSINFO_COV_EXCLUDE_ regexp or _TAPJS_PROCESSINFO_COV_EXCLUDE_FILES_ list.

Note that coverage instrumentation is by necessity enabled for all files, but it's only written to disk if the file (or any of its sources, if it has a sourcemap) is included.

Current Tags

  • 3.1.4                                ...           latest (a year ago)

49 Versions

  • 3.1.4                                ...           a year ago
  • 3.1.3                                ...           a year ago
  • 3.1.2                                ...           a year ago
  • 3.1.1                                ...           a year ago
  • 3.1.0                                ...           a year ago
  • 3.0.2                                ...           a year ago
  • 3.0.1                                ...           a year ago
  • 3.0.0                                ...           a year ago
  • 2.5.6                                ...           a year ago
  • 2.5.5                                ...           a year ago
  • 2.5.4                                ...           a year ago
  • 2.5.3                                ...           a year ago
  • 2.5.2                                ...           a year ago
  • 2.5.1                                ...           a year ago
  • 2.5.0                                ...           a year ago
  • 2.4.1                                ...           a year ago
  • 2.4.0                                ...           a year ago
  • 2.3.0                                ...           a year ago
  • 2.2.8                                ...           a year ago
  • 2.2.7                                ...           a year ago
  • 2.2.6                                ...           a year ago
  • 2.2.5                                ...           a year ago
  • 2.2.4                                ...           a year ago
  • 2.2.3                                ...           a year ago
  • 2.2.2                                ...           a year ago
  • 2.2.1                                ...           a year ago
  • 2.2.0                                ...           a year ago
  • 2.1.5                                ...           2 years ago
  • 2.1.4                                ...           2 years ago
  • 2.1.3                                ...           2 years ago
  • 2.1.2                                ...           2 years ago
  • 2.1.1                                ...           2 years ago
  • 2.1.0                                ...           2 years ago
  • 2.0.2                                ...           2 years ago
  • 2.0.1                                ...           2 years ago
  • 2.0.0                                ...           2 years ago
  • 1.0.12                                ...           2 years ago
  • 1.0.11                                ...           2 years ago
  • 1.0.10                                ...           2 years ago
  • 1.0.9                                ...           2 years ago
  • 1.0.8                                ...           2 years ago
  • 1.0.7                                ...           2 years ago
  • 1.0.6                                ...           2 years ago
  • 1.0.5                                ...           2 years ago
  • 1.0.4                                ...           2 years ago
  • 1.0.3                                ...           2 years ago
  • 1.0.2                                ...           2 years ago
  • 1.0.1                                ...           2 years ago
  • 1.0.0                                ...           2 years ago
Maintainers (2)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (4)
Dev Dependencies (14)
Dependents (2)

Copyright 2013 - present © cnpmjs.org | Home |