Skip to content
This repository was archived by the owner on Apr 4, 2023. It is now read-only.

Commit 56bc5d0

Browse files
fix: parse correctly CLI's version
In case the current Node.js version is not officialy supported by NativeScript CLI, i.e. its new and it is not verified or support for it is deprecated, `tns --version`'s ouput contains warning. Extract the actual version from the output no matter if there's a warning or not.
1 parent a67e4ba commit 56bc5d0

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

publish/scripts/installer.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,15 @@ var prompt = require('prompt-lite');
44

55
const { execSync } = require('child_process');
66
const semver = require('semver');
7-
const tnsVersionFull = execSync('tns --version', { encoding: 'ascii'});
7+
// In case the current Node.js version is not supported by CLI, a warning in `tns --version` output is shown.
8+
// Sample output:
9+
//
10+
/*Support for Node.js ^8.0.0 is deprecated and will be removed in one of the next releases of NativeScript. Please, upgrade to the latest Node.js LTS version.
11+
12+
6.0.0
13+
*/
14+
// Extract the actual version (6.0.0) from it.
15+
const tnsVersionFull = (execSync('tns --version', { encoding: 'ascii'}).match(/^(?:\d+\.){2}\d+.*?$/m) || [])[0];
816

917
// iOS modern build system is supported from version NativeScript-CLI version 5.2.0
1018
const supportsIOSModernBuildSystem = tnsVersionFull.indexOf("5.2.0-") > -1 || semver.gte(tnsVersionFull, "5.2.0");

src/scripts/postinstall.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2251,7 +2251,7 @@ function coerce(version) {
22512251
if (match == null)
22522252
return null;
22532253

2254-
return parse((match[1] || '0') + '.' + (match[2] || '0') + '.' + (match[3] || '0'));
2254+
return parse((match[1] || '0') + '.' + (match[2] || '0') + '.' + (match[3] || '0'));
22552255
}
22562256

22572257

@@ -4176,7 +4176,15 @@ var prompt = __webpack_require__(/*! prompt-lite */ 1);
41764176

41774177
const { execSync } = __webpack_require__(/*! child_process */ 3);
41784178
const semver = __webpack_require__(/*! semver */ 2);
4179-
const tnsVersionFull = execSync('tns --version', { encoding: 'ascii'});
4179+
// In case the current Node.js version is not supported by CLI, a warning in `tns --version` output is shown.
4180+
// Sample output:
4181+
//
4182+
/*Support for Node.js ^8.0.0 is deprecated and will be removed in one of the next releases of NativeScript. Please, upgrade to the latest Node.js LTS version.
4183+
4184+
6.0.0
4185+
*/
4186+
// Extract the actual version (6.0.0) from it.
4187+
const tnsVersionFull = (execSync('tns --version', { encoding: 'ascii'}).match(/^(?:\d+\.){2}\d+.*?$/m) || [])[0];
41804188

41814189
// iOS modern build system is supported from version NativeScript-CLI version 5.2.0
41824190
const supportsIOSModernBuildSystem = tnsVersionFull.indexOf("5.2.0-") > -1 || semver.gte(tnsVersionFull, "5.2.0");

0 commit comments

Comments
 (0)