



























@@ -27,6 +27,19 @@ function readJson(filePath) {
2727return JSON.parse(fs.readFileSync(filePath, "utf8"));
2828}
292930+function readTrackedJson(cwd, relativePath) {
31+const filePath = path.join(cwd, relativePath);
32+if (fs.existsSync(filePath)) {
33+return readJson(filePath);
34+}
35+return JSON.parse(
36+execFileSync("git", ["show", `:${relativePath}`], {
37+ cwd,
38+encoding: "utf8",
39+}),
40+);
41+}
42+3043function isAllowedPinnedSpec(spec) {
3144if (typeof spec !== "string") {
3245return false;
@@ -46,7 +59,7 @@ function isAllowedPinnedSpec(spec) {
4659function collectPackageJsonViolations(cwd) {
4760const violations = [];
4861for (const relativePath of listTrackedPackageJsonFiles(cwd)) {
49-const packageJson = readJson(path.join(cwd, relativePath));
62+const packageJson = readTrackedJson(cwd, relativePath);
5063for (const section of PACKAGE_DEPENDENCY_SECTIONS) {
5164for (const [name, spec] of Object.entries(packageJson[section] ?? {})) {
5265if (!isAllowedPinnedSpec(spec)) {
@@ -96,7 +109,7 @@ export function collectDependencyPinAudit(cwd = process.cwd()) {
96109const packageJsonFiles = listTrackedPackageJsonFiles(cwd);
97110let packageSpecCount = 0;
98111for (const relativePath of packageJsonFiles) {
99-const packageJson = readJson(path.join(cwd, relativePath));
112+const packageJson = readTrackedJson(cwd, relativePath);
100113for (const section of PACKAGE_DEPENDENCY_SECTIONS) {
101114packageSpecCount += Object.keys(packageJson[section] ?? {}).length;
102115}
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。