Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Send nr version #327

Merged
merged 11 commits into from
Dec 13, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions lib/agent.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ 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')
Expand Down Expand Up @@ -222,7 +223,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 +262,17 @@ class Agent {
agentVersion: this.config.version,
licensed: this.config.licensed
}
if (this.launcher?.readPackage) {
const { modules } = this.launcher.readPackage()
if (module['node-red'] !== 'latest') {
hardillb marked this conversation as resolved.
Show resolved Hide resolved
Steve-Mcl marked this conversation as resolved.
Show resolved Hide resolved
state.nodeRedVersion = modules['node-red']
} else {
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
Steve-Mcl marked this conversation as resolved.
Show resolved Hide resolved
}
}
if (this.currentMode === 'developer' && this.editorToken && this.editorAffinity) {
state.affinity = this.editorAffinity
}
Expand Down Expand Up @@ -434,7 +446,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 @@ -345,7 +346,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
2 changes: 1 addition & 1 deletion lib/mqtt.js
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ class MQTTClient {
}
}

checkIn () {
async checkIn () {
hardillb marked this conversation as resolved.
Show resolved Hide resolved
const payload = this.agent.getState()
if (!payload) {
// No payload means we're busy updating - don't call home
Expand Down
Loading