How duheng/sniperjs works
Project Type and Purpose
• This is an open-source, mono-repo JavaScript error-reporting library (managed by Lerna) that provides non-intrusive error collection and configurable report delivery. It targets both browser environments and multiple mini-app platforms (WeChat, Baidu, Alipay, etc.).
File-Structure Analysis
• At the root: a Lerna configuration (lerna.json) plus a Rollup config (rollup.config.js) for building all packages.
• packages/
• ErrorReporter – the core error-capture engine (src/ → dist/).
• MiniWxErrorReporter – platform-specific “adaptor” for WeChat-style mini-apps, built on top of core helpers.
• utils – shared utilities (throttling, merging, type checking).
• Build artifacts live under each package’s dist/ folder; package.json files declare inter-package dependencies.
Key README Insights
• Describes features: automatic JS error, HTTP error, Promise rejection capture, optional breadcrumbs.
• Configuration options for report URL, filters, sampling, and hook callback (beforeReport).
• Usage pattern: import the mini package before your App() call, instantiate with a config object, then the library silently intercepts, aggregates, and dispatches error logs to your server.
Detailed Points to Capture
• Lerna’s role in linking inter-package dependencies.
• Rollup config’s use across packages.
• The hierarchy: utils at the base, core engine on top, platform SDK at the top.
• Config object fields driving behavior (url, filters, sampling, callbacks).
• HTTP transport as a pluggable endpoint.