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

@zoxon/emitty

v1.4.2

Published

Determine the inheritance of template and style files

Downloads

261

Readme

emitty

Determine the inheritance of template and style files.

What is it? or what is problem?

Most HTML and CSS preprocessors use a synchronous API to access file system and don't use cache for already read files. It degrades performance and increases the time required to compile the code.

Also, when your project is very large and has a large number of dependencies between blocks (e.g. many mixins) — compiles all files of a project may take seconds or even minutes. This is unacceptable if you are working with a "watch" mode.

Solution?

This module allows you to compile only those files that depend on the changed file and require compilation.

For example, if you have the following files:

  • templates/
    • a.pug — depends on b.pug
    • b.pug
    • c.pug

If you change the c.pug file, then will be compiled only it. If you change the b.pug file, then will be compiled a.pug file.

Install

$ npm i -D emitty

Why?

Usage

const emitty = require('emitty').setup('templates', 'jade');

emitty.scan().then(() => {
  console.log(emitty.storage());
  // {
  //   'a.pug': {
  //     dependencies: ['components/b.pug'],
  //     ctime: new Date()
  //   },
  //   'components/b.pug': {
  //     dependencies: [],
  //     ctime: new Date()
  //   }
  // }
  }
});

Setup

setup(directory, language, [options])

Creates API for emitty.

| Parameter | Type | Default | Required | Description | |:-----------:|:--------------------:|:-------:|:--------:|:------------| | directory | String | null | + | Directory to start from. | | language | String or Object | null | + | The settings for the language that you want to use. For more details see «Language» section. | | [options] | Object | {} | - | For more details see «Options» section. |

API

const emitty = require('emitty').setup('templates', 'pug');

storage()

Returns a snapshot of the Storage.

console.log(emitty.storage());
// {
//   'a.pug': {
//     dependencies: ['components/b.pug'],
//     ctime: new Date()
//   },
//   'components/b.pug': {
//     dependencies: [],
//     ctime: new Date()
//   }
// }

keys()

Returns the keys of the Storage.

console.log(emitty.keys());
// ['a.pug', 'components/b.pug']

load(snapshot)

Clears the Storage and loads the new data.

emitty.load({
  'c.pug': {
    dependencies: ['nope.pug'],
    ctime: new Date()
  }
});
// console.log(emitty.keys());
// ['c.pug']

scan([filepath], [stats]) => Promise

Scans directory and updates the Storage. If you specify a filepath, then only that file will be scanned. Also you can specify stats of file (to avoid doing unnecessary actions inside emitty).

emitty.scan().then(() => {
  // console.log(emitty.keys());
  // ['a.pug', 'b.pug']
});

resolver

getDependencies(filepath)

Returns all files that depends on the specified file.

emitty.scan().then(() => {
  console.log(emitty.resolver.getDependencies('a.pug'));
  // ['components/b.pug']
});

checkDependencies(a, b)

Returns True if A depends on B.

emitty.scan().then(() => {
  console.log(emitty.resolver.getDependencies('a.pug'));
  // ['components/b.pug']
  console.log(emitty.resolver.checkDependencies('a.pug', 'components/b.pug'));
  // true
  console.log(emitty.resolver.checkDependencies('a.pug', 'nope.pug'));
  // false
});

stream([filepath], [stats]) => TransformStream

Is scan method, but for Stream and combines scan + resolver.

Scans directory or file and updates the Storage. Then, if file in stream depends on the changed file — pass it further. Else skip it.

Warning

If you do not specify the filepath to the changed file, it will be the last file that has changed since the last scan.

const stream = emitty.stream();
stream.on('end', () => {
  // console.log(emitty.keys());
  // ['a.pug', 'b.pug']
});

stream.end();

filter(filepath) => TransformStream

Passes continue to stream only those files that need to be compiled.

Options

| Option | Type | Default | For Stream | Description | |:-----------------:|:----------:|:----------------------------------------------------:|:----------:|:------------| | snapshot | Object | {} | - | You can load the previous state of the project in the Storage using this option. | | log | Function | console.log | + | The function that will be called if the file needs to be compiled. | | cleanupInterval | Number | null | - | Time interval over which the Storage will be cleared of obsolete items. Recommended for projects very big projects. | | makeVinylFile | Boolean | false | + | You can use gulp.src('patterns', { read: false }) to reduce access for filesystem. This option creates a Vinyl file within a Stream. | | basedir | String | null | - | The root directory of all absolute inclusion. | | scanner.depth | Number | 30 | - | The maximum number of nested directories to scan. | | scanner.exclude | String[] | ['.git', '**/node_modules', '**/bower_components'] | - | List of Glob-patterns for directories that are excluded when scanning. |

Language

Built-in configs

The emitty contains built-in configs for the following instruments:

You can use them when you configure emitty:

const emitty = require('emitty');
const emittyJade = emitty.setup('templates', 'pug');
const emittySugarml = emitty.setup('templates', 'sugarml');
// ...

Your own config

Instead of use built-in config you can specify your own config.

For example, config for Slm:

const emitty = require('emitty').setup('templates', {
  extensions: ['.slm'],
  matcher: /=?=\s(?:partial|extend)\(['"]([^'"]+)['"].*?\)/,
  comments: {
    start: '/',
    end: ''
  },
  indentBased: true
});

| Property | Type | Default | Required | Description | |:----------------:|:----------:|:-------:|:--------:|:------------| | [extends] | String | null | - | The name of built-in config, which will be basis for this config. If you specify this property, you can specify other properties as needed. | | extensions | String[] | null | + | List of file extensions to be included in Storage when scanning. | | matcher | RegExp | null | + | Regexp to run on each line of source code to match dependency references. | | comments.start | String | null | + | The start of a comment. | | comments.end | String | null | + | The end of a comment. | | [indentBased] | Boolean | false | - | The syntax of the language is based on indentation? | | [partials] | Boolean | false | - | Add additional partials files (files with _ prefix, like Sass/SCSS) to dependencies. |

How to use with Gulp

Changelog

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

License

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