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
11 changes: 10 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
## 1.97.4-dev
## 1.98.0-dev

### Dart API

* Add a `const Logger.defaultLogger` field. This provides a logger that emits to
standard error or the browser console, but automatically chooses whether to
use terminal colors.

### JavaScript API

Expand All @@ -8,6 +14,9 @@
* Properly emit deprecation warnings as text rather than `StringBuffer` objects
when running in a browser.

* Emit colored warnings and other messages on the console when running in a
browser.

## 1.97.3

* Fix a bug where nesting an at-rule within multiple style rules in plain CSS
Expand Down
4 changes: 2 additions & 2 deletions lib/src/async_compile.dart
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ Future<CompileResult> compileAsync(
}) async {
DeprecationProcessingLogger deprecationLogger =
logger = DeprecationProcessingLogger(
logger ?? Logger.stderr(),
logger ?? Logger.defaultLogger,
silenceDeprecations: {...?silenceDeprecations},
fatalDeprecations: {...?fatalDeprecations},
futureDeprecations: {...?futureDeprecations},
Expand Down Expand Up @@ -124,7 +124,7 @@ Future<CompileResult> compileStringAsync(
}) async {
DeprecationProcessingLogger deprecationLogger =
logger = DeprecationProcessingLogger(
logger ?? Logger.stderr(),
logger ?? Logger.defaultLogger,
silenceDeprecations: {...?silenceDeprecations},
fatalDeprecations: {...?fatalDeprecations},
futureDeprecations: {...?futureDeprecations},
Expand Down
6 changes: 3 additions & 3 deletions lib/src/compile.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// DO NOT EDIT. This file was generated from async_compile.dart.
// See tool/grind/synchronize.dart for details.
//
// Checksum: d305a0f75e329a29f5aff734ac31ce145fd3b8d5
// Checksum: aa378886d9a3d697d466ac916f7902cbc1b282ee
//
// ignore_for_file: unused_import

Expand Down Expand Up @@ -58,7 +58,7 @@ CompileResult compile(
}) {
DeprecationProcessingLogger deprecationLogger =
logger = DeprecationProcessingLogger(
logger ?? Logger.stderr(),
logger ?? Logger.defaultLogger,
silenceDeprecations: {...?silenceDeprecations},
fatalDeprecations: {...?fatalDeprecations},
futureDeprecations: {...?futureDeprecations},
Expand Down Expand Up @@ -133,7 +133,7 @@ CompileResult compileString(
}) {
DeprecationProcessingLogger deprecationLogger =
logger = DeprecationProcessingLogger(
logger ?? Logger.stderr(),
logger ?? Logger.defaultLogger,
silenceDeprecations: {...?silenceDeprecations},
fatalDeprecations: {...?fatalDeprecations},
futureDeprecations: {...?futureDeprecations},
Expand Down
8 changes: 4 additions & 4 deletions lib/src/evaluation_context.dart
Original file line number Diff line number Diff line change
Expand Up @@ -69,18 +69,18 @@ void warn(String message, {bool deprecation = false}) =>
message,
deprecation ? Deprecation.userAuthored : null,
),
_ when deprecation => (const Logger.stderr()).warnForDeprecation(
_ when deprecation => Logger.defaultLogger.warnForDeprecation(
Deprecation.userAuthored,
message,
),
_ => (const Logger.stderr()).warn(message),
_ => Logger.defaultLogger.warn(message),
};

/// Prints a deprecation warning with [message] of type [deprecation].
void warnForDeprecation(String message, Deprecation deprecation) =>
switch (EvaluationContext.currentOrNull) {
var context? => context.warn(message, deprecation),
_ => (const Logger.stderr()).warnForDeprecation(deprecation, message),
_ => Logger.defaultLogger.warnForDeprecation(deprecation, message),
};

/// Prints a deprecation warning with [message] of type [deprecation],
Expand All @@ -89,7 +89,7 @@ void warnForDeprecationFromApi(String message, Deprecation deprecation) {
if (EvaluationContext._currentOrNull case var context?) {
context.warn(message, deprecation);
} else {
Logger.stderr().warnForDeprecation(deprecation, message);
Logger.defaultLogger.warnForDeprecation(deprecation, message);
}
}

Expand Down
5 changes: 3 additions & 2 deletions lib/src/io/js.dart
Original file line number Diff line number Diff line change
Expand Up @@ -278,8 +278,9 @@ bool get isWindows => _process?.platform == 'win32';

bool get isMacOS => _process?.platform == 'darwin';

// Node seems to support ANSI escapes on all terminals.
bool get supportsAnsiEscapes => hasTerminal;
// Node seems to support ANSI escapes on all terminals, and browser consoles
// support them as well..
bool get supportsAnsiEscapes => hasTerminal || isBrowser;

int get exitCode => _process?.exitCode ?? 0;

Expand Down
8 changes: 4 additions & 4 deletions lib/src/js/compile.dart
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ NodeCompileResult compile(String path, [CompileOptions? options]) {
if (!isNodeJs) {
jsThrow(JsError("The compile() method is only available in Node.js."));
}
var color = options?.alertColor ?? hasTerminal;
var color = options?.alertColor ?? supportsAnsiEscapes;
var ascii = options?.alertAscii ?? glyph.ascii;
var logger = JSToDartLogger(
options?.logger,
Expand Down Expand Up @@ -82,7 +82,7 @@ NodeCompileResult compile(String path, [CompileOptions? options]) {
/// See https://github.com/sass/sass/spec/tree/main/js-api/compile.d.ts for
/// details.
NodeCompileResult compileString(String text, [CompileStringOptions? options]) {
var color = options?.alertColor ?? hasTerminal;
var color = options?.alertColor ?? supportsAnsiEscapes;
var ascii = options?.alertAscii ?? glyph.ascii;
var logger = JSToDartLogger(
options?.logger,
Expand Down Expand Up @@ -137,7 +137,7 @@ Promise compileAsync(String path, [CompileOptions? options]) {
if (!isNodeJs) {
jsThrow(JsError("The compileAsync() method is only available in Node.js."));
}
var color = options?.alertColor ?? hasTerminal;
var color = options?.alertColor ?? supportsAnsiEscapes;
var ascii = options?.alertAscii ?? glyph.ascii;
var logger = JSToDartLogger(
options?.logger,
Expand Down Expand Up @@ -189,7 +189,7 @@ Promise compileAsync(String path, [CompileOptions? options]) {
/// See https://github.com/sass/sass/spec/tree/main/js-api/compile.d.ts for
/// details.
Promise compileStringAsync(String text, [CompileStringOptions? options]) {
var color = options?.alertColor ?? hasTerminal;
var color = options?.alertColor ?? supportsAnsiEscapes;
var ascii = options?.alertAscii ?? glyph.ascii;
var logger = JSToDartLogger(
options?.logger,
Expand Down
4 changes: 2 additions & 2 deletions lib/src/js/legacy.dart
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ Future<RenderResult> _renderAsync(RenderOptions options) async {
var file = options.file.andThen(p.absolute);
var logger = JSToDartLogger(
options.logger,
Logger.stderr(color: hasTerminal),
Logger.defaultLogger,
);
if (options.data case var data?) {
result = await compileStringAsync(
Expand Down Expand Up @@ -171,7 +171,7 @@ RenderResult renderSync(RenderOptions options) {
var file = options.file.andThen(p.absolute);
var logger = JSToDartLogger(
options.logger,
Logger.stderr(color: hasTerminal),
Logger.defaultLogger,
);
if (options.data case var data?) {
result = compileString(
Expand Down
6 changes: 6 additions & 0 deletions lib/src/logger.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import 'package:stack_trace/stack_trace.dart';
import 'deprecation.dart';
import 'logger/deprecation_processing.dart';
import 'logger/stderr.dart';
import 'logger/default.dart';

/// An interface for loggers that print messages produced by Sass stylesheets.
///
Expand All @@ -23,6 +24,11 @@ abstract class Logger {
/// colors if [color] is `true` (default `false`).
const factory Logger.stderr({bool color}) = StderrLogger;

/// The logger that's used when no others are selected. This is always
/// [Logger.stderr], but with the value for `color` chosen based on whether
/// the current system supports terminal colors.
static const Logger defaultLogger = DefaultLogger();

/// Emits a warning with the given [message].
///
/// If [span] is passed, it's the location in the Sass source that generated
Expand Down
39 changes: 39 additions & 0 deletions lib/src/logger/default.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// Copyright 2026 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:source_span/source_span.dart';
import 'package:stack_trace/stack_trace.dart';

import '../deprecation.dart';
import '../io.dart';
import '../logger.dart';
import 'stderr.dart';

/// The logger "wrapped" by [DefaultLogger].
///
/// This must be global because it's assigned based on non-const function
/// results.
StderrLogger? _default;

/// A logger that wraps [StderrLogger] and chooses whether to activate colors
/// based on whether the current system supports it.
final class DefaultLogger extends LoggerWithDeprecationType {
const DefaultLogger();

/// Ensures [_defaultStderr] is initialized and returns it.
StderrLogger get _inner {
return _default ??= StderrLogger(color: supportsAnsiEscapes);
}

void internalWarn(
String message, {
FileSpan? span,
Trace? trace,
Deprecation? deprecation,
}) =>
_inner.internalWarn(message,
span: span, trace: trace, deprecation: deprecation);

void debug(String message, SourceSpan span) => _inner.debug(message, span);
}
2 changes: 1 addition & 1 deletion lib/src/visitor/async_evaluate.dart
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ final class _EvaluateVisitor
}) : _importCache = importCache ??
(nodeImporter == null ? AsyncImportCache.none() : null),
_nodeImporter = nodeImporter,
_logger = logger ?? const Logger.stderr(),
_logger = logger ?? Logger.defaultLogger,
_quietDeps = quietDeps,
_sourceMap = sourceMap,
// The default environment is overridden in [_execute] for full
Expand Down
4 changes: 2 additions & 2 deletions lib/src/visitor/evaluate.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// DO NOT EDIT. This file was generated from async_evaluate.dart.
// See tool/grind/synchronize.dart for details.
//
// Checksum: 57da0468055183da41deb31e5675447fe569975f
// Checksum: 4f4c80ef555355f888e134d764121a1117d4020c
//
// ignore_for_file: unused_import

Expand Down Expand Up @@ -377,7 +377,7 @@ final class _EvaluateVisitor
}) : _importCache =
importCache ?? (nodeImporter == null ? ImportCache.none() : null),
_nodeImporter = nodeImporter,
_logger = logger ?? const Logger.stderr(),
_logger = logger ?? Logger.defaultLogger,
_quietDeps = quietDeps,
_sourceMap = sourceMap,
// The default environment is overridden in [_execute] for full
Expand Down
2 changes: 1 addition & 1 deletion lib/src/visitor/serialize.dart
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ final class _SerializeVisitor
_indentCharacter = useSpaces ? $space : $tab,
_indentWidth = indentWidth ?? 2,
_lineFeed = lineFeed ?? LineFeed.lf,
_logger = logger ?? const Logger.stderr() {
_logger = logger ?? Logger.defaultLogger {
RangeError.checkValueInInterval(_indentWidth, 0, 10, "indentWidth");
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/sass_api/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
## 17.3.4-dev
## 17.4.0-dev

* No user-visible changes.

Expand Down
4 changes: 2 additions & 2 deletions pkg/sass_api/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ name: sass_api
# Note: Every time we add a new Sass AST node, we need to bump the *major*
# version because it's a breaking change for anyone who's implementing the
# visitor interface(s).
version: 17.3.4-dev
version: 17.4.0-dev
description: Additional APIs for Dart Sass.
homepage: https://github.com/sass/dart-sass

environment:
sdk: ">=3.6.0 <4.0.0"

dependencies:
sass: 1.97.4
sass: 1.98.0

dev_dependencies:
dartdoc: ">=8.0.14 <10.0.0"
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: sass
version: 1.97.4-dev
version: 1.98.0-dev
description: A Sass implementation in Dart.
homepage: https://github.com/sass/dart-sass

Expand Down