From 95d757b06aac34449ed4658f659a503dc44aeca1 Mon Sep 17 00:00:00 2001 From: Alexander Fenster Date: Fri, 8 Nov 2019 16:02:06 -0800 Subject: [PATCH] fix: better default exports in src/index.ts (#120) * fix: better default exports in src/index.ts * tslint disable --- templates/typescript_gapic/src/index.ts.njk | 16 +++++++++++++--- .../testdata/keymanager/src/index.ts.baseline | 6 ++++-- .../test/testdata/showcase/src/index.ts.baseline | 6 ++++-- .../testdata/texttospeech/src/index.ts.baseline | 6 ++++-- .../testdata/translate/src/index.ts.baseline | 6 ++++-- 5 files changed, 29 insertions(+), 11 deletions(-) diff --git a/templates/typescript_gapic/src/index.ts.njk b/templates/typescript_gapic/src/index.ts.njk index 21aa891d3..78a430ada 100644 --- a/templates/typescript_gapic/src/index.ts.njk +++ b/templates/typescript_gapic/src/index.ts.njk @@ -18,8 +18,18 @@ limitations under the License. {% import "../_license.njk" as license -%} {{license.license()}} import * as {{ api.naming.version }} from './{{ api.naming.version }}'; -export {{ '{' + api.naming.version + '}' }}; -{% for service in api.services -%} +{%- for service in api.services %} const {{ service.name.toPascalCase() }}Client = {{ api.naming.version }}.{{ service.name.toPascalCase() }}Client; -export {{ '{' + service.name.toPascalCase() + 'Client' + '}' }}; {%- endfor %} +export { {{- api.naming.version }} +{%- for service in api.services -%} +, {{ service.name.toPascalCase() + 'Client' }} +{%- endfor -%} +}; +// For compatibility with JavaScript libraries we need to provide this default export: +// tslint:disable-next-line no-default-export +export default { {{- api.naming.version }} +{%- for service in api.services -%} +, {{ service.name.toPascalCase() + 'Client' }} +{%- endfor -%} +}; diff --git a/typescript/test/testdata/keymanager/src/index.ts.baseline b/typescript/test/testdata/keymanager/src/index.ts.baseline index 973c582e0..6ebde6271 100644 --- a/typescript/test/testdata/keymanager/src/index.ts.baseline +++ b/typescript/test/testdata/keymanager/src/index.ts.baseline @@ -17,6 +17,8 @@ // ** All changes to this file may be overwritten. ** import * as v1 from './v1'; -export {v1}; const KeyManagementServiceClient = v1.KeyManagementServiceClient; -export {KeyManagementServiceClient}; +export {v1, KeyManagementServiceClient}; +// For compatibility with JavaScript libraries we need to provide this default export: +// tslint:disable-next-line no-default-export +export default {v1, KeyManagementServiceClient}; diff --git a/typescript/test/testdata/showcase/src/index.ts.baseline b/typescript/test/testdata/showcase/src/index.ts.baseline index bb32a1d31..685575503 100644 --- a/typescript/test/testdata/showcase/src/index.ts.baseline +++ b/typescript/test/testdata/showcase/src/index.ts.baseline @@ -17,6 +17,8 @@ // ** All changes to this file may be overwritten. ** import * as v1beta1 from './v1beta1'; -export {v1beta1}; const EchoClient = v1beta1.EchoClient; -export {EchoClient}; +export {v1beta1, EchoClient}; +// For compatibility with JavaScript libraries we need to provide this default export: +// tslint:disable-next-line no-default-export +export default {v1beta1, EchoClient}; diff --git a/typescript/test/testdata/texttospeech/src/index.ts.baseline b/typescript/test/testdata/texttospeech/src/index.ts.baseline index 73a2bd8e7..d6084cc33 100644 --- a/typescript/test/testdata/texttospeech/src/index.ts.baseline +++ b/typescript/test/testdata/texttospeech/src/index.ts.baseline @@ -17,6 +17,8 @@ // ** All changes to this file may be overwritten. ** import * as v1 from './v1'; -export {v1}; const TextToSpeechClient = v1.TextToSpeechClient; -export {TextToSpeechClient}; +export {v1, TextToSpeechClient}; +// For compatibility with JavaScript libraries we need to provide this default export: +// tslint:disable-next-line no-default-export +export default {v1, TextToSpeechClient}; diff --git a/typescript/test/testdata/translate/src/index.ts.baseline b/typescript/test/testdata/translate/src/index.ts.baseline index 2f98e1dd8..01defa5e5 100644 --- a/typescript/test/testdata/translate/src/index.ts.baseline +++ b/typescript/test/testdata/translate/src/index.ts.baseline @@ -17,6 +17,8 @@ // ** All changes to this file may be overwritten. ** import * as v3beta1 from './v3beta1'; -export {v3beta1}; const TranslationServiceClient = v3beta1.TranslationServiceClient; -export {TranslationServiceClient}; +export {v3beta1, TranslationServiceClient}; +// For compatibility with JavaScript libraries we need to provide this default export: +// tslint:disable-next-line no-default-export +export default {v3beta1, TranslationServiceClient};