npm-pkg-lint 5.3.1 → 5.4.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/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;
@@ -2407,8 +2407,8 @@ var require_semver2 = __commonJS({
2407
2407
  });
2408
2408
 
2409
2409
  // src/index.ts
2410
- import { createWriteStream, existsSync, promises as fs7, readFileSync } from "node:fs";
2411
- import path7 from "node:path";
2410
+ import { createWriteStream, existsSync as existsSync2, promises as fs7, readFileSync } from "node:fs";
2411
+ import path9 from "node:path";
2412
2412
  import { fileURLToPath as fileURLToPath4 } from "node:url";
2413
2413
  import { parseArgs } from "node:util";
2414
2414
 
@@ -2421,7 +2421,11 @@ var __getOwnPropNames2 = Object.getOwnPropertyNames;
2421
2421
  var __getProtoOf2 = Object.getPrototypeOf;
2422
2422
  var __hasOwnProp2 = Object.prototype.hasOwnProperty;
2423
2423
  var __commonJS2 = (cb, mod) => function __require2() {
2424
- return mod || (0, cb[__getOwnPropNames2(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
2424
+ try {
2425
+ return mod || (0, cb[__getOwnPropNames2(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
2426
+ } catch (e) {
2427
+ throw mod = 0, e;
2428
+ }
2425
2429
  };
2426
2430
  var __copyProps2 = (to2, from, except, desc) => {
2427
2431
  if (from && typeof from === "object" || typeof from === "function") {
@@ -2534,12 +2538,11 @@ function yellow(value) {
2534
2538
  function red(value) {
2535
2539
  return styleText("red", value);
2536
2540
  }
2537
- var Severity = /* @__PURE__ */ ((Severity2) => {
2538
- Severity2[Severity2["OFF"] = 0] = "OFF";
2539
- Severity2[Severity2["WARN"] = 1] = "WARN";
2540
- Severity2[Severity2["ERROR"] = 2] = "ERROR";
2541
- return Severity2;
2542
- })(Severity || {});
2541
+ var Severity = {
2542
+ OFF: 0,
2543
+ WARN: 1,
2544
+ ERROR: 2
2545
+ };
2543
2546
  function pluralize(word, count) {
2544
2547
  return count === 1 ? word : `${word}s`;
2545
2548
  }
@@ -2547,7 +2550,7 @@ function centerLineColumn(el) {
2547
2550
  return el.replace(/(\d+)\s+(\d+)/u, (_m, p1, p2) => dim(`${p1}:${p2}`));
2548
2551
  }
2549
2552
  function stripAnsi(text) {
2550
- return text.replaceAll(/\u001B\[[\d;]*m/g, "");
2553
+ return text.replaceAll(/\u{001B}\[[\d;]*m/gu, "");
2551
2554
  }
2552
2555
  function stylish(results) {
2553
2556
  let output = "\n";
@@ -2567,7 +2570,7 @@ function stylish(results) {
2567
2570
  fixableWarningCount += result.fixableWarningCount;
2568
2571
  const rows = messages.map((message) => {
2569
2572
  let messageType;
2570
- if (Boolean(message.fatal) || message.severity === 2) {
2573
+ if (Boolean(message.fatal) || message.severity === Severity.ERROR) {
2571
2574
  messageType = red("error");
2572
2575
  summaryColor = red;
2573
2576
  } else {
@@ -4350,14 +4353,14 @@ var import_tmp = __toESM(require_tmp(), 1);
4350
4353
  function escape(text) {
4351
4354
  return text.replace(/\./, "\\.");
4352
4355
  }
4353
- function directory(path8) {
4354
- return new RegExp(`(^|/)${path8}/`);
4356
+ function directory(path10) {
4357
+ return new RegExp(`(^|/)${path10}/`);
4355
4358
  }
4356
4359
  function extension(ext) {
4357
4360
  return new RegExp(`${escape(ext)}$`);
4358
4361
  }
4359
- function filename(path8) {
4360
- return new RegExp(`(^|/)${escape(path8)}$`);
4362
+ function filename(path10) {
4363
+ return new RegExp(`(^|/)${escape(path10)}$`);
4361
4364
  }
4362
4365
  function rcfile(base) {
4363
4366
  return new RegExp(`${escape(base)}(\\.(js|cjs|mjs|ts|yaml|yml|json))?$`);
@@ -4579,6 +4582,111 @@ function isBlacklisted(filename2) {
4579
4582
  return blacklist_default.some((entry) => filename2.match(entry));
4580
4583
  }
4581
4584
 
4585
+ // src/config/load-config.ts
4586
+ import path4 from "node:path";
4587
+
4588
+ // src/config/find-config.ts
4589
+ import { existsSync } from "node:fs";
4590
+ import path3 from "node:path";
4591
+ var basename = "npm-pkg-lint.config";
4592
+ var extensions = [".js", ".mjs", ".ts", ".mts"];
4593
+ var directories = [".", "config", ".github", ".gitlab"];
4594
+ function* candidates(root) {
4595
+ for (const directory2 of directories) {
4596
+ for (const extension2 of extensions) {
4597
+ yield path3.join(root, directory2, `${basename}${extension2}`);
4598
+ }
4599
+ }
4600
+ }
4601
+ function findConfigFile(dir) {
4602
+ const found = Array.from(candidates(path3.resolve(dir))).filter((it2) => existsSync(it2));
4603
+ if (found.length > 1) {
4604
+ const list = found.map((it2) => ` - ${it2}`).join("\n");
4605
+ throw new Error(
4606
+ `Multiple configuration files found, remove all but one or select one with \`--config\`:
4607
+ ${list}`
4608
+ );
4609
+ }
4610
+ return found[0];
4611
+ }
4612
+
4613
+ // src/config/import-config.ts
4614
+ import { pathToFileURL } from "node:url";
4615
+ async function importConfig(filePath) {
4616
+ const mod = await import(pathToFileURL(filePath).href);
4617
+ return mod.default;
4618
+ }
4619
+
4620
+ // src/config/validate-config.ts
4621
+ var isStringArray = (value) => Array.isArray(value) && value.every((it2) => typeof it2 === "string");
4622
+ var isBoolean = (value) => typeof value === "boolean";
4623
+ var isBooleanOrInteger = (value) => typeof value === "boolean" || Number.isSafeInteger(value);
4624
+ var schema = {
4625
+ allowDependencies: { check: isStringArray, expected: "an array of strings" },
4626
+ allowFiles: { check: isStringArray, expected: "an array of strings" },
4627
+ allowTypesDependencies: { check: isBoolean, expected: "a boolean" },
4628
+ ignoreMissingFields: { check: isBoolean, expected: "a boolean" },
4629
+ ignoreNodeVersion: { check: isBooleanOrInteger, expected: "a boolean or an integer" }
4630
+ };
4631
+ function validateConfig(value, filePath) {
4632
+ if (value === void 0) {
4633
+ throw new Error(`${filePath}: configuration file must have a default export`);
4634
+ }
4635
+ if (typeof value !== "object" || value === null || Array.isArray(value)) {
4636
+ throw new Error(`${filePath}: default export must be an object`);
4637
+ }
4638
+ const errors = [];
4639
+ for (const [key, entry] of Object.entries(value)) {
4640
+ if (!Object.hasOwn(schema, key)) {
4641
+ errors.push(`unknown option "${key}"`);
4642
+ continue;
4643
+ }
4644
+ const { check, expected } = schema[key];
4645
+ if (entry !== void 0 && !check(entry)) {
4646
+ errors.push(`option "${key}" must be ${expected}`);
4647
+ }
4648
+ }
4649
+ if (errors.length > 0) {
4650
+ const list = errors.map((it2) => ` - ${it2}`).join("\n");
4651
+ throw new Error(`${filePath}: invalid configuration:
4652
+ ${list}`);
4653
+ }
4654
+ return value;
4655
+ }
4656
+
4657
+ // src/config/load-config.ts
4658
+ async function loadConfig(options) {
4659
+ const { cwd, configFile } = options;
4660
+ const filePath = configFile ? path4.resolve(cwd, configFile) : findConfigFile(cwd);
4661
+ if (!filePath) {
4662
+ return void 0;
4663
+ }
4664
+ let exported;
4665
+ try {
4666
+ exported = await importConfig(filePath);
4667
+ } catch (err) {
4668
+ const message = err instanceof Error ? err.message : String(err);
4669
+ throw new Error(`Failed to load configuration file "${filePath}": ${message}`, { cause: err });
4670
+ }
4671
+ return { filePath, config: validateConfig(exported, filePath) };
4672
+ }
4673
+
4674
+ // src/config/resolve-options.ts
4675
+ function splitList(values) {
4676
+ return values.flatMap((it2) => it2.split(","));
4677
+ }
4678
+ function resolveOptions(cli, config = {}) {
4679
+ const allowedDependencies2 = cli.allowDependency.length > 0 ? splitList(cli.allowDependency) : config.allowDependencies;
4680
+ const allowedFiles = cli.allowFile.length > 0 ? splitList(cli.allowFile) : config.allowFiles;
4681
+ return {
4682
+ allowedDependencies: new Set(allowedDependencies2),
4683
+ allowedFiles: allowedFiles ?? [],
4684
+ allowTypesDependencies: cli.allowTypesDependencies ?? config.allowTypesDependencies,
4685
+ ignoreMissingFields: cli.ignoreMissingFields ?? config.ignoreMissingFields,
4686
+ ignoreNodeVersion: cli.ignoreNodeVersion ?? config.ignoreNodeVersion ?? false
4687
+ };
4688
+ }
4689
+
4582
4690
  // src/tarball.ts
4583
4691
  import fs3 from "node:fs";
4584
4692
  import { matchesGlob } from "node:path";
@@ -7575,8 +7683,8 @@ async function getFileContent(tarball, filenames) {
7575
7683
  const contents = {};
7576
7684
  return new Promise((resolve, reject) => {
7577
7685
  const t = new rt({
7578
- filter(path8) {
7579
- return filenames.includes(normalize(path8));
7686
+ filter(path10) {
7687
+ return filenames.includes(normalize(path10));
7580
7688
  }
7581
7689
  });
7582
7690
  t.on("entry", (entry) => {
@@ -7721,27 +7829,27 @@ async function verifyTarball(pkg, tarball, options) {
7721
7829
  }
7722
7830
 
7723
7831
  // src/tarball-location.ts
7724
- import path3 from "node:path";
7832
+ import path5 from "node:path";
7725
7833
  function normalize2(name) {
7726
7834
  return name.replace("/", "-").replace(/^@/, "");
7727
7835
  }
7728
7836
  function tarballLocation(pkg, pkgPath) {
7729
7837
  const name = normalize2(pkg.name);
7730
- return path3.join(path3.dirname(pkgPath), `${name}-${pkg.version}.tgz`);
7838
+ return path5.join(path5.dirname(pkgPath), `${name}-${pkg.version}.tgz`);
7731
7839
  }
7732
7840
 
7733
7841
  // src/utils/persistent-cache.ts
7734
7842
  import crypto from "node:crypto";
7735
7843
  import fs4 from "node:fs/promises";
7736
7844
  import os2 from "node:os";
7737
- import path4 from "node:path";
7845
+ import path6 from "node:path";
7738
7846
  var enabled = os2.platform() === "linux";
7739
- var cacheRoot = process.env.XDG_CACHE_HOME ?? path4.join(os2.homedir(), ".cache");
7740
- var cacheDir = path4.join(cacheRoot, "npm-pkg-lint");
7847
+ var cacheRoot = process.env.XDG_CACHE_HOME ?? path6.join(os2.homedir(), ".cache");
7848
+ var cacheDir = path6.join(cacheRoot, "npm-pkg-lint");
7741
7849
  function getFilePath(key) {
7742
7850
  const hash = crypto.createHash("md5").update(key).digest("hex");
7743
7851
  const filename2 = `${hash.slice(0, 2)}/${hash.slice(2)}.json`;
7744
- return path4.join(cacheDir, filename2);
7852
+ return path6.join(cacheDir, filename2);
7745
7853
  }
7746
7854
  async function setCacheDirecory(directory2) {
7747
7855
  await fs4.mkdir(directory2, { recursive: true });
@@ -7768,7 +7876,7 @@ async function persistentCacheSet(key, data) {
7768
7876
  }
7769
7877
  const filePath = getFilePath(key);
7770
7878
  const content = JSON.stringify(data, null, 2);
7771
- await fs4.mkdir(path4.dirname(filePath), { recursive: true });
7879
+ await fs4.mkdir(path6.dirname(filePath), { recursive: true });
7772
7880
  await fs4.writeFile(filePath, content, "utf-8");
7773
7881
  }
7774
7882
 
@@ -7838,7 +7946,7 @@ var getContext = (raw) => ({
7838
7946
  var getCommandPart = (part) => /[^\w./-]/.test(part) ? `'${part.replaceAll("'", "'\\''")}'` : part;
7839
7947
 
7840
7948
  // node_modules/nano-spawn/source/options.js
7841
- import path5 from "node:path";
7949
+ import path7 from "node:path";
7842
7950
  import { fileURLToPath as fileURLToPath3 } from "node:url";
7843
7951
  import process4 from "node:process";
7844
7952
  var getOptions = ({
@@ -7851,7 +7959,7 @@ var getOptions = ({
7851
7959
  cwd: cwdOption = ".",
7852
7960
  ...options
7853
7961
  }) => {
7854
- const cwd = cwdOption instanceof URL ? fileURLToPath3(cwdOption) : path5.resolve(cwdOption);
7962
+ const cwd = cwdOption instanceof URL ? fileURLToPath3(cwdOption) : path7.resolve(cwdOption);
7855
7963
  const env = envOption ? { ...process4.env, ...envOption } : void 0;
7856
7964
  const input = stdio[0]?.string;
7857
7965
  return {
@@ -7863,11 +7971,11 @@ var getOptions = ({
7863
7971
  };
7864
7972
  };
7865
7973
  var addLocalPath = ({ Path = "", PATH = Path, ...env }, cwd) => {
7866
- const pathParts = PATH.split(path5.delimiter);
7867
- const localPaths = getLocalPaths([], path5.resolve(cwd)).map((localPath) => path5.join(localPath, "node_modules/.bin")).filter((localPath) => !pathParts.includes(localPath));
7868
- return { ...env, PATH: [...localPaths, PATH].filter(Boolean).join(path5.delimiter) };
7974
+ const pathParts = PATH.split(path7.delimiter);
7975
+ const localPaths = getLocalPaths([], path7.resolve(cwd)).map((localPath) => path7.join(localPath, "node_modules/.bin")).filter((localPath) => !pathParts.includes(localPath));
7976
+ return { ...env, PATH: [...localPaths, PATH].filter(Boolean).join(path7.delimiter) };
7869
7977
  };
7870
- var getLocalPaths = (localPaths, localPath) => localPaths.at(-1) === localPath ? localPaths : getLocalPaths([...localPaths, localPath], path5.resolve(localPath, ".."));
7978
+ var getLocalPaths = (localPaths, localPath) => localPaths.at(-1) === localPath ? localPaths : getLocalPaths([...localPaths, localPath], path7.resolve(localPath, ".."));
7871
7979
 
7872
7980
  // node_modules/nano-spawn/source/spawn.js
7873
7981
  import { spawn } from "node:child_process";
@@ -7876,7 +7984,7 @@ import process7 from "node:process";
7876
7984
 
7877
7985
  // node_modules/nano-spawn/source/windows.js
7878
7986
  import fs5 from "node:fs/promises";
7879
- import path6 from "node:path";
7987
+ import path8 from "node:path";
7880
7988
  import process5 from "node:process";
7881
7989
  var applyForceShell = async (file, commandArguments, options) => await shouldForceShell(file, options) ? [escapeFile(file), commandArguments.map((argument) => escapeArgument(argument)), { ...options, shell: true }] : [file, commandArguments, options];
7882
7990
  var shouldForceShell = async (file, { shell, cwd, env = process5.env }) => process5.platform === "win32" && !shell && !await isExe(file, cwd, env);
@@ -7892,11 +8000,11 @@ var memoize = (function_) => (...arguments_) => (
7892
8000
  );
7893
8001
  var access = memoize(fs5.access);
7894
8002
  var mIsExe = memoize(async (file, cwd, PATH) => {
7895
- const parts = PATH.split(path6.delimiter).filter(Boolean).map((part) => part.replace(/^"(.*)"$/, "$1"));
8003
+ const parts = PATH.split(path8.delimiter).filter(Boolean).map((part) => part.replace(/^"(.*)"$/, "$1"));
7896
8004
  try {
7897
8005
  await Promise.any(
7898
8006
  [cwd, ...parts].flatMap(
7899
- (part) => exeExtensions.map((extension2) => access(`${path6.resolve(part, file)}${extension2}`))
8007
+ (part) => exeExtensions.map((extension2) => access(`${path8.resolve(part, file)}${extension2}`))
7900
8008
  )
7901
8009
  );
7902
8010
  } catch {
@@ -8357,7 +8465,7 @@ function isDisallowedDependency(pkg, dependency) {
8357
8465
  // src/rules/exports-default-order.ts
8358
8466
  var ruleId4 = "exports-default-order";
8359
8467
  var severity2 = Severity.ERROR;
8360
- function* validateOrder(pkgAst, value, path8) {
8468
+ function* validateOrder(pkgAst, value, path10) {
8361
8469
  if (!value || typeof value === "string") {
8362
8470
  return;
8363
8471
  }
@@ -8366,8 +8474,8 @@ function* validateOrder(pkgAst, value, path8) {
8366
8474
  return;
8367
8475
  }
8368
8476
  if (keys.includes("default") && keys.at(-1) !== "default") {
8369
- const { line, column } = jsonLocation(pkgAst, "member", "exports", ...path8, "default");
8370
- const property = path8.map((it2) => `["${it2}"]`).join("");
8477
+ const { line, column } = jsonLocation(pkgAst, "member", "exports", ...path10, "default");
8478
+ const property = path10.map((it2) => `["${it2}"]`).join("");
8371
8479
  yield {
8372
8480
  ruleId: ruleId4,
8373
8481
  severity: severity2,
@@ -8377,7 +8485,7 @@ function* validateOrder(pkgAst, value, path8) {
8377
8485
  };
8378
8486
  }
8379
8487
  for (const key of keys) {
8380
- yield* validateOrder(pkgAst, value[key], [...path8, key]);
8488
+ yield* validateOrder(pkgAst, value[key], [...path10, key]);
8381
8489
  }
8382
8490
  }
8383
8491
  function* exportsDefaultOrder(pkg, pkgAst) {
@@ -8389,7 +8497,7 @@ function* exportsDefaultOrder(pkg, pkgAst) {
8389
8497
  // src/rules/exports-import-require-order.ts
8390
8498
  var ruleId5 = "exports-import-require-order";
8391
8499
  var severity3 = Severity.ERROR;
8392
- function* validateOrder2(pkgAst, value, path8) {
8500
+ function* validateOrder2(pkgAst, value, path10) {
8393
8501
  if (!value || typeof value === "string") {
8394
8502
  return;
8395
8503
  }
@@ -8402,8 +8510,8 @@ function* validateOrder2(pkgAst, value, path8) {
8402
8510
  if (keys.indexOf(esm) <= keys.indexOf("require")) {
8403
8511
  continue;
8404
8512
  }
8405
- const { line, column } = jsonLocation(pkgAst, "member", "exports", ...path8, esm);
8406
- const property = path8.map((it2) => `["${it2}"]`).join("");
8513
+ const { line, column } = jsonLocation(pkgAst, "member", "exports", ...path10, esm);
8514
+ const property = path10.map((it2) => `["${it2}"]`).join("");
8407
8515
  yield {
8408
8516
  ruleId: ruleId5,
8409
8517
  severity: severity3,
@@ -8414,7 +8522,7 @@ function* validateOrder2(pkgAst, value, path8) {
8414
8522
  }
8415
8523
  }
8416
8524
  for (const key of keys) {
8417
- yield* validateOrder2(pkgAst, value[key], [...path8, key]);
8525
+ yield* validateOrder2(pkgAst, value[key], [...path10, key]);
8418
8526
  }
8419
8527
  }
8420
8528
  function* exportsImportRequireOrder(pkg, pkgAst) {
@@ -8426,14 +8534,14 @@ function* exportsImportRequireOrder(pkg, pkgAst) {
8426
8534
  // src/rules/exports-path.ts
8427
8535
  var ruleId6 = "exports-path";
8428
8536
  var severity4 = Severity.ERROR;
8429
- function* validatePath(pkgAst, value, path8) {
8537
+ function* validatePath(pkgAst, value, path10) {
8430
8538
  if (value === null) {
8431
8539
  return;
8432
8540
  }
8433
8541
  if (typeof value === "string") {
8434
8542
  if (!value.startsWith("./")) {
8435
- const { line, column } = jsonLocation(pkgAst, "value", "exports", ...path8);
8436
- const property = path8.map((it2) => `["${it2}"]`).join("");
8543
+ const { line, column } = jsonLocation(pkgAst, "value", "exports", ...path10);
8544
+ const property = path10.map((it2) => `["${it2}"]`).join("");
8437
8545
  yield {
8438
8546
  ruleId: ruleId6,
8439
8547
  severity: severity4,
@@ -8445,7 +8553,7 @@ function* validatePath(pkgAst, value, path8) {
8445
8553
  return;
8446
8554
  }
8447
8555
  for (const [key, val] of Object.entries(value)) {
8448
- yield* validatePath(pkgAst, val, [...path8, key]);
8556
+ yield* validatePath(pkgAst, val, [...path10, key]);
8449
8557
  }
8450
8558
  }
8451
8559
  function* exportsPath(pkg, pkgAst) {
@@ -8457,7 +8565,7 @@ function* exportsPath(pkg, pkgAst) {
8457
8565
  // src/rules/exports-types-order.ts
8458
8566
  var ruleId7 = "exports-types-order";
8459
8567
  var severity5 = Severity.ERROR;
8460
- function* validateOrder3(pkgAst, value, path8) {
8568
+ function* validateOrder3(pkgAst, value, path10) {
8461
8569
  if (!value || typeof value === "string") {
8462
8570
  return;
8463
8571
  }
@@ -8466,8 +8574,8 @@ function* validateOrder3(pkgAst, value, path8) {
8466
8574
  return;
8467
8575
  }
8468
8576
  if (keys.includes("types") && keys[0] !== "types") {
8469
- const { line, column } = jsonLocation(pkgAst, "member", "exports", ...path8, "types");
8470
- const property = path8.map((it2) => `["${it2}"]`).join("");
8577
+ const { line, column } = jsonLocation(pkgAst, "member", "exports", ...path10, "types");
8578
+ const property = path10.map((it2) => `["${it2}"]`).join("");
8471
8579
  yield {
8472
8580
  ruleId: ruleId7,
8473
8581
  severity: severity5,
@@ -8477,7 +8585,7 @@ function* validateOrder3(pkgAst, value, path8) {
8477
8585
  };
8478
8586
  }
8479
8587
  for (const key of keys) {
8480
- yield* validateOrder3(pkgAst, value[key], [...path8, key]);
8588
+ yield* validateOrder3(pkgAst, value[key], [...path10, key]);
8481
8589
  }
8482
8590
  }
8483
8591
  function* exportsTypesOrder(pkg, pkgAst) {
@@ -9345,7 +9453,7 @@ var pkgFilepath = fileURLToPath4(new URL("../package.json", import.meta.url));
9345
9453
  var { version } = JSON.parse(readFileSync(pkgFilepath, "utf-8"));
9346
9454
  var PACKAGE_JSON = "package.json";
9347
9455
  var HELP_TEXT = `usage: index.js [-h] [-v] [-t TARBALL] [-p PKGFILE] [--cache CACHE]
9348
- [--allow-dependency DEPENDENCY] [--allow-types-dependencies]
9456
+ [--config FILE] [--allow-dependency DEPENDENCY] [--allow-types-dependencies]
9349
9457
  [--allow-file FILE] [--ignore-missing-fields]
9350
9458
  [--ignore-node-version [MAJOR]]
9351
9459
 
@@ -9359,6 +9467,7 @@ options:
9359
9467
  -p, --pkgfile PKGFILE
9360
9468
  specify package.json location
9361
9469
  --cache CACHE specify cache directory
9470
+ --config FILE specify configuration file
9362
9471
  --allow-dependency DEPENDENCY
9363
9472
  explicitly allow given dependency (can be given
9364
9473
  multiple times or as a comma-separated list)
@@ -9375,7 +9484,7 @@ options:
9375
9484
  `;
9376
9485
  async function preloadStdin() {
9377
9486
  return new Promise((resolve, reject) => {
9378
- import_tmp.default.file((err, path8, fd) => {
9487
+ import_tmp.default.file((err, path10, fd) => {
9379
9488
  if (err) {
9380
9489
  reject(err);
9381
9490
  return;
@@ -9383,7 +9492,7 @@ async function preloadStdin() {
9383
9492
  const st2 = createWriteStream("", { fd, autoClose: true });
9384
9493
  process.stdin.pipe(st2);
9385
9494
  st2.on("finish", () => {
9386
- resolve(path8);
9495
+ resolve(path10);
9387
9496
  });
9388
9497
  st2.on("error", (err2) => {
9389
9498
  reject(err2);
@@ -9410,7 +9519,7 @@ async function getPackageJson(args, regenerateReportName) {
9410
9519
  return {
9411
9520
  pkg,
9412
9521
  pkgAst,
9413
- pkgPath: path7.join(
9522
+ pkgPath: path9.join(
9414
9523
  regenerateReportName ? `${pkg.name}-${pkg.version}.tgz` : args.tarball,
9415
9524
  PACKAGE_JSON
9416
9525
  )
@@ -9432,7 +9541,7 @@ async function getPackageJson(args, regenerateReportName) {
9432
9541
  function extractIgnoreNodeVersion(argv) {
9433
9542
  const FLAG = "--ignore-node-version";
9434
9543
  const rest = [];
9435
- let value = false;
9544
+ let value;
9436
9545
  for (let i = 0; i < argv.length; i++) {
9437
9546
  const arg = argv[i];
9438
9547
  if (arg === FLAG) {
@@ -9470,6 +9579,7 @@ function parseCliArgs(argv) {
9470
9579
  tarball: { type: "string", short: "t" },
9471
9580
  pkgfile: { type: "string", short: "p" },
9472
9581
  cache: { type: "string" },
9582
+ config: { type: "string" },
9473
9583
  "allow-dependency": { type: "string", multiple: true, default: [] },
9474
9584
  "allow-types-dependencies": { type: "boolean" },
9475
9585
  "allow-file": { type: "string", multiple: true, default: [] },
@@ -9487,6 +9597,7 @@ function parseCliArgs(argv) {
9487
9597
  action: "run",
9488
9598
  args: {
9489
9599
  cache: values.cache,
9600
+ config: values.config,
9490
9601
  pkgfile: values.pkgfile,
9491
9602
  tarball: values.tarball,
9492
9603
  ignoreMissingFields: values["ignore-missing-fields"],
@@ -9507,12 +9618,37 @@ async function loadPackage(args, regenerateReportName) {
9507
9618
  filePath: args.tarball ?? tarballLocation(pkg, pkgPath),
9508
9619
  reportPath: regenerateReportName ? `${pkg.name}-${pkg.version}.tgz` : void 0
9509
9620
  };
9510
- if (!existsSync(tarball.filePath)) {
9621
+ if (!existsSync2(tarball.filePath)) {
9511
9622
  console.error(`"${tarball.filePath}" does not exist, did you forget to run \`npm pack'?`);
9512
9623
  return void 0;
9513
9624
  }
9514
9625
  return { pkg, pkgAst, pkgPath, tarball };
9515
9626
  }
9627
+ async function resolveVerifyOptions(args) {
9628
+ try {
9629
+ const loaded = await loadConfig({ cwd: process.cwd(), configFile: args.config });
9630
+ return resolveOptions(args, loaded?.config);
9631
+ } catch (err) {
9632
+ console.error(err instanceof Error ? err.message : String(err));
9633
+ return void 0;
9634
+ }
9635
+ }
9636
+ function sortResults(results) {
9637
+ return results.map((result) => ({
9638
+ ...result,
9639
+ messages: result.messages.toSorted((a, b2) => {
9640
+ if (a.line !== b2.line) {
9641
+ return a.line - b2.line;
9642
+ }
9643
+ return a.column - b2.column;
9644
+ })
9645
+ }));
9646
+ }
9647
+ function countErrors(results) {
9648
+ return results.reduce((sum, result) => {
9649
+ return sum + result.errorCount;
9650
+ }, 0);
9651
+ }
9516
9652
  async function run() {
9517
9653
  let cli;
9518
9654
  try {
@@ -9531,8 +9667,11 @@ async function run() {
9531
9667
  return;
9532
9668
  }
9533
9669
  const { args } = cli;
9534
- const allowedDependencies2 = new Set(args.allowDependency.flatMap((it2) => it2.split(",")));
9535
- const allowedFiles = args.allowFile.flatMap((it2) => it2.split(","));
9670
+ const options = await resolveVerifyOptions(args);
9671
+ if (!options) {
9672
+ process.exitCode = 1;
9673
+ return;
9674
+ }
9536
9675
  if (args.cache) {
9537
9676
  await setCacheDirecory(args.cache);
9538
9677
  }
@@ -9548,27 +9687,11 @@ async function run() {
9548
9687
  }
9549
9688
  const { pkg, pkgAst, pkgPath, tarball } = loaded;
9550
9689
  setupBlacklist(pkg.name);
9551
- const options = {
9552
- allowedDependencies: allowedDependencies2,
9553
- allowTypesDependencies: args.allowTypesDependencies,
9554
- allowedFiles,
9555
- ignoreMissingFields: args.ignoreMissingFields,
9556
- ignoreNodeVersion: args.ignoreNodeVersion
9557
- };
9558
9690
  const results = await verify(pkg, pkgAst, pkgPath, tarball, options);
9559
- for (const result of results) {
9560
- result.messages.sort((a, b2) => {
9561
- if (a.line !== b2.line) {
9562
- return a.line - b2.line;
9563
- }
9564
- return a.column - b2.column;
9565
- });
9566
- }
9567
- const output = stylish(results);
9691
+ const sortedResults = sortResults(results);
9692
+ const output = stylish(sortedResults);
9568
9693
  process.stdout.write(output);
9569
- const totalErrors = results.reduce((sum, result) => {
9570
- return sum + result.errorCount;
9571
- }, 0);
9694
+ const totalErrors = countErrors(sortedResults);
9572
9695
  process.exitCode = totalErrors > 0 ? 1 : 0;
9573
9696
  }
9574
9697
  await run();