mirror of
https://github.com/bitwarden/browser
synced 2026-02-20 11:24:07 +00:00
chore(deps): Include Cargo dependencies in dep-ownership lint check
* Added Cardo dep ownership. * Fixed file paths. * Moved aes-gcm from KM to Tools.
This commit is contained in:
committed by
jaasen-livefront
parent
e6cb6ee38f
commit
e7afbac596
@@ -1,6 +1,6 @@
|
||||
/* eslint-disable no-console */
|
||||
|
||||
/// Ensure that all dependencies in package.json have an owner in the renovate.json file.
|
||||
/// Ensure that all dependencies in package.json and Cargo.toml have an owner in the renovate.json5 file.
|
||||
|
||||
import fs from "fs";
|
||||
import path from "path";
|
||||
@@ -11,22 +11,67 @@ const renovateConfig = JSON5.parse(
|
||||
fs.readFileSync(path.join(__dirname, "..", "..", ".github", "renovate.json5"), "utf8"),
|
||||
);
|
||||
|
||||
// Extract all packages with owners from renovate config
|
||||
const packagesWithOwners = renovateConfig.packageRules
|
||||
.flatMap((rule: any) => rule.matchPackageNames)
|
||||
.filter((packageName: string) => packageName != null);
|
||||
|
||||
function hasOwner(packageName: string): boolean {
|
||||
return packagesWithOwners.includes(packageName);
|
||||
}
|
||||
|
||||
// Collect npm dependencies
|
||||
const packageJson = JSON.parse(
|
||||
fs.readFileSync(path.join(__dirname, "..", "..", "package.json"), "utf8"),
|
||||
);
|
||||
const dependencies = Object.keys(packageJson.dependencies).concat(
|
||||
Object.keys(packageJson.devDependencies),
|
||||
const npmDependencies = [
|
||||
...Object.keys(packageJson.dependencies || {}),
|
||||
...Object.keys(packageJson.devDependencies || {}),
|
||||
];
|
||||
|
||||
// Collect Cargo dependencies from workspace Cargo.toml
|
||||
const cargoTomlPath = path.join(
|
||||
__dirname,
|
||||
"..",
|
||||
"..",
|
||||
"apps",
|
||||
"desktop",
|
||||
"desktop_native",
|
||||
"Cargo.toml",
|
||||
);
|
||||
const cargoTomlContent = fs.existsSync(cargoTomlPath) ? fs.readFileSync(cargoTomlPath, "utf8") : "";
|
||||
|
||||
const missingOwners = dependencies.filter((dep) => !packagesWithOwners.includes(dep));
|
||||
const cargoDependencies = new Set<string>();
|
||||
|
||||
if (missingOwners.length > 0) {
|
||||
// Extract dependency names from [workspace.dependencies] section by
|
||||
// extracting everything between [workspace.dependencies] and the next section start
|
||||
// (indicated by a "\n[").
|
||||
const workspaceSection =
|
||||
cargoTomlContent.split("[workspace.dependencies]")[1]?.split(/\n\[/)[0] ?? "";
|
||||
|
||||
// Process each line to extract dependency names
|
||||
workspaceSection
|
||||
.split("\n") // Process each line
|
||||
.map((line) => line.match(/^([a-zA-Z0-9_-]+)\s*=/)?.[1]) // Find the dependency name
|
||||
.filter((depName): depName is string => depName != null && !depName.startsWith("bitwarden")) // Make sure it's not an empty line or a Bitwarden dependency
|
||||
.forEach((depName) => cargoDependencies.add(depName));
|
||||
|
||||
// Check for missing owners
|
||||
const missingNpmOwners = npmDependencies.filter((dep) => !hasOwner(dep));
|
||||
const missingCargoOwners = Array.from(cargoDependencies).filter((dep) => !hasOwner(dep));
|
||||
|
||||
const allMissing = [...missingNpmOwners, ...missingCargoOwners];
|
||||
|
||||
if (allMissing.length > 0) {
|
||||
console.error("Missing owners for the following dependencies:");
|
||||
console.error(missingOwners.join("\n"));
|
||||
if (missingNpmOwners.length > 0) {
|
||||
console.error("\nNPM dependencies:");
|
||||
console.error(missingNpmOwners.join("\n"));
|
||||
}
|
||||
if (missingCargoOwners.length > 0) {
|
||||
console.error("\nCargo dependencies:");
|
||||
console.error(missingCargoOwners.join("\n"));
|
||||
}
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user