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

Default import package.json for spec compatibility #209

Merged
merged 3 commits into from
Sep 14, 2020
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
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