-
Notifications
You must be signed in to change notification settings - Fork 35
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
Support excluding specific file patterns in nested directories #29
Conversation
For a file pattern such as "dist/**/!(*.test.js)", previously it would add an entry of "!dist/**/!(*.test.js)/**" for the ignore-walker, which results in paths such as "dist/lib/x.test.js" getting included in the pack. The fix is to avoid appending the "/**" if the file ends in "**/!(pattern)".
Looks like the build is only failing on Node 4 due to ES6 syntax in a node module. |
@@ -165,7 +165,10 @@ const npmWalker = Class => class Walker extends Class { | |||
|
|||
if (Array.isArray(pkg.files)) | |||
super.onReadIgnoreFile('package.json', '*\n' + pkg.files.map( | |||
f => '!' + f + '\n!' + f.replace(/\/+$/, '') + '/**' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it be a better solution if we change this to always return '!' + f
, and then update ignore-walker to handle directories when the /**
is missing? Currently if I do this, the tests for the package-json-bin-x.js tests fail, e.g.
npm-packlist/test/package-json-bin-single.js
Lines 24 to 31 in 1a4c8bf
const json = { | |
name: 'test-package', | |
version: '1.6.2', | |
bin: '__bin', | |
files: [ | |
'lib' | |
] | |
} |
I don't think what I've done is the right solution, so I converted this to the issue #31 instead. |
Rather than converting the package.json `files` array to a set of reverse-ignore rules, resolve the globs, and treat the resulting file list as if it was the result of the fs.readdir call at the start. We still generate a set of "ignore" rules based on the presence of files, but only to handle the negated cases, so that situations like this behave as a user will tend to expect: { "files": [ "lib/", "!lib/foo.js" ] } This imposes some subtle and potentially risky changes. Not risky because they're bad or unexpected -- quite the opposite -- but simply risky because it's an area of npm where users tend to just throw bits at the wall and then ignore once it's sort of working. Since npm only reads ignore files and package.json files on package preparation and not extraction, the risk is limited. Some folks might update their client, and then publish some packages that don't behave quite as they intend, but feedback on npm.community and other venues has shown that in all cases where the v1 behavior differed from v2, users were surprised and frustrated. Close #14 Fix #29
Rather than converting the package.json `files` array to a set of reverse-ignore rules, resolve the globs, and treat the resulting file list as if it was the result of the fs.readdir call at the start. We still generate a set of "ignore" rules based on the presence of files, but only to handle the negated cases, so that situations like this behave as a user will tend to expect: { "files": [ "lib/", "!lib/foo.js" ] } This imposes some subtle and potentially risky changes. Not risky because they're bad or unexpected -- quite the opposite -- but simply risky because it's an area of npm where users tend to just throw bits at the wall and then ignore once it's sort of working. Since npm only reads ignore files and package.json files on package preparation and not extraction, the risk is limited. Some folks might update their client, and then publish some packages that don't behave quite as they intend, but feedback on npm.community and other venues has shown that in all cases where the v1 behavior differed from v2, users were surprised and frustrated. Close #14 Fix #29
Rather than converting the package.json `files` array to a set of reverse-ignore rules, resolve the globs, and treat the resulting file list as if it was the result of the fs.readdir call at the start. We still generate a set of "ignore" rules based on the presence of files, but only to handle the negated cases, so that situations like this behave as a user will tend to expect: { "files": [ "lib/", "!lib/foo.js" ] } This imposes some subtle and potentially risky changes. Not risky because they're bad or unexpected -- quite the opposite -- but simply risky because it's an area of npm where users tend to just throw bits at the wall and then ignore once it's sort of working. Since npm only reads ignore files and package.json files on package preparation and not extraction, the risk is limited. Some folks might update their client, and then publish some packages that don't behave quite as they intend, but feedback on npm.community and other venues has shown that in all cases where the v1 behavior differed from v2, users were surprised and frustrated. Close #14 Fix #29
Rather than converting the package.json `files` array to a set of reverse-ignore rules, resolve the globs, and treat the resulting file list as if it was the result of the fs.readdir call at the start. We still generate a set of "ignore" rules based on the presence of files, but only to handle the negated cases, so that situations like this behave as a user will tend to expect: { "files": [ "lib/", "!lib/foo.js" ] } This imposes some subtle and potentially risky changes. Not risky because they're bad or unexpected -- quite the opposite -- but simply risky because it's an area of npm where users tend to just throw bits at the wall and then ignore once it's sort of working. Since npm only reads ignore files and package.json files on package preparation and not extraction, the risk is limited. Some folks might update their client, and then publish some packages that don't behave quite as they intend, but feedback on npm.community and other venues has shown that in all cases where the v1 behavior differed from v2, users were surprised and frustrated. Close #14 Fix #29
Rather than converting the package.json `files` array to a set of reverse-ignore rules, resolve the globs, and treat the resulting file list as if it was the result of the fs.readdir call at the start. We still generate a set of "ignore" rules based on the presence of files, but only to handle the negated cases, so that situations like this behave as a user will tend to expect: { "files": [ "lib/", "!lib/foo.js" ] } This imposes some subtle and potentially risky changes. Not risky because they're bad or unexpected -- quite the opposite -- but simply risky because it's an area of npm where users tend to just throw bits at the wall and then ignore once it's sort of working. Since npm only reads ignore files and package.json files on package preparation and not extraction, the risk is limited. Some folks might update their client, and then publish some packages that don't behave quite as they intend, but feedback on npm.community and other venues has shown that in all cases where the v1 behavior differed from v2, users were surprised and frustrated. Close #14 Fix #29
For a file pattern such as
dist/**/!(*.test.js)
, previously it would add an entry of!dist/**/!(*.test.js)/**
for the ignore-walker, which results in paths such asdist/lib/x.test.js
getting included in the pack. The fix is to avoid appending the/**
if the file ends in**/!(pattern)
.The CLI output below on a temporary project shows that the current behaviour does not match the glob spec when it comes to excluding file patterns.
Thanks!