Skip to content

Commit dcea91e

Browse files
committed
Support alternate format for LTS version strings
1 parent eab41a7 commit dcea91e

File tree

3 files changed

+23
-3
lines changed

3 files changed

+23
-3
lines changed

.eslintignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
deps/
2+
test/temp/

lib/version.js

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ const settings = require('./settings').settings;
88
const Error = require('./error');
99

1010
const versionRegex =
11-
/^(([\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;
11+
/^(([\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;
1212

1313
class NodeVersion {
1414
constructor(remoteName, semanticVersion, arch) {
@@ -103,8 +103,19 @@ class NodeVersion {
103103
remoteName = 'default';
104104
}
105105

106-
if (remoteName === 'default' && settings.remotes) {
107-
remoteName = settings.remotes['default'] || 'node';
106+
if (settings.remotes) {
107+
if (remoteName === 'default') {
108+
remoteName = settings.remotes['default'] || 'node';
109+
} else if (remoteName === 'lts' && !semanticVersion) {
110+
// Interpret an 'lts' remote name as 'node' to enable compatibility
111+
// with NVM-style LTS version strings such as "lts/boron".
112+
remoteName = settings.remotes['default'] || 'node';
113+
if (label === '*') {
114+
// In NVM, "lts/*" means "latest LTS".
115+
// The NVS equivalent is "node/lts".
116+
label = 'lts';
117+
}
118+
}
108119
}
109120

110121
if ((!settings.remotes || !settings.remotes[remoteName]) &&

test/modules/versionTests.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,4 +166,12 @@ test('GetBinaryNameFromVersion', t => {
166166
t.is(NodeVersion.getBinaryNameFromVersion('7.8'), 'node');
167167
});
168168

169+
test('LTS versions', t => {
170+
t.is(NodeVersion.parse('lts').toString(), 'test/lts');
171+
t.is(NodeVersion.parse('lts/*').toString(), 'test/lts');
172+
t.is(NodeVersion.parse('lts/boron').toString(), 'test/boron');
173+
t.throws(() => NodeVersion.parse('lts/6.7.8'),
174+
(e) => e.message.indexOf('Remote name not found') >= 0);
175+
});
176+
169177
test.todo('Match');

0 commit comments

Comments
 (0)