Skip to content

Commit

Permalink
Merge glob package (#1974)
Browse files Browse the repository at this point in the history
  • Loading branch information
devoncarew authored Jan 23, 2025
2 parents ce30034 + cc43df8 commit 92114ab
Show file tree
Hide file tree
Showing 23 changed files with 2,785 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .github/ISSUE_TEMPLATE/glob.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
name: "package:glob"
about: "Create a bug or file a feature request against package:glob."
labels: "package:glob"
---
3 changes: 2 additions & 1 deletion .github/ISSUE_TEMPLATE/unified_analytics_event.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
name: "package:unified_analytics - request a new event"
description: "Create a request for collecting a new event or new event data."
labels: "package:unified_analytics"
labels:
- "package:unified_analytics"
body:
- type: markdown
attributes:
Expand Down
3 changes: 2 additions & 1 deletion .github/ISSUE_TEMPLATE/unified_analytics_user_property.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
name: "package:unified_analytics - request a new user property"
description: "Create a request for collecting a new user property."
labels: "package:unified_analytics"
labels:
- "package:unified_analytics"
body:
- type: markdown
attributes:
Expand Down
4 changes: 4 additions & 0 deletions .github/labeler.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@
- changed-files:
- any-glob-to-any-file: 'pkgs/file_testing/**'

'package:glob':
- changed-files:
- any-glob-to-any-file: 'pkgs/glob/**'

'package:graphs':
- changed-files:
- any-glob-to-any-file: 'pkgs/graphs/**'
Expand Down
39 changes: 39 additions & 0 deletions .github/workflows/glob.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: package:glob

permissions: read-all

on:
# Run CI on all PRs (against any branch) and on pushes to the main branch.
pull_request:
paths:
- '.github/workflows/glob.yaml'
- 'pkgs/glob/**'
push:
branches: [ main ]
paths:
- '.github/workflows/glob.yaml'
- 'pkgs/glob/**'
schedule:
- cron: '0 0 * * 0' # weekly

defaults:
run:
working-directory: pkgs/glob

jobs:
build:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
sdk: [stable, dev]
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
- uses: dart-lang/setup-dart@e630b99d28a3b71860378cafdc2a067c71107f94
with:
sdk: ${{ matrix.sdk }}
- run: dart pub get
- run: dart analyze --fatal-infos
- run: dart format --output=none --set-exit-if-changed .
if: ${{ matrix.sdk == 'stable' }}
- run: dart test
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ don't naturally belong to other topic monorepos (like
| [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) |
| [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) |
| [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) |
| [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) |
| [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) |
| [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) |
| [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) |
Expand Down Expand Up @@ -67,6 +68,7 @@ don't naturally belong to other topic monorepos (like
[extension_discovery_issues]: https://github.com/dart-lang/tools/issues?q=is%3Aissue+is%3Aopen+label%3Apackage%3Aextension_discovery
[file_issues]: https://github.com/dart-lang/tools/issues?q=is%3Aissue+is%3Aopen+label%3Apackage%3Afile
[file_testing_issues]: https://github.com/dart-lang/tools/issues?q=is%3Aissue+is%3Aopen+label%3Apackage%3Afile_testing
[glob_issues]: https://github.com/dart-lang/tools/issues?q=is%3Aissue+is%3Aopen+label%3Apackage%3Aglob
[graphs_issues]: https://github.com/dart-lang/tools/issues?q=is%3Aissue+is%3Aopen+label%3Apackage%3Agraphs
[html_issues]: https://github.com/dart-lang/tools/issues?q=is%3Aissue+is%3Aopen+label%3Apackage%3Ahtml
[io_issues]: https://github.com/dart-lang/tools/issues?q=is%3Aissue+is%3Aopen+label%3Apackage%3Aio
Expand Down
16 changes: 16 additions & 0 deletions pkgs/glob/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Don’t commit the following directories created by pub.
.buildlog
.dart_tool/
.pub/
build/
packages
.packages

# Or the files created by dart2js.
*.dart.js
*.js_
*.js.deps
*.js.map

# Include when developing application packages.
pubspec.lock
115 changes: 115 additions & 0 deletions pkgs/glob/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
## 2.1.3

- Require Dart 3.3.
- Move to `dart-lang/tools` monorepo.

## 2.1.2

- Allow `file` version `7.x`.
- Require Dart 2.19.

## 2.1.1

- Updated the dependency on `package:file` to require at least `6.1.3`.

## 2.1.0

- Return empty results instead of throwing when trying to list a path that does
not exist.

## 2.0.2

- Drop package:pedantic dependency, use package:lints instead.
- Update SDK lower bound to `2.15.0`

## 2.0.1

- Update example in README for new import.

## 2.0.0

- Stable null safety release.

### Breaking Change

The `list*` apis on `Glob` have been renamed to `listFileSystem*` and they now
require a `FileSystem` object from `package:file`.

There is a new convenience import, `package:glob/list_local_fs.dart` which
provides the old methods as extensions, and automatically passes a
`LocalFileSystem`.

## 1.2.1

- Add an empty list_local_fs.dart to ease upgrade from 1x to 2x

## 1.2.0

- Support running on Node.js.

## 1.1.7

- Set max SDK version to `<3.0.0`, and adjust other dependencies.

## 1.1.6

- Improve support for Dart 2 runtime semantics.

## 1.1.5

- Declare support for `async` 2.0.0.

- Require Dart 1.23.0.

## 1.1.4

- Throw an exception when listing globs whose initial paths don't exist in
case-insensitive mode. This matches the case-sensitive behavior.

## 1.1.3

- Support `string_scanner` 1.0.0.

## 1.1.2

- Fix all strong mode errors and warnings.

## 1.1.1

- Fix a bug where listing an absolute glob with `caseInsensitive: false` failed.

## 1.1.0

- Add a `caseSensitive` named parameter to `new Glob()` that controls whether
the glob is case-sensitive. This defaults to `false` on Windows and `true`
elsewhere.

Matching case-insensitively on Windows is a behavioral change, but since it
more closely matches the semantics of Windows paths it's considered a bug fix
rather than a breaking change.

## 1.0.5

- Narrow the dependency on `path`. Previously, this allowed versions that didn't
support all the functionality this package needs.

- Upgrade to the new test runner.

## 1.0.4

- Added overlooked `collection` dependency.

## 1.0.3

- Fix a bug where `Glob.list()` and `Glob.listSync()` would incorrectly throw
exceptions when a directory didn't exist on the filesystem.

## 1.0.2

- Fixed `Glob.list()` on Windows.

## 1.0.1

- Fix several analyzer warnings.

- Fix the tests on Windows.
27 changes: 27 additions & 0 deletions pkgs/glob/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
Copyright 2014, the Dart project authors.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:

* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following
disclaimer in the documentation and/or other materials provided
with the distribution.
* Neither the name of Google LLC nor the names of its
contributors may be used to endorse or promote products derived
from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
132 changes: 132 additions & 0 deletions pkgs/glob/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
[![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)
[![pub package](https://img.shields.io/pub/v/glob.svg)](https://pub.dev/packages/glob)
[![package publisher](https://img.shields.io/pub/publisher/glob.svg)](https://pub.dev/packages/glob/publisher)

`glob` is a file and directory globbing library that supports both checking
whether a path matches a glob and listing all entities that match a glob.

A "glob" is a pattern designed specifically to match files and directories. Most
shells support globs natively.

## Usage

To construct a glob, just use `Glob()`. As with `RegExp`s, it's a good idea to
keep around a glob if you'll be using it more than once so that it doesn't have
to be compiled over and over. You can check whether a path matches the glob
using `Glob.matches()`:

```dart
import 'package:glob/glob.dart';
final dartFile = Glob("**.dart");
// Print all command-line arguments that are Dart files.
void main(List<String> arguments) {
for (var argument in arguments) {
if (dartFile.matches(argument)) print(argument);
}
}
```

You can also list all files that match a glob using `Glob.list()` or
`Glob.listSync()`:

```dart
import 'package:glob/glob.dart';
import 'package:glob/list_local_fs.dart';
final dartFile = Glob("**.dart");
// Recursively list all Dart files in the current directory.
void main(List<String> arguments) {
for (var entity in dartFile.listSync()) {
print(entity.path);
}
}
```

## Syntax

The glob syntax hews closely to the widely-known Bash glob syntax, with a few
exceptions that are outlined below.

In order to be as cross-platform and as close to the Bash syntax as possible,
all globs use POSIX path syntax, including using `/` as a directory separator
regardless of which platform they're on. This is true even for Windows roots;
for example, a glob matching all files in the C drive would be `C:/*`.

Globs are case-sensitive by default on Posix systems and browsers, and
case-insensitive by default on Windows.

### Match any characters in a filename: `*`

The `*` character matches zero or more of any character other than `/`. This
means that it can be used to match all files in a given directory that match a
pattern without also matching files in a subdirectory. For example, `lib/*.dart`
will match `lib/glob.dart` but not `lib/src/utils.dart`.

### Match any characters across directories: `**`

`**` is like `*`, but matches `/` as well. It's useful for matching files or
listing directories recursively. For example, `lib/**.dart` will match both
`lib/glob.dart` and `lib/src/utils.dart`.

If `**` appears at the beginning of a glob, it won't match absolute paths or
paths beginning with `../`. For example, `**.dart` won't match `/foo.dart`,
although `/**.dart` will. This is to ensure that listing a bunch of paths and
checking whether they match a glob produces the same results as listing that
glob. In the previous example, `/foo.dart` wouldn't be listed for `**.dart`, so
it shouldn't be matched by it either.

This is an extension to Bash glob syntax that's widely supported by other glob
implementations.

### Match any single character: `?`

The `?` character matches a single character other than `/`. Unlike `*`, it
won't match any more or fewer than one character. For example, `test?.dart` will
match `test1.dart` but not `test10.dart` or `test.dart`.

### Match a range of characters: `[...]`

The `[...]` construction matches one of several characters. It can contain
individual characters, such as `[abc]`, in which case it will match any of those
characters; it can contain ranges, such as `[a-zA-Z]`, in which case it will
match any characters that fall within the range; or it can contain a mix of
both. It will only ever match a single character. For example,
`test[a-zA-Z_].dart` will match `testx.dart`, `testA.dart`, and `test_.dart`,
but not `test-.dart`.

If it starts with `^` or `!`, the construction will instead match all characters
_not_ mentioned. For example, `test[^a-z].dart` will match `test1.dart` but not
`testa.dart`.

This construction never matches `/`.

### Match one of several possibilities: `{...,...}`

The `{...,...}` construction matches one of several options, each of which is a
glob itself. For example, `lib/{*.dart,src/*}` matches `lib/glob.dart` and
`lib/src/data.txt`. It can contain any number of options greater than one, and
can even contain nested options.

This is an extension to Bash glob syntax, although it is supported by other
layers of Bash and is often used in conjunction with globs.

### Escaping a character: `\`

The `\` character can be used in any context to escape a character that would
otherwise be semantically meaningful. For example, `\*.dart` matches `*.dart`
but not `test.dart`.

### Syntax errors

Because they're used as part of the shell, almost all strings are valid Bash
globs. This implementation is more picky, and performs some validation to ensure
that globs are meaningful. For instance, unclosed `{` and `[` are disallowed.

### Reserved syntax: `(...)`

Parentheses are reserved in case this package adds support for Bash extended
globbing in the future. For the time being, using them will throw an error
unless they're escaped.
10 changes: 10 additions & 0 deletions pkgs/glob/analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
include: package:dart_flutter_team_lints/analysis_options.yaml

analyzer:
language:
strict-casts: true

linter:
rules:
- avoid_unused_constructor_parameters
- cancel_subscriptions
Loading

0 comments on commit 92114ab

Please sign in to comment.