From d6695c2de7968364c624f743ca38b13a0b859558 Mon Sep 17 00:00:00 2001 From: Nick O'Leary Date: Mon, 25 Mar 2019 21:15:49 +0000 Subject: [PATCH] Handle Windows paths when trying to resolve @node-red location Fixes #32 --- index.js | 10 ++++++++-- package-lock.json | 2 +- package.json | 2 +- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/index.js b/index.js index 1f3d33c..2866d17 100644 --- a/index.js +++ b/index.js @@ -98,10 +98,16 @@ class NodeTestHelper extends EventEmitter { } else { if (!fs.existsSync(path.join(prefix, '@node-red/runtime/lib/nodes'))) { // Not in the NR source tree, need to go hunting for the modules.... - if (/node_modules\/node-red\/lib$/.test(prefix)) { + if (fs.existsSync(path.join(prefix,'..','node_modules','@node-red/runtime/lib/nodes'))) { + // path/to/node_modules/node-red/lib + // path/to/node_modules/node-red/node_modules/@node-red + prefix = path.resolve(path.join(prefix,"..","node_modules")); + } else if (fs.existsSync(path.join(prefix,'..','..','@node-red/runtime/lib/nodes'))) { + // path/to/node_modules/node-red/lib + // path/to/node_modules/@node-red prefix = path.resolve(path.join(prefix,"..","..")); } else { - throw new Error("Cannot find the NR source tree. Please raise an issue against node-red/node-red-node-test-helper with full details."); + throw new Error("Cannot find the NR source tree. Path: '"+prefix+"'. Please raise an issue against node-red/node-red-node-test-helper with full details."); } } diff --git a/package-lock.json b/package-lock.json index cf5faf9..7c3539a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "node-red-node-test-helper", - "version": "0.2.1", + "version": "0.2.2", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index 3c38581..93a85fc 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "node-red-node-test-helper", - "version": "0.2.1", + "version": "0.2.2", "description": "A test framework for Node-RED nodes", "main": "index.js", "scripts": {