Socket
Socket
Sign inDemoInstall

esbuild-decorators

Package Overview
Dependencies
2
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    esbuild-decorators

Esbuild plugin for typescript experimentalDecorators and emitDecoratorMetadata


Version published
Weekly downloads
1.1K
increased by10.24%
Maintainers
1
Created
Weekly downloads
 

Readme

Source

esbuild-decorators

Testing/Build

Overview

This is a plugin for esbuild to handle the tsconfig setting "emitDecoratorMetadata": true,

When the decorator flag is set to true, the build process will inspect each .ts file and upon a decorator, will transpile with Typescript.

Usage

Install esbuild and the plugin

npm install -D esbuild esbuild-decorators
# or
pnpm install -D esbuild esbuild-decorators

Set up a build script

import { build } from 'esbuild';
import { esbuildDecorators } from '@anatine/esbuild-decorators'

async function myBuilder(
  tsconfig: string,
  entryPoints: string[],
  outfile: string,
  cwd: string = process.cwd()
) {
  const buildResult = await build({
    platform: 'node',
    target: 'node14',
    bundle: true,
    sourcemap: 'external',
    plugins: [
      esbuildDecorators({
        tsconfig,
        cwd,
      }),
    ],
    tsconfig,
    entryPoints,
    outfile,
    external: [
      // This is likely to be your friend...
    ],
  });
}

Run your builder.


Options

OptionDescription
tsconfigoptional : string : The path and filename of the tsconfig.json
cwdoptional : string : The current working directory
forceoptional : boolean : Will transpile all .ts files to Javascript with tsc
tsxoptional : boolean : Enable .tsx file support

Caveats

There is no doubt that this will affect the performance of esbuild. When emitDecoratorMetadata is set, every file will have to be loaded into this plugin.

This simple plugin hangs on the regex string: /((?<![(\s]\s*['"])@\w[.[\]\w\d]*\s*(?![;])[((?=\s)])/

Potentially esbuild could eventually do this regex search and expose positives via another plugin hook for transpiling.

Issue here: https://github.com/evanw/esbuild/issues/991


Decorator Match Testing

Check out the test files and submit any issues or PRs if you see a pattern that should be covered.


Credits

Thanks to the anatine organization who's fork I've forked. This fork has valid peer deps and has an esm module and commonjs module.

Keywords

FAQs

Last updated on 20 Aug 2022

Did you know?

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc