Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Normalise package.json#files before checking ignores and whitelist #123

Merged
merged 4 commits into from
Oct 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
Copy link
Author

@scagood scagood Sep 27, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems that ignore only supports posix, even though the read me says other wise 🤔

.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