Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/npm/cli.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorisaacs <i@izs.me>2011-12-15 04:20:50 +0400
committerisaacs <i@izs.me>2011-12-15 04:20:50 +0400
commit1c245046b649a5e5bee45a793002c85839cbe8a1 (patch)
treee8fb85af515128f8e9dd2e6947f281457c4aafb8
parent8731fef0f88617cccc856692f352f7228461a69e (diff)
Bring npmignore behavior more into line with gitignore
-rw-r--r--lib/utils/excludes.js40
-rw-r--r--test/packages/npm-test-ignore/.npmignore7
-rw-r--r--test/packages/npm-test-ignore/ignore30
-rw-r--r--test/packages/npm-test-ignore/ignoredir1/a0
-rw-r--r--test/packages/npm-test-ignore/ignoredir2/a0
-rw-r--r--test/packages/npm-test-ignore/include40
-rw-r--r--test/packages/npm-test-ignore/package.json3
-rw-r--r--test/packages/npm-test-ignore/sub/ignore10
-rw-r--r--test/packages/npm-test-ignore/sub/ignore30
-rw-r--r--test/packages/npm-test-ignore/sub/include0
-rw-r--r--test/packages/npm-test-ignore/sub/include20
-rw-r--r--test/packages/npm-test-ignore/sub/include41
-rw-r--r--test/packages/npm-test-ignore/test.sh27
13 files changed, 64 insertions, 14 deletions
diff --git a/lib/utils/excludes.js b/lib/utils/excludes.js
index c9920670f..9b407c945 100644
--- a/lib/utils/excludes.js
+++ b/lib/utils/excludes.js
@@ -88,8 +88,8 @@ function addIgnoreFile (file, gitBase, list, dir, cb) {
// see if a file should be included or not, given those exclude lists.
function test (file, excludeList) {
if (path.basename(file) === "package.json") return true
- //log.warn(file, "test file")
- //log.warn(excludeList, "test list")
+ // log.warn(file, "test file")
+ // log.warn(excludeList, "test list")
var incRe = /^\!(\!\!)*/
, excluded = false
for (var i = 0, l = excludeList.length; i < l; i ++) {
@@ -99,12 +99,15 @@ function test (file, excludeList) {
// chop the filename down to be relative to excludeDir
var rf = relativize(file, dir, true)
rf = rf.replace(/^\.?\//, "")
+ if (file.slice(-1) === "/") rf += "/"
+
+ // log.warn([file, rf], "rf")
for (var ii = 0, ll = excludes.length; ii < ll; ii ++) {
- //log.warn(JSON.stringify(excludes[ii]), "ex")
- var ex = excludes[ii].replace(/^(!*)\.\//, "$1")
+ var ex = excludes[ii].replace(/^(!*)\//, "$1")
, inc = !!ex.match(incRe)
+ // log.warn([ex, rf], "ex, rf")
// excluding/including a dir excludes/includes all the files in it.
if (ex.slice(-1) === "/") ex += "**"
@@ -118,20 +121,27 @@ function test (file, excludeList) {
if (inc && !excluded) continue
// if it matches the pattern, then it should be excluded.
- excluded = !!minimatch(rf, ex, { baseMatch: true })
- //if (inc) excluded = !excluded
-
- //if (excluded) {
- // console.error("excluded %s %s", rf, ex)
- //}
+ excluded = !!minimatch(rf, ex, { matchBase: true })
+ // log.error([rf, ex, excluded], "rf, ex, excluded")
// if you include foo, then it also includes foo/bar.js
if (inc && excluded && ex.slice(-3) !== "/**") {
- excluded = minimatch(rf, ex + "/**", { baseMatch: true })
- // console.error(rf, ex + "/**", inc, excluded)
+ excluded = minimatch(rf, ex + "/**", { matchBase: true })
+ // log.warn([rf, ex + "/**", inc, excluded], "dir without /")
+ }
+
+ // if you exclude foo, then it also excludes foo/bar.js
+ if (!inc
+ && excluded
+ && ex.slice(-3) !== "/**"
+ && rf.slice(-1) === "/"
+ && excludes.indexOf(ex + "/**") === -1) {
+ // log.warn(ex + "/**", "adding dir-matching exclude pattern")
+ excludes.push(ex + "/**")
+ ll ++
}
}
- //log.warn([rf, excluded, excludes], "file, excluded, excludes")
+ // log.warn([rf, excluded, excludes], "rf, excluded, excludes")
}
// true if it *should* be included
// log.warn([file, excludeList, excluded], "file, excluded")
@@ -141,5 +151,7 @@ function test (file, excludeList) {
// returns a function suitable for Array#filter
function filter (dir, list) { return function (file) {
file = file.trim()
- return file && test(path.resolve(dir, file), list)
+ var testFile = path.resolve(dir, file)
+ if (file.slice(-1) === "/") testFile += "/"
+ return file && test(testFile, list)
}}
diff --git a/test/packages/npm-test-ignore/.npmignore b/test/packages/npm-test-ignore/.npmignore
new file mode 100644
index 000000000..c7d927d0a
--- /dev/null
+++ b/test/packages/npm-test-ignore/.npmignore
@@ -0,0 +1,7 @@
+/sub/ignore1
+./sub/include2
+ignore3
+./include4
+ignoredir1
+ignoredir2/
+*.tgz
diff --git a/test/packages/npm-test-ignore/ignore3 b/test/packages/npm-test-ignore/ignore3
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/test/packages/npm-test-ignore/ignore3
diff --git a/test/packages/npm-test-ignore/ignoredir1/a b/test/packages/npm-test-ignore/ignoredir1/a
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/test/packages/npm-test-ignore/ignoredir1/a
diff --git a/test/packages/npm-test-ignore/ignoredir2/a b/test/packages/npm-test-ignore/ignoredir2/a
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/test/packages/npm-test-ignore/ignoredir2/a
diff --git a/test/packages/npm-test-ignore/include4 b/test/packages/npm-test-ignore/include4
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/test/packages/npm-test-ignore/include4
diff --git a/test/packages/npm-test-ignore/package.json b/test/packages/npm-test-ignore/package.json
new file mode 100644
index 000000000..6d492de78
--- /dev/null
+++ b/test/packages/npm-test-ignore/package.json
@@ -0,0 +1,3 @@
+{ "name":"npm-test-ignore"
+, "version":"1.2.5"
+, "scripts":{"test":"bash test.sh"}}
diff --git a/test/packages/npm-test-ignore/sub/ignore1 b/test/packages/npm-test-ignore/sub/ignore1
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/test/packages/npm-test-ignore/sub/ignore1
diff --git a/test/packages/npm-test-ignore/sub/ignore3 b/test/packages/npm-test-ignore/sub/ignore3
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/test/packages/npm-test-ignore/sub/ignore3
diff --git a/test/packages/npm-test-ignore/sub/include b/test/packages/npm-test-ignore/sub/include
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/test/packages/npm-test-ignore/sub/include
diff --git a/test/packages/npm-test-ignore/sub/include2 b/test/packages/npm-test-ignore/sub/include2
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/test/packages/npm-test-ignore/sub/include2
diff --git a/test/packages/npm-test-ignore/sub/include4 b/test/packages/npm-test-ignore/sub/include4
new file mode 100644
index 000000000..d16969cd1
--- /dev/null
+++ b/test/packages/npm-test-ignore/sub/include4
@@ -0,0 +1 @@
+This file should be in the package.
diff --git a/test/packages/npm-test-ignore/test.sh b/test/packages/npm-test-ignore/test.sh
new file mode 100644
index 000000000..cdf47f211
--- /dev/null
+++ b/test/packages/npm-test-ignore/test.sh
@@ -0,0 +1,27 @@
+x=`find . | grep ignore | grep -v npmignore`
+if [ "$x" != "" ]; then
+ echo "ignored files included: $x"
+ exit 1
+fi
+
+x=`find . | grep -v ignore | sort`
+y=".
+./include4
+./package.json
+./sub
+./sub/include
+./sub/include2
+./sub/include4
+./test.sh"
+if [ "$x" != "$y" ]; then
+ echo "missing included files"
+ echo "got:"
+ echo "==="
+ echo "$x"
+ echo "==="
+ echo "wanted:"
+ echo "==="
+ echo "$y"
+ echo "==="
+ exit 1
+fi