Skip to content

Commit

Permalink
Merge pull request #327 from FlowFuse/send-nr-version
Browse files Browse the repository at this point in the history
Send nr version
  • Loading branch information
Steve-Mcl authored Dec 13, 2024
2 parents de9bd72 + d27acfb commit eacc069
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
21 changes: 19 additions & 2 deletions lib/agent.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ const { IntervalJitter } = require('./IntervalJitter')
const { existsSync } = require('fs')
const { randomInt } = require('crypto')
const fs = require('fs/promises')
const { readFileSync } = require('fs')
const path = require('path')
const httpClient = require('./http')
const mqttClient = require('./mqtt')
const semver = require('semver')
const Launcher = require('./launcher.js')
const { info, warn, debug } = require('./logging/log')
const utils = require('./utils.js')
Expand Down Expand Up @@ -222,7 +224,7 @@ class Agent {

async getCurrentPackage () {
if (this.launcher) {
return await this.launcher.readPackage()
return this.launcher.readPackage()
}
return null
}
Expand Down Expand Up @@ -261,6 +263,21 @@ class Agent {
agentVersion: this.config.version,
licensed: this.config.licensed
}
if (this.launcher?.readPackage) {
const { modules } = this.launcher.readPackage()
if (semver.valid(modules['node-red']) !== null) {
state.nodeRedVersion = modules['node-red']
} else {
try {
const nrPackPath = path.join(this.launcher.projectDir, 'node_modules/node-red/package.json')
const content = readFileSync(nrPackPath)
const packJSON = JSON.parse(content)
state.nodeRedVersion = packJSON.version
} catch (err) {
// Bad node-red install
}
}
}
if (this.currentMode === 'developer' && this.editorToken && this.editorAffinity) {
state.affinity = this.editorAffinity
}
Expand Down Expand Up @@ -434,7 +451,7 @@ class Agent {
if (doFull && newState.reloadSnapshot !== true) {
let diskSnapshot = { flows: [], modules: {} }
try {
const modules = (await _launcher.readPackage())?.modules
const modules = (_launcher.readPackage())?.modules
const flows = await _launcher.readFlow()
diskSnapshot = { flows, modules }
} catch (error) {
Expand Down
7 changes: 4 additions & 3 deletions lib/launcher.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const childProcess = require('child_process')
const { existsSync } = require('fs')
const fs = require('fs/promises')
const { readFileSync } = require('fs')
const path = require('path')
const { log, info, debug, warn, NRlog } = require('./logging/log')
const { copyDir, hasProperty } = require('./utils')
Expand Down Expand Up @@ -89,7 +90,7 @@ class Launcher {
await fs.rm(path.join(this.projectDir, '.config.nodes.json.backup'), { force: true })
}

async readPackage () {
readPackage () {
debug(`Reading package.json: ${this.files.packageJSON}`)
const data = {
modules: {},
Expand All @@ -98,7 +99,7 @@ class Launcher {
description: ''
}
try {
const packageJSON = await fs.readFile(this.files.packageJSON)
const packageJSON = readFileSync(this.files.packageJSON)
const packageData = JSON.parse(packageJSON)
data.modules = packageData.dependencies
data.version = packageData.version
Expand Down Expand Up @@ -346,7 +347,7 @@ class Launcher {
// to be updated and the installDependencies function to be run.
const userDefinedNRVersion = this.settings?.editor?.nodeRedVersion
if (userDefinedNRVersion && options?.updateSettings && this.agent?.currentOwnerType === 'application') {
const pkg = await this.readPackage()
const pkg = this.readPackage()
const pkgNRVersion = pkg.modules?.['node-red'] || 'latest'
const snapshotNRVersion = this.snapshot?.modules?.['node-red']
if ((pkgNRVersion !== userDefinedNRVersion || snapshotNRVersion !== userDefinedNRVersion)) {
Expand Down

0 comments on commit eacc069

Please sign in to comment.