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

@emitty/core

v2.0.1

Published

A platform for finding dependencies between files and building tools for incremental compilation or build

Downloads

149

Readme

@emitty/core

A platform for finding dependencies between files and building tools for incremental compilation or build.

Table of Contents

Highlights

  • Simple and configurable.
  • Language free.
  • Support snapshots for postpone incremental builds.

Donation

Do you like this project? Support it by donating, creating an issue or pull request.

Donate

Installation

npm install @emitty/core

Usage

const emitty = require('@emitty/core').configure();

emitty.language({
    extensions: ['.pug', '.jade'],
    parser: require('@emitty/language-pug').parse
});

await emitty.filter('home.png'); // true
await emitty.filter('home.png', 'news.png'); // false

API

.configure([options])

Returns an Emitty instance with the methods described below.

[options]

  • Required: false
  • Type: Options

See Options section.

.language(specification)

Adds language support.

specification

  • Required: true
  • Type: Language

Specification of the language to be added.

:1234: How to add my own language?

export type Language = {
    extensions: string[]; // ['.pug', '.jade']
    parser: (filepath: string, buffer: Buffer) => { references: string[] };
};

.load(snapshot)

Loads information from the snapshot to the storage.

snapshot

  • Required: true
  • Type: Snapshot

Snapshot storage.

.dump()

Returns an object that contains a storage in the snapshot format.

.clear()

Completely cleans the storage.

.filter(source, [changed])

Determines whether to compile the changed file if it is passed.

:1234: How does it works?

source

  • Required: true
  • Type: string

The file that is currently being processed by the builder or compiler.

[changed]

  • Required: false
  • Type: string

The file that trigger the build or compile.

Options

cwd

  • Type: string
  • Default: process.cwd()

The current working directory.

fs

  • Type: FileSystemAdapter
  • Default: fs.*

Custom implementation of methods for working with the file system.

export type FileSystemAdapter = {
    access?: typeof fs.access;
    constants?: typeof fs.constants;
    readFile?: typeof fs.readFile;
};

FAQ

How does it works?

The .configure method initiates a storage to which all relationships between the files being processed are later written.

When you call the .filter method without the changed file, @emitty reads the source file and builds a dependency tree for that file (with recursive reads of dependencies). In this case, the filter always returns true to ensure that all files in the project are compiled and collected in the storage.

When you call the .filter method with the changed file, @emitty reads only the changed file and updates its dependencies (without recursive reads of dependencies). In this case, the filter returns true if there is a reference to the changed file in the dependency tree of the source file. Otherwise false.

How to use this with gulp?

Look at the gulp.js file for an example.

How to add my own language?

You can use the .language method with any language, even your own. Just implement the parser for your language.

type File = {
    references: string[];
};

export function myOwnLanguageParser(filepath: string, buffer: Buffer): Promise<File> {
    return Promise.resolve({
        references: ['home.own.language', 'components/header.own.language']
    });
}

Next, just use it with the .language method.

Changelog

See the Releases section of our GitHub project for changelog for each release version.

License

This software is released under the terms of the MIT license.