Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Complete implementation the deprecations API #2207

Merged
merged 11 commits into from
Apr 3, 2024
Merged
Show file tree
Hide file tree
Changes from 8 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
35 changes: 35 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,38 @@
## 1.74.0

### JS API

* The deprecations API is now available in the JS API! The `compile` methods
support the same `fatalDeprecations` and `futureDeprecations` options that
were already available in the Dart API and the CLI, as well as a new
`silenceDeprecations` option that allows you to silence deprecation warnings
of a given type.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a fair bet that most JS API users don't know or follow the Dart API, so it's probably better to frame this as adding three new features to the JS API rather than bringing two from the Dart API and adding one new

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done


### Command-Line Interface

* Add a new `--silence-deprecation` flag to match the new JS API.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similarly, although to a lesser extent, the CLI users are a somewhat different set than the JS API users. Better to keep the CLI descriptions as self-contained as possible—it's less net effort for us to duplicate some prose than for a bunch of readers to read extra paragraphs.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done


* Previously, if a future deprecation was passed to `--fatal-deprecation` but
not `--future-deprecation`, it would be treated as fatal despite not being
enabled. Both flags are now required to treat a future deprecation as fatal
with a warning emitted if `--fatal-deprecation` is passed without
`--future-deprecation`, matching the JS API's behavior.

### Dart API

* The `compile` methods now take in a `silenceDeprecations` parameter to match
the JS API.

* Add `Deprecation.obsoleteIn` to match the JS API. This is currently null for
all deprecations, but will be used once some deprecations become obsolete in
Dart Sass 2.0.0.

* Fix a bug where `compileStringToResultAsync` ignored `fatalDeprecations` and
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd mark this as **Potentially breaking bug fix:** on the off chance that someone was doing it without realizing that it wasn't failing.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

`futureDeprecations`.

* The behavior around making future deprecations fatal mentioned in the CLI
section above has also been changed in the Dart API.

## 1.73.0

* Add support for nesting in plain CSS files. This is not processed by Sass at
Expand Down
1 change: 1 addition & 0 deletions bin/sass.dart
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ Future<void> main(List<String> args) async {
// each compilation, which will limit repetition if verbose is not
// passed in addition to handling fatal/future deprecations.
logger: DeprecationHandlingLogger(options.logger,
silenceDeprecations: options.silenceDeprecations,
fatalDeprecations: options.fatalDeprecations,
futureDeprecations: options.futureDeprecations,
limitRepetition: false)));
Expand Down
12 changes: 11 additions & 1 deletion lib/sass.dart
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ CompileResult compileToResult(String path,
bool verbose = false,
bool sourceMap = false,
bool charset = true,
Iterable<Deprecation>? silenceDeprecations,
Iterable<Deprecation>? fatalDeprecations,
Iterable<Deprecation>? futureDeprecations}) =>
c.compile(path,
Expand All @@ -123,6 +124,7 @@ CompileResult compileToResult(String path,
verbose: verbose,
sourceMap: sourceMap,
charset: charset,
silenceDeprecations: silenceDeprecations,
fatalDeprecations: fatalDeprecations,
futureDeprecations: futureDeprecations);

Expand Down Expand Up @@ -207,6 +209,7 @@ CompileResult compileStringToResult(String source,
bool verbose = false,
bool sourceMap = false,
bool charset = true,
Iterable<Deprecation>? silenceDeprecations,
Iterable<Deprecation>? fatalDeprecations,
Iterable<Deprecation>? futureDeprecations}) =>
c.compileString(source,
Expand All @@ -225,6 +228,7 @@ CompileResult compileStringToResult(String source,
verbose: verbose,
sourceMap: sourceMap,
charset: charset,
silenceDeprecations: silenceDeprecations,
fatalDeprecations: fatalDeprecations,
futureDeprecations: futureDeprecations);

Expand All @@ -245,6 +249,7 @@ Future<CompileResult> compileToResultAsync(String path,
bool verbose = false,
bool sourceMap = false,
bool charset = true,
Iterable<Deprecation>? silenceDeprecations,
Iterable<Deprecation>? fatalDeprecations,
Iterable<Deprecation>? futureDeprecations}) =>
c.compileAsync(path,
Expand All @@ -260,6 +265,7 @@ Future<CompileResult> compileToResultAsync(String path,
verbose: verbose,
sourceMap: sourceMap,
charset: charset,
silenceDeprecations: silenceDeprecations,
fatalDeprecations: fatalDeprecations,
futureDeprecations: futureDeprecations);

Expand All @@ -285,6 +291,7 @@ Future<CompileResult> compileStringToResultAsync(String source,
bool verbose = false,
bool sourceMap = false,
bool charset = true,
Iterable<Deprecation>? silenceDeprecations,
Iterable<Deprecation>? fatalDeprecations,
Iterable<Deprecation>? futureDeprecations}) =>
c.compileStringAsync(source,
Expand All @@ -302,7 +309,10 @@ Future<CompileResult> compileStringToResultAsync(String source,
quietDeps: quietDeps,
verbose: verbose,
sourceMap: sourceMap,
charset: charset);
charset: charset,
silenceDeprecations: silenceDeprecations,
fatalDeprecations: fatalDeprecations,
futureDeprecations: futureDeprecations);

/// Like [compileToResult], but returns [CompileResult.css] rather than
/// returning [CompileResult] directly.
Expand Down
4 changes: 4 additions & 0 deletions lib/src/async_compile.dart
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,12 @@ Future<CompileResult> compileAsync(String path,
bool verbose = false,
bool sourceMap = false,
bool charset = true,
Iterable<Deprecation>? silenceDeprecations,
Iterable<Deprecation>? fatalDeprecations,
Iterable<Deprecation>? futureDeprecations}) async {
DeprecationHandlingLogger deprecationLogger = logger =
DeprecationHandlingLogger(logger ?? Logger.stderr(),
silenceDeprecations: {...?silenceDeprecations},
fatalDeprecations: {...?fatalDeprecations},
futureDeprecations: {...?futureDeprecations},
limitRepetition: !verbose);
Expand Down Expand Up @@ -106,10 +108,12 @@ Future<CompileResult> compileStringAsync(String source,
bool verbose = false,
bool sourceMap = false,
bool charset = true,
Iterable<Deprecation>? silenceDeprecations,
Iterable<Deprecation>? fatalDeprecations,
Iterable<Deprecation>? futureDeprecations}) async {
DeprecationHandlingLogger deprecationLogger = logger =
DeprecationHandlingLogger(logger ?? Logger.stderr(),
silenceDeprecations: {...?silenceDeprecations},
fatalDeprecations: {...?fatalDeprecations},
futureDeprecations: {...?futureDeprecations},
limitRepetition: !verbose);
Expand Down
6 changes: 5 additions & 1 deletion 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: a9421a2975e79ad591ae32474cd076e1379d0e75
// Checksum: 9d2d66aa8a5b5613cbae25c448356526aebbadbf
//
// ignore_for_file: unused_import

Expand Down Expand Up @@ -51,10 +51,12 @@ CompileResult compile(String path,
bool verbose = false,
bool sourceMap = false,
bool charset = true,
Iterable<Deprecation>? silenceDeprecations,
Iterable<Deprecation>? fatalDeprecations,
Iterable<Deprecation>? futureDeprecations}) {
DeprecationHandlingLogger deprecationLogger = logger =
DeprecationHandlingLogger(logger ?? Logger.stderr(),
silenceDeprecations: {...?silenceDeprecations},
fatalDeprecations: {...?fatalDeprecations},
futureDeprecations: {...?futureDeprecations},
limitRepetition: !verbose);
Expand Down Expand Up @@ -115,10 +117,12 @@ CompileResult compileString(String source,
bool verbose = false,
bool sourceMap = false,
bool charset = true,
Iterable<Deprecation>? silenceDeprecations,
Iterable<Deprecation>? fatalDeprecations,
Iterable<Deprecation>? futureDeprecations}) {
DeprecationHandlingLogger deprecationLogger = logger =
DeprecationHandlingLogger(logger ?? Logger.stderr(),
silenceDeprecations: {...?silenceDeprecations},
fatalDeprecations: {...?fatalDeprecations},
futureDeprecations: {...?futureDeprecations},
limitRepetition: !verbose);
Expand Down
14 changes: 14 additions & 0 deletions lib/src/deprecation.dart
Original file line number Diff line number Diff line change
Expand Up @@ -112,14 +112,28 @@ enum Deprecation {
/// what version of Dart Sass this deprecation will be live in.
final bool isFuture;

/// Underlying version string used by [obsoleteIn].
///
/// This is necessary because [Version] doesn't have a constant constructor,
/// so we can't use it directly as an enum property.
final String? _obsoleteIn;

/// The Dart Sass version this feature was fully removed in, making the
/// deprecation obsolete.
///
/// For deprecations that are not yet obsolete, this should be null.
Version? get obsoleteIn => _obsoleteIn?.andThen(Version.parse);

/// Constructs a regular deprecation.
const Deprecation(this.id, {required String? deprecatedIn, this.description})
: _deprecatedIn = deprecatedIn,
_obsoleteIn = null,
isFuture = false;

/// Constructs a future deprecation.
const Deprecation.future(this.id, {this.description})
: _deprecatedIn = null,
_obsoleteIn = null,
isFuture = true;

@override
Expand Down
22 changes: 22 additions & 0 deletions lib/src/embedded/compilation_dispatcher.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import 'dart:io';
import 'dart:isolate';
import 'dart:typed_data';

import 'package:collection/collection.dart';
import 'package:native_synchronization/mailbox.dart';
import 'package:path/path.dart' as p;
import 'package:protobuf/protobuf.dart';
Expand Down Expand Up @@ -124,6 +125,21 @@ final class CompilationDispatcher {
: EmbeddedLogger(this,
color: request.alertColor, ascii: request.alertAscii);

sass.Deprecation? deprecationOrWarn(String id) {
var deprecation = sass.Deprecation.fromId(id);
if (deprecation == null) {
logger.warn('Invalid deprecation "$id".');
}
return deprecation;
}

var fatalDeprecations =
request.fatalDeprecation.map(deprecationOrWarn).whereNotNull();
var silenceDeprecations =
request.silenceDeprecation.map(deprecationOrWarn).whereNotNull();
var futureDeprecations =
request.futureDeprecation.map(deprecationOrWarn).whereNotNull();

try {
var importers = request.importers.map((importer) =>
_decodeImporter(request, importer) ??
Expand All @@ -148,6 +164,9 @@ final class CompilationDispatcher {
url: input.url.isEmpty ? null : input.url,
quietDeps: request.quietDeps,
verbose: request.verbose,
fatalDeprecations: fatalDeprecations,
silenceDeprecations: silenceDeprecations,
futureDeprecations: futureDeprecations,
sourceMap: request.sourceMap,
charset: request.charset);

Expand All @@ -165,6 +184,9 @@ final class CompilationDispatcher {
style: style,
quietDeps: request.quietDeps,
verbose: request.verbose,
fatalDeprecations: fatalDeprecations,
silenceDeprecations: silenceDeprecations,
futureDeprecations: futureDeprecations,
sourceMap: request.sourceMap,
charset: request.charset);
} on FileSystemException catch (error) {
Expand Down
9 changes: 7 additions & 2 deletions lib/src/embedded/logger.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import 'package:path/path.dart' as p;
import 'package:source_span/source_span.dart';
import 'package:stack_trace/stack_trace.dart';

import '../deprecation.dart';
import '../logger.dart';
import '../util/nullable.dart';
import '../utils.dart';
Expand All @@ -14,7 +15,7 @@ import 'embedded_sass.pb.dart' hide SourceSpan;
import 'utils.dart';

/// A Sass logger that sends log messages as `LogEvent`s.
final class EmbeddedLogger implements Logger {
final class EmbeddedLogger implements DeprecationLogger {
/// The [CompilationDispatcher] to which to send events.
final CompilationDispatcher _dispatcher;

Expand All @@ -40,7 +41,10 @@ final class EmbeddedLogger implements Logger {
}

void warn(String message,
{FileSpan? span, Trace? trace, bool deprecation = false}) {
{FileSpan? span,
Trace? trace,
bool deprecation = false,
Deprecation? deprecationType}) {
var formatted = withGlyphs(() {
var buffer = StringBuffer();
if (_color) {
Expand Down Expand Up @@ -71,6 +75,7 @@ final class EmbeddedLogger implements Logger {
..formatted = formatted;
if (span != null) event.span = protofySpan(span);
if (trace != null) event.stackTrace = trace.toString();
if (deprecationType != null) event.deprecationType = deprecationType.id;
_dispatcher.sendLog(event);
}
}
14 changes: 14 additions & 0 deletions lib/src/executable/options.dart
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,14 @@ final class ExecutableOptions {
"Stylesheets imported through load paths count as dependencies.")
..addFlag('verbose',
help: "Print all deprecation warnings even when they're repetitive.")
..addMultiOption('silence-deprecation',
help: 'Deprecations to ignore.',
allowedHelp: {
for (var deprecation in Deprecation.values)
if (deprecation.deprecatedIn != null &&
deprecation.description != null)
deprecation.id: deprecation.description!,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can use if ... case to avoid this nullability assertion

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

})
..addMultiOption('fatal-deprecation',
help: 'Deprecations to treat as errors. You may also pass a Sass\n'
'version to include any behavior deprecated in or before it.\n'
Expand Down Expand Up @@ -521,6 +529,12 @@ final class ExecutableOptions {
: p.absolute(path));
}

/// The set of deprecations whose warnings should be silenced.
Set<Deprecation> get silenceDeprecations => {
for (var id in _options['silence-deprecation'] as List<String>)
Deprecation.fromId(id) ?? _fail('Invalid deprecation "$id".')
};

/// The set of deprecations that cause errors.
Set<Deprecation> get fatalDeprecations => _fatalDeprecations ??= () {
var deprecations = <Deprecation>{};
Expand Down
5 changes: 5 additions & 0 deletions lib/src/js.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@
// MIT-style license that can be found in the LICENSE file or at
// https://opensource.org/licenses/MIT.

import 'package:js/js_util.dart';

import 'js/exception.dart';
import 'js/deprecations.dart';
import 'js/exports.dart';
import 'js/compile.dart';
import 'js/compiler.dart';
Expand Down Expand Up @@ -52,6 +55,8 @@ void main() {
warn: allowInteropNamed('sass.Logger.silent.warn', (_, __) {}),
debug: allowInteropNamed('sass.Logger.silent.debug', (_, __) {})));
exports.NodePackageImporter = nodePackageImporterClass;
exports.deprecations = jsify(deprecations);
exports.Version = versionClass;

exports.info =
"dart-sass\t${const String.fromEnvironment('version')}\t(Sass Compiler)\t"
Expand Down
Loading
Loading