Skip to content

Commit

Permalink
Replace stackback with internal implementation (#80)
Browse files Browse the repository at this point in the history
Signed-off-by: Jon Koops <[email protected]>
  • Loading branch information
jonkoops authored Jul 12, 2024
1 parent bbcf168 commit 9f29cb8
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 97 deletions.
3 changes: 0 additions & 3 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
61 changes: 1 addition & 60 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -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
23 changes: 20 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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)
Expand Down Expand Up @@ -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
}
28 changes: 0 additions & 28 deletions package-lock.json

This file was deleted.

3 changes: 0 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@
"index.d.ts",
"index.js"
],
"dependencies": {
"stackback": "0.0.2"
},
"bin": {
"why-is-node-running": "cli.js"
},
Expand Down

0 comments on commit 9f29cb8

Please sign in to comment.