-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Handle package.json 'files' more intuitively
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
- Loading branch information
Showing
7 changed files
with
180 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
const {resolve, basename} = require('path') | ||
const pkg = resolve(__dirname, basename(__filename, '.js')) | ||
const rimraf = require('rimraf') | ||
const mkdirp = require('mkdirp') | ||
const t = require('tap') | ||
rimraf.sync(pkg) | ||
mkdirp.sync(pkg) | ||
t.teardown(() => rimraf.sync(pkg)) | ||
|
||
const fs = require('fs') | ||
fs.writeFileSync(pkg + '/package.json', JSON.stringify({ | ||
files: [ | ||
'lib', | ||
'!lib/one', | ||
] | ||
})) | ||
mkdirp.sync(pkg + '/lib') | ||
fs.writeFileSync(pkg + '/lib/one', 'one') | ||
fs.writeFileSync(pkg + '/lib/two', 'two') | ||
fs.writeFileSync(pkg + '/lib/tre', 'tre') | ||
fs.writeFileSync(pkg + '/lib/for', 'for') | ||
fs.writeFileSync(pkg + '/lib/.npmignore', 'two') | ||
fs.writeFileSync(pkg + '/lib/.DS_Store', 'a store of ds') | ||
|
||
const requireInject = require('require-inject') | ||
const glob = (pattern, opt, cb) => cb(new Error('no glob for you')) | ||
glob.sync = (pattern, opt) => { throw new Error('no glob for you') } | ||
const packlist = requireInject('../', { glob }) | ||
|
||
t.test('package with busted glob', async t => { | ||
await t.rejects(packlist({path: pkg}), { message: 'no glob for you' }) | ||
t.throws(() => packlist.sync({path: pkg}), { message: 'no glob for you' }) | ||
}) |