Graph
The Graph tool build’s on oneRepo’s powerful Workspace Graph by adding a Workspace & Workspace file validator and a Graph visualizer.
Configuration
Section titled ConfigurationThe one graph verify
command comes with some basic schema for validating package.json
files and no configuration is required.
However, you can enhance this by providing custom schema to match to workspaces and their files:
Commands
Section titled Commandsone graph
Section titled one graphRun core Graph commands
one graph show
Section titled one graph showShow this repository’s Workspace Graph using an online visualizer or output Graph representations to various formats.
This command can generate representations of your Workspace Graph for use in debugging, verifying, and documentation. By default, a URL will be given to visualize your Graph online.
Pass --open
to auto-open your default browser with the URL or use one of the --format
options to print out various other representations.
Option | Type | Description |
---|---|---|
--affected | boolean | Select all affected Workspaces. If no other inputs are chosen, this will default to true . |
--all, -a | boolean | Run across all Workspaces |
--format, -f | "mermaid" , "plain" , "json" | Output format for inspecting the Workspace Graph. |
--open | boolean | Auto-open the browser for the online visualizer. |
--staged | boolean | Use files on the git stage to calculate affected files or Workspaces. When unset or --no-staged , changes will be calculated from the entire branch, since its fork point. |
--workspaces, -w | array | List of Workspace names to run against |
Advanced options
Option | Type | Description |
---|---|---|
--from-ref | string | Git ref to start looking for affected files or Workspaces |
--through-ref | string | Git ref to start looking for affected files or Workspaces |
--url | string , default: "https://onerepo.tools/visualize/" | Override the URL used to visualize the Graph. The Graph data will be attached the the g query parameter as a JSON string of the DAG, compressed using zLib deflate. |
Print a URL to the online visualizer for the current affected Workspace Graph.
Open the online visualizer for your full Workspace Graph.
Generate a Mermaid graph to a file, isolating just the given <workspaces...>
and those that are dependent on it.
one graph verify
Section titled one graph verifyVerify the integrity of the repo’s dependency Graph and files in each Workspace.
This command will first validate dependencies across Workspace Graph trees using the given --mode
as well as Workspace configuration file integrity using the repo’s defined JSON schema validators.
Dependencies across Workspaces can be validated using one of the various modes:
off
: No validation will occur. Everything goes.loose
: Reused third-party dependencies will be required to have semantic version overlap across unique branches of the Graph.strict
: Versions of all dependencies across each discrete Workspace dependency tree must be strictly equal.
Option | Type | Description |
---|---|---|
--mode | "strict" , "loose" , "off" , default: "loose" | Dependency overlap validation method. |
Advanced options
Option | Type | Description |
---|---|---|
--custom-schema | string | Path to a custom JSON schema definition |
Verifying configurations
Section titled Verifying configurationsThe one graph verify
command in oneRepo has support for validating most configuration files in workspaces, including JSON, CJSON, YAML, and static JavaScript/TypeScript configurations.
Schema validation uses AJV with support for JSON schemas draft-2019-09 and draft-07. It also supports ajv-errors for better and more actionable error messaging.
Examples
Section titled ExamplesJSON validation
Section titled JSON validationJS/TS config validation
Section titled JS/TS config validationNote that if the configuration is the default export, like in the case of jest.config.js
files, you will need set the export name property or properties to validate. To validate the default
export use the property name default
.
Functional schema
Section titled Functional schemaThere are cases where more information about a workspace is needed for the schema to be complete. For this, the schema may also be a function that accepts two arguments, workspace
and graph
:
Base schema
Section titled Base schemaoneRepo provides a base schema with some defaults for private & public package.json
files. If the provided schema are not to your liking, you can override with the location glob '**'
:
Schema extensions
Section titled Schema extensionsRequired files
Section titled Required filesTo mark a file as required, the JSON schema validation has been extended to include a key $required
at the top level of each file schema. Setting this key to true
will result in errors if a matched workspace does not include this file: