diff --git a/smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/RuntimeConfigGenerator.java b/smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/RuntimeConfigGenerator.java index 9a76cd951ae..0b25cdc290f 100644 --- a/smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/RuntimeConfigGenerator.java +++ b/smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/RuntimeConfigGenerator.java @@ -99,9 +99,8 @@ final class RuntimeConfigGenerator { writer.addDependency(TypeScriptDependency.AWS_SDK_UTIL_USER_AGENT_NODE); writer.addImport("defaultUserAgent", "defaultUserAgent", TypeScriptDependency.AWS_SDK_UTIL_USER_AGENT_NODE.packageName); - writer.addImport("name", "name", "./package.json"); - writer.addImport("version", "version", "./package.json"); - writer.write("defaultUserAgent: defaultUserAgent(name, version),"); + writer.addDefaultImport("packageInfo", "./package.json"); + writer.write("defaultUserAgent: defaultUserAgent(packageInfo.name, packageInfo.version),"); } ); private final Map> browserRuntimeConfigDefaults = MapUtils.of( @@ -163,9 +162,8 @@ final class RuntimeConfigGenerator { writer.addDependency(TypeScriptDependency.AWS_SDK_UTIL_USER_AGENT_BROWSER); writer.addImport("defaultUserAgent", "defaultUserAgent", TypeScriptDependency.AWS_SDK_UTIL_USER_AGENT_BROWSER.packageName); - writer.addImport("name", "name", "./package.json"); - writer.addImport("version", "version", "./package.json"); - writer.write("defaultUserAgent: defaultUserAgent(name, version),"); + writer.addDefaultImport("packageInfo", "./package.json"); + writer.write("defaultUserAgent: defaultUserAgent(packageInfo.name, packageInfo.version),"); } ); private final Map> reactNativeRuntimeConfigDefaults = MapUtils.of( @@ -182,9 +180,9 @@ final class RuntimeConfigGenerator { writer.write("urlParser: parseUrl,"); }, "defaultUserAgent", writer -> { - writer.addImport("name", "name", "./package.json"); - writer.addImport("version", "version", "./package.json"); - writer.write("defaultUserAgent: `aws-sdk-js-v3-react-native-$${name}/$${version}`,"); + writer.addDefaultImport("packageInfo", "./package.json"); + writer.write("defaultUserAgent: " + + "`aws-sdk-js-v3-react-native-$${packageInfo.name}/$${packageInfo.version}`,"); } ); private final Map> sharedRuntimeConfigDefaults = MapUtils.of( diff --git a/smithy-typescript-codegen/src/test/java/software/amazon/smithy/typescript/codegen/RuntimeConfigGeneratorTest.java b/smithy-typescript-codegen/src/test/java/software/amazon/smithy/typescript/codegen/RuntimeConfigGeneratorTest.java index c116eec2dbd..08c2a9a8b37 100644 --- a/smithy-typescript-codegen/src/test/java/software/amazon/smithy/typescript/codegen/RuntimeConfigGeneratorTest.java +++ b/smithy-typescript-codegen/src/test/java/software/amazon/smithy/typescript/codegen/RuntimeConfigGeneratorTest.java @@ -92,6 +92,7 @@ public Map> getRuntimeConfigWriters( // Does the runtimeConfig.ts file expand the template properties properly? String runtimeConfigContents = manifest.getFileString("runtimeConfig.ts").get(); + assertThat(runtimeConfigContents, containsString("import packageInfo from \"./package.json\"")); assertThat(runtimeConfigContents, containsString("import { ClientDefaults } from \"./ExampleClient\";")); assertThat(runtimeConfigContents, containsString("syn: 'ack2',")); @@ -99,6 +100,7 @@ public Map> getRuntimeConfigWriters( // Does the runtimeConfig.browser.ts file expand the template properties properly? String runtimeConfigBrowserContents = manifest.getFileString("runtimeConfig.browser.ts").get(); + assertThat(runtimeConfigContents, containsString("import packageInfo from \"./package.json\"")); assertThat(runtimeConfigBrowserContents, containsString("import { ClientDefaults } from \"./ExampleClient\";")); assertThat(runtimeConfigContents, containsString("syn: 'ack2',")); @@ -106,6 +108,7 @@ public Map> getRuntimeConfigWriters( // Does the runtimeConfig.native.ts file expand the browser template properties properly? String runtimeConfigNativeContents = manifest.getFileString("runtimeConfig.native.ts").get(); + assertThat(runtimeConfigContents, containsString("import packageInfo from \"./package.json\"")); assertThat(runtimeConfigNativeContents, containsString("import { ClientDefaults } from \"./ExampleClient\";")); assertThat(runtimeConfigNativeContents,