Skip to content

Commit

Permalink
fix: Normalise package.json#files before checking ignores and white…
Browse files Browse the repository at this point in the history
…list (#123) (fixes #122)

Co-authored-by: 唯然 <[email protected]>
  • Loading branch information
scagood and aladdin-add authored Oct 10, 2023
1 parent 5507f43 commit 2d43f48
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 2 deletions.
6 changes: 4 additions & 2 deletions lib/util/get-npmignore.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ const exists = require("./exists")
const getPackageJson = require("./get-package-json")

const cache = new Cache()
const SLASH_AT_BEGIN_AND_END = /^!?\/+|^!|\/+$/gu
const PARENT_RELATIVE_PATH = /^\.\./u
const NEVER_IGNORED =
/^(?:readme\.[^.]*|(?:licen[cs]e|changes|changelog|history)(?:\.[^.]*)?)$/iu
Expand Down Expand Up @@ -90,7 +89,10 @@ function parseWhiteList(files) {

for (const file of files) {
if (typeof file === "string" && file) {
const body = file.replace(SLASH_AT_BEGIN_AND_END, "")
const body = path.posix
.normalize(file.replace(/^!/u, ""))
.replace(/\/+$/u, "")

if (file.startsWith("!")) {
igN.add(`${body}`)
igN.add(`${body}/**`)
Expand Down
1 change: 1 addition & 0 deletions tests/fixtures/no-unpublished/issue99/bin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#!/usr/bin/env node
Empty file.
8 changes: 8 additions & 0 deletions tests/fixtures/no-unpublished/issue99/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"bin": "./bin.js",
"exports": "./index.js",
"files": [
"./index.js",
"bin.js"
]
}
13 changes: 13 additions & 0 deletions tests/lib/rules/no-unpublished-require.js
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,19 @@ ruleTester.run("no-unpublished-require", rule, {
env: { node: true },
},

// https://github.com/eslint-community/eslint-plugin-n/issues/122
// Allow files to start with './' in package.json#files
{
filename: fixture("issue99/test/bin.js"),
code: "require('./index.js');",
env: { node: true },
},
{
filename: fixture("issue99/test/bin.js"),
code: "require('.');",
env: { node: true },
},

// allowModules option
{
filename: fixture("1/test.js"),
Expand Down

0 comments on commit 2d43f48

Please sign in to comment.