16
16
'use strict' ;
17
17
18
18
const path = require ( "path" ) ;
19
+ const process = require ( "process" )
19
20
const sinon = require ( "sinon" ) ;
20
21
const should = require ( 'should' ) ;
21
22
const fs = require ( 'fs' ) ;
@@ -25,17 +26,35 @@ var bodyParser = require("body-parser");
25
26
const express = require ( "express" ) ;
26
27
const http = require ( 'http' ) ;
27
28
const stoppable = require ( 'stoppable' ) ;
28
- const readPkgUp = require ( 'read-pkg-up' ) ;
29
29
const semver = require ( 'semver' ) ;
30
30
const EventEmitter = require ( 'events' ) . EventEmitter ;
31
31
32
32
const PROXY_METHODS = [ 'log' , 'status' , 'warn' , 'error' , 'debug' , 'trace' , 'send' ] ;
33
33
34
+
35
+ // Find the nearest package.json
36
+ function findPackageJson ( dir ) {
37
+ dir = path . resolve ( dir || process . cwd ( ) )
38
+ const { root } = path . parse ( dir )
39
+ if ( dir === root ) {
40
+ return null
41
+ }
42
+ const packagePath = path . join ( dir , 'package.json' )
43
+ if ( fs . existsSync ( packagePath ) ) {
44
+ return {
45
+ path : packagePath ,
46
+ packageJson : JSON . parse ( fs . readFileSync ( packagePath , 'utf-8' ) )
47
+ }
48
+ } else {
49
+ return findPackageJson ( path . resolve ( path . join ( dir , '..' ) ) )
50
+ }
51
+ }
52
+
34
53
/**
35
54
* Finds the NR runtime path by inspecting environment
36
55
*/
37
56
function findRuntimePath ( ) {
38
- const upPkg = readPkgUp . sync ( ) ;
57
+ const upPkg = findPackageJson ( )
39
58
// case 1: we're in NR itself
40
59
if ( upPkg . packageJson . name === 'node-red' ) {
41
60
if ( checkSemver ( upPkg . packageJson . version , "<0.20.0" ) ) {
0 commit comments