0d3cb498a3
Deploy local.promptfoo.app / Deploy to Cloudflare Pages (push) Waiting to run
Test and Publish Multi-arch Docker Image / test (push) Waiting to run
Test and Publish Multi-arch Docker Image / build-docker-and-push-digests (map[digest-suffix:linux-amd64 platform:linux/amd64 runner:ubuntu-latest]) (push) Blocked by required conditions
Test and Publish Multi-arch Docker Image / build-docker-and-push-digests (map[digest-suffix:linux-arm64 platform:linux/arm64 runner:ubuntu-24.04-arm]) (push) Blocked by required conditions
Test and Publish Multi-arch Docker Image / merge-docker-digests (push) Blocked by required conditions
Test and Publish Multi-arch Docker Image / Attest Multi-arch Image (push) Blocked by required conditions
CI / Shell Format Check (push) Waiting to run
CI / Check Ruby (3.4) (push) Waiting to run
CI / CI Config (push) Waiting to run
CI / Test on Node ${{ matrix.node }} and ${{ matrix.os }}${{ matrix.shard && format(' (shard {0}/3)', matrix.shard) || '' }} (push) Blocked by required conditions
CI / Build on Node ${{ matrix.node }} (push) Blocked by required conditions
CI / Style Check (push) Waiting to run
CI / Generate Assets (push) Waiting to run
CI / Check Python (3.14) (push) Waiting to run
CI / Check Python (3.9) (push) Waiting to run
CI / Build Docs (push) Waiting to run
CI / Code Scan Action (push) Waiting to run
CI / Site tests (push) Waiting to run
CI / webui tests (push) Waiting to run
CI / Run Integration Tests (push) Waiting to run
CI / Run Smoke Tests (push) Waiting to run
CI / Go Tests (push) Waiting to run
CI / Share Test (push) Waiting to run
CI / Redteam (Production API) (push) Waiting to run
CI / Redteam (Staging API) (push) Waiting to run
CI / GitHub Actions Lint (push) Waiting to run
CI / Check Ruby (3.0) (push) Waiting to run
release-please / release-please (push) Waiting to run
release-please / build (push) Blocked by required conditions
release-please / publish-npm (push) Blocked by required conditions
release-please / publish-npm-backfill (push) Waiting to run
release-please / docker (push) Blocked by required conditions
release-please / publish-code-scan-action (push) Blocked by required conditions
release-please / attest-code-scan-action (push) Blocked by required conditions
Validate Renovate Config / Validate Renovate Configuration (push) Waiting to run
96 lines
3.1 KiB
TypeScript
96 lines
3.1 KiB
TypeScript
import fs from 'node:fs';
|
|
import path from 'node:path';
|
|
import { fileURLToPath } from 'node:url';
|
|
|
|
import {
|
|
extractModuleSpecifiers,
|
|
getLayerForFile,
|
|
getPackageName,
|
|
getSourceFiles,
|
|
readLayerConfig,
|
|
} from './architectureUtils';
|
|
|
|
interface DependencyUsage {
|
|
files: Set<string>;
|
|
layers: Set<string>;
|
|
}
|
|
|
|
interface PackageJson {
|
|
dependencies?: Record<string, string>;
|
|
optionalDependencies?: Record<string, string>;
|
|
}
|
|
|
|
const repoRoot = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..');
|
|
const config = readLayerConfig(repoRoot);
|
|
const packageJson = JSON.parse(
|
|
fs.readFileSync(path.join(repoRoot, 'package.json'), 'utf8'),
|
|
) as PackageJson;
|
|
|
|
const runtimeDependencies = new Map<string, Set<'dependency' | 'optional'>>();
|
|
for (const dependency of Object.keys(packageJson.dependencies ?? {})) {
|
|
runtimeDependencies.set(dependency, new Set(['dependency']));
|
|
}
|
|
for (const dependency of Object.keys(packageJson.optionalDependencies ?? {})) {
|
|
const kinds = runtimeDependencies.get(dependency) ?? new Set<'dependency' | 'optional'>();
|
|
kinds.add('optional');
|
|
runtimeDependencies.set(dependency, kinds);
|
|
}
|
|
|
|
const usages = new Map<string, DependencyUsage>();
|
|
const undeclaredUsages = new Map<string, DependencyUsage>();
|
|
|
|
for (const sourceFile of getSourceFiles(repoRoot, false, config.ignoredRoots)) {
|
|
const sourceText = fs.readFileSync(path.join(repoRoot, sourceFile), 'utf8');
|
|
const layer = getLayerForFile(sourceFile, config);
|
|
|
|
for (const specifier of extractModuleSpecifiers(sourceText, sourceFile)) {
|
|
const packageName = getPackageName(specifier);
|
|
if (!packageName) {
|
|
continue;
|
|
}
|
|
|
|
const targetMap = runtimeDependencies.has(packageName) ? usages : undeclaredUsages;
|
|
const usage = targetMap.get(packageName) ?? {
|
|
files: new Set<string>(),
|
|
layers: new Set<string>(),
|
|
};
|
|
usage.files.add(sourceFile);
|
|
usage.layers.add(layer);
|
|
targetMap.set(packageName, usage);
|
|
}
|
|
}
|
|
|
|
const rows = [...runtimeDependencies.entries()]
|
|
.map(([dependency, kinds]) => {
|
|
const usage = usages.get(dependency);
|
|
const layers = usage ? [...usage.layers].sort() : [];
|
|
return {
|
|
dependency,
|
|
kind: [...kinds].sort().join('+'),
|
|
owner: layers.length === 0 ? 'unreferenced' : layers.length === 1 ? layers[0] : 'shared',
|
|
layers: layers.join(', ') || '-',
|
|
files: usage?.files.size ?? 0,
|
|
};
|
|
})
|
|
.sort((left, right) => left.dependency.localeCompare(right.dependency));
|
|
|
|
if (process.argv.includes('--json')) {
|
|
console.log(JSON.stringify(rows, null, 2));
|
|
process.exit(0);
|
|
}
|
|
|
|
console.log('| Dependency | Kind | Candidate owner | Direct layers | Source files |');
|
|
console.log('| --- | --- | --- | --- | ---: |');
|
|
for (const row of rows) {
|
|
console.log(`| ${row.dependency} | ${row.kind} | ${row.owner} | ${row.layers} | ${row.files} |`);
|
|
}
|
|
|
|
if (undeclaredUsages.size > 0) {
|
|
console.log('\nImported packages outside root runtime dependencies:');
|
|
for (const [dependency, usage] of [...undeclaredUsages.entries()].sort(([left], [right]) =>
|
|
left.localeCompare(right),
|
|
)) {
|
|
console.log(`- ${dependency}: ${[...usage.layers].sort().join(', ')}`);
|
|
}
|
|
}
|