Skip to content

Commit

Permalink
feat(versioning-scheme): handle beta versioning scheme
Browse files Browse the repository at this point in the history
Addresses
#121 (comment)
  • Loading branch information
Divyendu Singh committed May 4, 2020
1 parent b59c10b commit d59a0d7
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
16 changes: 14 additions & 2 deletions scripts/extension-version.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
function nextExtensionVersion({ prismaVersion, extensionVersion }) {
const isBeta = prismaVersion.includes('beta')
const derivedExtensionVersion = getDerivedExtensionVersion(
stripPreReleaseText(prismaVersion),
isBeta,
)

const derivedExistingExtensionVersion = getDerivedExtensionVersion(
extensionVersion,
isBeta,
)

if (derivedExtensionVersion === derivedExistingExtensionVersion) {
Expand All @@ -18,13 +21,22 @@ function stripPreReleaseText(version) {
return version.replace('-alpha', '').replace('-beta', '').replace('-dev', '')
}

function getDerivedExtensionVersion(version) {
function getDerivedExtensionVersion(version, isBeta = false) {
const tokens = version.split('.')

// Because https://github.com/prisma/vscode/issues/121#issuecomment-623327393
if (isBeta && tokens.length === 4) {
tokens[2] = 1
}
if (isBeta && tokens.length === 3) {
tokens[1] = 1
}

if (tokens.length === 4) {
return tokens.slice(1).join('.')
}
if (tokens.length === 3) {
return version
return tokens.join('.')
}
throw new Error(
`Version ${version} must have 3 or 4 tokens separated by "." character`,
Expand Down
8 changes: 4 additions & 4 deletions scripts/extension-version.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ describe('next extension version', () => {
prismaVersion: '2.0.0-beta.3',
extensionVersion: '0.0.35',
}),
).to.eq('0.0.3')
).to.eq('0.1.3')
})

it('it should work with stable channel and extension only push', () => {
Expand All @@ -18,7 +18,7 @@ describe('next extension version', () => {
prismaVersion: '2.0.0-beta.3',
extensionVersion: '0.0.3',
}),
).to.eq('0.0.3.1')
).to.eq('0.1.3.1')
})

it('it should work with stable channel and new prisma version', () => {
Expand All @@ -27,7 +27,7 @@ describe('next extension version', () => {
prismaVersion: '2.0.0-beta.4',
extensionVersion: '0.0.3',
}),
).to.eq('0.0.4')
).to.eq('0.1.4')
})

it('it should work with stable channel and new prisma version after an extension only publish', () => {
Expand All @@ -36,7 +36,7 @@ describe('next extension version', () => {
prismaVersion: '2.0.0-beta.4',
extensionVersion: '0.0.3.1',
}),
).to.eq('0.0.4')
).to.eq('0.1.4')
})

it('it should work with unstable channel and current version to new version schema', () => {
Expand Down

0 comments on commit d59a0d7

Please sign in to comment.