Skip to content
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
2 changes: 1 addition & 1 deletion browser_library_test/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 5 additions & 5 deletions browser_library_test/tool/grind.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ void main(List<String> 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',
Expand Down
10 changes: 4 additions & 6 deletions lib/src/config_variable.dart
Original file line number Diff line number Diff line change
Expand Up @@ -105,15 +105,13 @@ class ConfigVariable<T> {
_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();
Expand Down
5 changes: 2 additions & 3 deletions lib/src/github.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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];
}

Expand Down
5 changes: 2 additions & 3 deletions lib/src/homebrew.dart
Original file line number Diff line number Diff line change
Expand Up @@ -156,9 +156,8 @@ Future<void> _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,
Expand Down
39 changes: 16 additions & 23 deletions lib/src/js_require.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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.
///
Expand All @@ -38,33 +35,29 @@ class JSRequire {
/// when this package is loaded.
///
/// This defaults to false.
final bool lazy;
final bool lazy = false,

/// Whether the dependency is optional.
///
/// An optional dependency's module identifier will be `null` if a load fails
/// 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;

JSRequire(
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 ?? .all;

@override
String toString() => "const $identifier = require('$package') on $target";
Expand Down
5 changes: 2 additions & 3 deletions lib/src/js_require_set.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,13 @@ final _equality = EqualityBy<JSRequire, String>(
@internal
class JSRequireSet extends EqualitySet<JSRequire> {
/// 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<JSRequire> requires)
: super.from(_equality, requires);
new of(Iterable<JSRequire> requires) : super.from(_equality, requires);

@override
JSRequireSet union(Set<JSRequire> other) =>
Expand Down
7 changes: 2 additions & 5 deletions lib/src/last_changelog_section.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -55,9 +55,6 @@ class _Extractor {
/// more deeply-nested blocks.
final _indentationLevels = <int>[];

_Extractor(String text, {Object? sourceUrl})
: _scanner = StringScanner(text, sourceUrl: sourceUrl);

String extract(Version version) {
if (!_scanner.scan(
RegExp("## ${RegExp.escape(version.toString())}\r?\n"),
Expand Down
20 changes: 8 additions & 12 deletions lib/src/npm.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -457,14 +455,12 @@ Future<void> _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'),
Expand Down Expand Up @@ -575,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;
}
Expand Down Expand Up @@ -811,7 +807,7 @@ const _cliPkgExports = {};
/// Publishes the contents of `build/npm` to npm.
Future<void> _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 {
Expand Down
2 changes: 1 addition & 1 deletion lib/src/pub.dart
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ void addPubTasks() {
Future<void> _deploy() async {
Directory(p.dirname(_credentialsPath)).createSync(recursive: true);

File(_credentialsPath).openSync(mode: FileMode.writeOnlyAppend)
File(_credentialsPath).openSync(mode: .writeOnlyAppend)
..writeStringSync(pubCredentials.value)
..closeSync();

Expand Down
18 changes: 7 additions & 11 deletions lib/src/standalone.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -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}',
Expand Down Expand Up @@ -306,18 +305,15 @@ Future<List<int>> _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}-"
Expand Down
14 changes: 7 additions & 7 deletions lib/src/standalone/architecture.dart
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,13 @@ enum Architecture {
/// Whether this is a 64-bit RISCV architecture.
bool get isRiscv64 => this == riscv64;

factory Architecture.parse(String name) => switch (name) {
"arm" => Architecture.arm,
"arm64" => Architecture.arm64,
"ia32" => Architecture.ia32,
"x64" => Architecture.x64,
"riscv32" => Architecture.riscv32,
"riscv64" => Architecture.riscv64,
factory parse(String name) => switch (name) {
"arm" => .arm,
"arm64" => .arm64,
"ia32" => .ia32,
"x64" => .x64,
"riscv32" => .riscv32,
"riscv64" => .riscv64,
_ => fail('Unknown architecture "$name"'),
};

Expand Down
23 changes: 12 additions & 11 deletions lib/src/standalone/cli_platform.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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 = <Abi>{
// 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.
Expand All @@ -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;
Expand Down Expand Up @@ -107,9 +108,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()
Expand All @@ -119,7 +120,7 @@ class CliPlatform {
return p.basename(interp).startsWith('ld-musl-');
}

CliPlatform(this.os, this.arch, {bool musl = false}) : isMusl = musl {
this {
if (!_abiStrings.contains('${os}_$arch')) {
fail("Unknown or unsupported platform $os-$arch!");
}
Expand Down
18 changes: 9 additions & 9 deletions lib/src/standalone/operating_system.dart
Original file line number Diff line number Diff line change
Expand Up @@ -41,19 +41,19 @@ enum OperatingSystem {
/// Whether this represents Windows.
bool get isWindows => this == windows;

factory OperatingSystem.parse(String name) => switch (name) {
"android" => OperatingSystem.android,
"fuchsia" => OperatingSystem.fuchsia,
"ios" => OperatingSystem.ios,
"linux" => OperatingSystem.linux,
"macos" => OperatingSystem.macos,
"windows" => OperatingSystem.windows,
factory parse(String name) => switch (name) {
"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(),
};

Expand Down
Loading
Loading