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

@yukinotech/mobius

v1.0.6

Published

find all circular dependency for typescript

Downloads

2

Readme

MOBIUS

make find all circular dependency in typescript easy

support:

  • now only support typescript witch use import instead of require()
  • typescript alias
  • auto ignore typescript import type

usage

cli

install

npm i -g @yukinotech/mobius

find circular dependency

mobius run [my-project-dir-path] -t [my-project-tsconfig.json-path]

e.g

cd my-project //  my-project is a typescript project
mobius run ./ -t ./tsconfig.json -m typescript

get help from cli

mobius help [command]

e.g

=> mobius help run

Usage: mobius run [options] <codeDirPath>

Run a script

Options:
  -d, --debug                    Enable debugging
  -e, --exclude <exclude files>  exclude file
  -t, --tsConfigPath <path>      Path to tsconfig.json
  -m, --mode <mode type>         mode type "typescript"|"commonjs"|"esm"
  -s, --thread <threads>         thread number
  -h, --help                     display help for command

some tips for using cli

mixed project

In most projects, apart from the source code, there are many non-source code components, such as tests.

Here is an example: ./src contains TypeScript code and ./test contains commonjs code.

my-node-project/
│
├─ src/
│  ├─ index.ts
│  ├─ utils/
│  │  ├─ helper.ts
│  │  └─ constants.ts
│  └─ routes/
│     ├─ api.ts
│     └─ web.ts
│
├─ test/
│  ├─ unit/
│  │  ├─ test-helper.js
│  │  └─ index.test.js
│  └─ integration/
│     ├─ api.test.js
│     └─ web.test.js
│
├─ package.json
├─ tsconfig.json
├─ README.md
└─ .gitignore

Usually, we just want to check whether there are circular dependencies in the source code

In reference to the example above: it is preferable to set <codeDirPath> as ./my-node-project/src, if you just want to check only within the source code. And since ./src contains TypeScript code. You can use cli like this:

cd my-node-project
mobius run ./src -t ./tsconfig.json -m typescript

Just run for src can be more faster.

And for ./test,if you also want to to check whether there are circular dependencies in it,just run

cd my-node-project
mobius run ./test -m commonjs

If the -m parameter is not provided like just use mobius run ./ in project like this, the program might produce confusing results.

for typescript

why tsconfig.json is import

Q: why need a tsconfig.json? A: because typescript may have alias for path just like

tsconfig.json

"paths": {
  "components/*": ["components/*"]
}

According to the tsconfig.json, the program can determine that the actual path of @components/bridge is project-path/components/bridge

import bridge from '@components/bridge'
How to avoid circular dependency interference caused by having only type files

A file which only import and export type and interface can be ignored in a circular dependency loop

You can use import type to ignore just like

import type { Locale } from './locale/interface'

instead of

import { Locale } from './locale/interface'

mobius will ignore files that are only imported for type definitions

Perhaps mobius might support automatic inference in the future, but this could significantly increase the program's overhead.

Another way to ignore is to add ignore file with -e to exclude files.

mobius run ./ -t tsconfig.json -e ./src/interface.ts,./src/types

module

npm i @yukinotech/mobius
import mobius from '@yukinotech/mobius'

const main = async() => {
  const circleList = await mobius({
    tsConfigPath: '/Users/xxxx/workspace/project-name/tsconfig.json'
    projectDir: '/Users/xxxx/workspace/project-name'
    threadNum: 6 // make run with multiple thread
    mode: 'typescript',
    exclude: ['/Users/xxxx/workspace/project-name/test','/Users/xxxx/workspace/project-name/script']
  })
}

RoadMap

  • optimizing CLI interaction
  • auto find and analysis tsconfig
  • support nodejs esm
  • -e support glob token