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

ez-madge

v0.1.2

Published

Madge made easy! Functions and CLI to map project dependencies

Downloads

27

Readme

EZ-MADGE

Madge helps us to easily map dependencies between files.

Madge Documentation

This is a package that provides a way to quickly and easily integrate madge into your Javascript project.

It comes with 4 out of the box charts.

NOTE: By default, only js and jsx files are mapped. Future releases will extend this functionality.

Examples

NOTE: For proper mapping, please point to the entry point (top level) of your app.

Chart 1: Map all dependencies

This is the standard diagram that depicts all of your dependencies being mapped.

Full Dependency diagrams

Chart 2: Map Orphan nodes

These diagrams tell you which files are not imported or referenced through your app. Great for identifying unused files for deletion.

Orphan diagrams

Chart 3: Depth Level Mapping

This diagram let you map to only certain depth in the tree.

Great for larger projects.

Depth Level diagrams

Chart 4: Filter dependency files by extension - WIP

This diagram filters the tree nodes dependencies based on the file extension.

Madge has file extension filter of its own. This is useful for designating the parent nodes you want to limit by file extension.

This does not allow you to filter the dependent nodes by file extension.

As a result, you could have files you do not want to see, polluting your map.

This implementation differs as it filters both the parent and children dependencies.

The use case it was developed for was to see the interaction of React components as designated by the .jsx extension

NOTE: By default, the '.jsx' used in React projects, is the dependency filter extension.

Component diagrams

Install

$ npm install ez-madge --save-dev

Installing graphviz

Graphviz draws the diagrams.

Unfortunately, there is no out of the box way to integrate with the npm version of Graphviz.

As a result, you need to install Graphviz locally to run the tests. You can install it using brew.

brew install graphviz

You can run index from the cli or run it using node. Running it in node, gives you more opportunity to closely configure your visualization.

Usage

There is 2 ways to use this file:

CLI or API

CLI usage

You can install the package globally to use the cli

$ npm install -g ez-madge 
  Usage
    $ ez-madge <target file>

  Options
    --depth, -d  Determine levels of depth
    --output, -o  Determine an output location
    --font, -f  Change fontSize
    --vertical, -v  Graph vertical tree

  Examples
  $ ez-madge myApp/src/index.js -d=4

API usage

import mapDependencies from 'ez-madge'

const options = {
    // levelDepth is used for the diagramming options
    levelDepth: 3,
    // This is used to limit the dependencies of the parent and dependent nodes
    filteredExtensions:  ['js', 'jsx', 'graphql'],
    //These are common madge options - Please see Madge documentation for more details
    madge: {
      // font size for the diagram
      fontSize: '10px',
      // flag to include npm packages
      includeNpm: false,
      // file extensions to include in the parent nodes
      fileExtensions: ['js', 'jsx'],
      // Files to exclude from mapping.
      // It is generally a good idea to exclude test files at the minimum
      excludeRegExp: ['.*.test.jsx?$', '.scss$'],
      graphVizOptions: {
        G: {
          // Direction to map
          // LR = Left to right; 
          // TB= Top to Bottom;
          rankdir: 'LR'
        }
      }
    }
  };
};





mapDependencies(targetFile, diagramSaveLocation, options)