Skip to content
This repository was archived by the owner on Nov 16, 2019. It is now read-only.

npmignore entries trump files entries #20

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 18 additions & 7 deletions fstream-npm.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ var Ignore = require('fstream-ignore')
var inherits = require('inherits')
var path = require('path')
var fs = require('fs')
var Minimatch = require('minimatch').Minimatch

module.exports = Packer

Expand Down Expand Up @@ -179,7 +180,16 @@ Packer.prototype.applyIgnores = function (entry, partial, entryObj) {
}
// if (this.bundled) return true

return Ignore.prototype.applyIgnores.call(this, entry, partial, entryObj)
var includeFile = Ignore.prototype.applyIgnores.call(this, entry, partial, entryObj)
if (!partial && this.pkgRules && includeFile) {
var filesMatched = this.pkgRules.some(function (r) {
return (r.match('/' + entry) ||
r.match(entry))
})
return filesMatched
}

return includeFile
}

Packer.prototype.addIgnoreFiles = function () {
Expand Down Expand Up @@ -230,12 +240,13 @@ Packer.prototype.readRules = function (buf, e) {

if (!p.files || !Array.isArray(p.files)) return []

// ignore everything except what's in the files array.
return ['*'].concat(p.files.map(function (f) {
return '!' + f
})).concat(p.files.map(function (f) {
return '!' + f.replace(/\/+$/, '') + '/**'
}))
var mmopts = { matchBase: true, dot: true }
this.pkgRules = p.files.map(function (f) {
return [new Minimatch(f, mmopts),
new Minimatch(f.replace(/\/+$/, '') + '/**', mmopts)]
}).reduce(function (acc, arr) { return acc.concat(arr) }, [])

return []
}

Packer.prototype.getChildProps = function (stat) {
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
"main": "./fstream-npm.js",
"dependencies": {
"fstream-ignore": "^1.0.0",
"inherits": "2"
"inherits": "2",
"minimatch": "^3.0.0"
},
"devDependencies": {
"graceful-fs": "^4.1.2",
Expand Down