@iobroker/repochecker 5.11.1 → 5.12.1

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.
@@ -9,6 +9,7 @@
9
9
  */
10
10
 
11
11
  const compareVersions = require('compare-versions');
12
+ const semver = require('semver');
12
13
 
13
14
  const common = require('./common.js');
14
15
 
@@ -16,8 +17,10 @@ const common = require('./common.js');
16
17
 
17
18
  // node.js versions required and recommended
18
19
  // Note: node version specify rules for engines clause and do NOT reflect the recommended node version for users
19
- const recommendedNodeVersion = '20'; // This is the minimum node version that should be required at engines clause
20
- const requiredNodeVersion = '18'; // This is the minimum node version that must be required at engines clause
20
+ const specialAdapters = ['admin', 'backitup', 'javascript', 'js-controller'];
21
+ let recommendedNodeVersion = '22'; // This is the minimum node version that should be required at engines clause
22
+ let requiredNodeVersion = '20'; // This is the minimum node version that must be required at engines clause
23
+ const minimumNodeVersion = '18'; // This is the minimum node version that must be required ba all adapters at engines clause
21
24
 
22
25
  // packages which must or should be required as dependencies
23
26
  const dependenciesPackageJson = {
@@ -483,6 +486,22 @@ async function checkPackageJson(context) {
483
486
 
484
487
  let passed;
485
488
 
489
+ // adapt some limits for special adapters
490
+ if (specialAdapters.includes(context.adapterName)) {
491
+ if (requiredNodeVersion !== minimumNodeVersion) {
492
+ context.warnings.push(
493
+ `[S0000] Info: required node.js requirement ${requiredNodeVersion} reduced to ${minimumNodeVersion} for this adapter`,
494
+ );
495
+ requiredNodeVersion = minimumNodeVersion;
496
+ }
497
+ if (recommendedNodeVersion !== minimumNodeVersion) {
498
+ context.warnings.push(
499
+ `[S0000] Info: recommended node.js requirement ${recommendedNodeVersion} reduced to ${minimumNodeVersion} for this adapter`,
500
+ );
501
+ recommendedNodeVersion = minimumNodeVersion;
502
+ }
503
+ }
504
+
486
505
  //if (!context.githubUrlOriginal.match(/\/iobroker\./i)) {
487
506
  //console.log(`DEBUG: ${context.githubApiData.name}`)
488
507
  if (!context.githubApiData.name.match(/^iobroker\./i)) {
@@ -952,6 +971,7 @@ async function checkPackageJson(context) {
952
971
  }
953
972
 
954
973
  // check engines clause
974
+ let minimumNodeJsSupported = null;
955
975
  if (!context.cfg.onlyWWW) {
956
976
  if (!context.packageJson.engines) {
957
977
  context.errors.push(
@@ -975,6 +995,7 @@ async function checkPackageJson(context) {
975
995
  );
976
996
  } else {
977
997
  common.debug(`node check: ${JSON.stringify(match.groups)}`);
998
+ minimumNodeJsSupported = match.groups.vers;
978
999
  if (match.groups.cmp !== '>' && match.groups.cmp !== '>=') {
979
1000
  context.warnings.push(
980
1001
  `[W0028] Minimum node.js version ${recommendedNodeVersion} recommended. Please change "{'engines' : { 'node' >= '${match.groups.vers}' } }" to "{'engines' : { 'node' >= '${recommendedNodeVersion}' } }" at package.json.`,
@@ -1001,6 +1022,11 @@ async function checkPackageJson(context) {
1001
1022
  context.checks.push('"engines" check skipped for wwwOnly adapter.');
1002
1023
  }
1003
1024
 
1025
+ // Default to Node.js 20 if no engines clause was found for non-WWW adapters
1026
+ if (minimumNodeJsSupported === null && !context.cfg.onlyWWW) {
1027
+ minimumNodeJsSupported = '20';
1028
+ }
1029
+
1004
1030
  // Apply conditional requirements based on dependencies present in package.json
1005
1031
  // This must be done before checking dependencies so that version requirements are updated
1006
1032
  if (context.packageJson.dependencies) {
@@ -1134,6 +1160,57 @@ async function checkPackageJson(context) {
1134
1160
  }
1135
1161
  context.checks.push('required devDependencies have been checked.');
1136
1162
 
1163
+ // check @types/node version vs engines.node minimum version
1164
+ if (minimumNodeJsSupported !== null) {
1165
+ const minMajor = parseInt(minimumNodeJsSupported.split('.')[0], 10);
1166
+ context.checks.push(
1167
+ `Minimum supported Node.js version from engines clause is ${minimumNodeJsSupported} (major: ${minMajor}).`,
1168
+ );
1169
+
1170
+ const typesNodeDevVersion =
1171
+ context.packageJson.devDependencies && context.packageJson.devDependencies['@types/node'];
1172
+
1173
+ if (!typesNodeDevVersion) {
1174
+ context.warnings.push(
1175
+ `[S0065] No devDependency for "@types/node" found. Consider adding "@types/node":">=${minMajor}" to devDependencies at package.json.`,
1176
+ );
1177
+ }
1178
+
1179
+ // Check @types/node across all dependency types
1180
+ const typesNodeVersion =
1181
+ typesNodeDevVersion ||
1182
+ (context.packageJson.dependencies && context.packageJson.dependencies['@types/node']) ||
1183
+ (context.packageJson.optionalDependencies && context.packageJson.optionalDependencies['@types/node']);
1184
+
1185
+ if (typesNodeVersion) {
1186
+ try {
1187
+ if (!semver.validRange(typesNodeVersion)) {
1188
+ context.errors.push(
1189
+ `[E0068] Invalid semver format ${typesNodeVersion} for "@types/node" at package.json.`,
1190
+ );
1191
+ } else {
1192
+ // Check if @types/node allows a higher major version than the minimum
1193
+ if (semver.intersects(typesNodeVersion, `>=${minMajor + 1}.0.0`)) {
1194
+ context.warnings.push(
1195
+ `[W0066] "@types/node":"${typesNodeVersion}" at package.json allows major version greater than ${minMajor}. Downgrade to node.js ${minMajor}.x.x to avoid wrong typing is recommended.`,
1196
+ );
1197
+ } else if (!semver.satisfies(`${minMajor}.0.0`, typesNodeVersion)) {
1198
+ // Check if @types/node does not cover the minimum node version
1199
+ context.warnings.push(
1200
+ `[S0067] "@types/node":"${typesNodeVersion}" at package.json does not cover minimum node.js version ${minimumNodeJsSupported}. Consider updating to "@types/node":"^${minMajor}" to match the engines clause.`,
1201
+ );
1202
+ } else {
1203
+ context.checks.push(
1204
+ `@types/node "${typesNodeVersion}" matches minimum node.js version ${minimumNodeJsSupported}.`,
1205
+ );
1206
+ }
1207
+ }
1208
+ } catch (e) {
1209
+ common.debug(`Could not check @types/node version "${typesNodeVersion}": ${e}`);
1210
+ }
1211
+ }
1212
+ }
1213
+
1137
1214
  // Check for unneeded devDependencies when @iobroker/testing >= 5.1.1 is installed
1138
1215
  if (context.packageJson.devDependencies && context.packageJson.devDependencies['@iobroker/testing']) {
1139
1216
  const testingVersion = context.packageJson.devDependencies['@iobroker/testing'].replace(/[\^~]/, '').trim();
@@ -1393,3 +1470,7 @@ exports.validateReleaseFormat = validateReleaseFormat;
1393
1470
  // [0062] No devDependency declared for ${dependency}. Please consider adding "${dependency}":"${recommendedVersion}" to devDependencies at package.json`
1394
1471
  // [0063] "${pkg}" is already included in "@iobroker/testing" >= 5.1.1. Please remove from devDependencies at package.json
1395
1472
  // [0064] ${dependency} ${dependencyVersion} specified. Newer version ${actualVersion} exists.
1473
+ // [0065] No devDependency for "@types/node" found. Consider adding "@types/node":">=${minMajor}" to devDependencies at package.json.
1474
+ // [0066] "@types/node":"${typesNodeVersion}" allows node.js major version ${minMajor + 1} or higher. Consider using "^${minMajor}.0.0" or ">=${minMajor} <${minMajor + 1}".
1475
+ // [0067] "@types/node":"${typesNodeVersion}" does not cover minimum node.js version ${minimumNodeJsSupported}. Consider updating to ">=${minMajor}".
1476
+ // [0068] Invalid semver format ${typesNodeVersion} for devDependency "@types/node" at package.json.
@@ -1253,6 +1253,43 @@ async function checkIOPackageJson(context) {
1253
1253
  }
1254
1254
  }
1255
1255
 
1256
+ if (context.ioPackageJson.common.plugins && typeof context.ioPackageJson.common.plugins === 'object') {
1257
+ const pluginNames = Object.keys(context.ioPackageJson.common.plugins);
1258
+ const allDeps = {
1259
+ ...(context.packageJson.dependencies || {}),
1260
+ };
1261
+ const missingPluginDeps = pluginNames
1262
+ .filter(name => name !== 'sentry')
1263
+ .filter(name => !allDeps[`@iobroker/plugin-${name}`]);
1264
+ if (missingPluginDeps.length > 0) {
1265
+ for (const pluginName of missingPluginDeps) {
1266
+ context.warnings.push(
1267
+ `[W1115] Plugin "${pluginName}" listed in io-package.json but "@iobroker/plugin-${pluginName}" is not listed as dependency in package.json.`,
1268
+ );
1269
+ }
1270
+ } else {
1271
+ context.checks.push(
1272
+ 'All plugins in "common.plugins" have corresponding entries in package.json dependencies.',
1273
+ );
1274
+ }
1275
+
1276
+ // W1116: if sentry plugin is used, no explicit @sentry/* packages should be in dependencies
1277
+ if (pluginNames.includes('sentry')) {
1278
+ const sentryDeps = Object.keys(context.packageJson.dependencies || {}).filter(dep =>
1279
+ dep.startsWith('@sentry/'),
1280
+ );
1281
+ if (sentryDeps.length > 0) {
1282
+ context.warnings.push(
1283
+ `[W1116] Sentry plugin is configured in io-package.json but "@sentry/*" packages (${sentryDeps.join(', ')}) are listed as dependencies in package.json. When using the sentry plugin, explicit @sentry/* dependencies should not be added.`,
1284
+ );
1285
+ } else {
1286
+ context.checks.push('Sentry plugin used and no explicit @sentry/* dependencies found in package.json.');
1287
+ }
1288
+ }
1289
+ } else {
1290
+ context.checks.push('"common.plugins" not found in io-package.json, skipping check');
1291
+ }
1292
+
1256
1293
  if (context.ioPackageJson.notifications) {
1257
1294
  if (!Array.isArray(context.ioPackageJson.notifications)) {
1258
1295
  context.errors.push('[E1112] "notifications" in io-package.json must be an array');
@@ -1398,3 +1435,5 @@ exports.checkIOPackageJson = checkIOPackageJson;
1398
1435
  // [1112] "notifications" in io-package.json must be translated into all supported languages
1399
1436
  // [1113] "native" config object will not be used when "common.adminUI.config" is set to "none". Please remove native properties from io-package.json.
1400
1437
  // [1114] "common.schedule" is not supported / unused for daemon adapters and should be removed from io-package.json.
1438
+ // [1115] Plugin "${pluginName}" is listed in "common.plugins" of io-package.json but "@iobroker/plugin-${pluginName}" is not listed as a dependency in package.json. Please add it.
1439
+ // [1116] Sentry plugin is configured in io-package.json but "@sentry/*" packages (${sentryDeps.join(', ')}) are listed as dependencies in package.json. When using the sentry plugin, explicit @sentry/* dependencies should not be added.