Skip to content

updates to move away from dart:js_util #148

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

Merged
merged 6 commits into from
Feb 13, 2025
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
1,013 changes: 226 additions & 787 deletions dist/index.mjs

Large diffs are not rendered by default.

1,615 changes: 762 additions & 853 deletions dist/main.cjs

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/sig.txt

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

65 changes: 33 additions & 32 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

import 'dart:convert';
import 'dart:js_interop';
import 'dart:js_util';

import 'package:path/path.dart' as path;
import 'package:pub_semver/pub_semver.dart';
Expand Down Expand Up @@ -112,13 +112,15 @@ Future<void> _impl(List<String> args) async {
process.env('RUNNER_TEMP')!,
path.url.basename(url),
);
await promiseToFuture<String>(toolCache.downloadTool(url, archivePath));
await toolCache.downloadTool(url, archivePath).toDart;
var extractedFolder =
await promiseToFuture<String>(toolCache.extractZip(archivePath));
(await toolCache.extractZip(archivePath).toDart).toDart;
extractedFolder = path.join(extractedFolder, 'dart-sdk');

sdkPath = await promiseToFuture<String>(
toolCache.cacheDir(extractedFolder, toolName, version, architecture));
sdkPath = (await toolCache
.cacheDir(extractedFolder, toolName, version, architecture)
.toDart)
.toDart;
}

final pubCache = path.join(
Expand All @@ -136,10 +138,7 @@ Future<void> _impl(List<String> args) async {
core.setOutput('dart-version', getVersionFromSdk(sdkPath));

// Report success; print version.
await promiseToFuture<void>(exec.exec(
'dart',
['--version'.toJS].toJS,
));
await exec.exec('dart', ['--version'.toJS].toJS).toDart;
}

String getVersionFromSdk(String sdkPath) {
Expand Down Expand Up @@ -172,22 +171,22 @@ Future<void> createPubOIDCToken() async {
return;
}

final token =
await promiseToFuture<String>(core.getIDToken('https://pub.dev'));
final token = (await core.getIDToken('https://pub.dev').toDart).toDart;

core.exportVariable('PUB_TOKEN', token);

await promiseToFuture<void>(exec.exec(
'dart',
[
'pub'.toJS,
'token'.toJS,
'add'.toJS,
'https://pub.dev'.toJS,
'--env-var'.toJS,
'PUB_TOKEN'.toJS,
].toJS,
));
await exec
.exec(
'dart',
[
'pub'.toJS,
'token'.toJS,
'add'.toJS,
'https://pub.dev'.toJS,
'--env-var'.toJS,
'PUB_TOKEN'.toJS,
].toJS)
.toDart;
}

// https://storage.googleapis.com/dart-archive/channels/stable/release/latest/VERSION
Expand All @@ -206,17 +205,18 @@ Future<String> latestPublishedVersion(String channel, String flavor) async {
final http = HttpClient(
'setup-dart',
<JSAny>[].toJS,
jsify({
{
'allowRedirects': true,
'maxRedirects': 3,
'allowRetries': true,
'maxRetries': 3,
}) as JSObject?,
}.jsify() as JSObject?,
);

var response = await promiseToFuture<JSObject>(http.getJson(url));
var result = getProperty<JSObject>(response, 'result');
return getProperty(result, 'version');
var response = (await http.get(url).toDart) as HttpClientResponse;
var data = (await response.readBody().toDart).toDart;
var json = (jsonDecode(data) as Map).cast<String, Object?>();
return json['version'] as String;
}

/// Find the latest SDK patch version for the given SDK release.
Expand All @@ -230,12 +230,12 @@ Future<String> findLatestSdkForRelease(String sdkRelease) async {
final http = HttpClient(
'setup-dart',
<JSAny>[].toJS,
jsify({
{
'allowRedirects': true,
'maxRedirects': 3,
'allowRetries': true,
'maxRetries': 3,
}) as JSObject?,
}.jsify() as JSObject?,
);

// {
Expand All @@ -247,10 +247,11 @@ Future<String> findLatestSdkForRelease(String sdkRelease) async {
// "channels/stable/release/2.19.6/"
// ]
// }
var response = await promiseToFuture<JSObject>(http.getJson(url));
var result = getProperty<JSObject>(response, 'result');
var response = (await http.get(url).toDart) as HttpClientResponse;
var data = (await response.readBody().toDart).toDart;
var json = (jsonDecode(data) as Map).cast<String, Object?>();

final paths = (getProperty(result, 'prefixes') as List).cast<String>();
final paths = (json['prefixes'] as List).cast<String>();
final versions = paths.map((p) => (p.split('/')..removeLast()).last).toList();

// Sort versions by semver and return the highest version.
Expand Down
3 changes: 1 addition & 2 deletions lib/node/actions/core.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,5 @@ extension type Core(JSObject obj) {

external void exportVariable(String name, String value);

// JSPromise<String>
external JSPromise getIDToken(String audience);
external JSPromise<JSString> getIDToken(String audience);
}
10 changes: 8 additions & 2 deletions lib/node/actions/http_client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ extension type HttpClient._(JSObject obj) {
JSObject? requestOptions,
]);

// JSPromise<JSObject>
external JSPromise getJson(String requestUrl);
// JSPromise<HttpClientResponse>
external JSPromise<JSObject> get(String requestUrl);
external JSPromise<JSObject?> getJson(String requestUrl);
}

@JS()
extension type HttpClientResponse._(JSObject obj) {
external JSPromise<JSString> readBody();
}
7 changes: 3 additions & 4 deletions lib/node/actions/tool_cache.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,13 @@ extension type ToolCache(JSObject obj) {
/// @param url url of tool to download
/// @param dest path to download tool
/// @returns path to downloaded tool
// JSPromise<String>
external JSPromise downloadTool(String url, [String? dest]);
external JSPromise<JSString> downloadTool(String url, [String? dest]);

/// Extract a zip.
///
/// @param file path to the zip
/// @returns path to the destination directory
external JSPromise extractZip(String file);
external JSPromise<JSString> extractZip(String file);

/// Caches a directory and installs it into the tool cacheDir
///
Expand All @@ -41,7 +40,7 @@ extension type ToolCache(JSObject obj) {
/// @param version version of the tool. semver format
/// @param arch architecture of the tool. Optional.
/// Defaults to machine architecture
external JSPromise cacheDir(
external JSPromise<JSString> cacheDir(
String sourceDir,
String tool,
String version, [
Expand Down
6 changes: 4 additions & 2 deletions lib/node/process.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// BSD-style license that can be found in the LICENSE file.

import 'dart:js_interop';
import 'dart:js_util';
import 'dart:js_interop_unsafe';

/// Provides information about, and control over, the current Node.js process.
/// Wraps https://nodejs.org/api/process.html
Expand All @@ -17,7 +17,9 @@ extension type Process(JSObject obj) {
external JSObject get _env;

/// Read the environment variable [variable].
String? env(String variable) => getProperty<String?>(_env, variable);
String? env(String variable) {
return _env.getProperty<JSString?>(variable.toJS)?.toDart;
}

external int exitCode;
}
2 changes: 2 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ dependencies:
dev_dependencies:
args: ^2.4.0
crypto: ^3.0.0
dart_flutter_team_lints: ^2.0.0
dart_flutter_team_lints: ^3.0.0