npm-pkg-lint 5.3.2 → 5.4.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.
package/dist/index.js CHANGED
@@ -43,7 +43,7 @@ var require_tmp = __commonJS({
43
43
  "node_modules/tmp/lib/tmp.js"(exports, module) {
44
44
  var fs8 = __require("fs");
45
45
  var os3 = __require("os");
46
- var path8 = __require("path");
46
+ var path10 = __require("path");
47
47
  var crypto2 = __require("crypto");
48
48
  var _c = { fs: fs8.constants, os: os3.constants };
49
49
  var RANDOM_CHARS = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
@@ -250,12 +250,12 @@ var require_tmp = __commonJS({
250
250
  return [actualOptions, callback];
251
251
  }
252
252
  function _resolvePath(name, tmpDir, cb) {
253
- const pathToResolve = path8.isAbsolute(name) ? name : path8.join(tmpDir, name);
253
+ const pathToResolve = path10.isAbsolute(name) ? name : path10.join(tmpDir, name);
254
254
  fs8.stat(pathToResolve, function(err) {
255
255
  if (err) {
256
- fs8.realpath(path8.dirname(pathToResolve), function(err2, parentDir) {
256
+ fs8.realpath(path10.dirname(pathToResolve), function(err2, parentDir) {
257
257
  if (err2) return cb(err2);
258
- cb(null, path8.join(parentDir, path8.basename(pathToResolve)));
258
+ cb(null, path10.join(parentDir, path10.basename(pathToResolve)));
259
259
  });
260
260
  } else {
261
261
  fs8.realpath(pathToResolve, cb);
@@ -263,22 +263,22 @@ var require_tmp = __commonJS({
263
263
  });
264
264
  }
265
265
  function _resolvePathSync(name, tmpDir) {
266
- const pathToResolve = path8.isAbsolute(name) ? name : path8.join(tmpDir, name);
266
+ const pathToResolve = path10.isAbsolute(name) ? name : path10.join(tmpDir, name);
267
267
  try {
268
268
  fs8.statSync(pathToResolve);
269
269
  return fs8.realpathSync(pathToResolve);
270
270
  } catch (_err) {
271
- const parentDir = fs8.realpathSync(path8.dirname(pathToResolve));
272
- return path8.join(parentDir, path8.basename(pathToResolve));
271
+ const parentDir = fs8.realpathSync(path10.dirname(pathToResolve));
272
+ return path10.join(parentDir, path10.basename(pathToResolve));
273
273
  }
274
274
  }
275
275
  function _generateTmpName(opts) {
276
276
  const tmpDir = opts.tmpdir;
277
277
  if (!_isUndefined(opts.name)) {
278
- return path8.join(tmpDir, opts.dir, opts.name);
278
+ return path10.join(tmpDir, opts.dir, opts.name);
279
279
  }
280
280
  if (!_isUndefined(opts.template)) {
281
- return path8.join(tmpDir, opts.dir, opts.template).replace(TEMPLATE_PATTERN, _randomChars(6));
281
+ return path10.join(tmpDir, opts.dir, opts.template).replace(TEMPLATE_PATTERN, _randomChars(6));
282
282
  }
283
283
  const name = [
284
284
  opts.prefix ? opts.prefix : "tmp",
@@ -288,7 +288,7 @@ var require_tmp = __commonJS({
288
288
  _randomChars(12),
289
289
  opts.postfix ? "-" + opts.postfix : ""
290
290
  ].join("");
291
- return path8.join(tmpDir, opts.dir, name);
291
+ return path10.join(tmpDir, opts.dir, name);
292
292
  }
293
293
  function _assertPath(option, value) {
294
294
  if (typeof value !== "string") {
@@ -302,9 +302,9 @@ var require_tmp = __commonJS({
302
302
  function _assertOptionsBase(options) {
303
303
  if (!_isUndefined(options.name)) {
304
304
  const name = options.name;
305
- if (path8.isAbsolute(name)) throw new Error(`name option must not contain an absolute path, found "${name}".`);
306
- const basename = path8.basename(name);
307
- if (basename === ".." || basename === "." || basename !== name) {
305
+ if (path10.isAbsolute(name)) throw new Error(`name option must not contain an absolute path, found "${name}".`);
306
+ const basename2 = path10.basename(name);
307
+ if (basename2 === ".." || basename2 === "." || basename2 !== name) {
308
308
  throw new Error(`name option must not contain a path, found "${name}".`);
309
309
  }
310
310
  }
@@ -332,8 +332,8 @@ var require_tmp = __commonJS({
332
332
  if (_isUndefined(name)) return cb(null);
333
333
  _resolvePath(name, tmpDir, function(err, resolvedPath) {
334
334
  if (err) return cb(err);
335
- const relativePath = path8.relative(tmpDir, resolvedPath);
336
- if (relativePath.startsWith("..") || path8.isAbsolute(relativePath)) {
335
+ const relativePath = path10.relative(tmpDir, resolvedPath);
336
+ if (relativePath.startsWith("..") || path10.isAbsolute(relativePath)) {
337
337
  return cb(new Error(`${option} option must be relative to "${tmpDir}", found "${relativePath}".`));
338
338
  }
339
339
  cb(null, relativePath);
@@ -342,8 +342,8 @@ var require_tmp = __commonJS({
342
342
  function _getRelativePathSync(option, name, tmpDir) {
343
343
  if (_isUndefined(name)) return;
344
344
  const resolvedPath = _resolvePathSync(name, tmpDir);
345
- const relativePath = path8.relative(tmpDir, resolvedPath);
346
- if (relativePath.startsWith("..") || path8.isAbsolute(relativePath)) {
345
+ const relativePath = path10.relative(tmpDir, resolvedPath);
346
+ if (relativePath.startsWith("..") || path10.isAbsolute(relativePath)) {
347
347
  throw new Error(`${option} option must be relative to "${tmpDir}", found "${relativePath}".`);
348
348
  }
349
349
  return relativePath;
@@ -422,6 +422,33 @@ var require_constants = __commonJS({
422
422
  9007199254740991;
423
423
  var MAX_SAFE_COMPONENT_LENGTH = 16;
424
424
  var MAX_SAFE_BUILD_LENGTH = MAX_LENGTH - 6;
425
+ var WHITESPACE_CHARACTERS = [
426
+ " ",
427
+ "\n",
428
+ "\v",
429
+ "\f",
430
+ "\r",
431
+ " ",
432
+ "\xA0",
433
+ "\u1680",
434
+ "\u2000",
435
+ "\u2001",
436
+ "\u2002",
437
+ "\u2003",
438
+ "\u2004",
439
+ "\u2005",
440
+ "\u2006",
441
+ "\u2007",
442
+ "\u2008",
443
+ "\u2009",
444
+ "\u200A",
445
+ "\u2028",
446
+ "\u2029",
447
+ "\u202F",
448
+ "\u205F",
449
+ "\u3000",
450
+ "\uFEFF"
451
+ ];
425
452
  var RELEASE_TYPES = [
426
453
  "major",
427
454
  "premajor",
@@ -436,6 +463,7 @@ var require_constants = __commonJS({
436
463
  MAX_SAFE_COMPONENT_LENGTH,
437
464
  MAX_SAFE_BUILD_LENGTH,
438
465
  MAX_SAFE_INTEGER,
466
+ WHITESPACE_CHARACTERS,
439
467
  RELEASE_TYPES,
440
468
  SEMVER_SPEC_VERSION,
441
469
  FLAG_INCLUDE_PRERELEASE: 1,
@@ -1336,6 +1364,197 @@ var require_lrucache = __commonJS({
1336
1364
  }
1337
1365
  });
1338
1366
 
1367
+ // node_modules/semver/internal/trim-comparator-whitespace.js
1368
+ var require_trim_comparator_whitespace = __commonJS({
1369
+ "node_modules/semver/internal/trim-comparator-whitespace.js"(exports, module) {
1370
+ "use strict";
1371
+ var {
1372
+ MAX_LENGTH,
1373
+ MAX_SAFE_BUILD_LENGTH,
1374
+ WHITESPACE_CHARACTERS
1375
+ } = require_constants();
1376
+ var whitespace2 = new Uint8Array(65536);
1377
+ for (const char of WHITESPACE_CHARACTERS) {
1378
+ whitespace2[char.charCodeAt(0)] = 1;
1379
+ }
1380
+ var isWhitespace = (char) => char !== void 0 && whitespace2[char.charCodeAt(0)] === 1;
1381
+ var isVersionPrefix = (char) => char === "v" || char === "=" || isWhitespace(char);
1382
+ var isDigit2 = (char) => char !== void 0 && char >= "0" && char <= "9";
1383
+ var isLetter = (char) => char !== void 0 && (char >= "a" && char <= "z" || char >= "A" && char <= "Z");
1384
+ var isIdentifierCharacter = (char) => isDigit2(char) || isLetter(char) || char === "-";
1385
+ var isVersionStart = (char) => isDigit2(char) || char === "x" || char === "X" || char === "*";
1386
+ var findDigitsEndIndex = (range, start, limit, digitRuns) => {
1387
+ if (!isDigit2(range[start])) {
1388
+ return start;
1389
+ }
1390
+ if (start >= digitRuns.start && start < digitRuns.end) {
1391
+ return Math.min(start + limit, digitRuns.end);
1392
+ }
1393
+ if (start >= digitRuns.previousStart && start < digitRuns.previousEnd) {
1394
+ return Math.min(start + limit, digitRuns.previousEnd);
1395
+ }
1396
+ let end = start + 1;
1397
+ while (isDigit2(range[end])) {
1398
+ end++;
1399
+ }
1400
+ digitRuns.previousStart = digitRuns.start;
1401
+ digitRuns.previousEnd = digitRuns.end;
1402
+ digitRuns.start = start;
1403
+ digitRuns.end = end;
1404
+ return Math.min(start + limit, end);
1405
+ };
1406
+ var findVersionNumberEndIndex = (range, start, loose, digitRuns) => {
1407
+ if (!loose && range[start] === "0") {
1408
+ return start + 1;
1409
+ }
1410
+ return findDigitsEndIndex(range, start, loose ? MAX_LENGTH : MAX_LENGTH + 1, digitRuns);
1411
+ };
1412
+ var findPrereleaseIdentifierEndIndex = (range, start, loose, digitRuns) => {
1413
+ const digitsEnd = findDigitsEndIndex(range, start, MAX_LENGTH, digitRuns);
1414
+ if (isLetter(range[digitsEnd]) || range[digitsEnd] === "-") {
1415
+ let end = digitsEnd + 1;
1416
+ const limit = end + MAX_SAFE_BUILD_LENGTH;
1417
+ while (end < limit && isIdentifierCharacter(range[end])) {
1418
+ end++;
1419
+ }
1420
+ return end;
1421
+ }
1422
+ return findVersionNumberEndIndex(range, start, loose, digitRuns);
1423
+ };
1424
+ var findPrereleaseEndIndex = (range, start, loose, digitRuns) => {
1425
+ const hyphen = range[start] === "-";
1426
+ if (!loose && !hyphen) {
1427
+ return start;
1428
+ }
1429
+ const identifierStart = start + (hyphen ? 1 : 0);
1430
+ let end = findPrereleaseIdentifierEndIndex(range, identifierStart, loose, digitRuns);
1431
+ if (end === identifierStart) {
1432
+ if (!loose || !hyphen) {
1433
+ return start;
1434
+ }
1435
+ end = findPrereleaseIdentifierEndIndex(range, start, loose, digitRuns);
1436
+ }
1437
+ while (range[end] === ".") {
1438
+ const next = findPrereleaseIdentifierEndIndex(range, end + 1, loose, digitRuns);
1439
+ if (next === end + 1) {
1440
+ break;
1441
+ }
1442
+ end = next;
1443
+ }
1444
+ return end;
1445
+ };
1446
+ var findBuildIdentifierEndIndex = (range, start) => {
1447
+ let end = start;
1448
+ while (end - start < MAX_SAFE_BUILD_LENGTH && isIdentifierCharacter(range[end])) {
1449
+ end++;
1450
+ }
1451
+ return end;
1452
+ };
1453
+ var findBuildEndIndex = (range, start) => {
1454
+ if (range[start] !== "+") {
1455
+ return start;
1456
+ }
1457
+ let end = findBuildIdentifierEndIndex(range, start + 1);
1458
+ if (end === start + 1) {
1459
+ return start;
1460
+ }
1461
+ while (range[end] === ".") {
1462
+ const next = findBuildIdentifierEndIndex(range, end + 1);
1463
+ if (next === end + 1) {
1464
+ break;
1465
+ }
1466
+ end = next;
1467
+ }
1468
+ return end;
1469
+ };
1470
+ var findLooseFullVersionEndIndex = (range, start, digitRuns) => {
1471
+ let end = start;
1472
+ for (let component = 0; component < 3; component++) {
1473
+ const next = findVersionNumberEndIndex(range, end, true, digitRuns);
1474
+ if (next === end) {
1475
+ return start;
1476
+ }
1477
+ end = next;
1478
+ if (component < 2) {
1479
+ if (range[end] !== ".") {
1480
+ return start;
1481
+ }
1482
+ end++;
1483
+ }
1484
+ }
1485
+ const prereleaseEnd = findPrereleaseEndIndex(range, end, true, digitRuns);
1486
+ return findBuildEndIndex(range, prereleaseEnd);
1487
+ };
1488
+ var findPartialVersionComponentEndIndex = (range, start, digitRuns) => {
1489
+ if (isDigit2(range[start])) {
1490
+ return findVersionNumberEndIndex(range, start, false, digitRuns);
1491
+ }
1492
+ return isVersionStart(range[start]) ? start + 1 : start;
1493
+ };
1494
+ var findPartialVersionEndIndex = (range, start, digitRuns) => {
1495
+ let end = findPartialVersionComponentEndIndex(range, start, digitRuns);
1496
+ for (let component = 0; component < 2; component++) {
1497
+ if (range[end] !== ".") {
1498
+ return end;
1499
+ }
1500
+ const next = findPartialVersionComponentEndIndex(range, end + 1, digitRuns);
1501
+ if (next === end + 1) {
1502
+ return end;
1503
+ }
1504
+ end = next;
1505
+ }
1506
+ const prereleaseEnd = findPrereleaseEndIndex(range, end, false, digitRuns);
1507
+ return findBuildEndIndex(range, prereleaseEnd);
1508
+ };
1509
+ var findVersionEndIndex = (range, start, digitRuns) => {
1510
+ const fullVersionEnd = findLooseFullVersionEndIndex(range, start, digitRuns);
1511
+ return fullVersionEnd !== start ? fullVersionEnd : findPartialVersionEndIndex(range, start, digitRuns);
1512
+ };
1513
+ var findRemovableWhitespaceIndex = (range, matchStart) => {
1514
+ let position = matchStart;
1515
+ if (isWhitespace(range[position])) {
1516
+ position++;
1517
+ }
1518
+ if (range[position] === "<" || range[position] === ">") {
1519
+ position++;
1520
+ }
1521
+ if (range[position] === "=") {
1522
+ position++;
1523
+ }
1524
+ return isWhitespace(range[position]) ? position : -1;
1525
+ };
1526
+ var trimComparatorWhitespace = (range) => {
1527
+ let result = "";
1528
+ let copyFrom = 0;
1529
+ let cursor = 0;
1530
+ const digitRuns = { start: -1, end: -1, previousStart: -1, previousEnd: -1 };
1531
+ while (cursor < range.length) {
1532
+ const matchStart = cursor;
1533
+ if (range[cursor] === "<" || range[cursor] === ">") {
1534
+ cursor++;
1535
+ } else if (!isVersionPrefix(range[cursor]) && !isVersionStart(range[cursor])) {
1536
+ cursor++;
1537
+ continue;
1538
+ }
1539
+ while (cursor < range.length && isVersionPrefix(range[cursor])) {
1540
+ cursor++;
1541
+ }
1542
+ if (!isVersionStart(range[cursor])) {
1543
+ continue;
1544
+ }
1545
+ const whitespacePosition = findRemovableWhitespaceIndex(range, matchStart);
1546
+ if (whitespacePosition !== -1) {
1547
+ result += range.slice(copyFrom, whitespacePosition);
1548
+ copyFrom = whitespacePosition + 1;
1549
+ }
1550
+ cursor = findVersionEndIndex(range, cursor, digitRuns);
1551
+ }
1552
+ return result + range.slice(copyFrom);
1553
+ };
1554
+ module.exports = trimComparatorWhitespace;
1555
+ }
1556
+ });
1557
+
1339
1558
  // node_modules/semver/classes/range.js
1340
1559
  var require_range = __commonJS({
1341
1560
  "node_modules/semver/classes/range.js"(exports, module) {
@@ -1417,7 +1636,7 @@ var require_range = __commonJS({
1417
1636
  const hr2 = loose ? re2[t.HYPHENRANGELOOSE] : re2[t.HYPHENRANGE];
1418
1637
  range = range.replace(hr2, hyphenReplace(this.options.includePrerelease));
1419
1638
  debug("hyphen replace", range);
1420
- range = range.replace(re2[t.COMPARATORTRIM], comparatorTrimReplace);
1639
+ range = trimComparatorWhitespace(range);
1421
1640
  debug("comparator trim", range);
1422
1641
  range = range.replace(re2[t.TILDETRIM], tildeTrimReplace);
1423
1642
  debug("tilde trim", range);
@@ -1487,11 +1706,11 @@ var require_range = __commonJS({
1487
1706
  var Comparator = require_comparator();
1488
1707
  var debug = require_debug();
1489
1708
  var SemVer = require_semver();
1709
+ var trimComparatorWhitespace = require_trim_comparator_whitespace();
1490
1710
  var {
1491
1711
  safeRe: re2,
1492
1712
  src,
1493
1713
  t,
1494
- comparatorTrimReplace,
1495
1714
  tildeTrimReplace,
1496
1715
  caretTrimReplace
1497
1716
  } = require_re();
@@ -2407,8 +2626,8 @@ var require_semver2 = __commonJS({
2407
2626
  });
2408
2627
 
2409
2628
  // src/index.ts
2410
- import { createWriteStream, existsSync, promises as fs7, readFileSync } from "node:fs";
2411
- import path7 from "node:path";
2629
+ import { createWriteStream, existsSync as existsSync2, promises as fs7, readFileSync } from "node:fs";
2630
+ import path9 from "node:path";
2412
2631
  import { fileURLToPath as fileURLToPath4 } from "node:url";
2413
2632
  import { parseArgs } from "node:util";
2414
2633
 
@@ -4115,7 +4334,7 @@ import path from "node:path";
4115
4334
  import fs, { promises as fsPromises } from "node:fs";
4116
4335
  import { fileURLToPath } from "node:url";
4117
4336
 
4118
- // node_modules/p-locate/node_modules/yocto-queue/index.js
4337
+ // node_modules/yocto-queue/index.js
4119
4338
  var Node = class {
4120
4339
  value;
4121
4340
  next;
@@ -4181,7 +4400,7 @@ var Queue = class {
4181
4400
  }
4182
4401
  };
4183
4402
 
4184
- // node_modules/p-locate/node_modules/p-limit/index.js
4403
+ // node_modules/p-limit/index.js
4185
4404
  function pLimit(concurrency) {
4186
4405
  if (!((Number.isInteger(concurrency) || concurrency === Number.POSITIVE_INFINITY) && concurrency > 0)) {
4187
4406
  throw new TypeError("Expected `concurrency` to be a number from 1 and up");
@@ -4353,14 +4572,14 @@ var import_tmp = __toESM(require_tmp(), 1);
4353
4572
  function escape(text) {
4354
4573
  return text.replace(/\./, "\\.");
4355
4574
  }
4356
- function directory(path8) {
4357
- return new RegExp(`(^|/)${path8}/`);
4575
+ function directory(path10) {
4576
+ return new RegExp(`(^|/)${path10}/`);
4358
4577
  }
4359
4578
  function extension(ext) {
4360
4579
  return new RegExp(`${escape(ext)}$`);
4361
4580
  }
4362
- function filename(path8) {
4363
- return new RegExp(`(^|/)${escape(path8)}$`);
4581
+ function filename(path10) {
4582
+ return new RegExp(`(^|/)${escape(path10)}$`);
4364
4583
  }
4365
4584
  function rcfile(base) {
4366
4585
  return new RegExp(`${escape(base)}(\\.(js|cjs|mjs|ts|yaml|yml|json))?$`);
@@ -4582,6 +4801,111 @@ function isBlacklisted(filename2) {
4582
4801
  return blacklist_default.some((entry) => filename2.match(entry));
4583
4802
  }
4584
4803
 
4804
+ // src/config/load-config.ts
4805
+ import path4 from "node:path";
4806
+
4807
+ // src/config/find-config.ts
4808
+ import { existsSync } from "node:fs";
4809
+ import path3 from "node:path";
4810
+ var basename = "npm-pkg-lint.config";
4811
+ var extensions = [".js", ".mjs", ".ts", ".mts"];
4812
+ var directories = [".", "config", ".github", ".gitlab"];
4813
+ function* candidates(root) {
4814
+ for (const directory2 of directories) {
4815
+ for (const extension2 of extensions) {
4816
+ yield path3.join(root, directory2, `${basename}${extension2}`);
4817
+ }
4818
+ }
4819
+ }
4820
+ function findConfigFile(dir) {
4821
+ const found = Array.from(candidates(path3.resolve(dir))).filter((it2) => existsSync(it2));
4822
+ if (found.length > 1) {
4823
+ const list = found.map((it2) => ` - ${it2}`).join("\n");
4824
+ throw new Error(
4825
+ `Multiple configuration files found, remove all but one or select one with \`--config\`:
4826
+ ${list}`
4827
+ );
4828
+ }
4829
+ return found[0];
4830
+ }
4831
+
4832
+ // src/config/import-config.ts
4833
+ import { pathToFileURL } from "node:url";
4834
+ async function importConfig(filePath) {
4835
+ const mod = await import(pathToFileURL(filePath).href);
4836
+ return mod.default;
4837
+ }
4838
+
4839
+ // src/config/validate-config.ts
4840
+ var isStringArray = (value) => Array.isArray(value) && value.every((it2) => typeof it2 === "string");
4841
+ var isBoolean = (value) => typeof value === "boolean";
4842
+ var isBooleanOrInteger = (value) => typeof value === "boolean" || Number.isSafeInteger(value);
4843
+ var schema = {
4844
+ allowDependencies: { check: isStringArray, expected: "an array of strings" },
4845
+ allowFiles: { check: isStringArray, expected: "an array of strings" },
4846
+ allowTypesDependencies: { check: isBoolean, expected: "a boolean" },
4847
+ ignoreMissingFields: { check: isBoolean, expected: "a boolean" },
4848
+ ignoreNodeVersion: { check: isBooleanOrInteger, expected: "a boolean or an integer" }
4849
+ };
4850
+ function validateConfig(value, filePath) {
4851
+ if (value === void 0) {
4852
+ throw new Error(`${filePath}: configuration file must have a default export`);
4853
+ }
4854
+ if (typeof value !== "object" || value === null || Array.isArray(value)) {
4855
+ throw new Error(`${filePath}: default export must be an object`);
4856
+ }
4857
+ const errors = [];
4858
+ for (const [key, entry] of Object.entries(value)) {
4859
+ if (!Object.hasOwn(schema, key)) {
4860
+ errors.push(`unknown option "${key}"`);
4861
+ continue;
4862
+ }
4863
+ const { check, expected } = schema[key];
4864
+ if (entry !== void 0 && !check(entry)) {
4865
+ errors.push(`option "${key}" must be ${expected}`);
4866
+ }
4867
+ }
4868
+ if (errors.length > 0) {
4869
+ const list = errors.map((it2) => ` - ${it2}`).join("\n");
4870
+ throw new Error(`${filePath}: invalid configuration:
4871
+ ${list}`);
4872
+ }
4873
+ return value;
4874
+ }
4875
+
4876
+ // src/config/load-config.ts
4877
+ async function loadConfig(options) {
4878
+ const { cwd, configFile } = options;
4879
+ const filePath = configFile ? path4.resolve(cwd, configFile) : findConfigFile(cwd);
4880
+ if (!filePath) {
4881
+ return void 0;
4882
+ }
4883
+ let exported;
4884
+ try {
4885
+ exported = await importConfig(filePath);
4886
+ } catch (err) {
4887
+ const message = err instanceof Error ? err.message : String(err);
4888
+ throw new Error(`Failed to load configuration file "${filePath}": ${message}`, { cause: err });
4889
+ }
4890
+ return { filePath, config: validateConfig(exported, filePath) };
4891
+ }
4892
+
4893
+ // src/config/resolve-options.ts
4894
+ function splitList(values) {
4895
+ return values.flatMap((it2) => it2.split(","));
4896
+ }
4897
+ function resolveOptions(cli, config = {}) {
4898
+ const allowedDependencies2 = cli.allowDependency.length > 0 ? splitList(cli.allowDependency) : config.allowDependencies;
4899
+ const allowedFiles = cli.allowFile.length > 0 ? splitList(cli.allowFile) : config.allowFiles;
4900
+ return {
4901
+ allowedDependencies: new Set(allowedDependencies2),
4902
+ allowedFiles: allowedFiles ?? [],
4903
+ allowTypesDependencies: cli.allowTypesDependencies ?? config.allowTypesDependencies,
4904
+ ignoreMissingFields: cli.ignoreMissingFields ?? config.ignoreMissingFields,
4905
+ ignoreNodeVersion: cli.ignoreNodeVersion ?? config.ignoreNodeVersion ?? false
4906
+ };
4907
+ }
4908
+
4585
4909
  // src/tarball.ts
4586
4910
  import fs3 from "node:fs";
4587
4911
  import { matchesGlob } from "node:path";
@@ -7578,8 +7902,8 @@ async function getFileContent(tarball, filenames) {
7578
7902
  const contents = {};
7579
7903
  return new Promise((resolve, reject) => {
7580
7904
  const t = new rt({
7581
- filter(path8) {
7582
- return filenames.includes(normalize(path8));
7905
+ filter(path10) {
7906
+ return filenames.includes(normalize(path10));
7583
7907
  }
7584
7908
  });
7585
7909
  t.on("entry", (entry) => {
@@ -7724,27 +8048,27 @@ async function verifyTarball(pkg, tarball, options) {
7724
8048
  }
7725
8049
 
7726
8050
  // src/tarball-location.ts
7727
- import path3 from "node:path";
8051
+ import path5 from "node:path";
7728
8052
  function normalize2(name) {
7729
8053
  return name.replace("/", "-").replace(/^@/, "");
7730
8054
  }
7731
8055
  function tarballLocation(pkg, pkgPath) {
7732
8056
  const name = normalize2(pkg.name);
7733
- return path3.join(path3.dirname(pkgPath), `${name}-${pkg.version}.tgz`);
8057
+ return path5.join(path5.dirname(pkgPath), `${name}-${pkg.version}.tgz`);
7734
8058
  }
7735
8059
 
7736
8060
  // src/utils/persistent-cache.ts
7737
8061
  import crypto from "node:crypto";
7738
8062
  import fs4 from "node:fs/promises";
7739
8063
  import os2 from "node:os";
7740
- import path4 from "node:path";
8064
+ import path6 from "node:path";
7741
8065
  var enabled = os2.platform() === "linux";
7742
- var cacheRoot = process.env.XDG_CACHE_HOME ?? path4.join(os2.homedir(), ".cache");
7743
- var cacheDir = path4.join(cacheRoot, "npm-pkg-lint");
8066
+ var cacheRoot = process.env.XDG_CACHE_HOME ?? path6.join(os2.homedir(), ".cache");
8067
+ var cacheDir = path6.join(cacheRoot, "npm-pkg-lint");
7744
8068
  function getFilePath(key) {
7745
8069
  const hash = crypto.createHash("md5").update(key).digest("hex");
7746
8070
  const filename2 = `${hash.slice(0, 2)}/${hash.slice(2)}.json`;
7747
- return path4.join(cacheDir, filename2);
8071
+ return path6.join(cacheDir, filename2);
7748
8072
  }
7749
8073
  async function setCacheDirecory(directory2) {
7750
8074
  await fs4.mkdir(directory2, { recursive: true });
@@ -7771,7 +8095,7 @@ async function persistentCacheSet(key, data) {
7771
8095
  }
7772
8096
  const filePath = getFilePath(key);
7773
8097
  const content = JSON.stringify(data, null, 2);
7774
- await fs4.mkdir(path4.dirname(filePath), { recursive: true });
8098
+ await fs4.mkdir(path6.dirname(filePath), { recursive: true });
7775
8099
  await fs4.writeFile(filePath, content, "utf-8");
7776
8100
  }
7777
8101
 
@@ -7841,7 +8165,7 @@ var getContext = (raw) => ({
7841
8165
  var getCommandPart = (part) => /[^\w./-]/.test(part) ? `'${part.replaceAll("'", "'\\''")}'` : part;
7842
8166
 
7843
8167
  // node_modules/nano-spawn/source/options.js
7844
- import path5 from "node:path";
8168
+ import path7 from "node:path";
7845
8169
  import { fileURLToPath as fileURLToPath3 } from "node:url";
7846
8170
  import process4 from "node:process";
7847
8171
  var getOptions = ({
@@ -7854,7 +8178,7 @@ var getOptions = ({
7854
8178
  cwd: cwdOption = ".",
7855
8179
  ...options
7856
8180
  }) => {
7857
- const cwd = cwdOption instanceof URL ? fileURLToPath3(cwdOption) : path5.resolve(cwdOption);
8181
+ const cwd = cwdOption instanceof URL ? fileURLToPath3(cwdOption) : path7.resolve(cwdOption);
7858
8182
  const env = envOption ? { ...process4.env, ...envOption } : void 0;
7859
8183
  const input = stdio[0]?.string;
7860
8184
  return {
@@ -7866,11 +8190,11 @@ var getOptions = ({
7866
8190
  };
7867
8191
  };
7868
8192
  var addLocalPath = ({ Path = "", PATH = Path, ...env }, cwd) => {
7869
- const pathParts = PATH.split(path5.delimiter);
7870
- const localPaths = getLocalPaths([], path5.resolve(cwd)).map((localPath) => path5.join(localPath, "node_modules/.bin")).filter((localPath) => !pathParts.includes(localPath));
7871
- return { ...env, PATH: [...localPaths, PATH].filter(Boolean).join(path5.delimiter) };
8193
+ const pathParts = PATH.split(path7.delimiter);
8194
+ const localPaths = getLocalPaths([], path7.resolve(cwd)).map((localPath) => path7.join(localPath, "node_modules/.bin")).filter((localPath) => !pathParts.includes(localPath));
8195
+ return { ...env, PATH: [...localPaths, PATH].filter(Boolean).join(path7.delimiter) };
7872
8196
  };
7873
- var getLocalPaths = (localPaths, localPath) => localPaths.at(-1) === localPath ? localPaths : getLocalPaths([...localPaths, localPath], path5.resolve(localPath, ".."));
8197
+ var getLocalPaths = (localPaths, localPath) => localPaths.at(-1) === localPath ? localPaths : getLocalPaths([...localPaths, localPath], path7.resolve(localPath, ".."));
7874
8198
 
7875
8199
  // node_modules/nano-spawn/source/spawn.js
7876
8200
  import { spawn } from "node:child_process";
@@ -7879,7 +8203,7 @@ import process7 from "node:process";
7879
8203
 
7880
8204
  // node_modules/nano-spawn/source/windows.js
7881
8205
  import fs5 from "node:fs/promises";
7882
- import path6 from "node:path";
8206
+ import path8 from "node:path";
7883
8207
  import process5 from "node:process";
7884
8208
  var applyForceShell = async (file, commandArguments, options) => await shouldForceShell(file, options) ? [escapeFile(file), commandArguments.map((argument) => escapeArgument(argument)), { ...options, shell: true }] : [file, commandArguments, options];
7885
8209
  var shouldForceShell = async (file, { shell, cwd, env = process5.env }) => process5.platform === "win32" && !shell && !await isExe(file, cwd, env);
@@ -7895,11 +8219,11 @@ var memoize = (function_) => (...arguments_) => (
7895
8219
  );
7896
8220
  var access = memoize(fs5.access);
7897
8221
  var mIsExe = memoize(async (file, cwd, PATH) => {
7898
- const parts = PATH.split(path6.delimiter).filter(Boolean).map((part) => part.replace(/^"(.*)"$/, "$1"));
8222
+ const parts = PATH.split(path8.delimiter).filter(Boolean).map((part) => part.replace(/^"(.*)"$/, "$1"));
7899
8223
  try {
7900
8224
  await Promise.any(
7901
8225
  [cwd, ...parts].flatMap(
7902
- (part) => exeExtensions.map((extension2) => access(`${path6.resolve(part, file)}${extension2}`))
8226
+ (part) => exeExtensions.map((extension2) => access(`${path8.resolve(part, file)}${extension2}`))
7903
8227
  )
7904
8228
  );
7905
8229
  } catch {
@@ -8360,7 +8684,7 @@ function isDisallowedDependency(pkg, dependency) {
8360
8684
  // src/rules/exports-default-order.ts
8361
8685
  var ruleId4 = "exports-default-order";
8362
8686
  var severity2 = Severity.ERROR;
8363
- function* validateOrder(pkgAst, value, path8) {
8687
+ function* validateOrder(pkgAst, value, path10) {
8364
8688
  if (!value || typeof value === "string") {
8365
8689
  return;
8366
8690
  }
@@ -8369,8 +8693,8 @@ function* validateOrder(pkgAst, value, path8) {
8369
8693
  return;
8370
8694
  }
8371
8695
  if (keys.includes("default") && keys.at(-1) !== "default") {
8372
- const { line, column } = jsonLocation(pkgAst, "member", "exports", ...path8, "default");
8373
- const property = path8.map((it2) => `["${it2}"]`).join("");
8696
+ const { line, column } = jsonLocation(pkgAst, "member", "exports", ...path10, "default");
8697
+ const property = path10.map((it2) => `["${it2}"]`).join("");
8374
8698
  yield {
8375
8699
  ruleId: ruleId4,
8376
8700
  severity: severity2,
@@ -8380,7 +8704,7 @@ function* validateOrder(pkgAst, value, path8) {
8380
8704
  };
8381
8705
  }
8382
8706
  for (const key of keys) {
8383
- yield* validateOrder(pkgAst, value[key], [...path8, key]);
8707
+ yield* validateOrder(pkgAst, value[key], [...path10, key]);
8384
8708
  }
8385
8709
  }
8386
8710
  function* exportsDefaultOrder(pkg, pkgAst) {
@@ -8392,7 +8716,7 @@ function* exportsDefaultOrder(pkg, pkgAst) {
8392
8716
  // src/rules/exports-import-require-order.ts
8393
8717
  var ruleId5 = "exports-import-require-order";
8394
8718
  var severity3 = Severity.ERROR;
8395
- function* validateOrder2(pkgAst, value, path8) {
8719
+ function* validateOrder2(pkgAst, value, path10) {
8396
8720
  if (!value || typeof value === "string") {
8397
8721
  return;
8398
8722
  }
@@ -8405,8 +8729,8 @@ function* validateOrder2(pkgAst, value, path8) {
8405
8729
  if (keys.indexOf(esm) <= keys.indexOf("require")) {
8406
8730
  continue;
8407
8731
  }
8408
- const { line, column } = jsonLocation(pkgAst, "member", "exports", ...path8, esm);
8409
- const property = path8.map((it2) => `["${it2}"]`).join("");
8732
+ const { line, column } = jsonLocation(pkgAst, "member", "exports", ...path10, esm);
8733
+ const property = path10.map((it2) => `["${it2}"]`).join("");
8410
8734
  yield {
8411
8735
  ruleId: ruleId5,
8412
8736
  severity: severity3,
@@ -8417,7 +8741,7 @@ function* validateOrder2(pkgAst, value, path8) {
8417
8741
  }
8418
8742
  }
8419
8743
  for (const key of keys) {
8420
- yield* validateOrder2(pkgAst, value[key], [...path8, key]);
8744
+ yield* validateOrder2(pkgAst, value[key], [...path10, key]);
8421
8745
  }
8422
8746
  }
8423
8747
  function* exportsImportRequireOrder(pkg, pkgAst) {
@@ -8429,14 +8753,14 @@ function* exportsImportRequireOrder(pkg, pkgAst) {
8429
8753
  // src/rules/exports-path.ts
8430
8754
  var ruleId6 = "exports-path";
8431
8755
  var severity4 = Severity.ERROR;
8432
- function* validatePath(pkgAst, value, path8) {
8756
+ function* validatePath(pkgAst, value, path10) {
8433
8757
  if (value === null) {
8434
8758
  return;
8435
8759
  }
8436
8760
  if (typeof value === "string") {
8437
8761
  if (!value.startsWith("./")) {
8438
- const { line, column } = jsonLocation(pkgAst, "value", "exports", ...path8);
8439
- const property = path8.map((it2) => `["${it2}"]`).join("");
8762
+ const { line, column } = jsonLocation(pkgAst, "value", "exports", ...path10);
8763
+ const property = path10.map((it2) => `["${it2}"]`).join("");
8440
8764
  yield {
8441
8765
  ruleId: ruleId6,
8442
8766
  severity: severity4,
@@ -8448,7 +8772,7 @@ function* validatePath(pkgAst, value, path8) {
8448
8772
  return;
8449
8773
  }
8450
8774
  for (const [key, val] of Object.entries(value)) {
8451
- yield* validatePath(pkgAst, val, [...path8, key]);
8775
+ yield* validatePath(pkgAst, val, [...path10, key]);
8452
8776
  }
8453
8777
  }
8454
8778
  function* exportsPath(pkg, pkgAst) {
@@ -8460,7 +8784,7 @@ function* exportsPath(pkg, pkgAst) {
8460
8784
  // src/rules/exports-types-order.ts
8461
8785
  var ruleId7 = "exports-types-order";
8462
8786
  var severity5 = Severity.ERROR;
8463
- function* validateOrder3(pkgAst, value, path8) {
8787
+ function* validateOrder3(pkgAst, value, path10) {
8464
8788
  if (!value || typeof value === "string") {
8465
8789
  return;
8466
8790
  }
@@ -8469,8 +8793,8 @@ function* validateOrder3(pkgAst, value, path8) {
8469
8793
  return;
8470
8794
  }
8471
8795
  if (keys.includes("types") && keys[0] !== "types") {
8472
- const { line, column } = jsonLocation(pkgAst, "member", "exports", ...path8, "types");
8473
- const property = path8.map((it2) => `["${it2}"]`).join("");
8796
+ const { line, column } = jsonLocation(pkgAst, "member", "exports", ...path10, "types");
8797
+ const property = path10.map((it2) => `["${it2}"]`).join("");
8474
8798
  yield {
8475
8799
  ruleId: ruleId7,
8476
8800
  severity: severity5,
@@ -8480,7 +8804,7 @@ function* validateOrder3(pkgAst, value, path8) {
8480
8804
  };
8481
8805
  }
8482
8806
  for (const key of keys) {
8483
- yield* validateOrder3(pkgAst, value[key], [...path8, key]);
8807
+ yield* validateOrder3(pkgAst, value[key], [...path10, key]);
8484
8808
  }
8485
8809
  }
8486
8810
  function* exportsTypesOrder(pkg, pkgAst) {
@@ -8654,8 +8978,7 @@ function* outdatedEngines(pkg, pkgAst, ignoreNodeVersion) {
8654
8978
  if (!import_semver2.default.satisfies(expanded, range)) {
8655
8979
  continue;
8656
8980
  }
8657
- const parsed = import_semver2.default.parse(expanded);
8658
- const { major, minor } = parsed;
8981
+ const { major, minor } = import_semver2.default.parse(expanded);
8659
8982
  if (ignoreNodeVersion === major) {
8660
8983
  return;
8661
8984
  }
@@ -9348,7 +9671,7 @@ var pkgFilepath = fileURLToPath4(new URL("../package.json", import.meta.url));
9348
9671
  var { version } = JSON.parse(readFileSync(pkgFilepath, "utf-8"));
9349
9672
  var PACKAGE_JSON = "package.json";
9350
9673
  var HELP_TEXT = `usage: index.js [-h] [-v] [-t TARBALL] [-p PKGFILE] [--cache CACHE]
9351
- [--allow-dependency DEPENDENCY] [--allow-types-dependencies]
9674
+ [--config FILE] [--allow-dependency DEPENDENCY] [--allow-types-dependencies]
9352
9675
  [--allow-file FILE] [--ignore-missing-fields]
9353
9676
  [--ignore-node-version [MAJOR]]
9354
9677
 
@@ -9362,6 +9685,7 @@ options:
9362
9685
  -p, --pkgfile PKGFILE
9363
9686
  specify package.json location
9364
9687
  --cache CACHE specify cache directory
9688
+ --config FILE specify configuration file
9365
9689
  --allow-dependency DEPENDENCY
9366
9690
  explicitly allow given dependency (can be given
9367
9691
  multiple times or as a comma-separated list)
@@ -9378,7 +9702,7 @@ options:
9378
9702
  `;
9379
9703
  async function preloadStdin() {
9380
9704
  return new Promise((resolve, reject) => {
9381
- import_tmp.default.file((err, path8, fd) => {
9705
+ import_tmp.default.file((err, path10, fd) => {
9382
9706
  if (err) {
9383
9707
  reject(err);
9384
9708
  return;
@@ -9386,7 +9710,7 @@ async function preloadStdin() {
9386
9710
  const st2 = createWriteStream("", { fd, autoClose: true });
9387
9711
  process.stdin.pipe(st2);
9388
9712
  st2.on("finish", () => {
9389
- resolve(path8);
9713
+ resolve(path10);
9390
9714
  });
9391
9715
  st2.on("error", (err2) => {
9392
9716
  reject(err2);
@@ -9413,7 +9737,7 @@ async function getPackageJson(args, regenerateReportName) {
9413
9737
  return {
9414
9738
  pkg,
9415
9739
  pkgAst,
9416
- pkgPath: path7.join(
9740
+ pkgPath: path9.join(
9417
9741
  regenerateReportName ? `${pkg.name}-${pkg.version}.tgz` : args.tarball,
9418
9742
  PACKAGE_JSON
9419
9743
  )
@@ -9435,7 +9759,7 @@ async function getPackageJson(args, regenerateReportName) {
9435
9759
  function extractIgnoreNodeVersion(argv) {
9436
9760
  const FLAG = "--ignore-node-version";
9437
9761
  const rest = [];
9438
- let value = false;
9762
+ let value;
9439
9763
  for (let i = 0; i < argv.length; i++) {
9440
9764
  const arg = argv[i];
9441
9765
  if (arg === FLAG) {
@@ -9473,6 +9797,7 @@ function parseCliArgs(argv) {
9473
9797
  tarball: { type: "string", short: "t" },
9474
9798
  pkgfile: { type: "string", short: "p" },
9475
9799
  cache: { type: "string" },
9800
+ config: { type: "string" },
9476
9801
  "allow-dependency": { type: "string", multiple: true, default: [] },
9477
9802
  "allow-types-dependencies": { type: "boolean" },
9478
9803
  "allow-file": { type: "string", multiple: true, default: [] },
@@ -9490,6 +9815,7 @@ function parseCliArgs(argv) {
9490
9815
  action: "run",
9491
9816
  args: {
9492
9817
  cache: values.cache,
9818
+ config: values.config,
9493
9819
  pkgfile: values.pkgfile,
9494
9820
  tarball: values.tarball,
9495
9821
  ignoreMissingFields: values["ignore-missing-fields"],
@@ -9510,12 +9836,37 @@ async function loadPackage(args, regenerateReportName) {
9510
9836
  filePath: args.tarball ?? tarballLocation(pkg, pkgPath),
9511
9837
  reportPath: regenerateReportName ? `${pkg.name}-${pkg.version}.tgz` : void 0
9512
9838
  };
9513
- if (!existsSync(tarball.filePath)) {
9839
+ if (!existsSync2(tarball.filePath)) {
9514
9840
  console.error(`"${tarball.filePath}" does not exist, did you forget to run \`npm pack'?`);
9515
9841
  return void 0;
9516
9842
  }
9517
9843
  return { pkg, pkgAst, pkgPath, tarball };
9518
9844
  }
9845
+ async function resolveVerifyOptions(args) {
9846
+ try {
9847
+ const loaded = await loadConfig({ cwd: process.cwd(), configFile: args.config });
9848
+ return resolveOptions(args, loaded?.config);
9849
+ } catch (err) {
9850
+ console.error(err instanceof Error ? err.message : String(err));
9851
+ return void 0;
9852
+ }
9853
+ }
9854
+ function sortResults(results) {
9855
+ return results.map((result) => ({
9856
+ ...result,
9857
+ messages: result.messages.toSorted((a, b2) => {
9858
+ if (a.line !== b2.line) {
9859
+ return a.line - b2.line;
9860
+ }
9861
+ return a.column - b2.column;
9862
+ })
9863
+ }));
9864
+ }
9865
+ function countErrors(results) {
9866
+ return results.reduce((sum, result) => {
9867
+ return sum + result.errorCount;
9868
+ }, 0);
9869
+ }
9519
9870
  async function run() {
9520
9871
  let cli;
9521
9872
  try {
@@ -9534,8 +9885,11 @@ async function run() {
9534
9885
  return;
9535
9886
  }
9536
9887
  const { args } = cli;
9537
- const allowedDependencies2 = new Set(args.allowDependency.flatMap((it2) => it2.split(",")));
9538
- const allowedFiles = args.allowFile.flatMap((it2) => it2.split(","));
9888
+ const options = await resolveVerifyOptions(args);
9889
+ if (!options) {
9890
+ process.exitCode = 1;
9891
+ return;
9892
+ }
9539
9893
  if (args.cache) {
9540
9894
  await setCacheDirecory(args.cache);
9541
9895
  }
@@ -9551,27 +9905,11 @@ async function run() {
9551
9905
  }
9552
9906
  const { pkg, pkgAst, pkgPath, tarball } = loaded;
9553
9907
  setupBlacklist(pkg.name);
9554
- const options = {
9555
- allowedDependencies: allowedDependencies2,
9556
- allowTypesDependencies: args.allowTypesDependencies,
9557
- allowedFiles,
9558
- ignoreMissingFields: args.ignoreMissingFields,
9559
- ignoreNodeVersion: args.ignoreNodeVersion
9560
- };
9561
9908
  const results = await verify(pkg, pkgAst, pkgPath, tarball, options);
9562
- for (const result of results) {
9563
- result.messages.sort((a, b2) => {
9564
- if (a.line !== b2.line) {
9565
- return a.line - b2.line;
9566
- }
9567
- return a.column - b2.column;
9568
- });
9569
- }
9570
- const output = stylish(results);
9909
+ const sortedResults = sortResults(results);
9910
+ const output = stylish(sortedResults);
9571
9911
  process.stdout.write(output);
9572
- const totalErrors = results.reduce((sum, result) => {
9573
- return sum + result.errorCount;
9574
- }, 0);
9912
+ const totalErrors = countErrors(sortedResults);
9575
9913
  process.exitCode = totalErrors > 0 ? 1 : 0;
9576
9914
  }
9577
9915
  await run();