aboutsummaryrefslogtreecommitdiffstats
path: root/vanilla/node_modules/why-is-node-running
diff options
context:
space:
mode:
authorAdam Mathes <adam@adammathes.com>2026-02-13 21:34:48 -0800
committerAdam Mathes <adam@adammathes.com>2026-02-13 21:34:48 -0800
commit76cb9c2a39d477a64824a985ade40507e3bbade1 (patch)
tree41e997aa9c6f538d3a136af61dae9424db2005a9 /vanilla/node_modules/why-is-node-running
parent819a39a21ac992b1393244a4c283bbb125208c69 (diff)
downloadneko-76cb9c2a39d477a64824a985ade40507e3bbade1.tar.gz
neko-76cb9c2a39d477a64824a985ade40507e3bbade1.tar.bz2
neko-76cb9c2a39d477a64824a985ade40507e3bbade1.zip
feat(vanilla): add testing infrastructure and tests (NK-wjnczv)
Diffstat (limited to 'vanilla/node_modules/why-is-node-running')
-rw-r--r--vanilla/node_modules/why-is-node-running/.github/FUNDING.yml1
-rw-r--r--vanilla/node_modules/why-is-node-running/LICENSE21
-rw-r--r--vanilla/node_modules/why-is-node-running/README.md104
-rwxr-xr-xvanilla/node_modules/why-is-node-running/cli.js18
-rw-r--r--vanilla/node_modules/why-is-node-running/example.js15
-rw-r--r--vanilla/node_modules/why-is-node-running/include.js3
-rw-r--r--vanilla/node_modules/why-is-node-running/index.js67
-rw-r--r--vanilla/node_modules/why-is-node-running/package.json39
8 files changed, 268 insertions, 0 deletions
diff --git a/vanilla/node_modules/why-is-node-running/.github/FUNDING.yml b/vanilla/node_modules/why-is-node-running/.github/FUNDING.yml
new file mode 100644
index 0000000..90f7f20
--- /dev/null
+++ b/vanilla/node_modules/why-is-node-running/.github/FUNDING.yml
@@ -0,0 +1 @@
+github: mafintosh
diff --git a/vanilla/node_modules/why-is-node-running/LICENSE b/vanilla/node_modules/why-is-node-running/LICENSE
new file mode 100644
index 0000000..bae9da7
--- /dev/null
+++ b/vanilla/node_modules/why-is-node-running/LICENSE
@@ -0,0 +1,21 @@
+The MIT License (MIT)
+
+Copyright (c) 2016 Mathias Buus
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
diff --git a/vanilla/node_modules/why-is-node-running/README.md b/vanilla/node_modules/why-is-node-running/README.md
new file mode 100644
index 0000000..d5e4c54
--- /dev/null
+++ b/vanilla/node_modules/why-is-node-running/README.md
@@ -0,0 +1,104 @@
+# why-is-node-running
+
+Node is running but you don't know why? `why-is-node-running` is here to help you.
+
+## Installation
+
+Node 8 and above:
+
+```bash
+npm i why-is-node-running -g
+```
+
+Earlier Node versions (no longer supported):
+
+```bash
+npm i why-is-node-running@v1.x -g
+```
+
+## Usage
+
+```js
+const log = require('why-is-node-running') // should be your first require
+const net = require('net')
+
+function createServer () {
+ const server = net.createServer()
+ setInterval(function () {}, 1000)
+ server.listen(0)
+}
+
+createServer()
+createServer()
+
+setTimeout(function () {
+ log() // logs out active handles that are keeping node running
+}, 100)
+```
+
+Save the file as `example.js`, then execute:
+
+```bash
+node ./example.js
+```
+
+Here's the output:
+
+```
+There are 5 handle(s) keeping the process running
+
+# Timeout
+/home/maf/dev/node_modules/why-is-node-running/example.js:6 - setInterval(function () {}, 1000)
+/home/maf/dev/node_modules/why-is-node-running/example.js:10 - createServer()
+
+# TCPSERVERWRAP
+/home/maf/dev/node_modules/why-is-node-running/example.js:7 - server.listen(0)
+/home/maf/dev/node_modules/why-is-node-running/example.js:10 - createServer()
+
+# Timeout
+/home/maf/dev/node_modules/why-is-node-running/example.js:6 - setInterval(function () {}, 1000)
+/home/maf/dev/node_modules/why-is-node-running/example.js:11 - createServer()
+
+# TCPSERVERWRAP
+/home/maf/dev/node_modules/why-is-node-running/example.js:7 - server.listen(0)
+/home/maf/dev/node_modules/why-is-node-running/example.js:11 - createServer()
+
+# Timeout
+/home/maf/dev/node_modules/why-is-node-running/example.js:13 - setTimeout(function () {
+```
+
+**Important Note!**
+`unref`ed timers do not prevent the Node process from exiting. If you are running with Node v11.0.0 and above, `unref`ed timers will not be listed in the above list. Unfortunately, this is not supported in node versions below v11.0.0.
+
+## CLI
+
+You can also run `why-is-node-running` as a standalone if you don't want to include it inside your code. Sending `SIGUSR1`/`SIGINFO` signal to the process will produce the log. (`Ctrl + T` on macOS and BSD systems)
+
+```bash
+why-is-node-running /path/to/some/file.js
+```
+
+```
+probing module /path/to/some/file.js
+kill -SIGUSR1 31115 for logging
+```
+
+To trigger the log:
+
+```
+kill -SIGUSR1 31115
+```
+
+## Require CLI Option
+
+You can also use the node `-r` option to include `why-is-node-running`:
+
+```bash
+node -r why-is-node-running/include /path/to/some/file.js
+```
+
+The steps are otherwise the same as the above CLI section
+
+## License
+
+MIT
diff --git a/vanilla/node_modules/why-is-node-running/cli.js b/vanilla/node_modules/why-is-node-running/cli.js
new file mode 100755
index 0000000..15cf2b9
--- /dev/null
+++ b/vanilla/node_modules/why-is-node-running/cli.js
@@ -0,0 +1,18 @@
+#!/usr/bin/env node
+
+var spawn = require('child_process').spawn
+var path = require('path')
+
+var prog = path.resolve(process.argv[2])
+var progArgs = process.argv.slice(3)
+
+console.log('probing program', prog)
+
+var nodeArgs = [
+ '-r',
+ path.join(__dirname, 'include.js')
+]
+var nodeOpts = { stdio: 'inherit' }
+var child = spawn('node', nodeArgs.concat(prog).concat(progArgs), nodeOpts)
+
+console.log('kill -SIGUSR1', child.pid, 'for logging')
diff --git a/vanilla/node_modules/why-is-node-running/example.js b/vanilla/node_modules/why-is-node-running/example.js
new file mode 100644
index 0000000..4584d4b
--- /dev/null
+++ b/vanilla/node_modules/why-is-node-running/example.js
@@ -0,0 +1,15 @@
+var log = require('./')
+var net = require('net')
+
+function createServer () {
+ var server = net.createServer()
+ setInterval(function () {}, 1000)
+ server.listen(0)
+}
+
+createServer()
+createServer()
+
+setTimeout(function () {
+ log()
+}, 100)
diff --git a/vanilla/node_modules/why-is-node-running/include.js b/vanilla/node_modules/why-is-node-running/include.js
new file mode 100644
index 0000000..c7ffe28
--- /dev/null
+++ b/vanilla/node_modules/why-is-node-running/include.js
@@ -0,0 +1,3 @@
+var why = require('./')
+
+require('siginfo')(why, true)
diff --git a/vanilla/node_modules/why-is-node-running/index.js b/vanilla/node_modules/why-is-node-running/index.js
new file mode 100644
index 0000000..70842c5
--- /dev/null
+++ b/vanilla/node_modules/why-is-node-running/index.js
@@ -0,0 +1,67 @@
+var asyncHooks = require('async_hooks')
+var stackback = require('stackback')
+var path = require('path')
+var fs = require('fs')
+var sep = path.sep
+
+var active = new Map()
+var hook = asyncHooks.createHook({
+ init (asyncId, type, triggerAsyncId, resource) {
+ if (type === 'TIMERWRAP' || type === 'PROMISE') return
+ if (type === 'PerformanceObserver' || type === 'RANDOMBYTESREQUEST') return
+ var err = new Error('whatevs')
+ var stacks = stackback(err)
+ active.set(asyncId, {type, stacks, resource})
+ },
+ destroy (asyncId) {
+ active.delete(asyncId)
+ }
+})
+
+hook.enable()
+module.exports = whyIsNodeRunning
+
+function whyIsNodeRunning (logger) {
+ if (!logger) logger = console
+
+ hook.disable()
+ var activeResources = [...active.values()].filter(function(r) {
+ if (
+ typeof r.resource.hasRef === 'function'
+ && !r.resource.hasRef()
+ ) return false
+ return true
+ })
+
+ logger.error('There are %d handle(s) keeping the process running', activeResources.length)
+ for (const o of activeResources) printStacks(o)
+
+ function printStacks (o) {
+ var stacks = o.stacks.slice(1).filter(function (s) {
+ var filename = s.getFileName()
+ return filename && filename.indexOf(sep) > -1 && filename.indexOf('internal' + sep) !== 0 && filename.indexOf('node:internal' + sep) !== 0
+ })
+
+ logger.error('')
+ logger.error('# %s', o.type)
+
+ if (!stacks[0]) {
+ logger.error('(unknown stack trace)')
+ } else {
+ var padding = ''
+ stacks.forEach(function (s) {
+ var pad = (s.getFileName() + ':' + s.getLineNumber()).replace(/./g, ' ')
+ if (pad.length > padding.length) padding = pad
+ })
+ stacks.forEach(function (s) {
+ var prefix = s.getFileName() + ':' + s.getLineNumber()
+ try {
+ var src = fs.readFileSync(s.getFileName(), 'utf-8').split(/\n|\r\n/)
+ logger.error(prefix + padding.slice(prefix.length) + ' - ' + src[s.getLineNumber() - 1].trim())
+ } catch (e) {
+ logger.error(prefix + padding.slice(prefix.length))
+ }
+ })
+ }
+ }
+}
diff --git a/vanilla/node_modules/why-is-node-running/package.json b/vanilla/node_modules/why-is-node-running/package.json
new file mode 100644
index 0000000..9bf6a6d
--- /dev/null
+++ b/vanilla/node_modules/why-is-node-running/package.json
@@ -0,0 +1,39 @@
+{
+ "name": "why-is-node-running",
+ "version": "2.3.0",
+ "description": "Node is running but you don't know why? why-is-node-running is here to help you.",
+ "main": "index.js",
+ "dependencies": {
+ "siginfo": "^2.0.0",
+ "stackback": "0.0.2"
+ },
+ "bin": {
+ "why-is-node-running": "cli.js"
+ },
+ "engines": {
+ "node": ">=8"
+ },
+ "repository": {
+ "type": "git",
+ "url": "https://github.com/mafintosh/why-is-node-running.git"
+ },
+ "keywords": [
+ "debug",
+ "devops",
+ "test",
+ "events",
+ "handles"
+ ],
+ "author": "Mathias Buus (@mafintosh)",
+ "contributors": [
+ {
+ "name": "Jon Peck",
+ "email": "jpeck@fluxsauce.com"
+ }
+ ],
+ "license": "MIT",
+ "bugs": {
+ "url": "https://github.com/mafintosh/why-is-node-running/issues"
+ },
+ "homepage": "https://github.com/mafintosh/why-is-node-running"
+}