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

feat(codegen): move source files to 'src' folder #2844

Merged
merged 12 commits into from
Sep 29, 2021
Merged
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ codegen/sdk-codegen/smithy-build.json

coverage
dist
dist-*

/verdaccio/*
!/verdaccio/config.yaml
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ public Map<String, Consumer<TypeScriptWriter>> getRuntimeConfigWriters(
AwsDependency.STS_CLIENT.packageName);
} else {
writer.addImport("decorateDefaultCredentialProvider", "decorateDefaultCredentialProvider",
"./" + STS_ROLE_ASSUMERS_FILE);
"./src/" + STS_ROLE_ASSUMERS_FILE);
}
writer.addDependency(AwsDependency.CREDENTIAL_PROVIDER_NODE);
writer.addImport("defaultProvider", "credentialDefaultProvider",
Expand All @@ -206,19 +206,19 @@ public void writeAdditionalFiles(
String noTouchNoticePrefix = "// Please do not touch this file. It's generated from template in:\n"
+ "// https://github.com/aws/aws-sdk-js-v3/blob/main/codegen/smithy-aws-typescript-codegen/"
+ "src/main/resources/software/amazon/smithy/aws/typescript/codegen/";
writerFactory.accept("defaultRoleAssumers.ts", writer -> {
writerFactory.accept("src/defaultRoleAssumers.ts", writer -> {
trivikr marked this conversation as resolved.
Show resolved Hide resolved
String resourceName = String.format("%s%s.ts", STS_CLIENT_PREFIX, ROLE_ASSUMERS_FILE);
String source = IoUtils.readUtf8Resource(getClass(), resourceName);
writer.write("$L$L", noTouchNoticePrefix, resourceName);
writer.write("$L", source);
});
writerFactory.accept("defaultStsRoleAssumers.ts", writer -> {
writerFactory.accept("src/defaultStsRoleAssumers.ts", writer -> {
String resourceName = String.format("%s%s.ts", STS_CLIENT_PREFIX, STS_ROLE_ASSUMERS_FILE);
String source = IoUtils.readUtf8Resource(getClass(), resourceName);
writer.write("$L$L", noTouchNoticePrefix, resourceName);
writer.write("$L", source);
});
writerFactory.accept("defaultRoleAssumers.spec.ts", writer -> {
writerFactory.accept("test/defaultRoleAssumers.spec.ts", writer -> {
trivikr marked this conversation as resolved.
Show resolved Hide resolved
String resourceName = String.format("%s%s.ts", STS_CLIENT_PREFIX, ROLE_ASSUMERS_TEST_FILE);
String source = IoUtils.readUtf8Resource(getClass(), resourceName);
writer.write("$L$L", noTouchNoticePrefix, resourceName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import java.util.function.Consumer;
import software.amazon.smithy.codegen.core.SymbolProvider;
import software.amazon.smithy.model.Model;
import software.amazon.smithy.typescript.codegen.CodegenUtils;
import software.amazon.smithy.typescript.codegen.LanguageTarget;
import software.amazon.smithy.typescript.codegen.TypeScriptDependency;
import software.amazon.smithy.typescript.codegen.TypeScriptSettings;
Expand All @@ -47,7 +48,7 @@ public void writeAdditionalFiles(
return;
}

writerFactory.accept("endpoints.ts", writer -> {
writerFactory.accept(CodegenUtils.SOURCE_FOLDER + "/endpoints.ts", writer -> {
new EndpointGenerator(settings.getService(model), writer).run();
});
}
Expand Down Expand Up @@ -83,7 +84,8 @@ public Map<String, Consumer<TypeScriptWriter>> getRuntimeConfigWriters(
switch (target) {
case SHARED:
return MapUtils.of("regionInfoProvider", writer -> {
writer.addImport("defaultRegionInfoProvider", "defaultRegionInfoProvider", "./endpoints");
writer.addImport("defaultRegionInfoProvider", "defaultRegionInfoProvider",
"./" + CodegenUtils.SOURCE_FOLDER + "/endpoints");
writer.write("defaultRegionInfoProvider");
});
default:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ private static Symbol updateServiceSymbol(Symbol symbol, String serviceId) {
.collect(Collectors.joining("")) + "Client";
return symbol.toBuilder()
.name(name)
.namespace("./" + name, "/")
.definitionFile(name + ".ts")
.namespace("./src/" + name, "/")
.definitionFile("./src/" + name + ".ts")
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/build/
/coverage/
/docs/
/dist/
/dist-*
*.tsbuildinfo
*.tgz
*.log
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,11 @@ jest.mock("@aws-sdk/node-http-handler", () => ({
streamCollector: jest.fn(),
}));

import { getDefaultRoleAssumer, getDefaultRoleAssumerWithWebIdentity } from "./defaultRoleAssumers";
import type { AssumeRoleCommandInput } from "./commands/AssumeRoleCommand";
import { NodeHttpHandler, streamCollector } from "@aws-sdk/node-http-handler";
import { AssumeRoleWithWebIdentityCommandInput } from "./commands/AssumeRoleWithWebIdentityCommand";

import type { AssumeRoleCommandInput } from "../src/commands/AssumeRoleCommand";
import { AssumeRoleWithWebIdentityCommandInput } from "../src/commands/AssumeRoleWithWebIdentityCommand";
import { getDefaultRoleAssumer, getDefaultRoleAssumerWithWebIdentity } from "../src/defaultRoleAssumers";
const mockConstructorInput = jest.fn();
jest.mock("./STSClient", () => ({
STSClient: function (params: any) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import software.amazon.smithy.build.PluginContext;
import software.amazon.smithy.model.Model;
import software.amazon.smithy.model.node.Node;
import software.amazon.smithy.typescript.codegen.CodegenUtils;
import software.amazon.smithy.typescript.codegen.TypeScriptCodegenPlugin;

public class AddAwsAuthPluginTest {
Expand Down Expand Up @@ -37,18 +38,18 @@ public void awsClient() {
containsString(AwsDependency.CREDENTIAL_PROVIDER_NODE.packageName));

// Check config interface fields
assertThat(manifest.getFileString("NotSameClient.ts").get(), containsString("credentialDefaultProvider?"));
assertThat(manifest.getFileString("NotSameClient.ts").get(), not(containsString("signingName")));
assertThat(manifest.getFileString(CodegenUtils.SOURCE_FOLDER + "/NotSameClient.ts").get(), containsString("credentialDefaultProvider?"));
assertThat(manifest.getFileString(CodegenUtils.SOURCE_FOLDER + "/NotSameClient.ts").get(), not(containsString("signingName")));

// Check config files
assertThat(manifest.getFileString("runtimeConfig.ts").get(),
assertThat(manifest.getFileString(CodegenUtils.SOURCE_FOLDER + "/runtimeConfig.ts").get(),
containsString("decorateDefaultCredentialProvider"));
assertThat(manifest.getFileString("runtimeConfig.browser.ts").get(), containsString("Credential is missing"));
assertThat(manifest.getFileString("runtimeConfig.shared.ts").get(), not(containsString("signingName:")));
assertThat(manifest.getFileString(CodegenUtils.SOURCE_FOLDER + "/runtimeConfig.browser.ts").get(), containsString("Credential is missing"));
assertThat(manifest.getFileString(CodegenUtils.SOURCE_FOLDER + "/runtimeConfig.shared.ts").get(), not(containsString("signingName:")));

// Check the config resolution and middleware plugin
assertThat(manifest.getFileString("NotSameClient.ts").get(), containsString("resolveAwsAuthConfig"));
assertThat(manifest.getFileString("NotSameClient.ts").get(), containsString("getAwsAuthPlugin"));
assertThat(manifest.getFileString(CodegenUtils.SOURCE_FOLDER + "/NotSameClient.ts").get(), containsString("resolveAwsAuthConfig"));
assertThat(manifest.getFileString(CodegenUtils.SOURCE_FOLDER + "/NotSameClient.ts").get(), containsString("getAwsAuthPlugin"));
}

@Test
Expand Down Expand Up @@ -76,18 +77,18 @@ public void sigV4GenericClient() {
containsString(AwsDependency.CREDENTIAL_PROVIDER_NODE.packageName));

// Check config interface fields
assertThat(manifest.getFileString("SsdkExampleSigV4Client.ts").get(), containsString("credentialDefaultProvider?"));
assertThat(manifest.getFileString("SsdkExampleSigV4Client.ts").get(), containsString("signingName?"));
assertThat(manifest.getFileString(CodegenUtils.SOURCE_FOLDER + "/SsdkExampleSigV4Client.ts").get(), containsString("credentialDefaultProvider?"));
assertThat(manifest.getFileString(CodegenUtils.SOURCE_FOLDER + "/SsdkExampleSigV4Client.ts").get(), containsString("signingName?"));

// Check config files
assertThat(manifest.getFileString("runtimeConfig.ts").get(),
assertThat(manifest.getFileString(CodegenUtils.SOURCE_FOLDER + "/runtimeConfig.ts").get(),
containsString("decorateDefaultCredentialProvider"));
assertThat(manifest.getFileString("runtimeConfig.browser.ts").get(), containsString("Credential is missing"));
assertThat(manifest.getFileString("runtimeConfig.shared.ts").get(), containsString("signingName:"));
assertThat(manifest.getFileString(CodegenUtils.SOURCE_FOLDER + "/runtimeConfig.browser.ts").get(), containsString("Credential is missing"));
assertThat(manifest.getFileString(CodegenUtils.SOURCE_FOLDER + "/runtimeConfig.shared.ts").get(), containsString("signingName:"));

// Check the config resolution and middleware plugin
assertThat(manifest.getFileString("SsdkExampleSigV4Client.ts").get(), containsString("resolveSigV4AuthConfig"));
assertThat(manifest.getFileString("SsdkExampleSigV4Client.ts").get(), containsString("getSigV4AuthPlugin"));
assertThat(manifest.getFileString(CodegenUtils.SOURCE_FOLDER + "/SsdkExampleSigV4Client.ts").get(), containsString("resolveSigV4AuthConfig"));
assertThat(manifest.getFileString(CodegenUtils.SOURCE_FOLDER + "/SsdkExampleSigV4Client.ts").get(), containsString("getSigV4AuthPlugin"));
}

@Test
Expand Down Expand Up @@ -115,17 +116,17 @@ public void notSigV4GenericClient() {
not(containsString(AwsDependency.CREDENTIAL_PROVIDER_NODE.packageName)));

// Check config interface fields
assertThat(manifest.getFileString("SsdkExampleClient.ts").get(), not(containsString("credentialDefaultProvider?")));
assertThat(manifest.getFileString("SsdkExampleClient.ts").get(), not(containsString("signingName?")));
assertThat(manifest.getFileString(CodegenUtils.SOURCE_FOLDER + "/SsdkExampleClient.ts").get(), not(containsString("credentialDefaultProvider?")));
assertThat(manifest.getFileString(CodegenUtils.SOURCE_FOLDER + "/SsdkExampleClient.ts").get(), not(containsString("signingName?")));

// Check config files
assertThat(manifest.getFileString("runtimeConfig.ts").get(),
assertThat(manifest.getFileString(CodegenUtils.SOURCE_FOLDER + "/runtimeConfig.ts").get(),
not(containsString("decorateDefaultCredentialProvider")));
assertThat(manifest.getFileString("runtimeConfig.browser.ts").get(), not(containsString("Credential is missing")));
assertThat(manifest.getFileString("runtimeConfig.shared.ts").get(), not(containsString("signingName:")));
assertThat(manifest.getFileString(CodegenUtils.SOURCE_FOLDER + "/runtimeConfig.browser.ts").get(), not(containsString("Credential is missing")));
assertThat(manifest.getFileString(CodegenUtils.SOURCE_FOLDER + "/runtimeConfig.shared.ts").get(), not(containsString("signingName:")));

// Check the config resolution and middleware plugin
assertThat(manifest.getFileString("SsdkExampleClient.ts").get(), not(containsString("resolveSigV4AuthConfig")));
assertThat(manifest.getFileString("SsdkExampleClient.ts").get(), not(containsString("resolveAwsV4AuthConfig")));
assertThat(manifest.getFileString(CodegenUtils.SOURCE_FOLDER + "/SsdkExampleClient.ts").get(), not(containsString("resolveSigV4AuthConfig")));
assertThat(manifest.getFileString(CodegenUtils.SOURCE_FOLDER + "/SsdkExampleClient.ts").get(), not(containsString("resolveAwsV4AuthConfig")));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import software.amazon.smithy.build.PluginContext;
import software.amazon.smithy.model.Model;
import software.amazon.smithy.model.node.Node;
import software.amazon.smithy.typescript.codegen.CodegenUtils;
import software.amazon.smithy.typescript.codegen.TypeScriptCodegenPlugin;
import software.amazon.smithy.typescript.codegen.TypeScriptDependency;

Expand Down Expand Up @@ -40,13 +41,13 @@ public void awsClient() {
containsString(TypeScriptDependency.CONFIG_RESOLVER.packageName));

// Check config interface fields
assertThat(manifest.getFileString("NotSameClient.ts").get(), containsString("serviceId?:"));
assertThat(manifest.getFileString("NotSameClient.ts").get(), containsString("region?:"));
assertThat(manifest.getFileString(CodegenUtils.SOURCE_FOLDER + "/NotSameClient.ts").get(), containsString("serviceId?:"));
assertThat(manifest.getFileString(CodegenUtils.SOURCE_FOLDER + "/NotSameClient.ts").get(), containsString("region?:"));

// Check config files
assertThat(manifest.getFileString("runtimeConfig.shared.ts").get(), containsString("serviceId: config?.serviceId ?? \"Not Same\""));
assertThat(manifest.getFileString("runtimeConfig.browser.ts").get(), containsString("region: config?.region ?? invalidProvider"));
assertThat(manifest.getFileString("runtimeConfig.ts").get(), containsString("region: config?.region ?? loadNodeConfig"));
assertThat(manifest.getFileString(CodegenUtils.SOURCE_FOLDER + "/runtimeConfig.shared.ts").get(), containsString("serviceId: config?.serviceId ?? \"Not Same\""));
assertThat(manifest.getFileString(CodegenUtils.SOURCE_FOLDER + "/runtimeConfig.browser.ts").get(), containsString("region: config?.region ?? invalidProvider"));
assertThat(manifest.getFileString(CodegenUtils.SOURCE_FOLDER + "/runtimeConfig.ts").get(), containsString("region: config?.region ?? loadNodeConfig"));
}

@Test
Expand Down Expand Up @@ -76,13 +77,13 @@ public void sigV4GenericClient() {
containsString(TypeScriptDependency.CONFIG_RESOLVER.packageName));

// Check config interface fields
assertThat(manifest.getFileString("SsdkExampleSigV4Client.ts").get(), not(containsString("serviceId?:")));
assertThat(manifest.getFileString("SsdkExampleSigV4Client.ts").get(), containsString("region?:"));
assertThat(manifest.getFileString(CodegenUtils.SOURCE_FOLDER + "/SsdkExampleSigV4Client.ts").get(), not(containsString("serviceId?:")));
assertThat(manifest.getFileString(CodegenUtils.SOURCE_FOLDER + "/SsdkExampleSigV4Client.ts").get(), containsString("region?:"));

// Check config files
assertThat(manifest.getFileString("runtimeConfig.shared.ts").get(), not(containsString("serviceId:")));
assertThat(manifest.getFileString("runtimeConfig.browser.ts").get(), containsString("region: config?.region ?? invalidProvider"));
assertThat(manifest.getFileString("runtimeConfig.ts").get(), containsString("region: config?.region ?? loadNodeConfig"));
assertThat(manifest.getFileString(CodegenUtils.SOURCE_FOLDER + "/runtimeConfig.shared.ts").get(), not(containsString("serviceId:")));
assertThat(manifest.getFileString(CodegenUtils.SOURCE_FOLDER + "/runtimeConfig.browser.ts").get(), containsString("region: config?.region ?? invalidProvider"));
assertThat(manifest.getFileString(CodegenUtils.SOURCE_FOLDER + "/runtimeConfig.ts").get(), containsString("region: config?.region ?? loadNodeConfig"));
}

@Test
Expand Down Expand Up @@ -112,12 +113,12 @@ public void notSigV4GenericClient() {
containsString(TypeScriptDependency.CONFIG_RESOLVER.packageName));

// Check config interface fields
assertThat(manifest.getFileString("SsdkExampleClient.ts").get(), not(containsString("serviceId?:")));
assertThat(manifest.getFileString("SsdkExampleClient.ts").get(), not(containsString("region?:")));
assertThat(manifest.getFileString(CodegenUtils.SOURCE_FOLDER + "/SsdkExampleClient.ts").get(), not(containsString("serviceId?:")));
assertThat(manifest.getFileString(CodegenUtils.SOURCE_FOLDER + "/SsdkExampleClient.ts").get(), not(containsString("region?:")));

// Check config files
assertThat(manifest.getFileString("runtimeConfig.shared.ts").get(), not(containsString("serviceId:")));
assertThat(manifest.getFileString("runtimeConfig.browser.ts").get(), not(containsString("region:")));
assertThat(manifest.getFileString("runtimeConfig.ts").get(), not(containsString("region:")));
assertThat(manifest.getFileString(CodegenUtils.SOURCE_FOLDER + "/runtimeConfig.shared.ts").get(), not(containsString("serviceId:")));
assertThat(manifest.getFileString(CodegenUtils.SOURCE_FOLDER + "/runtimeConfig.browser.ts").get(), not(containsString("region:")));
assertThat(manifest.getFileString(CodegenUtils.SOURCE_FOLDER + "/runtimeConfig.ts").get(), not(containsString("region:")));
}
}
Loading