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

chore: run dependency check on commit hook #5412

Merged
merged 2 commits into from
Oct 24, 2023
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
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
"lint:ci": "lerna exec --since origin/main --exclude-dependents --ignore '@aws-sdk/client-*' --ignore '@aws-sdk/aws-*' 'eslint --quiet src/**/*.ts'",
"lint:release": "lerna exec --ignore '@aws-sdk/client-*' --ignore '@aws-sdk/aws-*' 'eslint --quiet src/**/*.ts'",
"lint:versions": "node scripts/runtime-dependency-version-check/runtime-dep-version-check.js",
"lint:dependencies": "node scripts/runtime-dependency-version-check/check-dependencies.js",
"local-publish": "node ./scripts/verdaccio-publish/index.js",
"test:all": "yarn build:all && jest --coverage --passWithNoTests && lerna run test --scope '@aws-sdk/{fetch-http-handler,hash-blob-browser}' && yarn test:versions && yarn test:integration",
"test:ci": "lerna run test --since origin/main",
Expand Down Expand Up @@ -146,7 +147,7 @@
},
"husky": {
"hooks": {
"pre-commit": "lint-staged && yarn lint:versions",
"pre-commit": "lint-staged && yarn lint:versions && yarn lint:dependencies",
"commit-msg": "commitlint -E HUSKY_GIT_PARAMS"
}
},
Expand Down
1 change: 1 addition & 0 deletions packages/credential-provider-http/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
"@smithy/protocol-http": "^3.0.8",
"@smithy/smithy-client": "^2.1.12",
"@smithy/types": "^2.4.0",
"@smithy/util-stream": "^2.0.17",
"tslib": "^2.5.0"
},
"devDependencies": {
Expand Down
1 change: 1 addition & 0 deletions packages/token-providers/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
"@aws-sdk/middleware-logger": "*",
"@aws-sdk/middleware-recursion-detection": "*",
"@aws-sdk/middleware-user-agent": "*",
"@aws-sdk/region-config-resolver": "*",
"@aws-sdk/types": "*",
"@aws-sdk/util-endpoints": "*",
"@aws-sdk/util-user-agent-browser": "*",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ const packages = path.join(root, "packages");
const walk = require("../utils/walk");

(async () => {
const errors = [];

for (const folder of fs.readdirSync(packages)) {
if (folder === "util-dynamodb") {
// exempt
Expand All @@ -32,9 +34,24 @@ const walk = require("../utils/walk");
continue;
}

const importedDependencies = [];
importedDependencies.push(
...new Set(
[...(contents.toString().match(/from "(@(aws-sdk|smithy)\/.*?)"/g) || [])]
.slice(1)
.map((_) => _.replace(/from "/g, "").replace(/"$/, ""))
)
);

for (const dependency of importedDependencies) {
if (!(dependency in pkgJson.dependencies) && dependency !== pkgJson.name) {
errors.push(`${dependency} undeclared but imported in ${pkgJson.name} ${file}}`);
}
}

for (const [dep, version] of Object.entries(pkgJson.devDependencies ?? {})) {
if ((dep.startsWith("@smithy") || dep.startsWith("@aws-sdk")) && contents.includes(`from "${dep}";`)) {
console.warn(`${dep} incorrectly declared in devDependencies of ${folder}`);
errors.push(`${dep} incorrectly declared in devDependencies of ${folder}`);
delete pkgJson.devDependencies[dep];
if (!pkgJson.dependencies) {
pkgJson.dependencies = {};
Expand All @@ -46,4 +63,8 @@ const walk = require("../utils/walk");
}
}
}

if (errors.length) {
throw new Error(errors.join("\n"));
}
})();