Skip to content

Commit 1faf8e6

Browse files
authored
updates to move away from dart:js_util (#148)
- updates to move away from dart:js_util - run npm update to get the latest versions of node packages
1 parent 614cb8d commit 1faf8e6

File tree

10 files changed

+1041
-1684
lines changed

10 files changed

+1041
-1684
lines changed

dist/index.mjs

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

dist/main.cjs

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

dist/sig.txt

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/main.dart

Lines changed: 33 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

5+
import 'dart:convert';
56
import 'dart:js_interop';
6-
import 'dart:js_util';
77

88
import 'package:path/path.dart' as path;
99
import 'package:pub_semver/pub_semver.dart';
@@ -112,13 +112,15 @@ Future<void> _impl(List<String> args) async {
112112
process.env('RUNNER_TEMP')!,
113113
path.url.basename(url),
114114
);
115-
await promiseToFuture<String>(toolCache.downloadTool(url, archivePath));
115+
await toolCache.downloadTool(url, archivePath).toDart;
116116
var extractedFolder =
117-
await promiseToFuture<String>(toolCache.extractZip(archivePath));
117+
(await toolCache.extractZip(archivePath).toDart).toDart;
118118
extractedFolder = path.join(extractedFolder, 'dart-sdk');
119119

120-
sdkPath = await promiseToFuture<String>(
121-
toolCache.cacheDir(extractedFolder, toolName, version, architecture));
120+
sdkPath = (await toolCache
121+
.cacheDir(extractedFolder, toolName, version, architecture)
122+
.toDart)
123+
.toDart;
122124
}
123125

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

138140
// Report success; print version.
139-
await promiseToFuture<void>(exec.exec(
140-
'dart',
141-
['--version'.toJS].toJS,
142-
));
141+
await exec.exec('dart', ['--version'.toJS].toJS).toDart;
143142
}
144143

145144
String getVersionFromSdk(String sdkPath) {
@@ -172,22 +171,22 @@ Future<void> createPubOIDCToken() async {
172171
return;
173172
}
174173

175-
final token =
176-
await promiseToFuture<String>(core.getIDToken('https://pub.dev'));
174+
final token = (await core.getIDToken('https://pub.dev').toDart).toDart;
177175

178176
core.exportVariable('PUB_TOKEN', token);
179177

180-
await promiseToFuture<void>(exec.exec(
181-
'dart',
182-
[
183-
'pub'.toJS,
184-
'token'.toJS,
185-
'add'.toJS,
186-
'https://pub.dev'.toJS,
187-
'--env-var'.toJS,
188-
'PUB_TOKEN'.toJS,
189-
].toJS,
190-
));
178+
await exec
179+
.exec(
180+
'dart',
181+
[
182+
'pub'.toJS,
183+
'token'.toJS,
184+
'add'.toJS,
185+
'https://pub.dev'.toJS,
186+
'--env-var'.toJS,
187+
'PUB_TOKEN'.toJS,
188+
].toJS)
189+
.toDart;
191190
}
192191

193192
// https://storage.googleapis.com/dart-archive/channels/stable/release/latest/VERSION
@@ -206,17 +205,18 @@ Future<String> latestPublishedVersion(String channel, String flavor) async {
206205
final http = HttpClient(
207206
'setup-dart',
208207
<JSAny>[].toJS,
209-
jsify({
208+
{
210209
'allowRedirects': true,
211210
'maxRedirects': 3,
212211
'allowRetries': true,
213212
'maxRetries': 3,
214-
}) as JSObject?,
213+
}.jsify() as JSObject?,
215214
);
216215

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

222222
/// Find the latest SDK patch version for the given SDK release.
@@ -230,12 +230,12 @@ Future<String> findLatestSdkForRelease(String sdkRelease) async {
230230
final http = HttpClient(
231231
'setup-dart',
232232
<JSAny>[].toJS,
233-
jsify({
233+
{
234234
'allowRedirects': true,
235235
'maxRedirects': 3,
236236
'allowRetries': true,
237237
'maxRetries': 3,
238-
}) as JSObject?,
238+
}.jsify() as JSObject?,
239239
);
240240

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

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

256257
// Sort versions by semver and return the highest version.

lib/node/actions/core.dart

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,5 @@ extension type Core(JSObject obj) {
2121

2222
external void exportVariable(String name, String value);
2323

24-
// JSPromise<String>
25-
external JSPromise getIDToken(String audience);
24+
external JSPromise<JSString> getIDToken(String audience);
2625
}

lib/node/actions/http_client.dart

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@ extension type HttpClient._(JSObject obj) {
1212
JSObject? requestOptions,
1313
]);
1414

15-
// JSPromise<JSObject>
16-
external JSPromise getJson(String requestUrl);
15+
// JSPromise<HttpClientResponse>
16+
external JSPromise<JSObject> get(String requestUrl);
17+
external JSPromise<JSObject?> getJson(String requestUrl);
18+
}
19+
20+
@JS()
21+
extension type HttpClientResponse._(JSObject obj) {
22+
external JSPromise<JSString> readBody();
1723
}

lib/node/actions/tool_cache.dart

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,13 @@ extension type ToolCache(JSObject obj) {
2525
/// @param url url of tool to download
2626
/// @param dest path to download tool
2727
/// @returns path to downloaded tool
28-
// JSPromise<String>
29-
external JSPromise downloadTool(String url, [String? dest]);
28+
external JSPromise<JSString> downloadTool(String url, [String? dest]);
3029

3130
/// Extract a zip.
3231
///
3332
/// @param file path to the zip
3433
/// @returns path to the destination directory
35-
external JSPromise extractZip(String file);
34+
external JSPromise<JSString> extractZip(String file);
3635

3736
/// Caches a directory and installs it into the tool cacheDir
3837
///
@@ -41,7 +40,7 @@ extension type ToolCache(JSObject obj) {
4140
/// @param version version of the tool. semver format
4241
/// @param arch architecture of the tool. Optional.
4342
/// Defaults to machine architecture
44-
external JSPromise cacheDir(
43+
external JSPromise<JSString> cacheDir(
4544
String sourceDir,
4645
String tool,
4746
String version, [

lib/node/process.dart

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// BSD-style license that can be found in the LICENSE file.
44

55
import 'dart:js_interop';
6-
import 'dart:js_util';
6+
import 'dart:js_interop_unsafe';
77

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

1919
/// Read the environment variable [variable].
20-
String? env(String variable) => getProperty<String?>(_env, variable);
20+
String? env(String variable) {
21+
return _env.getProperty<JSString?>(variable.toJS)?.toDart;
22+
}
2123

2224
external int exitCode;
2325
}

package-lock.json

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

pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@ dependencies:
1313
dev_dependencies:
1414
args: ^2.4.0
1515
crypto: ^3.0.0
16-
dart_flutter_team_lints: ^2.0.0
16+
dart_flutter_team_lints: ^3.0.0

0 commit comments

Comments
 (0)