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 🙏

© 2025 – Pkg Stats / Ryan Hefner

r2g.example

v0.0.1001

Published

Generated via a semver-oriented TypeScript library skeleton.

Downloads

12

Readme

r2g example project - how to use r2g for publishing NPM packages


This readme file accompanies the following video:


Remember that there are 3 test phases, phaseZ/phaseS/phaseT. See: https://github.com/ORESoftware/r2g


Remember that r2g can catch 4 types of problems:

  1. Failure to build/transpile project before publishing, because the built files are not tracked by source control.
  2. Missing dependencies - when people install your package with the --production flag, your package might be missing deps.
  3. Files that are missing in the NPM tarball: your .npmignore file or "files" property in package.json might be too aggressive/passive.
  4. General/unknown problems that relate to using/running your package as a dependency, instead of directly.

To learn how r2g works, do these steps in order:

  1. Clone this repo: $ git clone https://github.com/ORESoftware/r2g.example.git
  1. install r2g globally: $ npm i -g r2g
  1. Run $ r2g test at the cloned project root

=> The first problem is that it says it can't find our package ("r2g.example"). That is because we haven't created the files in the dist/ folder yet. So we build/transpile with tsc. This is the first kind of problem r2g can catch.

  1. Run $ tsc --watch, from the root of the project. npm i -g typescript if you don't have tsc installed.
  1. Run $ r2g test # should pass

=> You might notice "foobar test" in the output, during phase-Z.

  1. Go into package.json and change "r2g.test" to "r2g.testnot". Now, r2g will default to the $ npm test script.

=> In this case, npm test will run node test/simple.js

  1. Run $ r2g test

It will output:
r2g: phase-Z: Directory path which contains the r2g.example index file: /home/you/.r2g/temp/copy/r2g.example/dist

  1. Go into test/simple.js and switch to require('r2g.example') instead of require('../dist'), then run $ r2g test

It will output:
r2g: phase-Z: Directory path which contains the r2g.example index file: /home/you/.r2g/temp/project/node_modules/r2g.example/dist

  1. The difference between 7 and 8 is important. 7 loads the regular unpacked version of your package, and 8 will load a previously packed version of your package. Using 7 will npm test your package as usual. Using 8 will npm test your package in a way that tests itself as a dependency of itself and having been previously packed with NPM pack.
  1. Now, go into src/index.ts. Change r2gSmokeTest to r2gSmokeTestFoo. Run $ r2g test.

It will output:
r2g: phase-S: A module failed to export a function from "main" with key "r2gSmokeTest". r2g: phase-S: The module/package missing this export has the following name: r2g: phase-S: r2g.example

This means that your main (dist/index.js) failed to export a function with name r2gSmokeTest, because we changed it to r2gSmokeTestFoo, lulz.

  1. Change r2gSmokeTestFoo back to r2gSmokeTest, but return false from the function instead of true.

It will output:
r2g: phase-S: At least one exported "r2gSmokeTest" function failed. r2g: phase-S: Error: [ { path: 'r2g.example', result: false } ]

  1. Your r2gSmokeTest function must return true, and no other value is acceptable. To skip phase-S, use --skip=s or -s.

As an example, you can try using this for your r2gSmokeTest:

export const r2gSmokeTest = async () => {
  const z = exports.z;
  const v = await z.foo();
  return v === 'foo';
}

Ultimately, the purpose of r2gSmokeTest is if you don't want to use ".r2g/tests" in your project. Next we will create a directory in your project called .r2g which will house tests used for specifcally before publishing.

  1. Run r2g init in your project root. You will get this new dir with this structure:
.r2g/
  fixtures/
  tests/
  config.js
  readme.md
  1. The tests in the .r2g/tests folder are tests that will be copied like so:
project/
 node_modules/
  r2g.example/
    .r2g/
      fixtures/
      tests/

to:

project/
 fixtures/    # copied here
 tests/       # copied here
 node_modules/
  r2g.example/
    .r2g/
      fixtures/
      tests/

Where project is a temp directory that will load your package a dependency and run tests against it.

  1. In .r2g/tests/smoke-test.1.js, you will see something like this:
#!/usr/bin/env node
'use strict';

const assert = require('assert');
const path = require('path');
const cp = require('child_process');
const os = require('os');
const fs = require('fs');
const EE = require('events');

process.on('unhandledRejection', (reason, p) => {
  // note: unless we force process to exit with 1, process may exit with 0 upon an unhandledRejection
  console.error(reason);
  process.exit(1);
});

// your test goes here

Add these lines at the end:

console.error('whoops');
process.exit(1);

Now run r2g test. You will see:

r2g: About to run tests in your .r2g/tests dir. r2g: phase-T: Now we are in phase-T... r2g: phase-T: whoops r2g: [r2g/error] an r2g test failed => a script in this dir failed to exit with code 0: /home/you/.r2g/temp/project/tests

To fix this, simply change process.exit(1) to process.exit(0). You can put any tests you want in .r2g/tests


You have now see how the basic three phases work, S,Z,T. They just have random character names. They should have been in alphabetical order, but S,Z,T is the order in which they are currently run.

To learn more about the --pack / --full options, we will save those for another day.