Skip to content

Commit 3d8b4f0

Browse files
committed
Rename files and move things around
1 parent 6f4de31 commit 3d8b4f0

11 files changed

+103
-99
lines changed

bin/sass.dart

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,7 @@ import 'package:sass/src/importer/filesystem.dart';
1717
import 'package:sass/src/io.dart';
1818
import 'package:sass/src/stylesheet_graph.dart';
1919
import 'package:sass/src/utils.dart';
20-
import 'package:sass/src/embedded/executable.dart'
21-
if (dart.library.js) 'package:sass/src/embedded/js/executable.dart'
22-
as embedded;
20+
import 'package:sass/src/embedded/executable.dart' as embedded;
2321

2422
Future<void> main(List<String> args) async {
2523
if (args case ['--embedded', ...var rest]) {

lib/src/embedded/executable.dart

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,5 @@
1-
// Copyright 2019 Google Inc. Use of this source code is governed by an
1+
// Copyright 2025 Google Inc. Use of this source code is governed by an
22
// MIT-style license that can be found in the LICENSE file or at
33
// https://opensource.org/licenses/MIT.
44

5-
import 'dart:io';
6-
7-
import 'package:stream_channel/stream_channel.dart';
8-
9-
import 'isolate_dispatcher.dart';
10-
import 'options.dart';
11-
import 'util/length_delimited_transformer.dart';
12-
13-
void main(List<String> args) {
14-
if (parseOptions(args)) {
15-
IsolateDispatcher(
16-
StreamChannel.withGuarantees(stdin, stdout, allowSinkErrors: false)
17-
.transform(lengthDelimited),
18-
gracefulShutdown: false)
19-
.listen();
20-
}
21-
}
5+
export 'vm/executable.dart' if (dart.library.js) 'js/executable.dart';

lib/src/embedded/js/executable.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,24 @@
44

55
import 'package:stream_channel/stream_channel.dart';
66

7-
import '../isolate_dispatcher.dart';
8-
import '../isolate_main.dart';
97
import '../options.dart';
108
import '../util/length_delimited_transformer.dart';
9+
import '../worker_dispatcher.dart';
10+
import '../worker_entrypoint.dart';
1111
import 'io.dart';
1212
import 'sync_receive_port.dart';
1313
import 'worker_threads.dart';
1414

1515
void main(List<String> args) {
1616
if (parseOptions(args)) {
1717
if (isMainThread) {
18-
IsolateDispatcher(StreamChannel.withGuarantees(stdin, stdout,
18+
WorkerDispatcher(StreamChannel.withGuarantees(stdin, stdout,
1919
allowSinkErrors: false)
2020
.transform(lengthDelimited))
2121
.listen();
2222
} else {
2323
var port = workerData! as MessagePort;
24-
isolateMain(JSSyncReceivePort(port), JSSendPort(port));
24+
workerEntryPoint(JSSyncReceivePort(port), JSSendPort(port));
2525
}
2626
}
2727
}

lib/src/embedded/js/reusable_isolate.dart renamed to lib/src/embedded/js/reusable_worker.dart

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@ import 'js.dart';
1010
import 'sync_message_port.dart';
1111
import 'worker_threads.dart';
1212

13-
/// The entrypoint for a [ReusableIsolate].
13+
/// The entrypoint for a [ReusableWorker].
1414
///
1515
/// This must return a Record of filename and argv for creating the Worker.
16-
typedef ReusableIsolateEntryPoint = (String, JSArray<JSAny?>) Function();
16+
typedef ReusableWorkerEntryPoint = (String, JSArray<JSAny?>) Function();
1717

18-
class ReusableIsolate {
18+
class ReusableWorker {
1919
/// The worker.
2020
final Worker _worker;
2121

@@ -28,14 +28,14 @@ class ReusableIsolate {
2828
/// The subscription to [_receivePort].
2929
final StreamSubscription<dynamic> _subscription;
3030

31-
/// Whether the current isolate has been borrowed.
31+
/// Whether the current worker has been borrowed.
3232
bool _borrowed = false;
3333

34-
ReusableIsolate._(
34+
ReusableWorker._(
3535
this._worker, this._sendPort, this._receivePort, this._subscription);
3636

37-
/// Spawns a [ReusableIsolate] that runs the the entrypoint script.
38-
static Future<ReusableIsolate> spawn(ReusableIsolateEntryPoint entryPoint,
37+
/// Spawns a [ReusableWorker] that runs the the entrypoint script.
38+
static Future<ReusableWorker> spawn(ReusableWorkerEntryPoint entryPoint,
3939
{Function? onError}) async {
4040
var (filename, argv) = entryPoint();
4141
var channel = SyncMessagePort.createChannel();
@@ -53,14 +53,14 @@ class ReusableIsolate {
5353
((JSUint8Array buffer) {
5454
controller.add(buffer.toDart);
5555
}).toJS);
56-
return ReusableIsolate._(worker, sendPort, receivePort,
56+
return ReusableWorker._(worker, sendPort, receivePort,
5757
controller.stream.listen(_defaultOnData));
5858
}
5959

6060
/// Subscribe to messages from [_receivePort].
6161
void borrow(void onData(dynamic event)?) {
6262
if (_borrowed) {
63-
throw StateError('ReusableIsolate has already been borrowed.');
63+
throw StateError('ReusableWorker has already been borrowed.');
6464
}
6565
_borrowed = true;
6666
_subscription.onData(onData);
@@ -69,16 +69,16 @@ class ReusableIsolate {
6969
/// Unsubscribe to messages from [_receivePort].
7070
void release() {
7171
if (!_borrowed) {
72-
throw StateError('ReusableIsolate has not been borrowed.');
72+
throw StateError('ReusableWorker has not been borrowed.');
7373
}
7474
_borrowed = false;
7575
_subscription.onData(_defaultOnData);
7676
}
7777

78-
/// Sends [message] to the isolate.
78+
/// Sends [message] to the worker.
7979
///
80-
/// Throws a [StateError] if this is called while the isolate isn't borrowed,
81-
/// or if a second message is sent before the isolate has processed the first
80+
/// Throws a [StateError] if this is called while the worker isn't borrowed,
81+
/// or if a second message is sent before the worker has processed the first
8282
/// one.
8383
void send(Uint8List message) {
8484
if (!_borrowed) {
@@ -88,15 +88,15 @@ class ReusableIsolate {
8888
_sendPort.postMessage(array, [array.buffer].toJS);
8989
}
9090

91-
/// Shuts down the isolate.
91+
/// Shuts down the worker.
9292
void kill() {
9393
_sendPort.close();
9494
_worker.terminate();
9595
_receivePort.close();
9696
}
9797
}
9898

99-
/// The default handler for data events from the wrapped isolate when it's not
99+
/// The default handler for data events from the wrapped worker when it's not
100100
/// borrowed.
101101
void _defaultOnData(dynamic _) {
102102
throw StateError("Shouldn't receive a message before being borrowed.");

lib/src/embedded/js/isolate_main.dart renamed to lib/src/embedded/js/worker_entrypoint.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@ import 'js.dart';
99
@JS('process.argv')
1010
external JSArray<JSAny?> get _argv;
1111

12-
(String, JSArray<JSString>) isolateMain() {
12+
(String, JSArray<JSString>) workerEntryPoint() {
1313
return ((_argv[1]! as JSString).toDart, _argv.slice(2) as JSArray<JSString>);
1414
}

lib/src/embedded/options.dart

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

77
import '../io.dart';
8-
import 'isolate_dispatcher.dart';
8+
import 'worker_dispatcher.dart';
99

1010
/// Returns true if should start embedded compiler,
1111
/// and false if should exit.
1212
bool parseOptions(List<String> args) {
1313
switch (args) {
1414
case ["--version", ...]:
15-
var response = IsolateDispatcher.versionResponse();
15+
var response = WorkerDispatcher.versionResponse();
1616
response.id = 0;
1717
safePrint(JsonEncoder.withIndent(" ").convert(response.toProto3Json()));
1818
return false;

lib/src/embedded/vm/executable.dart

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Copyright 2025 Google Inc. Use of this source code is governed by an
2+
// MIT-style license that can be found in the LICENSE file or at
3+
// https://opensource.org/licenses/MIT.
4+
5+
import 'dart:io';
6+
7+
import 'package:stream_channel/stream_channel.dart';
8+
9+
import '../options.dart';
10+
import '../util/length_delimited_transformer.dart';
11+
import '../worker_dispatcher.dart';
12+
13+
void main(List<String> args) {
14+
if (parseOptions(args)) {
15+
WorkerDispatcher(
16+
StreamChannel.withGuarantees(stdin, stdout, allowSinkErrors: false)
17+
.transform(lengthDelimited),
18+
gracefulShutdown: false)
19+
.listen();
20+
}
21+
}

lib/src/embedded/reusable_isolate.dart renamed to lib/src/embedded/vm/reusable_worker.dart

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,21 @@ import 'dart:typed_data';
99
import 'package:native_synchronization/mailbox.dart';
1010
import 'package:native_synchronization/sendable.dart';
1111

12-
import 'sync_receive_port.dart';
12+
import '../sync_receive_port.dart';
1313

14-
/// The entrypoint for a [ReusableIsolate].
14+
/// The entrypoint for a [ReusableWorker].
1515
///
1616
/// This must be a static global function. It's run when the isolate is spawned,
17-
/// and is passed a [Mailbox] that receives messages from [ReusableIsolate.send]
17+
/// and is passed a [Mailbox] that receives messages from [ReusableWorker.send]
1818
/// and a [SendPort] that sends messages to the [ReceivePort] listened by
19-
/// [ReusableIsolate.borrow].
19+
/// [ReusableWorker.borrow].
2020
///
21-
/// If the [sendPort] sends a message before [ReusableIsolate.borrow] is called,
21+
/// If the [sendPort] sends a message before [ReusableWorker.borrow] is called,
2222
/// this will throw an unhandled [StateError].
23-
typedef ReusableIsolateEntryPoint = FutureOr<void> Function(
23+
typedef ReusableWorkerEntryPoint = FutureOr<void> Function(
2424
SyncReceivePort receivePort, SendPort sendPort);
2525

26-
class ReusableIsolate {
26+
class ReusableWorker {
2727
/// The wrapped isolate.
2828
final Isolate _isolate;
2929

@@ -39,16 +39,16 @@ class ReusableIsolate {
3939
/// Whether the current isolate has been borrowed.
4040
bool _borrowed = false;
4141

42-
ReusableIsolate._(
42+
ReusableWorker._(
4343
this._isolate,
4444
this._mailbox,
4545
this._receivePort, {
4646
Function? onError,
4747
}) : _subscription = _receivePort.listen(_defaultOnData, onError: onError);
4848

49-
/// Spawns a [ReusableIsolate] that runs the given [entryPoint].
50-
static Future<ReusableIsolate> spawn(
51-
ReusableIsolateEntryPoint entryPoint, {
49+
/// Spawns a [ReusableWorker] that runs the given [entryPoint].
50+
static Future<ReusableWorker> spawn(
51+
ReusableWorkerEntryPoint entryPoint, {
5252
Function? onError,
5353
}) async {
5454
var mailbox = Mailbox();
@@ -58,13 +58,13 @@ class ReusableIsolate {
5858
mailbox.asSendable,
5959
receivePort.sendPort,
6060
));
61-
return ReusableIsolate._(isolate, mailbox, receivePort, onError: onError);
61+
return ReusableWorker._(isolate, mailbox, receivePort, onError: onError);
6262
}
6363

6464
/// Subscribe to messages from [_receivePort].
6565
void borrow(void onData(dynamic event)?) {
6666
if (_borrowed) {
67-
throw StateError('ReusableIsolate has already been borrowed.');
67+
throw StateError('ReusableWorker has already been borrowed.');
6868
}
6969
_borrowed = true;
7070
_subscription.onData(onData);
@@ -73,7 +73,7 @@ class ReusableIsolate {
7373
/// Unsubscribe to messages from [_receivePort].
7474
void release() {
7575
if (!_borrowed) {
76-
throw StateError('ReusableIsolate has not been borrowed.');
76+
throw StateError('ReusableWorker has not been borrowed.');
7777
}
7878
_borrowed = false;
7979
_subscription.onData(_defaultOnData);
@@ -108,7 +108,7 @@ void _defaultOnData(dynamic _) {
108108
}
109109

110110
void _isolateMain(
111-
(ReusableIsolateEntryPoint, Sendable<Mailbox>, SendPort) message,
111+
(ReusableWorkerEntryPoint, Sendable<Mailbox>, SendPort) message,
112112
) {
113113
var (entryPoint, sendableMailbox, sendPort) = message;
114114
entryPoint(MailboxSyncReceivePort(sendableMailbox.materialize()), sendPort);

0 commit comments

Comments
 (0)