diff --git a/lib/debug.js b/lib/debug.js index a208e72ea..b6e1f9655 100644 --- a/lib/debug.js +++ b/lib/debug.js @@ -1,4 +1,4 @@ -const fork = require('child_process').fork; +const fork = require('node:child_process').fork; const adapter = { log: { @@ -151,4 +151,4 @@ function debugScript(data) { }); } -debugScript({ scriptName: 'script.js.Skript_1' }); \ No newline at end of file +debugScript({ scriptName: 'script.js.Skript_1' }); diff --git a/lib/debugger.js b/lib/debugger.js index b08ab05e1..8b577c669 100644 --- a/lib/debugger.js +++ b/lib/debugger.js @@ -20,12 +20,12 @@ * IN THE SOFTWARE. */ 'use strict'; -//const FS = require('fs'); -const Path = require('path'); +// const FS = require('fs'); +const Path = require('node:path'); const Repl = require('repl'); -const util = require('util'); +const util = require('node:util'); const vm = require('vm'); -const fileURLToPath = require('url').fileURLToPath; +const fileURLToPath = require('node:url').fileURLToPath; const debuglog = util.debuglog('inspect'); diff --git a/lib/inspect.js b/lib/inspect.js index 883e4bdb2..ea40f65c0 100644 --- a/lib/inspect.js +++ b/lib/inspect.js @@ -20,12 +20,12 @@ * IN THE SOFTWARE. */ 'use strict'; -const { spawn } = require('child_process'); -const { EventEmitter } = require('events'); -const net = require('net'); -const util = require('util'); -const path = require('path'); -const fs = require('fs'); +const { spawn } = require('node:child_process'); +const { EventEmitter } = require('node:events'); +const net = require('node:net'); +const util = require('node:util'); +const path = require('node:path'); +const fs = require('node:fs'); let breakOnStart; for (let i = 0; i < process.argv.length; i++) { diff --git a/lib/mirror.js b/lib/mirror.js index 64d411d20..6ee42ea1c 100644 --- a/lib/mirror.js +++ b/lib/mirror.js @@ -1,6 +1,6 @@ 'use strict'; -const fs = require('fs'); -const path = require('path'); +const fs = require('node:fs'); +const path = require('node:path'); const MODE_0777 = 511; @@ -25,12 +25,12 @@ class Mirror { this.lastSyncID = `${this.from}.lastSync`; this.log = options.log || { - silly: text => console.log(text), - debug: text => console.log(text), - info: text => console.log(text), - log: text => console.log(text), - warn: text => console.warn(text), - error: text => console.error(text) + silly: text => console.log(text), + debug: text => console.log(text), + info: text => console.log(text), + log: text => console.log(text), + warn: text => console.warn(text), + error: text => console.error(text), }; if (!fs.existsSync(this.diskRoot)) { @@ -99,7 +99,7 @@ class Mirror { this.log.error(`Please check that no other processes change data in the mirror directory!`); } - this.watchedFolder[root_].on('error', err => { + this.watchedFolder[root_].on('error', () => { this.log.debug(`Folder ${root_} was deleted`); try { this.watchedFolder[root_] && this.watchedFolder[root_].close(); @@ -115,7 +115,7 @@ class Mirror { } checkLastSyncObject(cb) { - this.adapter.getForeignObject(this.lastSyncID, (err, obj) => { + this.adapter.getForeignObject(this.lastSyncID, (_err, obj) => { if (!obj) { // create variable const obj = { @@ -128,13 +128,13 @@ class Mirror { min: 0, read: true, }, - type: 'state' + type: 'state', }; this.adapter.setForeignObject(this.lastSyncID, obj, () => this.adapter.setForeignState(this.lastSyncID, 0, true, () => cb && cb(0))); } else { - this.adapter.getForeignState(this.lastSyncID, (err, state) => + this.adapter.getForeignState(this.lastSyncID, (_err, state) => cb && cb(state && state.val)); } }); @@ -219,7 +219,7 @@ class Mirror { const diskListEntry = this.diskList[id]; try { //check if the directory exists and create if not: - fs.mkdirSync(path.dirname(diskListEntry.name), {recursive: true, mode: MODE_0777}); + fs.mkdirSync(path.dirname(diskListEntry.name), { recursive: true, mode: MODE_0777 }); fs.writeFileSync(diskListEntry.name, diskListEntry.source, {mode: MODE_0777}); diskListEntry.ts = Date.now(); return true; @@ -588,8 +588,8 @@ class Mirror { } scanDB(cb) { - this.adapter.getObjectView('system', 'channel', {startkey: 'script.js.', endkey: 'script.js.\u9999'}, (err, res) => { - // this is not required, because javascript subscribes on ALL objects + this.adapter.getObjectView('system', 'channel', { startkey: 'script.js.', endkey: 'script.js.\u9999' }, (err, res) => { + // this is not required, because JavaScript subscribes on ALL objects // adapter.subscribeForeignObjects('script.js.*'); const list = {}; if (err) { @@ -603,7 +603,7 @@ class Mirror { } } } - this.adapter.getObjectView('script', 'javascript', {startkey: 'script.js.', endkey: 'script.js.\u9999'}, (err, res) => { + this.adapter.getObjectView('script', 'javascript', { startkey: 'script.js.', endkey: 'script.js.\u9999' }, (err, res) => { if (err) { this.log.error(`Error while checking scripts javascript from objects database: ${err}`); } @@ -612,12 +612,14 @@ class Mirror { const value = res.rows[i].value; if (value && value._id && value.common) { list[res.rows[i].value._id] = res.rows[i].value; - // ensure that every script has a folder and if not then create it + // ensure that every script has a folder and if not, then create it this._checkIfAllFoldersAreExist(res.rows[i].value._id, list); } } } - cb && cb(list); + if (cb) { + cb(list); + } }); }); } diff --git a/package.json b/package.json index 97e2fd789..560387358 100644 --- a/package.json +++ b/package.json @@ -62,6 +62,7 @@ "@alcalzone/release-script-plugin-iobroker": "^3.7.2", "@alcalzone/release-script-plugin-license": "^3.7.0", "@iobroker/adapter-dev": "^1.3.0", + "@iobroker/testing": "^4.1.3", "@iobroker/types": "^6.0.11", "@iobroker/vis-2-widgets-react-dev": "^3.0.7", "alcalzone-shared": "^4.0.8",