Class: Archsight::Import::Handlers::JavaScriptGrapher
- Inherits:
-
Grapher
- Object
- Archsight::Import::Handler
- Grapher
- Archsight::Import::Handlers::JavaScriptGrapher
- Defined in:
- lib/archsight/import/handlers/javascript_grapher.rb
Overview
JavaScriptGrapher — analyses a JavaScript or TypeScript repository and generates a GraphViz DOT graph of its package/module structure, stored as architecture/javascript/modules on the TechnologyArtifact.
Covers .js, .mjs, .cjs, .ts, .tsx, .jsx (single grapher for both JS and TS).
Supported project layouts:
- Single package (package.json at root)
- NPM / Yarn workspaces ("workspaces" key in root package.json)
- PNPM workspaces (pnpm-workspace.yaml)
- Lerna (lerna.json)
- Nx / Turborepo (nx.json / turbo.json — scan direct subdirs)
Import resolution:
- Relative imports (./foo, ../bar)
- TypeScript tsconfig.json path aliases (@/utils → src/utils)
- Cross-workspace package imports (@company/shared → module root)
- "import type" lines are ignored (no runtime dependency)
Configuration:
import/config/path - Path to the repository root
import/config/ranksep - Horizontal gap between rank columns (default: 0.6)
import/config/nodesep - Vertical gap between nodes in a column (default: 0.15)
Constant Summary collapse
- SKIP_DIRS =
%w[node_modules dist build .next .nuxt out .turbo .nx .cache coverage .git test tests __tests__ __mocks__ e2e cypress playwright .storybook storybook-static fixtures temp tmp].freeze
- SOURCE_EXTS =
%w[.ts .tsx .js .jsx .mjs .cjs].freeze
- MAX_PKG_DEPTH =
Packages with more than this many path components are folded into their ancestor. Two levels gives mod_name/feature — matching Java and Ruby conventions.
2- FROM_RE =
/\bfrom\s+["']([^"'\n]+)["']/- REQUIRE_RE =
/\brequire\s*\(\s*["']([^"'\n]+)["']\s*\)/- DYNAMIC_RE =
/\bimport\s*\(\s*["']([^"'\n]+)["']\s*\)/- TYPE_RE =
/\bimport\s+type\b/
Constants inherited from Grapher
Instance Attribute Summary
Attributes inherited from Archsight::Import::Handler
#database, #import_resource, #progress, #resources_dir, #shared_writer
Class Method Summary collapse
Instance Method Summary collapse
Methods inherited from Grapher
#dot_graph, #execute, #safe_glob
Methods inherited from Archsight::Import::Handler
#compute_config_hash, #config, #config_all, #execute, #import_yaml, #initialize, #resource_yaml, #resources_to_yaml, #self_marker, #write_generates_meta, #write_yaml
Constructor Details
This class inherits a constructor from Archsight::Import::Handler
Class Method Details
.applicable?(path) ⇒ Boolean
34 35 36 37 |
# File 'lib/archsight/import/handlers/javascript_grapher.rb', line 34 def self.applicable?(path) File.exist?(File.join(path, "package.json")) || Dir.glob(File.join(path, "*/package.json")).any? end |
.language_name ⇒ Object
32 |
# File 'lib/archsight/import/handlers/javascript_grapher.rb', line 32 def self.language_name = "javascript" |
Instance Method Details
#wrap_single_module? ⇒ Boolean
39 40 41 |
# File 'lib/archsight/import/handlers/javascript_grapher.rb', line 39 def wrap_single_module? true end |