Skip to content

Commit a98975e

Browse files
authored
chore(actions): Fixes for upcoming Dart changes (#3742)
- Ensures that JS interop methods use only interop values for inputs/outputs. - Prefers Dart primitives (String, bool, int) over JS primitives (JSString, etc.) since newer Dart enables automatic conversion.
1 parent 38be40f commit a98975e

File tree

20 files changed

+408
-600
lines changed

20 files changed

+408
-600
lines changed

.github/composite_actions/launch_android_emulator/dist/main.cjs

Lines changed: 166 additions & 273 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.github/composite_actions/launch_android_emulator/dist/main.cjs.map

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.github/composite_actions/launch_ios_simulator/dist/main.cjs

Lines changed: 34 additions & 62 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.github/composite_actions/launch_ios_simulator/dist/main.cjs.map

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.github/composite_actions/setup_chromedriver/dist/main.cjs

Lines changed: 126 additions & 195 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.github/composite_actions/setup_chromedriver/dist/main.cjs.map

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.github/workflows/actions.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ jobs:
3232
- name: Setup Dart
3333
uses: dart-lang/setup-dart@e58aeb62aef51dcc4d0ba8eada7c08092aad5314 # main
3434
with:
35-
sdk: 3.2.0-90.0.dev
35+
sdk: 3.2.0-150.0.dev
3636

3737
- name: Setup pnpm
3838
uses: pnpm/action-setup@d882d12c64e032187b2edb46d3a0d003b7a43598 # 2.4.0
@@ -57,7 +57,7 @@ jobs:
5757
- name: Setup Dart
5858
uses: dart-lang/setup-dart@e58aeb62aef51dcc4d0ba8eada7c08092aad5314 # main
5959
with:
60-
sdk: 3.2.0-90.0.dev
60+
sdk: 3.2.0-150.0.dev
6161

6262
- name: Get Packages
6363
working-directory: actions

actions/lib/src/node/actions/cache.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ external Cache get cache;
1010
///
1111
/// See: https://www.npmjs.com/package/@actions/cache
1212
@JS()
13-
extension type Cache(JSObject it) {
13+
@anonymous
14+
extension type Cache._(JSObject it) {
1415
/// Returns true if Actions cache service feature is available, otherwise false.
1516
external bool isFeatureAvailable();
1617

actions/lib/src/node/actions/core.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ import 'package:actions/src/node/process.dart';
1010
external Core get core;
1111

1212
@JS()
13-
extension type Core(JSObject it) {
13+
@anonymous
14+
extension type Core._(JSObject it) {
1415
@JS('getInput')
1516
external String _getInput(String name);
1617

actions/lib/src/node/actions/exec.dart

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ import 'dart:js_util';
99
external Exec get exec;
1010

1111
@JS()
12-
extension type Exec(JSObject it) {
12+
@anonymous
13+
extension type Exec._(JSObject it) {
1314
@JS('exec')
1415
external JSPromise _exec(
1516
String commandLine, [
@@ -37,9 +38,9 @@ extension type Exec(JSObject it) {
3738
stderr: ((JSUint8Array buffer) =>
3839
stderr.write(utf8.decode(buffer.toDart))).toJS,
3940
),
40-
silent: (!echoOutput).toJS,
41-
cwd: workingDirectory?.toJS,
42-
ignoreReturnCode: (!failOnNonZeroExit).toJS,
41+
silent: !echoOutput,
42+
cwd: workingDirectory,
43+
ignoreReturnCode: !failOnNonZeroExit,
4344
);
4445
try {
4546
final exitCode = await promiseToFuture<int>(
@@ -64,20 +65,18 @@ extension type Exec(JSObject it) {
6465

6566
@JS()
6667
@anonymous
67-
@staticInterop
68-
class _ExecOptions {
68+
extension type _ExecOptions._(JSObject it) {
6969
external factory _ExecOptions({
7070
_ExecListeners? listeners,
71-
JSString? cwd,
72-
JSBoolean? silent,
73-
JSBoolean? ignoreReturnCode,
71+
String? cwd,
72+
bool? silent,
73+
bool? ignoreReturnCode,
7474
});
7575
}
7676

7777
@JS()
7878
@anonymous
79-
@staticInterop
80-
class _ExecListeners {
79+
extension type _ExecListeners._(JSObject it) {
8180
external factory _ExecListeners({
8281
JSFunction? stdout,
8382
JSFunction? stderr,

actions/lib/src/node/actions/http_request.dart

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,20 +17,21 @@ extension type HttpClient._(JSObject it) {
1717
Future<Map<String, Object?>> getJson(String requestUrl) async {
1818
final response = await _getJson(requestUrl).toDart;
1919
final result = response as TypedResponse<JSObject>;
20-
if (result.statusCode.toDartInt != 200) {
20+
if (result.statusCode != 200) {
2121
throw Exception('Could not fetch $requestUrl');
2222
}
2323
return (result.result!.dartify() as Map).cast();
2424
}
2525
}
2626

2727
@JS()
28+
@anonymous
2829
extension type TypedResponse<T extends JSAny>._(JSObject it) {
29-
external TypedResponse({
30+
external factory TypedResponse({
3031
int statusCode,
3132
T result,
3233
});
3334

34-
external JSNumber get statusCode;
35+
external int get statusCode;
3536
external T? get result;
3637
}

actions/lib/src/node/actions/tool_cache.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ external ToolCache get toolCache;
88

99
// https://www.npmjs.com/package/@actions/tool-cache
1010
@JS()
11-
extension type ToolCache(JSObject it) {
11+
@anonymous
12+
extension type ToolCache._(JSObject it) {
1213
@JS('find')
1314
external String _find(
1415
String toolName,

actions/lib/src/node/child_process.dart

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ extension type ChildProcess(JSObject it) {
1919
@JS('spawn')
2020
external NodeChildProcess _spawn(
2121
String command,
22-
List<String> args,
22+
JSArray args,
2323
_ChildProcessOptions options,
2424
);
2525

@@ -58,18 +58,18 @@ extension type ChildProcess(JSObject it) {
5858
encoding: 'utf8',
5959
shell: runInShell ? '/bin/sh' : null,
6060
),
61-
(JSError? error, JSString stdout, JSString stderr) {
61+
(JSError? error, String stdout, String stderr) {
6262
if (error != null) {
6363
return completer.completeError(
64-
ProcessException(command, args, error.message.toDart),
64+
ProcessException(command, args, error.message),
6565
);
6666
}
6767
completer.complete(
6868
ProcessResult(
69-
child.pid?.toDartInt ?? -1,
70-
child.exitCode!.toDartInt,
71-
stdout.toDart,
72-
stderr.toDart,
69+
child.pid ?? -1,
70+
child.exitCode!,
71+
stdout,
72+
stderr,
7373
),
7474
);
7575
}.toJS,
@@ -112,7 +112,7 @@ extension type ChildProcess(JSObject it) {
112112
);
113113
} on Object catch (e) {
114114
final message = switch (e) {
115-
JSError _ => e.message.toDart,
115+
JSError _ => e.message,
116116
_ => e.toString(),
117117
};
118118
throw ProcessException(command, args, message);
@@ -138,7 +138,7 @@ extension type ChildProcess(JSObject it) {
138138
}.toJS;
139139
return _spawn(
140140
command,
141-
args,
141+
args.map((arg) => arg.toJS).toList().toJS,
142142
_ChildProcessOptions(
143143
cwd: workingDirectory,
144144
env: {
@@ -175,23 +175,25 @@ extension type _ChildProcessOptions._(JSObject it) {
175175
}
176176

177177
@JS()
178-
extension type NodeChildProcess(JSObject it) implements EventEmitter {
178+
@anonymous
179+
extension type NodeChildProcess._(JSObject it) implements EventEmitter {
179180
Future<void> get onSpawn => once('spawn');
180181
Future<JSObject> get onError => once('error');
181182
Future<JSNumber> get onExit => once('exit');
182183
Future<void> get onClose => once('close');
183184
external bool kill([String signal]);
184185

185186
/// This is only set once the process has exited.
186-
external JSNumber? get exitCode;
187-
external JSNumber? get pid;
187+
external int? get exitCode;
188+
external int? get pid;
188189
external NodeWriteableStream? get stdin;
189190
external NodeReadableStream? get stdout;
190191
external NodeReadableStream? get stderr;
191192
}
192193

193194
@JS()
194-
extension type NodeReadableStream(JSObject it) implements EventEmitter {
195+
@anonymous
196+
extension type NodeReadableStream._(JSObject it) implements EventEmitter {
195197
Stream<List<int>> get stream {
196198
final controller = StreamController<List<int>>(sync: true);
197199
void onData(JSUint8Array chunk) {
@@ -223,7 +225,7 @@ extension type NodeReadableStream(JSObject it) implements EventEmitter {
223225
}
224226

225227
@JS()
226-
extension type EventEmitter(JSObject it) implements JSObject {
228+
extension type EventEmitter._(JSObject it) implements JSObject {
227229
external void addListener(String eventName, JSFunction? listener);
228230

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

251253
@JS()
252-
extension type NodeWriteableStream(JSObject it) {
253-
external void write(JSUint8Array chunk, [JSString? encoding, JSFunction flushCallback]);
254+
@anonymous
255+
extension type NodeWriteableStream._(JSObject it) {
256+
external void write(JSUint8Array chunk, [String? encoding, JSFunction flushCallback]);
254257
}

actions/lib/src/node/error.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ import 'dart:js_interop';
66
@JS('Error')
77
@staticInterop
88
extension type JSError(JSObject it) {
9-
external JSString get message;
10-
external JSString get code;
11-
external JSString get stack;
9+
external String get message;
10+
external String get code;
11+
external String get stack;
1212
external JSAny? get cause;
1313
}

actions/lib/src/node/fs.dart

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ abstract final class FileSystemAccess {
3131
}
3232

3333
@JS()
34-
extension type FileSystem(JSObject it) {
34+
extension type FileSystem._(JSObject it) {
3535
external bool existsSync(String path);
3636

3737
@JS('readFileSync')
@@ -89,8 +89,7 @@ extension type FileSystem(JSObject it) {
8989

9090
@JS()
9191
@anonymous
92-
@staticInterop
93-
class _RmdirOptions {
92+
extension type _RmdirOptions._(JSObject it) {
9493
external factory _RmdirOptions({
9594
bool? recursive,
9695
});

actions/lib/src/node/os.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@ import 'dart:js_interop';
77
external OperatingSystem get os;
88

99
@JS()
10-
extension type OperatingSystem(JSObject it) {
10+
extension type OperatingSystem._(JSObject it) {
1111
external String tmpdir();
1212
external JSArray cpus();
13-
external JSNumber freemem();
13+
external int freemem();
1414

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

1818
/// Available memory, in megabytes
19-
int get availableRam => freemem().toDartInt ~/ (1 << 20);
19+
int get availableRam => freemem() ~/ (1 << 20);
2020
}

actions/lib/src/node/process.dart

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,15 @@ import 'dart:js_interop';
55
import 'dart:js_interop_unsafe';
66

77
import 'package:actions/src/os.dart';
8+
import 'package:actions/src/util.dart';
89

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

1415
@JS()
15-
extension type Process(JSObject it) {
16+
extension type Process._(JSObject it) {
1617
/// The current Node version.
1718
external String get version;
1819

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

65-
external Never exit(int exitCode);
66+
@JS('exit')
67+
external void _exit(int exitCode);
68+
69+
Never exit(int exitCode) {
70+
_exit(exitCode);
71+
unreachable;
72+
}
6673
}
6774

6875
@JS('Object')

actions/lib/src/node/process_manager.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -217,14 +217,14 @@ final class NodeProcess implements Process, Closeable {
217217
@override
218218
Future<int> get exitCode async {
219219
if (_jsProcess.exitCode case final exitCode?) {
220-
return exitCode.toDartInt;
220+
return exitCode;
221221
}
222222
await Future.any([
223223
_jsProcess.onClose,
224224
_jsProcess.onError,
225225
_jsProcess.onExit,
226226
]);
227-
return _jsProcess.exitCode!.toDartInt;
227+
return _jsProcess.exitCode!;
228228
}
229229

230230
@override
@@ -233,7 +233,7 @@ final class NodeProcess implements Process, Closeable {
233233
}
234234

235235
@override
236-
int get pid => _jsProcess.pid?.toDartInt ?? -1;
236+
int get pid => _jsProcess.pid ?? -1;
237237

238238
@override
239239
Stream<List<int>> get stderr => _stderr.stream;

actions/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ version: 1.0.0
44
publish_to: none
55

66
environment:
7-
sdk: ^3.2.0-90.0.dev
7+
sdk: ^3.2.0-150.0.dev
88

99
dependencies:
1010
aws_common: any

actions/test/node/interop_test.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ void main() {
7070
),
7171
);
7272
await check(proc.onSpawn).completes();
73-
check(proc.pid?.toDartInt).isNotNull().isGreaterThan(0);
73+
check(proc.pid).isNotNull().isGreaterThan(0);
7474
});
7575

7676
test('spawn (pipe)', () async {
@@ -100,7 +100,7 @@ void main() {
100100
),
101101
);
102102
await check(proc.onSpawn).completes();
103-
check(proc.pid?.toDartInt).isNotNull().isGreaterThan(0);
103+
check(proc.pid).isNotNull().isGreaterThan(0);
104104
});
105105
});
106106

0 commit comments

Comments
 (0)