Skip to content

[WIP] feat: move source files to "src" folder #432

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

Closed
wants to merge 36 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
f6a5371
chore: add SOURCE_FOLDER to CodegenUtils
trivikr Sep 28, 2021
34658f6
chore: move pagination files in src folder
trivikr Sep 28, 2021
eea3fd9
chore: move waiters to src folder
trivikr Sep 28, 2021
926d480
chore: move protocols to src folder
trivikr Sep 28, 2021
480c688
chore: move runtimeConfig to src folder
trivikr Sep 28, 2021
bdfe8c2
chore: move models to src folder
trivikr Sep 28, 2021
577884d
chore: move aggregated client to src folder
trivikr Sep 28, 2021
a051115
chore: move index to src folder
trivikr Sep 28, 2021
b435bd8
chore: move files using shapeWriter to src folder
trivikr Sep 28, 2021
70df6ae
chore: remove duplicate index.ts written outside src folder
trivikr Sep 28, 2021
4d9d063
fix: remove src folder outside OutputFileLocation
trivikr Sep 28, 2021
29df1bf
fix: remove redundant prefix in SymbolVisitor
trivikr Sep 28, 2021
f4d02c0
fix: command imports
trivikr Sep 28, 2021
aa2e63a
fix: runtimeConfig import in ServiceGenerator
trivikr Sep 28, 2021
bdbc60c
fix: modular client import in aggregated client
trivikr Sep 28, 2021
28dbf63
fix: models import
trivikr Sep 28, 2021
fa8c1e2
fix: Client import in waiters
trivikr Sep 28, 2021
003a704
fix: imports in pagination
trivikr Sep 28, 2021
1ca2bde
fix: imports in Commands
trivikr Sep 28, 2021
f63e4ca
fix: prefix src in Symbol definition file
trivikr Sep 28, 2021
3ce4f3b
fix: self imports in models and commands
trivikr Sep 28, 2021
6b26a7a
chore: remove duplicate code by creating prefixedNamespace
trivikr Sep 28, 2021
5001977
fix: exports in models/index.ts
trivikr Sep 28, 2021
0620c5d
chore: remove redundant src folder prefix from non-modular client
trivikr Sep 28, 2021
53b6977
chore: move src folder prefix to output file name
trivikr Sep 28, 2021
97c989d
chore: do not prefix src in namespace
trivikr Sep 28, 2021
fc8c150
fix: prefix src in namespace
trivikr Sep 28, 2021
a686e52
chore: remove redundant code from waiter
trivikr Sep 28, 2021
eaacf01
chore: replace dist/* with dist-*
trivikr Sep 28, 2021
8e89668
chore: update tsconfig
trivikr Sep 28, 2021
900216c
chore: clean dist-* in clean:dist
trivikr Sep 28, 2021
a5fbce8
fix: gradlew build
trivikr Sep 29, 2021
2b36d42
test: prefix SOURCE_FOLDER while checking manifest file
trivikr Sep 29, 2021
8a937f3
fix: browser and react-native specific config
trivikr Sep 29, 2021
0162f6b
test: SymbolVisitor
trivikr Sep 29, 2021
2340bba
chore: add protocol_tests in test folder
trivikr Sep 29, 2021
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 @@ -36,6 +36,8 @@
@SmithyUnstableApi
public final class CodegenUtils {

public static final String SOURCE_FOLDER = "src";

private CodegenUtils() {}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ void execute() {
String baseName = protocol.getName().toLowerCase(Locale.US)
.replace("-", "_")
.replace(".", "_");
String protocolTestFileName = String.format("tests/functional/%s.spec.ts", baseName);
String protocolTestFileName = String.format("test/functional/%s.spec.ts", baseName);
context.setDeferredWriter(() -> writers.checkoutFileWriter(protocolTestFileName));
protocolGenerator.generateProtocolTests(context);
}
Expand Down Expand Up @@ -373,7 +373,8 @@ public Void serviceShape(ServiceShape shape) {

if (protocolGenerator != null) {
LOGGER.info("Generating serde for protocol " + protocolGenerator.getName() + " on " + shape.getId());
String fileName = "protocols/" + ProtocolGenerator.getSanitizedName(protocolGenerator.getName()) + ".ts";
String fileName = CodegenUtils.SOURCE_FOLDER + "/protocols/"
+ ProtocolGenerator.getSanitizedName(protocolGenerator.getName()) + ".ts";
writers.useFileWriter(fileName, writer -> {
ProtocolGenerator.GenerationContext context = new ProtocolGenerator.GenerationContext();
context.setProtocolName(protocolGenerator.getName());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,8 @@ private void writeSerdeDispatcher(boolean isInput) {
? ProtocolGenerator.getSerFunctionName(symbol, protocolGenerator.getName())
: ProtocolGenerator.getDeserFunctionName(symbol, protocolGenerator.getName());
writer.addImport(serdeFunctionName, serdeFunctionName,
"./protocols/" + ProtocolGenerator.getSanitizedName(protocolGenerator.getName()));
"./" + CodegenUtils.SOURCE_FOLDER + "/protocols/"
+ ProtocolGenerator.getSanitizedName(protocolGenerator.getName()));
writer.write("return $L($L, context);", serdeFunctionName, isInput ? "input" : "output");
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@
public final class HttpProtocolTestGenerator implements Runnable {

private static final Logger LOGGER = Logger.getLogger(HttpProtocolTestGenerator.class.getName());
private static final String TEST_CASE_FILE_TEMPLATE = "tests/functional/%s.spec.ts";
private static final String TEST_CASE_FILE_TEMPLATE = "test/functional/%s.spec.ts";

private final TypeScriptSettings settings;
private final Model model;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ static void writeIndex(

// write export statement for models
writer.write("export * from \"./models/index\";");
fileManifest.writeFile("index.ts", writer.toString());
fileManifest.writeFile(CodegenUtils.SOURCE_FOLDER + "/index.ts", writer.toString());
}

private static void writeProtocolExports(ProtocolGenerator protocolGenerator, TypeScriptWriter writer) {
Expand Down Expand Up @@ -115,26 +115,29 @@ private static void writeClientExports(
writer.write("export * from \"./commands/" + symbolProvider.toSymbol(operation).getName() + "\";");
if (operation.hasTrait(PaginatedTrait.ID)) {
hasPaginatedOperation = true;
String modulePath = PaginationGenerator.getOutputFilelocation(operation);
writer.write("export * from \"./$L\";", modulePath.replace(".ts", ""));
String modulePath = PaginationGenerator.getOutputFilelocation(operation)
.replaceFirst(CodegenUtils.SOURCE_FOLDER, "");
writer.write("export * from \".$L\";", modulePath.replace(".ts", ""));
}
if (operation.hasTrait(WaitableTrait.ID)) {
WaitableTrait waitableTrait = operation.expectTrait(WaitableTrait.class);
waitableTrait.getWaiters().forEach((String waiterName, Waiter waiter) -> {
String modulePath = WaiterGenerator.getOutputFileLocation(waiterName);
writer.write("export * from \"./$L\";", modulePath.replace(".ts", ""));
String modulePath = WaiterGenerator.getOutputFileLocation(waiterName)
.replaceFirst(CodegenUtils.SOURCE_FOLDER, "");
writer.write("export * from \".$L\";", modulePath.replace(".ts", ""));
});
}
}
if (hasPaginatedOperation) {
String modulePath = PaginationGenerator.PAGINATION_INTERFACE_FILE;
writer.write("export * from \"./$L\";", modulePath.replace(".ts", ""));
String modulePath = PaginationGenerator.PAGINATION_INTERFACE_FILE
.replaceFirst(CodegenUtils.SOURCE_FOLDER, "");
writer.write("export * from \".$L\";", modulePath.replace(".ts", ""));
}

// Write each custom export.
for (TypeScriptIntegration integration : integrations) {
integration.writeAdditionalExports(settings, model, symbolProvider, writer);
}
fileManifest.writeFile("index.ts", writer.toString());
fileManifest.writeFile(CodegenUtils.SOURCE_FOLDER + "/index.ts", writer.toString());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,6 @@ String getTemplateFileName() {
abstract String getTemplateFileName();

String getTargetFilename() {
return getTemplateFileName().replace(".template", "");
return CodegenUtils.SOURCE_FOLDER + "/" + getTemplateFileName().replace(".template", "");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,10 @@ static void writePackageJson(
if (settings.generateClient()) {
// Add the Node vs Browser hook.
node = node.withMember("browser", Node.objectNode()
.withMember("./runtimeConfig", "./runtimeConfig.browser"));
.withMember("./dist-es/runtimeConfig", "./dist-es/runtimeConfig.browser"));
// Add the ReactNative hook.
node = node.withMember("react-native", Node.objectNode()
.withMember("./runtimeConfig", "./runtimeConfig.native"));
.withMember("./dist-es/runtimeConfig", "./dist-es/runtimeConfig.native"));
}

// Set the package to private if required.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
@SmithyInternalApi
final class PaginationGenerator implements Runnable {

static final String PAGINATION_INTERFACE_FILE = "pagination/Interfaces.ts";
static final String PAGINATION_INTERFACE_FILE = CodegenUtils.SOURCE_FOLDER + "/pagination/Interfaces.ts";

private final TypeScriptWriter writer;
private final PaginationInfo paginatedInfo;
Expand Down Expand Up @@ -89,9 +89,7 @@ public void run() {
outputSymbol.getNamespace());
String nonModularLocation = serviceSymbol.getNamespace()
.replace(serviceSymbol.getName(), nonModularServiceName);
writer.addImport(nonModularServiceName,
nonModularServiceName,
nonModularLocation);
writer.addImport(nonModularServiceName, nonModularServiceName, nonModularLocation);
writer.addImport(serviceSymbol.getName(), serviceSymbol.getName(), serviceSymbol.getNamespace());

// Import Pagination types
Expand All @@ -104,7 +102,7 @@ public void run() {
}

static String getOutputFilelocation(OperationShape operation) {
return "pagination/" + operation.getId().getName() + "Paginator.ts";
return CodegenUtils.SOURCE_FOLDER + "/pagination/" + operation.getId().getName() + "Paginator.ts";
}

static void generateServicePaginationInterfaces(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,8 @@ final class RuntimeConfigGenerator {
void generate(LanguageTarget target) {
String template = TypeScriptUtils.loadResourceAsString(target.getTemplateFileName());
String contents = template
.replace("${clientModuleName}", symbolProvider.toSymbol(service).getNamespace())
.replace("${clientModuleName}", symbolProvider.toSymbol(service).getNamespace()
.replaceFirst(CodegenUtils.SOURCE_FOLDER + "/", ""))
.replace("${clientConfigName}", symbolProvider.toSymbol(service).getName() + "Config")
.replace("${apiVersion}", service.getVersion())
.replace("$", "$$") // sanitize template place holders.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,8 @@ static String getResolvedConfigTypeName(Symbol symbol) {
@Override
public void run() {
writer.addImport("Client", "__Client", "@aws-sdk/smithy-client");
writer.addImport("getRuntimeConfig", "__getRuntimeConfig", "./runtimeConfig");
writer.addImport("getRuntimeConfig", "__getRuntimeConfig",
"./" + CodegenUtils.SOURCE_FOLDER + "/runtimeConfig");

// Normalize the input and output types of the command to account for
// things like an operation adding input where there once wasn't any
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -407,8 +407,10 @@ private Symbol.Builder createSymbolBuilder(Shape shape, String typeName, String
}

private Symbol.Builder createGeneratedSymbolBuilder(Shape shape, String typeName, String namespace) {
return createSymbolBuilder(shape, typeName, namespace)
.definitionFile(toFilename(namespace));
String prefixedNamespace = "./" + CodegenUtils.SOURCE_FOLDER
+ (namespace.startsWith(".") ? namespace.substring(1) : namespace);
return createSymbolBuilder(shape, typeName, prefixedNamespace)
.definitionFile(toFilename(prefixedNamespace));
}

private String toFilename(String namespace) {
Expand All @@ -421,7 +423,7 @@ private String toFilename(String namespace) {
*/
static final class ModuleNameDelegator {
static final int DEFAULT_CHUNK_SIZE = 300;
static final String SHAPE_NAMESPACE_PREFIX = "./models/";
static final String SHAPE_NAMESPACE_PREFIX = "/models/";

private final Map<Shape, String> visitedModels = new HashMap<>();
private int bucketCount = 0;
Expand All @@ -442,7 +444,7 @@ public String formatModuleName(Shape shape, String name) {
return visitedModels.get(shape);
}
// Add models into buckets no bigger than chunk size.
String path = SHAPE_NAMESPACE_PREFIX + "models_" + bucketCount;
String path = "." + SHAPE_NAMESPACE_PREFIX + "models_" + bucketCount;
visitedModels.put(shape, path);
currentBucketSize++;
if (currentBucketSize == chunkSize) {
Expand All @@ -454,14 +456,15 @@ public String formatModuleName(Shape shape, String name) {

static void writeModelIndex(Model model, SymbolProvider symbolProvider, FileManifest fileManifest) {
TypeScriptWriter writer = new TypeScriptWriter("");
String modelPrefix = "./" + CodegenUtils.SOURCE_FOLDER + SHAPE_NAMESPACE_PREFIX;
model.shapes()
.map(shape -> symbolProvider.toSymbol(shape).getNamespace())
.filter(namespace -> namespace.startsWith(SHAPE_NAMESPACE_PREFIX))
.filter(namespace -> namespace.startsWith(modelPrefix))
.distinct()
.sorted(Comparator.naturalOrder())
.forEach(namespace -> writer.write(
"export * from $S;", namespace.replaceFirst(SHAPE_NAMESPACE_PREFIX, "./")));
fileManifest.writeFile("models/index.ts", writer.toString());
"export * from $S;", namespace.replaceFirst(modelPrefix, "./")));
fileManifest.writeFile(CodegenUtils.SOURCE_FOLDER + "/models/index.ts", writer.toString());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,11 @@ List<SymbolDependency> getDependencies() {
void useShapeWriter(Shape shape, SymbolProvider provider, Consumer<TypeScriptWriter> writerConsumer) {
// Checkout/create the appropriate writer for the shape.
Symbol symbol = provider.toSymbol(shape);
TypeScriptWriter writer = checkoutWriter(symbol.getDefinitionFile());
String fileName = symbol.getDefinitionFile();
if (!fileName.startsWith("./" + CodegenUtils.SOURCE_FOLDER)) {
fileName = "./" + CodegenUtils.SOURCE_FOLDER + "/" + fileName;
}
TypeScriptWriter writer = checkoutWriter(fileName);

// Add any needed DECLARE symbols.
writer.addImportReferences(symbol, SymbolReference.ContextOption.DECLARE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public void run() {
}

public static String getOutputFileLocation(String waiterName) {
return "waiters/waitFor" + waiterName + ".ts";
return CodegenUtils.SOURCE_FOLDER + "/waiters/waitFor" + waiterName + ".ts";
}

private void generateWaiter() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,14 @@
"build:es": "tsc -p tsconfig.es.json",
"build:types": "tsc -p tsconfig.types.json",
"clean": "yarn clean:dist && yarn clean:docs",
"clean:dist": "rimraf ./dist",
"clean:dist": "rimraf ./dist-*",
"clean:docs": "rimraf ./docs",
"downlevel-dts": "downlevel-dts dist/types dist/types/ts3.4",
"downlevel-dts": "downlevel-dts dist-types dist-types/ts3.4",
"test": "jest --coverage --passWithNoTests"
},
"main": "./dist/cjs/index.js",
"types": "./dist/types/index.d.ts",
"module": "./dist/es/index.js",
"browser": {
"./runtimeConfig": "./runtimeConfig.browser"
},
"react-native": {
"./runtimeConfig": "./runtimeConfig.native"
},
"main": "./dist-cjs/index.js",
"types": "./dist-types/index.d.ts",
"module": "./dist-es/index.js",
"sideEffects": false,
"dependencies": {
"tslib": "^2.3.0"
Expand All @@ -40,7 +34,7 @@
},
"typesVersions": {
"<4.0": {
"dist/types/*": ["dist/types/ts3.4/*"]
"dist-types/*": ["dist-types/ts3.4/*"]
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@
"es2015.iterable",
"es2015.symbol.wellknown"
],
"outDir": "dist/es"
"outDir": "dist-es"
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"compilerOptions": {
"rootDir": "./src",
"alwaysStrict": true,
"target": "ES2018",
"module": "commonjs",
Expand All @@ -11,7 +12,7 @@
"incremental": true,
"resolveJsonModule": true,
"esModuleInterop": true,
"outDir": "dist/cjs",
"outDir": "dist-cjs",
"removeComments": true
},
"typedocOptions": {
Expand All @@ -33,5 +34,6 @@
"out": "docs",
"theme": "minimal",
"plugin": ["@aws-sdk/client-documentation-generator"]
}
},
"exclude": ["test/**/*"]
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"compilerOptions": {
"removeComments": false,
"declaration": true,
"declarationDir": "dist/types"
}
"declarationDir": "dist-types"
},
"exclude": ["test/**/*", "dist-types/**/*"]
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,15 @@ public void generatesRuntimeConfigFiles() {
// Did we generate the runtime config files?
// note that asserting the contents of runtime config files is handled in its own unit tests.
Assertions.assertTrue(manifest.hasFile("package.json"));
Assertions.assertTrue(manifest.hasFile("runtimeConfig.browser.ts"));
Assertions.assertTrue(manifest.hasFile("runtimeConfig.ts"));
Assertions.assertTrue(manifest.hasFile("index.ts"));
Assertions.assertTrue(manifest.hasFile(CodegenUtils.SOURCE_FOLDER + "/runtimeConfig.browser.ts"));
Assertions.assertTrue(manifest.hasFile(CodegenUtils.SOURCE_FOLDER + "/runtimeConfig.ts"));
Assertions.assertTrue(manifest.hasFile(CodegenUtils.SOURCE_FOLDER + "/index.ts"));

// Does the package.json file point to the runtime config?
String packageJsonContents = manifest.getFileString("package.json").get();
ObjectNode packageJson = Node.parse(packageJsonContents).expectObjectNode();
assertThat(packageJson.expectObjectMember("browser").getStringMember("./runtimeConfig"),
equalTo(Optional.of(Node.from("./runtimeConfig.browser"))));
assertThat(packageJson.expectObjectMember("browser").getStringMember("./dist-es/runtimeConfig"),
equalTo(Optional.of(Node.from("./dist-es/runtimeConfig.browser"))));
}

@Test
Expand All @@ -69,8 +69,8 @@ public void decoratesSymbolProvider() {

new TypeScriptCodegenPlugin().execute(context);

Assertions.assertTrue(manifest.hasFile("Foo.ts"));
assertThat(manifest.getFileString("Foo.ts").get(), containsString("export class Foo"));
Assertions.assertTrue(manifest.hasFile(CodegenUtils.SOURCE_FOLDER + "/Foo.ts"));
assertThat(manifest.getFileString(CodegenUtils.SOURCE_FOLDER + "/Foo.ts").get(), containsString("export class Foo"));
}

@Test
Expand All @@ -91,12 +91,12 @@ public void generatesServiceClients() {
.build();
new TypeScriptCodegenPlugin().execute(context);

Assertions.assertTrue(manifest.hasFile("Example.ts"));
assertThat(manifest.getFileString("Example.ts").get(),
Assertions.assertTrue(manifest.hasFile(CodegenUtils.SOURCE_FOLDER + "/Example.ts"));
assertThat(manifest.getFileString(CodegenUtils.SOURCE_FOLDER + "/Example.ts").get(),
containsString("export class Example extends ExampleClient"));

Assertions.assertTrue(manifest.hasFile("ExampleClient.ts"));
assertThat(manifest.getFileString("ExampleClient.ts").get(), containsString("export class ExampleClient"));
Assertions.assertTrue(manifest.hasFile(CodegenUtils.SOURCE_FOLDER + "/ExampleClient.ts"));
assertThat(manifest.getFileString(CodegenUtils.SOURCE_FOLDER + "/ExampleClient.ts").get(), containsString("export class ExampleClient"));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ private void testCommmandCodegen(String file, String expectedType) {
.build();

new TypeScriptCodegenPlugin().execute(context);
String contents = manifest.getFileString("/commands/GetFooCommand.ts").get();
String contents = manifest.getFileString(CodegenUtils.SOURCE_FOLDER + "//commands/GetFooCommand.ts").get();

assertThat(contents, containsString("as __MetadataBearer"));
assertThat(contents, containsString(expectedType));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public void writeAdditionalExports(

IndexGenerator.writeIndex(settings, model, symbolProvider, manifest, integrations, null);

String contents = manifest.getFileString("index.ts").get();
String contents = manifest.getFileString(CodegenUtils.SOURCE_FOLDER + "/index.ts").get();
assertThat(contents, containsString("export * from \"./Example\";"));
assertThat(contents, containsString("export * from \"./ExampleClient\";"));
assertThat(contents, containsString("export * from \"./commands/GetFooCommand\";"));
Expand Down
Loading