Skip to content

Commit faf2b86

Browse files
authored
Merge pull request #1207 from dart-lang/merge-io-package
Merge `package:io`
2 parents 223daf5 + ba87c44 commit faf2b86

34 files changed

+2198
-0
lines changed

.github/ISSUE_TEMPLATE/io.md

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

.github/labeler.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,10 @@
6464
- changed-files:
6565
- any-glob-to-any-file: 'pkgs/html/**'
6666

67+
'package:io':
68+
- changed-files:
69+
- any-glob-to-any-file: 'pkgs/io/**'
70+
6771
'package:json_rpc_2':
6872
- changed-files:
6973
- any-glob-to-any-file: 'pkgs/json_rpc_2/**'

.github/workflows/io.yaml

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
name: package:io
2+
3+
on:
4+
# Run on PRs and pushes to the default branch.
5+
push:
6+
branches: [ main ]
7+
paths:
8+
- '.github/workflows/io.yml'
9+
- 'pkgs/io/**'
10+
pull_request:
11+
branches: [ main ]
12+
paths:
13+
- '.github/workflows/io.yml'
14+
- 'pkgs/io/**'
15+
schedule:
16+
- cron: "0 0 * * 0"
17+
18+
env:
19+
PUB_ENVIRONMENT: bot.github
20+
21+
22+
defaults:
23+
run:
24+
working-directory: pkgs/io/
25+
26+
27+
jobs:
28+
# Check code formatting and static analysis on a single OS (linux)
29+
# against Dart dev and stable.
30+
analyze:
31+
runs-on: ubuntu-latest
32+
strategy:
33+
fail-fast: false
34+
matrix:
35+
sdk: [dev, 3.4]
36+
steps:
37+
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
38+
- uses: dart-lang/setup-dart@e630b99d28a3b71860378cafdc2a067c71107f94
39+
with:
40+
sdk: ${{ matrix.sdk }}
41+
- id: install
42+
name: Install dependencies
43+
run: dart pub get
44+
- name: Check formatting
45+
run: dart format --output=none --set-exit-if-changed .
46+
if: always() && steps.install.outcome == 'success'
47+
- name: Analyze code
48+
run: dart analyze --fatal-infos
49+
if: always() && steps.install.outcome == 'success'
50+
51+
# Run tests on a matrix consisting of two dimensions:
52+
# 1. OS: ubuntu-latest, (macos-latest, windows-latest)
53+
# 2. release channel: dev, stable
54+
test:
55+
needs: analyze
56+
runs-on: ${{ matrix.os }}
57+
strategy:
58+
fail-fast: false
59+
matrix:
60+
# Add macos-latest and/or windows-latest if relevant for this package.
61+
os: [ubuntu-latest]
62+
sdk: [dev, 3.4]
63+
steps:
64+
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
65+
- uses: dart-lang/setup-dart@e630b99d28a3b71860378cafdc2a067c71107f94
66+
with:
67+
sdk: ${{ matrix.sdk }}
68+
- id: install
69+
name: Install dependencies
70+
run: dart pub get
71+
- run: dart test
72+
if: always() && steps.install.outcome == 'success'

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ don't naturally belong to other topic monorepos (like
2929
| [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) |
3030
| [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) |
3131
| [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) |
32+
| [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) |
3233
| [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) |
3334
| [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) |
3435
| [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) |

pkgs/io/.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
.dart_tool/
2+
.pub/
3+
.packages
4+
pubspec.lock

pkgs/io/AUTHORS

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Below is a list of people and organizations that have contributed
2+
# to the project. Names should be added to the list like so:
3+
#
4+
# Name/Organization <email address>
5+
6+
Google Inc.
7+

pkgs/io/CHANGELOG.md

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
## 1.0.5
2+
3+
* Require Dart 3.4.
4+
* Move to `dart-lang/tools` monorepo.
5+
6+
## 1.0.4
7+
8+
* Updates to the readme.
9+
10+
## 1.0.3
11+
12+
* Revert `meta` constraint to `^1.3.0`.
13+
14+
## 1.0.2
15+
16+
* Update `meta` constraint to `>=1.3.0 <3.0.0`.
17+
18+
## 1.0.1
19+
20+
* Update code examples to call the unified `dart` developer tool.
21+
22+
## 1.0.0
23+
24+
* Migrate this package to null-safety.
25+
* Require Dart >=2.12.
26+
27+
## 0.3.5
28+
29+
* Require Dart >=2.1.
30+
* Remove dependency on `package:charcode`.
31+
32+
## 0.3.4
33+
34+
* Fix a number of issues affecting the package score on `pub.dev`.
35+
36+
## 0.3.3
37+
38+
* Updates for Dart 2 constants. Require at least Dart `2.0.0-dev.54`.
39+
40+
* Fix the type of `StartProcess` typedef to match `Process.start` from
41+
`dart:io`.
42+
43+
## 0.3.2+1
44+
45+
* `ansi.dart`
46+
47+
* The "forScript" code paths now ignore the `ansiOutputEnabled` value. Affects
48+
the `escapeForScript` property on `AnsiCode` and the `wrap` and `wrapWith`
49+
functions when `forScript` is true.
50+
51+
## 0.3.2
52+
53+
* `ansi.dart`
54+
55+
* Added `forScript` named argument to top-level `wrapWith` function.
56+
57+
* `AnsiCode`
58+
59+
* Added `String get escapeForScript` property.
60+
61+
* Added `forScript` named argument to `wrap` function.
62+
63+
## 0.3.1
64+
65+
- Added `SharedStdIn.nextLine` (similar to `readLineSync`) and `lines`:
66+
67+
```dart
68+
main() async {
69+
// Prints the first line entered on stdin.
70+
print(await sharedStdIn.nextLine());
71+
72+
// Prints all remaining lines.
73+
await for (final line in sharedStdIn.lines) {
74+
print(line);
75+
}
76+
}
77+
```
78+
79+
- Added a `copyPath` and `copyPathSync` function, similar to `cp -R`.
80+
81+
- Added a dependency on `package:path`.
82+
83+
- Added the remaining missing arguments to `ProcessManager.spawnX` which
84+
forward to `Process.start`. It is now an interchangeable function for running
85+
a process.
86+
87+
## 0.3.0
88+
89+
- **BREAKING CHANGE**: The `arguments` argument to `ProcessManager.spawn` is
90+
now positional (not named) and required. This makes it more similar to the
91+
built-in `Process.start`, and easier to use as a drop in replacement:
92+
93+
```dart
94+
main() {
95+
processManager.spawn('dart', ['--version']);
96+
}
97+
```
98+
99+
- Fixed a bug where processes created from `ProcessManager.spawn` could not
100+
have their `stdout`/`stderr` read through their respective getters (a runtime
101+
error was always thrown).
102+
103+
- Added `ProcessMangaer#spawnBackground`, which does not forward `stdin`.
104+
105+
- Added `ProcessManager#spawnDetached`, which does not forward any I/O.
106+
107+
- Added the `shellSplit()` function, which parses a list of arguments in the
108+
same manner as [the POSIX shell][what_is_posix_shell].
109+
110+
[what_is_posix_shell]: https://pubs.opengroup.org/onlinepubs/9699919799/utilities/contents.html
111+
112+
## 0.2.0
113+
114+
- Initial commit of...
115+
- `FutureOr<bool> String isExecutable(path)`.
116+
- `ExitCode`
117+
- `ProcessManager` and `Spawn`
118+
- `sharedStdIn` and `SharedStdIn`
119+
- `ansi.dart` library with support for formatting terminal output

pkgs/io/LICENSE

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
Copyright 2017, 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/io/README.md

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
[![Build Status](https://github.com/dart-lang/tools/actions/workflows/io.yaml/badge.svg)](https://github.com/dart-lang/tools/actions/workflows/io.yaml)
2+
[![pub package](https://img.shields.io/pub/v/io.svg)](https://pub.dev/packages/io)
3+
[![package publisher](https://img.shields.io/pub/publisher/io.svg)](https://pub.dev/packages/io/publisher)
4+
5+
Contains utilities for the Dart VM's `dart:io`.
6+
7+
## Usage - `io.dart`
8+
9+
### Files
10+
11+
#### `isExecutable`
12+
13+
Returns whether a provided file path is considered _executable_ on the host
14+
operating system.
15+
16+
### Processes
17+
18+
#### `ExitCode`
19+
20+
An `enum`-like class that contains known exit codes.
21+
22+
#### `ProcessManager`
23+
24+
A higher-level service for spawning and communicating with processes.
25+
26+
##### Use `spawn` to create a process with std[in|out|err] forwarded by default
27+
28+
```dart
29+
Future<void> main() async {
30+
final manager = ProcessManager();
31+
32+
// Print `dart` tool version to stdout.
33+
print('** Running `dart --version`');
34+
var spawn = await manager.spawn('dart', ['--version']);
35+
await spawn.exitCode;
36+
37+
// Check formatting and print the result to stdout.
38+
print('** Running `dart format --output=none .`');
39+
spawn = await manager.spawn('dart', ['format', '--output=none', '.']);
40+
await spawn.exitCode;
41+
42+
// Check if a package is ready for publishing.
43+
// Upon hitting a blocking stdin state, you may directly
44+
// output to the processes's stdin via your own, similar to how a bash or
45+
// shell script would spawn a process.
46+
print('** Running pub publish');
47+
spawn = await manager.spawn('dart', ['pub', 'publish', '--dry-run']);
48+
await spawn.exitCode;
49+
50+
// Closes stdin for the entire program.
51+
await sharedStdIn.terminate();
52+
}
53+
```
54+
55+
#### `sharedStdIn`
56+
57+
A safer version of the default `stdin` stream from `dart:io` that allows a
58+
subscriber to cancel their subscription, and then allows a _new_ subscriber to
59+
start listening. This differs from the default behavior where only a single
60+
listener is ever allowed in the application lifecycle:
61+
62+
```dart
63+
test('should allow multiple subscribers', () async {
64+
final logs = <String>[];
65+
final asUtf8 = sharedStdIn.transform(UTF8.decoder);
66+
// Wait for input for the user.
67+
logs.add(await asUtf8.first);
68+
// Wait for more input for the user.
69+
logs.add(await asUtf8.first);
70+
expect(logs, ['Hello World', 'Goodbye World']);
71+
});
72+
```
73+
74+
For testing, an instance of `SharedStdIn` may be created directly.
75+
76+
## Usage - `ansi.dart`
77+
78+
```dart
79+
import 'dart:io' as io;
80+
import 'package:io/ansi.dart';
81+
82+
void main() {
83+
// To use one style, call the `wrap` method on one of the provided top-level
84+
// values.
85+
io.stderr.writeln(red.wrap("Bad error!"));
86+
87+
// To use multiple styles, call `wrapWith`.
88+
print(wrapWith('** Important **', [red, styleBold, styleUnderlined]));
89+
90+
// The wrap functions will simply return the provided value unchanged if
91+
// `ansiOutputEnabled` is false.
92+
//
93+
// You can override the value `ansiOutputEnabled` by wrapping code in
94+
// `overrideAnsiOutput`.
95+
overrideAnsiOutput(false, () {
96+
assert('Normal text' == green.wrap('Normal text'));
97+
});
98+
}
99+
```
100+
101+
## Publishing automation
102+
103+
For information about our publishing automation and release process, see
104+
https://github.com/dart-lang/ecosystem/wiki/Publishing-automation.

pkgs/io/analysis_options.yaml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# https://dart.dev/guides/language/analysis-options
2+
include: package:dart_flutter_team_lints/analysis_options.yaml
3+
4+
analyzer:
5+
language:
6+
strict-casts: true
7+
strict-inference: true
8+
strict-raw-types: true
9+
10+
linter:
11+
rules:
12+
- avoid_bool_literals_in_conditional_expressions
13+
- avoid_classes_with_only_static_members
14+
- avoid_private_typedef_functions
15+
- avoid_redundant_argument_values
16+
- avoid_returning_this
17+
- avoid_unused_constructor_parameters
18+
- avoid_void_async
19+
- cancel_subscriptions
20+
- join_return_with_assignment
21+
- literal_only_boolean_expressions
22+
- missing_whitespace_between_adjacent_strings
23+
- no_adjacent_strings_in_list
24+
- no_runtimeType_toString
25+
- prefer_const_declarations
26+
- prefer_expression_function_bodies
27+
- prefer_final_locals
28+
- unnecessary_await_in_return
29+
- unnecessary_breaks
30+
- use_if_null_to_convert_nulls_to_bools
31+
- use_raw_strings
32+
- use_string_buffers

0 commit comments

Comments
 (0)