diff --git a/.changeset/great-schools-cheer.md b/.changeset/great-schools-cheer.md new file mode 100644 index 00000000000..a845151cc84 --- /dev/null +++ b/.changeset/great-schools-cheer.md @@ -0,0 +1,2 @@ +--- +--- 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 c40851880a4..2433e7f5168 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 @@ -169,11 +169,17 @@ void generate(LanguageTarget target) { .replaceFirst(CodegenUtils.SOURCE_FOLDER + "/", "")) .replace("${clientConfigName}", symbolProvider.toSymbol(service).getName() + "Config") .replace("${apiVersion}", service.getVersion()) - .replace("$", "$$") // sanitize template place holders. - .replace("$${customizations}", "${L@customizations}"); + .replace("${", "$${") // sanitize template place holders. + .replace("$${customizations}", "${L@customizations}") + .replace("$${prepareCustomizations}", "${L@prepareCustomizations}"); delegator.useFileWriter(target.getTargetFilename(), writer -> { // Inject customizations into the ~template. + writer.onSection("prepareCustomizations", original -> { + for (TypeScriptIntegration integration : integrations) { + integration.prepareCustomizations(writer, target, settings, model); + } + }); writer.indent().onSection("customizations", original -> { // Start with defaults, use a TreeMap for keeping entries sorted. Map> configs = @@ -198,7 +204,7 @@ void generate(LanguageTarget target) { }); }); writer.dedent(); - writer.write(contents, ""); + writer.write(contents, "", ""); }); } diff --git a/smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/integration/TypeScriptIntegration.java b/smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/integration/TypeScriptIntegration.java index bc612cedda4..5c2f11379ce 100644 --- a/smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/integration/TypeScriptIntegration.java +++ b/smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/integration/TypeScriptIntegration.java @@ -253,4 +253,17 @@ default Map> getRuntimeConfigWriters( default List getExtensionConfigurationInterfaces() { return Collections.emptyList(); } + + /** + * Allows the customization to write arbitrary preparatory code prior to the returned config object. + */ + @SmithyInternalApi + default void prepareCustomizations( + TypeScriptWriter writer, + LanguageTarget target, + TypeScriptSettings settings, + Model model + ) { + return; + } } diff --git a/smithy-typescript-codegen/src/main/resources/software/amazon/smithy/typescript/codegen/runtimeConfig.browser.ts.template b/smithy-typescript-codegen/src/main/resources/software/amazon/smithy/typescript/codegen/runtimeConfig.browser.ts.template index a6a8eb1e9ee..1d42f61d15c 100644 --- a/smithy-typescript-codegen/src/main/resources/software/amazon/smithy/typescript/codegen/runtimeConfig.browser.ts.template +++ b/smithy-typescript-codegen/src/main/resources/software/amazon/smithy/typescript/codegen/runtimeConfig.browser.ts.template @@ -10,7 +10,7 @@ export const getRuntimeConfig = (config: ${clientConfigName}) => { const defaultsMode = resolveDefaultsModeConfig(config); const defaultConfigProvider = () => defaultsMode().then(loadConfigsForDefaultMode); const clientSharedValues = getSharedRuntimeConfig(config); - return { + ${prepareCustomizations}return { ...clientSharedValues, ...config, runtime: "browser", diff --git a/smithy-typescript-codegen/src/main/resources/software/amazon/smithy/typescript/codegen/runtimeConfig.native.ts.template b/smithy-typescript-codegen/src/main/resources/software/amazon/smithy/typescript/codegen/runtimeConfig.native.ts.template index 705735d7203..9d24bec16a6 100644 --- a/smithy-typescript-codegen/src/main/resources/software/amazon/smithy/typescript/codegen/runtimeConfig.native.ts.template +++ b/smithy-typescript-codegen/src/main/resources/software/amazon/smithy/typescript/codegen/runtimeConfig.native.ts.template @@ -6,7 +6,7 @@ import { getRuntimeConfig as getBrowserRuntimeConfig } from "./runtimeConfig.bro */ export const getRuntimeConfig = (config: ${clientConfigName}) => { const browserDefaults = getBrowserRuntimeConfig(config); - return { + ${prepareCustomizations}return { ...browserDefaults, ...config, runtime: "react-native", diff --git a/smithy-typescript-codegen/src/main/resources/software/amazon/smithy/typescript/codegen/runtimeConfig.shared.ts.template b/smithy-typescript-codegen/src/main/resources/software/amazon/smithy/typescript/codegen/runtimeConfig.shared.ts.template index 5ec08befe15..b83ca69f052 100644 --- a/smithy-typescript-codegen/src/main/resources/software/amazon/smithy/typescript/codegen/runtimeConfig.shared.ts.template +++ b/smithy-typescript-codegen/src/main/resources/software/amazon/smithy/typescript/codegen/runtimeConfig.shared.ts.template @@ -3,7 +3,9 @@ import { ${clientConfigName} } from "${clientModuleName}"; /** * @internal */ -export const getRuntimeConfig = (config: ${clientConfigName}) => ({ - apiVersion: "${apiVersion}", -${customizations} -}); +export const getRuntimeConfig = (config: ${clientConfigName}) => { + ${prepareCustomizations}return { + apiVersion: "${apiVersion}", + ${customizations} + } +}; diff --git a/smithy-typescript-codegen/src/main/resources/software/amazon/smithy/typescript/codegen/runtimeConfig.ts.template b/smithy-typescript-codegen/src/main/resources/software/amazon/smithy/typescript/codegen/runtimeConfig.ts.template index e55472de15b..5f9234674e5 100644 --- a/smithy-typescript-codegen/src/main/resources/software/amazon/smithy/typescript/codegen/runtimeConfig.ts.template +++ b/smithy-typescript-codegen/src/main/resources/software/amazon/smithy/typescript/codegen/runtimeConfig.ts.template @@ -12,7 +12,7 @@ export const getRuntimeConfig = (config: ${clientConfigName}) => { const defaultsMode = resolveDefaultsModeConfig(config); const defaultConfigProvider = () => defaultsMode().then(loadConfigsForDefaultMode); const clientSharedValues = getSharedRuntimeConfig(config); - return { + ${prepareCustomizations}return { ...clientSharedValues, ...config, runtime: "node",