Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(actions): Fixes for upcoming Dart changes #3742

Merged
merged 1 commit into from
Sep 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
439 changes: 166 additions & 273 deletions .github/composite_actions/launch_android_emulator/dist/main.cjs

Large diffs are not rendered by default.

Large diffs are not rendered by default.

96 changes: 34 additions & 62 deletions .github/composite_actions/launch_ios_simulator/dist/main.cjs

Large diffs are not rendered by default.

Large diffs are not rendered by default.

321 changes: 126 additions & 195 deletions .github/composite_actions/setup_chromedriver/dist/main.cjs

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions .github/composite_actions/setup_chromedriver/dist/main.cjs.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions .github/workflows/actions.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ jobs:
- name: Setup Dart
uses: dart-lang/setup-dart@e58aeb62aef51dcc4d0ba8eada7c08092aad5314 # main
with:
sdk: 3.2.0-90.0.dev
sdk: 3.2.0-150.0.dev

- name: Setup pnpm
uses: pnpm/action-setup@d882d12c64e032187b2edb46d3a0d003b7a43598 # 2.4.0
Expand All @@ -57,7 +57,7 @@ jobs:
- name: Setup Dart
uses: dart-lang/setup-dart@e58aeb62aef51dcc4d0ba8eada7c08092aad5314 # main
with:
sdk: 3.2.0-90.0.dev
sdk: 3.2.0-150.0.dev

- name: Get Packages
working-directory: actions
Expand Down
3 changes: 2 additions & 1 deletion actions/lib/src/node/actions/cache.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ external Cache get cache;
///
/// See: https://www.npmjs.com/package/@actions/cache
@JS()
extension type Cache(JSObject it) {
@anonymous
extension type Cache._(JSObject it) {
/// Returns true if Actions cache service feature is available, otherwise false.
external bool isFeatureAvailable();

Expand Down
3 changes: 2 additions & 1 deletion actions/lib/src/node/actions/core.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ import 'package:actions/src/node/process.dart';
external Core get core;

@JS()
extension type Core(JSObject it) {
@anonymous
extension type Core._(JSObject it) {
@JS('getInput')
external String _getInput(String name);

Expand Down
21 changes: 10 additions & 11 deletions actions/lib/src/node/actions/exec.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ import 'dart:js_util';
external Exec get exec;

@JS()
extension type Exec(JSObject it) {
@anonymous
extension type Exec._(JSObject it) {
@JS('exec')
external JSPromise _exec(
String commandLine, [
Expand Down Expand Up @@ -37,9 +38,9 @@ extension type Exec(JSObject it) {
stderr: ((JSUint8Array buffer) =>
stderr.write(utf8.decode(buffer.toDart))).toJS,
),
silent: (!echoOutput).toJS,
cwd: workingDirectory?.toJS,
ignoreReturnCode: (!failOnNonZeroExit).toJS,
silent: !echoOutput,
cwd: workingDirectory,
ignoreReturnCode: !failOnNonZeroExit,
);
try {
final exitCode = await promiseToFuture<int>(
Expand All @@ -64,20 +65,18 @@ extension type Exec(JSObject it) {

@JS()
@anonymous
@staticInterop
class _ExecOptions {
extension type _ExecOptions._(JSObject it) {
external factory _ExecOptions({
_ExecListeners? listeners,
JSString? cwd,
JSBoolean? silent,
JSBoolean? ignoreReturnCode,
String? cwd,
bool? silent,
bool? ignoreReturnCode,
});
}

@JS()
@anonymous
@staticInterop
class _ExecListeners {
extension type _ExecListeners._(JSObject it) {
external factory _ExecListeners({
JSFunction? stdout,
JSFunction? stderr,
Expand Down
7 changes: 4 additions & 3 deletions actions/lib/src/node/actions/http_request.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,21 @@ extension type HttpClient._(JSObject it) {
Future<Map<String, Object?>> getJson(String requestUrl) async {
final response = await _getJson(requestUrl).toDart;
final result = response as TypedResponse<JSObject>;
if (result.statusCode.toDartInt != 200) {
if (result.statusCode != 200) {
throw Exception('Could not fetch $requestUrl');
}
return (result.result!.dartify() as Map).cast();
}
}

@JS()
@anonymous
extension type TypedResponse<T extends JSAny>._(JSObject it) {
external TypedResponse({
external factory TypedResponse({
int statusCode,
T result,
});

external JSNumber get statusCode;
external int get statusCode;
external T? get result;
}
3 changes: 2 additions & 1 deletion actions/lib/src/node/actions/tool_cache.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ external ToolCache get toolCache;

// https://www.npmjs.com/package/@actions/tool-cache
@JS()
extension type ToolCache(JSObject it) {
@anonymous
extension type ToolCache._(JSObject it) {
@JS('find')
external String _find(
String toolName,
Expand Down
35 changes: 19 additions & 16 deletions actions/lib/src/node/child_process.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ extension type ChildProcess(JSObject it) {
@JS('spawn')
external NodeChildProcess _spawn(
String command,
List<String> args,
JSArray args,
_ChildProcessOptions options,
);

Expand Down Expand Up @@ -58,18 +58,18 @@ extension type ChildProcess(JSObject it) {
encoding: 'utf8',
shell: runInShell ? '/bin/sh' : null,
),
(JSError? error, JSString stdout, JSString stderr) {
(JSError? error, String stdout, String stderr) {
if (error != null) {
return completer.completeError(
ProcessException(command, args, error.message.toDart),
ProcessException(command, args, error.message),
);
}
completer.complete(
ProcessResult(
child.pid?.toDartInt ?? -1,
child.exitCode!.toDartInt,
stdout.toDart,
stderr.toDart,
child.pid ?? -1,
child.exitCode!,
stdout,
stderr,
),
);
}.toJS,
Expand Down Expand Up @@ -112,7 +112,7 @@ extension type ChildProcess(JSObject it) {
);
} on Object catch (e) {
final message = switch (e) {
JSError _ => e.message.toDart,
JSError _ => e.message,
_ => e.toString(),
};
throw ProcessException(command, args, message);
Expand All @@ -138,7 +138,7 @@ extension type ChildProcess(JSObject it) {
}.toJS;
return _spawn(
command,
args,
args.map((arg) => arg.toJS).toList().toJS,
_ChildProcessOptions(
cwd: workingDirectory,
env: {
Expand Down Expand Up @@ -175,23 +175,25 @@ extension type _ChildProcessOptions._(JSObject it) {
}

@JS()
extension type NodeChildProcess(JSObject it) implements EventEmitter {
@anonymous
extension type NodeChildProcess._(JSObject it) implements EventEmitter {
Future<void> get onSpawn => once('spawn');
Future<JSObject> get onError => once('error');
Future<JSNumber> get onExit => once('exit');
Future<void> get onClose => once('close');
external bool kill([String signal]);

/// This is only set once the process has exited.
external JSNumber? get exitCode;
external JSNumber? get pid;
external int? get exitCode;
external int? get pid;
external NodeWriteableStream? get stdin;
external NodeReadableStream? get stdout;
external NodeReadableStream? get stderr;
}

@JS()
extension type NodeReadableStream(JSObject it) implements EventEmitter {
@anonymous
extension type NodeReadableStream._(JSObject it) implements EventEmitter {
Stream<List<int>> get stream {
final controller = StreamController<List<int>>(sync: true);
void onData(JSUint8Array chunk) {
Expand Down Expand Up @@ -223,7 +225,7 @@ extension type NodeReadableStream(JSObject it) implements EventEmitter {
}

@JS()
extension type EventEmitter(JSObject it) implements JSObject {
extension type EventEmitter._(JSObject it) implements JSObject {
external void addListener(String eventName, JSFunction? listener);

external void removeListener(String eventName, JSFunction? listener);
Expand All @@ -249,6 +251,7 @@ extension type EventEmitter(JSObject it) implements JSObject {
}

@JS()
extension type NodeWriteableStream(JSObject it) {
external void write(JSUint8Array chunk, [JSString? encoding, JSFunction flushCallback]);
@anonymous
extension type NodeWriteableStream._(JSObject it) {
external void write(JSUint8Array chunk, [String? encoding, JSFunction flushCallback]);
}
6 changes: 3 additions & 3 deletions actions/lib/src/node/error.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import 'dart:js_interop';
@JS('Error')
@staticInterop
extension type JSError(JSObject it) {
external JSString get message;
external JSString get code;
external JSString get stack;
external String get message;
external String get code;
external String get stack;
external JSAny? get cause;
}
5 changes: 2 additions & 3 deletions actions/lib/src/node/fs.dart
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ abstract final class FileSystemAccess {
}

@JS()
extension type FileSystem(JSObject it) {
extension type FileSystem._(JSObject it) {
external bool existsSync(String path);

@JS('readFileSync')
Expand Down Expand Up @@ -89,8 +89,7 @@ extension type FileSystem(JSObject it) {

@JS()
@anonymous
@staticInterop
class _RmdirOptions {
extension type _RmdirOptions._(JSObject it) {
external factory _RmdirOptions({
bool? recursive,
});
Expand Down
6 changes: 3 additions & 3 deletions actions/lib/src/node/os.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ import 'dart:js_interop';
external OperatingSystem get os;

@JS()
extension type OperatingSystem(JSObject it) {
extension type OperatingSystem._(JSObject it) {
external String tmpdir();
external JSArray cpus();
external JSNumber freemem();
external int freemem();

/// Number of logical cores
int get numCores => cpus().toDart.length;

/// Available memory, in megabytes
int get availableRam => freemem().toDartInt ~/ (1 << 20);
int get availableRam => freemem() ~/ (1 << 20);
}
11 changes: 9 additions & 2 deletions actions/lib/src/node/process.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@ import 'dart:js_interop';
import 'dart:js_interop_unsafe';

import 'package:actions/src/os.dart';
import 'package:actions/src/util.dart';

/// Provides information about, and control over, the current Node.js process.
/// Wraps https://nodejs.org/api/process.html
@JS()
external Process get process;

@JS()
extension type Process(JSObject it) {
extension type Process._(JSObject it) {
/// The current Node version.
external String get version;

Expand Down Expand Up @@ -62,7 +63,13 @@ extension type Process(JSObject it) {
String? getEnv(String variable) =>
_env.getProperty<JSString?>(variable.toJS)?.toDart;

external Never exit(int exitCode);
@JS('exit')
external void _exit(int exitCode);

Never exit(int exitCode) {
_exit(exitCode);
unreachable;
}
}

@JS('Object')
Expand Down
6 changes: 3 additions & 3 deletions actions/lib/src/node/process_manager.dart
Original file line number Diff line number Diff line change
Expand Up @@ -217,14 +217,14 @@ final class NodeProcess implements Process, Closeable {
@override
Future<int> get exitCode async {
if (_jsProcess.exitCode case final exitCode?) {
return exitCode.toDartInt;
return exitCode;
}
await Future.any([
_jsProcess.onClose,
_jsProcess.onError,
_jsProcess.onExit,
]);
return _jsProcess.exitCode!.toDartInt;
return _jsProcess.exitCode!;
}

@override
Expand All @@ -233,7 +233,7 @@ final class NodeProcess implements Process, Closeable {
}

@override
int get pid => _jsProcess.pid?.toDartInt ?? -1;
int get pid => _jsProcess.pid ?? -1;

@override
Stream<List<int>> get stderr => _stderr.stream;
Expand Down
2 changes: 1 addition & 1 deletion actions/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ version: 1.0.0
publish_to: none

environment:
sdk: ^3.2.0-90.0.dev
sdk: ^3.2.0-150.0.dev

dependencies:
aws_common: any
Expand Down
4 changes: 2 additions & 2 deletions actions/test/node/interop_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ void main() {
),
);
await check(proc.onSpawn).completes();
check(proc.pid?.toDartInt).isNotNull().isGreaterThan(0);
check(proc.pid).isNotNull().isGreaterThan(0);
});

test('spawn (pipe)', () async {
Expand Down Expand Up @@ -100,7 +100,7 @@ void main() {
),
);
await check(proc.onSpawn).completes();
check(proc.pid?.toDartInt).isNotNull().isGreaterThan(0);
check(proc.pid).isNotNull().isGreaterThan(0);
});
});

Expand Down