Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions lib/match-conditions.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,12 @@ export class ConditionMatcher {
}

isStringMatch(conditions) {
// "a && b" — split on && and require every part to match.
if (conditions.includes('&&')) {
const parts = conditions.split('&&').map((s) => s.trim());
if (parts.some((part) => part === '')) return false;
return parts.every((part) => this.isStringMatch(part));
}
if (
semver.validRange(conditions) &&
semver.satisfies(this.semVersion, conditions)
Expand Down
36 changes: 36 additions & 0 deletions test/test-match-conditions.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,5 +128,41 @@ test('isMatch', (t) => {
t.ok(isMatch(true), 'true is matched');
t.notOk(isMatch(false), 'false is not matched');
t.notOk(isMatch(123), 'invalid input is not matched');
t.ok(isMatch('darwin && v5'), 'isMatch delegates && string to isStringMatch');
t.notOk(
isMatch('darwin && hurd'),
'isMatch delegates partial && string -> false'
);
t.end();
});

test('isStringMatch - && malformed', (t) => {
t.notOk(
testMatcher.isStringMatch('darwin &&'),
'trailing && produces empty part -> false'
);
t.notOk(
testMatcher.isStringMatch('&& darwin'),
'leading && produces empty part -> false'
);
t.notOk(testMatcher.isStringMatch('&&'), 'bare && -> false');
t.notOk(
testMatcher.isStringMatch('darwin && && v5'),
'repeated && produces empty middle part -> false'
);
t.end();
});

test('isStringMatch - && syntax with semver range: aix && >=26', (t) => {
const testMatcher = new ConditionMatcher({
version: 'v26.0.0',
platform: 'aix',
arch: 'ppc64',
distro: '',
release: '',
endian: 'big',
fips: ''
});
t.ok(testMatcher.isStringMatch('aix && >=26'), 'aix + v26 -> true');
t.end();
});
Loading