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

refcycle

v2.0.1

Published

ordonnancement of import in a typescript project

Downloads

1

Readme

Cyclic reference detection

Intro

This application is meant to solve circular dependencies issues. To do so, it will scan hard dependencies

hard dependencies -> dependencies that need to be resolved during the parse of the module (i.e. every thing imported that is in the global scope of the file):

  • A reference to a class, function or variable in the global scope
  • An inheritance to a class
  • An initialized static variable
  • a decorator and its parameters

If theses hard dependencies form a DAG, then it extracts a topological order for the loading of the modules. Otherwise, throw "cyclic graph of hard dependencies" exception. This order can be stored in a namespace (a file containing all the import), or inside each module (the loading order is not ensured).

Remark

Detecting which dependencies are needed to form the global scope can be reduced to the halting problem (impossible in the general case). So this library look only top level declaration. If a function is called from the global scope, its body is not analyzed.

class A { static b: B } // global scope depends B

function AMixin() { return class { static b: B}; }
const A = AMixin(); // global scope doesn't depend on B as content of `AMixin` in not scanned

Execute

Backup your files before executing this command.

```bash
npm run start -- <tsConfigPath> <globalNamespacePath> <format> [graphHardDependenciesPath]
```
  • tsConfigPath (required): the full path of the tsconfig.json (or tsconfig.app.json) of the project. The file must exist
  • globalNamespacePath (required): the full path of the file that will order the imports
  • format (required): format imports in each file (Experimental, set it to false if unsure)
  • graphHardDependenciesPath (optional): if there are some cycles in the graph of hard dependencies, this program will generate a .gml file highlighting the strongly connected component that you must break. .gml file can be opened with yEd.

yEd

to display the graph :

  1. select all node (ctrl+a)
  2. Tools -> fit Node to Label
  3. Layout -> Organic -> Preferred Edge Length: 125

Note

  • internal import must be relative i.e.
    • import { Document } from "src/toto" Not OK
    • import { Document } from "./src/toto" OK
  • the dependencies of the target project must be installed (with npm instal for example).
  • if you get a [warning], correct the import so that it import the globalNamespace and not directly a file