From 8ad9da227cdd015e2b872d8f1f2788352ef85824 Mon Sep 17 00:00:00 2001 From: Momo Kornher Date: Sun, 18 Dec 2022 21:44:15 +0000 Subject: [PATCH] feat: graduate `InlineJavaScriptCode` and `InlineTypeScriptCode` to stable BREAKING CHANGE: `InlineJsxCode` and `InlineTsxCode` classes have been removed. Use `InlineJavaScriptCode` or `InlineTypeScriptCode` respectively and set `transformOptions.loader` to `jsx` or `tsx`. --- API.md | 126 --------------------------------------- src/index.ts | 2 - src/inline-code.ts | 69 +++------------------ test/inline-code.test.ts | 30 ---------- 4 files changed, 7 insertions(+), 220 deletions(-) diff --git a/API.md b/API.md index b2ab51c5..1911aa8d 100644 --- a/API.md +++ b/API.md @@ -2738,132 +2738,6 @@ Determines whether this Code is inline code or not. --- -### InlineJsxCode - -An implementation of `lambda.InlineCode` using the esbuild Transform API. Inline function code is limited to 4 KiB after transformation. - -#### Initializers - -```typescript -import { InlineJsxCode } from '@mrgrain/cdk-esbuild' - -new InlineJsxCode(code: string, props?: TransformerProps) -``` - -##### `code`Required - -- *Type:* `string` - -The inline code to be transformed. - ---- - -##### `props`Optional - -- *Type:* [`@mrgrain/cdk-esbuild.TransformerProps`](#@mrgrain/cdk-esbuild.TransformerProps) - -Props to change the behavior of the transformer. - -Default values for `transformOptions`: -- `loader='jsx'` - -> https://esbuild.github.io/api/#transform-api - ---- - -#### Methods - -##### `bind` - -```typescript -public bind(scope: Construct) -``` - -###### `scope`Required - -- *Type:* [`constructs.Construct`](#constructs.Construct) - ---- - - -#### Properties - -##### `isInline`Required - -```typescript -public readonly isInline: boolean; -``` - -- *Type:* `boolean` - -Determines whether this Code is inline code or not. - ---- - - -### InlineTsxCode - -An implementation of `lambda.InlineCode` using the esbuild Transform API. Inline function code is limited to 4 KiB after transformation. - -#### Initializers - -```typescript -import { InlineTsxCode } from '@mrgrain/cdk-esbuild' - -new InlineTsxCode(code: string, props?: TransformerProps) -``` - -##### `code`Required - -- *Type:* `string` - -The inline code to be transformed. - ---- - -##### `props`Optional - -- *Type:* [`@mrgrain/cdk-esbuild.TransformerProps`](#@mrgrain/cdk-esbuild.TransformerProps) - -Props to change the behavior of the transformer. - -Default values for `transformOptions`: -- `loader='tsx'` - -> https://esbuild.github.io/api/#transform-api - ---- - -#### Methods - -##### `bind` - -```typescript -public bind(scope: Construct) -``` - -###### `scope`Required - -- *Type:* [`constructs.Construct`](#constructs.Construct) - ---- - - -#### Properties - -##### `isInline`Required - -```typescript -public readonly isInline: boolean; -``` - -- *Type:* `boolean` - -Determines whether this Code is inline code or not. - ---- - - ### InlineTypeScriptCode An implementation of `lambda.InlineCode` using the esbuild Transform API. Inline function code is limited to 4 KiB after transformation. diff --git a/src/index.ts b/src/index.ts index 0330da69..25d338bd 100644 --- a/src/index.ts +++ b/src/index.ts @@ -35,8 +35,6 @@ export { export { TransformerProps, InlineJavaScriptCode, - InlineJsxCode, - InlineTsxCode, InlineTypeScriptCode, } from './inline-code'; diff --git a/src/inline-code.ts b/src/inline-code.ts index d17b4782..77b6b838 100644 --- a/src/inline-code.ts +++ b/src/inline-code.ts @@ -6,7 +6,7 @@ import { TransformOptions, Loader } from './esbuild-types'; import { isEsbuildError } from './utils'; /** - * @stability experimental + * @stability stable */ export interface TransformerProps { /** @@ -115,14 +115,14 @@ function transformerProps(loader: Loader, props: TransformerProps = {}): Transfo /** * An implementation of `lambda.InlineCode` using the esbuild Transform API. Inline function code is limited to 4 KiB after transformation. * - * @stability experimental + * @stability stable */ export class InlineJavaScriptCode extends BaseInlineCode { public constructor( /** * The inline code to be transformed. * - * @stability experimental + * @stability stable */ code: string, /** @@ -132,7 +132,7 @@ export class InlineJavaScriptCode extends BaseInlineCode { * - `loader='js'` * * @see https://esbuild.github.io/api/#transform-api - * @stability experimental + * @stability stable */ props?: TransformerProps, ) { @@ -141,45 +141,18 @@ export class InlineJavaScriptCode extends BaseInlineCode { } } -/** - * An implementation of `lambda.InlineCode` using the esbuild Transform API. Inline function code is limited to 4 KiB after transformation. - * - * @stability experimental - */ -export class InlineJsxCode extends BaseInlineCode { - public constructor( - /** - * The inline code to be transformed. - * - * @stability experimental - */ - code: string, - /** - * Props to change the behavior of the transformer. - * - * Default values for `transformOptions`: - * - `loader='jsx'` - * - * @see https://esbuild.github.io/api/#transform-api - * @stability experimental - */ - props?: TransformerProps, - ) { - super(code, transformerProps('jsx', props)); - } -} /** * An implementation of `lambda.InlineCode` using the esbuild Transform API. Inline function code is limited to 4 KiB after transformation. * - * @stability experimental + * @stability stable */ export class InlineTypeScriptCode extends BaseInlineCode { public constructor( /** * The inline code to be transformed. * - * @stability experimental + * @stability stable */ code: string, /** @@ -189,38 +162,10 @@ export class InlineTypeScriptCode extends BaseInlineCode { * - `loader='ts'` * * @see https://esbuild.github.io/api/#transform-api - * @stability experimental + * @stability stable */ props?: TransformerProps, ) { super(code, transformerProps('ts', props)); } } - -/** - * An implementation of `lambda.InlineCode` using the esbuild Transform API. Inline function code is limited to 4 KiB after transformation. - * - * @stability experimental - */ -export class InlineTsxCode extends BaseInlineCode { - public constructor( - /** - * The inline code to be transformed. - * - * @stability experimental - */ - code: string, - /** - * Props to change the behavior of the transformer. - * - * Default values for `transformOptions`: - * - `loader='tsx'` - * - * @see https://esbuild.github.io/api/#transform-api - * @stability experimental - */ - props?: TransformerProps, - ) { - super(code, transformerProps('tsx', props)); - } -} diff --git a/test/inline-code.test.ts b/test/inline-code.test.ts index 10fbb1c6..192696da 100644 --- a/test/inline-code.test.ts +++ b/test/inline-code.test.ts @@ -4,8 +4,6 @@ import * as esbuild from 'esbuild'; import { mocked } from 'jest-mock'; import { InlineJavaScriptCode, - InlineJsxCode, - InlineTsxCode, InlineTypeScriptCode, } from '../src'; import { EsbuildProvider } from '../src/esbuild-provider'; @@ -26,20 +24,6 @@ describe('using transformerProps', () => { }); }); - describe('given some jsx code', () => { - it('should transform the code', () => { - const code = new InlineJsxCode( - 'const App = () => (
Hello World
)', - ); - - const { inlineCode } = code.bind(new Stack()); - - expect(inlineCode).toBe( - 'const App = () => /* @__PURE__ */ React.createElement("div", null, "Hello World");\n', - ); - }); - }); - describe('given some ts code', () => { it('should transform the code', () => { const code = new InlineTypeScriptCode('let x: number = 1'); @@ -98,20 +82,6 @@ describe('using transformerProps', () => { }); }); - describe('given some tsx code', () => { - it('should transform the code', () => { - const code = new InlineTsxCode( - 'const App = (): JSX.Element => (
Hello World
)', - ); - - const { inlineCode } = code.bind(new Stack()); - - expect(inlineCode).toBe( - 'const App = () => /* @__PURE__ */ React.createElement("div", null, "Hello World");\n', - ); - }); - }); - describe('given some broken ts code', () => { it('should throws', () => { expect(() => {