chore: import upstream snapshot with attribution
CI / Shell Format Check (push) Has been cancelled
CI / Check Ruby (3.4) (push) Has been cancelled
CI / CI Config (push) Has been cancelled
CI / Test on Node ${{ matrix.node }} and ${{ matrix.os }}${{ matrix.shard && format(' (shard {0}/3)', matrix.shard) || '' }} (push) Has been cancelled
CI / Build on Node ${{ matrix.node }} (push) Has been cancelled
CI / Style Check (push) Has been cancelled
CI / Generate Assets (push) Has been cancelled
CI / Check Python (3.14) (push) Has been cancelled
CI / Check Python (3.9) (push) Has been cancelled
CI / Build Docs (push) Has been cancelled
CI / Code Scan Action (push) Has been cancelled
CI / Site tests (push) Has been cancelled
CI / webui tests (push) Has been cancelled
CI / Run Integration Tests (push) Has been cancelled
CI / Run Smoke Tests (push) Has been cancelled
CI / Go Tests (push) Has been cancelled
CI / Share Test (push) Has been cancelled
CI / Redteam (Production API) (push) Has been cancelled
CI / Redteam (Staging API) (push) Has been cancelled
CI / GitHub Actions Lint (push) Has been cancelled
CI / Check Ruby (3.0) (push) Has been cancelled
release-please / release-please (push) Has been cancelled
release-please / build (push) Has been cancelled
release-please / publish-npm (push) Has been cancelled
release-please / publish-npm-backfill (push) Has been cancelled
release-please / docker (push) Has been cancelled
release-please / publish-code-scan-action (push) Has been cancelled
release-please / attest-code-scan-action (push) Has been cancelled
Deploy local.promptfoo.app / Deploy to Cloudflare Pages (push) Has been cancelled
Test and Publish Multi-arch Docker Image / test (push) Has been cancelled
Test and Publish Multi-arch Docker Image / build-docker-and-push-digests (map[digest-suffix:linux-amd64 platform:linux/amd64 runner:ubuntu-latest]) (push) Has been cancelled
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) Has been cancelled
Test and Publish Multi-arch Docker Image / merge-docker-digests (push) Has been cancelled
Test and Publish Multi-arch Docker Image / Attest Multi-arch Image (push) Has been cancelled
Validate Renovate Config / Validate Renovate Configuration (push) Has been cancelled
CI / Shell Format Check (push) Has been cancelled
CI / Check Ruby (3.4) (push) Has been cancelled
CI / CI Config (push) Has been cancelled
CI / Test on Node ${{ matrix.node }} and ${{ matrix.os }}${{ matrix.shard && format(' (shard {0}/3)', matrix.shard) || '' }} (push) Has been cancelled
CI / Build on Node ${{ matrix.node }} (push) Has been cancelled
CI / Style Check (push) Has been cancelled
CI / Generate Assets (push) Has been cancelled
CI / Check Python (3.14) (push) Has been cancelled
CI / Check Python (3.9) (push) Has been cancelled
CI / Build Docs (push) Has been cancelled
CI / Code Scan Action (push) Has been cancelled
CI / Site tests (push) Has been cancelled
CI / webui tests (push) Has been cancelled
CI / Run Integration Tests (push) Has been cancelled
CI / Run Smoke Tests (push) Has been cancelled
CI / Go Tests (push) Has been cancelled
CI / Share Test (push) Has been cancelled
CI / Redteam (Production API) (push) Has been cancelled
CI / Redteam (Staging API) (push) Has been cancelled
CI / GitHub Actions Lint (push) Has been cancelled
CI / Check Ruby (3.0) (push) Has been cancelled
release-please / release-please (push) Has been cancelled
release-please / build (push) Has been cancelled
release-please / publish-npm (push) Has been cancelled
release-please / publish-npm-backfill (push) Has been cancelled
release-please / docker (push) Has been cancelled
release-please / publish-code-scan-action (push) Has been cancelled
release-please / attest-code-scan-action (push) Has been cancelled
Deploy local.promptfoo.app / Deploy to Cloudflare Pages (push) Has been cancelled
Test and Publish Multi-arch Docker Image / test (push) Has been cancelled
Test and Publish Multi-arch Docker Image / build-docker-and-push-digests (map[digest-suffix:linux-amd64 platform:linux/amd64 runner:ubuntu-latest]) (push) Has been cancelled
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) Has been cancelled
Test and Publish Multi-arch Docker Image / merge-docker-digests (push) Has been cancelled
Test and Publish Multi-arch Docker Image / Attest Multi-arch Image (push) Has been cancelled
Validate Renovate Config / Validate Renovate Configuration (push) Has been cancelled
This commit is contained in:
@@ -0,0 +1,95 @@
|
||||
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(', ')}`);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user