Skip to content

Commit 2d43f48

Browse files
scagoodaladdin-add
andauthoredOct 10, 2023
fix: Normalise package.json#files before checking ignores and whitelist (#123) (fixes #122)
Co-authored-by: 唯然 <weiran.zsd@outlook.com>
1 parent 5507f43 commit 2d43f48

File tree

5 files changed

+26
-2
lines changed

5 files changed

+26
-2
lines changed
 

‎lib/util/get-npmignore.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ const exists = require("./exists")
1212
const getPackageJson = require("./get-package-json")
1313

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

9190
for (const file of files) {
9291
if (typeof file === "string" && file) {
93-
const body = file.replace(SLASH_AT_BEGIN_AND_END, "")
92+
const body = path.posix
93+
.normalize(file.replace(/^!/u, ""))
94+
.replace(/\/+$/u, "")
95+
9496
if (file.startsWith("!")) {
9597
igN.add(`${body}`)
9698
igN.add(`${body}/**`)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
#!/usr/bin/env node

‎tests/fixtures/no-unpublished/issue99/index.js

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"bin": "./bin.js",
3+
"exports": "./index.js",
4+
"files": [
5+
"./index.js",
6+
"bin.js"
7+
]
8+
}

‎tests/lib/rules/no-unpublished-require.js

+13
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,19 @@ ruleTester.run("no-unpublished-require", rule, {
240240
env: { node: true },
241241
},
242242

243+
// https://github.com/eslint-community/eslint-plugin-n/issues/122
244+
// Allow files to start with './' in package.json#files
245+
{
246+
filename: fixture("issue99/test/bin.js"),
247+
code: "require('./index.js');",
248+
env: { node: true },
249+
},
250+
{
251+
filename: fixture("issue99/test/bin.js"),
252+
code: "require('.');",
253+
env: { node: true },
254+
},
255+
243256
// allowModules option
244257
{
245258
filename: fixture("1/test.js"),

0 commit comments

Comments
 (0)
Please sign in to comment.