@reponova/lang-json
v0.4.0
Published
JSON / JSONC support for RepoNova with schema-aware extraction (package.json, tsconfig*, nx.json, project.json)
Maintainers
Readme
@reponova/lang-json
JSON / JSONC support for RepoNova. Schema-aware: recognises the canonical configuration files of the JS/TS ecosystem (package.json, tsconfig*, nx.json, project.json, lerna.json, turbo.json) and surfaces them as first-class graph entities. Falls back to a generic top-level-keys-as-symbols extraction for everything else. Backed by Microsoft's jsonc-parser — no tree-sitter grammar required, JSONC syntax (// line comments, /* … */ block comments, trailing commas) is supported transparently for every file shape.
Install
reponova lang add @reponova/lang-jsonWhat it extracts
- Symbols:
package.json— the package'snameas aconstant(sograph_searchagainst the package name resolves to the file), everyscripts.*as afunction(the shell command becomes the docstring), everybinentry (string AND map form) as afunction.tsconfig*.json— surfaces structural metadata only viaimports/ file-level tags; no per-key symbol noise.nx.json—targetDefaults.*asfunctionsymbols (executor / command in the docstring),namedInputs.*asvariablesymbols.project.json(Nx) —targets.*asfunctionsymbols (executor / command in docstring),tags[]asvariablesymbols (so Nx scope rules likescope:auth/type:libbecome graph facets).turbo.json—pipeline.*(Turbo 1) ANDtasks.*(Turbo 2) asfunctionsymbols.- Generic JSON / JSONC (anything that doesn't match a known schema) — top-level keys as
variablesymbols, capped to the configuredmaxGenericKeys(default200, see Configuration).
- Decorators: every symbol carries a single decorator describing its provenance —
npm-script,npm-bin,package-name,nx-target,nx-target-default,nx-named-input,nx-tag,turbo-task,json-key. This lets downstream queries filter by source schema. - Edges:
- Imports:
dependencies/devDependencies/peerDependencies/optionalDependenciesfrompackage.json(each carries<dep>@<spec>innames[0]); tsconfigextends(string AND TS 5.0 array form) andreferences[].path;compilerOptions.paths.<alias>expanded into one import per target with the alias preserved innames[0](wildcard aliases carryisWildcard: true); npmworkspaces(array form AND{ packages: [...] }form),lerna.jsonpackages[], andturbo.jsonextends[]; Nxplugins[](string AND{ plugin, options }forms) andgenerators.*. - References: Nx
project.jsonimplicitDependencies[]asreferencesedges from the project to each declared dependency.
- Imports:
- File docstring: the package / generic-JSON
descriptionfield, when present. - File-level tags:
package.json(always),privateandworkspaces(when set on apackage.json);tsconfig,extends,project-references;nx,monorepo;nx-project,nx-application/nx-library;lerna,turborepo; plainjsonfor the generic fallback. - File node kind:
module.
Extensions
.json, .jsonc
The schema kind is detected from the basename (case-insensitive, Windows path separators normalised). Custom-suffix tsconfig files (tsconfig.spec.json, tsconfig.lib.json, tsconfig.<anything>.json) are recognised as tsconfig.
Configuration
In reponova.yml:
plugins:
json:
enabled: true # default: true
maxGenericKeys: 200 # default: 200 — cap on generic-fallback symbols per file
# patterns: [] # override global patterns for JSON files
# exclude: [] # override global exclude for JSON files| Property | Type | Default | Description |
|----------|------|---------|-------------|
| enabled | boolean | true | Enable/disable JSON file detection and extraction |
| maxGenericKeys | number | 200 | Cap on top-level keys surfaced as variable symbols for files that fall into the generic fallback (no recognised schema). Stops large data dumps / translation tables / lookup files from creating thousands of nodes. The cap does NOT apply to schema-recognised files (package.json, tsconfig*, nx.json, project.json, …) which are already structured. Set to a large number (or Infinity) to disable. |
| patterns | string[] | [] | Glob patterns to override global file matching for this plugin |
| exclude | string[] | [] | Glob patterns to override global exclusions for this plugin |
maxGenericKeys is also accepted as a constructor option for callers that consume the plugin programmatically:
import { JsonExtractor } from "@reponova/lang-json";
const ext = new JsonExtractor({ maxGenericKeys: 500 }); // raise the cap
// or
const ext = new JsonExtractor({ maxGenericKeys: Infinity }); // disable entirelyResolution semantics
- Relative tsconfig-style specs (
extends,references[].path,pathsaliases) resolve against the importing file's directory:"./foo.json"fromapps/web/tsconfig.json→apps/web/foo.json. Path traversal (../) and./are normalised. - The
.jsonextension is appended when the spec lacks one:"../shared/base"fromapps/web/tsconfig.json→apps/shared/base.json. - Directory-style references (
"./libs/core") also offer the implicitlibs/core/tsconfig.jsoncandidate so directory-style references resolve to the directory's tsconfig. - Bare specifiers (
react,@tsconfig/node20/tsconfig.json, workspace package names) return[]and are treated as external.node_moduleswalks,package.jsonexportsfield rewriting, and workspace alias resolution are deliberately delegated to RepoNova's upstream import resolver — this plugin only handles relative-path semantics. - The
binfield onpackage.jsonaccepts both the single-string form ("bin": "./cli.js"— the synthesised symbol takes the package's short name) and the map form ("bin": { "tool-a": "./a.js", "tool-b": "./b.js" }— one symbol per entry). - The
privateflag onpackage.jsonis recognised as both the canonical JSON boolean ("private": true) and the legacy string form ("private": "true") some hand-edited files use. - Comments inside JSON files are NOT preserved as symbol docstrings — only the structured
description/ per-script command body fields are surfaced. Trailing commas and JSONC comments do not break parsing in any file (includingpackage.json, although strict tooling like npm itself does not accept them there). - The schema-detection step is filename-only: a
package.jsonplaced at/data/package.jsonis still extracted as a package even if its content is not a real npm manifest. If the content is malformed JSON, the parser tolerates partial recovery and the extractor surfaces whatever it could parse without throwing.
License
MIT — see LICENSE.
