Code Monkey home page Code Monkey logo

indeps's Introduction


indeps

๐Ÿ” Visualize the dependencies & sub-dependencies in your Javascript application.
Report Bug ยท Request Feature


Table of Contents
  1. About The Project
  2. How it works
  3. Getting Started
  4. Usage
  5. Roadmap
  6. License

About The Project

indeps is a tool for visualizing the dependencies that make up your JavaScript application. Combing through your lockfile is tedious, and isn't a very efficient way to understand the "bigger picture" of the packages within your project. Discovering the source of clashing dependencies or the dependency path for a specific module can be time consuming, and wears down your CMD + F keys. indeps attempts to solve this issue by providing a human-friendly UI for displaying & analyzing your projects resolved dependencies.

  • Easily search through the dependencies & sub-dependencies within your JavaScript project.
  • View the dependency tree for any given package.
  • Filter dependencies by various criteria, such as showing only the @types packages. Or, only show the packages that you've defined as a development dependency for the project.
  • Coming soon: Visualize your dependencies in a treemap and/or graph.

How it works

On the surface, indeps simply parses both your lockfile (either yarn.lock or package-lock.json) and your package.json file, runs additional analysis on these files, and injects this normalized data into a UI that is served by a local HTTP server. Currently, indeps requires:

  • A valid lockfile
    • Supports Yarn V1, Yarn V2(berry), and NPM(5+) lock files.
  • A valid package.json file
    • As of v0.1.0, we require a valid package.json file to run the indeps process. We require information about the devDependencies & dependencies that are defined in your package.json file, and certain lockfile formats do not provide sufficient indication as to which package/package resolution points to a package that the application defined as a dependency or development dependency. In the future, we may allow lockfile-only analysis, with a limited feature set compared to a full lockfile + package.json analysis.

(back to top)

Getting Started

indeps can be ran as either a CLI, or one may also utilize our various function exports to run the indeps processes programatically.

Prerequisites

  • Node v12+

Installation

indeps can be installed locally or globally.

To install indeps on a per-project basis:

npm i -D [email protected]
# or
yarn add -D [email protected]

Alternatively, installing indeps globally allows you to run it easily on any of your local projects. To install globally, run:

npm i -g [email protected]
# or
yarn global add [email protected]

(back to top)

Usage

As a CLI utility

indeps can be used a CLI utility to visualize the dependencies defined within any yarn.lock file - even if it is not inside a specific project.

If the package was installed globally, you can simply run indeps within any project directory with a valid lockfile & package.json file. Alternatively, you can specify the files you want to be used for the visualization through the --lock(-l) and --pkg flags:

# Can use either a path relative to your current directory
indeps --lock my-project/yarn.lock --pkg my-project/package.json
# Or specify an absolute path
indeps --lock /users/steve/my-project/yarn.lock --pkg /users/steve/my-project/package.json
# leaving it empty will check for a package.json/lockfile in the current directory
indeps

--lock/-l

Path to the lockfile to use for visualization.

--pkg

Path to the package.json file to use for the visualization.

--port/-p

The port used to serve the local indeps client. Defaults to 8088.

--open/-o

Automatically open the client in a browser if one is available on the host machine on server start. Defaults to true.

You may also use --no-open as an alias for --open false

--quiet/-q

Disables the default informational log messages; only display warning & error logs. Defaults to false.

(back to top)

Using the exported methods

Although indeps was made primarily with CLI usage in mind, we also export some high-level methods that allow you to run the various steps of the indeps process programatically. This provides a way for users to extend the functionality of indeps, or create plugins & extensions for bundlers or task runners.

import fs from "fs";

import {
  /** Parses a string-representation of `package.json` to an indeps-compatible parsed object */
  parsePkg,
  /** Parses a string-representation of a `yarn.lock` or `package-lock.json` file to an indeps-compatible parsed object */
  parseLock,
  /** Generates a dependency graph based on the object returned from `parseLock` */
  createDependencyGraph,
  /** Normalizes all data into a single object. */
  createDependencyData,
  /** A function that creates an instance of the "Viewer", responsible for managing the local server that handles serving the indeps UI. */
  createViewer
} from "indeps";

(async () => {
  // Get the raw data of the "package.json" file
  const pkgData = fs.readFileSync("/path/to/package.json", "utf8");

  // Parse raw data using `parsePkg`
  const pkg = parsePkg({
    data: pkgData
  });

  // Get the raw data of the lockfile
  const lockData = fs.readFileSync(
    "/path/to/package-lock.json", // or `yarn.lock`
    "utf8"
  );

  // Parse using `parseLock`
  const lock = parseLock({
    type: "yarn",
    data: lockData
  });

  // create a DAG from the packages specified in the lockfile. This is used to determine the require path - or dependency tree - of each module.
  const graph = createDependencyGraph(lock);

  // Normalize & hydrate all of the necessary data into a complete dependency list.
  const data = createDependencyData({
    lock,
    pkg,
    graph
  });

  // create the viewer instance. The viewer is responsible for running a local HTTP server and serving the indeps UI.
  const viewer = createViewer({
    data,
    port: 8008,
    packageName: parsedPkg.name,
    open: true
  });

  // start the server. Returns a node HTTP server instance (`node.httpServer`).
  const server = await viewer.startServer();
})();

Current focus is CLI usage - the exported methods will be expanded to be more usable & extendable as we reach closer to v1.0.0.

(back to top)

Roadmap

Status Milestone
๐Ÿš€ Implement NPM & Yarn V2 (berry) support
๐Ÿšง Improve dependency list UI
๐Ÿšง Create dependency graph/treemap visualization capabilities
๐Ÿšง Static site generation
๐Ÿšง Rewrite of method exports, plugin & theme support

See the open issues for a full list of proposed features (and known issues).

(back to top)

License

Distributed under the MIT License. See LICENSE.txt.

(back to top)

indeps's People

Contributors

ben-kincaid avatar

Stargazers

 avatar Vitor Fernandes avatar

Watchers

 avatar

indeps's Issues

Migrate Yarn 1 lexer/parser to use `@yarnpkg/lockfile`

During the creation of the node lib, a custom lexer + parser was created to parse Yarn 1's non-standard YAML syntax. There were two reasons for this:

  1. I was curious and wanted to try writing my own parser/lexer
  2. We could customize the parser/lexer to only include logic that was needed by the app
  3. open-source Yarn 1 parsers were sparse, and were often not well supported or very old/deprecated.

However, these lexers and parsers and pretty elementary, and add a lot of test overhead. Delegating this parser logic to an external library will allow us to not worry about testing the individual lexer/parser, and offloads the responsibility for testing & specification changes to a third-party package.

@yarnpkg/lockfile was originally not considered as it has been a while since it has been updated. After more consideration, this is most likely fine as the Yarn 1 lock file syntax has stayed stable, and assumingly yarn uses this tool internally to build the applications dependency tree.

Let's move forward with replacing our custom Yarn 1 parser/lexer with @yarnpkg/lockfile. This should probably coincide with the work done for #26.

Optimize client bundle size

Currently, the bundle size for the client is ~1.3mb.

We should aim to get this client bundle as small as possible. Target size is around 300kb.

Show requiring package for sub-dependencies

In the dependency list, we do not show any indication on the sub-dependency item dropdown for what package is responsible for requiring it in the projects dependency tree.

Some indication in the dropdown should be added for displaying the name(s) of the requiring packages for that specification version.

Add package-lock.json support

Up until now, i have only focused on Yarn 1/Yarn 2 lockfiles and have not yet implemented support for package-lock.json. This is primarily because I wanted to try my hand at rolling my own lexer & parser for Yarn 1 lockfiles (this will most definitely eventually be refactored to use @yarnpkg/lockfile). I also wanted to start on the client as soon as possible, which helped with figuring out a lot about the final data schema that needed to be created on the backend and ingested by the client.

Before public release with v0.1.0, we must add support for parsing the package-lock file and inject the outputted ParsedData.

Complete `README.md` for `v0.1.0`

The README must be updated with relevant install & usage information pertinent to v0.1.0.

Installation instructions should be given.
Usage should include instructions for both the CLI and the exported method.
Documentation should be given for both the possible CLI options as well as the parameters accepted by the default export method.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.