Skip to content

Commit be0b153

Browse files
authored
Revert "Completely new cross-platform API introduced" (#957)
This reverts commit 0def20c. Temporarily reverting to fix long-tail issues with internal usage patterns.
1 parent a23519d commit be0b153

56 files changed

Lines changed: 502 additions & 5561 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

pkgs/platform/.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
.dart_tool/
55
.pub/
66
build/
7-
doc/
7+
packages
8+
.packages
89

910
# Include when developing application packages.
1011
pubspec.lock

pkgs/platform/CHANGELOG.md

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,3 @@
1-
## 3.2.0-wip
2-
3-
* New non-backwards compatible API.
4-
Use `Platform.current` to access the current platform,
5-
and `Platform.current.native` to either get access to native
6-
platform information, or get a `null` on non-native platforms.
7-
Similarly `Platform.current.web` is only non-`null` on the web.
8-
9-
Mocking APIs are moved to a separate library to ensure they are
10-
only used for testing, and to allow better performance in production.
11-
12-
Legacy APIs are deprecated, but retained and emulated using the new API.
13-
Use `dart fix` to migrate off the deprecated API.
14-
151
## 3.1.7-wip
162

173
- Run `dart format` with the new style.

pkgs/platform/README.md

Lines changed: 6 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,10 @@
1-
[![Pub](https://img.shields.io/pub/v/platform.svg)](https://pub.dev/packages/platform)
1+
[![Pub](https://img.shields.io/pub/v/platform.svg)](https://pub.dartlang.org/packages/platform)
22

33
A generic platform abstraction for Dart.
44

5-
### Cross-platform platform API
6-
Provides access to platform specific information of the current runtime platform
7-
through a cross-platform API.
5+
Like `dart:io`, `package:platform` supplies a rich, Dart-idiomatic API for
6+
accessing platform-specific information.
87

9-
On a native platform, the `NativePlatform` class in this package provides a
10-
lightweight wrapper around the static `Platform` properties of `dart:io`,
11-
with the same rich, Dart-idiomatic API for querying the current runtime.
12-
13-
On the web, there is no `NativePlatform` object, and cross-platform client code
14-
can avoid dependencies on such properties simply by checking if
15-
`Platform.current.nativePlatform` is `null`.
16-
Instead web code has a `Platform.current.browserPlatform` values that is
17-
a non-`null` `BrowserPlatform`.
18-
19-
Example:
20-
```dart
21-
import 'package:platform/platform.dart';
22-
23-
void main() {
24-
switch (Platform.current) {
25-
case Platform(:var nativePlatform?):
26-
// `nativePlatform` has `dart:io`'s `Platform` properties.
27-
print(
28-
'Running on ${nativePlatform.operatingSystem} v.'
29-
'${nativePlatform.operatingSystemVersion}',
30-
);
31-
case Platform(:var browserPlatform?):
32-
// `browserPlatform` has version information from `windows.userAgent`.
33-
print('Running on ${browserPlatform.userAgent}');
34-
}
35-
}
36-
```
37-
38-
### Code size
39-
40-
Using platform-specific properties like `Platform.isLinux` as branch conditions
41-
will allow a production compiler to completely omit the branch
42-
that it knows it's not currently compiling for.
43-
44-
### Testing and Mocking
45-
46-
In tests, the `package:platform/testing.dart` library provides ways to mock
47-
platform objects with custom tailored configurations,
48-
and allows `Zone` based overriding of the `Platform.current` value.
49-
> [!NOTE]
50-
> The testing library should only be used in tests, since its mere presence
51-
> may affect how much code a compiled program will retain.
8+
`package:platform` provides a lightweight wrapper around the static `Platform`
9+
properties that exist in `dart:io`. However, it uses instance properties rather
10+
than static properties, making it possible to mock out in tests.

pkgs/platform/analysis_options.yaml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,3 @@ analyzer:
44
errors:
55
# Allow having TODOs in the code
66
todo: ignore
7-
# Increase the pressure?
8-
deprecated_member_use: warning
9-
deprecated_member_use_from_same_package: warning
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import 'package:platform/platform.dart';
2+
3+
void main(List<String> arguments) {
4+
const LocalPlatform platform = LocalPlatform();
5+
6+
print('Operating System: ${platform.operatingSystem}.');
7+
print('Local Hostname: ${platform.localHostname}.');
8+
print('Number of Processors: ${platform.numberOfProcessors}.');
9+
print('Path Separator: ${platform.pathSeparator}.');
10+
print('Locale Name: ${platform.localeName}.');
11+
print('Stdin Supports ANSI: ${platform.stdinSupportsAnsi}.');
12+
print('Stdout Supports ANSI: ${platform.stdoutSupportsAnsi}.');
13+
print('Executable Arguments: ${platform.executableArguments}.');
14+
print('Dart Version: ${platform.version}.');
15+
}

pkgs/platform/example/bin/platform.dart

Lines changed: 0 additions & 27 deletions
This file was deleted.

pkgs/platform/example/bin/platform_using_switch.dart

Lines changed: 0 additions & 22 deletions
This file was deleted.

pkgs/platform/example/bin/tree_shake.dart

Lines changed: 0 additions & 43 deletions
This file was deleted.

pkgs/platform/example/bin/tree_shake_nullaware.dart

Lines changed: 0 additions & 40 deletions
This file was deleted.

pkgs/platform/example/bin/tree_shake_pattern_const.dart

Lines changed: 0 additions & 48 deletions
This file was deleted.

0 commit comments

Comments
 (0)