New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details
Socket
Book a DemoSign in
Socket

esbuild-plugin-type-schema

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

esbuild-plugin-type-schema

It convert decorator tagged in build-time to anything you want!

latest
npmnpm
Version
1.0.8
Version published
Maintainers
1
Created
Source

esbuild-plugin-type-schema

Version Downloads/week License

Installation

$ npm install esbuild-plugin-type-schema --save-dev
$ yarn add esbuild-plugin-type-schema -D

Usage

const { build } = require("esbuild");
const { JSONTypeSchema } = require("esbuild-plugin-type-schema");

build({
    entryPoints: ["test/index.ts"],
    outfile: "test/dist/bundle.js",
    format: "esm",
    plugins: [JSONTypeSchema("./test/dist/type.json")],
    tsconfig: "./tsconfig.json",
});

Custom

export function JSONTypeSchema(outJsonPath: string): Plugin {
    const json: SimpleClassTypeInfo[] = [];
    return TypeSchema({
        onProgress(_, classTypeInfo: ClassTypeInfo) {
            json.push({
                name: classTypeInfo.target.getName(),
                properties: classTypeInfo.properties.map((prop) => {
                    return {
                        name: prop.target.getName(),
                        type: prop.target.getTypeNode().getText(),
                    };
                }),
                methods: classTypeInfo.methods.map((method) => {
                    return {
                        name: method.target.getName(),
                        params: method.target
                            .getParameters()
                            .map((param) => param.getTypeNode().getText()),
                        return: method.target.getReturnType().getText(),
                    };
                }),
            });
        },

        onEnd() {
            fs.writeFileSync(outJsonPath, JSON.stringify(json, undefined, 4));
        },
    });
}

_See src/json-type-schema.ts

Result

[
    {
        "name": "Abcf",
        "properties": [
            {
                "name": "a",
                "type": "Abce"
            }
        ],
        "methods": []
    },
    {
        "name": "Abc",
        "properties": [
            {
                "name": "a",
                "type": "number"
            },
            {
                "name": "b",
                "type": "u32[]"
            }
        ],
        "methods": []
    },
    {
        "name": "Abcd",
        "properties": [
            {
                "name": "a",
                "type": "number"
            }
        ],
        "methods": [
            {
                "name": "heihei",
                "params": [
                    "u32",
                    "number"
                ],
                "return": "void"
            }
        ]
    },
    {
        "name": "Abce",
        "properties": [
            {
                "name": "a",
                "type": "number"
            }
        ],
        "methods": []
    }
]

FAQs

Package last updated on 30 Aug 2021

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