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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@basemachina/bm-action-dep-parser

v0.1.0

Published

BaseMachina アクション依存関係解析ツール

Readme

bm-action-dep-parser

BaseMachina アクション依存関係解析ツール

概要

このツールは、BaseMachinaのJavaScriptアクションとビューのコードを静的解析して、各ファイルがどのアクションに依存しているかを特定します。

注意: このプロジェクトは、ビューやJavaScriptアクションが構造化されたディレクトリに配置されていることを想定しています。例えば以下のようなディレクトリ構造を前提としています。 必ずしもこちらと同じにする必要はありませんが、ビューやJavaScriptアクションのエントリーポイントが明確になるようにしてください。

project/
├── actions/
│   └── js/
|       └── sampleAction.js
└── views/
    ├── components/
    │   └── SortableForm.tsx
    └── pages/
        ├── SortableFormPage.tsx
        └── paginatedTable/
            └── index.tsx

機能

  • 解析対象(JSアクションかビューか)と対象ディレクトリを指定可能
  • 各ファイルごとに依存しているアクションの識別子をリストアップ
  • アクション呼び出し関数(executeAction, useExecuteAction, useExecuteActionLazy)を検出
  • 変数に格納されたアクション識別子も検出
  • JSON形式で結果を出力
  • ビューのエントリーポイント分析: ビューのエントリーポイントから直接・間接的に依存しているすべてのアクションを可視化(ビューは常にエントリーポイント分析モード)
  • カスタムエントリーポイントパターン: エントリーポイントを柔軟に指定可能(デフォルトは pages/**/*.{tsx,jsx,ts,js}*.{tsx,jsx,ts,js} で、ネスト構造とフラット構造の両方に対応)
  • アクション識別子によるフィルタリング: 特定のアクションに依存するビューやアクションのみを抽出し、変更影響範囲の分析を効率化

出力例

 npx @basemachina/bm-action-dep-parser view ./bm-action-dep-parser/tests/fixtures/views 
[
  {
    "entrypoint": "pages/SortableFormPage.tsx",
    "dependencies": {
      "direct": [],
      "indirect": {
        "components/SortableForm.tsx": [
          "get-products",
          "update-category"
        ]
      }
    }
  },
  {
    "entrypoint": "pages/paginatedTable/index.tsx",
    "dependencies": {
      "direct": [
        "get-users"
      ],
      "indirect": {}
    }
  }
]

使用方法

CLIツールとして使用

npx @basemachina/bm-action-dep-parser action ./packages/actions/js
npx @basemachina/bm-action-dep-parser view ./packages/views

オプション

# カスタムエントリーポイントパターンを指定(ビューの場合のみ)
npx @basemachina/bm-action-dep-parser view ./packages/views --entry-point-patterns "**/*.tsx"

# 特定のアクションに依存するビューのみを抽出
npx @basemachina/bm-action-dep-parser view ./packages/views --filter-action get-users

# 複数のアクションでフィルタリング(OR論理)
npx @basemachina/bm-action-dep-parser view ./packages/views --filter-action get-users,update-category

# アクション解析でもフィルタリング可能
npx @basemachina/bm-action-dep-parser action ./packages/actions/js --filter-action base-action

# ヘルプを表示
npx @basemachina/bm-action-dep-parser --help

フィルタリング機能の使用例

特定のアクションの変更影響範囲を分析する場合:

# get-usersアクションに依存するビューを特定
npx @basemachina/bm-action-dep-parser view ./packages/views --filter-action get-users

# 出力: get-usersを直接または間接的に使用するビューのみが表示される
[
  {
    "entrypoint": "pages/UserListPage.tsx",
    "dependencies": {
      "direct": ["get-users"],
      "indirect": {}
    }
  }
]

存在しないアクション識別子を指定した場合、警告メッセージが標準エラー出力に表示されます:

Warning: Action identifier 'nonexistent-action' not found in dependency graph
No dependencies found for the specified action identifier(s)
[]

ローカルでの実行

pnpm run analyze action ./packages/actions/js
pnpm run analyze view ./packages/views

技術詳細

このツールは以下のモジュールで構成されています:

  1. index.ts: メインエントリーポイント
  2. cli.ts: コマンドラインインターフェース
  3. analyze-action-dependencies.ts: メイン解析ロジック
  4. lib/file-finder.ts: ファイル検索モジュール
  5. lib/code-analyzer.ts: コード解析モジュール(TypeScript Compiler API使用)
  6. lib/dependency-extractor.ts: 依存関係抽出モジュール
  7. lib/result-formatter.ts: 結果出力モジュール(JSON形式)
  8. lib/dependency-graph-builder.ts: ビュー依存関係グラフ構築モジュール
  9. lib/action-dependency-graph-builder.ts: アクション依存関係グラフ構築モジュール
  10. lib/entry-point-analyzer.ts: エントリーポイント解析モジュール
  11. lib/dependency-filter.ts: 依存関係フィルタリングモジュール(アクション識別子による逆引き検索)

TypeScriptのコンパイラAPIを使用してコードを解析し、アクション呼び出しを検出しています。エントリーポイント分析では、ファイル間の依存関係も解析して、間接的なアクション依存関係も検出します。