diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index ef0f802..72d2651 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -18,9 +18,6 @@ jobs: node-version: 20 registry-url: https://registry.npmjs.org - - name: Install dependencies - run: npm ci - - name: Publish to NPM run: npm publish --provenance --access public env: diff --git a/.gitignore b/.gitignore index d1bed12..504afef 100644 --- a/.gitignore +++ b/.gitignore @@ -1,61 +1,2 @@ -# Logs -logs -*.log -npm-debug.log* -yarn-debug.log* -yarn-error.log* - -# Runtime data -pids -*.pid -*.seed -*.pid.lock - -# Directory for instrumented libs generated by jscoverage/JSCover -lib-cov - -# Coverage directory used by tools like istanbul -coverage - -# nyc test coverage -.nyc_output - -# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) -.grunt - -# Bower dependency directory (https://bower.io/) -bower_components - -# node-waf configuration -.lock-wscript - -# Compiled binary addons (https://nodejs.org/api/addons.html) -build/Release - -# Dependency directories node_modules/ -jspm_packages/ - -# Typescript v1 declaration files -typings/ - -# Optional npm cache directory -.npm - -# Optional eslint cache -.eslintcache - -# Optional REPL history -.node_repl_history - -# Output of 'npm pack' -*.tgz - -# Yarn Integrity file -.yarn-integrity - -# dotenv environment variables file -.env - -# next.js build output -.next +package-lock.json diff --git a/index.js b/index.js index d73eaee..1b1fb8d 100644 --- a/index.js +++ b/index.js @@ -2,7 +2,6 @@ import { createHook } from 'node:async_hooks' import { readFileSync } from 'node:fs' import { relative } from 'node:path' import { fileURLToPath } from 'node:url' -import stackback from 'stackback' const IGNORED_TYPES = [ 'TIMERWRAP', @@ -18,9 +17,13 @@ const hook = createHook({ return } - const stacks = stackback(new Error()).slice(1) + const stacks = captureStackTraces().slice(1) - asyncResources.set(asyncId, { type, stacks, resource }) + asyncResources.set(asyncId, { + type, + resource, + stacks + }) }, destroy (asyncId) { asyncResources.delete(asyncId) @@ -85,3 +88,17 @@ function formatFilePath (filePath) { function normalizeFilePath (filePath) { return filePath.startsWith('file://') ? fileURLToPath(filePath) : filePath } + +// See: https://v8.dev/docs/stack-trace-api +function captureStackTraces () { + const target = {} + const original = Error.prepareStackTrace + + Error.prepareStackTrace = (error, stackTraces) => stackTraces + Error.captureStackTrace(target, captureStackTraces) + + const capturedTraces = target.stack + Error.prepareStackTrace = original + + return capturedTraces +} diff --git a/package-lock.json b/package-lock.json deleted file mode 100644 index d69899a..0000000 --- a/package-lock.json +++ /dev/null @@ -1,28 +0,0 @@ -{ - "name": "why-is-node-running", - "version": "3.1.0", - "lockfileVersion": 3, - "requires": true, - "packages": { - "": { - "name": "why-is-node-running", - "version": "3.1.0", - "license": "MIT", - "dependencies": { - "stackback": "0.0.2" - }, - "bin": { - "why-is-node-running": "cli.js" - }, - "engines": { - "node": ">=20.11" - } - }, - "node_modules/stackback": { - "version": "0.0.2", - "resolved": "https://registry.npmjs.org/stackback/-/stackback-0.0.2.tgz", - "integrity": "sha512-1XMJE5fQo1jGH6Y/7ebnwPOBEkIEnT4QF32d5R1+VXdXveM0IBMJt8zfaxX1P3QhVwrYe+576+jkANtSS2mBbw==", - "license": "MIT" - } - } -} diff --git a/package.json b/package.json index a1ed19a..f8f2b56 100644 --- a/package.json +++ b/package.json @@ -16,9 +16,6 @@ "index.d.ts", "index.js" ], - "dependencies": { - "stackback": "0.0.2" - }, "bin": { "why-is-node-running": "cli.js" },