Skip to content

Commit

Permalink
fix(private): add dependency checking to private folder
Browse files Browse the repository at this point in the history
  • Loading branch information
kuhe committed Apr 11, 2024
1 parent 50002cf commit 91a03a4
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ static void generateDocumentBodyShapeSerde(
*/
static void generateJsonParseBody(GenerationContext context) {
TypeScriptWriter writer = context.getWriter();
writer.addDependency(AwsDependency.AWS_SDK_CORE);
writer.addImport("parseJsonBody", "parseBody", AwsDependency.AWS_SDK_CORE);
}

Expand All @@ -126,6 +127,7 @@ static void generateJsonParseBodyWithQueryHeader(GenerationContext context) {
*/
static void generateJsonParseErrorBody(GenerationContext context) {
TypeScriptWriter writer = context.getWriter();
writer.addDependency(AwsDependency.AWS_SDK_CORE);
writer.addImport("parseJsonErrorBody", "parseErrorBody", AwsDependency.AWS_SDK_CORE);
}

Expand All @@ -137,6 +139,7 @@ static void generateJsonParseErrorBody(GenerationContext context) {
*/
static void generateXmlParseBody(GenerationContext context) {
TypeScriptWriter writer = context.getWriter();
writer.addDependency(AwsDependency.AWS_SDK_CORE);
writer.addImport("parseXmlBody", "parseBody", AwsDependency.AWS_SDK_CORE);
}

Expand All @@ -148,6 +151,7 @@ static void generateXmlParseBody(GenerationContext context) {
*/
static void generateXmlParseErrorBody(GenerationContext context) {
TypeScriptWriter writer = context.getWriter();
writer.addDependency(AwsDependency.AWS_SDK_CORE);
writer.addImport("parseXmlErrorBody", "parseErrorBody", AwsDependency.AWS_SDK_CORE);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ public void generateSharedComponents(GenerationContext context) {
TypeScriptWriter writer = context.getWriter();
writer.addDependency(AwsDependency.XML_BUILDER);

writer.addDependency(AwsDependency.AWS_SDK_CORE);
writer.addImport("loadRestXmlErrorCode", null, AwsDependency.AWS_SDK_CORE);

writer.write(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ final class JsonMemberSerVisitor extends DocumentMemberSerVisitor {
this.isAwsQueryCompat = context.getService().hasTrait(AwsQueryCompatibleTrait.class);
this.serdeElisionEnabled = !this.isAwsQueryCompat && !context.getSettings().generateServerSdk();
if (isAwsQueryCompat) {
writer.addDependency(AwsDependency.AWS_SDK_CORE);
writer.addImport("_toStr", null, AwsDependency.AWS_SDK_CORE);
writer.addImport("_toNum", null, AwsDependency.AWS_SDK_CORE);
writer.addImport("_toBool", null, AwsDependency.AWS_SDK_CORE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ public void generateSharedComponents(GenerationContext context) {

TypeScriptWriter writer = context.getWriter();
writer.addUseImports(getApplicationProtocol().getResponseType());
writer.addDependency(AwsDependency.AWS_SDK_CORE);
writer.addImport("loadRestJsonErrorCode", null, AwsDependency.AWS_SDK_CORE);

if (context.getService().hasTrait(AwsQueryCompatibleTrait.class)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ public void generateSharedComponents(GenerationContext context) {
TypeScriptWriter writer = context.getWriter();
writer.addUseImports(getApplicationProtocol().getResponseType());
writer.addImport("take", null, TypeScriptDependency.AWS_SMITHY_CLIENT);
writer.addDependency(AwsDependency.AWS_SDK_CORE);
writer.addImport("loadRestJsonErrorCode", null, AwsDependency.AWS_SDK_CORE);

writer.write(
Expand Down
5 changes: 5 additions & 0 deletions private/aws-client-api-test/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@
"module": "./dist-es/index.js",
"sideEffects": false,
"dependencies": {
"@aws-sdk/credential-provider-node": "*",
"@aws-sdk/middleware-bucket-endpoint": "*",
"@aws-sdk/middleware-sdk-s3": "*",
"@aws-sdk/signature-v4-multi-region": "*",
"@aws-sdk/util-user-agent-node": "*",
"@aws-sdk/client-s3": "*",
"@smithy/config-resolver": "^2.2.0",
"@smithy/eventstream-serde-node": "^2.2.0",
Expand Down
1 change: 1 addition & 0 deletions private/aws-echo-service/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"dependencies": {
"@aws-crypto/sha256-browser": "3.0.0",
"@aws-crypto/sha256-js": "3.0.0",
"@aws-sdk/core": "*",
"@aws-sdk/middleware-host-header": "*",
"@aws-sdk/middleware-logger": "*",
"@aws-sdk/middleware-recursion-detection": "*",
Expand Down
24 changes: 18 additions & 6 deletions scripts/runtime-dependency-version-check/check-dependencies.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,15 @@ const pkgJsonEnforcement = require("./package-json-enforcement");

const root = path.join(__dirname, "..", "..");
const packages = path.join(root, "packages");
const _private = path.join(root, "private");
const topLevelFolders = [packages, _private];
const packageFolders = [];
const walk = require("../utils/walk");

for (const topLevelFolder of topLevelFolders) {
packageFolders.push(...fs.readdirSync(topLevelFolder));
}

const node_libraries = [
"buffer",
"child_process",
Expand Down Expand Up @@ -41,16 +48,21 @@ const node_libraries = [
(async () => {
const errors = [];

for (const folder of fs.readdirSync(packages)) {
if (folder === "util-dynamodb") {
for (const packageFolder of packageFolders) {
if (packageFolder === "util-dynamodb") {
// exempt
continue;
}

const pkgJsonPath = path.join(packages, folder, "package.json");
errors.push(...pkgJsonEnforcement(pkgJsonPath, true));
const containingFolder = topLevelFolders.find((f) => fs.existsSync(path.join(f, packageFolder, "package.json")));

const pkgJsonPath = path.join(containingFolder, packageFolder, "package.json");

if (containingFolder === packages) {
errors.push(...pkgJsonEnforcement(pkgJsonPath, true));
}

const srcPath = path.join(packages, folder, "src");
const srcPath = path.join(containingFolder, packageFolder, "src");
const pkgJson = require(pkgJsonPath);

if (!pkgJson.dependencies.tslib) {
Expand Down Expand Up @@ -93,7 +105,7 @@ const node_libraries = [

for (const [dep, version] of Object.entries(pkgJson.devDependencies ?? {})) {
if ((dep.startsWith("@smithy") || dep.startsWith("@aws-sdk")) && contents.includes(`from "${dep}";`)) {
errors.push(`${dep} incorrectly declared in devDependencies of ${folder}`);
errors.push(`${dep} incorrectly declared in devDependencies of ${packageFolder}`);
delete pkgJson.devDependencies[dep];
if (!pkgJson.dependencies) {
pkgJson.dependencies = {};
Expand Down

0 comments on commit 91a03a4

Please sign in to comment.