Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

ts-graphviz

ts-graphviz2.1mMIT2.1.6TypeScript support: included

Graphviz library for TypeScript

graphviz, dot

readme

License: MIT PRs Welcome CI All Contributors

OpenSSF Best Practices OpenSSF Scorecard Tidelift

npm version node version deno version npm

ts-graphviz

Graphviz library for TypeScript.

🔗

GitHub npm yarn Refarence

Sponsor OpenCollective

format: Biome test: Vitest build: Vite


Key Features ✨

ts-graphviz package provides models and ASTs for the Graphviz DOT language fully integrated with TypeScript.

  • TypeScript-friendly API
    • It provides models in the DOT language. TypeScript type definitions are also provided for attributes and even attribute types.
  • Freedom from programming paradigms
    • Designed to be object-oriented, it provides APIs that can be adapted to both imperative and declarative APIs. You can choose the paradigm that best fits your project.
  • Suitable for any use cases
    • Both a high-layer API to provide models and a low-layer API to handle ASTs are provided to address any use cases.
  • Modular and Extensible
    • The library is split into multiple packages, each serving a specific purpose. This modular design allows users to pick and choose the functionality they need, resulting in improved maintainability and flexibility.
  • Cross Platform
    • It supports both Node.js and Deno and Browser.
  • Customizable
    • It provides a way to extend the library's type system to customize graph visualization solutions to meet specific needs.

Installation 💽

Node.js

This package can then be installed using a package manager.

# npm
$ npm install -S ts-graphviz
# or yarn
$ yarn add ts-graphviz
# or pnpm
$ pnpm add ts-graphviz

Note Want to try before installing? Check out Runkit to see how it works.

Deno 🦕

Deno v1.28 and above supports npm.

You can install and use the package by specifying the following:

import { toDot } from 'npm:ts-graphviz';

Usage 📑

This section provides an overview of the package.

For more detailed API specifications, please refer to the comments in the TypeScript type definitions and the document automatically generated based on them.

ts-graphviz Module 🚩

This module provides Model, an interface for working with the DOT language in JavaScript/TypeScript.

ts-graphviz

Object-Oriented ❤️

Model is designed to be object-oriented and provides classes Digraph, Graph, Subgraph, Node, and Edge.

Provides a toDot function to convert Model to DOT (DOT language string).

import { attribute as _, Digraph, Subgraph, Node, Edge, toDot } from 'ts-graphviz';

const G = new Digraph();
const A = new Subgraph('A');
const node1 = new Node('node1', {
  [_.color]: 'red'
});
const node2 = new Node('node2', {
  [_.color]: 'blue'
});
const edge = new Edge([node1, node2], {
  [_.label]: 'Edge Label',
  [_.color]: 'pink'
});
G.addSubgraph(A);
A.addNode(node1);
A.addNode(node2);
A.addEdge(edge);
const dot = toDot(G);
// digraph {
//   subgraph "A" {
//     "node1" [
//       color = "red",
//     ];
//     "node2" [
//       color = "blue",
//     ];
//     "node1" -> "node2" [
//       label = "Edge Label",
//       color = "pink",
//     ];
//   }
// }
<summary>Advanced Usage</summary>
Custom Class 🤖

You can also add your own implementation by inheriting from the class.

import { Digraph, Node, Edge, EdgeTargetTuple, attribute as _, toDot } from 'ts-graphviz';

class MyCustomDigraph extends Digraph {
  constructor() {
    super('G', {
      [_.label]: 'This is Custom Digraph',
    });
  }
}
class MyCustomNode extends Node {
  constructor(id: string) {
    super(`node_${id}`, {
      [_.label]: `This is Custom Node ${id}`,
    });
  }
}

class MyCustomEdge extends Edge {
  constructor(targets: EdgeTargetTuple) {
    super(targets, {
      [_.label]: 'This is Custom Edge',
    });
  }
}

const digraph = new MyCustomDigraph();
const node1 = new MyCustomNode('A');
const node2 = new MyCustomNode('B');
const edge = new MyCustomEdge([node1, node2]);
digraph.addNode(node1);
digraph.addNode(node2);
digraph.addEdge(edge);
const dot = toDot(digraph);
// digraph "G" {
//   label = "This is Custom Digraph";
//   "node_A" [
//     label = "This is Custom Node A";
//   ];
//   "node_B" [
//     label = "This is Custom Node B";
//   ];
//   "node_A" -> "node_B" [
//     label = "This is Custom Edge";
//   ];
// }
Models Context API ( with method) 🧅

You can also use the Models Context API to create custom classes for objects generated inside of Graph.

The with methods of Digraph, Graph, and Subgraph, which are implementations of GraphBaseModel, are provided to predefine custom models.

const g = new Digraph();
g.with({
  Node: MyCustomNode,
  Edge: MyCustomEdge,
});
const a = g.createNode('A'); // MyCustomNode
const b = g.createNode('B'); // MyCustomNode
g.createEdge([a, b]); // MyCustomEdge
const dot = toDot(g);
// digraph {
//   "node_A" [
//     label = "This is Custom Node A";
//   ];
//   "node_B" [
//     label = "This is Custom Node B";
//   ];
//   "node_A" -> "node_B" [
//     label = "This is Custom Edge";
//   ];
// }
fromDot function ⏪

The status of this function is ! beta.

The main scenario for using this library is to use the toDot function, but it also supports conversions in the reverse direction.

By converting DOT to Model, a portion of the code can be written in the DOT language.

const G = fromDot(
  `digraph {
    node_A [
      label = "This is a Label of Node A";
    ];
  }`,
);

G.edge(['node_A', 'node_B']);

const dot = toDot(G)
// digraph {
//   "node_A" [
//     label = "This is a Label of Node A";
//   ];
//   "node_A" -> "node_B";
// }

Declarative API 😎

When creating Graph or Digraph, you can use Model Factory to provide a notation more similar to the DOT language.

Model also has a declarative API, so you can consistently choose a declarative paradigm.

import { attribute as _, digraph, toDot } from 'ts-graphviz';

 const G = digraph('G', (g) => {
  const a = g.node('aa');
  const b = g.node('bb');
  const c = g.node('cc');
  g.edge([a, b, c], {
    [_.color]: 'red'
  });
  g.subgraph('A', (A) => {
    const Aa = A.node('Aaa', {
      [_.color]: 'pink'
    });

    const Ab = A.node('Abb', {
      [_.color]: 'violet'
    });
    const Ac = A.node('Acc');
    A.edge([Aa.port('a'), Ab, Ac, 'E'], {
      [_.color]: 'red'
    });
  });
});

const dot = toDot(G);
// digraph "G" {
//   "aa";
//   "bb";
//   "cc";
//   subgraph "A" {
//     "Aaa" [
//       color = "pink",
//     ];
//     "Abb" [
//       color = "violet",
//     ];
//     "Acc";
//     "Aaa":"a" -> "Abb" -> "Acc" -> "E" [
//       color = "red",
//     ];
//   }
//   "aa" -> "bb" -> "cc" [
//     color = "red",
//   ];
// }

Note Of course, we also provide an API for creating strict mode graphs.

import { strict, toDot } from 'ts-graphviz';

const G = strict.graph(...);
const dot = toDot(G);
// strict graph {
// }
<summary>Advanced Usage</summary>
Models Context API ( withContext function ) 💈

The withContext function returns a Model Factory function.

This Model Factory provides a means to replace RootGraphModel with a custom class, such as Digraph or Graph.

This API provides a way to integrate declarative APIs and custom classes.

const { digraph } = withContext({
  Digraph: MyCustomDigraph,
  Node: MyCustomNode,
  Edge: MyCustomEdge,
});

const G = digraph((g) => {
  const a = g.node('A'); // MyCustomNode
  const b = g.node('B'); // MyCustomNode
  g.edge([a, b]); // MyCustomEdge
});
const dot = toDot(g);
// digraph "G" {
//   label = "This is Custom Digraph";
//   "node_A" [
//     label = "This is Custom Node A";
//   ];
//   "node_B" [
//     label = "This is Custom Node B";
//   ];
//   "node_A" -> "node_B" [
//     label = "This is Custom Edge";
//   ];
// }

@ts-graphviz/adapter Module 🔌

This module status is beta.

Provides an interface to run Graphviz dot commands.

Graphviz must be installed so that the dot command can be executed.

Execute the dot command to output a DOT language string to a stream or file.

Adapter State Machine

This module provides the following functions.

  • The toStream function converts DOT to Stream.

      import { toStream } from 'ts-graphviz/adapter';
    
      const dot = `
        digraph example {
          node1 [
            label = "My Node",
          ]
        }
      `;
    
      const stream = await toStream(dot, { format: 'svg' });
      // Node.js
      stream.pipe(process.stdout);
      // Deno
      await stream.pipeTo(Deno.stdout.writable);
  • Writes DOT to a file at the specified path toFile function

      import { toFile } from 'ts-graphviz/adapter';
    
      const dot = `
        digraph example {
          node1 [
            label = "My Node",
          ]
        }
      `;
    
      await toFile(dot, './result.svg', { format: 'svg' });

Note Designed to work with Node.js and Deno, Stream is runtime native.

@ts-graphviz/ast Module 🔢

This module status is beta.

An API is provided to handle ASTs for advanced use.

State Machine

The following functions are provided as described in the state transition diagram.

  • The fromModel function converts Model to AST.
  • The toModel function converts AST to Model.
  • The stringify function converts AST to DOT.
  • The parse function to convert from DOT to AST.

Note As you can see from the above figure, the toDot function provided by the ts-graphviz package is a composite of fromModel and stringify. The fromDot function is a composite of parse and toModel.

Detailed usage is TODO. Please refer to the TypeScript type definition.

<summary>The parse function and AST</summary>
import { parse } from '@ts-graphviz/ast';

const ast = parse(`
  digraph example {
    node1 [
      label = "My Node",
    ]
  }
`);
// {
//   type: 'Dot',
//   location: {
//     start: { offset: 3, line: 2, column: 3 },
//     end: { offset: 68, line: 7, column: 1 }
//   },
//   children: [
//     {
//       id: {
//         value: 'example',
//         quoted: false,
//         type: 'Literal',
//         location: {
//           start: { offset: 11, line: 2, column: 11 },
//           end: { offset: 18, line: 2, column: 18 }
//         },
//         children: []
//       },
//       directed: true,
//       strict: false,
//       type: 'Graph',
//       location: {
//         start: { offset: 3, line: 2, column: 3 },
//         end: { offset: 67, line: 6, column: 4 }
//       },
//       children: [
//         {
//           id: {
//             value: 'node1',
//             quoted: false,
//             type: 'Literal',
//             location: {
//               start: { offset: 25, line: 3, column: 5 },
//               end: { offset: 30, line: 3, column: 10 }
//             },
//             children: []
//           },
//           type: 'Node',
//           location: {
//             start: { offset: 25, line: 3, column: 5 },
//             end: { offset: 63, line: 5, column: 6 }
//           },
//           children: [
//             {
//               key: {
//                 value: 'label',
//                 quoted: false,
//                 type: 'Literal',
//                 location: {
//                   start: { offset: 39, line: 4, column: 7 },
//                   end: { offset: 44, line: 4, column: 12 }
//                 },
//                 children: []
//               },
//               value: {
//                 value: 'My Node',
//                 quoted: true,
//                 type: 'Literal',
//                 location: {
//                   start: { offset: 47, line: 4, column: 15 },
//                   end: { offset: 56, line: 4, column: 24 }
//                 },
//                 children: []
//               },
//               location: {
//                 start: { offset: 39, line: 4, column: 7 },
//                 end: { offset: 57, line: 4, column: 25 }
//               },
//               type: 'Attribute',
//               children: []
//             }
//           ]
//         }
//       ]
//     }
//   ]
// }

Extending the Type System 🧰

The status of this feature is beta.

With ts-graphviz, you can extend the library's type system to customize graph visualization solutions to meet specific needs.

Note To allow for customization, types are named with the $ symbol.

If you want to extend a type definition in cases not listed below, check the source code to see if you can extend it with $....

If not, please create an issue or pull request.

Use Case: Specifying Custom Graph Layout and Output Formats

import { $keywords } from '@ts-graphviz/common';
import { toFile } from '@ts-graphviz/adapter';

// 1. Declare the '@ts-graphviz/adapter' module.
declare module '@ts-graphviz/adapter' {
  export namespace Layout {
    // 2. Define the $values interface in the Layout namespace.
    // 3. Inherit from $keywords<'my-custom-algorithm'> and specify the name of the new layout engine in <...>.
    export interface $values extends $keywords<'my-custom-algorithm'> {}
  }

  export namespace Format {
    // 4. Define the $values interface in the Format namespace.
    // 5. Inherit from $keywords<'mp4'> and specify the name of the new output format in <...>.
    export interface $values extends $keywords<'mp4'> {}
  }
}

toFile('digraph { a -> b }', '/path/to/file', {
  layout: 'my-custom-algorithm',
  format: 'mp4',
});

Use Case: Adding Custom Attributes

import { $keywords } from '@ts-graphviz/common';
import { digraph, toDot, attribute as _ } from 'ts-graphviz';

// 1. Declare the '@ts-graphviz/common' module.
declare module '@ts-graphviz/common' {
  export namespace GraphAttributeKey {
    // 2. Define the $values interface in the GraphAttributeKey namespace.
    // 3. Inherit from $keywords<'hoge'> and specify the name of the new attribute in <...>.
    export interface $values extends $keywords<'hoge'> {}
  }

  export namespace Attribute {
    // 4. Define the $keys interface in the Attribute namespace.
    // 5. Inherit from $keywords<'hoge'> and specify the name of the new attribute in <...>.
    export interface $keys extends $keywords<'hoge'> {}

    // 6. Define the $types interface in the Attribute namespace.
    // 7. Specify the new attribute in the key and define its corresponding value in the value.
    export interface $types {
      hoge: string;
    }
  }
}

console.log(
  toDot(
    digraph((g) => {
      g.set(_.hoge, 'fuga');
    }),
  ),
);

Deep dive 🏊‍♂️

Architecture 🏛

See ARCHITECTURE.md for more details.

Security 🛡️

See SECURITY.md for more details.

Who's using ts-graphviz 📜

Note Let us know that you're using ts-graphviz on GitHub Discussions 🙏

Related projects can be found at ts-graphviz GitHub Organization.

The TypeScript/JavaScript ecosystem provides a variety of OSS with the goal of making Graphviz more connected and easier to use.

Contributors 👥

Thanks goes to these wonderful people (emoji key):

Yuki Yamazaki
Yuki Yamazaki

💻 ⚠️ 📖 🤔
LaySent
LaySent

🐛 ⚠️
elasticdotventures
elasticdotventures

📖
Christian Murphy
Christian Murphy

💻 🤔 📖
Artem
Artem

🐛
fredericohpandolfo
fredericohpandolfo

🐛
diegoquinteiro
diegoquinteiro

🐛
robross0606
robross0606

🤔
Blake Regalia
Blake Regalia

🐛
bigbug
bigbug

💬
mrwk
mrwk

💬
svdvonde
svdvonde

💬
Adam
Adam

💬
Trevor Scheer
Trevor Scheer

️️️️♿️
Prem Pillai
Prem Pillai

🐛
nagasawaryoya
nagasawaryoya

💻 ⚠️
YukiSasaki
YukiSasaki

💻 ⚠️
Madd0g
Madd0g

🐛
j4k0xb
j4k0xb

🐛
HKrogstie
HKrogstie

🐛
Nils K
Nils K

🐛
hao2013
hao2013

🚧 👀

This project follows the all-contributors specification. Contributions of any kind welcome!

How to Contribute 💪

The easiest way to contribute is to use the library and star repository.

Questions 💭

Feel free to ask questions on GitHub Discussions.

Report bugs / request additional features 💡

Please register at GitHub Issues.

Development / Bug Fixes 🧑‍💻

See CONTRIBUTING.md.

Financial Support 💸

Support this project by becoming a sponsor. Your logo will show up here with a link to your website. Become a sponsor

OpenCollective Sponsors

Thank you to all our backers! 🙏 Become a backer

OpenCollective Backers

Please support ts-graphviz on Open Collective or GitHub Sponsors.

Note Even just a dollar is enough motivation to develop 😊

ts-graphviz for Enterprise 🏢

Available as part of the Tidelift Subscription.

The maintainers of ts-graphviz and thousands of other packages are working with Tidelift to deliver commercial support and maintenance for the open-source dependencies you use to build your applications. Save time, reduce risk, and improve code health, while paying the maintainers of the exact dependencies you use.

Learn more.

License ⚖️

This software is released under the MIT License, see LICENSE.

changelog

ts-graphviz

2.1.6

Patch Changes

2.1.5

Patch Changes

2.1.4

Patch Changes

2.1.3

Patch Changes

2.1.2

Patch Changes

2.1.1

Patch Changes

2.1.0

Minor Changes

Patch Changes

2.0.0

Major Changes

  • #956 1e4f57a Thanks @kamiazya! - # ts-graphviz v2

    Why?

    Dropping support for Node.js 14 & 16

    We are introducing a major version upgrade to ts-graphviz to ensure better performance, security, and compatibility with the latest improvements in the JavaScript ecosystem. With this upgrade, we will no longer support Node.js 14 & 16, which has reached its End-of-Life (EOL), and set the new minimum guaranteed version to Node.js 18.

    This major version upgrade is necessary due to the following reasons:

    1. Breaking Change: Dropping support for Node.js 14 & 16 is considered a breaking change, which requires a major version upgrade according to semantic versioning principles.

    2. Improved Stability and Performance: By focusing on LTS versions, we can provide a library that benefits from the stability, long-term support, and performance improvements provided by newer Node.js versions.

    3. Security: Ensuring that our library is compatible with the latest supported Node.js versions helps to minimize potential security vulnerabilities.

    To help our users understand our approach to Node.js version support, we have established a clear Node.js Version Support Policy for ts-graphviz.

    We encourage our users to update their projects to the latest LTS version of Node.js to ensure the best performance, security, and compatibility with ts-graphviz.

    Key Concepts

    ts-graphviz is a TypeScript library designed to create, manipulate, and render Graphviz DOT language graphs.

    It is built around several key concepts that make it modular, extensible, and easy to use:

    1. TypeScript-First Design & Type Definitions: ts-graphviz is designed with TypeScript as its primary language, providing strong typing and ensuring seamless integration with TypeScript projects. This enables users to leverage the full power of TypeScript's type system and tooling while working with Graphviz graphs. The library includes comprehensive type definitions for DOT language elements, making it easier to work with Graphviz elements in a type-safe manner.

    2. Object-Oriented API: ts-graphviz provides an object-oriented API for creating and manipulating graph elements like graphs, nodes, and edges. This enables users to work with complex graph structures intuitively and efficiently.

    3. Modular Design[New in v2]: The library is split into multiple packages, each serving a specific purpose. This modular design allows users to pick and choose the functionality they need, resulting in improved maintainability and flexibility.

    4. AST Support: ts-graphviz includes a module for processing DOT language at the Abstract Syntax Tree (AST) level. This feature allows users to parse and generate DOT language while preserving its structure, making it easier to manipulate and transform graphs programmatically.

    5. Runtime Adapter: The library provides adapter functions that enable users to execute Graphviz commands across different runtime environments, such as Node.js and Deno. These adapter functions serve as a wrapper, allowing for seamless integration with various platforms.

    6. Extensibility: ts-graphviz has been designed with extensibility in mind, allowing users to extend its functionality with custom implementations for specific use cases.

    7. Multi-Paradigm Support: ts-graphviz is designed to accommodate various programming paradigms, such as Object-Oriented Programming, Declarative Programming, and Functional Programming. This ensures that users can choose the programming style that best suits their needs and preferences, making it adaptable and versatile across different use cases and development approaches.

    By combining these key concepts, ts-graphviz aims to provide a powerful and user-friendly tool for working with Graphviz DOT language in TypeScript projects.

    What's changed?

    Package splitting and monorepo-ization

    Purpose

    The purpose of package splitting and monorepo-ization in the ts-graphviz v2 is to achieve the following objectives:

    • Improved modularity: By separating functionality into distinct packages, the library becomes more modular. This allows users to install and use only the specific components they need, reducing unnecessary dependencies and improving overall performance.
    • Easier maintainability: Splitting the library into smaller packages makes it easier for developers to maintain and update each package independently. This allows for faster bug fixes, feature enhancements, and more efficient development cycles.
    • Clearer dependencies: Package splitting results in a more explicit dependency structure between components, making it easier for developers to understand and manage dependencies within the project.
    • Increased flexibility: With a modular package structure, users can choose to use only the features they need, making it easier to integrate ts-graphviz into a broader range of projects and applications.
    • Simplified collaboration: By breaking down the library into separate packages within a monorepo, contributors can focus on specific areas of interest without interfering with other parts of the library. This facilitates collaboration and encourages more developers to contribute to the project.
    • Centralized management: Monorepo-ization allows for the centralized management of all the packages. This enables developers to track issues, manage pull requests, and maintain documentation in a single location, increasing efficiency and reducing overhead.
    • Consistent versioning and releases: Monorepo-ization ensures that versioning and release processes are consistent across all packages, making it easier to maintain and update the library as a whole.

    Overall, package splitting and monorepo-ization aim to create a more robust, maintainable, and user-friendly library that better serves the needs of the ts-graphviz community.

    Packages

    In v2 of ts-graphviz, the library functionality will be split into several packages. The packages to be split are as follows:

    • @ts-graphviz/common: Contains type information related to DOT language attributes, attribute values, and models.
    • @ts-graphviz/ast: Includes the module for processing DOT language at the AST (Abstract Syntax Tree) level.
    • @ts-graphviz/core: Comprises the implementation of models and functions provided to users.
    • @ts-graphviz/adapter: Handles runtime-dependent processing. For example, it provides I/O processing related to image generation in Graphviz on different runtimes, such as Node.js and Deno.

    To ensure that existing users are not affected, the ts-graphviz package will remain available. This change will result in a clear division of functionality and will improve the scalability and maintainability of the project. However, users of previous versions and users who wish to use the library without extending it will be able to continue to use the ts-graphviz package as is.

    • ts-graphviz: The main package that serves as the entry point for users. It provides a high-level API for creating, manipulating, and rendering Graphviz DOT language graphs. This package depends on the other packages to provide its functionality.

    Please note that while we strive to maintain compatibility, there might be some minor differences or limitations in the compatibility package compared to the original ts-graphviz library. It is essential to review the documentation and update your code accordingly if needed, but only when you decide to migrate to the new package structure.

    Dependency graph

    | Package | Summary | Description | | -------------------------------------------------------------------------- | ----------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------- | | ts-graphviz | Graphviz library for TypeScript | The main package that serves as the entry point for users. It provides a high-level API for creating, manipulating, and rendering Graphviz DOT language graphs. | | @ts-graphviz/common | Graphviz Types and Utilities | Contains type information related to DOT language attributes, attribute values, and models. | | @ts-graphviz/ast | Graphviz AST(Abstract Syntax Tree) Utilities | Includes the module for processing DOT language at the AST (Abstract Syntax Tree) level. | | @ts-graphviz/core | Graphviz Models for Object-Oriented Programming | Comprises the implementation of models and functions provided to users. | | @ts-graphviz/adapter | Graphviz Runtime adapters for Cross Platform | Handles runtime-dependent processing, such as input/output processing and Renderer implementations for different environments. |

    dependency-graph

    Node.js Version Support Update

    Starting with the upcoming release, ts-graphviz will no longer support Node.js 14 & 16, which has reached its End-of-Life (EOL). The new minimum guaranteed version will be Node.js 18. This decision allows us to focus on providing a secure and up-to-date library while minimizing the maintenance burden of supporting outdated versions.

    To minimize disruption for our users, we have established a clear Node.js Version Support Policy for our library. This policy helps users understand our approach to Node.js version support and what to expect when using our library.

    We encourage our users to update their projects to the latest LTS version of Node.js to ensure the best performance, security, and compatibility with ts-graphviz.

    Node.js Version Support Policy

    Our goal is to provide a stable and secure library for our users while keeping up with improvements in the JavaScript ecosystem. To achieve this, we have established the following Node.js version support policy for ts-graphviz:

    1. Minimum Guaranteed Version: We guarantee support for the latest Node.js version that has entered Long-Term Support (LTS) at the time of a major release of our library. This ensures that our library benefits from the stability and long-term support provided by LTS versions.

    2. End-of-Life (EOL) Policy: We will cease support for Node.js versions when they reach their EOL, as defined by the Node.js release schedule. This helps us focus on providing a secure and up-to-date library while minimizing the maintenance burden of supporting outdated versions.

    3. Version Support Communication: We will communicate our Node.js version support policy in our library's documentation and release notes. When a new major version is released or when a Node.js version enters EOL, we will inform our users through release notes, blog posts, or other relevant channels.

    4. Migration Guides : When introducing breaking changes due to Node.js version support updates, we will provide migration guides to help our users transition their projects to the new requirements smoothly.

    Migration Guides

    Update Node.js Version

    To migrate to the new Node.js version support policy, follow these steps:

    1. Check Node.js Version: First, check the version of Node.js used in your project by running the following command in your terminal:
      node -v
    2. Update Node.js: If your project is using Node.js 14 or 16, update it to the latest LTS version of Node.js (Node.js 18) by following the installation instructions provided on the official Node.js website or using a version manager like nvm or n.
    3. Update Dependencies: After updating Node.js, review your project's dependencies to ensure that they are compatible with the new Node.js version. Update any dependencies that require changes to work with the latest LTS version of Node.js.
    4. Test and Verify: Test your project with the updated Node.js version to ensure that it works as expected. Verify that all functionality is intact and that there are no compatibility issues with the new Node.js version.

    By following these steps, you can migrate your project to the latest LTS version of Node.js and ensure compatibility with ts-graphviz.

    Migrate AttributeKeyDict type to Attribute.keys type

    AttributeKeyDict was deprecated in v1, so it was removed in v2. Please modify to use Attribute.keys.

    - import { AttributeKeyDict } from 'ts-graphviz';
    + import { Attribute } from '@ts-graphviz/common';
    
    - const foo: AttributeKeyDict = ...;
    + const foo: Attribute.keys = ...;

    Migrate ts-graphviz/adapter to @ts-graphviz/adapter

    To migrate from the ts-graphviz/adapter module to the @ts-graphviz/adapter module, follow these steps:

    1. Update Import Statements: Update import statements in your code to use the new module name.

      - import { } from 'ts-graphviz/adapter';
      + import { } from '@ts-graphviz/adapter';
    2. Update Package.json: Update the ts-graphviz dependency in your package.json file to use the new version of the @ts-graphviz/adapter module.

      - "ts-graphviz": "^1.0.0",
      + "ts-graphviz": "^2.0.0",
      + "@ts-graphviz/adapter": "^2.0.0",
    3. Update Code References: Search your codebase for any references to the ts-graphviz/adapter module and update them to use the new module name.

      - import { } from 'ts-graphviz/adapter';
      + import { } from '@ts-graphviz/adapter';

    Migrate ts-graphviz/ast to @ts-graphviz/ast

    To migrate from the ts-graphviz/adapter module to the @ts-graphviz/adapter module, follow these steps:

    1. Update Import Statements: Update import statements in your code to use the new module name.

      - import { } from 'ts-graphviz/ast';
      + import { } from '@ts-graphviz/ast';
    2. Update Package.json: Update the ts-graphviz dependency in your package.json file to use the new version of the @ts-graphviz/ast module.

      - "ts-graphviz": "^1.0.0",
      + "ts-graphviz": "^2.0.0",
      + "@ts-graphviz/ast": "^2.0.0",
    3. Update Code References: Search your codebase for any references to the ts-graphviz/ast module and update them to use the new module name.

      - import { } from 'ts-graphviz/ast';
      + import { } from '@ts-graphviz/ast';

    Migrate Extending the Type System

    Common types moves to @ts-graphviz/common in v2.0.0.

    If you have extended the type system, you need to update the import path.

    Use Case: Specifying Custom Graph Layout and Output Formats
    -import { $keywords } from 'ts-graphviz';
    +import { $keywords } from '@ts-graphviz/common';
    -import { toFile } from 'ts-graphviz/adapter';
    +import { toFile } from '@ts-graphviz/adapter';
    
    -// 1. Declare the 'ts-graphviz/adapter' module.
    -declare module 'ts-graphviz/adapter' {
    +// 1. Declare the '@ts-graphviz/adapter' module.
    +declare module '@ts-graphviz/adapter' {
      export namespace Layout {
        // 2. Define the $values interface in the Layout namespace.
        // 3. Inherit from $keywords<'my-custom-algorithm'> and specify the name of the new layout engine in <...>.
        export interface $values extends $keywords<'my-custom-algorithm'> {}
      }
    
      export namespace Format {
        // 4. Define the $values interface in the Format namespace.
        // 5. Inherit from $keywords<'mp4'> and specify the name of the new output format in <...>.
        export interface $values extends $keywords<'mp4'> {}
      }
    }
    
    toFile('digraph { a -> b }', '/path/to/file', {
      layout: 'my-custom-algorithm',
      format: 'mp4',
    });
    Use Case: Adding Custom Attributes
    - import { digraph, toDot, attribute as _, $keywords } from 'ts-graphviz';
    + import {  $keywords } from '@ts-graphviz'/common;
    + import { digraph, toDot, attribute as _ } from 'ts-graphviz';
    
    -// 1. Declare the 'ts-graphviz' module.
    -declare module 'ts-graphviz' {
    +// 1. Declare the '@ts-graphviz/common' module.
    +declare module '@ts-graphviz/common' {
      export namespace GraphAttributeKey {
        // 2. Define the $values interface in the GraphAttributeKey namespace.
        // 3. Inherit from $keywords<'hoge'> and specify the name of the new attribute in <...>.
        export interface $values extends $keywords<'hoge'> {}
      }
    
      export namespace Attribute {
        // 4. Define the $keys interface in the Attribute namespace.
        // 5. Inherit from $keywords<'hoge'> and specify the name of the new attribute in <...>.
        export interface $keys extends $keywords<'hoge'> {}
    
        // 6. Define the $types interface in the Attribute namespace.
        // 7. Specify the new attribute in the key and define its corresponding value in the value.
        export interface $types {
          hoge: string;
        }
      }
    }
    
    console.log(
      toDot(
        digraph((g) => {
          g.set(_.hoge, 'fuga');
        }),
      ),
    );

    Development

    Package manager

    Migration from yarn v1 to pnpm has been done for package management.

    Build tool and Test suite

    To enhance the development experience, the build tool has been changed from rollup to vite, and the test suite from jest to vitest. This was done because jest lacked standard support for monorepo integration and TypeScript, requiring the installation of additional plugins. However, vite and vitest handle these challenges more elegantly, providing a smoother and more efficient development workflow.

    Release flow

    The release flow has been updated to use the changeset tool to manage changes and releases.

    This tool allows for a more streamlined and automated release process, making it easier to manage versioning and changelogs across multiple packages within the monorepo.

    Linter an Formatter

    The linter and formatter have been updated to use biome, respectively.

    This change was made to ensure consistent code style and formatting across the entire codebase, making it easier to maintain and contribute to the project.

    API Changes

    • The status of the ModelContext API and other APIs that were provided in beta and alpha have been removed. This is a temporary measure to ensure compliance with the @microsoft/api-extractor specification used internally in the d.ts file rollup.

Patch Changes