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

react-to-uml

v1.0.5

Published

Visualize your react components tree with uml diagram

Downloads

4

Readme

It is appropriate to your project if it uses babel and webpack.

Install

npm i react-to-uml

Connect to your project

// webpack.base.ts
import { makePlugins } from 'react-to-uml';

const rootPath = process.cwd();
const packagesPaths = new RegExp(rootPath + '/(packages)');
const entryFileName = rootPath + '/packages/app/client.js';
const gatheredComponentsFileName = `${rootPath}/build/assets/gatheredComponentsByFileName.json`;
const outUmlFileName = `${rootPath}/build/assets/treeComponentsUML.json`;

const { babelPlugin, webpackPlugin } = makePlugins({
  packagesPaths,
  entryFileName,
  gatheredComponentsFileName,
  outUmlFileName,
});

export default {
  entry: './packages/app/client.js',
  plugins: [new HtmlWebpackPlugin({ template: './public/index.html' }), webpackPlugin],
  output: {
    filename: '[name].bundle.js',
    path: path.resolve(__dirname, 'build'),
  },
  resolve: {
    extensions: ['.js', '.jsx', '.ts', '.tsx', '...'],
  },
  module: {
    rules: [
      {
        test: /\.(js|jsx|ts|tsx)$/,
        exclude: /node_modules/,
        use: {
          loader: 'babel-loader',
          options: {
            plugins: [babelPlugin],
            presets: [
              ['@babel/preset-typescript'],
              ['@babel/preset-react', { runtime: 'automatic' }],
              ['@babel/preset-env'],
            ],
          },
        },
      },
    ],
  },
} as Configuration;

After build your project

  1. You will get the treeComponentsUML.uml file where will be stored your diagram
  2. On a small project, you can test it here
  3. But to visualize it for the real project the simplest way is to use the plantUML java library
  4. Download the jar file here
  5. Download the graphviz it is needed for the kind of diagrams generated by the library
  6. Run java -Xmx2G -jar plantuml-1.2023.11.jar ./build/assets/treeComponentsUML.uml -tsvg -verbose -t4 (more CLI params here)
  7. Use your svg file. It is possible to render other formats (more CLI params here)

Extra options

acceptableExts?: string[];

by default ['jsx', 'js', 'tsx', 'ts'] - files in which library will looking for the jsx

isGroupByParentDirNeeded?: boolean;

by default false - grouping your components by root dir, e.g. for monorepo with packages root dir it will group it like in the picture below

repetitiveCountForRemoveFromTree?: number;

by default 4 - to adjust your zoom of view, components with a count of repetitive more than this param will be removed from the diagram.

Troubleshooting

To turn on extra logs in this library use --debug with your build script.

npm run build --debug

What is next?

Once you gathered the data from your code base, just imagine what you could do in the next step. This library right now just organizes the process of traverse, so it is possible to add logic into the library and gather extra data on the way like:

  1. Test coverage for each file and component
  2. Size of your files and components
  3. Component names into files (if you use an approach with multiple components in one file)
  4. Something else
  5. Render it with the interactive like d3.js with the real-time input search filter, and highlights of the arcs when you select one of the nodes