fix: 补齐发布包补丁文件
This commit is contained in:
1 parent
0d9f4a7d6f
commit
fb072d844b
3 files changed
+51
-8
No files matched your search
@@ -26,6 +26,26 @@ export async function checkPackage(directory) {
|
||||
.sort();
|
||||
if (JSON.stringify(actual) !== JSON.stringify(expected))
|
||||
throw new Error("Release file list mismatch");
|
||||
|
||||
const packagePath = path.join(directory, "package.json");
|
||||
let releasePackage;
|
||||
try {
|
||||
releasePackage = JSON.parse(await readFile(packagePath, "utf8"));
|
||||
} catch (error) {
|
||||
if (error.code !== "ENOENT") throw error;
|
||||
}
|
||||
const patchedDependencies = releasePackage?.pnpm?.patchedDependencies ?? {};
|
||||
for (const [dependency, patchPath] of Object.entries(patchedDependencies)) {
|
||||
if (
|
||||
typeof patchPath !== "string" ||
|
||||
path.isAbsolute(patchPath) ||
|
||||
patchPath.split("/").includes("..")
|
||||
)
|
||||
throw new Error("Invalid patched dependency path: " + dependency);
|
||||
if (!actual.includes(patchPath))
|
||||
throw new Error(`Release is missing patched dependency ${dependency}: ${patchPath}`);
|
||||
}
|
||||
|
||||
for (const file of manifest.files) {
|
||||
if (file.path.startsWith("/") || file.path.split("/").includes(".."))
|
||||
throw new Error("Unsafe release path");
|
||||
|
||||
@@ -6,22 +6,27 @@ import path from "node:path";
|
||||
import test from "node:test";
|
||||
import { checkPackage } from "./check-package.mjs";
|
||||
|
||||
async function createPackage() {
|
||||
async function createPackage(extraFiles = {}) {
|
||||
const directory = await mkdtemp(path.join(os.tmpdir(), "personal-brand-release-"));
|
||||
await mkdir(path.join(directory, "apps"), { recursive: true });
|
||||
const content = Buffer.from("release fixture");
|
||||
await writeFile(path.join(directory, "apps/api.js"), content);
|
||||
const files = new Map([["apps/api.js", content]]);
|
||||
for (const [relative, value] of Object.entries(extraFiles)) {
|
||||
const fileContent = Buffer.isBuffer(value) ? value : Buffer.from(value);
|
||||
await mkdir(path.dirname(path.join(directory, relative)), { recursive: true });
|
||||
await writeFile(path.join(directory, relative), fileContent);
|
||||
files.set(relative, fileContent);
|
||||
}
|
||||
await writeFile(
|
||||
path.join(directory, "manifest.json"),
|
||||
JSON.stringify({
|
||||
version: "fixture-1",
|
||||
files: [
|
||||
{
|
||||
path: "apps/api.js",
|
||||
bytes: content.byteLength,
|
||||
sha256: createHash("sha256").update(content).digest("hex"),
|
||||
},
|
||||
],
|
||||
files: [...files].map(([filePath, fileContent]) => ({
|
||||
path: filePath,
|
||||
bytes: fileContent.byteLength,
|
||||
sha256: createHash("sha256").update(fileContent).digest("hex"),
|
||||
})),
|
||||
}),
|
||||
);
|
||||
return directory;
|
||||
@@ -56,3 +61,20 @@ test("release package checker rejects files missing from the manifest", async ()
|
||||
await rm(directory, { recursive: true, force: true });
|
||||
}
|
||||
});
|
||||
|
||||
test("release package checker rejects patched dependencies missing from the package", async () => {
|
||||
const directory = await createPackage({
|
||||
"package.json": JSON.stringify({
|
||||
pnpm: {
|
||||
patchedDependencies: {
|
||||
"example-package@1.0.0": "patches/example-package.patch",
|
||||
},
|
||||
},
|
||||
}),
|
||||
});
|
||||
try {
|
||||
await assert.rejects(checkPackage(directory), /missing patched dependency/);
|
||||
} finally {
|
||||
await rm(directory, { recursive: true, force: true });
|
||||
}
|
||||
});
|
||||
@@ -119,6 +119,7 @@ async function main() {
|
||||
]) {
|
||||
await cp(path.join(root, file), path.join(output, file));
|
||||
}
|
||||
await cp(path.join(root, "patches"), path.join(output, "patches"), { recursive: true });
|
||||
for (const workspace of [
|
||||
"apps/api",
|
||||
"packages/config",
|
||||
|
||||
Reference in new issue
Block a user