fix: 收口发布包完整性与模板契约迁移
This commit is contained in:
1 parent
38e9d59864
commit
16fd827634
7 files changed
+812
-26
No files matched your search
@@ -54,6 +54,66 @@ export async function checkPackage(directory) {
|
||||
if (content.byteLength !== file.bytes || digest !== file.sha256)
|
||||
throw new Error("Release checksum mismatch: " + file.path);
|
||||
}
|
||||
|
||||
const workspacePackages = new Map();
|
||||
for (const relative of actual.filter(
|
||||
(file) => file === "package.json" || file.endsWith("/package.json"),
|
||||
)) {
|
||||
const workspacePackage = JSON.parse(await readFile(path.join(directory, relative), "utf8"));
|
||||
if (typeof workspacePackage.name !== "string" || !workspacePackage.name)
|
||||
throw new Error("Workspace package has no name: " + relative);
|
||||
workspacePackages.set(workspacePackage.name, {
|
||||
directory: path.posix.dirname(relative),
|
||||
manifest: workspacePackage,
|
||||
});
|
||||
}
|
||||
for (const [name, workspacePackage] of workspacePackages) {
|
||||
for (const section of ["dependencies", "devDependencies", "optionalDependencies"]) {
|
||||
for (const [dependency, range] of Object.entries(workspacePackage.manifest[section] ?? {})) {
|
||||
if (typeof range !== "string" || !range.startsWith("workspace:")) continue;
|
||||
const target = workspacePackages.get(dependency);
|
||||
if (!target) {
|
||||
throw new Error(
|
||||
`Release is missing workspace dependency ${dependency} required by ${name}`,
|
||||
);
|
||||
}
|
||||
if (target.directory === ".") {
|
||||
throw new Error(`Workspace dependency ${dependency} cannot be the release root package`);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (actual.includes("template-catalog.json")) {
|
||||
const catalog = JSON.parse(
|
||||
await readFile(path.join(directory, "template-catalog.json"), "utf8"),
|
||||
);
|
||||
if (catalog.formatVersion !== "1" || !Array.isArray(catalog.packages))
|
||||
throw new Error("Invalid template catalog");
|
||||
const keys = new Set();
|
||||
for (const entry of catalog.packages) {
|
||||
if (
|
||||
typeof entry.packageKey !== "string" ||
|
||||
typeof entry.version !== "string" ||
|
||||
typeof entry.archiveChecksum !== "string" ||
|
||||
typeof entry.archivePath !== "string"
|
||||
)
|
||||
throw new Error("Invalid template catalog entry");
|
||||
if (keys.has(entry.packageKey))
|
||||
throw new Error("Duplicate template package in catalog: " + entry.packageKey);
|
||||
keys.add(entry.packageKey);
|
||||
if (
|
||||
path.isAbsolute(entry.archivePath) ||
|
||||
entry.archivePath.split("/").includes("..") ||
|
||||
!actual.includes(entry.archivePath)
|
||||
)
|
||||
throw new Error("Template archive is missing from release: " + entry.packageKey);
|
||||
const digest = createHash("sha256")
|
||||
.update(await readFile(path.join(directory, entry.archivePath)))
|
||||
.digest("hex");
|
||||
if (digest !== entry.archiveChecksum)
|
||||
throw new Error("Template archive checksum mismatch: " + entry.packageKey);
|
||||
}
|
||||
}
|
||||
return manifest;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user