Skip to content

Commit

Permalink
Merge pull request #144 from unindented/transform-version-api
Browse files Browse the repository at this point in the history
Add transformVersion as an exportable function
  • Loading branch information
malept authored Oct 4, 2018
2 parents d6d7054 + 8b28e2b commit 82ad864
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ addons:
- fakeroot
- lintian

before_script: chmod -R g-w test/fixtures

deploy:
provider: npm
email: [email protected]
Expand Down
16 changes: 13 additions & 3 deletions src/installer.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,16 @@ function getSize (options) {
return pify(fsize)(options.src)
}

/**
* Transforms a SemVer version into a Debian-style version.
*
* Use '~' on pre-releases for proper Debian version ordering.
* See https://www.debian.org/doc/debian-policy/ch-controlfields.html#s-f-Version
*/
function transformVersion (version) {
return version.replace(/(\d)[_.+-]?((RC|rc|pre|dev|beta|alpha)[_.+-]?\d*)$/, '$1~$2')
}

/**
* Get the hash of default options for the installer. Some come from the info
* read from `package.json`, and some are hardcoded.
Expand All @@ -87,9 +97,7 @@ function getDefaults (data) {
genericName: pkg.genericName || pkg.productName || pkg.name,
description: pkg.description,
productDescription: pkg.productDescription || pkg.description,
// Use '~' on pre-releases for proper Debian version ordering.
// See https://www.debian.org/doc/debian-policy/ch-controlfields.html#s-f-Version
version: (pkg.version || '0.0.0').replace(/(\d)[_.+-]?((RC|rc|pre|dev|beta|alpha)[_.+-]?\d*)$/, '$1~$2'),
version: transformVersion(pkg.version || '0.0.0'),
revision: pkg.revision || '1',

section: 'utils',
Expand Down Expand Up @@ -436,3 +444,5 @@ module.exports = data => {
throw err
})
}

module.exports.transformVersion = transformVersion
7 changes: 7 additions & 0 deletions test/installer.js
Original file line number Diff line number Diff line change
Expand Up @@ -250,4 +250,11 @@ describe('module', function () {
process.umask(defaultMask)
})
})

describe('transformVersion', () => {
it('uses tildes for pre-release versions', () => {
chai.expect(installer.transformVersion('1.2.3')).to.equal('1.2.3')
chai.expect(installer.transformVersion('1.2.3-beta.4')).to.equal('1.2.3~beta.4')
})
})
})

0 comments on commit 82ad864

Please sign in to comment.