Skip to content

Commit

Permalink
Default import package.json for spec compatibility (#209)
Browse files Browse the repository at this point in the history
Co-authored-by: Raphael Varonos <r.varonos@gmail.com>
  • Loading branch information
trivikr and rvaronos authored Sep 14, 2020
1 parent 9c321fc commit 4266f89
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, Consumer<TypeScriptWriter>> browserRuntimeConfigDefaults = MapUtils.of(
Expand Down Expand Up @@ -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<String, Consumer<TypeScriptWriter>> reactNativeRuntimeConfigDefaults = MapUtils.of(
Expand All @@ -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<String, Consumer<TypeScriptWriter>> sharedRuntimeConfigDefaults = MapUtils.of(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,20 +92,23 @@ public Map<String, Consumer<TypeScriptWriter>> 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',"));
assertThat(runtimeConfigSharedContents, containsString("foo: 'bar',"));

// 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',"));
assertThat(runtimeConfigSharedContents, containsString("foo: 'bar',"));

// 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,
Expand Down

0 comments on commit 4266f89

Please sign in to comment.