Skip to content

Commit c449fa5

Browse files
committed
fix: extract arch test
1 parent 5a3a860 commit c449fa5

File tree

3 files changed

+26
-8
lines changed

3 files changed

+26
-8
lines changed

build/main.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24630,6 +24630,12 @@ function getDependenciesFromPackageJson(pkg, types) {
2463024630
}
2463124631
return result;
2463224632
}
24633+
function isSupportedArchitecture(pkg, os, cpu, libc) {
24634+
const osMatches = pkg.os === void 0 || pkg.os.length > 0 && pkg.os.includes(os);
24635+
const cpuMatches = pkg.cpu === void 0 || pkg.cpu.length > 0 && pkg.cpu.includes(cpu);
24636+
const libcMatches = pkg.libc === void 0 || pkg.libc.length > 0 && pkg.libc.includes(libc);
24637+
return osMatches && cpuMatches && libcMatches;
24638+
}
2463324639

2463424640
// src/packs.ts
2463524641
var core3 = __toESM(require_core(), 1);
@@ -24937,7 +24943,7 @@ async function scanForDependencySize(messages, threshold, currentDeps, baseDeps,
2493724943
for (const [pkg, versions] of allOptionalVersions) {
2493824944
for (const version of versions) {
2493924945
const pkgMeta = await fetchPackageMetadata(pkg, version);
24940-
if (pkgMeta && (pkgMeta.os && pkgMeta.os.length > 0 && !pkgMeta.os.includes("linux") || pkgMeta.cpu && pkgMeta.cpu.length > 0 && !pkgMeta.cpu.includes("x64"))) {
24946+
if (pkgMeta && isSupportedArchitecture(pkgMeta, "linux", "x64", "glibc")) {
2494124947
const entry = newVersions.findIndex(
2494224948
(v) => v.name === pkg && v.version === version
2494324949
);

src/checks/dependency-size.ts

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ import * as core from '@actions/core';
22
import {type ParsedLockFile, traverse} from 'lockparse';
33
import {
44
calculateTotalDependencySizeIncrease,
5-
fetchPackageMetadata
5+
fetchPackageMetadata,
6+
isSupportedArchitecture
67
} from '../npm.js';
78
import {formatBytes} from '../common.js';
89

@@ -68,12 +69,7 @@ export async function scanForDependencySize(
6869
const pkgMeta = await fetchPackageMetadata(pkg, version);
6970
if (
7071
pkgMeta &&
71-
((pkgMeta.os &&
72-
pkgMeta.os.length > 0 &&
73-
!pkgMeta.os.includes('linux')) ||
74-
(pkgMeta.cpu &&
75-
pkgMeta.cpu.length > 0 &&
76-
!pkgMeta.cpu.includes('x64')))
72+
isSupportedArchitecture(pkgMeta, 'linux', 'x64', 'glibc')
7773
) {
7874
const entry = newVersions.findIndex(
7975
(v) => v.name === pkg && v.version === version

src/npm.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ export interface PackageMetadata {
66
version: string;
77
os?: string[];
88
cpu?: string[];
9+
libc?: string[];
910
dist?: {
1011
unpackedSize?: number;
1112
attestations?: {
@@ -220,3 +221,18 @@ export function getDependenciesFromPackageJson(
220221

221222
return result;
222223
}
224+
225+
export function isSupportedArchitecture(
226+
pkg: PackageJson,
227+
os: string,
228+
cpu: string,
229+
libc: string
230+
): boolean {
231+
const osMatches =
232+
pkg.os === undefined || (pkg.os.length > 0 && pkg.os.includes(os));
233+
const cpuMatches =
234+
pkg.cpu === undefined || (pkg.cpu.length > 0 && pkg.cpu.includes(cpu));
235+
const libcMatches =
236+
pkg.libc === undefined || (pkg.libc.length > 0 && pkg.libc.includes(libc));
237+
return osMatches && cpuMatches && libcMatches;
238+
}

0 commit comments

Comments
 (0)