Skip to content

Commit 4f1f762

Browse files
authored
chore(build): update dependency validation script (#5871)
1 parent 6a7fc32 commit 4f1f762

File tree

1 file changed

+37
-6
lines changed

1 file changed

+37
-6
lines changed

scripts/runtime-dependency-version-check/check-dependencies.js

Lines changed: 37 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,33 @@ const root = path.join(__dirname, "..", "..");
1111
const packages = path.join(root, "packages");
1212
const walk = require("../utils/walk");
1313

14+
const node_libraries = [
15+
"buffer",
16+
"child_process",
17+
"crypto",
18+
"dns",
19+
"dns/promises",
20+
"events",
21+
"fs",
22+
"fs/promises",
23+
"http",
24+
"http2",
25+
"https",
26+
"os",
27+
"path",
28+
"path/posix",
29+
"path/win32",
30+
"process",
31+
"stream",
32+
"stream/consumers",
33+
"stream/promises",
34+
"stream/web",
35+
"tls",
36+
"url",
37+
"util",
38+
"zlib",
39+
];
40+
1441
(async () => {
1542
const errors = [];
1643

@@ -44,17 +71,21 @@ const walk = require("../utils/walk");
4471
const importedDependencies = [];
4572
importedDependencies.push(
4673
...new Set(
47-
[...(contents.toString().match(/(from |import\()"(@(aws-sdk|smithy)\/.*?)";/g) || [])].map((_) =>
48-
_.replace(/from "/g, "").replace(/";$/, "")
49-
)
74+
[...(contents.toString().match(/(from |import\()"(.*?)";/g) || [])]
75+
.map((_) => _.replace(/from "/g, "").replace(/";$/, ""))
76+
.filter((_) => !_.startsWith(".") && !node_libraries.includes(_))
5077
)
5178
);
5279

5380
for (const dependency of importedDependencies) {
81+
const dependencyPackageName = dependency.startsWith("@")
82+
? dependency.split("/").slice(0, 2).join("/")
83+
: dependency.split("/")[0];
84+
5485
if (
55-
!(dependency in (pkgJson.dependencies ?? {})) &&
56-
!(dependency in (pkgJson.peerDependencies ?? {})) &&
57-
dependency !== pkgJson.name
86+
!(dependencyPackageName in (pkgJson.dependencies ?? {})) &&
87+
!(dependencyPackageName in (pkgJson.peerDependencies ?? {})) &&
88+
dependencyPackageName !== pkgJson.name
5889
) {
5990
errors.push(`${dependency} undeclared but imported in ${pkgJson.name} ${file}}`);
6091
}

0 commit comments

Comments
 (0)