@iobroker/js-controller-common 4.0.5-alpha.2-20220208-ac4cf51e → 4.0.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -61,23 +61,23 @@ const IoSeq =
61
61
  Seq &&
62
62
  class extends Seq {
63
63
  log(info, callback) {
64
- const ioInfo = info;
64
+ const ioInfo = deepClone(info);
65
65
  ioInfo.props = ioInfo.props || {};
66
66
 
67
67
  // map our log levels to Seq levels
68
- const level = (info.level || '').toLowerCase();
68
+ const level = (ioInfo.level || '').toLowerCase();
69
69
  if (level.includes('error')) {
70
- info.level = 'Error';
70
+ ioInfo.level = 'Error';
71
71
  } else if (level.includes('warn')) {
72
- info.level = 'Warning';
72
+ ioInfo.level = 'Warning';
73
73
  } else if (level.includes('info')) {
74
- info.level = 'Information';
74
+ ioInfo.level = 'Information';
75
75
  } else if (level.includes('debug')) {
76
- info.level = 'Debug';
76
+ ioInfo.level = 'Debug';
77
77
  } else if (level.includes('silly')) {
78
- info.level = 'Verbose';
78
+ ioInfo.level = 'Verbose';
79
79
  } else {
80
- info.level = 'Information';
80
+ ioInfo.level = 'Information';
81
81
  }
82
82
 
83
83
  // we add own properties
@@ -10,7 +10,7 @@ const cpPromise = require('promisify-child-process');
10
10
  const jwt = require('jsonwebtoken');
11
11
  const { createInterface } = require('readline');
12
12
  const { PassThrough } = require('stream');
13
- const { detectPackageManager } = require('@alcalzone/pak');
13
+ const { detectPackageManager, packageManagers } = require('@alcalzone/pak');
14
14
  const EXIT_CODES = require('./exitCodes');
15
15
  const zlib = require('zlib');
16
16
 
@@ -1258,34 +1258,32 @@ function getRepositoryFile(urlOrPath, additionalInfo, callback) {
1258
1258
  */
1259
1259
  async function getRepositoryFileAsync(url, hash, force, _actualRepo) {
1260
1260
  let _hash;
1261
- if (_actualRepo && !force && hash && (url.startsWith('http://') || url.startsWith('https://'))) {
1262
- axios = axios || require('axios');
1263
- _hash = await axios({ url: url.replace(/\.json$/, '-hash.json'), timeout: 10000 });
1264
- if (_hash && _hash.data && hash === _hash.data.hash) {
1265
- return _actualRepo;
1266
- }
1267
- }
1268
-
1269
1261
  let data;
1270
1262
 
1271
1263
  if (url.startsWith('http://') || url.startsWith('https://')) {
1272
1264
  axios = axios || require('axios');
1273
- if (!_hash) {
1265
+ try {
1274
1266
  _hash = await axios({ url: url.replace(/\.json$/, '-hash.json'), timeout: 10000 });
1267
+ } catch {
1268
+ // ignore missing hash file
1275
1269
  }
1276
1270
 
1277
- if (_actualRepo && hash && _hash && _hash.data && _hash.data.hash === hash) {
1271
+ if (_actualRepo && !force && hash && _hash && _hash.data && _hash.data.hash === hash) {
1278
1272
  data = _actualRepo;
1279
1273
  } else {
1280
1274
  const agent = `${module.exports.appName}, RND: ${randomID}, Node:${process.version}, V:${
1281
1275
  require('../../package.json').version
1282
1276
  }`;
1283
- data = await axios({
1284
- url,
1285
- timeout: 10000,
1286
- headers: { 'User-Agent': agent }
1287
- });
1288
- data = data.data;
1277
+ try {
1278
+ data = await axios({
1279
+ url,
1280
+ timeout: 10000,
1281
+ headers: { 'User-Agent': agent }
1282
+ });
1283
+ data = data.data;
1284
+ } catch (e) {
1285
+ throw new Error(`Cannot download repository file from "${url}": ${e.message}`);
1286
+ }
1289
1287
  }
1290
1288
  } else {
1291
1289
  if (fs.existsSync(url)) {
@@ -1456,6 +1454,38 @@ function getSystemNpmVersion(callback) {
1456
1454
 
1457
1455
  const getSystemNpmVersionAsync = promisify(getSystemNpmVersion);
1458
1456
 
1457
+ /**
1458
+ * @private
1459
+ * Figure out which package manager is in charge, but with a fallback to npm.
1460
+ * @param {string} [cwd] Which directory to work in. If none is given, this defaults to ioBroker's root directory.
1461
+ * @returns {Promise<PackageManager>}
1462
+ */
1463
+ async function detectPackageManagerWithFallback(cwd) {
1464
+ try {
1465
+ // For the first attempt, use pak's default of requiring a lockfile. This makes sure we find ioBroker's root dir
1466
+ return await detectPackageManager(
1467
+ typeof cwd === 'string'
1468
+ ? // If a cwd was provided, use it
1469
+ { cwd }
1470
+ : // Otherwise try to find the ioBroker root dir
1471
+ {
1472
+ cwd: __dirname,
1473
+ setCwdToPackageRoot: true
1474
+ }
1475
+ );
1476
+ } catch {
1477
+ // Lockfile not found, use default to avoid picking up a wrong package manager
1478
+ // like a globally installed yarn
1479
+ }
1480
+
1481
+ // Since we have no lockfile to rely on, assume the root dir is 2 levels above js-controller
1482
+ const ioBrokerRootDir = path.join(getControllerDir(), '../..');
1483
+ // And fallback to npm
1484
+ const pak = new packageManagers.npm();
1485
+ pak.cwd = cwd || ioBrokerRootDir;
1486
+ return pak;
1487
+ }
1488
+
1459
1489
  /**
1460
1490
  * @typedef {object} InstallNodeModuleOptions
1461
1491
  * @property {boolean} [unsafePerm] Whether the `--unsafe-perm` flag should be used
@@ -1471,16 +1501,7 @@ const getSystemNpmVersionAsync = promisify(getSystemNpmVersion);
1471
1501
  */
1472
1502
  async function installNodeModule(npmUrl, options = {}) {
1473
1503
  // Figure out which package manager is in charge (probably npm at this point)
1474
- const pak = await detectPackageManager(
1475
- typeof options.cwd === 'string'
1476
- ? // If a cwd was provided, use it
1477
- { cwd: options.cwd }
1478
- : // Otherwise find the ioBroker root dir
1479
- {
1480
- cwd: __dirname,
1481
- setCwdToPackageRoot: true
1482
- }
1483
- );
1504
+ const pak = await detectPackageManagerWithFallback(options.cwd);
1484
1505
  // By default, don't print all the stuff the package manager spits out
1485
1506
  if (!options.debug) {
1486
1507
  pak.loglevel = 'error';
@@ -1520,16 +1541,7 @@ async function installNodeModule(npmUrl, options = {}) {
1520
1541
  */
1521
1542
  async function uninstallNodeModule(packageName, options = {}) {
1522
1543
  // Figure out which package manager is in charge (probably npm at this point)
1523
- const pak = await detectPackageManager(
1524
- typeof options.cwd === 'string'
1525
- ? // If a cwd was provided, use it
1526
- { cwd: options.cwd }
1527
- : // Otherwise find the ioBroker root dir
1528
- {
1529
- cwd: __dirname,
1530
- setCwdToPackageRoot: true
1531
- }
1532
- );
1544
+ const pak = await detectPackageManagerWithFallback(options.cwd);
1533
1545
  // By default, don't print all the stuff the package manager spits out
1534
1546
  if (!options.debug) {
1535
1547
  pak.loglevel = 'error';
@@ -1563,16 +1575,7 @@ async function uninstallNodeModule(packageName, options = {}) {
1563
1575
  */
1564
1576
  async function rebuildNodeModules(options = {}) {
1565
1577
  // Figure out which package manager is in charge (probably npm at this point)
1566
- const pak = await detectPackageManager(
1567
- typeof options.cwd === 'string'
1568
- ? // If a cwd was provided, use it
1569
- { cwd: options.cwd }
1570
- : // Otherwise find the ioBroker root dir
1571
- {
1572
- cwd: __dirname,
1573
- setCwdToPackageRoot: true
1574
- }
1575
- );
1578
+ const pak = await detectPackageManagerWithFallback(options.cwd);
1576
1579
  // By default, don't print all the stuff the package manager spits out
1577
1580
  if (!options.debug) {
1578
1581
  pak.loglevel = 'error';
@@ -2995,6 +2998,7 @@ function pipeLinewise(input, output) {
2995
2998
  crlfDelay: Infinity
2996
2999
  });
2997
3000
  rl.on('line', line => output.write(line + os.EOL));
3001
+ rl.on('error', () => {}); // Ignore errors
2998
3002
  }
2999
3003
 
3000
3004
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@iobroker/js-controller-common",
3
- "version": "4.0.5-alpha.2-20220208-ac4cf51e",
3
+ "version": "4.0.7",
4
4
  "engines": {
5
5
  "node": ">=12.0.0"
6
6
  },
@@ -47,5 +47,5 @@
47
47
  "lib/",
48
48
  "index.js"
49
49
  ],
50
- "gitHead": "164e97c24ac7094a4442a3d44268e2b480db1171"
50
+ "gitHead": "2237fea5948423f64650a3cc58286eec11335729"
51
51
  }