npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

longstack

v1.1.0

Published

LongStack 会在异常产生时自动附加前序调用堆栈,并支持过滤用户代码(模块)所产生的堆栈,帮助快速定位异步调用问题。

Downloads

13

Readme

LongStack

LongStack 会在异常产生时自动附加前序调用堆栈,并支持过滤用户代码(模块)所产生的堆栈,帮助快速定位异步调用问题。

使用此模块时,Node.js 版本需大于 v8.2.x

安装

npm i longstack

用法

const longstack = require('longstack');
longstack.enable([options]);

options:

  • removeNativeCode: 是否移除非用户代码产生的堆栈, 默认值为 false
  • maxAsyncDepth: 最大异步调用栈深度, 默认值为 64

配置全局生效,只需在用户代码入口处开启即可。

请注意:此模块启动后会造成性能损耗,性能敏感代码请勿使用此模块。

例子

Promise.resolve(1).then(val => {
    setTimeout(()=>{
        try {
            ThisMayThrowError;
        } catch(err) {
            console.error(err);
        };
    }, 1000);
});

上面的代码执行后会打印出如下错误:

ReferenceError: ThisMayThrowError is not defined
at Timeout.setTimeout [as _onTimeout] (test.js:8:13)
at ontimeout (timers.js:427:11)
at tryOnTimeout (timers.js:289:5)
at listOnTimeout (timers.js:252:5)
at Timer.processTimers (timers.js:212:10)

Timeout.setTimeout 之前的执行堆栈都丢失了。 在开启 LongStack 后,会打印出从 loader 到当前模块的(异步)执行堆栈(如下所示):

ReferenceError: ThisMayThrowError is not defined
at Timeout.setTimeout [as _onTimeout] (test.js:8:13)
at ontimeout (timers.js:427:11)
at tryOnTimeout (timers.js:289:5)
at listOnTimeout (timers.js:252:5)
at Timer.processTimers (timers.js:212:10)
at emitInitNative (internal/async_hooks.js:137:43)
at emitInitScript (internal/async_hooks.js:336:3)
at initAsyncResource (internal/timers.js:50:5)
at new Timeout (internal/timers.js:82:3)
at setTimeout (timers.js:403:19)
at Promise.resolve.then.val (test.js:6:5)
at process._tickCallback (internal/process/next_tick.js:178:7)
at Function.Module.runMain (internal/modules/cjs/loader.js:721:11)
at startup (internal/bootstrap/node.js:228:19)
at PromiseWrap.emitInitNative (internal/async_hooks.js:137:43)
at Promise.then ()
at Object. (test.js:5:20)
at Module._compile (internal/modules/cjs/loader.js:678:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:689:10)
at Module.load (internal/modules/cjs/loader.js:589:32)
at tryModuleLoad (internal/modules/cjs/loader.js:528:12)
at Function.Module._load (internal/modules/cjs/loader.js:520:3)
at Function.Module.runMain (internal/modules/cjs/loader.js:719:10)

如果想过滤出用户(模块)代码,可以开启 removeNativeCode 选项,以便于查看与定位问题:

ReferenceError: ThisMayThrowError is not defined
at Timeout.setTimeout [as _onTimeout] (test.js:10:13)
at Promise.resolve.then.val (test.js:8:5)
at Object. (test.js:7:20)