@iobroker/repochecker 5.12.1 → 5.13.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.
@@ -8,6 +8,7 @@
8
8
  */
9
9
 
10
10
  const yaml = require('js-yaml');
11
+ const { minimatch } = require('minimatch');
11
12
  const common = require('./common.js');
12
13
 
13
14
  const DEPENDABOT_FILE = '/.github/dependabot.yml';
@@ -35,6 +36,108 @@ function fileExistsInList(context, filePath) {
35
36
  return context.filesList.includes(filePath) || context.filesList.includes(filePath.replace(/^\//, ''));
36
37
  }
37
38
 
39
+ /**
40
+ * Normalizes a dependabot directory specification to absolute unix-style format.
41
+ *
42
+ * @param {unknown} directory - Directory specification from dependabot config
43
+ * @returns {string | null} Normalized directory or null for invalid input
44
+ */
45
+ function normalizeDirectorySpec(directory) {
46
+ if (typeof directory !== 'string') {
47
+ return null;
48
+ }
49
+
50
+ const trimmed = directory.trim();
51
+ if (!trimmed) {
52
+ return null;
53
+ }
54
+
55
+ const withUnixSeparators = trimmed.replace(/\\/g, '/');
56
+ if (withUnixSeparators === '/') {
57
+ return '/';
58
+ }
59
+
60
+ const withLeadingSlash = withUnixSeparators.startsWith('/') ? withUnixSeparators : `/${withUnixSeparators}`;
61
+ return withLeadingSlash.replace(/\/+$/, '') || '/';
62
+ }
63
+
64
+ /**
65
+ * Returns the directory path for a package.json file path.
66
+ *
67
+ * @param {string} filePath - Path to package.json
68
+ * @returns {string} Directory path (always starts with "/")
69
+ */
70
+ function getPackageJsonDirectory(filePath) {
71
+ const normalizedFilePath = filePath.startsWith('/') ? filePath : `/${filePath}`;
72
+ const lastSlash = normalizedFilePath.lastIndexOf('/');
73
+ if (lastSlash <= 0) {
74
+ return '/';
75
+ }
76
+ return normalizedFilePath.substring(0, lastSlash) || '/';
77
+ }
78
+
79
+ /**
80
+ * Returns true when the directory specification is a known wildcard-all shortcut.
81
+ *
82
+ * @param {string} directorySpec - Normalized dependabot directory specification
83
+ * @returns {boolean} true if this pattern covers all directories
84
+ */
85
+ function isAllDirectoriesShortcut(directorySpec) {
86
+ return (
87
+ directorySpec === '**' ||
88
+ directorySpec === '**/*' ||
89
+ directorySpec === '*/**' ||
90
+ directorySpec === '/**' ||
91
+ directorySpec === '/**/*'
92
+ );
93
+ }
94
+
95
+ /**
96
+ * Returns true if a dependabot directory specification covers the package directory.
97
+ *
98
+ * @param {string} packageDirectory - Directory containing package.json
99
+ * @param {unknown} rawDirectorySpec - Raw directory specification from dependabot config
100
+ * @returns {boolean} true if directory specification matches package directory
101
+ */
102
+ function directorySpecMatchesPackageDirectory(packageDirectory, rawDirectorySpec) {
103
+ const directorySpec = normalizeDirectorySpec(rawDirectorySpec);
104
+ if (!directorySpec) {
105
+ return false;
106
+ }
107
+
108
+ if (isAllDirectoriesShortcut(directorySpec)) {
109
+ return true;
110
+ }
111
+
112
+ if (!/[*?[\]{}]/.test(directorySpec)) {
113
+ return packageDirectory === directorySpec;
114
+ }
115
+
116
+ return minimatch(packageDirectory, directorySpec, { dot: true });
117
+ }
118
+
119
+ /**
120
+ * Returns true if an npm dependabot entry covers the given package directory.
121
+ *
122
+ * @param {object} npmEntry - Dependabot update entry with package-ecosystem npm
123
+ * @param {string} packageDirectory - Directory containing package.json
124
+ * @returns {boolean} true if npm entry covers the package directory
125
+ */
126
+ function npmEntryCoversPackageDirectory(npmEntry, packageDirectory) {
127
+ if (directorySpecMatchesPackageDirectory(packageDirectory, npmEntry['directory'])) {
128
+ return true;
129
+ }
130
+
131
+ const configuredDirectories = npmEntry['directories'];
132
+ if (!Array.isArray(configuredDirectories)) {
133
+ return false;
134
+ }
135
+
136
+ return configuredDirectories.some(directorySpec =>
137
+ directorySpecMatchesPackageDirectory(packageDirectory, directorySpec),
138
+ );
139
+ }
140
+
38
141
  /**
39
142
  * Recursively collects all `uses:` string values from a parsed workflow object.
40
143
  *
@@ -311,7 +414,7 @@ async function checkDependabot(context) {
311
414
  context.checks.push('Dependabot is configured for "npm" ecosystem.');
312
415
  }
313
416
 
314
- // W8905: If multiple package.json files exist in non-root directories, check npm entry uses directories wildcard
417
+ // W8905: Ensure every non-root package.json directory is covered by at least one npm dependabot entry
315
418
  if (hasNpm) {
316
419
  const filesList = context.filesList || [];
317
420
  const nonRootPackageJsonFiles = filesList.filter(f => {
@@ -322,23 +425,18 @@ async function checkDependabot(context) {
322
425
 
323
426
  if (nonRootPackageJsonFiles.length > 0) {
324
427
  const npmEntries = updates.filter(u => u['package-ecosystem'] === 'npm');
325
- const hasDirectoriesWildcard = npmEntries.some(u => {
326
- const configuredDirectories = u['directories'];
327
- return (
328
- Array.isArray(configuredDirectories) &&
329
- configuredDirectories.some(dir => dir === '**/*' || dir === '**')
330
- );
428
+ const unmatchedPackageJsonFiles = nonRootPackageJsonFiles.filter(filePath => {
429
+ const packageDirectory = getPackageJsonDirectory(filePath);
430
+ return !npmEntries.some(entry => npmEntryCoversPackageDirectory(entry, packageDirectory));
331
431
  });
332
432
 
333
- if (!hasDirectoriesWildcard) {
433
+ if (unmatchedPackageJsonFiles.length > 0) {
334
434
  context.warnings.push(
335
- `[W8905] Repository contains package.json files in non-root directories (e.g. ${nonRootPackageJsonFiles.slice(0, 3).join(', ')}). ` +
336
- `Dependabot may miss updates unless the "npm" ecosystem entry uses "directories: ['**/*']" instead of "directory: '/'"`,
435
+ `[W8905] Repository contains package.json files in non-root directories (e.g. ${unmatchedPackageJsonFiles.slice(0, 3).join(', ')}), ` +
436
+ `but no npm dependabot entry matches affected directories. Add matching "directory" or "directories" entries.`,
337
437
  );
338
438
  } else {
339
- context.checks.push(
340
- 'Dependabot npm entry uses "directories" wildcard covering non-root package.json files.',
341
- );
439
+ context.checks.push('Dependabot npm entries cover all non-root package.json directories.');
342
440
  }
343
441
  }
344
442
  }
@@ -494,7 +592,7 @@ exports.checkDependabot = checkDependabot;
494
592
  // [E8902] Dependabot configuration file is not valid YAML or cannot be read.
495
593
  // [E8903] No entry with "package-ecosystem:" found.
496
594
  // [E8904] No entry with "package-ecosystem: npm" found.
497
- // [W8905] Repository has non-root package.json but npm entry does not use directories wildcard.
595
+ // [W8905] Repository has non-root package.json directories not covered by npm dependabot entries.
498
596
  // [S8906] Suggest cron instead of monthly schedule.
499
597
  // [W8907] open-pull-requests-limit < 5 (very low).
500
598
  // [S8908] open-pull-requests-limit < 10 (recommend at least 15).
@@ -74,6 +74,26 @@ function isGlobPattern(entry) {
74
74
  return /[*?{]/.test(entry);
75
75
  }
76
76
 
77
+ /**
78
+ * Checks whether a specific file path is included by package.json "files" entries.
79
+ * Handles both plain path entries and glob patterns (using minimatch).
80
+ *
81
+ * @param {string} filePath file path without leading slash (e.g. 'CHANGELOG_OLD.md')
82
+ * @param {string[]} filesEntries entries from package.json "files"
83
+ * @returns {boolean} true if the file is included
84
+ */
85
+ function isFileIncludedInFiles(filePath, filesEntries) {
86
+ return filesEntries.some(entry => {
87
+ const normalized = entry.replace(/^\.?\//, '').replace(/\/+$/, '');
88
+
89
+ if (isGlobPattern(entry)) {
90
+ return minimatch(filePath, normalized, { dot: true });
91
+ }
92
+
93
+ return normalized === '.' || normalized === filePath || filePath.startsWith(`${normalized}/`);
94
+ });
95
+ }
96
+
77
97
  /**
78
98
  * Checks whether the given i18n directory is covered by any entry in the package.json "files" array.
79
99
  * Handles both plain path entries and glob patterns (using minimatch).
@@ -210,10 +230,17 @@ async function checkGitIgnore(context) {
210
230
  // 950 - 989
211
231
  async function checkNpmIgnore(context) {
212
232
  console.log('\n[E9500 - E9998] checkNpmIgnore');
233
+
234
+ // Detect .dev-server directory presence in the repository
235
+ const devServerExistsInRepo = context.filesList.some(
236
+ f => f === '/.dev-server' || f === '/.dev-server/' || f.startsWith('/.dev-server/'),
237
+ );
238
+
213
239
  const checkFiles = [
214
240
  'node_modules/',
215
241
  'test/',
216
242
  'src/',
243
+ 'CHANGELOG_OLD.md',
217
244
  'appveyor.yml',
218
245
  '.travis.yml',
219
246
  'tsconfig.json',
@@ -247,6 +274,19 @@ async function checkNpmIgnore(context) {
247
274
  context.checks.push('package.json "files" already used.');
248
275
  }
249
276
 
277
+ if (isFileIncludedInFiles('CHANGELOG_OLD.md', context.packageJson.files)) {
278
+ context.warnings.push(
279
+ '[S9508] CHANGELOG_OLD.md is included by package.json "files". Consider excluding it from npm package publishing.',
280
+ );
281
+ }
282
+
283
+ // Check that .dev-server directory is not included in package.json "files"
284
+ if (devServerExistsInRepo && isFileIncludedInFiles('.dev-server', context.packageJson.files)) {
285
+ context.errors.push(
286
+ '[E9509] .dev-server directory is included by package.json "files". This development directory must not be published to npm.',
287
+ );
288
+ }
289
+
250
290
  // Check that i18n directories present in the repo are covered by the "files" entries
251
291
  const i18nDirs = findI18nDirs(context.filesList);
252
292
  for (const i18nDir of i18nDirs) {
@@ -321,6 +361,22 @@ async function checkNpmIgnore(context) {
321
361
  );
322
362
  }
323
363
  }
364
+
365
+ // Check that .dev-server directory is excluded from .npmignore
366
+ if (devServerExistsInRepo) {
367
+ const devServerExcluded = rules.some(rule => {
368
+ if (typeof rule === 'string') {
369
+ const normalized = rule.replace(/^\//, '').replace(/\/+$/, '');
370
+ return normalized === '.dev-server';
371
+ }
372
+ return rule.test('.dev-server') || rule.test('.dev-server/');
373
+ });
374
+ if (!devServerExcluded) {
375
+ context.errors.push(
376
+ '[E9510] .dev-server directory found in repository but not excluded in .npmignore. This development directory must not be published to npm.',
377
+ );
378
+ }
379
+ }
324
380
  }
325
381
  }
326
382
  return context;
@@ -348,3 +404,6 @@ exports.checkNpmIgnore = checkNpmIgnore;
348
404
  // [9505] iob_npm.done not found in .npmignore` ### removed ###
349
405
  // [9506] i18n directory excluded by .npmignore
350
406
  // [9507] i18n directory not included in package.json "files"
407
+ // [9508] CHANGELOG_OLD.md included in package.json "files"
408
+ // [9509] .dev-server directory included by package.json "files"
409
+ // [9510] .dev-server directory not excluded in .npmignore
@@ -25,6 +25,7 @@
25
25
  const mapSeverity4New = {
26
26
  W0063: 'E', // [W0063] "@types/mocha, mocha, @types/sinon, sinon"
27
27
  W0028: 'E', // [W0028] Minimum node.js version 22 recommended.
28
+ W0040: 'E', // [W0040] "keywords" within package.json should contain "ioBroker"
28
29
  W1027: 'E', // [W1027] Missing suggested translation into ru,pt,nl,fr,it,es,pl,uk,zh-cn of "common.titleLang"
29
30
  W1032: 'E', // [W1032] Many "common.news" found in io-package.json
30
31
  W1034: 'E', // [W1034] Missing suggested translation into ru,pt,nl,fr,it,es,pl,uk,zh-cn of "common.desc"
@@ -32,6 +33,7 @@ const mapSeverity4New = {
32
33
  W1084: 'E', // [W1084] "common.title" is deprecated and replaced by "common.titleLang".
33
34
  W2007: 'E', // [W2007] Version 0.7.0-beta.2 is tagged as "latest" at npm
34
35
  W3009: 'E', // [W3009] Workflow "test-and-release.yml" is missing recommended concurrency configuration.
36
+ W5512: 'E', // [W5512] admin/jsonConfig.json schema validation error: ...
35
37
  W6021: 'E', // [W6021] "## License" is not the last section in README.md.
36
38
  W8915: 'E', // [W8915] Dependabot npm entry (directory: "/") has no "cooldown" configured.
37
39
  W8916: 'E', // [W8916] Dependabot configuration "/.github/dependabot.yml" has no entry with "package-ecosystem: github-actions".
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "5.12.1",
2
+ "version": "5.13.1",
3
3
  "name": "@iobroker/repochecker",
4
4
  "dependencies": {
5
5
  "ajv": "^8.20.0",