Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: remove deprecated support of top-level TransformOptions on InlineCode classes #281

Merged
merged 3 commits into from
Dec 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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