Skip to content

Commit

Permalink
chore(build): update dependency validation script (#5871)
Browse files Browse the repository at this point in the history
  • Loading branch information
kuhe authored Mar 8, 2024
1 parent 6a7fc32 commit 4f1f762
Showing 1 changed file with 37 additions and 6 deletions.
43 changes: 37 additions & 6 deletions scripts/runtime-dependency-version-check/check-dependencies.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,33 @@ const root = path.join(__dirname, "..", "..");
const packages = path.join(root, "packages");
const walk = require("../utils/walk");

const node_libraries = [
"buffer",
"child_process",
"crypto",
"dns",
"dns/promises",
"events",
"fs",
"fs/promises",
"http",
"http2",
"https",
"os",
"path",
"path/posix",
"path/win32",
"process",
"stream",
"stream/consumers",
"stream/promises",
"stream/web",
"tls",
"url",
"util",
"zlib",
];

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

Expand Down Expand Up @@ -44,17 +71,21 @@ const walk = require("../utils/walk");
const importedDependencies = [];
importedDependencies.push(
...new Set(
[...(contents.toString().match(/(from |import\()"(@(aws-sdk|smithy)\/.*?)";/g) || [])].map((_) =>
_.replace(/from "/g, "").replace(/";$/, "")
)
[...(contents.toString().match(/(from |import\()"(.*?)";/g) || [])]
.map((_) => _.replace(/from "/g, "").replace(/";$/, ""))
.filter((_) => !_.startsWith(".") && !node_libraries.includes(_))
)
);

for (const dependency of importedDependencies) {
const dependencyPackageName = dependency.startsWith("@")
? dependency.split("/").slice(0, 2).join("/")
: dependency.split("/")[0];

if (
!(dependency in (pkgJson.dependencies ?? {})) &&
!(dependency in (pkgJson.peerDependencies ?? {})) &&
dependency !== pkgJson.name
!(dependencyPackageName in (pkgJson.dependencies ?? {})) &&
!(dependencyPackageName in (pkgJson.peerDependencies ?? {})) &&
dependencyPackageName !== pkgJson.name
) {
errors.push(`${dependency} undeclared but imported in ${pkgJson.name} ${file}}`);
}
Expand Down

0 comments on commit 4f1f762

Please sign in to comment.