1616'use strict' ;
1717
1818const path = require ( "path" ) ;
19+ const process = require ( "process" )
1920const sinon = require ( "sinon" ) ;
2021const should = require ( 'should' ) ;
2122const fs = require ( 'fs' ) ;
@@ -25,17 +26,35 @@ var bodyParser = require("body-parser");
2526const express = require ( "express" ) ;
2627const http = require ( 'http' ) ;
2728const stoppable = require ( 'stoppable' ) ;
28- const readPkgUp = require ( 'read-pkg-up' ) ;
2929const semver = require ( 'semver' ) ;
3030const EventEmitter = require ( 'events' ) . EventEmitter ;
3131
3232const PROXY_METHODS = [ 'log' , 'status' , 'warn' , 'error' , 'debug' , 'trace' , 'send' ] ;
3333
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+
3453/**
3554 * Finds the NR runtime path by inspecting environment
3655 */
3756function findRuntimePath ( ) {
38- const upPkg = readPkgUp . sync ( ) ;
57+ const upPkg = findPackageJson ( )
3958 // case 1: we're in NR itself
4059 if ( upPkg . packageJson . name === 'node-red' ) {
4160 if ( checkSemver ( upPkg . packageJson . version , "<0.20.0" ) ) {
0 commit comments