Skip to content

Commit

Permalink
Backport deprecation API to legacy JS API
Browse files Browse the repository at this point in the history
  • Loading branch information
jathak committed Jul 29, 2024
1 parent d0e02eb commit 617de35
Show file tree
Hide file tree
Showing 15 changed files with 247 additions and 104 deletions.
15 changes: 15 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
## 1.78.0

### JS API

* Backport the deprecation options (`fatalDeprecations`, `futureDeprecations`,
and `silenceDeprecations`) to the legacy JS API. The legacy JS API is itself
deprecated, and you should move off of it if possible, but this will allow
users of bundlers and other tools that are still using the legacy API to
still control deprecation warnings.

### Embedded Sass

* Fix a bug where parse-time deprecation warnings could not be controlled by
the deprecation options in some circumstances.

## 1.77.8

* No user-visible changes.
Expand Down
19 changes: 7 additions & 12 deletions bin/sass.dart
Original file line number Diff line number Diff line change
Expand Up @@ -46,18 +46,13 @@ Future<void> main(List<String> args) async {
}

var graph = StylesheetGraph(ImportCache(
importers: [...options.pkgImporters, FilesystemImporter.noLoadPath],
loadPaths: options.loadPaths,
// This logger is only used for handling fatal/future deprecations
// during parsing, and is re-used across parses, so we don't want to
// limit repetition. A separate DeprecationHandlingLogger is created for
// each compilation, which will limit repetition if verbose is not
// passed in addition to handling fatal/future deprecations.
logger: DeprecationProcessingLogger(options.logger,
silenceDeprecations: options.silenceDeprecations,
fatalDeprecations: options.fatalDeprecations,
futureDeprecations: options.futureDeprecations,
limitRepetition: false)));
importers: [...options.pkgImporters, FilesystemImporter.noLoadPath],
loadPaths: options.loadPaths,
logger: options.logger,
silenceDeprecations: options.silenceDeprecations,
fatalDeprecations: options.fatalDeprecations,
futureDeprecations: options.futureDeprecations,
));
if (options.watch) {
await watch(options, graph);
return;
Expand Down
20 changes: 16 additions & 4 deletions lib/sass.dart
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,10 @@ CompileResult compileToResult(String path,
importers: importers,
logger: logger ?? Logger.stderr(color: color),
loadPaths: loadPaths,
packageConfig: packageConfig),
packageConfig: packageConfig,
silenceDeprecations: {...?silenceDeprecations},
fatalDeprecations: {...?fatalDeprecations},
futureDeprecations: {...?futureDeprecations}),
functions: functions,
style: style,
quietDeps: quietDeps,
Expand Down Expand Up @@ -219,7 +222,10 @@ CompileResult compileStringToResult(String source,
importers: importers,
logger: logger ?? Logger.stderr(color: color),
packageConfig: packageConfig,
loadPaths: loadPaths),
loadPaths: loadPaths,
silenceDeprecations: {...?silenceDeprecations},
fatalDeprecations: {...?fatalDeprecations},
futureDeprecations: {...?futureDeprecations}),
functions: functions,
style: style,
importer: importer,
Expand Down Expand Up @@ -258,7 +264,10 @@ Future<CompileResult> compileToResultAsync(String path,
importers: importers,
logger: logger ?? Logger.stderr(color: color),
loadPaths: loadPaths,
packageConfig: packageConfig),
packageConfig: packageConfig,
silenceDeprecations: {...?silenceDeprecations},
fatalDeprecations: {...?fatalDeprecations},
futureDeprecations: {...?futureDeprecations}),
functions: functions,
style: style,
quietDeps: quietDeps,
Expand Down Expand Up @@ -301,7 +310,10 @@ Future<CompileResult> compileStringToResultAsync(String source,
importers: importers,
logger: logger ?? Logger.stderr(color: color),
packageConfig: packageConfig,
loadPaths: loadPaths),
loadPaths: loadPaths,
silenceDeprecations: {...?silenceDeprecations},
fatalDeprecations: {...?fatalDeprecations},
futureDeprecations: {...?futureDeprecations}),
functions: functions,
style: style,
importer: importer,
Expand Down
14 changes: 8 additions & 6 deletions lib/src/async_compile.dart
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,13 @@ Future<CompileResult> compileAsync(String path,
Iterable<Deprecation>? silenceDeprecations,
Iterable<Deprecation>? fatalDeprecations,
Iterable<Deprecation>? futureDeprecations}) async {
DeprecationProcessingLogger deprecationLogger = logger =
DeprecationProcessingLogger(logger ?? Logger.stderr(),
DeprecationProcessingLogger deprecationLogger =
logger = DeprecationProcessingLogger(logger ?? Logger.stderr(),
silenceDeprecations: {...?silenceDeprecations},
fatalDeprecations: {...?fatalDeprecations},
futureDeprecations: {...?futureDeprecations},
limitRepetition: !verbose);
limitRepetition: !verbose)
..validate();

// If the syntax is different than the importer would default to, we have to
// parse the file manually and we can't store it in the cache.
Expand Down Expand Up @@ -111,12 +112,13 @@ Future<CompileResult> compileStringAsync(String source,
Iterable<Deprecation>? silenceDeprecations,
Iterable<Deprecation>? fatalDeprecations,
Iterable<Deprecation>? futureDeprecations}) async {
DeprecationProcessingLogger deprecationLogger = logger =
DeprecationProcessingLogger(logger ?? Logger.stderr(),
DeprecationProcessingLogger deprecationLogger =
logger = DeprecationProcessingLogger(logger ?? Logger.stderr(),
silenceDeprecations: {...?silenceDeprecations},
fatalDeprecations: {...?fatalDeprecations},
futureDeprecations: {...?futureDeprecations},
limitRepetition: !verbose);
limitRepetition: !verbose)
..validate();

var stylesheet =
Stylesheet.parse(source, syntax ?? Syntax.scss, url: url, logger: logger);
Expand Down
51 changes: 45 additions & 6 deletions lib/src/async_import_cache.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import 'importer/no_op.dart';
import 'importer/utils.dart';
import 'io.dart';
import 'logger.dart';
import 'logger/deprecation_processing.dart';
import 'util/map.dart';
import 'util/nullable.dart';
import 'utils.dart';
Expand Down Expand Up @@ -95,20 +96,40 @@ final class AsyncImportCache {
{Iterable<AsyncImporter>? importers,
Iterable<String>? loadPaths,
PackageConfig? packageConfig,
Logger? logger})
Logger? logger,
Set<Deprecation>? fatalDeprecations,
Set<Deprecation>? futureDeprecations,
Set<Deprecation>? silenceDeprecations})
: _importers = _toImporters(importers, loadPaths, packageConfig),
_logger = logger ?? const Logger.stderr();
_logger = _makeLogger(logger,
fatalDeprecations: fatalDeprecations,
futureDeprecations: futureDeprecations,
silenceDeprecations: silenceDeprecations);

/// Creates an import cache without any globally-available importers.
AsyncImportCache.none({Logger? logger})
AsyncImportCache.none(
{Logger? logger,
Set<Deprecation>? fatalDeprecations,
Set<Deprecation>? futureDeprecations,
Set<Deprecation>? silenceDeprecations})
: _importers = const [],
_logger = logger ?? const Logger.stderr();
_logger = _makeLogger(logger,
fatalDeprecations: fatalDeprecations,
futureDeprecations: futureDeprecations,
silenceDeprecations: silenceDeprecations);

/// Creates an import cache without any globally-available importers, and only
/// the passed in importers.
AsyncImportCache.only(Iterable<AsyncImporter> importers, {Logger? logger})
AsyncImportCache.only(Iterable<AsyncImporter> importers,
{Logger? logger,
Set<Deprecation>? fatalDeprecations,
Set<Deprecation>? futureDeprecations,
Set<Deprecation>? silenceDeprecations})
: _importers = List.unmodifiable(importers),
_logger = logger ?? const Logger.stderr();
_logger = _makeLogger(logger,
fatalDeprecations: fatalDeprecations,
futureDeprecations: futureDeprecations,
silenceDeprecations: silenceDeprecations);

/// Converts the user's [importers], [loadPaths], and [packageConfig]
/// options into a single list of importers.
Expand All @@ -127,6 +148,24 @@ final class AsyncImportCache {
];
}

/// Wraps [logger] to support deprecation options, unless [logger] is already
/// a [DeprecationProcessingLogger].
static DeprecationProcessingLogger _makeLogger(Logger? logger,
{Set<Deprecation>? fatalDeprecations,
Set<Deprecation>? futureDeprecations,
Set<Deprecation>? silenceDeprecations}) =>
switch (logger) {
DeprecationProcessingLogger logger => logger,
_ => DeprecationProcessingLogger(logger ?? const Logger.stderr(),
fatalDeprecations: fatalDeprecations ?? const {},
futureDeprecations: futureDeprecations ?? const {},
silenceDeprecations: silenceDeprecations ?? const {},
// This wrapper may be used for multiple compilations, so we don't
// limit repetition to make sure warnings are emitted with each
// compilation.
limitRepetition: false),
};

/// Canonicalizes [url] according to one of this cache's importers.
///
/// The [baseUrl] should be the canonical URL of the stylesheet that contains
Expand Down
16 changes: 9 additions & 7 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: ab2c6fa2588988a86abdbe87512134098e01b39e
// Checksum: 69b31749dc94c7f717e9d395327e4209c4d3feb0
//
// ignore_for_file: unused_import

Expand Down Expand Up @@ -54,12 +54,13 @@ CompileResult compile(String path,
Iterable<Deprecation>? silenceDeprecations,
Iterable<Deprecation>? fatalDeprecations,
Iterable<Deprecation>? futureDeprecations}) {
DeprecationProcessingLogger deprecationLogger = logger =
DeprecationProcessingLogger(logger ?? Logger.stderr(),
DeprecationProcessingLogger deprecationLogger =
logger = DeprecationProcessingLogger(logger ?? Logger.stderr(),
silenceDeprecations: {...?silenceDeprecations},
fatalDeprecations: {...?fatalDeprecations},
futureDeprecations: {...?futureDeprecations},
limitRepetition: !verbose);
limitRepetition: !verbose)
..validate();

// If the syntax is different than the importer would default to, we have to
// parse the file manually and we can't store it in the cache.
Expand Down Expand Up @@ -120,12 +121,13 @@ CompileResult compileString(String source,
Iterable<Deprecation>? silenceDeprecations,
Iterable<Deprecation>? fatalDeprecations,
Iterable<Deprecation>? futureDeprecations}) {
DeprecationProcessingLogger deprecationLogger = logger =
DeprecationProcessingLogger(logger ?? Logger.stderr(),
DeprecationProcessingLogger deprecationLogger =
logger = DeprecationProcessingLogger(logger ?? Logger.stderr(),
silenceDeprecations: {...?silenceDeprecations},
fatalDeprecations: {...?fatalDeprecations},
futureDeprecations: {...?futureDeprecations},
limitRepetition: !verbose);
limitRepetition: !verbose)
..validate();

var stylesheet =
Stylesheet.parse(source, syntax ?? Syntax.scss, url: url, logger: logger);
Expand Down
1 change: 1 addition & 0 deletions lib/src/deprecation.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import 'package:cli_pkg/js.dart';
import 'package:collection/collection.dart';
import 'package:pub_semver/pub_semver.dart';

import 'logger.dart';
import 'util/nullable.dart';

/// A deprecated feature in the language.
Expand Down
5 changes: 4 additions & 1 deletion lib/src/executable/compile_stylesheet.dart
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,10 @@ Future<void> _compileStylesheetWithoutErrorHandling(ExecutableOptions options,
var importCache = AsyncImportCache(
importers: options.pkgImporters,
loadPaths: options.loadPaths,
logger: options.logger);
logger: options.logger,
silenceDeprecations: options.silenceDeprecations,
fatalDeprecations: options.fatalDeprecations,
futureDeprecations: options.futureDeprecations);

result = source == null
? await compileStringAsync(await readStdin(),
Expand Down
53 changes: 46 additions & 7 deletions lib/src/import_cache.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_import_cache.dart.
// See tool/grind/synchronize.dart for details.
//
// Checksum: 4362e28e5cd425786c235d2a6a2bb60539403799
// Checksum: eabe4eaed7125aa058e11e5442a7e9f2e696df26
//
// ignore_for_file: unused_import

Expand All @@ -23,6 +23,7 @@ import 'importer/no_op.dart';
import 'importer/utils.dart';
import 'io.dart';
import 'logger.dart';
import 'logger/deprecation_processing.dart';
import 'util/map.dart';
import 'util/nullable.dart';
import 'utils.dart';
Expand Down Expand Up @@ -96,20 +97,40 @@ final class ImportCache {
{Iterable<Importer>? importers,
Iterable<String>? loadPaths,
PackageConfig? packageConfig,
Logger? logger})
Logger? logger,
Set<Deprecation>? fatalDeprecations,
Set<Deprecation>? futureDeprecations,
Set<Deprecation>? silenceDeprecations})
: _importers = _toImporters(importers, loadPaths, packageConfig),
_logger = logger ?? const Logger.stderr();
_logger = _makeLogger(logger,
fatalDeprecations: fatalDeprecations,
futureDeprecations: futureDeprecations,
silenceDeprecations: silenceDeprecations);

/// Creates an import cache without any globally-available importers.
ImportCache.none({Logger? logger})
ImportCache.none(
{Logger? logger,
Set<Deprecation>? fatalDeprecations,
Set<Deprecation>? futureDeprecations,
Set<Deprecation>? silenceDeprecations})
: _importers = const [],
_logger = logger ?? const Logger.stderr();
_logger = _makeLogger(logger,
fatalDeprecations: fatalDeprecations,
futureDeprecations: futureDeprecations,
silenceDeprecations: silenceDeprecations);

/// Creates an import cache without any globally-available importers, and only
/// the passed in importers.
ImportCache.only(Iterable<Importer> importers, {Logger? logger})
ImportCache.only(Iterable<Importer> importers,
{Logger? logger,
Set<Deprecation>? fatalDeprecations,
Set<Deprecation>? futureDeprecations,
Set<Deprecation>? silenceDeprecations})
: _importers = List.unmodifiable(importers),
_logger = logger ?? const Logger.stderr();
_logger = _makeLogger(logger,
fatalDeprecations: fatalDeprecations,
futureDeprecations: futureDeprecations,
silenceDeprecations: silenceDeprecations);

/// Converts the user's [importers], [loadPaths], and [packageConfig]
/// options into a single list of importers.
Expand All @@ -128,6 +149,24 @@ final class ImportCache {
];
}

/// Wraps [logger] to support deprecation options, unless [logger] is already
/// a [DeprecationProcessingLogger].
static DeprecationProcessingLogger _makeLogger(Logger? logger,
{Set<Deprecation>? fatalDeprecations,
Set<Deprecation>? futureDeprecations,
Set<Deprecation>? silenceDeprecations}) =>
switch (logger) {
DeprecationProcessingLogger logger => logger,
_ => DeprecationProcessingLogger(logger ?? const Logger.stderr(),
fatalDeprecations: fatalDeprecations ?? const {},
futureDeprecations: futureDeprecations ?? const {},
silenceDeprecations: silenceDeprecations ?? const {},
// This wrapper may be used for multiple compilations, so we don't
// limit repetition to make sure warnings are emitted with each
// compilation.
limitRepetition: false),
};

/// Canonicalizes [url] according to one of this cache's importers.
///
/// The [baseUrl] should be the canonical URL of the stylesheet that contains
Expand Down
Loading

0 comments on commit 617de35

Please sign in to comment.