Skip to content

Commit

Permalink
feat: parse legacy lerna tags
Browse files Browse the repository at this point in the history
  • Loading branch information
antongolub committed Jun 21, 2022
1 parent a20c348 commit c130191
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 5 deletions.
21 changes: 16 additions & 5 deletions src/main/js/tag.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ const f0 = {
if (!tag.endsWith('-f0')) return null

const pattern = /^(\d{4}\.(?:[1-9]|1[012])\.(?:0[1-9]|[12]\d|30|31))-((?:[a-z0-9-]+\.)?[a-z0-9-]+)\.(v?\d+\.\d+\.\d+.*)-f0$/
const matched = pattern.exec(tag)
const [, _date, _name, version] = matched || []
const matched = pattern.exec(tag) || []
const [, _date, _name, version] = matched

if (!semver.valid(version)) return null

Expand All @@ -33,8 +33,8 @@ const f1 = {
if (!tag.endsWith('-f1')) return null

const pattern = /^(\d{4}\.(?:[1-9]|1[012])\.(?:0[1-9]|[12]\d|30|31))-[a-z0-9-]+\.(v?\d+\.\d+\.\d+.*)\.([^.]+)-f1$/
const matched = pattern.exec(tag)
const [, _date, version, b64] = matched || []
const matched = pattern.exec(tag) || []
const [, _date, version, b64] = matched

if (!semver.valid(version)) return null

Expand All @@ -54,6 +54,17 @@ const f1 = {
}
}

const lerna = {
parse(tag) {
const pattern = /^(@?[a-z0-9-]+(?:\/[a-z0-9-]+)?)@(v?\d+\.\d+\.\d+.*)/
const [, name, version] = pattern.exec(tag) || []

if (!semver.valid(version)) return null

return {name, version, format: 'lerna', ref: tag}
}
}

// TODO
// const variants = [f0, f1]
// export const parseTag = (tag) => {
Expand All @@ -65,7 +76,7 @@ const f1 = {
// return null
// }

export const parseTag = (tag) => f0.parse(tag) || f1.parse(tag) || null
export const parseTag = (tag) => f0.parse(tag) || f1.parse(tag) || lerna.parse(tag) || null

export const formatTag = (tag) => f0.format(tag) || f1.format(tag) || null

Expand Down
10 changes: 10 additions & 0 deletions src/test/js/tag.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,16 @@ test('formatTag() / parseTag()', () => {
format: 'f1',
ref: '2022.6.13-examplecom.v1.0.0.ZXhhbXBsZS5jb20-f1'
}
],
[
'@qiwi/[email protected]',
{
name: '@qiwi/pijma-ssr',
version: '1.1.12',
format: 'lerna',
ref: '@qiwi/[email protected]'
},
true
]
]

Expand Down

0 comments on commit c130191

Please sign in to comment.