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

modulor

v0.0.6

Published

Bundles inference from static files distribution

Downloads

11

Readme

Modulor

Bundles configuration inference from static files distribution

Install

$ npm install modulor

Description

This package is composed of core classes based on node core streams :

  • Walker (lib/core/walker) : file tree traversal stream (through readdirp)
  • DOMAnalyzer (lib/core/dom) : DOM analyzer for scripts entries and file distribution detection (through jsdom)
  • ASTAnalyzer (lib/core/ast) : AST analyzer for shared & conditionnal modules detection (through amdetective)
  • Bundler (lib/core/bundler) : modules registry analyzer and configuration inferrer

All streams chunks are / should be of instances of File class (lib/core/file) which rely on mime-types module for file types. Streams chunks are tested according to this rule and streams may emit warn events in case of error / wrong pipelining.

Usage

modulor(source)

This method creates a stream that traverse source folder and emit a data event with inferred configuration. It is composed of a Walker, a DOMAnalyzer, a ASTAnalyzer and a Bundler stream piped together (see below).

modulor(source).on('data', function (configuration) {
    // ...
})

The emitted configuration object is formatted according to the detected file distribution type. By default, the object has the following structure :

  • bundles : array with for each bundle :
    • name : bundle ID
    • include : array of packaged modules' IDs

modulor.types

This file distribution types :

  • modulor.types.REQUIREJS for RequireJS
  • ...

modulor.File.create(properties)

This method creates a file object with the following properties JSON object :

  • root : the root path of the distribution the file belongs to
  • path : the path of the file relative to the distribution's root
  • fullPath : the full path of the file
  • type : the mimetype of the file (File.types.HTML or File.types.JAVASCRIPT)
  • name : the name of the file (filename or module ID)
  • parents : array with parents files (HTML for javascript files, parent module for modules)
  • dependencies : array with dependencies files (javascript integrated file for HTML, submodules for modules/javascript)

All properties are optionnal

modulor.Walker.create(source, filter)

This method creates a readeable stream that traverse a given source path and emit each file matching the filter globs. This a wrapper around readdirp module.

modulor.Walker.create(source, filter)
  .on('data', function (file) {
      // ...
  })
  .on('end', function () {
      // ...
  })

modulor.DOMAnalyzer.create()

This method creates a Document Object Model (DOM) analyzer in the form of a transform stream that take file input chunks with type File.types.HTML and emit all linked javascript files as file chunks with type File.types.JAVASCRIPT The stream has a type property (with a modulor.types.* value)

modulor.DOMAnalyzer.create()
  .on('data', function (file) {
      // ...
  })
  .on('warn', function (file) {
      // event emitted if file is not a File instance 
      // or its type property is not File.types.HTML
      // ...
  })
  .on('end', function () {
      // ...
  })

modulor.ASTAnalyzer.create(type)

This method creates an Abstract Syntax Tree (AST) analyzer in the form of a transform stream that take file input chunks with type File.types.JAVASCRIPT and emit all modules as chunks of the same type. By default, the stream reads the type property of its source stream and has a configuration property corresponding to this file distribution type configuration. The optionnal type parameter is used to force distribution type if the stream is not piped with a DOMAnalyzer stream.

modulor.ASTAnalyzer.create(type)
  .on('data', function (file) {
      // ...
  })
  .on('warn', function (file) {
      // event emitted if file is not a File instance
      // or its type property is not File.types.JAVASCRIPT
      // ...
  })
  .on('end', function () {
      // ...
  })

modulor.Bundler.create(type, configuration)

This method creates a transform stream that take file input chunks with type File.types.JAVASCRIPT and emit the inferred configuration. The stream reads the type and configuration properties of its source stream. The optionnal type and configuration parameters are used to force the file distribution's type and configuration if the stream is not piped with a ASTAnalyzer stream.

modulor.Bundler.create(type, configuration)
  .on('data', function (configuration) {
      // ...
  })
  .on('warn', function (file) {
      // event emitted if file is not a File instance
      // or its type property is not File.types.JAVASCRIPT
      // ...
  })
  .on('end', function () {
      // ...
  })