Skip to content
Open
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
12 changes: 12 additions & 0 deletions .github/renovate.json5
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@
"@yao-pkg/pkg",
"anyhow",
"arboard",
"ashpd",
"babel-loader",
"base64-loader",
"base64",
Expand All @@ -142,6 +143,7 @@
"core-foundation",
"copy-webpack-plugin",
"css-loader",
"ctor",
"dirs",
"electron",
"electron-builder",
Expand Down Expand Up @@ -179,6 +181,7 @@
"sass",
"sass-loader",
"scopeguard",
"secmem-proc",
"security-framework",
"security-framework-sys",
"semver",
Expand All @@ -187,6 +190,7 @@
"simplelog",
"style-loader",
"sysinfo",
"thiserror",
"tokio",
"tokio-util",
"tracing",
Expand All @@ -210,6 +214,7 @@
"windows-registry",
"zbus",
"zbus_polkit",
"zeroizing-alloc",
],
description: "Platform owned dependencies",
commitMessagePrefix: "[deps] Platform:",
Expand Down Expand Up @@ -285,6 +290,7 @@
"@types/jsdom",
"@types/papaparse",
"@types/zxcvbn",
"aes-gcm",
"async-trait",
"clap",
"jsdom",
Expand Down Expand Up @@ -337,6 +343,7 @@
"aes",
"big-integer",
"cbc",
"chacha20poly1305",
"linux-keyutils",
"memsec",
"node-forge",
Expand Down Expand Up @@ -445,6 +452,7 @@
matchPackageNames: [
"anyhow",
"arboard",
"ashpd",
"babel-loader",
"base64-loader",
"base64",
Expand All @@ -454,6 +462,7 @@
"core-foundation",
"copy-webpack-plugin",
"css-loader",
"ctor",
"dirs",
"electron-builder",
"electron-log",
Expand Down Expand Up @@ -488,6 +497,7 @@
"sass",
"sass-loader",
"scopeguard",
"secmem-proc",
"security-framework",
"security-framework-sys",
"semver",
Expand All @@ -496,6 +506,7 @@
"simplelog",
"style-loader",
"sysinfo",
"thiserror",
"tokio",
"tokio-util",
"tracing",
Expand All @@ -517,6 +528,7 @@
"windows-registry",
"zbus",
"zbus_polkit",
"zeroizing-alloc",
],
matchUpdateTypes: ["minor", "patch"],
dependencyDashboardApproval: true,
Expand Down
57 changes: 51 additions & 6 deletions scripts/dep-ownership.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand All @@ -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 cargoDependencies = new Set<string>();

// 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 missingOwners = dependencies.filter((dep) => !packagesWithOwners.includes(dep));
const allMissing = [...missingNpmOwners, ...missingCargoOwners];

if (missingOwners.length > 0) {
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);
}

Expand Down
Loading