feat(supply-chain): list the packages the bundle ships and state what each proof covers (13-12)
The module inventory named dependency modules external:<file>, so no artifact said which package versions reach the public bundle. It now records npm:<name>@<version> ids and a packages list. supply-chain.md states what the SBOM, bundle list and provenance prove, and one SBOM scope mismatch (scheduler). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
a5dc851e0d
commit
331ec84037
@@ -152,6 +152,8 @@ export const moduleInventoryArtifactSchema = z
|
||||
})
|
||||
.strict(),
|
||||
),
|
||||
// 13-12: `name@version` of every package with a module in the bundle.
|
||||
packages: z.array(z.string().regex(/^(?:@[^/@]+\/)?[^/@]+@[^/@]+$/u)),
|
||||
})
|
||||
.strict();
|
||||
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { readFileSync } from "node:fs";
|
||||
import path from "node:path";
|
||||
|
||||
import type { Plugin } from "vite";
|
||||
@@ -39,6 +40,7 @@ export function viteModuleInventoryPlugin(
|
||||
{
|
||||
schemaVersion: 1,
|
||||
chunks,
|
||||
packages: bundledPackages(chunks),
|
||||
},
|
||||
null,
|
||||
2,
|
||||
@@ -48,7 +50,41 @@ export function viteModuleInventoryPlugin(
|
||||
};
|
||||
}
|
||||
|
||||
function normalizeModuleId(
|
||||
/**
|
||||
* 13-12. The `name@version` of every package with at least one module in the
|
||||
* emitted bundle: what the public release actually ships, as opposed to the
|
||||
* SBOM, which lists the whole installed graph.
|
||||
*/
|
||||
export function bundledPackages(chunks: readonly ModuleInventoryChunk[]): string[] {
|
||||
const packages = new Set<string>();
|
||||
for (const chunk of chunks) {
|
||||
for (const module of chunk.modules) {
|
||||
const match = /^npm:((?:@[^/]+\/)?[^/@]+@[^/]+)\//u.exec(module);
|
||||
if (match?.[1]) packages.add(match[1]);
|
||||
}
|
||||
}
|
||||
return [...packages].sort();
|
||||
}
|
||||
|
||||
const packageManifests = new Map<string, Readonly<{ name: string; version: string }>>();
|
||||
|
||||
function installedPackage(directory: string): Readonly<{ name: string; version: string }> {
|
||||
let manifest = packageManifests.get(directory);
|
||||
if (!manifest) {
|
||||
const parsed = JSON.parse(readFileSync(path.join(directory, "package.json"), "utf8")) as {
|
||||
name?: unknown;
|
||||
version?: unknown;
|
||||
};
|
||||
if (typeof parsed.name !== "string" || typeof parsed.version !== "string") {
|
||||
throw new TypeError(`bundled package has no name/version: ${directory}`);
|
||||
}
|
||||
manifest = Object.freeze({ name: parsed.name, version: parsed.version });
|
||||
packageManifests.set(directory, manifest);
|
||||
}
|
||||
return manifest;
|
||||
}
|
||||
|
||||
export function normalizeModuleId(
|
||||
moduleId: string,
|
||||
repositoryRoot: string,
|
||||
): string {
|
||||
@@ -56,6 +92,18 @@ function normalizeModuleId(
|
||||
if (!path.isAbsolute(withoutQuery)) {
|
||||
return withoutQuery.replaceAll("\\", "/");
|
||||
}
|
||||
// 13-12: a dependency module keeps its package identity, read from the
|
||||
// package.json of the directory it was resolved into.
|
||||
const file = withoutQuery.replaceAll("\\", "/");
|
||||
const marker = "/node_modules/";
|
||||
const at = file.lastIndexOf(marker);
|
||||
if (at >= 0) {
|
||||
const segments = file.slice(at + marker.length).split("/");
|
||||
const nameLength = segments[0]?.startsWith("@") ? 2 : 1;
|
||||
const directory = file.slice(0, at + marker.length) + segments.slice(0, nameLength).join("/");
|
||||
const { name, version } = installedPackage(directory);
|
||||
return `npm:${name}@${version}/${segments.slice(nameLength).join("/")}`;
|
||||
}
|
||||
const relative = path.relative(repositoryRoot, withoutQuery);
|
||||
return relative.startsWith("..")
|
||||
? `external:${path.basename(withoutQuery)}`
|
||||
|
||||
Reference in New Issue
Block a user