npm-pkg-lint 5.3.2 → 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/README.md +41 -1
- package/dist/config.d.ts +25 -0
- package/dist/config.js +13 -0
- package/dist/config.js.map +7 -0
- package/dist/index.js +204 -84
- package/dist/index.js.map +4 -4
- package/package.json +8 -5
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
|
|
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 =
|
|
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(
|
|
256
|
+
fs8.realpath(path10.dirname(pathToResolve), function(err2, parentDir) {
|
|
257
257
|
if (err2) return cb(err2);
|
|
258
|
-
cb(null,
|
|
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 =
|
|
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(
|
|
272
|
-
return
|
|
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
|
|
278
|
+
return path10.join(tmpDir, opts.dir, opts.name);
|
|
279
279
|
}
|
|
280
280
|
if (!_isUndefined(opts.template)) {
|
|
281
|
-
return
|
|
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
|
|
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 (
|
|
306
|
-
const
|
|
307
|
-
if (
|
|
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 =
|
|
336
|
-
if (relativePath.startsWith("..") ||
|
|
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 =
|
|
346
|
-
if (relativePath.startsWith("..") ||
|
|
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
|
|
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
|
|
|
@@ -4353,14 +4353,14 @@ var import_tmp = __toESM(require_tmp(), 1);
|
|
|
4353
4353
|
function escape(text) {
|
|
4354
4354
|
return text.replace(/\./, "\\.");
|
|
4355
4355
|
}
|
|
4356
|
-
function directory(
|
|
4357
|
-
return new RegExp(`(^|/)${
|
|
4356
|
+
function directory(path10) {
|
|
4357
|
+
return new RegExp(`(^|/)${path10}/`);
|
|
4358
4358
|
}
|
|
4359
4359
|
function extension(ext) {
|
|
4360
4360
|
return new RegExp(`${escape(ext)}$`);
|
|
4361
4361
|
}
|
|
4362
|
-
function filename(
|
|
4363
|
-
return new RegExp(`(^|/)${escape(
|
|
4362
|
+
function filename(path10) {
|
|
4363
|
+
return new RegExp(`(^|/)${escape(path10)}$`);
|
|
4364
4364
|
}
|
|
4365
4365
|
function rcfile(base) {
|
|
4366
4366
|
return new RegExp(`${escape(base)}(\\.(js|cjs|mjs|ts|yaml|yml|json))?$`);
|
|
@@ -4582,6 +4582,111 @@ function isBlacklisted(filename2) {
|
|
|
4582
4582
|
return blacklist_default.some((entry) => filename2.match(entry));
|
|
4583
4583
|
}
|
|
4584
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
|
+
|
|
4585
4690
|
// src/tarball.ts
|
|
4586
4691
|
import fs3 from "node:fs";
|
|
4587
4692
|
import { matchesGlob } from "node:path";
|
|
@@ -7578,8 +7683,8 @@ async function getFileContent(tarball, filenames) {
|
|
|
7578
7683
|
const contents = {};
|
|
7579
7684
|
return new Promise((resolve, reject) => {
|
|
7580
7685
|
const t = new rt({
|
|
7581
|
-
filter(
|
|
7582
|
-
return filenames.includes(normalize(
|
|
7686
|
+
filter(path10) {
|
|
7687
|
+
return filenames.includes(normalize(path10));
|
|
7583
7688
|
}
|
|
7584
7689
|
});
|
|
7585
7690
|
t.on("entry", (entry) => {
|
|
@@ -7724,27 +7829,27 @@ async function verifyTarball(pkg, tarball, options) {
|
|
|
7724
7829
|
}
|
|
7725
7830
|
|
|
7726
7831
|
// src/tarball-location.ts
|
|
7727
|
-
import
|
|
7832
|
+
import path5 from "node:path";
|
|
7728
7833
|
function normalize2(name) {
|
|
7729
7834
|
return name.replace("/", "-").replace(/^@/, "");
|
|
7730
7835
|
}
|
|
7731
7836
|
function tarballLocation(pkg, pkgPath) {
|
|
7732
7837
|
const name = normalize2(pkg.name);
|
|
7733
|
-
return
|
|
7838
|
+
return path5.join(path5.dirname(pkgPath), `${name}-${pkg.version}.tgz`);
|
|
7734
7839
|
}
|
|
7735
7840
|
|
|
7736
7841
|
// src/utils/persistent-cache.ts
|
|
7737
7842
|
import crypto from "node:crypto";
|
|
7738
7843
|
import fs4 from "node:fs/promises";
|
|
7739
7844
|
import os2 from "node:os";
|
|
7740
|
-
import
|
|
7845
|
+
import path6 from "node:path";
|
|
7741
7846
|
var enabled = os2.platform() === "linux";
|
|
7742
|
-
var cacheRoot = process.env.XDG_CACHE_HOME ??
|
|
7743
|
-
var cacheDir =
|
|
7847
|
+
var cacheRoot = process.env.XDG_CACHE_HOME ?? path6.join(os2.homedir(), ".cache");
|
|
7848
|
+
var cacheDir = path6.join(cacheRoot, "npm-pkg-lint");
|
|
7744
7849
|
function getFilePath(key) {
|
|
7745
7850
|
const hash = crypto.createHash("md5").update(key).digest("hex");
|
|
7746
7851
|
const filename2 = `${hash.slice(0, 2)}/${hash.slice(2)}.json`;
|
|
7747
|
-
return
|
|
7852
|
+
return path6.join(cacheDir, filename2);
|
|
7748
7853
|
}
|
|
7749
7854
|
async function setCacheDirecory(directory2) {
|
|
7750
7855
|
await fs4.mkdir(directory2, { recursive: true });
|
|
@@ -7771,7 +7876,7 @@ async function persistentCacheSet(key, data) {
|
|
|
7771
7876
|
}
|
|
7772
7877
|
const filePath = getFilePath(key);
|
|
7773
7878
|
const content = JSON.stringify(data, null, 2);
|
|
7774
|
-
await fs4.mkdir(
|
|
7879
|
+
await fs4.mkdir(path6.dirname(filePath), { recursive: true });
|
|
7775
7880
|
await fs4.writeFile(filePath, content, "utf-8");
|
|
7776
7881
|
}
|
|
7777
7882
|
|
|
@@ -7841,7 +7946,7 @@ var getContext = (raw) => ({
|
|
|
7841
7946
|
var getCommandPart = (part) => /[^\w./-]/.test(part) ? `'${part.replaceAll("'", "'\\''")}'` : part;
|
|
7842
7947
|
|
|
7843
7948
|
// node_modules/nano-spawn/source/options.js
|
|
7844
|
-
import
|
|
7949
|
+
import path7 from "node:path";
|
|
7845
7950
|
import { fileURLToPath as fileURLToPath3 } from "node:url";
|
|
7846
7951
|
import process4 from "node:process";
|
|
7847
7952
|
var getOptions = ({
|
|
@@ -7854,7 +7959,7 @@ var getOptions = ({
|
|
|
7854
7959
|
cwd: cwdOption = ".",
|
|
7855
7960
|
...options
|
|
7856
7961
|
}) => {
|
|
7857
|
-
const cwd = cwdOption instanceof URL ? fileURLToPath3(cwdOption) :
|
|
7962
|
+
const cwd = cwdOption instanceof URL ? fileURLToPath3(cwdOption) : path7.resolve(cwdOption);
|
|
7858
7963
|
const env = envOption ? { ...process4.env, ...envOption } : void 0;
|
|
7859
7964
|
const input = stdio[0]?.string;
|
|
7860
7965
|
return {
|
|
@@ -7866,11 +7971,11 @@ var getOptions = ({
|
|
|
7866
7971
|
};
|
|
7867
7972
|
};
|
|
7868
7973
|
var addLocalPath = ({ Path = "", PATH = Path, ...env }, cwd) => {
|
|
7869
|
-
const pathParts = PATH.split(
|
|
7870
|
-
const localPaths = getLocalPaths([],
|
|
7871
|
-
return { ...env, PATH: [...localPaths, PATH].filter(Boolean).join(
|
|
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) };
|
|
7872
7977
|
};
|
|
7873
|
-
var getLocalPaths = (localPaths, localPath) => localPaths.at(-1) === localPath ? localPaths : getLocalPaths([...localPaths, localPath],
|
|
7978
|
+
var getLocalPaths = (localPaths, localPath) => localPaths.at(-1) === localPath ? localPaths : getLocalPaths([...localPaths, localPath], path7.resolve(localPath, ".."));
|
|
7874
7979
|
|
|
7875
7980
|
// node_modules/nano-spawn/source/spawn.js
|
|
7876
7981
|
import { spawn } from "node:child_process";
|
|
@@ -7879,7 +7984,7 @@ import process7 from "node:process";
|
|
|
7879
7984
|
|
|
7880
7985
|
// node_modules/nano-spawn/source/windows.js
|
|
7881
7986
|
import fs5 from "node:fs/promises";
|
|
7882
|
-
import
|
|
7987
|
+
import path8 from "node:path";
|
|
7883
7988
|
import process5 from "node:process";
|
|
7884
7989
|
var applyForceShell = async (file, commandArguments, options) => await shouldForceShell(file, options) ? [escapeFile(file), commandArguments.map((argument) => escapeArgument(argument)), { ...options, shell: true }] : [file, commandArguments, options];
|
|
7885
7990
|
var shouldForceShell = async (file, { shell, cwd, env = process5.env }) => process5.platform === "win32" && !shell && !await isExe(file, cwd, env);
|
|
@@ -7895,11 +8000,11 @@ var memoize = (function_) => (...arguments_) => (
|
|
|
7895
8000
|
);
|
|
7896
8001
|
var access = memoize(fs5.access);
|
|
7897
8002
|
var mIsExe = memoize(async (file, cwd, PATH) => {
|
|
7898
|
-
const parts = PATH.split(
|
|
8003
|
+
const parts = PATH.split(path8.delimiter).filter(Boolean).map((part) => part.replace(/^"(.*)"$/, "$1"));
|
|
7899
8004
|
try {
|
|
7900
8005
|
await Promise.any(
|
|
7901
8006
|
[cwd, ...parts].flatMap(
|
|
7902
|
-
(part) => exeExtensions.map((extension2) => access(`${
|
|
8007
|
+
(part) => exeExtensions.map((extension2) => access(`${path8.resolve(part, file)}${extension2}`))
|
|
7903
8008
|
)
|
|
7904
8009
|
);
|
|
7905
8010
|
} catch {
|
|
@@ -8360,7 +8465,7 @@ function isDisallowedDependency(pkg, dependency) {
|
|
|
8360
8465
|
// src/rules/exports-default-order.ts
|
|
8361
8466
|
var ruleId4 = "exports-default-order";
|
|
8362
8467
|
var severity2 = Severity.ERROR;
|
|
8363
|
-
function* validateOrder(pkgAst, value,
|
|
8468
|
+
function* validateOrder(pkgAst, value, path10) {
|
|
8364
8469
|
if (!value || typeof value === "string") {
|
|
8365
8470
|
return;
|
|
8366
8471
|
}
|
|
@@ -8369,8 +8474,8 @@ function* validateOrder(pkgAst, value, path8) {
|
|
|
8369
8474
|
return;
|
|
8370
8475
|
}
|
|
8371
8476
|
if (keys.includes("default") && keys.at(-1) !== "default") {
|
|
8372
|
-
const { line, column } = jsonLocation(pkgAst, "member", "exports", ...
|
|
8373
|
-
const property =
|
|
8477
|
+
const { line, column } = jsonLocation(pkgAst, "member", "exports", ...path10, "default");
|
|
8478
|
+
const property = path10.map((it2) => `["${it2}"]`).join("");
|
|
8374
8479
|
yield {
|
|
8375
8480
|
ruleId: ruleId4,
|
|
8376
8481
|
severity: severity2,
|
|
@@ -8380,7 +8485,7 @@ function* validateOrder(pkgAst, value, path8) {
|
|
|
8380
8485
|
};
|
|
8381
8486
|
}
|
|
8382
8487
|
for (const key of keys) {
|
|
8383
|
-
yield* validateOrder(pkgAst, value[key], [...
|
|
8488
|
+
yield* validateOrder(pkgAst, value[key], [...path10, key]);
|
|
8384
8489
|
}
|
|
8385
8490
|
}
|
|
8386
8491
|
function* exportsDefaultOrder(pkg, pkgAst) {
|
|
@@ -8392,7 +8497,7 @@ function* exportsDefaultOrder(pkg, pkgAst) {
|
|
|
8392
8497
|
// src/rules/exports-import-require-order.ts
|
|
8393
8498
|
var ruleId5 = "exports-import-require-order";
|
|
8394
8499
|
var severity3 = Severity.ERROR;
|
|
8395
|
-
function* validateOrder2(pkgAst, value,
|
|
8500
|
+
function* validateOrder2(pkgAst, value, path10) {
|
|
8396
8501
|
if (!value || typeof value === "string") {
|
|
8397
8502
|
return;
|
|
8398
8503
|
}
|
|
@@ -8405,8 +8510,8 @@ function* validateOrder2(pkgAst, value, path8) {
|
|
|
8405
8510
|
if (keys.indexOf(esm) <= keys.indexOf("require")) {
|
|
8406
8511
|
continue;
|
|
8407
8512
|
}
|
|
8408
|
-
const { line, column } = jsonLocation(pkgAst, "member", "exports", ...
|
|
8409
|
-
const property =
|
|
8513
|
+
const { line, column } = jsonLocation(pkgAst, "member", "exports", ...path10, esm);
|
|
8514
|
+
const property = path10.map((it2) => `["${it2}"]`).join("");
|
|
8410
8515
|
yield {
|
|
8411
8516
|
ruleId: ruleId5,
|
|
8412
8517
|
severity: severity3,
|
|
@@ -8417,7 +8522,7 @@ function* validateOrder2(pkgAst, value, path8) {
|
|
|
8417
8522
|
}
|
|
8418
8523
|
}
|
|
8419
8524
|
for (const key of keys) {
|
|
8420
|
-
yield* validateOrder2(pkgAst, value[key], [...
|
|
8525
|
+
yield* validateOrder2(pkgAst, value[key], [...path10, key]);
|
|
8421
8526
|
}
|
|
8422
8527
|
}
|
|
8423
8528
|
function* exportsImportRequireOrder(pkg, pkgAst) {
|
|
@@ -8429,14 +8534,14 @@ function* exportsImportRequireOrder(pkg, pkgAst) {
|
|
|
8429
8534
|
// src/rules/exports-path.ts
|
|
8430
8535
|
var ruleId6 = "exports-path";
|
|
8431
8536
|
var severity4 = Severity.ERROR;
|
|
8432
|
-
function* validatePath(pkgAst, value,
|
|
8537
|
+
function* validatePath(pkgAst, value, path10) {
|
|
8433
8538
|
if (value === null) {
|
|
8434
8539
|
return;
|
|
8435
8540
|
}
|
|
8436
8541
|
if (typeof value === "string") {
|
|
8437
8542
|
if (!value.startsWith("./")) {
|
|
8438
|
-
const { line, column } = jsonLocation(pkgAst, "value", "exports", ...
|
|
8439
|
-
const property =
|
|
8543
|
+
const { line, column } = jsonLocation(pkgAst, "value", "exports", ...path10);
|
|
8544
|
+
const property = path10.map((it2) => `["${it2}"]`).join("");
|
|
8440
8545
|
yield {
|
|
8441
8546
|
ruleId: ruleId6,
|
|
8442
8547
|
severity: severity4,
|
|
@@ -8448,7 +8553,7 @@ function* validatePath(pkgAst, value, path8) {
|
|
|
8448
8553
|
return;
|
|
8449
8554
|
}
|
|
8450
8555
|
for (const [key, val] of Object.entries(value)) {
|
|
8451
|
-
yield* validatePath(pkgAst, val, [...
|
|
8556
|
+
yield* validatePath(pkgAst, val, [...path10, key]);
|
|
8452
8557
|
}
|
|
8453
8558
|
}
|
|
8454
8559
|
function* exportsPath(pkg, pkgAst) {
|
|
@@ -8460,7 +8565,7 @@ function* exportsPath(pkg, pkgAst) {
|
|
|
8460
8565
|
// src/rules/exports-types-order.ts
|
|
8461
8566
|
var ruleId7 = "exports-types-order";
|
|
8462
8567
|
var severity5 = Severity.ERROR;
|
|
8463
|
-
function* validateOrder3(pkgAst, value,
|
|
8568
|
+
function* validateOrder3(pkgAst, value, path10) {
|
|
8464
8569
|
if (!value || typeof value === "string") {
|
|
8465
8570
|
return;
|
|
8466
8571
|
}
|
|
@@ -8469,8 +8574,8 @@ function* validateOrder3(pkgAst, value, path8) {
|
|
|
8469
8574
|
return;
|
|
8470
8575
|
}
|
|
8471
8576
|
if (keys.includes("types") && keys[0] !== "types") {
|
|
8472
|
-
const { line, column } = jsonLocation(pkgAst, "member", "exports", ...
|
|
8473
|
-
const property =
|
|
8577
|
+
const { line, column } = jsonLocation(pkgAst, "member", "exports", ...path10, "types");
|
|
8578
|
+
const property = path10.map((it2) => `["${it2}"]`).join("");
|
|
8474
8579
|
yield {
|
|
8475
8580
|
ruleId: ruleId7,
|
|
8476
8581
|
severity: severity5,
|
|
@@ -8480,7 +8585,7 @@ function* validateOrder3(pkgAst, value, path8) {
|
|
|
8480
8585
|
};
|
|
8481
8586
|
}
|
|
8482
8587
|
for (const key of keys) {
|
|
8483
|
-
yield* validateOrder3(pkgAst, value[key], [...
|
|
8588
|
+
yield* validateOrder3(pkgAst, value[key], [...path10, key]);
|
|
8484
8589
|
}
|
|
8485
8590
|
}
|
|
8486
8591
|
function* exportsTypesOrder(pkg, pkgAst) {
|
|
@@ -9348,7 +9453,7 @@ var pkgFilepath = fileURLToPath4(new URL("../package.json", import.meta.url));
|
|
|
9348
9453
|
var { version } = JSON.parse(readFileSync(pkgFilepath, "utf-8"));
|
|
9349
9454
|
var PACKAGE_JSON = "package.json";
|
|
9350
9455
|
var HELP_TEXT = `usage: index.js [-h] [-v] [-t TARBALL] [-p PKGFILE] [--cache CACHE]
|
|
9351
|
-
[--allow-dependency DEPENDENCY] [--allow-types-dependencies]
|
|
9456
|
+
[--config FILE] [--allow-dependency DEPENDENCY] [--allow-types-dependencies]
|
|
9352
9457
|
[--allow-file FILE] [--ignore-missing-fields]
|
|
9353
9458
|
[--ignore-node-version [MAJOR]]
|
|
9354
9459
|
|
|
@@ -9362,6 +9467,7 @@ options:
|
|
|
9362
9467
|
-p, --pkgfile PKGFILE
|
|
9363
9468
|
specify package.json location
|
|
9364
9469
|
--cache CACHE specify cache directory
|
|
9470
|
+
--config FILE specify configuration file
|
|
9365
9471
|
--allow-dependency DEPENDENCY
|
|
9366
9472
|
explicitly allow given dependency (can be given
|
|
9367
9473
|
multiple times or as a comma-separated list)
|
|
@@ -9378,7 +9484,7 @@ options:
|
|
|
9378
9484
|
`;
|
|
9379
9485
|
async function preloadStdin() {
|
|
9380
9486
|
return new Promise((resolve, reject) => {
|
|
9381
|
-
import_tmp.default.file((err,
|
|
9487
|
+
import_tmp.default.file((err, path10, fd) => {
|
|
9382
9488
|
if (err) {
|
|
9383
9489
|
reject(err);
|
|
9384
9490
|
return;
|
|
@@ -9386,7 +9492,7 @@ async function preloadStdin() {
|
|
|
9386
9492
|
const st2 = createWriteStream("", { fd, autoClose: true });
|
|
9387
9493
|
process.stdin.pipe(st2);
|
|
9388
9494
|
st2.on("finish", () => {
|
|
9389
|
-
resolve(
|
|
9495
|
+
resolve(path10);
|
|
9390
9496
|
});
|
|
9391
9497
|
st2.on("error", (err2) => {
|
|
9392
9498
|
reject(err2);
|
|
@@ -9413,7 +9519,7 @@ async function getPackageJson(args, regenerateReportName) {
|
|
|
9413
9519
|
return {
|
|
9414
9520
|
pkg,
|
|
9415
9521
|
pkgAst,
|
|
9416
|
-
pkgPath:
|
|
9522
|
+
pkgPath: path9.join(
|
|
9417
9523
|
regenerateReportName ? `${pkg.name}-${pkg.version}.tgz` : args.tarball,
|
|
9418
9524
|
PACKAGE_JSON
|
|
9419
9525
|
)
|
|
@@ -9435,7 +9541,7 @@ async function getPackageJson(args, regenerateReportName) {
|
|
|
9435
9541
|
function extractIgnoreNodeVersion(argv) {
|
|
9436
9542
|
const FLAG = "--ignore-node-version";
|
|
9437
9543
|
const rest = [];
|
|
9438
|
-
let value
|
|
9544
|
+
let value;
|
|
9439
9545
|
for (let i = 0; i < argv.length; i++) {
|
|
9440
9546
|
const arg = argv[i];
|
|
9441
9547
|
if (arg === FLAG) {
|
|
@@ -9473,6 +9579,7 @@ function parseCliArgs(argv) {
|
|
|
9473
9579
|
tarball: { type: "string", short: "t" },
|
|
9474
9580
|
pkgfile: { type: "string", short: "p" },
|
|
9475
9581
|
cache: { type: "string" },
|
|
9582
|
+
config: { type: "string" },
|
|
9476
9583
|
"allow-dependency": { type: "string", multiple: true, default: [] },
|
|
9477
9584
|
"allow-types-dependencies": { type: "boolean" },
|
|
9478
9585
|
"allow-file": { type: "string", multiple: true, default: [] },
|
|
@@ -9490,6 +9597,7 @@ function parseCliArgs(argv) {
|
|
|
9490
9597
|
action: "run",
|
|
9491
9598
|
args: {
|
|
9492
9599
|
cache: values.cache,
|
|
9600
|
+
config: values.config,
|
|
9493
9601
|
pkgfile: values.pkgfile,
|
|
9494
9602
|
tarball: values.tarball,
|
|
9495
9603
|
ignoreMissingFields: values["ignore-missing-fields"],
|
|
@@ -9510,12 +9618,37 @@ async function loadPackage(args, regenerateReportName) {
|
|
|
9510
9618
|
filePath: args.tarball ?? tarballLocation(pkg, pkgPath),
|
|
9511
9619
|
reportPath: regenerateReportName ? `${pkg.name}-${pkg.version}.tgz` : void 0
|
|
9512
9620
|
};
|
|
9513
|
-
if (!
|
|
9621
|
+
if (!existsSync2(tarball.filePath)) {
|
|
9514
9622
|
console.error(`"${tarball.filePath}" does not exist, did you forget to run \`npm pack'?`);
|
|
9515
9623
|
return void 0;
|
|
9516
9624
|
}
|
|
9517
9625
|
return { pkg, pkgAst, pkgPath, tarball };
|
|
9518
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
|
+
}
|
|
9519
9652
|
async function run() {
|
|
9520
9653
|
let cli;
|
|
9521
9654
|
try {
|
|
@@ -9534,8 +9667,11 @@ async function run() {
|
|
|
9534
9667
|
return;
|
|
9535
9668
|
}
|
|
9536
9669
|
const { args } = cli;
|
|
9537
|
-
const
|
|
9538
|
-
|
|
9670
|
+
const options = await resolveVerifyOptions(args);
|
|
9671
|
+
if (!options) {
|
|
9672
|
+
process.exitCode = 1;
|
|
9673
|
+
return;
|
|
9674
|
+
}
|
|
9539
9675
|
if (args.cache) {
|
|
9540
9676
|
await setCacheDirecory(args.cache);
|
|
9541
9677
|
}
|
|
@@ -9551,27 +9687,11 @@ async function run() {
|
|
|
9551
9687
|
}
|
|
9552
9688
|
const { pkg, pkgAst, pkgPath, tarball } = loaded;
|
|
9553
9689
|
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
9690
|
const results = await verify(pkg, pkgAst, pkgPath, tarball, options);
|
|
9562
|
-
|
|
9563
|
-
|
|
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);
|
|
9691
|
+
const sortedResults = sortResults(results);
|
|
9692
|
+
const output = stylish(sortedResults);
|
|
9571
9693
|
process.stdout.write(output);
|
|
9572
|
-
const totalErrors =
|
|
9573
|
-
return sum + result.errorCount;
|
|
9574
|
-
}, 0);
|
|
9694
|
+
const totalErrors = countErrors(sortedResults);
|
|
9575
9695
|
process.exitCode = totalErrors > 0 ? 1 : 0;
|
|
9576
9696
|
}
|
|
9577
9697
|
await run();
|