Skip to content

Commit 5767f6d

Browse files
committed
Fix semver check to handle prerelease tags
1 parent 8a6e0c0 commit 5767f6d

2 files changed

Lines changed: 15 additions & 7 deletions

File tree

index.js

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ function findRuntimePath() {
3737
const upPkg = readPkgUp.sync();
3838
// case 1: we're in NR itself
3939
if (upPkg.pkg.name === 'node-red') {
40-
if (semver.ltr(upPkg.pkg.version,"<0.20.0")) {
40+
if (checkSemver(upPkg.pkg.version,"<0.20.0")) {
4141
return path.join(path.dirname(upPkg.path), upPkg.pkg.main);
4242
} else {
4343
return path.join(path.dirname(upPkg.path),"packages","node_modules","node-red");
@@ -58,6 +58,14 @@ function findRuntimePath() {
5858
}
5959
}
6060

61+
62+
// As we have prerelease tags in development version, they need stripping off
63+
// before semver will do a sensible comparison with a range.
64+
function checkSemver(localVersion,testRange) {
65+
var parts = localVersion.split("-");
66+
return semver.satisfies(parts[0],testRange);
67+
}
68+
6169
class NodeTestHelper extends EventEmitter {
6270
constructor() {
6371
super();
@@ -79,8 +87,7 @@ class NodeTestHelper extends EventEmitter {
7987
this._log = RED.log;
8088
// access internal Node-RED runtime methods
8189
const prefix = path.dirname(requirePath);
82-
83-
if (semver.ltr(RED.version(),"<0.20.0")) {
90+
if (checkSemver(RED.version(),"<0.20.0")) {
8491
this._context = require(path.join(prefix, 'runtime', 'nodes', 'context'));
8592
this._comms = require(path.join(prefix, 'api', 'editor', 'comms'));
8693
this.credentials = require(path.join(prefix, 'runtime', 'nodes', 'credentials'));
@@ -99,6 +106,7 @@ class NodeTestHelper extends EventEmitter {
99106
this._NodePrototype = require(path.join(prefix, '@node-red/runtime/lib/nodes/Node')).prototype;
100107
}
101108
} catch (ignored) {
109+
console.log(ignored);
102110
// ignore, assume init will be called again by a test script supplying the runtime path
103111
}
104112
}

package-lock.json

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)