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

freezircular

v1.5.0

Published

A script to prevent new circular dependencies from being added

Downloads

57

Readme

Freezircular

Freezircular is a tool to detect circular dependencies in your code. It keeps track of which circular dependencies were there before, and which are new. The main motivation for this tool is to prevent new circular dependencies from being added to a codebase.

Freezircular keeps a baseline of circular dependencies in your codebase - you can either set it up to prevent new circular dependencies from being added to a codebase, or to just prevent any circular dependencies whatsoever from being added.

To run it, invoke npx freezircular - it will let you know if any new circular dependencies are added while ignoring previously existing ones.

Setup

Settings

Make sure to set up the settings in your package.json file, on a property called freezircular. The entryPath for your app is the most important bit.

   "freezircular": {
        "entryPath": "src/index.ts",
        "autoAddDeps": true,
        "previousDepsPath": ".freezircularDeps",
        "verbose": true,
        "tsConfig": "tsconfig.json"
   },
  • entryPath: starting point for your application, typically index.ts, src/index.ts, src/App.tsx or something like that. If it's not set, Freezircular will look for an index file and if it can't find one, it will fail.

  • autoAddDeps: whether the .freezircularDeps, which keeps track of previous circular dependencies, should be added to git via git add after every change to circular dependencies. Defaults to true.

  • previousDepsPath: path to the file which contains the previous baseline for circular dependencies. Normally you won't need to modify the default. Defaults to .freezircularDeps.

  • verbose: whether to show a message whenever there are no new circular dependencies introduced. Defaults to true.

  • tsConfig: route to your tsconfig.json file, if you're using TS. If it's not set, freezircular will try to use a tsconfig.json file if it finds one, otherwise it'll be ignored.

Establish a baseline

If you are setting up Freezircular on a codebase which already has circular dependencies on it, you should let Freezircular know that there are some old ones by creating a baseline. To do this, run Freezircular with the --baseline parameter:

npx freezircular --baseline

This will store the information of your circular deps in the file specified in previousDepsPath (by default, .freezircularDeps). Freezircular will take care of updating this file as circular dependencies get removed.

Pre-commit hook

Finally, it's suggested to set Freezircular up as a pre-commit hook, e.g., using husky:

npx husky add .husky/pre-commit "npx freezircular"

Execution will fail (i.e., the commit will be aborted) if Freezircular detects any new circular dependencies, but any previously existing circular dependencies will be ignored.