Skip to content

Commit

Permalink
chore: remove deprecated support of top-level TransformOptions on Inl…
Browse files Browse the repository at this point in the history
…ineCode classes (#281)

BREAKING CHANGE: `InlineCode` classes now only take `TransformerProps` as second argument. Please provide any transform options via `props.transformOptions`. Previously `TransformOptions` could be provided at the top-level.
  • Loading branch information
mrgrain authored Dec 18, 2022
1 parent f1fd77a commit 7159ef9
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 79 deletions.
36 changes: 14 additions & 22 deletions API.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/bundler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
48 changes: 9 additions & 39 deletions src/inline-code.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand All @@ -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.
*
Expand All @@ -148,17 +126,15 @@ 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'`
*
* @see https://esbuild.github.io/api/#transform-api
* @stability experimental
*/
props?: TransformerProps | TransformOptions,
props?: TransformerProps,
) {

super(code, transformerProps('js', props));
Expand All @@ -179,17 +155,15 @@ 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'`
*
* @see https://esbuild.github.io/api/#transform-api
* @stability experimental
*/
props?: TransformerProps | TransformOptions,
props?: TransformerProps,
) {
super(code, transformerProps('jsx', props));
}
Expand All @@ -209,17 +183,15 @@ 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'`
*
* @see https://esbuild.github.io/api/#transform-api
* @stability experimental
*/
props?: TransformerProps | TransformOptions,
props?: TransformerProps,
) {
super(code, transformerProps('ts', props));
}
Expand All @@ -239,17 +211,15 @@ 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'`
*
* @see https://esbuild.github.io/api/#transform-api
* @stability experimental
*/
props?: TransformerProps | TransformOptions,
props?: TransformerProps,
) {
super(code, transformerProps('tsx', props));
}
Expand Down
17 changes: 0 additions & 17 deletions test/inline-code.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down

0 comments on commit 7159ef9

Please sign in to comment.