why-is-node-running
Advanced tools
Comparing version 2.3.0 to 3.0.0
#!/usr/bin/env node | ||
var spawn = require('child_process').spawn | ||
var path = require('path') | ||
import { spawn } from 'node:child_process' | ||
import path from 'node:path' | ||
@@ -12,4 +12,4 @@ var prog = path.resolve(process.argv[2]) | ||
var nodeArgs = [ | ||
'-r', | ||
path.join(__dirname, 'include.js') | ||
'--import', | ||
path.join(import.meta.dirname, 'include.js') | ||
] | ||
@@ -16,0 +16,0 @@ var nodeOpts = { stdio: 'inherit' } |
@@ -1,3 +0,3 @@ | ||
var log = require('./') | ||
var net = require('net') | ||
import why from './index.js' | ||
import net from 'node:net' | ||
@@ -14,3 +14,3 @@ function createServer () { | ||
setTimeout(function () { | ||
log() | ||
why() | ||
}, 100) |
@@ -1,3 +0,4 @@ | ||
var why = require('./') | ||
import why from './index.js' | ||
import siginfo from 'siginfo' | ||
require('siginfo')(why, true) | ||
siginfo(why, true) |
23
index.js
@@ -1,5 +0,7 @@ | ||
var asyncHooks = require('async_hooks') | ||
var stackback = require('stackback') | ||
var path = require('path') | ||
var fs = require('fs') | ||
import asyncHooks from 'node:async_hooks' | ||
import fs from 'node:fs' | ||
import path from 'node:path' | ||
import { fileURLToPath } from 'node:url' | ||
import stackback from 'stackback' | ||
var sep = path.sep | ||
@@ -22,5 +24,4 @@ | ||
hook.enable() | ||
module.exports = whyIsNodeRunning | ||
function whyIsNodeRunning (logger) { | ||
export default function whyIsNodeRunning (logger) { | ||
if (!logger) logger = console | ||
@@ -54,9 +55,9 @@ | ||
stacks.forEach(function (s) { | ||
var pad = (s.getFileName() + ':' + s.getLineNumber()).replace(/./g, ' ') | ||
var pad = (normalizeFileName(s.getFileName()) + ':' + s.getLineNumber()).replace(/./g, ' ') | ||
if (pad.length > padding.length) padding = pad | ||
}) | ||
stacks.forEach(function (s) { | ||
var prefix = s.getFileName() + ':' + s.getLineNumber() | ||
var prefix = normalizeFileName(s.getFileName()) + ':' + s.getLineNumber() | ||
try { | ||
var src = fs.readFileSync(s.getFileName(), 'utf-8').split(/\n|\r\n/) | ||
var src = fs.readFileSync(normalizeFileName(s.getFileName()), 'utf-8').split(/\n|\r\n/) | ||
logger.error(prefix + padding.slice(prefix.length) + ' - ' + src[s.getLineNumber() - 1].trim()) | ||
@@ -70,1 +71,5 @@ } catch (e) { | ||
} | ||
function normalizeFileName(fileName) { | ||
return fileName.startsWith('file://') ? fileURLToPath(fileName) : fileName | ||
} |
{ | ||
"name": "why-is-node-running", | ||
"version": "2.3.0", | ||
"type": "module", | ||
"version": "3.0.0", | ||
"description": "Node is running but you don't know why? why-is-node-running is here to help you.", | ||
"main": "index.js", | ||
"exports": { | ||
".": "./index.js", | ||
"./includes": "./include.js" | ||
}, | ||
"dependencies": { | ||
@@ -14,3 +18,3 @@ "siginfo": "^2.0.0", | ||
"engines": { | ||
"node": ">=8" | ||
"node": ">=20.11" | ||
}, | ||
@@ -17,0 +21,0 @@ "repository": { |
@@ -22,4 +22,4 @@ # why-is-node-running | ||
```js | ||
const log = require('why-is-node-running') // should be your first require | ||
const net = require('net') | ||
import why from 'why-is-node-running' // should be your first import | ||
import net from 'node:net' | ||
@@ -36,3 +36,3 @@ function createServer () { | ||
setTimeout(function () { | ||
log() // logs out active handles that are keeping node running | ||
why() // logs out active handles that are keeping node running | ||
}, 100) | ||
@@ -94,8 +94,8 @@ ``` | ||
## Require CLI Option | ||
## Import CLI Option | ||
You can also use the node `-r` option to include `why-is-node-running`: | ||
You can also use Node's [`--import`](https://nodejs.org/api/cli.html#--importmodule) option to preload `why-is-node-running`: | ||
```bash | ||
node -r why-is-node-running/include /path/to/some/file.js | ||
node --import why-is-node-running/include /path/to/some/file.js | ||
``` | ||
@@ -102,0 +102,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
Shell access
Supply chain riskThis module accesses the system shell. Accessing the system shell increases the risk of executing arbitrary code.
Found 1 instance in 1 package
Debug access
Supply chain riskUses debug, reflection and dynamic code execution features.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
7678
90
0
0
Yes