diff --git a/package-lock.json b/package-lock.json index b1e676f..a87e53f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@open-audio-stack/core", - "version": "0.1.48", + "version": "0.1.49", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@open-audio-stack/core", - "version": "0.1.48", + "version": "0.1.49", "license": "cc0-1.0", "dependencies": { "@vscode/sudo-prompt": "^9.3.1", diff --git a/package.json b/package.json index 7386922..989f935 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@open-audio-stack/core", - "version": "0.1.48", + "version": "0.1.49", "description": "Open-source audio plugin management software", "type": "module", "main": "./build/index.js", diff --git a/src/classes/Manager.ts b/src/classes/Manager.ts index 98907f3..bead600 100644 --- a/src/classes/Manager.ts +++ b/src/classes/Manager.ts @@ -6,7 +6,7 @@ import { ManagerReport, PackageVersion } from '../types/Package.js'; import { RegistryInterface, RegistryPackages, RegistryType } from '../types/Registry.js'; import { Base } from './Base.js'; import { packageCompatibleFiles } from '../helpers/package.js'; -import { getArchitecture, getSystem } from '../helpers/utilsLocal.js'; +import { Architecture, SystemType } from '../index-browser.js'; export class Manager extends Base { protected config: Config; @@ -64,7 +64,7 @@ export class Manager extends Base { } } - listPackages(installed?: boolean, showAll = false) { + listPackages(installed?: boolean, architecture?: Architecture, system?: SystemType) { let packages = Array.from(this.packages.values()); if (installed !== undefined) { @@ -75,11 +75,13 @@ export class Manager extends Base { ); } - if (!showAll) { + if (architecture || system) { packages = packages.filter(pkg => { const pkgVersion = pkg.getVersionLatest(); if (!pkgVersion) return false; - const files = packageCompatibleFiles(pkgVersion, [getArchitecture()], [getSystem()], []); + const archArr = architecture ? [architecture] : []; + const sysArr = system ? [system] : []; + const files = packageCompatibleFiles(pkgVersion, archArr, sysArr, []); return files.length > 0; }); } diff --git a/tests/classes/Manager.test.ts b/tests/classes/Manager.test.ts index 2bd384c..9c6f078 100644 --- a/tests/classes/Manager.test.ts +++ b/tests/classes/Manager.test.ts @@ -1,5 +1,12 @@ import { expect, test } from 'vitest'; -import { PLUGIN, PLUGIN_PACKAGE, PLUGIN_PACKAGE_EMPTY, PLUGIN_PACKAGE_MULTIPLE } from '../data/Plugin'; +import { + PLUGIN, + PLUGIN_INCOMPATIBLE, + PLUGIN_PACKAGE, + PLUGIN_PACKAGE_EMPTY, + PLUGIN_PACKAGE_INCOMPATIBLE, + PLUGIN_PACKAGE_MULTIPLE, +} from '../data/Plugin'; import { Manager } from '../../src/classes/Manager'; import { RegistryType } from '../../src/types/Registry'; import { Package } from '../../src/classes/Package'; @@ -110,6 +117,15 @@ test('Manager list packages', () => { expect(manager.listPackages(false)).toEqual([pkg]); }); +test('Manager list packages incompatible', () => { + const manager = new Manager(RegistryType.Plugins); + const pkgNoWin = new Package(PLUGIN_PACKAGE_INCOMPATIBLE.slug); + pkgNoWin.addVersion(PLUGIN_PACKAGE_INCOMPATIBLE.version, PLUGIN_INCOMPATIBLE); + manager.addPackage(pkgNoWin); + expect(manager.listPackages(undefined, Architecture.X64, SystemType.Win)).toEqual([]); + expect(manager.listPackages(undefined, Architecture.X64, SystemType.Linux)).toEqual([pkgNoWin]); +}); + test('Manager filter packages', () => { const manager = new Manager(RegistryType.Plugins); const pkg = new Package(PLUGIN_PACKAGE.slug); diff --git a/tests/data/Plugin.ts b/tests/data/Plugin.ts index 5479a6b..6f96741 100644 --- a/tests/data/Plugin.ts +++ b/tests/data/Plugin.ts @@ -91,6 +91,10 @@ export const PLUGIN: PluginInterface = { export const PLUGIN_INSTALLED: PluginInterface = structuredClone(PLUGIN); PLUGIN_INSTALLED.installed = true; +export const PLUGIN_INCOMPATIBLE: PluginInterface = structuredClone(PLUGIN); +// Remove the Windows-compatible file entry so this package is incompatible with Win. +PLUGIN_INCOMPATIBLE.files.splice(4, 1); + export const PLUGIN_PACKAGE: PackageInterface = { slug, version, @@ -121,3 +125,11 @@ export const PLUGIN_PACKAGE_MULTIPLE: PackageInterface = { '1.3.2': PLUGIN, }, }; + +export const PLUGIN_PACKAGE_INCOMPATIBLE: PackageInterface = { + slug, + version, + versions: { + [version]: PLUGIN_INCOMPATIBLE, + }, +};