@@ -2,9 +2,11 @@ const { IntervalJitter } = require('./IntervalJitter')
22const { existsSync } = require ( 'fs' )
33const { randomInt } = require ( 'crypto' )
44const fs = require ( 'fs/promises' )
5+ const { readFileSync } = require ( 'fs' )
56const path = require ( 'path' )
67const httpClient = require ( './http' )
78const mqttClient = require ( './mqtt' )
9+ const semver = require ( 'semver' )
810const Launcher = require ( './launcher.js' )
911const { info, warn, debug } = require ( './logging/log' )
1012const utils = require ( './utils.js' )
@@ -222,7 +224,7 @@ class Agent {
222224
223225 async getCurrentPackage ( ) {
224226 if ( this . launcher ) {
225- return await this . launcher . readPackage ( )
227+ return this . launcher . readPackage ( )
226228 }
227229 return null
228230 }
@@ -261,6 +263,21 @@ class Agent {
261263 agentVersion : this . config . version ,
262264 licensed : this . config . licensed
263265 }
266+ if ( this . launcher ?. readPackage ) {
267+ const { modules } = this . launcher . readPackage ( )
268+ if ( semver . valid ( modules [ 'node-red' ] ) !== null ) {
269+ state . nodeRedVersion = modules [ 'node-red' ]
270+ } else {
271+ try {
272+ const nrPackPath = path . join ( this . launcher . projectDir , 'node_modules/node-red/package.json' )
273+ const content = readFileSync ( nrPackPath )
274+ const packJSON = JSON . parse ( content )
275+ state . nodeRedVersion = packJSON . version
276+ } catch ( err ) {
277+ // Bad node-red install
278+ }
279+ }
280+ }
264281 if ( this . currentMode === 'developer' && this . editorToken && this . editorAffinity ) {
265282 state . affinity = this . editorAffinity
266283 }
@@ -434,7 +451,7 @@ class Agent {
434451 if ( doFull && newState . reloadSnapshot !== true ) {
435452 let diskSnapshot = { flows : [ ] , modules : { } }
436453 try {
437- const modules = ( await _launcher . readPackage ( ) ) ?. modules
454+ const modules = ( _launcher . readPackage ( ) ) ?. modules
438455 const flows = await _launcher . readFlow ( )
439456 diskSnapshot = { flows, modules }
440457 } catch ( error ) {
0 commit comments