Skip to content

Commit b1d5f98

Browse files
authored
Backport deprecation API to legacy JS API (#2293)
1 parent 56a4237 commit b1d5f98

18 files changed

+251
-151
lines changed

.github/workflows/test.yml

Lines changed: 52 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -312,61 +312,63 @@ jobs:
312312
env:
313313
CHROME_EXECUTABLE: chrome
314314

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

319-
strategy:
320-
fail-fast: false
321-
matrix:
322-
dart_channel: [stable]
323-
node-version: ['lts/*']
324-
include:
325-
# Test older LTS versions
326-
#
327-
# TODO: Test on lts/-2 and lts/-3 once they support
328-
# `structuredClone()` (that is, once they're v18 or later).
329-
- os: ubuntu-latest
330-
dart_channel: stable
331-
node-version: lts/-1
332-
# Test LTS version with dart dev channel
333-
- os: ubuntu-latest
334-
dart_channel: dev
335-
node-version: 'lts/*'
317+
# sass_parser_tests:
318+
# name: "sass-parser Tests | Dart ${{ matrix.dart_channel }} | Node ${{ matrix.node-version }}"
319+
# runs-on: ubuntu-latest
336320

337-
steps:
338-
- uses: actions/checkout@v4
339-
- uses: ./.github/util/initialize
340-
with:
341-
dart-sdk: ${{ matrix.dart_channel }}
342-
github-token: ${{ github.token }}
343-
node-version: ${{ matrix.node-version }}
321+
# strategy:
322+
# fail-fast: false
323+
# matrix:
324+
# dart_channel: [stable]
325+
# node-version: ['lts/*']
326+
# include:
327+
# # Test older LTS versions
328+
# #
329+
# # TODO: Test on lts/-2 and lts/-3 once they support
330+
# # `structuredClone()` (that is, once they're v18 or later).
331+
# - os: ubuntu-latest
332+
# dart_channel: stable
333+
# node-version: lts/-1
334+
# # Test LTS version with dart dev channel
335+
# - os: ubuntu-latest
336+
# dart_channel: dev
337+
# node-version: 'lts/*'
344338

345-
- run: dart run grinder pkg-npm-dev
346-
env: {UPDATE_SASS_SASS_REPO: false}
347-
- run: npm link
348-
working-directory: build/npm
349-
- run: npm install
350-
working-directory: pkg/sass-parser/
351-
- run: npm link sass
352-
working-directory: pkg/sass-parser/
353-
- name: Run tests
354-
run: npm test
355-
working-directory: pkg/sass-parser/
339+
# steps:
340+
# - uses: actions/checkout@v4
341+
# - uses: ./.github/util/initialize
342+
# with:
343+
# dart-sdk: ${{ matrix.dart_channel }}
344+
# github-token: ${{ github.token }}
345+
# node-version: ${{ matrix.node-version }}
346+
347+
# - run: dart run grinder pkg-npm-dev
348+
# env: {UPDATE_SASS_SASS_REPO: false}
349+
# - run: npm link
350+
# working-directory: build/npm
351+
# - run: npm install
352+
# working-directory: pkg/sass-parser/
353+
# - run: npm link sass
354+
# working-directory: pkg/sass-parser/
355+
# - name: Run tests
356+
# run: npm test
357+
# working-directory: pkg/sass-parser/
356358

357-
sass_parser_static_analysis:
358-
name: "sass-parser Static Analysis"
359-
runs-on: ubuntu-latest
359+
# sass_parser_static_analysis:
360+
# name: "sass-parser Static Analysis"
361+
# runs-on: ubuntu-latest
360362

361-
steps:
362-
- uses: actions/checkout@v4
363-
- uses: actions/setup-node@v4
364-
with: {node-version: 'lts/*'}
365-
- run: npm install
366-
working-directory: pkg/sass-parser/
367-
- name: Run static analysis
368-
run: npm run check
369-
working-directory: pkg/sass-parser/
363+
# steps:
364+
# - uses: actions/checkout@v4
365+
# - uses: actions/setup-node@v4
366+
# with: {node-version: 'lts/*'}
367+
# - run: npm install
368+
# working-directory: pkg/sass-parser/
369+
# - name: Run static analysis
370+
# run: npm run check
371+
# working-directory: pkg/sass-parser/
370372

371373
# TODO - postcss/postcss#1958: Enable this once PostCSS doesn't have TypeDoc
372374
# warnings.

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@
88

99
### JS API
1010

11+
* Backport the deprecation options (`fatalDeprecations`, `futureDeprecations`,
12+
and `silenceDeprecations`) to the legacy JS API. The legacy JS API is itself
13+
deprecated, and you should move off of it if possible, but this will allow
14+
users of bundlers and other tools that are still using the legacy API to
15+
still control deprecation warnings.
16+
1117
* Fix a bug where accessing `SourceSpan.url` would crash when a relative URL was
1218
passed to the Sass API.
1319

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

37+
* Fix a bug where parse-time deprecation warnings could not be controlled by
38+
the deprecation options in some circumstances.
39+
3140
## 1.77.8
3241

3342
* No user-visible changes.

bin/sass.dart

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import 'package:sass/src/executable/watch.dart';
1515
import 'package:sass/src/import_cache.dart';
1616
import 'package:sass/src/importer/filesystem.dart';
1717
import 'package:sass/src/io.dart';
18-
import 'package:sass/src/logger/deprecation_processing.dart';
1918
import 'package:sass/src/stylesheet_graph.dart';
2019
import 'package:sass/src/utils.dart';
2120
import 'package:sass/src/embedded/executable.dart'
@@ -48,16 +47,11 @@ Future<void> main(List<String> args) async {
4847
var graph = StylesheetGraph(ImportCache(
4948
importers: [...options.pkgImporters, FilesystemImporter.noLoadPath],
5049
loadPaths: options.loadPaths,
51-
// This logger is only used for handling fatal/future deprecations
52-
// during parsing, and is re-used across parses, so we don't want to
53-
// limit repetition. A separate DeprecationHandlingLogger is created for
54-
// each compilation, which will limit repetition if verbose is not
55-
// passed in addition to handling fatal/future deprecations.
56-
logger: DeprecationProcessingLogger(options.logger,
57-
silenceDeprecations: options.silenceDeprecations,
58-
fatalDeprecations: options.fatalDeprecations,
59-
futureDeprecations: options.futureDeprecations,
60-
limitRepetition: false)));
50+
logger: ImportCache.wrapLogger(
51+
options.logger,
52+
options.silenceDeprecations,
53+
options.fatalDeprecations,
54+
options.futureDeprecations)));
6155
if (options.watch) {
6256
await watch(options, graph);
6357
return;

lib/sass.dart

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,9 @@ CompileResult compileToResult(String path,
115115
logger: logger,
116116
importCache: ImportCache(
117117
importers: importers,
118-
logger: logger ?? Logger.stderr(color: color),
118+
logger: ImportCache.wrapLogger(logger, silenceDeprecations,
119+
fatalDeprecations, futureDeprecations,
120+
color: color),
119121
loadPaths: loadPaths,
120122
packageConfig: packageConfig),
121123
functions: functions,
@@ -217,7 +219,9 @@ CompileResult compileStringToResult(String source,
217219
logger: logger,
218220
importCache: ImportCache(
219221
importers: importers,
220-
logger: logger ?? Logger.stderr(color: color),
222+
logger: ImportCache.wrapLogger(logger, silenceDeprecations,
223+
fatalDeprecations, futureDeprecations,
224+
color: color),
221225
packageConfig: packageConfig,
222226
loadPaths: loadPaths),
223227
functions: functions,
@@ -256,7 +260,9 @@ Future<CompileResult> compileToResultAsync(String path,
256260
logger: logger,
257261
importCache: AsyncImportCache(
258262
importers: importers,
259-
logger: logger ?? Logger.stderr(color: color),
263+
logger: AsyncImportCache.wrapLogger(logger, silenceDeprecations,
264+
fatalDeprecations, futureDeprecations,
265+
color: color),
260266
loadPaths: loadPaths,
261267
packageConfig: packageConfig),
262268
functions: functions,
@@ -299,7 +305,9 @@ Future<CompileResult> compileStringToResultAsync(String source,
299305
logger: logger,
300306
importCache: AsyncImportCache(
301307
importers: importers,
302-
logger: logger ?? Logger.stderr(color: color),
308+
logger: AsyncImportCache.wrapLogger(logger, silenceDeprecations,
309+
fatalDeprecations, futureDeprecations,
310+
color: color),
303311
packageConfig: packageConfig,
304312
loadPaths: loadPaths),
305313
functions: functions,

lib/src/async_compile.dart

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,13 @@ Future<CompileResult> compileAsync(String path,
4545
Iterable<Deprecation>? silenceDeprecations,
4646
Iterable<Deprecation>? fatalDeprecations,
4747
Iterable<Deprecation>? futureDeprecations}) async {
48-
DeprecationProcessingLogger deprecationLogger = logger =
49-
DeprecationProcessingLogger(logger ?? Logger.stderr(),
48+
DeprecationProcessingLogger deprecationLogger =
49+
logger = DeprecationProcessingLogger(logger ?? Logger.stderr(),
5050
silenceDeprecations: {...?silenceDeprecations},
5151
fatalDeprecations: {...?fatalDeprecations},
5252
futureDeprecations: {...?futureDeprecations},
53-
limitRepetition: !verbose);
53+
limitRepetition: !verbose)
54+
..validate();
5455

5556
// If the syntax is different than the importer would default to, we have to
5657
// parse the file manually and we can't store it in the cache.
@@ -111,12 +112,13 @@ Future<CompileResult> compileStringAsync(String source,
111112
Iterable<Deprecation>? silenceDeprecations,
112113
Iterable<Deprecation>? fatalDeprecations,
113114
Iterable<Deprecation>? futureDeprecations}) async {
114-
DeprecationProcessingLogger deprecationLogger = logger =
115-
DeprecationProcessingLogger(logger ?? Logger.stderr(),
115+
DeprecationProcessingLogger deprecationLogger =
116+
logger = DeprecationProcessingLogger(logger ?? Logger.stderr(),
116117
silenceDeprecations: {...?silenceDeprecations},
117118
fatalDeprecations: {...?fatalDeprecations},
118119
futureDeprecations: {...?futureDeprecations},
119-
limitRepetition: !verbose);
120+
limitRepetition: !verbose)
121+
..validate();
120122

121123
var stylesheet =
122124
Stylesheet.parse(source, syntax ?? Syntax.scss, url: url, logger: logger);

lib/src/async_import_cache.dart

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import 'importer/no_op.dart';
1616
import 'importer/utils.dart';
1717
import 'io.dart';
1818
import 'logger.dart';
19+
import 'logger/deprecation_processing.dart';
1920
import 'util/map.dart';
2021
import 'util/nullable.dart';
2122
import 'utils.dart';
@@ -97,18 +98,18 @@ final class AsyncImportCache {
9798
PackageConfig? packageConfig,
9899
Logger? logger})
99100
: _importers = _toImporters(importers, loadPaths, packageConfig),
100-
_logger = logger ?? const Logger.stderr();
101+
_logger = logger ?? Logger.stderr();
101102

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

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

113114
/// Converts the user's [importers], [loadPaths], and [packageConfig]
114115
/// options into a single list of importers.
@@ -360,4 +361,25 @@ final class AsyncImportCache {
360361
_resultsCache.remove(canonicalUrl);
361362
_importCache.remove(canonicalUrl);
362363
}
364+
365+
/// Wraps [logger] to process deprecations within an ImportCache.
366+
///
367+
/// This wrapped logger will handle the deprecation options, but will not
368+
/// limit repetition, as it can be re-used across parses. A logger passed to
369+
/// an ImportCache or AsyncImportCache should generally be wrapped here first,
370+
/// unless it's already been wrapped to process deprecations, in which case
371+
/// this method has no effect.
372+
static DeprecationProcessingLogger wrapLogger(
373+
Logger? logger,
374+
Iterable<Deprecation>? silenceDeprecations,
375+
Iterable<Deprecation>? fatalDeprecations,
376+
Iterable<Deprecation>? futureDeprecations,
377+
{bool color = false}) {
378+
if (logger is DeprecationProcessingLogger) return logger;
379+
return DeprecationProcessingLogger(logger ?? Logger.stderr(color: color),
380+
silenceDeprecations: {...?silenceDeprecations},
381+
fatalDeprecations: {...?fatalDeprecations},
382+
futureDeprecations: {...?futureDeprecations},
383+
limitRepetition: false);
384+
}
363385
}

lib/src/compile.dart

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
// DO NOT EDIT. This file was generated from async_compile.dart.
66
// See tool/grind/synchronize.dart for details.
77
//
8-
// Checksum: ab2c6fa2588988a86abdbe87512134098e01b39e
8+
// Checksum: 69b31749dc94c7f717e9d395327e4209c4d3feb0
99
//
1010
// ignore_for_file: unused_import
1111

@@ -54,12 +54,13 @@ CompileResult compile(String path,
5454
Iterable<Deprecation>? silenceDeprecations,
5555
Iterable<Deprecation>? fatalDeprecations,
5656
Iterable<Deprecation>? futureDeprecations}) {
57-
DeprecationProcessingLogger deprecationLogger = logger =
58-
DeprecationProcessingLogger(logger ?? Logger.stderr(),
57+
DeprecationProcessingLogger deprecationLogger =
58+
logger = DeprecationProcessingLogger(logger ?? Logger.stderr(),
5959
silenceDeprecations: {...?silenceDeprecations},
6060
fatalDeprecations: {...?fatalDeprecations},
6161
futureDeprecations: {...?futureDeprecations},
62-
limitRepetition: !verbose);
62+
limitRepetition: !verbose)
63+
..validate();
6364

6465
// If the syntax is different than the importer would default to, we have to
6566
// parse the file manually and we can't store it in the cache.
@@ -120,12 +121,13 @@ CompileResult compileString(String source,
120121
Iterable<Deprecation>? silenceDeprecations,
121122
Iterable<Deprecation>? fatalDeprecations,
122123
Iterable<Deprecation>? futureDeprecations}) {
123-
DeprecationProcessingLogger deprecationLogger = logger =
124-
DeprecationProcessingLogger(logger ?? Logger.stderr(),
124+
DeprecationProcessingLogger deprecationLogger =
125+
logger = DeprecationProcessingLogger(logger ?? Logger.stderr(),
125126
silenceDeprecations: {...?silenceDeprecations},
126127
fatalDeprecations: {...?fatalDeprecations},
127128
futureDeprecations: {...?futureDeprecations},
128-
limitRepetition: !verbose);
129+
limitRepetition: !verbose)
130+
..validate();
129131

130132
var stylesheet =
131133
Stylesheet.parse(source, syntax ?? Syntax.scss, url: url, logger: logger);

lib/src/executable/compile_stylesheet.dart

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,11 @@ Future<void> _compileStylesheetWithoutErrorHandling(ExecutableOptions options,
9797
var importCache = AsyncImportCache(
9898
importers: options.pkgImporters,
9999
loadPaths: options.loadPaths,
100-
logger: options.logger);
100+
logger: AsyncImportCache.wrapLogger(
101+
options.logger,
102+
options.silenceDeprecations,
103+
options.fatalDeprecations,
104+
options.futureDeprecations));
101105

102106
result = source == null
103107
? await compileStringAsync(await readStdin(),

lib/src/executable/repl.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ Future<void> repl(ExecutableOptions options) async {
2626
silenceDeprecations: options.silenceDeprecations,
2727
fatalDeprecations: options.fatalDeprecations,
2828
futureDeprecations: options.futureDeprecations,
29-
limitRepetition: !options.verbose);
29+
limitRepetition: !options.verbose)
30+
..validate();
3031
var evaluator = Evaluator(
3132
importer: FilesystemImporter.cwd,
3233
importCache: ImportCache(

0 commit comments

Comments
 (0)