Skip to content

feat: add a best-effort semver() function to filter expressions - #2

Open
keegancsmith wants to merge 1 commit into
mainfrom
k/semver
Open

keegancsmith wants to merge 1 commit into
mainfrom
k/semver

Conversation

@keegancsmith

Copy link
Copy Markdown
Member

Workiva asked for semver-aware comparisons in Sourcegraph's jsonpath: filter (Linear CU-4085). Versions in config files are rarely strict semver, so semver(value, range) parses loosely (v4, 18.x, ^1.2, actions/checkout@v4, pnpm@9.15.0+sha512..., pnpm lockfile peer suffixes) and treats values it can't read as false. Both arguments are parsed as npm-style ranges and the function is true when they overlap, so one function covers "version below X", "range accepts X" (Workiva's accepts(18.3.1)), and with !, "can't resolve below X". The SOURCEGRAPH.md entry has the full semantics.

Please merge with a merge commit (not squash) so the commit Sourcegraph's go.mod pins stays on main.

Workiva asked for version comparisons, such as finding dependencies older
than a version or whether a declared range accepts one, which regexes
can't express. Version strings in package.json files, lockfiles and
workflows are rarely strict semver, so semver(value, range) parses them
loosely (v4, 18.x, ^1.2, actions/checkout@v4, pnpm@9+sha512...) and treats
anything it can't read as false rather than an error.

Both arguments are parsed as ranges and the function asks whether they
overlap. That covers version-in-range, range-accepts-version, and, with
!, "can't resolve below X", with one function.

Amp-Thread-ID: https://ampcode.com/threads/T-01a21660-38a0-70c9-b11d-fd07df914a14
@keegancsmith keegancsmith changed the title Add a best-effort semver() function to filter expressions feat: add a best-effort semver() function to filter expressions Nov 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant