diff --git a/fstream-npm.js b/fstream-npm.js index 8f8114f..bb7d69e 100644 --- a/fstream-npm.js +++ b/fstream-npm.js @@ -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 @@ -179,7 +180,19 @@ 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) { + var ruleMatched = (r.match('/' + entry) || r.match(entry)) + if (ruleMatched) { + r.matchedExistingFile = true + } + return ruleMatched + }) + return filesMatched + } + + return includeFile } Packer.prototype.addIgnoreFiles = function () { @@ -230,12 +243,14 @@ 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) { + var f2 = f.replace('\/+$/', '') + var globRule = new Minimatch('{' + f2 + ',' + f2 + '/**}') + globRule.originalPattern = f + return globRule + }) + return [] } Packer.prototype.getChildProps = function (stat) { diff --git a/package.json b/package.json index 285a123..04368dd 100644 --- a/package.json +++ b/package.json @@ -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",