Closed ifduyue closed 9 years ago
Find this in https://github.com/isaacs/node-glob/blob/e3cdccc0e295c2e1d5f40cf74c73ea17a8319c5c/README.md#options
root The place where patterns starting with / will be mounted onto. Defaults to path.resolve(options.cwd, "/") (/ on Unix systems, and C:\ or some such on Windows.)
Here is a demo https://github.com/ifduyue/gulp-src-with-opts-cwd-and-root, and what I want to do:
$ tree this-is-root/
this-is-root/
├── a
├── b
└── c
├── d
└── e
1 directory, 4 files
Set directory this-is-a-root
as the root (like a chroot root
), so that every glob, not matter whether it start with /
or not, captures expected files under this-is-root
.
But it doesn't work. Below is the output of running gulp:
$ gulp
[01:00:16] Using gulpfile ~/workspace/github/gulp-src-with-opts-cwd-and-root/gulpfile.js
[01:00:16] Starting 'default'...
[01:00:16] glob is [ 'a', '/b', 'c/d', '/c/e' ]
[01:00:16] Finished 'default' after 16 ms
[01:00:16] { cwd: 'this-is-root' } 'captures' [ 'a', 'd' ]
[01:00:16] { root: 'this-is-root' } 'captures' [ 'this-is-root/b',
'../Users/d/workspace/github/gulp-src-with-opts-cwd-and-root/this-is-root/c/e' ]
[01:00:16] { cwd: 'this-is-root', root: 'this-is-root' } 'captures' [ 'this-is-root/b',
'../Users/d/workspace/github/gulp-src-with-opts-cwd-and-root/this-is-root/c/e' ]
It is expected that all the files under this-is-root
are captures by gulp.src
.
But the reality is no matter how I use a combination of the opts cwd
and root
, it only capture two files, not all four.
It seems both glob-stream and node-glob manipulate on globs
and opt.cwd
, and something happens.
Quoted from here
It can be inferred that
root
takes effect only if glob starts with '/', and relative path are resolved againstcwd
. Why treating paths start with and not start with '/' differently? Is it better to treat them all the same? So that: