Skip to content

Commit 92114ab

Browse files
authored
Merge glob package (#1974)
2 parents ce30034 + cc43df8 commit 92114ab

23 files changed

+2785
-2
lines changed

.github/ISSUE_TEMPLATE/glob.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
name: "package:glob"
3+
about: "Create a bug or file a feature request against package:glob."
4+
labels: "package:glob"
5+
---

.github/ISSUE_TEMPLATE/unified_analytics_event.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
name: "package:unified_analytics - request a new event"
22
description: "Create a request for collecting a new event or new event data."
3-
labels: "package:unified_analytics"
3+
labels:
4+
- "package:unified_analytics"
45
body:
56
- type: markdown
67
attributes:

.github/ISSUE_TEMPLATE/unified_analytics_user_property.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
name: "package:unified_analytics - request a new user property"
22
description: "Create a request for collecting a new user property."
3-
labels: "package:unified_analytics"
3+
labels:
4+
- "package:unified_analytics"
45
body:
56
- type: markdown
67
attributes:

.github/labeler.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,10 @@
5656
- changed-files:
5757
- any-glob-to-any-file: 'pkgs/file_testing/**'
5858

59+
'package:glob':
60+
- changed-files:
61+
- any-glob-to-any-file: 'pkgs/glob/**'
62+
5963
'package:graphs':
6064
- changed-files:
6165
- any-glob-to-any-file: 'pkgs/graphs/**'

.github/workflows/glob.yaml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
name: package:glob
2+
3+
permissions: read-all
4+
5+
on:
6+
# Run CI on all PRs (against any branch) and on pushes to the main branch.
7+
pull_request:
8+
paths:
9+
- '.github/workflows/glob.yaml'
10+
- 'pkgs/glob/**'
11+
push:
12+
branches: [ main ]
13+
paths:
14+
- '.github/workflows/glob.yaml'
15+
- 'pkgs/glob/**'
16+
schedule:
17+
- cron: '0 0 * * 0' # weekly
18+
19+
defaults:
20+
run:
21+
working-directory: pkgs/glob
22+
23+
jobs:
24+
build:
25+
runs-on: ubuntu-latest
26+
strategy:
27+
fail-fast: false
28+
matrix:
29+
sdk: [stable, dev]
30+
steps:
31+
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
32+
- uses: dart-lang/setup-dart@e630b99d28a3b71860378cafdc2a067c71107f94
33+
with:
34+
sdk: ${{ matrix.sdk }}
35+
- run: dart pub get
36+
- run: dart analyze --fatal-infos
37+
- run: dart format --output=none --set-exit-if-changed .
38+
if: ${{ matrix.sdk == 'stable' }}
39+
- run: dart test

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ don't naturally belong to other topic monorepos (like
2727
| [extension_discovery](pkgs/extension_discovery/) | A convention and utilities for package extension discovery. | [![issues](https://img.shields.io/badge/issues-4774bc)][extension_discovery_issues] | [![pub package](https://img.shields.io/pub/v/extension_discovery.svg)](https://pub.dev/packages/extension_discovery) |
2828
| [file](pkgs/file/) | A pluggable, mockable file system abstraction for Dart. | [![issues](https://img.shields.io/badge/issues-4774bc)][file_issues] | [![pub package](https://img.shields.io/pub/v/file.svg)](https://pub.dev/packages/file) |
2929
| [file_testing](pkgs/file_testing/) | Testing utilities for package:file. | [![issues](https://img.shields.io/badge/issues-4774bc)][file_testing_issues] | [![pub package](https://img.shields.io/pub/v/file_testing.svg)](https://pub.dev/packages/file_testing) |
30+
| [glob](pkgs/glob/) | A library to perform Bash-style file and directory globbing. | [![issues](https://img.shields.io/badge/issues-4774bc)][glob_issues] | [![pub package](https://img.shields.io/pub/v/glob.svg)](https://pub.dev/packages/glob) |
3031
| [graphs](pkgs/graphs/) | Graph algorithms that operate on graphs in any representation. | [![issues](https://img.shields.io/badge/issues-4774bc)][graphs_issues] | [![pub package](https://img.shields.io/pub/v/graphs.svg)](https://pub.dev/packages/graphs) |
3132
| [html](pkgs/html/) | APIs for parsing and manipulating HTML content outside the browser. | [![issues](https://img.shields.io/badge/issues-4774bc)][html_issues] | [![pub package](https://img.shields.io/pub/v/html.svg)](https://pub.dev/packages/html) |
3233
| [io](pkgs/io/) | Utilities for the Dart VM Runtime including support for ANSI colors, file copying, and standard exit code values. | [![issues](https://img.shields.io/badge/issues-4774bc)][io_issues] | [![pub package](https://img.shields.io/pub/v/io.svg)](https://pub.dev/packages/io) |
@@ -67,6 +68,7 @@ don't naturally belong to other topic monorepos (like
6768
[extension_discovery_issues]: https://github.com/dart-lang/tools/issues?q=is%3Aissue+is%3Aopen+label%3Apackage%3Aextension_discovery
6869
[file_issues]: https://github.com/dart-lang/tools/issues?q=is%3Aissue+is%3Aopen+label%3Apackage%3Afile
6970
[file_testing_issues]: https://github.com/dart-lang/tools/issues?q=is%3Aissue+is%3Aopen+label%3Apackage%3Afile_testing
71+
[glob_issues]: https://github.com/dart-lang/tools/issues?q=is%3Aissue+is%3Aopen+label%3Apackage%3Aglob
7072
[graphs_issues]: https://github.com/dart-lang/tools/issues?q=is%3Aissue+is%3Aopen+label%3Apackage%3Agraphs
7173
[html_issues]: https://github.com/dart-lang/tools/issues?q=is%3Aissue+is%3Aopen+label%3Apackage%3Ahtml
7274
[io_issues]: https://github.com/dart-lang/tools/issues?q=is%3Aissue+is%3Aopen+label%3Apackage%3Aio

pkgs/glob/.gitignore

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Don’t commit the following directories created by pub.
2+
.buildlog
3+
.dart_tool/
4+
.pub/
5+
build/
6+
packages
7+
.packages
8+
9+
# Or the files created by dart2js.
10+
*.dart.js
11+
*.js_
12+
*.js.deps
13+
*.js.map
14+
15+
# Include when developing application packages.
16+
pubspec.lock

pkgs/glob/CHANGELOG.md

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
## 2.1.3
2+
3+
- Require Dart 3.3.
4+
- Move to `dart-lang/tools` monorepo.
5+
6+
## 2.1.2
7+
8+
- Allow `file` version `7.x`.
9+
- Require Dart 2.19.
10+
11+
## 2.1.1
12+
13+
- Updated the dependency on `package:file` to require at least `6.1.3`.
14+
15+
## 2.1.0
16+
17+
- Return empty results instead of throwing when trying to list a path that does
18+
not exist.
19+
20+
## 2.0.2
21+
22+
- Drop package:pedantic dependency, use package:lints instead.
23+
- Update SDK lower bound to `2.15.0`
24+
25+
## 2.0.1
26+
27+
- Update example in README for new import.
28+
29+
## 2.0.0
30+
31+
- Stable null safety release.
32+
33+
### Breaking Change
34+
35+
The `list*` apis on `Glob` have been renamed to `listFileSystem*` and they now
36+
require a `FileSystem` object from `package:file`.
37+
38+
There is a new convenience import, `package:glob/list_local_fs.dart` which
39+
provides the old methods as extensions, and automatically passes a
40+
`LocalFileSystem`.
41+
42+
## 1.2.1
43+
44+
- Add an empty list_local_fs.dart to ease upgrade from 1x to 2x
45+
46+
## 1.2.0
47+
48+
- Support running on Node.js.
49+
50+
## 1.1.7
51+
52+
- Set max SDK version to `<3.0.0`, and adjust other dependencies.
53+
54+
## 1.1.6
55+
56+
- Improve support for Dart 2 runtime semantics.
57+
58+
## 1.1.5
59+
60+
- Declare support for `async` 2.0.0.
61+
62+
- Require Dart 1.23.0.
63+
64+
## 1.1.4
65+
66+
- Throw an exception when listing globs whose initial paths don't exist in
67+
case-insensitive mode. This matches the case-sensitive behavior.
68+
69+
## 1.1.3
70+
71+
- Support `string_scanner` 1.0.0.
72+
73+
## 1.1.2
74+
75+
- Fix all strong mode errors and warnings.
76+
77+
## 1.1.1
78+
79+
- Fix a bug where listing an absolute glob with `caseInsensitive: false` failed.
80+
81+
## 1.1.0
82+
83+
- Add a `caseSensitive` named parameter to `new Glob()` that controls whether
84+
the glob is case-sensitive. This defaults to `false` on Windows and `true`
85+
elsewhere.
86+
87+
Matching case-insensitively on Windows is a behavioral change, but since it
88+
more closely matches the semantics of Windows paths it's considered a bug fix
89+
rather than a breaking change.
90+
91+
## 1.0.5
92+
93+
- Narrow the dependency on `path`. Previously, this allowed versions that didn't
94+
support all the functionality this package needs.
95+
96+
- Upgrade to the new test runner.
97+
98+
## 1.0.4
99+
100+
- Added overlooked `collection` dependency.
101+
102+
## 1.0.3
103+
104+
- Fix a bug where `Glob.list()` and `Glob.listSync()` would incorrectly throw
105+
exceptions when a directory didn't exist on the filesystem.
106+
107+
## 1.0.2
108+
109+
- Fixed `Glob.list()` on Windows.
110+
111+
## 1.0.1
112+
113+
- Fix several analyzer warnings.
114+
115+
- Fix the tests on Windows.

pkgs/glob/LICENSE

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
Copyright 2014, the Dart project authors.
2+
3+
Redistribution and use in source and binary forms, with or without
4+
modification, are permitted provided that the following conditions are
5+
met:
6+
7+
* Redistributions of source code must retain the above copyright
8+
notice, this list of conditions and the following disclaimer.
9+
* Redistributions in binary form must reproduce the above
10+
copyright notice, this list of conditions and the following
11+
disclaimer in the documentation and/or other materials provided
12+
with the distribution.
13+
* Neither the name of Google LLC nor the names of its
14+
contributors may be used to endorse or promote products derived
15+
from this software without specific prior written permission.
16+
17+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18+
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19+
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20+
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21+
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22+
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23+
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24+
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25+
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

pkgs/glob/README.md

Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
[![Dart CI](https://github.com/dart-lang/glob/actions/workflows/test-package.yml/badge.svg)](https://github.com/dart-lang/glob/actions/workflows/test-package.yml)
2+
[![pub package](https://img.shields.io/pub/v/glob.svg)](https://pub.dev/packages/glob)
3+
[![package publisher](https://img.shields.io/pub/publisher/glob.svg)](https://pub.dev/packages/glob/publisher)
4+
5+
`glob` is a file and directory globbing library that supports both checking
6+
whether a path matches a glob and listing all entities that match a glob.
7+
8+
A "glob" is a pattern designed specifically to match files and directories. Most
9+
shells support globs natively.
10+
11+
## Usage
12+
13+
To construct a glob, just use `Glob()`. As with `RegExp`s, it's a good idea to
14+
keep around a glob if you'll be using it more than once so that it doesn't have
15+
to be compiled over and over. You can check whether a path matches the glob
16+
using `Glob.matches()`:
17+
18+
```dart
19+
import 'package:glob/glob.dart';
20+
21+
final dartFile = Glob("**.dart");
22+
23+
// Print all command-line arguments that are Dart files.
24+
void main(List<String> arguments) {
25+
for (var argument in arguments) {
26+
if (dartFile.matches(argument)) print(argument);
27+
}
28+
}
29+
```
30+
31+
You can also list all files that match a glob using `Glob.list()` or
32+
`Glob.listSync()`:
33+
34+
```dart
35+
import 'package:glob/glob.dart';
36+
import 'package:glob/list_local_fs.dart';
37+
38+
final dartFile = Glob("**.dart");
39+
40+
// Recursively list all Dart files in the current directory.
41+
void main(List<String> arguments) {
42+
for (var entity in dartFile.listSync()) {
43+
print(entity.path);
44+
}
45+
}
46+
```
47+
48+
## Syntax
49+
50+
The glob syntax hews closely to the widely-known Bash glob syntax, with a few
51+
exceptions that are outlined below.
52+
53+
In order to be as cross-platform and as close to the Bash syntax as possible,
54+
all globs use POSIX path syntax, including using `/` as a directory separator
55+
regardless of which platform they're on. This is true even for Windows roots;
56+
for example, a glob matching all files in the C drive would be `C:/*`.
57+
58+
Globs are case-sensitive by default on Posix systems and browsers, and
59+
case-insensitive by default on Windows.
60+
61+
### Match any characters in a filename: `*`
62+
63+
The `*` character matches zero or more of any character other than `/`. This
64+
means that it can be used to match all files in a given directory that match a
65+
pattern without also matching files in a subdirectory. For example, `lib/*.dart`
66+
will match `lib/glob.dart` but not `lib/src/utils.dart`.
67+
68+
### Match any characters across directories: `**`
69+
70+
`**` is like `*`, but matches `/` as well. It's useful for matching files or
71+
listing directories recursively. For example, `lib/**.dart` will match both
72+
`lib/glob.dart` and `lib/src/utils.dart`.
73+
74+
If `**` appears at the beginning of a glob, it won't match absolute paths or
75+
paths beginning with `../`. For example, `**.dart` won't match `/foo.dart`,
76+
although `/**.dart` will. This is to ensure that listing a bunch of paths and
77+
checking whether they match a glob produces the same results as listing that
78+
glob. In the previous example, `/foo.dart` wouldn't be listed for `**.dart`, so
79+
it shouldn't be matched by it either.
80+
81+
This is an extension to Bash glob syntax that's widely supported by other glob
82+
implementations.
83+
84+
### Match any single character: `?`
85+
86+
The `?` character matches a single character other than `/`. Unlike `*`, it
87+
won't match any more or fewer than one character. For example, `test?.dart` will
88+
match `test1.dart` but not `test10.dart` or `test.dart`.
89+
90+
### Match a range of characters: `[...]`
91+
92+
The `[...]` construction matches one of several characters. It can contain
93+
individual characters, such as `[abc]`, in which case it will match any of those
94+
characters; it can contain ranges, such as `[a-zA-Z]`, in which case it will
95+
match any characters that fall within the range; or it can contain a mix of
96+
both. It will only ever match a single character. For example,
97+
`test[a-zA-Z_].dart` will match `testx.dart`, `testA.dart`, and `test_.dart`,
98+
but not `test-.dart`.
99+
100+
If it starts with `^` or `!`, the construction will instead match all characters
101+
_not_ mentioned. For example, `test[^a-z].dart` will match `test1.dart` but not
102+
`testa.dart`.
103+
104+
This construction never matches `/`.
105+
106+
### Match one of several possibilities: `{...,...}`
107+
108+
The `{...,...}` construction matches one of several options, each of which is a
109+
glob itself. For example, `lib/{*.dart,src/*}` matches `lib/glob.dart` and
110+
`lib/src/data.txt`. It can contain any number of options greater than one, and
111+
can even contain nested options.
112+
113+
This is an extension to Bash glob syntax, although it is supported by other
114+
layers of Bash and is often used in conjunction with globs.
115+
116+
### Escaping a character: `\`
117+
118+
The `\` character can be used in any context to escape a character that would
119+
otherwise be semantically meaningful. For example, `\*.dart` matches `*.dart`
120+
but not `test.dart`.
121+
122+
### Syntax errors
123+
124+
Because they're used as part of the shell, almost all strings are valid Bash
125+
globs. This implementation is more picky, and performs some validation to ensure
126+
that globs are meaningful. For instance, unclosed `{` and `[` are disallowed.
127+
128+
### Reserved syntax: `(...)`
129+
130+
Parentheses are reserved in case this package adds support for Bash extended
131+
globbing in the future. For the time being, using them will throw an error
132+
unless they're escaped.

0 commit comments

Comments
 (0)