From 51128545a348c608dd757d2c26354ff6528b6832 Mon Sep 17 00:00:00 2001 From: Natalie Weizenbaum Date: Wed, 19 Aug 2026 15:00:26 -0700 Subject: [PATCH 1/4] Reformat with the latest Dart version --- browser_library_test/pubspec.yaml | 2 +- lib/src/github.dart | 5 +- lib/src/homebrew.dart | 5 +- lib/src/npm.dart | 5 +- lib/src/standalone/cli_platform.dart | 6 +- lib/src/utils.dart | 15 +- pubspec.yaml | 2 +- test/chocolatey_test.dart | 80 ++-- test/github_test.dart | 40 +- test/homebrew_test.dart | 51 ++- test/npm_test.dart | 548 +++++++++++++-------------- test/standalone_test.dart | 101 +++-- test/testing_test.dart | 29 +- 13 files changed, 432 insertions(+), 457 deletions(-) diff --git a/browser_library_test/pubspec.yaml b/browser_library_test/pubspec.yaml index 7f39f1d..910488c 100644 --- a/browser_library_test/pubspec.yaml +++ b/browser_library_test/pubspec.yaml @@ -3,7 +3,7 @@ version: 0.0.0 publish_to: none environment: - sdk: ">=3.2.0 <4.0.0" + sdk: ">=3.13.0 <4.0.0" dependencies: js: ^0.6.3 diff --git a/lib/src/github.dart b/lib/src/github.dart index 9134baf..bbbe7d6 100644 --- a/lib/src/github.dart +++ b/lib/src/github.dart @@ -77,9 +77,8 @@ String? _parseGit(String url) => RegExp( /// /// Returns `null` if it couldn't be parsed. String? _parseHttp(String url) { - var match = RegExp( - r"^https?://github\.com/([^/]+/[^/]+?)(\.git)?($|/)", - ).firstMatch(url); + var match = RegExp(r"^https?://github\.com/([^/]+/[^/]+?)(\.git)?($|/)") + .firstMatch(url); return match == null ? null : match[1]; } diff --git a/lib/src/homebrew.dart b/lib/src/homebrew.dart index 021ef5d..28a01d3 100644 --- a/lib/src/homebrew.dart +++ b/lib/src/homebrew.dart @@ -156,9 +156,8 @@ Future _update() async { "git", arguments: [ "push", - url( - "https://$githubUser:$githubPassword@github.com/$homebrewRepo.git", - ).toString(), + url("https://$githubUser:$githubPassword@github.com/$homebrewRepo.git") + .toString(), "HEAD:${await _originHead(repo)}", ], workingDirectory: repo, diff --git a/lib/src/npm.dart b/lib/src/npm.dart index 97d4f8e..89ceb68 100644 --- a/lib/src/npm.dart +++ b/lib/src/npm.dart @@ -457,9 +457,8 @@ Future _buildPackage() async { 'build/$_npmName.dart.js', p.join(dir.path, '$_npmName.dart.js'), ); - var allRequires = _requiresForTarget( - JSRequireTarget.all, - ).union(extractedRequires); + var allRequires = _requiresForTarget(JSRequireTarget.all) + .union(extractedRequires); var nodeRequires = _requiresForTarget(JSRequireTarget.node); var cliRequires = _requiresForTarget(JSRequireTarget.cli).union(nodeRequires); diff --git a/lib/src/standalone/cli_platform.dart b/lib/src/standalone/cli_platform.dart index b3fcebc..8f57e45 100644 --- a/lib/src/standalone/cli_platform.dart +++ b/lib/src/standalone/cli_platform.dart @@ -107,9 +107,9 @@ class CliPlatform { /// Returns whether the current platform is using musl LibC. static bool get _isCurrentPlatformMusl { - var section = Elf.fromFile( - Platform.resolvedExecutable, - )?.namedSections('.interp').firstOrNull; + var section = Elf.fromFile(Platform.resolvedExecutable) + ?.namedSections('.interp') + .firstOrNull; if (section == null) return false; var file = File(Platform.resolvedExecutable).openSync() diff --git a/lib/src/utils.dart b/lib/src/utils.dart index 09b723a..d20d12c 100644 --- a/lib/src/utils.dart +++ b/lib/src/utils.dart @@ -30,12 +30,10 @@ import 'package:yaml/yaml.dart'; import 'info.dart'; /// The raw YAML of the pubspec. -final rawPubspec = - loadYaml( - File('pubspec.yaml').readAsStringSync(), - sourceUrl: Uri(path: 'pubspec.yaml'), - ) - as Map; +final rawPubspec = loadYaml( + File('pubspec.yaml').readAsStringSync(), + sourceUrl: Uri(path: 'pubspec.yaml'), +) as Map; /// The set of entrypoint paths for executables defined by this package. Set get entrypoints => p.PathSet.of(executables.value.values); @@ -149,9 +147,8 @@ String? _readLicense(String dir) { // If there are multiple possibilities, choose the shortest one because it's // most likely to be canonical. - return File( - p.join(dir, minBy(possibilities, (path) => path.length)), - ).readAsStringSync(); + return File(p.join(dir, minBy(possibilities, (path) => path.length))) + .readAsStringSync(); } /// Ensure that the `build/` directory exists. diff --git a/pubspec.yaml b/pubspec.yaml index c3c1de6..b4ae678 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -4,7 +4,7 @@ description: Grinder tasks for releasing Dart CLI packages. homepage: https://github.com/google/dart_cli_pkg environment: - sdk: ">=3.8.0 <4.0.0" + sdk: ">=3.13.0 <4.0.0" dependencies: archive: ^4.0.6 diff --git a/test/chocolatey_test.dart b/test/chocolatey_test.dart index cef897b..7af0321 100644 --- a/test/chocolatey_test.dart +++ b/test/chocolatey_test.dart @@ -126,13 +126,13 @@ void main() { "it contains multiple s", () => assertNuspecError( """ - - - - - - - """, + + + + + + + """, "The nuspec may not have multiple package > metadata > " "dependencies elements.", ), @@ -148,20 +148,20 @@ void main() { .file( "my_app/build/chocolatey/my_app_choco.nuspec", _equalsXml(""" - - - - my_app_choco - A good app - Natalie Weizenbaum - 1.2.3 - - - - - - """), + + + + my_app_choco + A good app + Natalie Weizenbaum + 1.2.3 + + + + + + """), ) .validate(); }); @@ -171,10 +171,10 @@ void main() { () async { await d.package(pubspec, _enableChocolatey(), [ _nuspec(""" - - - - """), + + + + """), ]).create(); await (await grind(["pkg-chocolatey"])).shouldExit(0); @@ -183,21 +183,21 @@ void main() { .file( "my_app/build/chocolatey/my_app_choco.nuspec", _equalsXml(""" - - - - my_app_choco - A good app - Natalie Weizenbaum - - - - - 1.2.3 - - - """), + + + + my_app_choco + A good app + Natalie Weizenbaum + + + + + 1.2.3 + + + """), ) .validate(); }, diff --git a/test/github_test.dart b/test/github_test.dart index 0a73dce..5ffdd6e 100644 --- a/test/github_test.dart +++ b/test/github_test.dart @@ -306,13 +306,11 @@ void main() { }, ); - test( - "prefers an explicit username to the GITHUB_PASSWORD environment variable", - () async { - await d.package(pubspecWithHomepage, _enableGithub()).create(); - await assertPassword("pwd", environment: {"GITHUB_PASSWORD": "wrong"}); - }, - ); + test("prefers an explicit username to the GITHUB_PASSWORD environment " + "variable", () async { + await d.package(pubspecWithHomepage, _enableGithub()).create(); + await assertPassword("pwd", environment: {"GITHUB_PASSWORD": "wrong"}); + }); }); group("bearer token", () { @@ -359,21 +357,19 @@ void main() { }, ); - test( - "prefers an explicit username to the GITHUB_PASSWORD environment variable", - () async { - await d - .package( - pubspecWithHomepage, - _enableGithub(password: false, bearer: true), - ) - .create(); - await assertToken( - "secret", - environment: {"GITHUB_BEARER_TOKEN": "wrong"}, - ); - }, - ); + test("prefers an explicit username to the GITHUB_PASSWORD environment " + "variable", () async { + await d + .package( + pubspecWithHomepage, + _enableGithub(password: false, bearer: true), + ) + .create(); + await assertToken( + "secret", + environment: {"GITHUB_BEARER_TOKEN": "wrong"}, + ); + }); }); group("release notes", () { diff --git a/test/homebrew_test.dart b/test/homebrew_test.dart index d42a545..133feb4 100644 --- a/test/homebrew_test.dart +++ b/test/homebrew_test.dart @@ -53,10 +53,10 @@ void main() { await d.dir("me/homebrew.git", [ d.file("my_app.rb", """ - class MyApp < Formula - sha256 "original sha" - end - """), + class MyApp < Formula + sha256 "original sha" + end + """), ]).create(); await _makeRepo("me/homebrew.git"); @@ -82,10 +82,10 @@ void main() { await d.dir("me/homebrew.git", [ d.file("my_app.rb", """ - class MyApp < Formula - url "original url" - end - """), + class MyApp < Formula + url "original url" + end + """), ]).create(); await _makeRepo("me/homebrew.git"); @@ -446,9 +446,8 @@ void main() { await git(["tag", "1.2.3"]); await _createHomebrewRepo(); - File( - d.path("me/homebrew.git/my_app.rb"), - ).renameSync(d.path("me/homebrew.git/my_app@1.0.0.rb")); + File(d.path("me/homebrew.git/my_app.rb")) + .renameSync(d.path("me/homebrew.git/my_app@1.0.0.rb")); await _commitAll("me/homebrew.git", "Rename the formula"); var server = await _serveArchive(); @@ -477,26 +476,26 @@ void main() { /// If [repo] is `false`, this won't set `pkg.homebrewRepo`. String _enableHomebrew({String? config, bool repo = true}) => """ - void main(List args) { - ${config ?? ''} - ${repo ? 'pkg.homebrewRepo.value = "me/homebrew";' : ''} - pkg.githubRepo.value = "me/app"; - pkg.githubUser.value = "usr"; - pkg.githubPassword.value = "pwd"; - pkg.addHomebrewTasks(); - grind(args); - } -"""; + void main(List args) { + ${config ?? ''} + ${repo ? 'pkg.homebrewRepo.value = "me/homebrew";' : ''} + pkg.githubRepo.value = "me/app"; + pkg.githubUser.value = "usr"; + pkg.githubPassword.value = "pwd"; + pkg.addHomebrewTasks(); + grind(args); + } + """; /// Creates a default Homebrew repository in `me/homebrew.git`. Future _createHomebrewRepo() async { await d.dir("me/homebrew.git", [ d.file("my_app.rb", """ - class MyApp < Formula - url "original url" - sha256 "original sha" - end - """), + class MyApp < Formula + url "original url" + sha256 "original sha" + end + """), ]).create(); await _makeRepo("me/homebrew.git"); } diff --git a/test/npm_test.dart b/test/npm_test.dart index 1fd16c3..1eeeade 100644 --- a/test/npm_test.dart +++ b/test/npm_test.dart @@ -117,13 +117,13 @@ void main() { .package( pubspec, """ - void main(List args) { - pkg.jsModuleMainLibrary.value = "lib/src/exports.dart"; + void main(List args) { + pkg.jsModuleMainLibrary.value = "lib/src/exports.dart"; - pkg.addNpmTasks(); - grind(args); - } - """, + pkg.addNpmTasks(); + grind(args); + } + """, [ _packageJson, d.dir("lib/src", [_exportsHello('"Hi, there!"')]), @@ -153,14 +153,14 @@ void main() { .package( pubspec, """ - void main(List args) { - pkg.jsModuleMainLibrary.value = "lib/src/exports.dart"; - pkg.jsRequires.value = [$requireDeclarations]; + void main(List args) { + pkg.jsModuleMainLibrary.value = "lib/src/exports.dart"; + pkg.jsRequires.value = [$requireDeclarations]; - pkg.addNpmTasks(); - grind(args); - } - """, + pkg.addNpmTasks(); + grind(args); + } + """, [ _packageJson, d.dir("lib/src", [_exportsHello('osLoaded')]), @@ -249,9 +249,9 @@ void main() { () async { expect( hasAccessToRequire(""" - pkg.JSRequire('http', target: pkg.JSRequireTarget.node), - pkg.JSRequire('os', target: pkg.JSRequireTarget.defaultTarget), - """), + pkg.JSRequire('http', target: pkg.JSRequireTarget.node), + pkg.JSRequire('os', target: pkg.JSRequireTarget.defaultTarget), + """), completion(isFalse), ); }, @@ -309,14 +309,14 @@ void main() { .package( pubspec, """ - void main(List args) { - pkg.jsModuleMainLibrary.value = "lib/src/exports.dart"; - pkg.jsRequires.value.add($requireDeclaration); + void main(List args) { + pkg.jsModuleMainLibrary.value = "lib/src/exports.dart"; + pkg.jsRequires.value.add($requireDeclaration); - pkg.addNpmTasks(); - grind(args); - } - """, + pkg.addNpmTasks(); + grind(args); + } + """, [ _packageJson, d.dir("lib/src", [d.file("exports.dart", "void main() {}")]), @@ -394,13 +394,13 @@ void main() { await d.dir("my_app/bin", [ d.file("foo.dart", r""" - void main() { - print("node: ${const bool.fromEnvironment('node')}"); - print("version: ${const String.fromEnvironment('version')}"); - print("dart-version: " - "${const String.fromEnvironment('dart-version')}"); - } - """), + void main() { + print("node: ${const bool.fromEnvironment('node')}"); + print("version: ${const String.fromEnvironment('version')}"); + print("dart-version: " + "${const String.fromEnvironment('dart-version')}"); + } + """), ]).create(); await (await grind(["pkg-npm-dev"])).shouldExit(); @@ -426,14 +426,14 @@ void main() { .package( pubspec, """ - void main(List args) { - pkg.environmentConstants.value["my-const"] = - ${riskyArgStringLiteral(invokedByDart: true)}; + void main(List args) { + pkg.environmentConstants.value["my-const"] = + ${riskyArgStringLiteral(invokedByDart: true)}; - pkg.addNpmTasks(); - grind(args); - } - """, + pkg.addNpmTasks(); + grind(args); + } + """, [_packageJson], ) .create(); @@ -532,12 +532,12 @@ void main() { d.dir("lib/src", [_exportsHello('"Hi, there!"')]), d.dir("bin", [ d.file("exec.dart", r""" - import '../lib/src/exports.dart' as lib; + import '../lib/src/exports.dart' as lib; - void main(List args) { - print("Hello from exec"); - } - """), + void main(List args) { + print("Hello from exec"); + } + """), ]), ], ).create(); @@ -585,12 +585,12 @@ void main() { .package( pubspec, r""" - void main(List args) { - pkg.addNpmTasks(); - pkg.jsForceStrictMode.value = true; - grind(args); - } - """, + void main(List args) { + pkg.addNpmTasks(); + pkg.jsForceStrictMode.value = true; + grind(args); + } + """, [ _packageJson, d.dir("bin", [d.file("foo.dart", strictOrSloppy)]), @@ -645,16 +645,16 @@ void main() { .package( pubspec, """ - void main(List args) { - pkg.npmPackageJson.value = { - "name": "my_app", - "another": "attribute" - }; - - pkg.addNpmTasks(); - grind(args); - } - """, + void main(List args) { + pkg.npmPackageJson.value = { + "name": "my_app", + "another": "attribute" + }; + + pkg.addNpmTasks(); + grind(args); + } + """, [ d.file( "package.json", @@ -738,13 +738,13 @@ void main() { .package( pubspec, """ - void main(List args) { - pkg.jsModuleMainLibrary.value = "lib/src/module_main.dart"; + void main(List args) { + pkg.jsModuleMainLibrary.value = "lib/src/module_main.dart"; - pkg.addNpmTasks(); - grind(args); - } - """, + pkg.addNpmTasks(); + grind(args); + } + """, [ _packageJson, d.dir("lib/src", [d.file("module_main.dart", "void main() {}")]), @@ -827,18 +827,18 @@ void main() { .package( pubspec, """ - void main(List args) { - pkg.jsModuleMainLibrary.value = "lib/src/exports.dart"; - pkg.jsRequires.value = [ - pkg.JSRequire('util', target: pkg.JSRequireTarget.cli), - pkg.JSRequire('os', target: pkg.JSRequireTarget.node), - ]; - pkg.jsEsmExports.value = {'hello'}; - - pkg.addNpmTasks(); - grind(args); - } - """, + void main(List args) { + pkg.jsModuleMainLibrary.value = "lib/src/exports.dart"; + pkg.jsRequires.value = [ + pkg.JSRequire('util', target: pkg.JSRequireTarget.cli), + pkg.JSRequire('os', target: pkg.JSRequireTarget.node), + ]; + pkg.jsEsmExports.value = {'hello'}; + + pkg.addNpmTasks(); + grind(args); + } + """, [ _packageJson, d.dir("lib/src", [_exportsHello('osLoaded')]), @@ -1031,10 +1031,10 @@ void main() { .package( pubspec, """ - void main(List args) { - print(pkg.npmDistTag); - } - """, + void main(List args) { + print(pkg.npmDistTag); + } + """, [_packageJson], ) .create(); @@ -1048,10 +1048,10 @@ void main() { await d.package( {...pubspec, "version": "1.2.3-foo.4.bar"}, """ - void main(List args) { - print(pkg.npmDistTag); - } - """, + void main(List args) { + print(pkg.npmDistTag); + } + """, [_packageJson], ).create(); @@ -1064,10 +1064,10 @@ void main() { await d.package( {...pubspec, "version": "1.2.3-4.foo"}, """ - void main(List args) { - print(pkg.npmDistTag); - } - """, + void main(List args) { + print(pkg.npmDistTag); + } + """, [_packageJson], ).create(); @@ -1081,11 +1081,11 @@ void main() { .package( pubspec, """ - void main(List args) { - pkg.npmDistTag.value = "qux"; - print(pkg.npmDistTag); - } - """, + void main(List args) { + pkg.npmDistTag.value = "qux"; + print(pkg.npmDistTag); + } + """, [_packageJson], ) .create(); @@ -1120,13 +1120,13 @@ void main() { .package( pubspec, """ - void main(List args) { - pkg.npmReadme.value = "Other README text"; + void main(List args) { + pkg.npmReadme.value = "Other README text"; - pkg.addNpmTasks(); - grind(args); - } - """, + pkg.addNpmTasks(); + grind(args); + } + """, [_packageJson, d.file("README.md", "Some README text")], ) .create(); @@ -1217,12 +1217,12 @@ void main() { .package( pubspec, """ - void main(List args) { - pkg.npmAdditionalFiles.value = {"foo/bar/baz.txt": "contents"}; - pkg.addNpmTasks(); - grind(args); - } - """, + void main(List args) { + pkg.npmAdditionalFiles.value = {"foo/bar/baz.txt": "contents"}; + pkg.addNpmTasks(); + grind(args); + } + """, [_packageJson], ) .create(); @@ -1236,12 +1236,12 @@ void main() { .package( pubspec, """ - void main(List args) { - pkg.npmAdditionalFiles.value = {"/foo/bar/baz.txt": "contents"}; - pkg.addNpmTasks(); - grind(args); - } - """, + void main(List args) { + pkg.npmAdditionalFiles.value = {"/foo/bar/baz.txt": "contents"}; + pkg.addNpmTasks(); + grind(args); + } + """, [_packageJson], ) .create(); @@ -1267,36 +1267,36 @@ void main() { .package( pubspec, r""" - void main(List args) { - pkg.addNpmTasks(); - pkg.jsForceStrictMode.value = true; - grind(args); - } - """, + void main(List args) { + pkg.addNpmTasks(); + pkg.jsForceStrictMode.value = true; + grind(args); + } + """, [ _packageJson, d.dir("bin", [ d.file("foo.dart", """ - import 'package:cli_pkg/js.dart'; - import 'package:js/js.dart'; - - @JS("Function") - class _JSFunction { - external _JSFunction(String arguments, String body); - external Object? call(); - } - - void main() { - try { - wrapJSExceptions(() { - _JSFunction("error", - "throw \${${json.encode(expression)}};").call(); - }); - } catch (_, stackTrace) { - print(stackTrace); - } - } - """), + import 'package:cli_pkg/js.dart'; + import 'package:js/js.dart'; + + @JS("Function") + class _JSFunction { + external _JSFunction(String arguments, String body); + external Object? call(); + } + + void main() { + try { + wrapJSExceptions(() { + _JSFunction("error", + "throw \${${json.encode(expression)}};").call(); + }); + } catch (_, stackTrace) { + print(stackTrace); + } + } + """), ]), ], ) @@ -1421,14 +1421,14 @@ void main() { .package( pubspec, """ - void main(List args) { - pkg.jsModuleMainLibrary.value = "lib/src/exports.dart"; - pkg.jsRequires.value = [$requireDeclarations]; + void main(List args) { + pkg.jsModuleMainLibrary.value = "lib/src/exports.dart"; + pkg.jsRequires.value = [$requireDeclarations]; - pkg.addNpmTasks(); - grind(args); - } - """, + pkg.addNpmTasks(); + grind(args); + } + """, [ _packageJson, d.dir("lib/src", [d.file("exports.dart", dartExports)]), @@ -1470,33 +1470,33 @@ void main() { "pkg.JSRequire('os', target: pkg.JSRequireTarget.node, " "lazy: true, identifier: 'os_lazy')", """ - import 'package:js/js.dart'; + import 'package:js/js.dart'; - @JS() - class Exports { - external set os(Object? value); - external set osLazy(Object? value); - } + @JS() + class Exports { + external set os(Object? value); + external set osLazy(Object? value); + } - @JS() - external Exports get exports; + @JS() + external Exports get exports; - @JS('os') - external Object? os; + @JS('os') + external Object? os; - @JS('os_lazy') - external Object? get osLazy; + @JS('os_lazy') + external Object? get osLazy; - void main() { - exports.os = os; - exports.osLazy = osLazy; - } - """, + void main() { + exports.os = os; + exports.osLazy = osLazy; + } + """, """ - var my_app = require("my_app"); + var my_app = require("my_app"); - console.log(my_app.os === my_app.osLazy); - """, + console.log(my_app.os === my_app.osLazy); + """, ), completion(isTrue), ); @@ -1508,33 +1508,33 @@ void main() { "pkg.JSRequire('module_not_found', " "target: pkg.JSRequireTarget.node, lazy: true)", """ - import 'package:js/js.dart'; - import 'package:js/js_util.dart'; + import 'package:js/js.dart'; + import 'package:js/js_util.dart'; - @JS() - class Exports { - external set run(Object? value); - } + @JS() + class Exports { + external set run(Object? value); + } - @JS() - external Exports get exports; + @JS() + external Exports get exports; - @JS('module_not_found') - external Object? get moduleNotFound; + @JS('module_not_found') + external Object? get moduleNotFound; - void main() { - exports.run = allowInterop(() => moduleNotFound); - } - """, + void main() { + exports.run = allowInterop(() => moduleNotFound); + } + """, """ - var my_app = require("my_app"); - - try { - myapp.run() - } catch (_) { - console.log(true) - } - """, + var my_app = require("my_app"); + + try { + myapp.run() + } catch (_) { + console.log(true) + } + """, ), completion(isTrue), ); @@ -1547,33 +1547,33 @@ void main() { "pkg.JSRequire('os', target: pkg.JSRequireTarget.node, " "optional: true, identifier: 'os_optional')", """ - import 'package:js/js.dart'; + import 'package:js/js.dart'; - @JS() - class Exports { - external set os(Object? value); - external set osOptional(Object? value); - } + @JS() + class Exports { + external set os(Object? value); + external set osOptional(Object? value); + } - @JS() - external Exports get exports; + @JS() + external Exports get exports; - @JS('os') - external Object? os; + @JS('os') + external Object? os; - @JS('os_optional') - external Object? osOptional; + @JS('os_optional') + external Object? osOptional; - void main() { - exports.os = os; - exports.osOptional = osOptional; - } - """, + void main() { + exports.os = os; + exports.osOptional = osOptional; + } + """, """ - var my_app = require("my_app"); + var my_app = require("my_app"); - console.log(my_app.os === my_app.osOptional); - """, + console.log(my_app.os === my_app.osOptional); + """, ), completion(isTrue), ); @@ -1587,29 +1587,29 @@ void main() { "pkg.JSRequire('module_not_found', " "target: pkg.JSRequireTarget.node, optional: true)", """ - import 'package:js/js.dart'; - import 'package:js/js_util.dart'; + import 'package:js/js.dart'; + import 'package:js/js_util.dart'; - @JS() - class Exports { - external set moduleNotFound(Object? value); - } + @JS() + class Exports { + external set moduleNotFound(Object? value); + } - @JS() - external Exports get exports; + @JS() + external Exports get exports; - @JS('module_not_found') - external Object? moduleNotFound; + @JS('module_not_found') + external Object? moduleNotFound; - void main() { - exports.moduleNotFound = moduleNotFound; - } - """, + void main() { + exports.moduleNotFound = moduleNotFound; + } + """, """ - var my_app = require("my_app"); + var my_app = require("my_app"); - console.log(my_app.moduleNotFound === null) - """, + console.log(my_app.moduleNotFound === null) + """, ), completion(isTrue), ); @@ -1624,33 +1624,33 @@ void main() { "lazy: true, optional: true, " "identifier: 'os_lazy_optional')", """ - import 'package:js/js.dart'; + import 'package:js/js.dart'; - @JS() - class Exports { - external set os(Object? value); - external set osLazyOptional(Object? value); - } + @JS() + class Exports { + external set os(Object? value); + external set osLazyOptional(Object? value); + } - @JS() - external Exports get exports; + @JS() + external Exports get exports; - @JS('os') - external Object? os; + @JS('os') + external Object? os; - @JS('os_lazy_optional') - external Object? get osLazyOptional; + @JS('os_lazy_optional') + external Object? get osLazyOptional; - void main() { - exports.os = os; - exports.osLazyOptional = osLazyOptional; - } - """, + void main() { + exports.os = os; + exports.osLazyOptional = osLazyOptional; + } + """, """ - var my_app = require("my_app"); + var my_app = require("my_app"); - console.log(my_app.os === my_app.osLazyOptional); - """, + console.log(my_app.os === my_app.osLazyOptional); + """, ), completion(isTrue), ); @@ -1664,29 +1664,29 @@ void main() { "target: pkg.JSRequireTarget.node, lazy: true, " "optional: true)", """ - import 'package:js/js.dart'; - import 'package:js/js_util.dart'; + import 'package:js/js.dart'; + import 'package:js/js_util.dart'; - @JS() - class Exports { - external set run(Object? value); - } + @JS() + class Exports { + external set run(Object? value); + } - @JS() - external Exports get exports; + @JS() + external Exports get exports; - @JS('module_not_found') - external Object? get moduleNotFound; + @JS('module_not_found') + external Object? get moduleNotFound; - void main() { - exports.run = allowInterop(() => moduleNotFound); - } - """, + void main() { + exports.run = allowInterop(() => moduleNotFound); + } + """, """ - var my_app = require("my_app"); + var my_app = require("my_app"); - console.log(my_app.run() === null) - """, + console.log(my_app.run() === null) + """, ), completion(isTrue), ); @@ -1701,22 +1701,22 @@ void main() { /// The [expression] has access to an `osLoaded` field that's true if Node.js's /// `os` core library has been loaded and `false` otherwise. d.FileDescriptor _exportsHello(String expression) => d.file("exports.dart", """ - import 'package:js/js.dart'; + import 'package:js/js.dart'; - @JS() - class Exports { - external set hello(Object value); - } + @JS() + class Exports { + external set hello(Object value); + } - @JS() - external Exports get exports; + @JS() + external Exports get exports; - @JS('os') - external Object? os; + @JS('os') + external Object? os; - final osLoaded = os != null; + final osLoaded = os != null; - void main() { - exports.hello = ($expression); - } - """); + void main() { + exports.hello = ($expression); + } +"""); diff --git a/test/standalone_test.dart b/test/standalone_test.dart index 044aa2d..1357776 100644 --- a/test/standalone_test.dart +++ b/test/standalone_test.dart @@ -49,9 +49,8 @@ void main() { test("default to pkg.dartName", () async { await d.package(pubspec, _enableStandalone).create(); - await (await grind([ - "pkg-standalone-${CliPlatform.current}", - ])).shouldExit(0); + await (await grind(["pkg-standalone-${CliPlatform.current}"])) + .shouldExit(0); await d.archive("my_app/build/my_app-1.2.3-$_archiveSuffix", [ d.dir("my_app"), @@ -67,9 +66,8 @@ void main() { } """).create(); - await (await grind([ - "pkg-standalone-${CliPlatform.current}", - ])).shouldExit(0); + await (await grind(["pkg-standalone-${CliPlatform.current}"])) + .shouldExit(0); await d.archive("my_app/build/my-app-1.2.3-$_archiveSuffix", [ d.dir("my-app"), @@ -86,9 +84,8 @@ void main() { } """).create(); - await (await grind([ - "pkg-standalone-${CliPlatform.current}", - ])).shouldExit(0); + await (await grind(["pkg-standalone-${CliPlatform.current}"])) + .shouldExit(0); await d.archive("my_app/build/my-sa-app-1.2.3-$_archiveSuffix", [ d.dir("my-sa-app"), @@ -105,9 +102,8 @@ void main() { test("default to the pubspec's executables", () async { await d.package(pubspec, _enableStandalone).create(); - await (await grind([ - "pkg-standalone-${CliPlatform.current}", - ])).shouldExit(0); + await (await grind(["pkg-standalone-${CliPlatform.current}"])) + .shouldExit(0); await d.archive("my_app/build/my_app-1.2.3-$_archiveSuffix", [ d.dir("my_app", [ @@ -133,9 +129,8 @@ void main() { } """).create(); - await (await grind([ - "pkg-standalone-${CliPlatform.current}", - ])).shouldExit(0); + await (await grind(["pkg-standalone-${CliPlatform.current}"])) + .shouldExit(0); await d.archive("my_app/build/my_app-1.2.3-$_archiveSuffix", [ d.dir("my_app", [ @@ -160,9 +155,8 @@ void main() { } """).create(); - await (await grind([ - "pkg-standalone-${CliPlatform.current}", - ])).shouldExit(0); + await (await grind(["pkg-standalone-${CliPlatform.current}"])) + .shouldExit(0); await d.archive("my_app/build/my_app-1.2.3-$_archiveSuffix", [ d.dir("my_app", [ @@ -187,9 +181,8 @@ void main() { } """).create(); - await (await grind([ - "pkg-standalone-${CliPlatform.current}", - ])).shouldExit(0); + await (await grind(["pkg-standalone-${CliPlatform.current}"])) + .shouldExit(0); await d.archive("my_app/build/my_app-1.2.3-$_archiveSuffix", [ d.dir("my_app", [ @@ -214,9 +207,8 @@ void main() { } """).create(); - await (await grind([ - "pkg-standalone-${CliPlatform.current}", - ])).shouldExit(0); + await (await grind(["pkg-standalone-${CliPlatform.current}"])) + .shouldExit(0); await d.archive("my_app/build/my_app-1.2.3-$_archiveSuffix", [ d.dir("my_app", [ @@ -250,16 +242,16 @@ void main() { }, }, """ - void main(List args) { - // TODO(nweiz): Test spaces and commas when dart-lang/sdk#46050 and - // #44995 are fixed. - pkg.environmentConstants.value["my-const"] = - ${riskyArgStringLiteral(invokedByDart: true, dartCompileExe: true)}; - - pkg.addStandaloneTasks(); - grind(args); - } - """, + void main(List args) { + // TODO(nweiz): Test spaces and commas when dart-lang/sdk#46050 and + // #44995 are fixed. + pkg.environmentConstants.value["my-const"] = + ${riskyArgStringLiteral(invokedByDart: true, dartCompileExe: true)}; + + pkg.addStandaloneTasks(); + grind(args); + } + """, ) .create(); @@ -270,9 +262,8 @@ void main() { ), ]).create(); - await (await grind([ - "pkg-standalone-${CliPlatform.current}", - ])).shouldExit(0); + await (await grind(["pkg-standalone-${CliPlatform.current}"])) + .shouldExit(0); await extract("my_app/build/my_app-1.2.3-$_archiveSuffix", "out"); // Directly @@ -311,9 +302,8 @@ void main() { await executable.shouldExit(0); // Through an absolute symlink - Link( - d.path("foo-absolute$dotBat"), - ).createSync(d.path("out/my_app/foo$dotBat")); + Link(d.path("foo-absolute$dotBat")) + .createSync(d.path("out/my_app/foo$dotBat")); executable = await TestProcess.start( d.path("foo-absolute$dotBat"), [], @@ -323,9 +313,8 @@ void main() { await executable.shouldExit(0); // Through a nested symlink - Link( - d.path("foo-nested$dotBat"), - ).createSync(d.path("foo-relative$dotBat")); + Link(d.path("foo-nested$dotBat")) + .createSync(d.path("foo-relative$dotBat")); executable = await TestProcess.start( d.path("foo-nested$dotBat"), [], @@ -393,9 +382,8 @@ void main() { [d.file("LICENSE", "Please use my code")], ) .create(); - await (await grind([ - "pkg-standalone-${CliPlatform.current}", - ])).shouldExit(0); + await (await grind(["pkg-standalone-${CliPlatform.current}"])) + .shouldExit(0); await d.archive("my_app/build/my_app-1.2.3-$_archiveSuffix", [ d.dir("my_app/src", [ @@ -414,9 +402,8 @@ void main() { test("is still generated if the package doesn't have a license", () async { await d.package(pubspec, _enableStandalone).create(); - await (await grind([ - "pkg-standalone-${CliPlatform.current}", - ])).shouldExit(0); + await (await grind(["pkg-standalone-${CliPlatform.current}"])) + .shouldExit(0); await d.archive("my_app/build/my_app-1.2.3-$_archiveSuffix", [ d.dir("my_app/src", [ @@ -571,14 +558,14 @@ void main() { "executables": {"const": "const"}, }, """ - void main(List args) { - pkg.environmentConstants.value["my-const"] = - ${riskyArgStringLiteral(invokedByDart: true, dartCompileExe: true)}; - - pkg.addStandaloneTasks(); - grind(args); - } - """, + void main(List args) { + pkg.environmentConstants.value["my-const"] = + ${riskyArgStringLiteral(invokedByDart: true, dartCompileExe: true)}; + + pkg.addStandaloneTasks(); + grind(args); + } + """, ) .create(); diff --git a/test/testing_test.dart b/test/testing_test.dart index d11b465..709a8ec 100644 --- a/test/testing_test.dart +++ b/test/testing_test.dart @@ -35,12 +35,12 @@ void main() { .package( pubspec, """ - void main(List args) { - pkg.addNpmTasks(); - pkg.addStandaloneTasks(); - grind(args); - } - """, + void main(List args) { + pkg.addNpmTasks(); + pkg.addStandaloneTasks(); + grind(args); + } + """, [ d.file("package.json", json.encode({"name": "my_app"})), ], @@ -70,12 +70,12 @@ void main() { "executables": {"bar": "foo"}, }, """ - void main(List args) { - pkg.addNpmTasks(); - pkg.addStandaloneTasks(); - grind(args); - } - """, + void main(List args) { + pkg.addNpmTasks(); + pkg.addStandaloneTasks(); + grind(args); + } + """, ) .create(); @@ -371,9 +371,8 @@ void main() { await (await grind(["pkg-npm-dev"])).shouldExit(0); // This just shouldn't throw an error. - await _testCase( - "pkg.ensureExecutableUpToDate('foo', node: true);", - ).create(); + await _testCase("pkg.ensureExecutableUpToDate('foo', node: true);") + .create(); await (await _test()).shouldExit(0); }); From d1eeba02babc96bc5679b3989d5174262a76ff09 Mon Sep 17 00:00:00 2001 From: Natalie Weizenbaum Date: Wed, 19 Aug 2026 15:01:09 -0700 Subject: [PATCH 2/4] Run automated fixes --- lib/src/config_variable.dart | 10 ++++------ lib/src/js_require.dart | 2 +- lib/src/js_require_set.dart | 5 ++--- lib/src/last_changelog_section.dart | 2 +- lib/src/standalone/architecture.dart | 2 +- lib/src/standalone/cli_platform.dart | 2 +- lib/src/standalone/operating_system.dart | 2 +- test/descriptor/archive.dart | 2 +- 8 files changed, 12 insertions(+), 15 deletions(-) diff --git a/lib/src/config_variable.dart b/lib/src/config_variable.dart index d7201cf..8eea2a1 100644 --- a/lib/src/config_variable.dart +++ b/lib/src/config_variable.dart @@ -105,15 +105,13 @@ class ConfigVariable { _cached = false; } - ConfigVariable._fn(T Function() callback, {T Function(T)? freeze}) + new _fn(T Function() callback, {this._freeze}) : _callback = callback, - _defaultCallback = callback, - _freeze = freeze; + _defaultCallback = callback; - ConfigVariable._value(this._value, {T Function(T)? freeze}) + new _value(this._value, {this._freeze}) : _defaultValue = _value, - _cached = true, - _freeze = freeze; + _cached = true; @override String toString() => value.toString(); diff --git a/lib/src/js_require.dart b/lib/src/js_require.dart index fc6ecf9..cfc5b67 100644 --- a/lib/src/js_require.dart +++ b/lib/src/js_require.dart @@ -53,7 +53,7 @@ class JSRequire { /// This defaults to [JSRequireTarget.all]. final JSRequireTarget target; - JSRequire( + new( this.package, { String? identifier, JSRequireTarget? target, diff --git a/lib/src/js_require_set.dart b/lib/src/js_require_set.dart index ae89665..f303e25 100644 --- a/lib/src/js_require_set.dart +++ b/lib/src/js_require_set.dart @@ -27,14 +27,13 @@ final _equality = EqualityBy( @internal class JSRequireSet extends EqualitySet { /// Creates an empty set. - JSRequireSet() : super(_equality); + new() : super(_equality); /// Creates a set containing [requires]. /// /// If a require with the same identifier appears multiple times in /// [requires], the first one takes precedence. - JSRequireSet.of(Iterable requires) - : super.from(_equality, requires); + new of(Iterable requires) : super.from(_equality, requires); @override JSRequireSet union(Set other) => diff --git a/lib/src/last_changelog_section.dart b/lib/src/last_changelog_section.dart index 38f12e1..38c769b 100644 --- a/lib/src/last_changelog_section.dart +++ b/lib/src/last_changelog_section.dart @@ -55,7 +55,7 @@ class _Extractor { /// more deeply-nested blocks. final _indentationLevels = []; - _Extractor(String text, {Object? sourceUrl}) + new(String text, {Object? sourceUrl}) : _scanner = StringScanner(text, sourceUrl: sourceUrl); String extract(Version version) { diff --git a/lib/src/standalone/architecture.dart b/lib/src/standalone/architecture.dart index 0fb25c4..c02d20d 100644 --- a/lib/src/standalone/architecture.dart +++ b/lib/src/standalone/architecture.dart @@ -41,7 +41,7 @@ enum Architecture { /// Whether this is a 64-bit RISCV architecture. bool get isRiscv64 => this == riscv64; - factory Architecture.parse(String name) => switch (name) { + factory parse(String name) => switch (name) { "arm" => Architecture.arm, "arm64" => Architecture.arm64, "ia32" => Architecture.ia32, diff --git a/lib/src/standalone/cli_platform.dart b/lib/src/standalone/cli_platform.dart index 8f57e45..9513da5 100644 --- a/lib/src/standalone/cli_platform.dart +++ b/lib/src/standalone/cli_platform.dart @@ -119,7 +119,7 @@ class CliPlatform { return p.basename(interp).startsWith('ld-musl-'); } - CliPlatform(this.os, this.arch, {bool musl = false}) : isMusl = musl { + new(this.os, this.arch, {bool musl = false}) : isMusl = musl { if (!_abiStrings.contains('${os}_$arch')) { fail("Unknown or unsupported platform $os-$arch!"); } diff --git a/lib/src/standalone/operating_system.dart b/lib/src/standalone/operating_system.dart index 6fee406..012af2e 100644 --- a/lib/src/standalone/operating_system.dart +++ b/lib/src/standalone/operating_system.dart @@ -41,7 +41,7 @@ enum OperatingSystem { /// Whether this represents Windows. bool get isWindows => this == windows; - factory OperatingSystem.parse(String name) => switch (name) { + factory parse(String name) => switch (name) { "android" => OperatingSystem.android, "fuchsia" => OperatingSystem.fuchsia, "ios" => OperatingSystem.ios, diff --git a/test/descriptor/archive.dart b/test/descriptor/archive.dart index 5bc4aef..8e2beec 100644 --- a/test/descriptor/archive.dart +++ b/test/descriptor/archive.dart @@ -75,7 +75,7 @@ class ArchiveDescriptor extends Descriptor implements FileDescriptor { )).expand((files) => files); } - ArchiveDescriptor(super.name, Iterable contents) + new(super.name, Iterable contents) : contents = List.unmodifiable(contents); @override From 2ed674be0dfcd91e3d54f308608cb840e307fa44 Mon Sep 17 00:00:00 2001 From: Natalie Weizenbaum Date: Wed, 19 Aug 2026 15:24:02 -0700 Subject: [PATCH 3/4] Use primary constructors --- lib/src/js_require.dart | 39 ++++++++++++---------------- lib/src/last_changelog_section.dart | 7 ++--- lib/src/standalone/cli_platform.dart | 13 +++++----- test/descriptor/archive.dart | 9 +++---- 4 files changed, 29 insertions(+), 39 deletions(-) diff --git a/lib/src/js_require.dart b/lib/src/js_require.dart index cfc5b67..92e8b6f 100644 --- a/lib/src/js_require.dart +++ b/lib/src/js_require.dart @@ -22,14 +22,11 @@ import 'js_require_target.dart'; /// /// Note that if [jsEsmExports] is set, ESM files with `import`s are generated /// in addition to CJS files with `require()`. -class JSRequire { +class JSRequire( /// The argument to the `require()` function. - final String package; - - /// The global identifier to assign to the result of `require()`. - /// - /// This defaults to a valid JS identifier based on [package]. - final String identifier; + final String package, { + String? identifier, + JSRequireTarget? target, /// Whether the dependency is loaded lazily. /// @@ -38,7 +35,7 @@ class JSRequire { /// when this package is loaded. /// /// This defaults to false. - final bool lazy; + final bool lazy = false, /// Whether the dependency is optional. /// @@ -46,25 +43,21 @@ class JSRequire { /// rather than throwing an error. /// /// This defaults to false. - final bool optional; + final bool optional = false, +}) { + /// The global identifier to assign to the result of `require()`. + /// + /// This defaults to a valid JS identifier based on [package]. + final String identifier = + identifier ?? + package + .replaceFirst(RegExp(r'^@'), '') + .replaceAll(RegExp(r'[^a-zA-Z0-9_]'), '_'); /// The target in which to include this require. /// /// This defaults to [JSRequireTarget.all]. - final JSRequireTarget target; - - new( - this.package, { - String? identifier, - JSRequireTarget? target, - this.lazy = false, - this.optional = false, - }) : identifier = - identifier ?? - package - .replaceFirst(RegExp(r'^@'), '') - .replaceAll(RegExp(r'[^a-zA-Z0-9_]'), '_'), - target = target ?? JSRequireTarget.all; + final JSRequireTarget target = target ?? JSRequireTarget.all; @override String toString() => "const $identifier = require('$package') on $target"; diff --git a/lib/src/last_changelog_section.dart b/lib/src/last_changelog_section.dart index 38c769b..5d13151 100644 --- a/lib/src/last_changelog_section.dart +++ b/lib/src/last_changelog_section.dart @@ -39,9 +39,9 @@ String lastChangelogSection( /// A class that extracts the first entry from a changelog, reformatted to /// remove line breaks that will show up in GitHub release notes. -class _Extractor { +class _Extractor(String text, {Object? sourceUrl}) { /// The scanner that scans the changelog. - final StringScanner _scanner; + final StringScanner _scanner = StringScanner(text, sourceUrl: sourceUrl); /// The buffer to which to write the extracted entry. final _buffer = StringBuffer(); @@ -55,9 +55,6 @@ class _Extractor { /// more deeply-nested blocks. final _indentationLevels = []; - new(String text, {Object? sourceUrl}) - : _scanner = StringScanner(text, sourceUrl: sourceUrl); - String extract(Version version) { if (!_scanner.scan( RegExp("## ${RegExp.escape(version.toString())}\r?\n"), diff --git a/lib/src/standalone/cli_platform.dart b/lib/src/standalone/cli_platform.dart index 9513da5..d64f177 100644 --- a/lib/src/standalone/cli_platform.dart +++ b/lib/src/standalone/cli_platform.dart @@ -42,17 +42,18 @@ final _abiStrings = { /// A struct representing a platform for which we can build standalone /// executables. -class CliPlatform { +class CliPlatform( /// The operating system. - final OperatingSystem os; + final OperatingSystem os, /// The CPU architecture, such as "ia32" or "arm64". - final Architecture arch; - + final Architecture arch, { + bool musl = false, +}) { /// Whether the executable should be built to use musl LibC instead of glibc. /// /// This is only ever true if [os] is "linux". - final bool isMusl; + final bool isMusl = musl; /// Whether this is the same platform as the running Dart executable. bool get isCurrent => this == current; @@ -119,7 +120,7 @@ class CliPlatform { return p.basename(interp).startsWith('ld-musl-'); } - new(this.os, this.arch, {bool musl = false}) : isMusl = musl { + this { if (!_abiStrings.contains('${os}_$arch')) { fail("Unknown or unsupported platform $os-$arch!"); } diff --git a/test/descriptor/archive.dart b/test/descriptor/archive.dart index 8e2beec..1b4d86c 100644 --- a/test/descriptor/archive.dart +++ b/test/descriptor/archive.dart @@ -26,9 +26,11 @@ import '../utils.dart'; /// A [Descriptor] describing files in a Tar or Zip archive. /// /// The format is determined by the descriptor's file extension. -class ArchiveDescriptor extends Descriptor implements FileDescriptor { +class ArchiveDescriptor(super.name, Iterable contents) + extends Descriptor + implements FileDescriptor { /// Descriptors for entries in this archive. - final List contents; + final List contents = List.unmodifiable(contents); /// Returns a `package:archive` [Archive] object that contains the contents of /// this file. @@ -75,9 +77,6 @@ class ArchiveDescriptor extends Descriptor implements FileDescriptor { )).expand((files) => files); } - new(super.name, Iterable contents) - : contents = List.unmodifiable(contents); - @override Future create([String? parent]) async { var path = p.join(parent ?? sandbox, name); From cee9ed610272e232b33253a3ec21575a2548c5a6 Mon Sep 17 00:00:00 2001 From: Natalie Weizenbaum Date: Wed, 19 Aug 2026 16:58:48 -0700 Subject: [PATCH 4/4] Use dot shorthands --- browser_library_test/tool/grind.dart | 10 ++-- lib/src/js_require.dart | 2 +- lib/src/npm.dart | 19 +++---- lib/src/pub.dart | 2 +- lib/src/standalone.dart | 18 +++---- lib/src/standalone/architecture.dart | 12 ++--- lib/src/standalone/cli_platform.dart | 4 +- lib/src/standalone/operating_system.dart | 16 +++--- test/npm_test.dart | 68 +++++++++--------------- 9 files changed, 63 insertions(+), 88 deletions(-) diff --git a/browser_library_test/tool/grind.dart b/browser_library_test/tool/grind.dart index e123868..4ad16b9 100644 --- a/browser_library_test/tool/grind.dart +++ b/browser_library_test/tool/grind.dart @@ -25,11 +25,11 @@ void main(List args) { }; pkg.jsModuleMainLibrary.value = "lib/src/module_main.dart"; pkg.jsRequires.value = [ - pkg.JSRequire('immutable', target: pkg.JSRequireTarget.all), - pkg.JSRequire('lodash', target: pkg.JSRequireTarget.browser), - pkg.JSRequire('os', target: pkg.JSRequireTarget.node), - pkg.JSRequire('fs', target: pkg.JSRequireTarget.cli), - pkg.JSRequire('http', target: pkg.JSRequireTarget.defaultTarget), + pkg.JSRequire('immutable', target: .all), + pkg.JSRequire('lodash', target: .browser), + pkg.JSRequire('os', target: .node), + pkg.JSRequire('fs', target: .cli), + pkg.JSRequire('http', target: .defaultTarget), ]; pkg.jsEsmExports.value = { 'loadedAllDependency', diff --git a/lib/src/js_require.dart b/lib/src/js_require.dart index 92e8b6f..9ab50fb 100644 --- a/lib/src/js_require.dart +++ b/lib/src/js_require.dart @@ -57,7 +57,7 @@ class JSRequire( /// The target in which to include this require. /// /// This defaults to [JSRequireTarget.all]. - final JSRequireTarget target = target ?? JSRequireTarget.all; + final JSRequireTarget target = target ?? .all; @override String toString() => "const $identifier = require('$package') on $target"; diff --git a/lib/src/npm.dart b/lib/src/npm.dart index 89ceb68..7495b61 100644 --- a/lib/src/npm.dart +++ b/lib/src/npm.dart @@ -275,9 +275,7 @@ void addNpmTasks() { npmDistTag.freeze(); var hasNonCliRequires = jsRequires.value.any( - (require) => - require.target != JSRequireTarget.cli && - require.target != JSRequireTarget.all, + (require) => require.target != .cli && require.target != .all, ); if (jsModuleMainLibrary.value == null) { if (hasNonCliRequires) { @@ -457,13 +455,12 @@ Future _buildPackage() async { 'build/$_npmName.dart.js', p.join(dir.path, '$_npmName.dart.js'), ); - var allRequires = _requiresForTarget(JSRequireTarget.all) - .union(extractedRequires); + var allRequires = _requiresForTarget(.all).union(extractedRequires); - var nodeRequires = _requiresForTarget(JSRequireTarget.node); - var cliRequires = _requiresForTarget(JSRequireTarget.cli).union(nodeRequires); - var browserRequires = _requiresForTarget(JSRequireTarget.browser); - var defaultRequires = _requiresForTarget(JSRequireTarget.defaultTarget); + var nodeRequires = _requiresForTarget(.node); + var cliRequires = _requiresForTarget(.cli).union(nodeRequires); + var browserRequires = _requiresForTarget(.browser); + var defaultRequires = _requiresForTarget(.defaultTarget); writeString( p.join('build', 'npm', 'package.json'), @@ -574,7 +571,7 @@ JSRequireSet _copyJSAndInjectDependencies(String source, String destination) { .firstWhereOrNull((require) => require.package == package) ?.identifier; if (identifier == null) { - var require = JSRequire(package, target: JSRequireTarget.all); + var require = JSRequire(package, target: .all); extractedRequires.add(require); identifier = require.identifier; } @@ -810,7 +807,7 @@ const _cliPkgExports = {}; /// Publishes the contents of `build/npm` to npm. Future _deploy() async { if (npmToken.value case var token?) { - var file = File(".npmrc").openSync(mode: FileMode.writeOnlyAppend); + var file = File(".npmrc").openSync(mode: .writeOnlyAppend); file.writeStringSync("\n//registry.npmjs.org/:_authToken=$token"); file.closeSync(); } else { diff --git a/lib/src/pub.dart b/lib/src/pub.dart index e012cc2..445a919 100644 --- a/lib/src/pub.dart +++ b/lib/src/pub.dart @@ -79,7 +79,7 @@ void addPubTasks() { Future _deploy() async { Directory(p.dirname(_credentialsPath)).createSync(recursive: true); - File(_credentialsPath).openSync(mode: FileMode.writeOnlyAppend) + File(_credentialsPath).openSync(mode: .writeOnlyAppend) ..writeStringSync(pubCredentials.value) ..closeSync(); diff --git a/lib/src/standalone.dart b/lib/src/standalone.dart index ba45fde..8ba2d63 100644 --- a/lib/src/standalone.dart +++ b/lib/src/standalone.dart @@ -24,7 +24,6 @@ import 'config_variable.dart'; import 'info.dart'; import 'sdk_channel.dart'; import 'standalone/cli_platform.dart'; -import 'standalone/operating_system.dart'; import 'template.dart'; import 'utils.dart'; @@ -97,7 +96,7 @@ void _compileNative({bool enableAsserts = false}) { 'dart', arguments: [ 'compile', - useExe.value(CliPlatform.current) ? 'exe' : 'aot-snapshot', + useExe.value(.current) ? 'exe' : 'aot-snapshot', if (enableAsserts) '--enable-asserts', for (var entry in environmentConstants.value.entries) '-D${entry.key}=${entry.value}', @@ -306,18 +305,15 @@ Future> _dartExecutable(CliPlatform platform) async { "https://github.com/dart-musl/dart/releases/" "download/$dartVersion/" "dartsdk-${platform.os}-${platform.arch}-release.tar.gz", - CliPlatform(os: OperatingSystem.android) => + CliPlatform(os: .android) => "https://github.com/" "dart-android/dart/releases/download/$dartVersion/" "dartsdk-${platform.os}-${platform.arch}-release.tar.gz", - CliPlatform( - os: var os && (OperatingSystem.fuchsia || OperatingSystem.ios), - ) => - fail( - "${os.toHumanString()} executables can only be generated when running " - "on ${os.toHumanString()}, because Dart doesn't distribute SDKs for " - "that platform.", - ), + CliPlatform(os: var os && (.fuchsia || .ios)) => fail( + "${os.toHumanString()} executables can only be generated when running " + "on ${os.toHumanString()}, because Dart doesn't distribute SDKs for " + "that platform.", + ), _ => "https://storage.googleapis.com/dart-archive/channels/" "${SdkChannel.current}/release/$dartVersion/sdk/dartsdk-${platform.os}-" diff --git a/lib/src/standalone/architecture.dart b/lib/src/standalone/architecture.dart index c02d20d..23e3a77 100644 --- a/lib/src/standalone/architecture.dart +++ b/lib/src/standalone/architecture.dart @@ -42,12 +42,12 @@ enum Architecture { bool get isRiscv64 => this == riscv64; factory parse(String name) => switch (name) { - "arm" => Architecture.arm, - "arm64" => Architecture.arm64, - "ia32" => Architecture.ia32, - "x64" => Architecture.x64, - "riscv32" => Architecture.riscv32, - "riscv64" => Architecture.riscv64, + "arm" => .arm, + "arm64" => .arm64, + "ia32" => .ia32, + "x64" => .x64, + "riscv32" => .riscv32, + "riscv64" => .riscv64, _ => fail('Unknown architecture "$name"'), }; diff --git a/lib/src/standalone/cli_platform.dart b/lib/src/standalone/cli_platform.dart index d64f177..ea16c3c 100644 --- a/lib/src/standalone/cli_platform.dart +++ b/lib/src/standalone/cli_platform.dart @@ -24,9 +24,9 @@ import 'operating_system.dart'; /// Certain ABIs that Dart recognizes but cli_pkg doesn't support for various /// reasons. -const _unsupportedAbis = { +const _unsupportedAbis = { // This is still experimental and Dart isn't shipping SDKs for it yet - Abi.linuxRiscv32, + .linuxRiscv32, }; /// The set of all ABI strings known by this SDK. diff --git a/lib/src/standalone/operating_system.dart b/lib/src/standalone/operating_system.dart index 012af2e..b9e28cf 100644 --- a/lib/src/standalone/operating_system.dart +++ b/lib/src/standalone/operating_system.dart @@ -42,18 +42,18 @@ enum OperatingSystem { bool get isWindows => this == windows; factory parse(String name) => switch (name) { - "android" => OperatingSystem.android, - "fuchsia" => OperatingSystem.fuchsia, - "ios" => OperatingSystem.ios, - "linux" => OperatingSystem.linux, - "macos" => OperatingSystem.macos, - "windows" => OperatingSystem.windows, + "android" => .android, + "fuchsia" => .fuchsia, + "ios" => .ios, + "linux" => .linux, + "macos" => .macos, + "windows" => .windows, _ => fail('Unknown operating system "$name"'), }; String toHumanString() => switch (this) { - OperatingSystem.ios => "iOS", - OperatingSystem.macos => "macOS", + .ios => "iOS", + .macos => "macOS", _ => name[0].toUpperCase() + name.substring(1).toLowerCase(), }; diff --git a/test/npm_test.dart b/test/npm_test.dart index 1eeeade..67dc60a 100644 --- a/test/npm_test.dart +++ b/test/npm_test.dart @@ -201,45 +201,35 @@ void main() { test("have access to global requires", () async { expect( - hasAccessToRequire( - "pkg.JSRequire('os', target: pkg.JSRequireTarget.all)", - ), + hasAccessToRequire("pkg.JSRequire('os', target: .all)"), completion(isTrue), ); }); test("have access to node requires", () async { expect( - hasAccessToRequire( - "pkg.JSRequire('os', target: pkg.JSRequireTarget.node)", - ), + hasAccessToRequire("pkg.JSRequire('os', target: .node)"), completion(isTrue), ); }); test("don't have access to cli requires", () async { expect( - hasAccessToRequire( - "pkg.JSRequire('os', target: pkg.JSRequireTarget.cli)", - ), + hasAccessToRequire("pkg.JSRequire('os', target: .cli)"), completion(isFalse), ); }); test("don't have access to browser requires", () async { expect( - hasAccessToRequire( - "pkg.JSRequire('os', target: pkg.JSRequireTarget.browser)", - ), + hasAccessToRequire("pkg.JSRequire('os', target: .browser)"), completion(isFalse), ); }); test("has access to default requires without a node target", () async { expect( - hasAccessToRequire( - "pkg.JSRequire('os', target: pkg.JSRequireTarget.defaultTarget)", - ), + hasAccessToRequire("pkg.JSRequire('os', target: .defaultTarget)"), completion(isTrue), ); }); @@ -249,8 +239,8 @@ void main() { () async { expect( hasAccessToRequire(""" - pkg.JSRequire('http', target: pkg.JSRequireTarget.node), - pkg.JSRequire('os', target: pkg.JSRequireTarget.defaultTarget), + pkg.JSRequire('http', target: .node), + pkg.JSRequire('os', target: .defaultTarget), """), completion(isFalse), ); @@ -353,36 +343,28 @@ void main() { test("with access to cli requires", () async { expect( - hasAccessToRequire( - "pkg.JSRequire('os', target: pkg.JSRequireTarget.cli)", - ), + hasAccessToRequire("pkg.JSRequire('os', target: .cli)"), completion(isTrue), ); }); test("with access to node requires", () async { expect( - hasAccessToRequire( - "pkg.JSRequire('os', target: pkg.JSRequireTarget.node)", - ), + hasAccessToRequire("pkg.JSRequire('os', target: .node)"), completion(isTrue), ); }); test("without access to browser requires", () async { expect( - hasAccessToRequire( - "pkg.JSRequire('os', target: pkg.JSRequireTarget.browser)", - ), + hasAccessToRequire("pkg.JSRequire('os', target: .browser)"), completion(isFalse), ); }); test("without access to default requires", () async { expect( - hasAccessToRequire( - "pkg.JSRequire('os', target: pkg.JSRequireTarget.defaultTarget)", - ), + hasAccessToRequire("pkg.JSRequire('os', target: .defaultTarget)"), completion(isFalse), ); }); @@ -766,7 +748,7 @@ void main() { const grindDotDart = """ void main(List args) { pkg.jsModuleMainLibrary.value = "lib/src/module_main.dart"; - pkg.jsRequires.value = [pkg.JSRequire('util', target: pkg.JSRequireTarget.cli)]; + pkg.jsRequires.value = [pkg.JSRequire('util', target: .cli)]; pkg.addNpmTasks(); grind(args); @@ -777,8 +759,8 @@ void main() { void main(List args) { pkg.jsModuleMainLibrary.value = "lib/src/module_main.dart"; pkg.jsRequires.value = [ - pkg.JSRequire('util', target: pkg.JSRequireTarget.cli), - pkg.JSRequire('other', target: pkg.JSRequireTarget.node), + pkg.JSRequire('util', target: .cli), + pkg.JSRequire('other', target: .node), ]; pkg.addNpmTasks(); @@ -830,8 +812,8 @@ void main() { void main(List args) { pkg.jsModuleMainLibrary.value = "lib/src/exports.dart"; pkg.jsRequires.value = [ - pkg.JSRequire('util', target: pkg.JSRequireTarget.cli), - pkg.JSRequire('os', target: pkg.JSRequireTarget.node), + pkg.JSRequire('util', target: .cli), + pkg.JSRequire('os', target: .node), ]; pkg.jsEsmExports.value = {'hello'}; @@ -1466,8 +1448,8 @@ void main() { test("have access to lazy requires", () async { expect( load( - "pkg.JSRequire('os', target: pkg.JSRequireTarget.node), " - "pkg.JSRequire('os', target: pkg.JSRequireTarget.node, " + "pkg.JSRequire('os', target: .node), " + "pkg.JSRequire('os', target: .node, " "lazy: true, identifier: 'os_lazy')", """ import 'package:js/js.dart'; @@ -1506,7 +1488,7 @@ void main() { expect( load( "pkg.JSRequire('module_not_found', " - "target: pkg.JSRequireTarget.node, lazy: true)", + "target: .node, lazy: true)", """ import 'package:js/js.dart'; import 'package:js/js_util.dart'; @@ -1543,8 +1525,8 @@ void main() { test("have access to optional requires", () async { expect( load( - "pkg.JSRequire('os', target: pkg.JSRequireTarget.node), " - "pkg.JSRequire('os', target: pkg.JSRequireTarget.node, " + "pkg.JSRequire('os', target: .node), " + "pkg.JSRequire('os', target: .node, " "optional: true, identifier: 'os_optional')", """ import 'package:js/js.dart'; @@ -1585,7 +1567,7 @@ void main() { expect( load( "pkg.JSRequire('module_not_found', " - "target: pkg.JSRequireTarget.node, optional: true)", + "target: .node, optional: true)", """ import 'package:js/js.dart'; import 'package:js/js_util.dart'; @@ -1619,8 +1601,8 @@ void main() { test("have access to lazy optional requires", () async { expect( load( - "pkg.JSRequire('os', target: pkg.JSRequireTarget.node)," - "pkg.JSRequire('os', target: pkg.JSRequireTarget.node, " + "pkg.JSRequire('os', target: .node)," + "pkg.JSRequire('os', target: .node, " "lazy: true, optional: true, " "identifier: 'os_lazy_optional')", """ @@ -1661,7 +1643,7 @@ void main() { expect( load( "pkg.JSRequire('module_not_found', " - "target: pkg.JSRequireTarget.node, lazy: true, " + "target: .node, lazy: true, " "optional: true)", """ import 'package:js/js.dart';