Skip to content

Commit

Permalink
feat: supporting prerelease and build modifiers as well as .x notatio…
Browse files Browse the repository at this point in the history
…n for versions
  • Loading branch information
martinheidegger committed Apr 26, 2022
1 parent 2a6165e commit 34556c6
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
5 changes: 3 additions & 2 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -306,9 +306,10 @@ function validatePluginDefinition (key: string, value: string, index: number, st
if (value === '*' || value === '') {
throw new Error(`${e} "${key}" can not be marked as "${value}" as a vague version is not cachable or secure!`)
}
const parts = /^(\^|~|>=|<|>|<=|==)?((\d+)(\.\d+)?(\.\d+)?)?$/.exec(value)
const parts = /^(\^|~|>=|<|>|<=|==)?((\d+)(\.([0-9]+|x))?(\.([0-9]+|x))?(-[a-z0-9.]+)?(\+[a-z0-9.]+)?)?$/i.exec(value)
if (parts !== null) {
const [range, version, major, minor, patch] = parts.slice(1)
/* eslint-disable-next-line @typescript-eslint/no-unused-vars */
const [range, version, major, minor, _minorNum, patch, _patchNum] = parts.slice(1)
if (strict) {
if (range !== undefined || range === '') {
throw new Error(`${e} "${key}" can not specify a version range "${range}" and needs to be just the version: ${version ?? '1.2.3'}`)
Expand Down
23 changes: 18 additions & 5 deletions test/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ import { PluginDefinitions, validatePluginDefinitions } from '../index'

const valids: Array<{ input: PluginDefinitions, test?: PluginDefinitions, strict?: boolean }> = [
{ input: {} },
{
input: {
a: '1.2.3'
}
},
{ input: { a: '1.2.3' } },
{ input: { a: '1.2' }, strict: false },
{ input: { a: '1.2.x' }, strict: false },
{ input: { a: '1.2.3-prerelease.build1' } },
{ input: { a: '1.2.3-prerelease.build1+build' } },
{ input: { a: '1.2.3+build' } },
{
input: {
// Keys unsorted!
Expand Down Expand Up @@ -144,6 +145,18 @@ const invalids: Array<{ def: PluginDefinitions, error: string, strict?: boolean
' a': '1.2.3'
},
error: 'Entry #0 has a name with a space in it, this is not acceptable. Use names without spaces!'
},
{
def: { a: '1.2x.3' },
error: 'Entry #0 "a" needs to be either a (semver-)version like 1.2.3 or a valid URL: 1.2x.3'
},
{
def: { a: '1.2.3x' },
error: 'Entry #0 "a" needs to be either a (semver-)version like 1.2.3 or a valid URL: 1.2.3x'
},
{
def: { a: '1.x2.3' },
error: 'Entry #0 "a" needs to be either a (semver-)version like 1.2.3 or a valid URL: 1.x2.3'
}
]

Expand Down

0 comments on commit 34556c6

Please sign in to comment.