Skip to content

Commit 2fa4981

Browse files
authored
chore: Update glob docs with replacement to ordered globs (#2788)
1 parent fe9dee6 commit 2fa4981

File tree

1 file changed

+20
-8
lines changed

1 file changed

+20
-8
lines changed

docs/getting-started/6-explaining-globs.md

+20-8
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ sidebar_label: Explaining Globs
99

1010
A glob is a string of literal and/or wildcard characters used to match filepaths. Globbing is the act of locating files on a filesystem using one or more globs.
1111

12-
The `src()` method expects a single glob string or an array of globs to determine which files your pipeline will operate on. At least one match must be found for your glob(s) otherwise `src()` will error. When an array of globs is used, they are matched in array order - especially useful for negative globs.
12+
The `src()` method expects a single glob string or an array of globs to determine which files your pipeline will operate on. At least one match must be found for your glob(s) otherwise `src()` will error. When an array of globs is used, any negative globs will remove matches from any positive glob.
1313

1414
## Segments and separators
1515

@@ -49,26 +49,37 @@ Here, the glob is appropriately restricted to the `scripts/` directory. It will
4949

5050
## Special character: ! (negative)
5151

52-
Since globs are matched in array order, a negative glob must follow at least one non-negative glob in an array. The first finds a set of matches, then the negative glob removes a portion of those results. When excluding all files within a directory, you must add `/**` after the directory name, which the globbing library optimizes internally.
52+
Globs prefixed with the `!` character will "negate" the glob, excluding the match completely. All negative globs are applied to every positive glob, which is a departure from gulp versions before v5.
53+
54+
Here, the `scripts/` directory will be traversed for all files ending in `.js`, but all files from the `scripts/vendor/` directory will be excluded.
5355

5456
```js
5557
['scripts/**/*.js', '!scripts/vendor/**']
5658
```
5759

58-
If any non-negative globs follow a negative, nothing will be removed from the later set of matches.
60+
Negative globs can be used as an alternative for restricting double-star globs.
5961

6062
```js
61-
['scripts/**/*.js', '!scripts/vendor/**', 'scripts/vendor/react.js']
63+
['**/*.js', '!node_modules/**']
6264
```
6365

64-
Negative globs can be used as an alternative for restricting double-star globs.
66+
## Ordered globs
67+
68+
Versions of gulp before v5 allowed "ordered globs"; however, that has been removed to align with most globbing libraries in the ecosystem.
69+
70+
If you need the "ordered glob" functionality, you can use the [ordered-read-streams][ordered-read-streams-docs] library to combine streams:
6571

6672
```js
67-
['**/*.js', '!node_modules/**']
73+
const order = require("ordered-read-streams");
74+
75+
exports.default = function () {
76+
return order([
77+
gulp.src("input/jquery/dist/jquery.js"),
78+
gulp.src("input/detect_swipe/jquery.detect_swipe.js"),
79+
]).pipe(gulp.dest('output/'));
80+
}
6881
```
6982

70-
<small>In the previous example, if the negative glob was `!node_modules/**/*.js`, the globbing library wouldn't optimize the negation and every match would have to be compared against the negative glob, which would be extremely slow. To ignore all files in a directory, only add the `/**` glob after the directory name.</small>
71-
7283
## Overlapping globs
7384

7485
Two or more globs that (un)intentionally match the same file are considered overlapping. When overlapping globs are used within a single `src()`, gulp does its best to remove the duplicates, but doesn't attempt to deduplicate across separate `src()` calls.
@@ -86,3 +97,4 @@ Most of what you'll need to work with globs in gulp is covered here. If you'd li
8697
[glob-primer-docs]: https://github.com/isaacs/node-glob#glob-primer
8798
[begin-globbing-docs]: https://github.com/begin/globbing#what-is-globbing
8899
[wikipedia-glob]: https://en.wikipedia.org/wiki/Glob_(programming)
100+
[ordered-read-streams-docs]: https://github.com/gulpjs/ordered-read-streams#orderedstreams-options

0 commit comments

Comments
 (0)