npm-pkg-lint 5.2.4 → 5.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -20,7 +20,8 @@ Core principles:
20
20
  ```
21
21
  usage: index.js [-h] [-v] [-t TARBALL] [-p PKGFILE] [--cache CACHE]
22
22
  [--allow-dependency DEPENDENCY] [--allow-types-dependencies]
23
- [--ignore-missing-fields]
23
+ [--allow-file FILE] [--ignore-missing-fields]
24
+ [--ignore-node-version [MAJOR]]
24
25
 
25
26
  Opiniated linter for NPM package tarball and package.json metadata
26
27
 
@@ -37,6 +38,9 @@ optional arguments:
37
38
  multiple times or as a comma-separated list)
38
39
  --allow-types-dependencies
39
40
  allow production dependencies to `@types/*`
41
+ --allow-file FILE explicitly allow given filename or glob in tarball
42
+ (can be given multiple times or as a comma-separated
43
+ list)
40
44
  --ignore-missing-fields
41
45
  ignore errors for missing fields (but still checks for
42
46
  empty and valid)
@@ -71,13 +75,14 @@ This tool can be used directly with Github Actions:
71
75
  > You need to have `npm-pkg-lint` installed as a dependency in `package.json`.
72
76
  > This ensures you have control over which version of the tool is actually running.
73
77
 
74
- | Input parameter | Default | Description |
75
- | -------------------- | --------- | ------------------------------------------------------------------------------------------ |
76
- | allow-dependencies | `-` | Comma-separated list of dependencies to explicitly allow even if they would yield an error |
77
- | build | `"build"` | Build command (executed with `npm run`). Set to `false` to disable build. |
78
- | folders | `"."` | Space-separated list of folder to run in. |
79
- | ignore-node-version | - | Ignore error for outdated node version (see --ignore-node-version CLI argument) |
80
- | npm-pack | `true` | When enabled `npm pack` is run automatically |
78
+ | Input parameter | Default | Description |
79
+ | -------------------- | --------- | ----------------------------------------------------------------------------------------------------------- |
80
+ | allow-dependencies | `-` | Comma-separated list of dependencies to explicitly allow even if they would yield an error |
81
+ | allow-files | `-` | Comma-separated list of filenames or globs to explicitly allow in tarball even if they would yield an error |
82
+ | build | `"build"` | Build command (executed with `npm run`). Set to `false` to disable build. |
83
+ | folders | `"."` | Space-separated list of folder to run in. |
84
+ | ignore-node-version | - | Ignore error for outdated node version (see --ignore-node-version CLI argument) |
85
+ | npm-pack | `true` | When enabled `npm pack` is run automatically |
81
86
 
82
87
  ## Disallowed files
83
88
 
@@ -93,6 +98,12 @@ Disallows certain files from being included in the package tarball.
93
98
  - Typescript configs (tsconfig)
94
99
  - Editor-related files
95
100
 
101
+ If needed, `--allow-file` can be used to explicitly allow one or more files or globs in the tarball even if they would otherwise be disallowed.
102
+
103
+ > [!TIP]
104
+ > `--allow-file '**/*'` can be used to effectively disable this rule entirely.
105
+ > Use `'**/*,**/.*'` if you also need to allow dotfiles (e.g. `.eslintrc.json`).
106
+
96
107
  ## Missing files
97
108
 
98
109
  Requires files specified in `package.json` to be present.
package/dist/index.js CHANGED
@@ -4581,6 +4581,7 @@ function isBlacklisted(filename2) {
4581
4581
 
4582
4582
  // src/tarball.ts
4583
4583
  import fs3 from "node:fs";
4584
+ import { matchesGlob } from "node:path";
4584
4585
 
4585
4586
  // node_modules/tar/dist/esm/index.min.js
4586
4587
  import Qr from "events";
@@ -7595,8 +7596,13 @@ async function getFileContent(tarball, filenames) {
7595
7596
  rs2.pipe(t);
7596
7597
  });
7597
7598
  }
7598
- function blacklistedFiles(filelist) {
7599
- return filelist.filter(isBlacklisted);
7599
+ function isAllowedFile(filename2, allowedFiles) {
7600
+ return allowedFiles.some((pattern) => matchesGlob(filename2, pattern));
7601
+ }
7602
+ function blacklistedFiles(filelist, allowedFiles = []) {
7603
+ return filelist.filter(
7604
+ (filename2) => isBlacklisted(filename2) && !isAllowedFile(filename2, allowedFiles)
7605
+ );
7600
7606
  }
7601
7607
  function normalizeRequiredFiles(src) {
7602
7608
  if (typeof src === "string") {
@@ -7675,10 +7681,11 @@ function fileExists(filelist, filename2) {
7675
7681
  }
7676
7682
  return false;
7677
7683
  }
7678
- async function verifyTarball(pkg, tarball) {
7684
+ async function verifyTarball(pkg, tarball, options) {
7679
7685
  const messages = [];
7680
7686
  const filelist = await getFileList(tarball.filePath);
7681
- for (const filename2 of blacklistedFiles(filelist)) {
7687
+ const disallowedFiles = blacklistedFiles(filelist, options.allowedFiles);
7688
+ for (const filename2 of disallowedFiles) {
7682
7689
  messages.push({
7683
7690
  ruleId: "no-disallowed-files",
7684
7691
  severity: 2,
@@ -9159,7 +9166,11 @@ function verifyDependencies(pkg, pkgAst, options) {
9159
9166
  }
9160
9167
  return messages;
9161
9168
  }
9162
- async function verifyPackageJson(pkg, pkgAst, filePath, options = { allowedDependencies: /* @__PURE__ */ new Set(), ignoreNodeVersion: false }) {
9169
+ async function verifyPackageJson(pkg, pkgAst, filePath, options = {
9170
+ allowedDependencies: /* @__PURE__ */ new Set(),
9171
+ allowedFiles: [],
9172
+ ignoreNodeVersion: false
9173
+ }) {
9163
9174
  const { ignoreNodeVersion } = options;
9164
9175
  const messages = [
9165
9176
  ...conflictingTypesTypings(pkg, pkgAst),
@@ -9315,7 +9326,7 @@ async function verifyShebang(pkg, tarball) {
9315
9326
  // src/verify.ts
9316
9327
  async function verify(pkg, pkgAst, pkgPath, tarball, options) {
9317
9328
  return [
9318
- ...await verifyTarball(pkg, tarball),
9329
+ ...await verifyTarball(pkg, tarball, { allowedFiles: options.allowedFiles }),
9319
9330
  ...await verifyPackageJson(pkg, pkgAst, pkgPath, options),
9320
9331
  ...await verifyPackageLock(),
9321
9332
  ...await verifyShebang(pkg, tarball)
@@ -9328,7 +9339,8 @@ var { version } = JSON.parse(readFileSync(pkgFilepath, "utf-8"));
9328
9339
  var PACKAGE_JSON = "package.json";
9329
9340
  var HELP_TEXT = `usage: index.js [-h] [-v] [-t TARBALL] [-p PKGFILE] [--cache CACHE]
9330
9341
  [--allow-dependency DEPENDENCY] [--allow-types-dependencies]
9331
- [--ignore-missing-fields] [--ignore-node-version [MAJOR]]
9342
+ [--allow-file FILE] [--ignore-missing-fields]
9343
+ [--ignore-node-version [MAJOR]]
9332
9344
 
9333
9345
  Opiniated linter for NPM package tarball and package.json metadata
9334
9346
 
@@ -9345,6 +9357,9 @@ options:
9345
9357
  multiple times or as a comma-separated list)
9346
9358
  --allow-types-dependencies
9347
9359
  allow production dependencies to \`@types/*\`
9360
+ --allow-file FILE explicitly allow given filename or glob in tarball
9361
+ (can be given multiple times or as a comma-separated
9362
+ list)
9348
9363
  --ignore-missing-fields
9349
9364
  ignore errors for missing fields (but still checks for
9350
9365
  empty and valid)
@@ -9450,6 +9465,7 @@ function parseCliArgs(argv) {
9450
9465
  cache: { type: "string" },
9451
9466
  "allow-dependency": { type: "string", multiple: true, default: [] },
9452
9467
  "allow-types-dependencies": { type: "boolean" },
9468
+ "allow-file": { type: "string", multiple: true, default: [] },
9453
9469
  "ignore-missing-fields": { type: "boolean" }
9454
9470
  },
9455
9471
  strict: true
@@ -9469,7 +9485,8 @@ function parseCliArgs(argv) {
9469
9485
  ignoreMissingFields: values["ignore-missing-fields"],
9470
9486
  ignoreNodeVersion,
9471
9487
  allowDependency: values["allow-dependency"],
9472
- allowTypesDependencies: values["allow-types-dependencies"]
9488
+ allowTypesDependencies: values["allow-types-dependencies"],
9489
+ allowFile: values["allow-file"]
9473
9490
  }
9474
9491
  };
9475
9492
  }
@@ -9508,6 +9525,7 @@ async function run() {
9508
9525
  }
9509
9526
  const { args } = cli;
9510
9527
  const allowedDependencies2 = new Set(args.allowDependency.flatMap((it2) => it2.split(",")));
9528
+ const allowedFiles = args.allowFile.flatMap((it2) => it2.split(","));
9511
9529
  if (args.cache) {
9512
9530
  await setCacheDirecory(args.cache);
9513
9531
  }
@@ -9526,6 +9544,7 @@ async function run() {
9526
9544
  const options = {
9527
9545
  allowedDependencies: allowedDependencies2,
9528
9546
  allowTypesDependencies: args.allowTypesDependencies,
9547
+ allowedFiles,
9529
9548
  ignoreMissingFields: args.ignoreMissingFields,
9530
9549
  ignoreNodeVersion: args.ignoreNodeVersion
9531
9550
  };