-
Notifications
You must be signed in to change notification settings - Fork 357
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement
sass --embedded
in pure JS mode
- Loading branch information
Showing
27 changed files
with
490 additions
and
74 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
// Copyright 2024 Google Inc. Use of this source code is governed by an | ||
// MIT-style license that can be found in the LICENSE file or at | ||
// https://opensource.org/licenses/MIT. | ||
|
||
import 'dart:ffi'; | ||
|
||
/// More than MaxMutatorThreadCount isolates in the same isolate group | ||
/// can deadlock the Dart VM. | ||
/// See https://github.com/sass/dart-sass/pull/2019 | ||
int get concurrencyLimit => sizeOf<IntPtr>() <= 4 ? 7 : 15; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
// Copyright 2024 Google Inc. Use of this source code is governed by an | ||
// MIT-style license that can be found in the LICENSE file or at | ||
// https://opensource.org/licenses/MIT. | ||
|
||
import 'dart:isolate' show SendPort; | ||
|
||
import 'compilation_dispatcher.dart'; | ||
import 'sync_receive_port.dart'; | ||
|
||
void isolateMain(SyncReceivePort receivePort, SendPort sendPort) { | ||
CompilationDispatcher(receivePort, sendPort).listen(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
// Copyright 2024 Google Inc. Use of this source code is governed by an | ||
// MIT-style license that can be found in the LICENSE file or at | ||
// https://opensource.org/licenses/MIT. | ||
|
||
import 'dart:js_interop'; | ||
|
||
@JS('os.cpus') | ||
external JSArray _cpus(); | ||
|
||
int get concurrencyLimit => _cpus().toDart.length; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// Copyright 2024 Google Inc. Use of this source code is governed by an | ||
// MIT-style license that can be found in the LICENSE file or at | ||
// https://opensource.org/licenses/MIT. | ||
|
||
import 'package:stream_channel/stream_channel.dart'; | ||
|
||
import '../compilation_dispatcher.dart'; | ||
import '../isolate_dispatcher.dart'; | ||
import '../options.dart'; | ||
import '../util/length_delimited_transformer.dart'; | ||
import 'io.dart'; | ||
import 'sync_receive_port.dart'; | ||
import 'worker_threads.dart'; | ||
|
||
void main(List<String> args) { | ||
if (parseOptions(args)) { | ||
if (isMainThread) { | ||
IsolateDispatcher(StreamChannel.withGuarantees(stdin, stdout, | ||
allowSinkErrors: false) | ||
.transform(lengthDelimited)) | ||
.listen(); | ||
} else { | ||
var port = workerData! as MessagePort; | ||
CompilationDispatcher(JSSyncReceivePort(port), JSSendPort(port)).listen(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
// Copyright 2024 Google Inc. Use of this source code is governed by an | ||
// MIT-style license that can be found in the LICENSE file or at | ||
// https://opensource.org/licenses/MIT. | ||
|
||
import 'dart:async'; | ||
import 'dart:typed_data'; | ||
import 'dart:js_interop'; | ||
|
||
import '../../io.dart'; | ||
|
||
/// In Node JS's main thread we need to wait for worker to exit in order | ||
/// to get exit code set by worker asynchronously. Therefore skip explict | ||
/// exit on main thread, but close stdin and wait for shutdown. | ||
void exit([int? code]) { | ||
if (code != null) { | ||
exitCode = code; | ||
} | ||
_stdinDestory(); | ||
} | ||
|
||
@JS('process.stdin.destroy') | ||
external void _stdinDestory(); | ||
|
||
@JS('process.stdin.on') | ||
external void _stdinOn(String type, JSFunction listener); | ||
|
||
@JS('process.stdout.write') | ||
external void _stdoutWrite(JSUint8Array buffer); | ||
|
||
Stream<List<int>> get stdin { | ||
var controller = StreamController<Uint8List>( | ||
onCancel: () { | ||
_stdinDestory(); | ||
}, | ||
sync: true); | ||
_stdinOn( | ||
'data', | ||
(JSUint8Array chunk) { | ||
controller.sink.add(chunk.toDart); | ||
}.toJS); | ||
_stdinOn( | ||
'end', | ||
() { | ||
controller.sink.close(); | ||
}.toJS); | ||
_stdinOn( | ||
'error', | ||
(JSObject e) { | ||
controller.sink.addError(e); | ||
}.toJS); | ||
return controller.stream; | ||
} | ||
|
||
StreamSink<List<int>> get stdout { | ||
var controller = StreamController<Uint8List>(sync: true); | ||
controller.stream.listen((buffer) { | ||
_stdoutWrite(buffer.toJS); | ||
}); | ||
return controller.sink; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// Copyright 2024 Google LLC. Use of this source code is governed by an | ||
// MIT-style license that can be found in the LICENSE file or at | ||
// https://opensource.org/licenses/MIT. | ||
|
||
import 'dart:isolate' show SendPort; | ||
export 'dart:isolate' show SendPort; | ||
import 'dart:js_interop'; | ||
|
||
@JS('process.exit') | ||
external void _exit(); | ||
|
||
abstract class Isolate { | ||
static Never exit([SendPort? finalMessagePort, Object? message]) { | ||
if (message != null) { | ||
finalMessagePort?.send(message); | ||
} | ||
_exit(); | ||
|
||
// This is unreachable, but needed for return type [Never] | ||
throw Error(); | ||
} | ||
} |
Oops, something went wrong.