sboudrias / gulp-exclude-gitignore Goto Github PK
View Code? Open in Web Editor NEWGulp plugin to exclude file contained in .gitignore from the stream
License: ISC License
Gulp plugin to exclude file contained in .gitignore from the stream
License: ISC License
I'm having an issue with a Yeoman generator - on Node/npm version 5.x .gitignore files are automatically renamed to .npmignore (see this npm issue)
Because of this, my gulp tasks fail when using gulp-exclude-gitignore with:
Error: ENOENT: no such file or directory, open '/Users/andrei/dev/exttmp/.gitignore'
at Error (native)
at Object.fs.openSync (fs.js:549:18)
at Object.fs.readFileSync (fs.js:397:15)
at module.exports (/Users/andrei/dev/exttmp/node_modules/gulp-exclude-gitignore/lib/index.js:17:21)
at Gulp.<anonymous> (/Users/andrei/dev/exttmp/gulpfile.js:17:11)
at module.exports (/Users/andrei/dev/exttmp/node_modules/orchestrator/lib/runTask.js:34:7)
...
Branch | Build failing π¨ |
---|---|
Dependency | sinon |
Current Version | 3.2.1 |
Type | devDependency |
This version is covered by your current version range and after updating it in your project the build failed.
As sinon is βonlyβ a devDependency of this project it might not break production or downstream projects, but βonlyβ your build or test tools β preventing new deploys or publishes.
I recommend you give this issue a high priority. Iβm sure you can resolve this πͺ
The new version differs by 24 commits.
e9f40a2
Rename Changelog.txt to History.md
40edb3e
Update docs/changelog.md and set new release id in docs/_config.yml
27986c8
Add release documentation for v3.3.0
85f30b5
3.3.0
7d45683
Update Changelog.txt and AUTHORS for new release
10906a7
Merge pull request #1560 from servel333/nested_property_matcher
a54b38c
Fixes docs for error.
04ba963
Adds sinon.match.hasNested
5fbd9ee
Merge pull request #1549 from killmenot/fix-1442
0a34cf5
Merge pull request #1550 from kuba-orlik/patch-1
a90f3ce
Merge pull request #1558 from fatso83/fix-eslint-error
32e4516
Update code to stricter linting
212e91d
Fix eslint peerDependencies error
5606815
Fix double backticks in inline code examples
af30213
fix #1442
There are 24 commits in total.
See the full diff
There is a collection of frequently asked questions and of course you may always ask my humans.
Your Greenkeeper Bot π΄
1.2.0
to 1.2.1
.π¨ View failing branch.
This version is covered by your current version range and after updating it in your project the build failed.
gulp-plumber is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.
There is a collection of frequently asked questions. If those donβt help, you can always ask the humans behind Greenkeeper.
Your Greenkeeper Bot π΄
Hi,
when .gitignore file is empty gulp-exclude-gitignore
crashes with the following error:
/usr/local/lib/node_modules/eclint/node_modules/gulp-match/index.js:36
throw new Error('gulp-match: empty glob array');
^
Error: gulp-match: empty glob array
at module.exports (/usr/local/lib/node_modules/eclint/node_modules/gulp-match/index.js:36:10)
at DestroyableTransform._transform (/usr/local/lib/node_modules/eclint/node_modules/gulp-ignore/index.js:17:8)
at DestroyableTransform.Transform._read (/usr/local/lib/node_modules/eclint/node_modules/readable-stream/lib/_stream_transform.js:184:10)
at DestroyableTransform.Transform._write (/usr/local/lib/node_modules/eclint/node_modules/readable-stream/lib/_stream_transform.js:172:83)
at doWrite (/usr/local/lib/node_modules/eclint/node_modules/readable-stream/lib/_stream_writable.js:428:64)
at writeOrBuffer (/usr/local/lib/node_modules/eclint/node_modules/readable-stream/lib/_stream_writable.js:417:5)
at DestroyableTransform.Writable.write (/usr/local/lib/node_modules/eclint/node_modules/readable-stream/lib/_stream_writable.js:334:11)
at StreamFilter.ondata (/usr/local/lib/node_modules/eclint/node_modules/readable-stream/lib/_stream_readable.js:619:20)
at emitOne (events.js:116:13)
at StreamFilter.emit (events.js:211:7)
Line 26 of your index you're using a arrow function, this will break on older versions of node.
.map(str => str.trim())
If possible can you please use babel and create a dist folder with non es6 for older versions?
if you want me to do it let me know
(I'm not sure if this is a valid feature request as my scenario is somewhat of an edge case, and there may be a better way to work around it. With that said...)
In my initial glob, I specify the option {dot: true}
before piping to gulp-exclude-gitignore as follows:
return gulp.src('**/*.json', {dot: true})
.pipe(excludeGitignore())
// etc...
The resulting stream contains the files from my project that I expect, but it also includes JSON dot files from directories listed in my .gitignore
file. For example, even though node_modules
is ignored, the stream contains the file node_modules/extend/.jscs.json
.
I believe the root cause of this problem is an unfortunate side effect of using a blacklist via the gulp-ignore package's exclude
function and the fact that minimatch excludes dot files by default. That is, without additional options, minimatch will always indicate that a dot file does not match, but the gulp-ignore exclude
function negates minimatch's status (via gulp-match), and thus includes all dot files present in the stream.
The following test case demonstrates the problem (the file paths come from an actual project, so this example could be improved to be more generic):
describe('when file paths contain dot files', function () {
it('excludes dot files covered by .gitignore', function (done) {
this.stub = sinon.stub(fs, 'readFileSync');
var contents = [
'build',
'node_modules',
'server.pid'
].join('\n');
this.stub.withArgs(path.resolve('.gitignore'), 'utf8').returns(contents);
var stream = excludeGitignore();
var filePaths = [];
stream.on('data', function (file) {
filePaths.push(file.relative);
});
stream.on('finish', function () {
assert.deepEqual(filePaths, [
'.eslintrc-gulpfile.json',
'package.json',
'test/server/.eslintrc.json',
'test/server/jasmine.json'
]);
done();
});
stream.write(fakeFile('.eslintrc-gulpfile.json'));
stream.write(fakeFile('package.json'));
stream.write(fakeFile('node_modules/extend/.jscs.json'));
stream.write(fakeFile('test/server/.eslintrc.json'));
stream.write(fakeFile('test/server/jasmine.json'));
stream.end();
this.stub.restore();
});
});
The test fails with the following message:
1) when file paths contain dot files excludes dot files covered by .gitignore:
Uncaught AssertionError: [ '.eslintrc-gulpfile.json',
'package.json',
'node_modules/extend/.jscs.json',
'test/server/.eslintrc.json',
'test/serve deepEqual [ '.eslintrc-gulpfile.json',
'package.json',
'test/server/.eslintrc.json',
'test/server/jasmine.json' ]
+ expected - actual
[
".eslintrc-gulpfile.json"
"package.json"
- "node_modules/extend/.jscs.json"
"test/server/.eslintrc.json"
"test/server/jasmine.json"
]
If I were able to pass minimatch options to excludeGitignore
, such that they were passed through to gulpIgnore.exclude
, and thus all the way to minimatch, I could get my scenario to work as expected. For example, the following minimal change seems to work:
diff --git a/lib/index.js b/lib/index.js
index 5ab76a9..08ccbd1 100644
--- a/lib/index.js
+++ b/lib/index.js
@@ -14,8 +14,9 @@ var appendStars = function (dirname, str) {
];
};
-module.exports = function (gitignorePath) {
+module.exports = function (gitignorePath, minimatchOptions) {
gitignorePath = path.resolve(gitignorePath || '.gitignore');
+ minimatchOptions = minimatchOptions || {};
var dirname = path.dirname(path.relative(process.cwd(), gitignorePath));
if (dirname === '.') {
dirname = '';
@@ -32,5 +33,5 @@ module.exports = function (gitignorePath) {
return m.concat(paths);
}, []);
- return gulpIgnore.exclude(ignoredFiles);
+ return gulpIgnore.exclude(ignoredFiles, minimatchOptions);
};
(As is, if you want to specify minimatchOptions
, you have to also specify gitignorePath
. If I were to submit a PR, I probably would write it such that both parameters could be optional. That is, the signature would be excludeGitignore([gitignorePath][, minimatchOptions])
.)
Now, updating the call to excludeGitignore
in the above test case to the following:
var stream = excludeGitignore('.gitignore', {dot: true});
results in a passing test.
Sorry for making you wade through all that. π¬
In summary, would you consider the addition of minimatchOptions
to be a bad smell because I'm coupling the gulp.src
minimatch options to excludeGitignore
? Or am I just overcomplicating this, and there's a better solution that doesn't require modifying gulp-exclude-gitignore?
For example, if my gulp script is running from directory a/
, and I have a .gitignore in directory a/b/
, and I run excludeGitignore("b/.gitignore")
, it will prefix the patterns in the .gitignore with just a/
instead of a/b/
.
I think that what we should actually do is resolve the full path of the gitignore and prefix the patterns with the parent directory of the .gitignore, wherever it is in the file system. Alternatively, we could specify an option to override either the prefix or the current working directory.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. πππ
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google β€οΈ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.