From f7565a0ccf2626d3801839acef656e1b54e9f046 Mon Sep 17 00:00:00 2001 From: Alexander Harris Date: Mon, 22 Nov 2021 12:38:22 -0800 Subject: [PATCH] fix: remove unnecessary types file from generated index --- ...act-index-studio-template-renderer.test.ts | 34 +++++++++++++++++++ .../react-index-studio-template-renderer.ts | 1 + 2 files changed, 35 insertions(+) create mode 100644 packages/codegen-ui-react/lib/__tests__/react-index-studio-template-renderer.test.ts diff --git a/packages/codegen-ui-react/lib/__tests__/react-index-studio-template-renderer.test.ts b/packages/codegen-ui-react/lib/__tests__/react-index-studio-template-renderer.test.ts new file mode 100644 index 000000000..f2805d237 --- /dev/null +++ b/packages/codegen-ui-react/lib/__tests__/react-index-studio-template-renderer.test.ts @@ -0,0 +1,34 @@ +/* + Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + + Licensed under the Apache License, Version 2.0 (the "License"). + You may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + */ +import { ReactRenderConfig } from '..'; +import { ReactIndexStudioTemplateRenderer } from '../react-index-studio-template-renderer'; + +class ReactIndexStudioTemplateRendererWithExposedRenderConfig extends ReactIndexStudioTemplateRenderer { + getRenderConfig(): ReactRenderConfig { + return this.renderConfig; + } +} + +describe('ReactIndexStudioTemplateRenderer', () => { + describe('constructor', () => { + test('overrides renderTypeDeclarations to false', () => { + const renderer = new ReactIndexStudioTemplateRendererWithExposedRenderConfig([], { + renderTypeDeclarations: true, + }); + expect(renderer.getRenderConfig().renderTypeDeclarations).toBeFalsy(); + }); + }); +}); diff --git a/packages/codegen-ui-react/lib/react-index-studio-template-renderer.ts b/packages/codegen-ui-react/lib/react-index-studio-template-renderer.ts index 620a2dd1b..a42ed39cc 100644 --- a/packages/codegen-ui-react/lib/react-index-studio-template-renderer.ts +++ b/packages/codegen-ui-react/lib/react-index-studio-template-renderer.ts @@ -49,6 +49,7 @@ export class ReactIndexStudioTemplateRenderer extends StudioTemplateRenderer< this.renderConfig = { ...defaultRenderConfig, ...renderConfig, + renderTypeDeclarations: false, // Never render type declarations for index.js|ts file. }; this.fileName = `index.${scriptKindToFileExtensionNonReact(this.renderConfig.script)}`; }