@iobroker/repochecker 5.5.5 → 5.6.0

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.
package/README.md CHANGED
@@ -25,6 +25,13 @@ Example:
25
25
  Placeholder for the next version (at the beginning of the line):
26
26
  ### **WORK IN PROGRESS**
27
27
  -->
28
+ ### 5.6.0 (2026-03-27)
29
+ - (@copilot) Suppress unwanted npm E404 error output when checking adapters that are not published on npm.
30
+ - (@copilot) Added E2006 error when an npm package has no published versions available, instead of silently skipping version checks.
31
+ - (@copilot) Handle unpublished npm packages: detect "Unpublished on ..." response from npm registry and report a specific E2000 error instead of the generic "not found" message; suppress raw npm error logs for unpublished packages in README/LICENSE year checks. [#766]
32
+ - (@copilot) Fixed crash in checkNpm (E2000-E2999) when npm package has no `dist-tags` or `versions` field in registry response. [#764].
33
+ - (@copilot) Added W5042 and S5043 checks: source files (`*.js`, `*.mjs`, `*.cjs`, `*.ts`) are now scanned for `require`/`import` statements (excluding `admin/`, `doc/`, `src-admin/`, `test/` directories and `*.test.*`/`*.config.*` files). W5042 warns when an imported package is not listed in `dependencies` of `package.json`. S5043 suggests using the `node:` prefix when importing known Node.js built-in modules without it.
34
+
28
35
  ### 5.5.5 (2026-03-24)
29
36
  . (mcm1957) remove '[S6014] README.md section "## Installation" should be removed unless the adapter requires special installation handling.'
30
37
 
package/lib/M2000_Npm.js CHANGED
@@ -28,8 +28,17 @@ async function getNpm(context) {
28
28
  try {
29
29
  const response = await axios(`https://registry.npmjs.org/iobroker.${context.adapterName}`);
30
30
  body = response.data;
31
- } catch {
32
- /* */
31
+ } catch (e) {
32
+ if (
33
+ e.response &&
34
+ e.response.data &&
35
+ typeof e.response.data.error === 'string' &&
36
+ e.response.data.error.toLowerCase().includes('unpublish')
37
+ ) {
38
+ context.cfg.npmUnpublished = e.response.data.error;
39
+ context.cfg.npmExists = false;
40
+ return context;
41
+ }
33
42
  }
34
43
  // bug in NPM some modules could be accessed via normal web page, but not by API
35
44
  if (!body) {
@@ -44,6 +53,12 @@ async function getNpm(context) {
44
53
  return context;
45
54
  }
46
55
  }
56
+
57
+ if (!body['dist-tags'] || !body['dist-tags'].latest) {
58
+ context.cfg.npmExists = false;
59
+ return context;
60
+ }
61
+
47
62
  context.cfg.npmExists = true;
48
63
  return context;
49
64
  }
@@ -54,7 +69,18 @@ async function checkNpm(context) {
54
69
  try {
55
70
  const response = await axios(`https://registry.npmjs.org/iobroker.${context.adapterName}`);
56
71
  body = response.data;
57
- } catch {
72
+ } catch (e) {
73
+ if (
74
+ e.response &&
75
+ e.response.data &&
76
+ typeof e.response.data.error === 'string' &&
77
+ e.response.data.error.toLowerCase().includes('unpublish')
78
+ ) {
79
+ context.errors.push(
80
+ `[E2000] Package iobroker.${context.adapterName} was ${e.response.data.error}. Please republish at npm`,
81
+ );
82
+ return context;
83
+ }
58
84
  /* */
59
85
  }
60
86
  // bug in NPM some modules could be accessed via normal web page, but not by API
@@ -63,7 +89,7 @@ async function checkNpm(context) {
63
89
  const _response = await axios(`https://www.npmjs.com/package/iobroker.${context.adapterName}`);
64
90
  if (!_response.data) {
65
91
  context.errors.push(
66
- `[E2000] Package iobroker.${context.adapterName} found on npm. Please publish at npm`,
92
+ `[E2000] Package iobroker.${context.adapterName} not found on npm. Please publish at npm`,
67
93
  );
68
94
  return context;
69
95
  }
@@ -72,13 +98,13 @@ async function checkNpm(context) {
72
98
  context.checks.push('Adapter found on npm');
73
99
  if (!body.includes('href="/~bluefox"') && body.includes('href="/~iobluefox"')) {
74
100
  context.errors.push(
75
- `[E2001] Bluefox was not found in the collaborators on NPM!. Please execute in adapter directory: "npm owner add bluefox iobroker.${context.adapterName}"`,
101
+ `[E2001] Bluefox was not as collaborator on npm. Please execute in adapter directory: "npm owner add bluefox iobroker.${context.adapterName}" or invite him at npmjs.com`,
76
102
  );
77
103
  } else {
78
104
  context.checks.push('Bluefox found in collaborators on NPM');
79
105
  }
80
106
  } catch {
81
- context.errors.push('[E2000] Not found on npm. Please publish');
107
+ context.errors.push('[E2000] Package iobroker.${context.adapterName} not found on npm. Please publish');
82
108
  return context;
83
109
  }
84
110
  } else {
@@ -89,39 +115,45 @@ async function checkNpm(context) {
89
115
  !body.maintainers.find(user => user.name === 'bluefox' || user.name === 'iobluefox')
90
116
  ) {
91
117
  context.errors.push(
92
- `[E2001] Bluefox was not found in the collaborators on NPM!. Please execute in adapter directory: "npm owner add bluefox iobroker.${context.adapterName}"`,
118
+ `[E2001] Bluefox was not as collaborator on npm. Please execute in adapter directory: "npm owner add bluefox iobroker.${context.adapterName}" or invite him at npmjs.com`,
93
119
  );
94
120
  } else {
95
121
  context.checks.push('Bluefox found in collaborators on NPM');
96
122
  }
97
123
 
98
- if (!body['dist-tags'] || context.packageJson.version !== body['dist-tags'].latest) {
99
- if (compareVersions.compare(body['dist-tags'].latest, context.packageJson.version, '>=')) {
100
- context.errors.push(
101
- `[E2003] Version of package.json (${context.packageJson.version}) lower than latest version on NPM (${(body['dist-tags'] && body['dist-tags'].latest) || JSON.stringify(body)})`,
102
- );
103
- } else {
104
- if (!common.isAlphaVersion(context.packageJson.version)) {
105
- context.warnings.push(
106
- `[W2002] Version of package.json (${context.packageJson.version}) doesn't match latest version on NPM (${(body['dist-tags'] && body['dist-tags'].latest) || JSON.stringify(body)})`,
124
+ if (body['dist-tags'] && body['dist-tags'].latest) {
125
+ if (context.packageJson.version !== body['dist-tags'].latest) {
126
+ if (compareVersions.compare(body['dist-tags'].latest, context.packageJson.version, '>=')) {
127
+ context.errors.push(
128
+ `[E2003] Version of package.json (${context.packageJson.version}) lower than latest version on NPM (${body['dist-tags'].latest})`,
107
129
  );
108
130
  } else {
109
- context.checks.push(`Alpha version ${context.packageJson.version} not checked`);
131
+ if (!common.isAlphaVersion(context.packageJson.version)) {
132
+ context.warnings.push(
133
+ `[W2002] Version of package.json (${context.packageJson.version}) doesn't match latest version on NPM (${body['dist-tags'].latest})`,
134
+ );
135
+ } else {
136
+ context.checks.push(`Alpha version ${context.packageJson.version} not checked`);
137
+ }
110
138
  }
139
+ } else {
140
+ context.checks.push(
141
+ `Version of package.json ${context.packageJson.version} matches latest version on NPM`,
142
+ );
111
143
  }
112
- } else {
113
- context.checks.push(`Version of package.json ${context.packageJson.version} matches latest version on NPM`);
114
- }
115
144
 
116
- if (body['dist-tags'] && body['dist-tags'].latest) {
117
145
  if (!context.ioPackageJson.common.news || !context.ioPackageJson.common.news[body['dist-tags'].latest]) {
118
146
  context.errors.push(
119
147
  `[E2005] No "common.news" in io-package.json found for version ${body['dist-tags'].latest} marked as "latest" at npm`,
120
148
  );
121
149
  }
150
+ } else {
151
+ context.errors.push(
152
+ `[E2006] Package iobroker.${context.adapterName} has no valid published version on npm. Please publish a version.`,
153
+ );
122
154
  }
123
155
  }
124
- if (context.ioPackageJson && context.ioPackageJson.common && context.ioPackageJson.common.news) {
156
+ if (context.ioPackageJson && context.ioPackageJson.common && context.ioPackageJson.common.news && body.versions) {
125
157
  const missingVersions = [];
126
158
  for (const vers in context.ioPackageJson.common.news) {
127
159
  //console.log(`[DEBUG] news for ${vers}`);
@@ -156,7 +188,6 @@ exports.getNpm = getNpm;
156
188
  // List of error and warnings used at this module
157
189
  // ----------------------------------------------
158
190
 
159
- // [2000] Not found on npm. Please publish
160
191
  // [2000] Not found on npm. Please publish
161
192
  // [2001] Bluefox was not found in the collaborators on NPM!. Please execute in adapter directory: "npm owner add bluefox iobroker.${context.adapterName}"
162
193
  // [2001] Bluefox was not found in the collaborators on NPM!. Please execute in adapter directory: "npm owner add bluefox iobroker.${context.adapterName}"
@@ -164,3 +195,4 @@ exports.getNpm = getNpm;
164
195
  // [2003] Version of package.json (${context.packageJson.version}) lower than latest version on NPM (${
165
196
  // [2004] Version "${missingVersions.join(', ')}" listed at common.news at io-package.json does not exist at NPM. Please remove from news section.
166
197
  // [2004] Versions "${missingVersions.join(', ')}" listed at common.news at io-package.json do not exist at NPM. Please remove from news section.
198
+ // [2006] Package iobroker.${context.adapterName} has no valid published version on npm. Please publish a version.
package/lib/M5000_Code.js CHANGED
@@ -20,6 +20,52 @@ const M5500__jsonConfig = require('./M5500__JsonConfig.js');
20
20
  // YAML file extensions for validation
21
21
  const yamlExtensions = ['.yml', '.yaml'];
22
22
 
23
+ // Known Node.js built-in modules (can be used with node: prefix)
24
+ const NODE_BUILT_INS = new Set([
25
+ 'assert',
26
+ 'async_hooks',
27
+ 'buffer',
28
+ 'child_process',
29
+ 'cluster',
30
+ 'console',
31
+ 'constants',
32
+ 'crypto',
33
+ 'dgram',
34
+ 'diagnostics_channel',
35
+ 'dns',
36
+ 'domain',
37
+ 'events',
38
+ 'fs',
39
+ 'http',
40
+ 'http2',
41
+ 'https',
42
+ 'inspector',
43
+ 'module',
44
+ 'net',
45
+ 'os',
46
+ 'path',
47
+ 'perf_hooks',
48
+ 'process',
49
+ 'punycode',
50
+ 'querystring',
51
+ 'readline',
52
+ 'repl',
53
+ 'stream',
54
+ 'string_decoder',
55
+ 'sys',
56
+ 'timers',
57
+ 'tls',
58
+ 'trace_events',
59
+ 'tty',
60
+ 'url',
61
+ 'util',
62
+ 'v8',
63
+ 'vm',
64
+ 'wasi',
65
+ 'worker_threads',
66
+ 'zlib',
67
+ ]);
68
+
23
69
  // utility to parse words.js
24
70
  function extractWords(words) {
25
71
  try {
@@ -119,6 +165,84 @@ function isKeyUsedInAdminConfig(context, key) {
119
165
  return false;
120
166
  }
121
167
 
168
+ /**
169
+ * Extract the base package name from an import/require path.
170
+ * For scoped packages like @scope/name/subpath -> @scope/name
171
+ * For regular packages like name/subpath -> name
172
+ *
173
+ * @param {string} importPath - The raw import path
174
+ * @returns {string} The base package name
175
+ */
176
+ function extractPackageName(importPath) {
177
+ if (importPath.startsWith('@')) {
178
+ // Scoped package: @scope/name/... -> @scope/name
179
+ const parts = importPath.split('/');
180
+ return parts.slice(0, 2).join('/');
181
+ }
182
+ // Regular package: name/... -> name
183
+ return importPath.split('/')[0];
184
+ }
185
+
186
+ /**
187
+ * Strip single-line and block comments from source code content.
188
+ * This is a best-effort approach: it handles the common cases but does not
189
+ * account for comment-like sequences inside string literals.
190
+ *
191
+ * @param {string} content - Source file content
192
+ * @returns {string} Content with comments removed
193
+ */
194
+ function stripComments(content) {
195
+ // Remove block comments (/* ... */)
196
+ let result = content.replace(/\/\*[\s\S]*?\*\//g, '');
197
+ // Remove single-line comments (// ...)
198
+ result = result.replace(/\/\/[^\n]*/g, '');
199
+ return result;
200
+ }
201
+
202
+ /**
203
+ * Extract all require/import targets from source file content.
204
+ *
205
+ * @param {string} content - File content
206
+ * @returns {string[]} Array of unique import targets
207
+ */
208
+ function extractImports(content) {
209
+ const imports = new Set();
210
+
211
+ // Strip comments first to avoid matching require/import patterns inside comments
212
+ const code = stripComments(content);
213
+
214
+ // require('...') or require("...") or require(`...`)
215
+ const requirePattern = /\brequire\s*\(\s*['"`]([^'"`\n]+)['"`]\s*\)/g;
216
+ let match;
217
+ while ((match = requirePattern.exec(code)) !== null) {
218
+ imports.add(match[1]);
219
+ }
220
+
221
+ // import ... from '...' (handles multi-line imports too)
222
+ // Requires 'import' keyword before 'from' to avoid matching
223
+ // 'from' in log messages, strings, or other non-import contexts.
224
+ // Non-greedy [\s\S]*? always stops at the nearest 'from', so consecutive
225
+ // import statements are each matched independently.
226
+ const fromPattern = /\b(?:import)\b[\s\S]*?\bfrom\s+['"`]([^'"`\n]+)['"`]/g;
227
+ while ((match = fromPattern.exec(code)) !== null) {
228
+ imports.add(match[1]);
229
+ }
230
+
231
+ // Side-effect imports: import 'package'
232
+ const sideEffectImportPattern = /\bimport\s+['"`]([^'"`\n]+)['"`]/g;
233
+ while ((match = sideEffectImportPattern.exec(code)) !== null) {
234
+ imports.add(match[1]);
235
+ }
236
+
237
+ // dynamic import('...')
238
+ const dynamicImportPattern = /\bimport\s*\(\s*['"`]([^'"`\n]+)['"`]\s*\)/g;
239
+ while ((match = dynamicImportPattern.exec(code)) !== null) {
240
+ imports.add(match[1]);
241
+ }
242
+
243
+ return [...imports];
244
+ }
245
+
122
246
  async function checkCode(context) {
123
247
  console.log('\n[E5000 - E5999] checkCode');
124
248
 
@@ -293,7 +417,7 @@ async function checkCode(context) {
293
417
  }
294
418
  if (unusedI18nKeys.length) {
295
419
  foundI18nLangs.add(lang);
296
- }lang
420
+ }
297
421
  } catch {
298
422
  // parse errors are reported elsewhere
299
423
  }
@@ -1032,7 +1156,110 @@ async function checkCode(context) {
1032
1156
  }
1033
1157
  }
1034
1158
 
1035
- // first free 5042
1159
+ // W5042/S5043: Scan source files for require/import statements and check dependencies
1160
+ // Exclude files in admin/, build/, doc/, src-admin/, admin-src/, test/ directories
1161
+ // and *.test.* and *.config.* files
1162
+ const sourceFileExtensions = new Set(['.js', '.mjs', '.cjs', '.ts']);
1163
+ const excludedSourceDirs = new Set([
1164
+ 'admin',
1165
+ 'build',
1166
+ 'doc',
1167
+ 'src-admin',
1168
+ 'admin-src',
1169
+ 'test',
1170
+ 'node_modules',
1171
+ '.git',
1172
+ '.vscode',
1173
+ '.dev-server',
1174
+ ]);
1175
+ const packageDependencies = context.packageJson.dependencies || {};
1176
+ const packageDevDependencies = context.packageJson.devDependencies || {};
1177
+
1178
+ // Track packages already reported to avoid duplicate messages
1179
+ const reportedDependencyIssues = new Set();
1180
+
1181
+ for (const filePath of Object.keys(context)) {
1182
+ if (!filePath.startsWith('/') || typeof context[filePath] !== 'string') {
1183
+ continue;
1184
+ }
1185
+
1186
+ const ext = path.extname(filePath);
1187
+ if (!sourceFileExtensions.has(ext)) {
1188
+ continue;
1189
+ }
1190
+
1191
+ // Skip files in excluded directories
1192
+ const pathParts = filePath.split('/').filter(p => p !== '');
1193
+ if (pathParts.some(p => excludedSourceDirs.has(p))) {
1194
+ continue;
1195
+ }
1196
+
1197
+ // Skip *.test.* and *.config.* files
1198
+ const fileBaseName = path.basename(filePath);
1199
+ if (fileBaseName === 'tasks.js' || fileBaseName.includes('.test.') || fileBaseName.includes('.config.')) {
1200
+ continue;
1201
+ }
1202
+
1203
+ common.debug(`Scanning "${filePath.slice(1)}" for dependencies`);
1204
+
1205
+ const imports = extractImports(context[filePath]);
1206
+
1207
+ for (const importTarget of imports) {
1208
+ common.debug(` Found import: "${importTarget}"`);
1209
+
1210
+ // Skip relative paths (./xxx, ../xxx) and absolute paths (/xxx)
1211
+ if (importTarget.startsWith('.') || importTarget.startsWith('/')) {
1212
+ continue;
1213
+ }
1214
+
1215
+ // Skip node: prefixed built-ins - check is complete
1216
+ if (importTarget.startsWith('node:')) {
1217
+ continue;
1218
+ }
1219
+
1220
+ // Extract base package name (handles scoped packages and subpath imports)
1221
+ const packageName = extractPackageName(importTarget);
1222
+
1223
+ // Skip if already reported for this package
1224
+ if (reportedDependencyIssues.has(packageName)) {
1225
+ continue;
1226
+ }
1227
+
1228
+ // Skip if package is listed in dependencies
1229
+ if (packageDependencies[packageName]) {
1230
+ continue;
1231
+ }
1232
+
1233
+ // For @types/* packages, devDependencies is also acceptable
1234
+ if (packageName.startsWith('@types/') && packageDevDependencies[packageName]) {
1235
+ continue;
1236
+ }
1237
+
1238
+ // For @iobroker/types, devDependencies is also acceptable
1239
+ if (packageName === '@iobroker/types' && packageDevDependencies['@iobroker/types']) {
1240
+ continue;
1241
+ }
1242
+
1243
+ // @types/iobroker in devDependencies is an acceptable alternative for @iobroker/types
1244
+ if (packageName === '@iobroker/types' && packageDevDependencies['@types/iobroker']) {
1245
+ continue;
1246
+ }
1247
+
1248
+ // Check if it's a known Node.js built-in module
1249
+ if (NODE_BUILT_INS.has(packageName)) {
1250
+ context.warnings.push(
1251
+ `[S5043] Package "${packageName}" is a built-in Node.js module. Please use "node:${packageName}" prefix instead.`,
1252
+ );
1253
+ } else {
1254
+ context.warnings.push(
1255
+ `[W5042] Package "${packageName}" is used in source files but not found in dependencies of package.json. Dependency might be missing.`,
1256
+ );
1257
+ }
1258
+
1259
+ reportedDependencyIssues.add(packageName);
1260
+ }
1261
+ }
1262
+
1036
1263
  // 5500 - xxx reserved for jsonConfig module
1037
1264
 
1038
1265
  return context;
@@ -1091,5 +1318,7 @@ exports.checkCode = checkCode;
1091
1318
  // [5039] "admin/words.js" found but not referenced anywhere. File seems to be outdated, please consider removing it.
1092
1319
  // [E5040] Example configuration (option1/option2) found in "native" of io-package.json. Please remove example configuration from your code. (moved from E1111 in M1000)
1093
1320
  // [W5041] Example configuration (option1/option2) found in i18n translation files (en, de, ...). Please remove example configuration from your code. (renamed from W1111)
1321
+ // [W5042] Package "${packageName}" is used in source files but not found in dependencies of package.json. Dependency might be missing.
1322
+ // [S5043] Package "${packageName}" is a built-in Node.js module. Please use "node:${packageName}" prefix instead.
1094
1323
 
1095
1324
  // [5500 - ] see M5500_jsonConfig.js
@@ -243,21 +243,21 @@ async function checkReadme(context) {
243
243
  }
244
244
 
245
245
  let npmYear = 0;
246
- try {
247
- const result = execSync(`npm view iobroker.${context.adapterName} --json`, { encoding: 'utf-8' });
248
- const npmJson = JSON.parse(result);
249
- //console.log(`[DEBUG] ${JSON.stringify(npmJson)}`);
250
- if (npmJson['dist-tags'] && npmJson['dist-tags'].latest) {
251
- const latest = npmJson['dist-tags'].latest;
252
- const timeStr = npmJson.time[latest];
253
- npmYear = new Date(timeStr).getFullYear();
254
- // console.log(`${latest} - ${timeStr} - ${npmYear}`);
255
- }
256
- } catch (e) {
257
- if (context.npmExists) {
246
+ if (context.cfg.npmExists) {
247
+ try {
248
+ const result = execSync(`npm view iobroker.${context.adapterName} --json`, { encoding: 'utf-8' });
249
+ const npmJson = JSON.parse(result);
250
+ //console.log(`[DEBUG] ${JSON.stringify(npmJson)}`);
251
+ if (npmJson['dist-tags'] && npmJson['dist-tags'].latest) {
252
+ const latest = npmJson['dist-tags'].latest;
253
+ const timeStr = npmJson.time[latest];
254
+ npmYear = new Date(timeStr).getFullYear();
255
+ // console.log(`${latest} - ${timeStr} - ${npmYear}`);
256
+ }
257
+ } catch (e) {
258
258
  context.warnings.push('[W6010] Could not retrieve timestamp of LATEST revision at npm.');
259
+ common.error(`executing "npm view" - ${e}`);
259
260
  }
260
- common.error(`executing "npm view" - ${e}`);
261
261
  }
262
262
 
263
263
  const pos = data.indexOf('## License');
@@ -53,17 +53,19 @@ async function checkLicenseFile(context) {
53
53
  context.checks.push('LICENSE file found');
54
54
 
55
55
  let npmYear = 0;
56
- try {
57
- const result = execSync(`npm view iobroker.${context.adapterName} --json`, { encoding: 'utf-8' });
58
- const npmJson = JSON.parse(result);
59
- //console.log(`[DEBUG] ${JSON.stringify(npmJson)}`);
60
- if (npmJson['dist-tags'] && npmJson['dist-tags'].latest) {
61
- const latest = npmJson['dist-tags'].latest;
62
- const timeStr = npmJson.time[latest];
63
- npmYear = new Date(timeStr).getFullYear();
56
+ if (context.cfg.npmExists) {
57
+ try {
58
+ const result = execSync(`npm view iobroker.${context.adapterName} --json`, { encoding: 'utf-8' });
59
+ const npmJson = JSON.parse(result);
60
+ //console.log(`[DEBUG] ${JSON.stringify(npmJson)}`);
61
+ if (npmJson['dist-tags'] && npmJson['dist-tags'].latest) {
62
+ const latest = npmJson['dist-tags'].latest;
63
+ const timeStr = npmJson.time[latest];
64
+ npmYear = new Date(timeStr).getFullYear();
65
+ }
66
+ } catch (e) {
67
+ common.error(`executing "npm view" - ${e}`);
64
68
  }
65
- } catch (e) {
66
- console.log(`Error executing "npm view" - ${e}`);
67
69
  }
68
70
 
69
71
  if (context.packageJson.license === 'MIT') {
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "5.5.5",
2
+ "version": "5.6.0",
3
3
  "name": "@iobroker/repochecker",
4
4
  "dependencies": {
5
5
  "ajv": "^8.18.0",