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

copenhagen

v0.1.0

Published

Experimental infrastructure for creating Istanbul-compatible code coverage

Downloads

4

Readme

Copenhagen

Experimental infrastructure for creating Istanbul-compatible code coverage.

Background

Istanbul is a code coverage tool for JavaScript. It supports a wide range of reporters and is used by tools like nyc.

Unfortunately Istanbul isn't great with newer JavaScript syntax. Various solutions exist which use source maps to convert coverage reports to the original source. Inevitably these solutions encounter edge-cases where the resulting report is inaccurate or incomplete.

Istanbul modifies your code (known as instrumenting) in order to collect coverage data. This can cause stack traces to be misaligned with your actual code, making it harder to debug failing tests.

Coverage data is stored in a global variable. In Node.js this means special exit handlers are required to persist the data to disk. Further, coverage data can't be accessed without executing the instrumented code. If the code cannot run in a particular environment this will cause a crash. ES2015 code must be transpiled before it can be instrumented which breaks nyc's --all option when combined with AVA and custom precompilers.

Loading the istanbul dependency can be slow. nyc has special lazy-loading logic to work around this issue. Instrumenting can be slow as well, leading nyc to implement a cache layer.

Copenhagen was created to address these issues.

It uses Babel plugins to add instrumentation, allowing new syntax to be instrumented before code is transpiled to ES5. It can also statically generate the initial coverage data so the instrumented code does not have to be executed. These plugins can be used independently in a separate build pipeline.

Source maps can be generated for the instrumented code. These can be used to correct stack traces.

Alternative compilers may be be written to support languages such as TypeScript or CoffeeScript.

The default data collector is a singleton module. Tools like nyc can use this module to get a stream for the collected data. This data can then be piped to disk, alleviating the need for exit handlers.

The single export of the main copenhagen module is a cacheSalt, which can be used to cache the instrumentation output. Other features are available through individual modules, e.g. copenhagen/instrument. This makes it easier to lazy load dependencies.

Remaining work

Copenhagen is still new. I'd like to integrate it with nyc. The cacheSalt implementation should be improved to work with local Git clones and npm-based Git installs. This will help development. Much more syntax needs to be supported, as well as Istanbul's ignore pragmas. There is a __coverage__ Babel plugin which may contain some useful syntax.