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

@tradie/node-package-template

v1.1.0-alpha.b2a4b8e1

Published

A tradie template for creating packages that run on NodeJS.

Downloads

6

Readme

@tradie/node-package-template

npm Travis Commitizen friendly

A tradie template for creating packages that run on NodeJS.

Featuring:

  • linting with eslint
  • type checking with flow
  • transpilation with babel
  • testing with jest

Usage

  1. Create a new package:

    npx --package @tradie/node-package-template tradie create

  2. Build the files:

    yarn run build

  3. Run the tests:

    yarn run test

  4. Publish the package:

    yarn publish

Commands

tradie create

Create the package files.

tradie clean

Remove generated files.

Will remove files matching lib/** and coverage/**.

tradie lint

Lint source and test files.

tradie build [--watch]

Lint and transpile source files.

Will lint and transpile source files matching src/**/*.{js,jsx} and write the result to lib/. Will copy Flow types to lib/.

Will ignore test files, fixtures and mocks matching {src,test}/**/*.test.{js,jsx}, {src/test}/**/__mocks__/ or {src/test}/**/__fixtures__/.

tradie test [--watch] [--coverage]

Run test files.

Will run test files matching {src,test}/**/*.test.{js,jsx}.

How to

Setup Flowtype

  1. Create the config file:

    • .flowconfig
    [ignore]
    
    # ignore transpiled code
    <PROJECT_ROOT>/lib
    

    You can learn more about configuring Flow here.

  2. Install the types for jest:

    flow-typed install jest@^20 --flowVersion 0.48.0

    You can learn more about installing Flow types here.

  3. Annotate your files:

    • src/index.js
    // @flow
    ...
    • src/index.test.js
    // @flow
    ...

    You can learn more about writing code for Flow here.

Write tests

  1. Create a test file and write some assertions

    • src/index.test.js
    
    describe('lame example()', () => {
      it('should pass', () => {
        expect(true).toBeTruthy();
      });
    });
    

    You can learn more about writing assertions with Jest here.

    Jest provides mock functions and manual mock functions which are worth learning!

Customising the test environment

Occasionally you'll need to run some code to setup your test environment before running your tests. Jest will try running src/_.test.js and test/_.test.js before it runs your tests. You can place any necessary test setup in here.

e.g.

import {shallow} from 'enzyme';

//allow global access to `shallow()` in test files
// to avoid `import`ing it in every file
global.shallow = shallow;

Include other ty[es of files

  1. Create a new directory for your files

    e.g. files/

  2. Reference your files from your sources using require.resolve()

    e.g. fs.readFileSync(require.resolve('../files/data.txt'));

  3. Update the files key in your package.json so NPM publishes the files in the package

    e.g. "files": ["lib", "files"],