From dc1a0560b6f7d7461c1f43530f201d7715eb2734 Mon Sep 17 00:00:00 2001 From: Momo Kornher Date: Sun, 18 Dec 2022 19:21:40 +0000 Subject: [PATCH 1/3] chore: remove deprecated support of top-level TransformOptions on InlineXCode classes BREAKING CHANGE: `InlineXCode` classes now only take `TransformerProps` as second argument. Please provide any transform options via `props.transformOptions`. --- src/bundler.ts | 2 +- src/inline-code.ts | 48 +++++++++------------------------------------- 2 files changed, 10 insertions(+), 40 deletions(-) diff --git a/src/bundler.ts b/src/bundler.ts index b7aa4cb5..ff1d6b70 100644 --- a/src/bundler.ts +++ b/src/bundler.ts @@ -162,7 +162,7 @@ export class EsbuildBundler { public readonly entryPoints: EntryPoints, /** - * Props to change the behaviour of the bundler. + * Props to change the behavior of the bundler. * * @stability experimental */ diff --git a/src/inline-code.ts b/src/inline-code.ts index b3d21300..d17b4782 100644 --- a/src/inline-code.ts +++ b/src/inline-code.ts @@ -102,28 +102,7 @@ abstract class BaseInlineCode extends InlineCode { } } -function instanceOfTransformerProps(object: any): object is TransformerProps { - return [ - 'transformOptions', - 'transformFn', - 'esbuildBinaryPath', - 'esbuildModulePath', - ].reduce( - (isTransformerProps: boolean, propToCheck: string): boolean => - (isTransformerProps || (propToCheck in object)), - false, - ); -} - -function transformerProps(loader: Loader, props?: TransformerProps | TransformOptions): TransformerProps { - if (!props) { - return { transformOptions: { loader } }; - } - - if (!instanceOfTransformerProps(props) ) { - return { transformOptions: { loader, ...props } }; - } - +function transformerProps(loader: Loader, props: TransformerProps = {}): TransformerProps { return { ...props, transformOptions: { @@ -133,7 +112,6 @@ function transformerProps(loader: Loader, props?: TransformerProps | TransformOp }; } - /** * An implementation of `lambda.InlineCode` using the esbuild Transform API. Inline function code is limited to 4 KiB after transformation. * @@ -148,9 +126,7 @@ export class InlineJavaScriptCode extends BaseInlineCode { */ code: string, /** - * Support for `TransformOptions` is deprecated. Please provide `TransformerProps`! - * - * Props to change the behaviour of the transformer. + * Props to change the behavior of the transformer. * * Default values for `props.transformOptions`: * - `loader='js'` @@ -158,7 +134,7 @@ export class InlineJavaScriptCode extends BaseInlineCode { * @see https://esbuild.github.io/api/#transform-api * @stability experimental */ - props?: TransformerProps | TransformOptions, + props?: TransformerProps, ) { super(code, transformerProps('js', props)); @@ -179,9 +155,7 @@ export class InlineJsxCode extends BaseInlineCode { */ code: string, /** - * Support for `TransformOptions` is deprecated. Please provide `TransformerProps`! - * - * Props to change the behaviour of the transformer. + * Props to change the behavior of the transformer. * * Default values for `transformOptions`: * - `loader='jsx'` @@ -189,7 +163,7 @@ export class InlineJsxCode extends BaseInlineCode { * @see https://esbuild.github.io/api/#transform-api * @stability experimental */ - props?: TransformerProps | TransformOptions, + props?: TransformerProps, ) { super(code, transformerProps('jsx', props)); } @@ -209,9 +183,7 @@ export class InlineTypeScriptCode extends BaseInlineCode { */ code: string, /** - * Support for `TransformOptions` is deprecated. Please provide `TransformerProps`! - * - * Props to change the behaviour of the transformer. + * Props to change the behavior of the transformer. * * Default values for `transformOptions`: * - `loader='ts'` @@ -219,7 +191,7 @@ export class InlineTypeScriptCode extends BaseInlineCode { * @see https://esbuild.github.io/api/#transform-api * @stability experimental */ - props?: TransformerProps | TransformOptions, + props?: TransformerProps, ) { super(code, transformerProps('ts', props)); } @@ -239,9 +211,7 @@ export class InlineTsxCode extends BaseInlineCode { */ code: string, /** - * Support for `TransformOptions` is deprecated. Please provide `TransformerProps`! - * - * Props to change the behaviour of the transformer. + * Props to change the behavior of the transformer. * * Default values for `transformOptions`: * - `loader='tsx'` @@ -249,7 +219,7 @@ export class InlineTsxCode extends BaseInlineCode { * @see https://esbuild.github.io/api/#transform-api * @stability experimental */ - props?: TransformerProps | TransformOptions, + props?: TransformerProps, ) { super(code, transformerProps('tsx', props)); } From 8d45b1d97e5fd624f8cc94641edcc85fe87b0240 Mon Sep 17 00:00:00 2001 From: Momo Kornher Date: Sun, 18 Dec 2022 21:23:23 +0000 Subject: [PATCH 2/3] remove deprecated test --- test/inline-code.test.ts | 17 ----------------- 1 file changed, 17 deletions(-) diff --git a/test/inline-code.test.ts b/test/inline-code.test.ts index 14aed798..10fbb1c6 100644 --- a/test/inline-code.test.ts +++ b/test/inline-code.test.ts @@ -12,23 +12,6 @@ import { EsbuildProvider } from '../src/esbuild-provider'; const providerSpy = jest.spyOn(EsbuildProvider, '_require'); -describe('using transformOptions', () => { - describe('given a banner code', () => { - it('should add the banner before the code', () => { - const code = new InlineJavaScriptCode( - "const banana = 'fruit' ?? 'vegetable'", - { - banner: '/** BANNER */', - }, - ); - - const { inlineCode } = code.bind(new Stack()); - - expect(inlineCode).toBe('/** BANNER */\nconst banana = "fruit";\n'); - }); - }); -}); - describe('using transformerProps', () => { describe('given some js code', () => { it('should transform the code', () => { From 4c4fc82956ef877f6a68059e865109cf45738228 Mon Sep 17 00:00:00 2001 From: github-actions Date: Sun, 18 Dec 2022 21:26:37 +0000 Subject: [PATCH 3/3] chore: self mutation Signed-off-by: github-actions --- API.md | 36 ++++++++++++++---------------------- 1 file changed, 14 insertions(+), 22 deletions(-) diff --git a/API.md b/API.md index aaf07252..b2ab51c5 100644 --- a/API.md +++ b/API.md @@ -2389,7 +2389,7 @@ Examples: - *Type:* [`@mrgrain/cdk-esbuild.BundlerProps`](#@mrgrain/cdk-esbuild.BundlerProps) -Props to change the behaviour of the bundler. +Props to change the behavior of the bundler. --- @@ -2452,7 +2452,7 @@ public readonly props: BundlerProps; - *Type:* [`@mrgrain/cdk-esbuild.BundlerProps`](#@mrgrain/cdk-esbuild.BundlerProps) -Props to change the behaviour of the bundler. +Props to change the behavior of the bundler. --- @@ -2684,7 +2684,7 @@ An implementation of `lambda.InlineCode` using the esbuild Transform API. Inline ```typescript import { InlineJavaScriptCode } from '@mrgrain/cdk-esbuild' -new InlineJavaScriptCode(code: string, props?: TransformOptions | TransformerProps) +new InlineJavaScriptCode(code: string, props?: TransformerProps) ``` ##### `code`Required @@ -2697,11 +2697,9 @@ The inline code to be transformed. ##### `props`Optional -- *Type:* [`@mrgrain/cdk-esbuild.TransformOptions`](#@mrgrain/cdk-esbuild.TransformOptions) | [`@mrgrain/cdk-esbuild.TransformerProps`](#@mrgrain/cdk-esbuild.TransformerProps) - -Support for `TransformOptions` is deprecated. Please provide `TransformerProps`! +- *Type:* [`@mrgrain/cdk-esbuild.TransformerProps`](#@mrgrain/cdk-esbuild.TransformerProps) -Props to change the behaviour of the transformer. +Props to change the behavior of the transformer. Default values for `props.transformOptions`: - `loader='js'` @@ -2749,7 +2747,7 @@ An implementation of `lambda.InlineCode` using the esbuild Transform API. Inline ```typescript import { InlineJsxCode } from '@mrgrain/cdk-esbuild' -new InlineJsxCode(code: string, props?: TransformOptions | TransformerProps) +new InlineJsxCode(code: string, props?: TransformerProps) ``` ##### `code`Required @@ -2762,11 +2760,9 @@ The inline code to be transformed. ##### `props`Optional -- *Type:* [`@mrgrain/cdk-esbuild.TransformOptions`](#@mrgrain/cdk-esbuild.TransformOptions) | [`@mrgrain/cdk-esbuild.TransformerProps`](#@mrgrain/cdk-esbuild.TransformerProps) +- *Type:* [`@mrgrain/cdk-esbuild.TransformerProps`](#@mrgrain/cdk-esbuild.TransformerProps) -Support for `TransformOptions` is deprecated. Please provide `TransformerProps`! - -Props to change the behaviour of the transformer. +Props to change the behavior of the transformer. Default values for `transformOptions`: - `loader='jsx'` @@ -2814,7 +2810,7 @@ An implementation of `lambda.InlineCode` using the esbuild Transform API. Inline ```typescript import { InlineTsxCode } from '@mrgrain/cdk-esbuild' -new InlineTsxCode(code: string, props?: TransformOptions | TransformerProps) +new InlineTsxCode(code: string, props?: TransformerProps) ``` ##### `code`Required @@ -2827,11 +2823,9 @@ The inline code to be transformed. ##### `props`Optional -- *Type:* [`@mrgrain/cdk-esbuild.TransformOptions`](#@mrgrain/cdk-esbuild.TransformOptions) | [`@mrgrain/cdk-esbuild.TransformerProps`](#@mrgrain/cdk-esbuild.TransformerProps) - -Support for `TransformOptions` is deprecated. Please provide `TransformerProps`! +- *Type:* [`@mrgrain/cdk-esbuild.TransformerProps`](#@mrgrain/cdk-esbuild.TransformerProps) -Props to change the behaviour of the transformer. +Props to change the behavior of the transformer. Default values for `transformOptions`: - `loader='tsx'` @@ -2879,7 +2873,7 @@ An implementation of `lambda.InlineCode` using the esbuild Transform API. Inline ```typescript import { InlineTypeScriptCode } from '@mrgrain/cdk-esbuild' -new InlineTypeScriptCode(code: string, props?: TransformOptions | TransformerProps) +new InlineTypeScriptCode(code: string, props?: TransformerProps) ``` ##### `code`Required @@ -2892,11 +2886,9 @@ The inline code to be transformed. ##### `props`Optional -- *Type:* [`@mrgrain/cdk-esbuild.TransformOptions`](#@mrgrain/cdk-esbuild.TransformOptions) | [`@mrgrain/cdk-esbuild.TransformerProps`](#@mrgrain/cdk-esbuild.TransformerProps) - -Support for `TransformOptions` is deprecated. Please provide `TransformerProps`! +- *Type:* [`@mrgrain/cdk-esbuild.TransformerProps`](#@mrgrain/cdk-esbuild.TransformerProps) -Props to change the behaviour of the transformer. +Props to change the behavior of the transformer. Default values for `transformOptions`: - `loader='ts'`