Skip to content

Commit

Permalink
Merge pull request #1207 from dart-lang/merge-io-package
Browse files Browse the repository at this point in the history
Merge `package:io`
  • Loading branch information
mosuem authored Dec 10, 2024
2 parents 223daf5 + ba87c44 commit faf2b86
Show file tree
Hide file tree
Showing 34 changed files with 2,198 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .github/ISSUE_TEMPLATE/io.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
name: "package:io"
about: "Create a bug or file a feature request against package:io."
labels: "package:io"
---
4 changes: 4 additions & 0 deletions .github/labeler.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@
- changed-files:
- any-glob-to-any-file: 'pkgs/html/**'

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

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

on:
# Run on PRs and pushes to the default branch.
push:
branches: [ main ]
paths:
- '.github/workflows/io.yml'
- 'pkgs/io/**'
pull_request:
branches: [ main ]
paths:
- '.github/workflows/io.yml'
- 'pkgs/io/**'
schedule:
- cron: "0 0 * * 0"

env:
PUB_ENVIRONMENT: bot.github


defaults:
run:
working-directory: pkgs/io/


jobs:
# Check code formatting and static analysis on a single OS (linux)
# against Dart dev and stable.
analyze:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
sdk: [dev, 3.4]
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
- uses: dart-lang/setup-dart@e630b99d28a3b71860378cafdc2a067c71107f94
with:
sdk: ${{ matrix.sdk }}
- id: install
name: Install dependencies
run: dart pub get
- name: Check formatting
run: dart format --output=none --set-exit-if-changed .
if: always() && steps.install.outcome == 'success'
- name: Analyze code
run: dart analyze --fatal-infos
if: always() && steps.install.outcome == 'success'

# Run tests on a matrix consisting of two dimensions:
# 1. OS: ubuntu-latest, (macos-latest, windows-latest)
# 2. release channel: dev, stable
test:
needs: analyze
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
# Add macos-latest and/or windows-latest if relevant for this package.
os: [ubuntu-latest]
sdk: [dev, 3.4]
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
- uses: dart-lang/setup-dart@e630b99d28a3b71860378cafdc2a067c71107f94
with:
sdk: ${{ matrix.sdk }}
- id: install
name: Install dependencies
run: dart pub get
- run: dart test
if: always() && steps.install.outcome == 'success'
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ don't naturally belong to other topic monorepos (like
| [file_testing](pkgs/file_testing/) | Testing utilities for package:file. | [![package issues](https://img.shields.io/badge/package:file_testing-4774bc)](https://github.com/dart-lang/tools/issues?q=is%3Aissue+is%3Aopen+label%3Apackage%3Afile_testing) | [![pub package](https://img.shields.io/pub/v/file_testing.svg)](https://pub.dev/packages/file_testing) |
| [graphs](pkgs/graphs/) | Graph algorithms that operate on graphs in any representation. | [![package issues](https://img.shields.io/badge/package:graphs-4774bc)](https://github.com/dart-lang/tools/issues?q=is%3Aissue+is%3Aopen+label%3Apackage%3Agraphs) | [![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. | [![package issues](https://img.shields.io/badge/package:html-4774bc)](https://github.com/dart-lang/tools/issues?q=is%3Aissue+is%3Aopen+label%3Apackage%3Ahtml) | [![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. | [![pub package](https://img.shields.io/pub/v/io.svg)](https://pub.dev/packages/io) |
| [json_rpc_2](pkgs/json_rpc_2/) | Utilities to write a client or server using the JSON-RPC 2.0 spec. | [![package issues](https://img.shields.io/badge/package:json_rpc_2-4774bc)](https://github.com/dart-lang/tools/issues?q=is%3Aissue+is%3Aopen+label%3Apackage%3Ajson_rpc_2) | [![pub package](https://img.shields.io/pub/v/json_rpc_2.svg)](https://pub.dev/packages/json_rpc_2) |
| [mime](pkgs/mime/) | Utilities for handling media (MIME) types, including determining a type from a file extension and file contents. | [![package issues](https://img.shields.io/badge/package:mime-4774bc)](https://github.com/dart-lang/tools/issues?q=is%3Aissue+is%3Aopen+label%3Apackage%3Amime) | [![pub package](https://img.shields.io/pub/v/mime.svg)](https://pub.dev/packages/mime) |
| [oauth2](pkgs/oauth2/) | A client library for authenticating with a remote service via OAuth2 on behalf of a user, and making authorized HTTP requests with the user's OAuth2 credentials. | [![package issues](https://img.shields.io/badge/package:oauth2-4774bc)](https://github.com/dart-lang/tools/issues?q=is%3Aissue+is%3Aopen+label%3Apackage%3Aoauth2) | [![pub package](https://img.shields.io/pub/v/oauth2.svg)](https://pub.dev/packages/oauth2) |
Expand Down
4 changes: 4 additions & 0 deletions pkgs/io/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.dart_tool/
.pub/
.packages
pubspec.lock
7 changes: 7 additions & 0 deletions pkgs/io/AUTHORS
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Below is a list of people and organizations that have contributed
# to the project. Names should be added to the list like so:
#
# Name/Organization <email address>

Google Inc.

119 changes: 119 additions & 0 deletions pkgs/io/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
## 1.0.5

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

## 1.0.4

* Updates to the readme.

## 1.0.3

* Revert `meta` constraint to `^1.3.0`.

## 1.0.2

* Update `meta` constraint to `>=1.3.0 <3.0.0`.

## 1.0.1

* Update code examples to call the unified `dart` developer tool.

## 1.0.0

* Migrate this package to null-safety.
* Require Dart >=2.12.

## 0.3.5

* Require Dart >=2.1.
* Remove dependency on `package:charcode`.

## 0.3.4

* Fix a number of issues affecting the package score on `pub.dev`.

## 0.3.3

* Updates for Dart 2 constants. Require at least Dart `2.0.0-dev.54`.

* Fix the type of `StartProcess` typedef to match `Process.start` from
`dart:io`.

## 0.3.2+1

* `ansi.dart`

* The "forScript" code paths now ignore the `ansiOutputEnabled` value. Affects
the `escapeForScript` property on `AnsiCode` and the `wrap` and `wrapWith`
functions when `forScript` is true.

## 0.3.2

* `ansi.dart`

* Added `forScript` named argument to top-level `wrapWith` function.

* `AnsiCode`

* Added `String get escapeForScript` property.

* Added `forScript` named argument to `wrap` function.

## 0.3.1

- Added `SharedStdIn.nextLine` (similar to `readLineSync`) and `lines`:

```dart
main() async {
// Prints the first line entered on stdin.
print(await sharedStdIn.nextLine());
// Prints all remaining lines.
await for (final line in sharedStdIn.lines) {
print(line);
}
}
```

- Added a `copyPath` and `copyPathSync` function, similar to `cp -R`.

- Added a dependency on `package:path`.

- Added the remaining missing arguments to `ProcessManager.spawnX` which
forward to `Process.start`. It is now an interchangeable function for running
a process.

## 0.3.0

- **BREAKING CHANGE**: The `arguments` argument to `ProcessManager.spawn` is
now positional (not named) and required. This makes it more similar to the
built-in `Process.start`, and easier to use as a drop in replacement:

```dart
main() {
processManager.spawn('dart', ['--version']);
}
```

- Fixed a bug where processes created from `ProcessManager.spawn` could not
have their `stdout`/`stderr` read through their respective getters (a runtime
error was always thrown).

- Added `ProcessMangaer#spawnBackground`, which does not forward `stdin`.

- Added `ProcessManager#spawnDetached`, which does not forward any I/O.

- Added the `shellSplit()` function, which parses a list of arguments in the
same manner as [the POSIX shell][what_is_posix_shell].

[what_is_posix_shell]: https://pubs.opengroup.org/onlinepubs/9699919799/utilities/contents.html

## 0.2.0

- Initial commit of...
- `FutureOr<bool> String isExecutable(path)`.
- `ExitCode`
- `ProcessManager` and `Spawn`
- `sharedStdIn` and `SharedStdIn`
- `ansi.dart` library with support for formatting terminal output
27 changes: 27 additions & 0 deletions pkgs/io/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
Copyright 2017, 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.
104 changes: 104 additions & 0 deletions pkgs/io/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
[![Build Status](https://github.com/dart-lang/tools/actions/workflows/io.yaml/badge.svg)](https://github.com/dart-lang/tools/actions/workflows/io.yaml)
[![pub package](https://img.shields.io/pub/v/io.svg)](https://pub.dev/packages/io)
[![package publisher](https://img.shields.io/pub/publisher/io.svg)](https://pub.dev/packages/io/publisher)

Contains utilities for the Dart VM's `dart:io`.

## Usage - `io.dart`

### Files

#### `isExecutable`

Returns whether a provided file path is considered _executable_ on the host
operating system.

### Processes

#### `ExitCode`

An `enum`-like class that contains known exit codes.

#### `ProcessManager`

A higher-level service for spawning and communicating with processes.

##### Use `spawn` to create a process with std[in|out|err] forwarded by default

```dart
Future<void> main() async {
final manager = ProcessManager();
// Print `dart` tool version to stdout.
print('** Running `dart --version`');
var spawn = await manager.spawn('dart', ['--version']);
await spawn.exitCode;
// Check formatting and print the result to stdout.
print('** Running `dart format --output=none .`');
spawn = await manager.spawn('dart', ['format', '--output=none', '.']);
await spawn.exitCode;
// Check if a package is ready for publishing.
// Upon hitting a blocking stdin state, you may directly
// output to the processes's stdin via your own, similar to how a bash or
// shell script would spawn a process.
print('** Running pub publish');
spawn = await manager.spawn('dart', ['pub', 'publish', '--dry-run']);
await spawn.exitCode;
// Closes stdin for the entire program.
await sharedStdIn.terminate();
}
```

#### `sharedStdIn`

A safer version of the default `stdin` stream from `dart:io` that allows a
subscriber to cancel their subscription, and then allows a _new_ subscriber to
start listening. This differs from the default behavior where only a single
listener is ever allowed in the application lifecycle:

```dart
test('should allow multiple subscribers', () async {
final logs = <String>[];
final asUtf8 = sharedStdIn.transform(UTF8.decoder);
// Wait for input for the user.
logs.add(await asUtf8.first);
// Wait for more input for the user.
logs.add(await asUtf8.first);
expect(logs, ['Hello World', 'Goodbye World']);
});
```

For testing, an instance of `SharedStdIn` may be created directly.

## Usage - `ansi.dart`

```dart
import 'dart:io' as io;
import 'package:io/ansi.dart';
void main() {
// To use one style, call the `wrap` method on one of the provided top-level
// values.
io.stderr.writeln(red.wrap("Bad error!"));
// To use multiple styles, call `wrapWith`.
print(wrapWith('** Important **', [red, styleBold, styleUnderlined]));
// The wrap functions will simply return the provided value unchanged if
// `ansiOutputEnabled` is false.
//
// You can override the value `ansiOutputEnabled` by wrapping code in
// `overrideAnsiOutput`.
overrideAnsiOutput(false, () {
assert('Normal text' == green.wrap('Normal text'));
});
}
```

## Publishing automation

For information about our publishing automation and release process, see
https://github.com/dart-lang/ecosystem/wiki/Publishing-automation.
32 changes: 32 additions & 0 deletions pkgs/io/analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# https://dart.dev/guides/language/analysis-options
include: package:dart_flutter_team_lints/analysis_options.yaml

analyzer:
language:
strict-casts: true
strict-inference: true
strict-raw-types: true

linter:
rules:
- avoid_bool_literals_in_conditional_expressions
- avoid_classes_with_only_static_members
- avoid_private_typedef_functions
- avoid_redundant_argument_values
- avoid_returning_this
- avoid_unused_constructor_parameters
- avoid_void_async
- cancel_subscriptions
- join_return_with_assignment
- literal_only_boolean_expressions
- missing_whitespace_between_adjacent_strings
- no_adjacent_strings_in_list
- no_runtimeType_toString
- prefer_const_declarations
- prefer_expression_function_bodies
- prefer_final_locals
- unnecessary_await_in_return
- unnecessary_breaks
- use_if_null_to_convert_nulls_to_bools
- use_raw_strings
- use_string_buffers
Loading

0 comments on commit faf2b86

Please sign in to comment.