0.2.19 • Published 2 years ago

@anatine/esbuild-decorators v0.2.19

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

esbuild-decorators

Testing/Build Known Vulnerabilities

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
npm install -D @anatine/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 Thomas Schaaf as this was his shared code that lead me here. Original Source

Thanks to the npm package strip-comments that was stripped down to cover only typescript comments and string removals

0.2.19

2 years ago

0.2.18

3 years ago

0.2.17

3 years ago

0.2.12

3 years ago

0.2.11

3 years ago

0.2.10

3 years ago

0.2.9

3 years ago

0.2.8

3 years ago

0.2.7

3 years ago

0.2.6

3 years ago

0.2.5

3 years ago

0.2.4

3 years ago

0.2.3

3 years ago

0.2.2

3 years ago

0.2.1

3 years ago

0.2.0

3 years ago

0.1.6

3 years ago

0.1.5

3 years ago

0.1.0

3 years ago

0.1.2

3 years ago

0.1.1

3 years ago

0.1.4

3 years ago

0.1.3

3 years ago

0.0.7

3 years ago

0.0.6

3 years ago

0.0.4

3 years ago

0.0.2

3 years ago

0.0.1

3 years ago