gulp.src(glob-stream)负面glob杀死匹配后的正面glob [英] gulp.src (glob-stream) positive glob after negative glob kills match

查看:167
本文介绍了gulp.src(glob-stream)负面glob杀死匹配后的正面glob的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在印象之外,也看到了代码,表示积极的glob只会受到来自后面的消极情况的限制。



那么,怎么样呢?

  gulp.src([
'../WebContent/g/css/ng-client.css'
],{base:' ../ WebContent'})。pipe(使用())

结果为 ng-client.css 被列出来。



while

  gulp.src([
'!../ WebContent / g / css / *',
'../WebContent/g/css/ng-client.css'
],{base:'../ WebContent'})。pipe(using())

没有列出相同的文件?



我想知道我在考虑那些导致我期望第二个代码阻止返回文件 - 而不是一个解决方案,如何克服这种情况下,我看到了像这样的建议:



我知道我可以做类似的事情:

  gulp.src([
'!../ WebContent / g / css /!(ng-client.css)',
'../WebContent/g/css/ng-client.css '
],{base:'../ WebContent'})。pipe(using())

Q为什么第二个文件没有按照我的预期返回?

解决方案

这很有趣。

您对 glob-stream 源代码的阅读似乎是正确的。它也匹配 glob-stream 本身的文档。但是为什么 gulp 的表现与预期不同?我认为这是因为您没有运行您正在阅读的代码。



即使全新安装 gulp 你没有使用最新版本的 glob-stream 。以下是我刚创建的一个项目中 npm list 的相关摘录:

 ├─┬gulp@3.9.1 
│└─┬vinyl-fs@0.3.14
│├─┬glob-stream@3.1.18

这表示正在使用 glob-stream@3.1.18 。您链接的源代码来自 glob-stream@5.0.0

在GitHub上阅读 glob-stream 的版本标签时,文档中第一次提到glob命令是 4.0.1 。所以它看起来像主要版本 3.x 4.x 之间的行为向后不兼容的变化。



我们可以通过直接运行 glob-stream 来检查:

  var gs = require('glob-stream'); 
gs.create([
'!../ WebContent / g / css / ng *',
'../WebContent/g/css/ng-client.css'
])。pipe(using());

使用 glob-stream@3.1.18 (最后一版 3.x )不会返回任何文件。使用 glob-stream@4.0.0 运行它返回 ng-client.css file。



令我想知道的事情是 gulp文档明确提到了你一直期待的行为。但事实上运行他们在文档中使用的相同示例代码并不会产生他们声称的结果:

  gulp.src (['client / *。js','!client / b * .js','client / bad.js'])

运行 gulp@3.9.1 只返回 client / a.js ,但不是 client / bad.js



看起来其他人有同样的问题。有一个模块叫 gulp-src-ordered-globs (它指这是一个GitHub问题)。使用这个模块,你的例子和Gulp.js文档中的例子都能按预期工作。



如果你真的想深入了解所有这些的底层,那可能是最好的在GitHub上打开问题或向Gulp.js Gitter上的某人询问


I was under the impression and also from looking at the code that the a positive glob would only be restricted by negative globs that come AFTER IT.

So how comes that

gulp.src([
           '../WebContent/g/css/ng-client.css'
        ],{base: '../WebContent'}).pipe(using()) 

results in ng-client.css being listed.

While

gulp.src([
           '!../WebContent/g/css/*',
           '../WebContent/g/css/ng-client.css'
        ],{base: '../WebContent'}).pipe(using())  

does not list the same file?

I want to figure out what is wrong with the way I am thinking of those glob streams that is causing me to expect the second code block to return the file as well - not a solution to how to overcome this scenario, I have seen suggestions like the one In: Glob / minimatch: how to gulp.src() everything, then exclude folder but keep one file in it

and I know that I can do something similar like:

gulp.src([
       '!../WebContent/g/css/!(ng-client.css)',
       '../WebContent/g/css/ng-client.css'
    ],{base: '../WebContent'}).pipe(using())  

The Q is why doesn't the second return the file as I expect it to?

解决方案

This is interesting.

Your reading of the glob-stream source code seems to be correct. It also matches the documentation of glob-stream itself. But then why is gulp behaving differently than expected? I think it's because you're not running the code you have been reading.

Even on a fresh install of gulp you're not using the newest version of glob-stream. Here's the relevant excerpt of npm list from a project I just created:

├─┬ gulp@3.9.1
│ └─┬ vinyl-fs@0.3.14
│   ├─┬ glob-stream@3.1.18

That means glob-stream@3.1.18 is being used. The source code you linked is from glob-stream@5.0.0.

Going through the version tags of glob-stream on GitHub the first mention of glob order in the documentation is in 4.0.1. So it looks like a backwards-incompatible change in behavior was made between major versions 3.x and 4.x.

We can check this by running glob-stream directly:

var gs = require('glob-stream');
gs.create([
  '!../WebContent/g/css/ng*',
  '../WebContent/g/css/ng-client.css'
]).pipe(using());

Running this with glob-stream@3.1.18 (the last release of 3.x) returns no files. Running it with glob-stream@4.0.0 does return the ng-client.css file.

The thing that makes me wonder is that the gulp documentation explicitly mentions the behavior you have been expecting all along. But in fact running the very same example code they use in their documenation doesn't yield the results they claim:

gulp.src(['client/*.js', '!client/b*.js', 'client/bad.js'])

Running this with gulp@3.9.1 only returns client/a.js, but not client/bad.js.

It looks like somebody else was having the same problem. There's a module called gulp-src-ordered-globs (which refers to this a GitHub issue). Using this module both your example and the one from the Gulp.js documentation work as expected.

If you really want to get to the bottom of all this, it's probably best to open an issue on GitHub or ask somebody on the Gulp.js Gitter.

这篇关于gulp.src(glob-stream)负面glob杀死匹配后的正面glob的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆