jscycles 0.2.0

Find circular imports between files and workspace packages in JavaScript and TypeScript projects
Documentation

CI crates.io License: MIT OR Apache-2.0

Find circular imports in JavaScript and TypeScript projects, between files within a package and between the packages of a monorepo.

jscycles is a single native binary. It parses every file with tree-sitter, resolves imports the way TypeScript does (path aliases, extends, declaration files, .js specifiers that point at .ts sources), and understands npm, yarn, pnpm and bun workspaces. On the public repositories measured below it runs 5 to 25 times faster than madge and dpdm.

Documentation: jscycles.dev

Built with an AI coding assistant and checked hard: see Is this AI slop?

$ jscycles packages
✓ No inter-package cycles

✗ @ts-morph/common: 2 cycles
  src/collections/SortedKeyValueArray.ts -> src/utils/index.ts -> … -> src/collections/SortedKeyValueArray.ts
  src/typescript/index.ts -> src/typescript/tsInternal.ts -> src/typescript/index.ts

✗ ts-morph: 3 cycles
  …
  src/Project.ts -> src/ProjectContext.ts -> src/Project.ts

Summary: 3 packages, 2 with file cycles (5 total), 0 inter-package cycles

Install

npm install --save-dev jscycles   # or pnpm, yarn, bun
npx jscycles

The npm package runs a prebuilt native binary for Linux (x86-64, ARM64; static, so Alpine too), macOS (Intel, Apple Silicon) or Windows (x86-64), chosen through optional dependencies; nothing runs at install time. The same binaries are attached to each GitHub release with a SHA256SUMS file, and cargo install jscycles --locked builds it from source (Rust 1.93 or newer). See install.

Quick start

Run it at the root of a repository:

jscycles                      # every package under the current directory
jscycles packages/core        # one directory
jscycles --only "@myorg/*"    # packages whose name matches a glob
jscycles --inner              # file cycles only
jscycles --outer              # package cycles only
jscycles --skip-type-imports  # leave out imports that only carry types
jscycles --json > cycles.json # machine-readable report

The exit status is 0 when no cycle is found, 1 when cycles are found, and 2 on any error (bad configuration, unreadable files, syntax errors, resource limits). A failed scan never reports clean, so in CI a single step is enough:

- run: npx jscycles

Documentation

The full documentation is at jscycles.dev:

Command line

Usage: jscycles [OPTIONS] [paths]...

Arguments:
  [paths]...  Paths to check (if empty, uses config scan paths)

Options:
      --only <only>              Only check packages matching glob pattern (can be repeated)
      --exclude <exclude>        Exclude packages matching glob pattern (can be repeated)
      --extensions <extensions>  File extensions to analyze [default: ts,tsx,mts,cts,js,jsx,mjs,cjs]
      --tsconfig <tsconfig>      Path to tsconfig.json
      --no-tsconfig              Skip tsconfig.json auto-detection
      --skip-type-imports        Ignore type-only imports (import type, export type, declaration files)
      --json                     Output as JSON
      --stdin                    Read paths from stdin
  -c, --config <config>          Path to config file [default: jscycles.yaml]
  -q, --quiet                    Only output if cycles found
      --inner                    Show only file-level (inner) cycles
      --outer                    Show only package-level (outer) cycles
  -v, --verbose                  Show all packages (including clean) and file-level details
  -h, --help                     Print help
  -V, --version                  Print version

Performance

Median of five runs after one warm-up, on an Apple M3 Pro (12 cores) running macOS, analyzing each repository's packages directory with every source extension enabled:

Repository Source files jscycles 0.2.0 madge 8.0.0 dpdm 3.14.0
nest 1,068 0.08 s 2.04 s 0.86 s
typeorm 3,609 0.28 s 2.97 s 1.48 s
excalidraw 631 0.11 s 2.63 s 0.87 s
ts-morph 1,171 0.08 s 1.64 s 0.83 s

The tools count cycles differently (see how it works), so their cycle counts are not comparable. Reproduce with python3 scripts/compare_tools.py; results depend on hardware and file cache.

Library

jscycles is also a Rust library (docs.rs): package discovery, import extraction, resolution and cycle detection are public. The command-line tool in src/main.rs shows how to combine them. In particular, pass the boundaries from PackageDiscovery::discover_with_boundaries to ImportExtractor::with_nested_packages and with_owners, so each file is analyzed by its nearest package. Library changes for 0.2 are in the upgrade notes.

Contributing

The most useful contribution is a bug report with a small project that reproduces it; see CONTRIBUTING.md for building, testing and the differential test harness. Please report security issues privately, as described in SECURITY.md.

License

Licensed under either of Apache License 2.0 or MIT license at your option. Contributions are accepted under the same terms.