Skip to content

Commit

Permalink
Backport deprecation API to legacy JS API (#2293)
Browse files Browse the repository at this point in the history
  • Loading branch information
jathak committed Sep 3, 2024
1 parent 56a4237 commit b1d5f98
Show file tree
Hide file tree
Showing 18 changed files with 251 additions and 151 deletions.
102 changes: 52 additions & 50 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -312,61 +312,63 @@ jobs:
env:
CHROME_EXECUTABLE: chrome

sass_parser_tests:
name: "sass-parser Tests | Dart ${{ matrix.dart_channel }} | Node ${{ matrix.node-version }}"
runs-on: ubuntu-latest
# TODO - sass/dart-sass#2329: Re-enable once these errors are resolved.

strategy:
fail-fast: false
matrix:
dart_channel: [stable]
node-version: ['lts/*']
include:
# Test older LTS versions
#
# TODO: Test on lts/-2 and lts/-3 once they support
# `structuredClone()` (that is, once they're v18 or later).
- os: ubuntu-latest
dart_channel: stable
node-version: lts/-1
# Test LTS version with dart dev channel
- os: ubuntu-latest
dart_channel: dev
node-version: 'lts/*'
# sass_parser_tests:
# name: "sass-parser Tests | Dart ${{ matrix.dart_channel }} | Node ${{ matrix.node-version }}"
# runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- uses: ./.github/util/initialize
with:
dart-sdk: ${{ matrix.dart_channel }}
github-token: ${{ github.token }}
node-version: ${{ matrix.node-version }}
# strategy:
# fail-fast: false
# matrix:
# dart_channel: [stable]
# node-version: ['lts/*']
# include:
# # Test older LTS versions
# #
# # TODO: Test on lts/-2 and lts/-3 once they support
# # `structuredClone()` (that is, once they're v18 or later).
# - os: ubuntu-latest
# dart_channel: stable
# node-version: lts/-1
# # Test LTS version with dart dev channel
# - os: ubuntu-latest
# dart_channel: dev
# node-version: 'lts/*'

- run: dart run grinder pkg-npm-dev
env: {UPDATE_SASS_SASS_REPO: false}
- run: npm link
working-directory: build/npm
- run: npm install
working-directory: pkg/sass-parser/
- run: npm link sass
working-directory: pkg/sass-parser/
- name: Run tests
run: npm test
working-directory: pkg/sass-parser/
# steps:
# - uses: actions/checkout@v4
# - uses: ./.github/util/initialize
# with:
# dart-sdk: ${{ matrix.dart_channel }}
# github-token: ${{ github.token }}
# node-version: ${{ matrix.node-version }}

# - run: dart run grinder pkg-npm-dev
# env: {UPDATE_SASS_SASS_REPO: false}
# - run: npm link
# working-directory: build/npm
# - run: npm install
# working-directory: pkg/sass-parser/
# - run: npm link sass
# working-directory: pkg/sass-parser/
# - name: Run tests
# run: npm test
# working-directory: pkg/sass-parser/

sass_parser_static_analysis:
name: "sass-parser Static Analysis"
runs-on: ubuntu-latest
# sass_parser_static_analysis:
# name: "sass-parser Static Analysis"
# runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with: {node-version: 'lts/*'}
- run: npm install
working-directory: pkg/sass-parser/
- name: Run static analysis
run: npm run check
working-directory: pkg/sass-parser/
# steps:
# - uses: actions/checkout@v4
# - uses: actions/setup-node@v4
# with: {node-version: 'lts/*'}
# - run: npm install
# working-directory: pkg/sass-parser/
# - name: Run static analysis
# run: npm run check
# working-directory: pkg/sass-parser/

# TODO - postcss/postcss#1958: Enable this once PostCSS doesn't have TypeDoc
# warnings.
Expand Down
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@

### 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.

* Fix a bug where accessing `SourceSpan.url` would crash when a relative URL was
passed to the Sass API.

Expand All @@ -28,6 +34,9 @@
* Fix a race condition where the embedded host could fail to shut down if it was
closed around the same time a new compilation was started.

* 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
16 changes: 5 additions & 11 deletions bin/sass.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import 'package:sass/src/executable/watch.dart';
import 'package:sass/src/import_cache.dart';
import 'package:sass/src/importer/filesystem.dart';
import 'package:sass/src/io.dart';
import 'package:sass/src/logger/deprecation_processing.dart';
import 'package:sass/src/stylesheet_graph.dart';
import 'package:sass/src/utils.dart';
import 'package:sass/src/embedded/executable.dart'
Expand Down Expand Up @@ -48,16 +47,11 @@ 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)));
logger: ImportCache.wrapLogger(
options.logger,
options.silenceDeprecations,
options.fatalDeprecations,
options.futureDeprecations)));
if (options.watch) {
await watch(options, graph);
return;
Expand Down
16 changes: 12 additions & 4 deletions lib/sass.dart
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,9 @@ CompileResult compileToResult(String path,
logger: logger,
importCache: ImportCache(
importers: importers,
logger: logger ?? Logger.stderr(color: color),
logger: ImportCache.wrapLogger(logger, silenceDeprecations,
fatalDeprecations, futureDeprecations,
color: color),
loadPaths: loadPaths,
packageConfig: packageConfig),
functions: functions,
Expand Down Expand Up @@ -217,7 +219,9 @@ CompileResult compileStringToResult(String source,
logger: logger,
importCache: ImportCache(
importers: importers,
logger: logger ?? Logger.stderr(color: color),
logger: ImportCache.wrapLogger(logger, silenceDeprecations,
fatalDeprecations, futureDeprecations,
color: color),
packageConfig: packageConfig,
loadPaths: loadPaths),
functions: functions,
Expand Down Expand Up @@ -256,7 +260,9 @@ Future<CompileResult> compileToResultAsync(String path,
logger: logger,
importCache: AsyncImportCache(
importers: importers,
logger: logger ?? Logger.stderr(color: color),
logger: AsyncImportCache.wrapLogger(logger, silenceDeprecations,
fatalDeprecations, futureDeprecations,
color: color),
loadPaths: loadPaths,
packageConfig: packageConfig),
functions: functions,
Expand Down Expand Up @@ -299,7 +305,9 @@ Future<CompileResult> compileStringToResultAsync(String source,
logger: logger,
importCache: AsyncImportCache(
importers: importers,
logger: logger ?? Logger.stderr(color: color),
logger: AsyncImportCache.wrapLogger(logger, silenceDeprecations,
fatalDeprecations, futureDeprecations,
color: color),
packageConfig: packageConfig,
loadPaths: loadPaths),
functions: functions,
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
28 changes: 25 additions & 3 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 @@ -97,18 +98,18 @@ final class AsyncImportCache {
PackageConfig? packageConfig,
Logger? logger})
: _importers = _toImporters(importers, loadPaths, packageConfig),
_logger = logger ?? const Logger.stderr();
_logger = logger ?? Logger.stderr();

/// Creates an import cache without any globally-available importers.
AsyncImportCache.none({Logger? logger})
: _importers = const [],
_logger = logger ?? const Logger.stderr();
_logger = logger ?? Logger.stderr();

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

/// Converts the user's [importers], [loadPaths], and [packageConfig]
/// options into a single list of importers.
Expand Down Expand Up @@ -360,4 +361,25 @@ final class AsyncImportCache {
_resultsCache.remove(canonicalUrl);
_importCache.remove(canonicalUrl);
}

/// Wraps [logger] to process deprecations within an ImportCache.
///
/// This wrapped logger will handle the deprecation options, but will not
/// limit repetition, as it can be re-used across parses. A logger passed to
/// an ImportCache or AsyncImportCache should generally be wrapped here first,
/// unless it's already been wrapped to process deprecations, in which case
/// this method has no effect.
static DeprecationProcessingLogger wrapLogger(
Logger? logger,
Iterable<Deprecation>? silenceDeprecations,
Iterable<Deprecation>? fatalDeprecations,
Iterable<Deprecation>? futureDeprecations,
{bool color = false}) {
if (logger is DeprecationProcessingLogger) return logger;
return DeprecationProcessingLogger(logger ?? Logger.stderr(color: color),
silenceDeprecations: {...?silenceDeprecations},
fatalDeprecations: {...?fatalDeprecations},
futureDeprecations: {...?futureDeprecations},
limitRepetition: false);
}
}
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
6 changes: 5 additions & 1 deletion lib/src/executable/compile_stylesheet.dart
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,11 @@ Future<void> _compileStylesheetWithoutErrorHandling(ExecutableOptions options,
var importCache = AsyncImportCache(
importers: options.pkgImporters,
loadPaths: options.loadPaths,
logger: options.logger);
logger: AsyncImportCache.wrapLogger(
options.logger,
options.silenceDeprecations,
options.fatalDeprecations,
options.futureDeprecations));

result = source == null
? await compileStringAsync(await readStdin(),
Expand Down
3 changes: 2 additions & 1 deletion lib/src/executable/repl.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ Future<void> repl(ExecutableOptions options) async {
silenceDeprecations: options.silenceDeprecations,
fatalDeprecations: options.fatalDeprecations,
futureDeprecations: options.futureDeprecations,
limitRepetition: !options.verbose);
limitRepetition: !options.verbose)
..validate();
var evaluator = Evaluator(
importer: FilesystemImporter.cwd,
importCache: ImportCache(
Expand Down
Loading

0 comments on commit b1d5f98

Please sign in to comment.