Skip to content

Commit eacc069

Browse files
authored
Merge pull request #327 from FlowFuse/send-nr-version
Send nr version
2 parents de9bd72 + d27acfb commit eacc069

File tree

2 files changed

+23
-5
lines changed

2 files changed

+23
-5
lines changed

lib/agent.js

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@ const { IntervalJitter } = require('./IntervalJitter')
22
const { existsSync } = require('fs')
33
const { randomInt } = require('crypto')
44
const fs = require('fs/promises')
5+
const { readFileSync } = require('fs')
56
const path = require('path')
67
const httpClient = require('./http')
78
const mqttClient = require('./mqtt')
9+
const semver = require('semver')
810
const Launcher = require('./launcher.js')
911
const { info, warn, debug } = require('./logging/log')
1012
const 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) {

lib/launcher.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
const childProcess = require('child_process')
22
const { existsSync } = require('fs')
33
const fs = require('fs/promises')
4+
const { readFileSync } = require('fs')
45
const path = require('path')
56
const { log, info, debug, warn, NRlog } = require('./logging/log')
67
const { copyDir, hasProperty } = require('./utils')
@@ -89,7 +90,7 @@ class Launcher {
8990
await fs.rm(path.join(this.projectDir, '.config.nodes.json.backup'), { force: true })
9091
}
9192

92-
async readPackage () {
93+
readPackage () {
9394
debug(`Reading package.json: ${this.files.packageJSON}`)
9495
const data = {
9596
modules: {},
@@ -98,7 +99,7 @@ class Launcher {
9899
description: ''
99100
}
100101
try {
101-
const packageJSON = await fs.readFile(this.files.packageJSON)
102+
const packageJSON = readFileSync(this.files.packageJSON)
102103
const packageData = JSON.parse(packageJSON)
103104
data.modules = packageData.dependencies
104105
data.version = packageData.version
@@ -346,7 +347,7 @@ class Launcher {
346347
// to be updated and the installDependencies function to be run.
347348
const userDefinedNRVersion = this.settings?.editor?.nodeRedVersion
348349
if (userDefinedNRVersion && options?.updateSettings && this.agent?.currentOwnerType === 'application') {
349-
const pkg = await this.readPackage()
350+
const pkg = this.readPackage()
350351
const pkgNRVersion = pkg.modules?.['node-red'] || 'latest'
351352
const snapshotNRVersion = this.snapshot?.modules?.['node-red']
352353
if ((pkgNRVersion !== userDefinedNRVersion || snapshotNRVersion !== userDefinedNRVersion)) {

0 commit comments

Comments
 (0)