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

makit

v1.17.1

Published

Make in JavaScript done right!

Downloads

62

Readme

makit

npm version downloads Build Status Coveralls dependencies semantic-release GitHub issues David David Dev DUB license Commitizen friendly

Purposes and Principles:

  • Minimal Concepts. It's intended to be a general purpose build automation tool just like GNU Make. Do not introduce unnecessary concept to keep it simple and stupid.
  • Less Restrictions. It should be as open as GNU Make, makit doesn't expect recipes return anything, doesn't even requrie a recipe for its rule definition, and doesn't care about the actual output of recipes.
  • JavaScript Style. Recipes can be written as callback style, Promise style or just synchronous style. Automatic variables are replaced by camelCased equivalents. Wildcard in static patterns are replaced by JavaScript RegExp and globs.

API Spec: https://searchfe.github.io/makit/modules/_index_.html

Get Started

Basically, the syntax is as simple as Makefiles but with a .js extension. A Makefile.js contains a set of rules, each of which consists of 3 parts:

  • target: either a filepath string, a glob string, or a RegExp object.
  • prerequisites: list of filepath strings, functions that return a list of strings, or list of strings and functions. functions here can be either sync or async.
  • recipe: an optional function, can be either sync or async.

Suppose we have a makefile.js containing the following contents:

const { rule } = require('makit')

rule('all', ['a1.min.js'])  // default rule

rule('a1.min.js', ['a.js'], function () {
    const src = readFileSync(this.dependencies[0], 'utf8')
    const dst = UglifyJS.minify(src).code
    writeFileSync(this.target, dst)
})

When we run makit(which is equivelant to make all cause all is the first rule), makit tries to make the target all which requires a1.min.js so the second rule will be applied firstly and its recipe is called to generate the target a1.min.js. The prerequisites for all has been fully resolved now and makit then tries to call its recipe, which is not defined for the above case so makit will just skip call the recipe and assume the target all is made successfully.

See /demo directory for a working demo. For more details see the typedoc for .rule()

Config

The makit CLI supports --help to print usage info:

makit.js [OPTION] <TARGET>...

Options:
  --version       Show version number                             [boolean]
  --makefile, -m  makefile path                                    [string]
  --database, -d  database file, will be used for cache invalidation
                                                   [default: "./.makit.db"]
  --require, -r   require a module before loading makefile.js or
                  makefile.ts                         [array] [default: []]
  --verbose, -v   set loglevel to verbose                         [boolean]
  --debug, -v     set loglevel to debug                           [boolean]
  --loglevel, -l  error, warning, info, verbose, debug
                                                   [choices: 0, 1, 2, 3, 4]
  --graph, -g     output dependency graph        [boolean] [default: false]
  --help          Show help                                       [boolean]

Or specify in package.json:

{
  "name": "your package name",
  "dependencies": {},
  "makit": {
    "loglevel": 2,
    "makefile": "makefile.ts",
    "require": ["ts-node/register"]
  }
}

Async (Promise & Callbacks)

When the recipe returns a Promise, that promise will be awaited.

rule('a1.min.js', ['a.js'], async function () {
    const src = await readFile(this.dependencies[0], 'utf8')
    const dst = UglifyJS.minify(src).code
    await writeFile(this.target, dst)
})
// equivelent to
rule('a1.min.js', ['a.js'], async ctx => {
    const src = await readFile(ctx.dependencies[0], 'utf8')
    const dst = UglifyJS.minify(src).code
    await writeFile(ctx.target, dst)
})

Callback style functions also work:

rule('clean', [], (ctx, done) => rimraf('{*.md5,*.min.js}', done))

Dynamic Dependencies

// `makit a.js.md5` will make a.js.md5 from a.js
rule('*.js.md5', ctx => ctx.target.replace('.md5', ''), async function () {
    const src = await this.readDependency(0)
    await this.writeTarget(md5(src))
})

Similarly, async prerequisites functions, i.e. functions of return type Promise<string> or Promise<string[]>, are also supported.

Matching Groups and Reference

Makit uses extglob to match target names. Furthermore it's extended to support match groups which can be referenced in prerequisites.

// `makit output/app/app.js` will make app.js.md5 from a.ts
rule('(output/**)/(*).js', '$1/$2.ts', async function () {
    return this.writeTarget(tsc(await this.readDependency()))
})
make('output/app/app.js')

Dynamic Prerequisites

It's sometimes handy to call make() within the recipe, but global make() is not valid in recipes. For example the following rule is NOT valid:

const { rule, make } = require('makit')

rule('bundle.js', 'a.js', async (ctx) => {
    await make('b.js')
    const js = (await ctx.readFile('a.js')) + (await ctx.readFile('b.js'))
    ctx.writeTarget(js)
})

We introduce rude() to facilitate this situation, a ctx.make API is available inside the recipe of rude:

const { rude } = require('makit')

rude(
    'bundle.js', [], async ctx => {
        await ctx.make('a.js')
        await ctx.make('b.js')
        const js = (await ctx.readFile('a.js')) + (await ctx.readFile('b.js'))
        return ctx.writeTarget(js)
    }
)

A pseudo rule with bundle.js.rude.dep as target, the contents of which is the actual dependencies, will be generated for each rude().