From 7e2d04655edf07d5d98f9a0366773b02f1e44577 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kat=20March=C3=A1n?= Date: Fri, 1 Apr 2016 15:17:36 -0700 Subject: [PATCH 1/2] npmignore entries trump files entries Previously, files were treated as negated-negated ignores. This made it fairly tricky to control whether files or .npmignore took priority when deciding whether a file should be included. With this change, files are included through a more explicit process, and any applicable ignores will trump specific files. --- fstream-npm.js | 25 ++++++++++++++++++------- package.json | 3 ++- 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/fstream-npm.js b/fstream-npm.js index 8f8114f..83f043a 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,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 () { @@ -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) { 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", From 05d9771669ae93df5ebbd6866407fd659710d360 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kat=20March=C3=A1n?= Date: Mon, 4 Apr 2016 11:02:40 -0700 Subject: [PATCH 2/2] track which files array entries have had any matches --- fstream-npm.js | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/fstream-npm.js b/fstream-npm.js index 83f043a..bb7d69e 100644 --- a/fstream-npm.js +++ b/fstream-npm.js @@ -183,8 +183,11 @@ Packer.prototype.applyIgnores = function (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)) + var ruleMatched = (r.match('/' + entry) || r.match(entry)) + if (ruleMatched) { + r.matchedExistingFile = true + } + return ruleMatched }) return filesMatched } @@ -242,10 +245,11 @@ Packer.prototype.readRules = function (buf, e) { 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) }, []) - + var f2 = f.replace('\/+$/', '') + var globRule = new Minimatch('{' + f2 + ',' + f2 + '/**}') + globRule.originalPattern = f + return globRule + }) return [] }