Socket
Book a DemoInstallSign in
Socket

@toil/typebox-genx

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@toil/typebox-genx

Code generation tool that extends `@sinclair/typebox-codegen` package with import functionality

latest
Source
npmnpm
Version
0.1.0
Version published
Maintainers
1
Created
Source

typebox-genx

GitHub Actions npm en ru

typebox-genx (TypeBox Generator eXtended) is a code generation tool that extends @sinclair/typebox-codegen package with import functionality

Installation

Install via Bun:

bun install @toil/typebox-genx

Install via Node:

npm install @toil/typebox-genx

Before starting

This lib is very very very very unstable and some parts of planned functionality aren't available.

Lib work bad with scopes and i mean you have separate files for types

Supports only 1 type of import by line. Any of these code variants are valid:

[!WARNING] Now you can only import with import {...} from "...". Also you can use "type".

import type { ClientOpts } from "@vot.js/node";
// or
// import { ClientOpts as RenamedOpts } from "@vot.js/node";
// or
import { Client, type ClientOpts } from "@vot.js/node";
// or
// import * as Client from "@vot.js/node";
// and many more

These code variants unsupported:

import Client, { ClientOpts } from "@vot.js/node";
// or
import "@vot.js/node";

Now typeof variable unsupported too

Getting started

The library class provides several methods:

const genx = new GenX({
  root: path.join(__dirname),
  includeNearbyFiles: true,
});

// read from input dir and write to output
await genx.generateByDir(
  path.join(__dirname, "src/types"),
  path.join(__dirname, "dist"),
);

// read file and return result to variable
const codeByFile = await genx.generateByFile(
  path.join(__dirname, "src/types/with.ts"),
);

// read string and return result to variable
const raw = `import type { RequestMethod } from "@toil/translate/types/providers/base";

export type Test = {
  method: RequestMethod;
};`;

const codeByStr = await genx.generateByCode(raw);

// clear saved imports and depends list if needed
genx.clearData();

// create client for enabled workspaces
const genxw = new GenX({
  root: path.join(__dirname, "packages", "packageA"),
  workspaceRoot: path.join(__dirname),
});

await genx.generateByDir(
  path.join(__dirname, "packages", "packageA"),
  path.join(__dirname, "dist"),
);

Build

To build, you must have:

  • Bun

Don't forget to install the dependencies:

bun install

Start building:

bun build:all

Tests

The library has minimal test coverage to check its performance.

Run the tests:

bun test

Keywords

typebox

FAQs

Package last updated on 05 Mar 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts