Skip to content

Commit

Permalink
Support alternate format for LTS version strings
Browse files Browse the repository at this point in the history
  • Loading branch information
jasongin committed Oct 15, 2018
1 parent eab41a7 commit dcea91e
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 3 deletions.
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
deps/
test/temp/
17 changes: 14 additions & 3 deletions lib/version.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const settings = require('./settings').settings;
const Error = require('./error');

const versionRegex =
/^(([\w-]+)\/)?((v?(\d+(\.\d+(\.\d+)?)?(-[0-9A-Za-z.-]+)?))|([a-z][a-z_-][0-9a-z_-]*))(\/((x86)|(32)|((x)?64)|(arm\w*)|(ppc\w*)|(s390x)))?$/i;
/^(([\w-]+)\/)?((v?(\d+(\.\d+(\.\d+)?)?(-[0-9A-Za-z.-]+)?))|([a-z][a-z_-][0-9a-z_-]*|\*))(\/((x86)|(32)|((x)?64)|(arm\w*)|(ppc\w*)|(s390x)))?$/i;

class NodeVersion {
constructor(remoteName, semanticVersion, arch) {
Expand Down Expand Up @@ -103,8 +103,19 @@ class NodeVersion {
remoteName = 'default';
}

if (remoteName === 'default' && settings.remotes) {
remoteName = settings.remotes['default'] || 'node';
if (settings.remotes) {
if (remoteName === 'default') {
remoteName = settings.remotes['default'] || 'node';
} else if (remoteName === 'lts' && !semanticVersion) {
// Interpret an 'lts' remote name as 'node' to enable compatibility
// with NVM-style LTS version strings such as "lts/boron".
remoteName = settings.remotes['default'] || 'node';
if (label === '*') {
// In NVM, "lts/*" means "latest LTS".
// The NVS equivalent is "node/lts".
label = 'lts';
}
}
}

if ((!settings.remotes || !settings.remotes[remoteName]) &&
Expand Down
8 changes: 8 additions & 0 deletions test/modules/versionTests.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,4 +166,12 @@ test('GetBinaryNameFromVersion', t => {
t.is(NodeVersion.getBinaryNameFromVersion('7.8'), 'node');
});

test('LTS versions', t => {
t.is(NodeVersion.parse('lts').toString(), 'test/lts');
t.is(NodeVersion.parse('lts/*').toString(), 'test/lts');
t.is(NodeVersion.parse('lts/boron').toString(), 'test/boron');
t.throws(() => NodeVersion.parse('lts/6.7.8'),
(e) => e.message.indexOf('Remote name not found') >= 0);
});

test.todo('Match');

0 comments on commit dcea91e

Please sign in to comment.