mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-18 06:20:44 +00:00
fix(ci): read sparse package manifests from index
This commit is contained in:
@@ -27,6 +27,19 @@ function readJson(filePath) {
|
||||
return JSON.parse(fs.readFileSync(filePath, "utf8"));
|
||||
}
|
||||
|
||||
function readTrackedJson(cwd, relativePath) {
|
||||
const filePath = path.join(cwd, relativePath);
|
||||
if (fs.existsSync(filePath)) {
|
||||
return readJson(filePath);
|
||||
}
|
||||
return JSON.parse(
|
||||
execFileSync("git", ["show", `:${relativePath}`], {
|
||||
cwd,
|
||||
encoding: "utf8",
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
function isAllowedPinnedSpec(spec) {
|
||||
if (typeof spec !== "string") {
|
||||
return false;
|
||||
@@ -46,7 +59,7 @@ function isAllowedPinnedSpec(spec) {
|
||||
function collectPackageJsonViolations(cwd) {
|
||||
const violations = [];
|
||||
for (const relativePath of listTrackedPackageJsonFiles(cwd)) {
|
||||
const packageJson = readJson(path.join(cwd, relativePath));
|
||||
const packageJson = readTrackedJson(cwd, relativePath);
|
||||
for (const section of PACKAGE_DEPENDENCY_SECTIONS) {
|
||||
for (const [name, spec] of Object.entries(packageJson[section] ?? {})) {
|
||||
if (!isAllowedPinnedSpec(spec)) {
|
||||
@@ -96,7 +109,7 @@ export function collectDependencyPinAudit(cwd = process.cwd()) {
|
||||
const packageJsonFiles = listTrackedPackageJsonFiles(cwd);
|
||||
let packageSpecCount = 0;
|
||||
for (const relativePath of packageJsonFiles) {
|
||||
const packageJson = readJson(path.join(cwd, relativePath));
|
||||
const packageJson = readTrackedJson(cwd, relativePath);
|
||||
for (const section of PACKAGE_DEPENDENCY_SECTIONS) {
|
||||
packageSpecCount += Object.keys(packageJson[section] ?? {}).length;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { execFileSync } from "node:child_process";
|
||||
import { mkdirSync, writeFileSync } from "node:fs";
|
||||
import { mkdirSync, rmSync, writeFileSync } from "node:fs";
|
||||
import path from "node:path";
|
||||
import { afterEach, describe, expect, it } from "vitest";
|
||||
import { collectDependencyPinViolations } from "../../scripts/check-dependency-pins.mjs";
|
||||
@@ -143,6 +143,21 @@ packageExtensions:
|
||||
]);
|
||||
});
|
||||
|
||||
it("reads tracked package manifests from the index when sparse checkout omits them", () => {
|
||||
const dir = makeRepo();
|
||||
mkdirSync(path.join(dir, "qa", "convex-credential-broker"), { recursive: true });
|
||||
writeJson(path.join(dir, "package.json"), {});
|
||||
writeJson(path.join(dir, "qa", "convex-credential-broker", "package.json"), {
|
||||
dependencies: {
|
||||
exact: "1.2.3",
|
||||
},
|
||||
});
|
||||
git(dir, ["add", "package.json", "qa/convex-credential-broker/package.json"]);
|
||||
rmSync(path.join(dir, "qa"), { recursive: true, force: true });
|
||||
|
||||
expect(collectDependencyPinViolations(dir)).toEqual([]);
|
||||
});
|
||||
|
||||
it("rejects floating workspace overrides and package extension dependencies", () => {
|
||||
const dir = makeRepo();
|
||||
writeJson(path.join(dir, "package.json"), {});
|
||||
|
||||
Reference in New Issue
Block a user