Skip to content

Commit d15a41a

Browse files
authored
Merge pull request #1326 from sass/limit-warnings
Add an option to the CLI and Dart Sass to silence warnings from deps
2 parents 7f982a1 + 16f1816 commit d15a41a

File tree

16 files changed

+423
-52
lines changed

16 files changed

+423
-52
lines changed

CHANGELOG.md

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,27 @@
1-
## 1.33.1
1+
## 1.34.0
22

33
* Don't emit the same warning in the same location multiple times.
44

5+
* Cap deprecation warnings at 5 per feature by default.
6+
7+
### Command Line Interface
8+
9+
* Add a `--quiet-deps` flag which silences compiler warnings from stylesheets
10+
loaded through `--load-path`s.
11+
12+
* Add a `--verbose` flag which causes the compiler to emit all deprecation
13+
warnings, not just 5 per feature.
14+
15+
### Dart API
16+
17+
* Add a `quietDeps` argument to `compile()`, `compileString()`,
18+
`compileAsync()`, and `compileStringAsync()` which silences compiler warnings
19+
from stylesheets loaded through importers, load paths, and `package:` URLs.
20+
21+
* Add a `verbose` argument to `compile()`, `compileString()`, `compileAsync()`,
22+
and `compileStringAsync()` which causes the compiler to emit all deprecation
23+
warnings, not just 5 per feature.
24+
525
## 1.33.0
626

727
* Deprecate the use of `/` for division. The new `math.div()` function should be

lib/sass.dart

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,13 @@ export 'src/warn.dart' show warn;
6161
///
6262
/// The [style] parameter controls the style of the resulting CSS.
6363
///
64+
/// If [quietDeps] is `true`, this will silence compiler warnings emitted for
65+
/// stylesheets loaded through [importers], [loadPaths], or [packageConfig].
66+
///
67+
/// By default, once a deprecation warning for a given feature is printed five
68+
/// times, further warnings for that feature are silenced. If [verbose] is true,
69+
/// all deprecation warnings are printed instead.
70+
///
6471
/// If [sourceMap] is passed, it's passed a [SingleMapping] that indicates which
6572
/// sections of the source file(s) correspond to which in the resulting CSS.
6673
/// It's called immediately before this method returns, and only if compilation
@@ -94,6 +101,8 @@ String compile(String path,
94101
PackageConfig? packageConfig,
95102
Iterable<Callable>? functions,
96103
OutputStyle? style,
104+
bool quietDeps = false,
105+
bool verbose = false,
97106
void sourceMap(SingleMapping map)?,
98107
bool charset = true}) {
99108
logger ??= Logger.stderr(color: color);
@@ -106,6 +115,8 @@ String compile(String path,
106115
packageConfig: packageConfig),
107116
functions: functions,
108117
style: style,
118+
quietDeps: quietDeps,
119+
verbose: verbose,
109120
sourceMap: sourceMap != null,
110121
charset: charset);
111122
result.sourceMap.andThen(sourceMap);
@@ -150,6 +161,13 @@ String compile(String path,
150161
/// [String] or a [Uri]. If [importer] is passed, [url] must be passed as well
151162
/// and `importer.load(url)` should return `source`.
152163
///
164+
/// If [quietDeps] is `true`, this will silence compiler warnings emitted for
165+
/// stylesheets loaded through [importers], [loadPaths], or [packageConfig].
166+
///
167+
/// By default, once a deprecation warning for a given feature is printed five
168+
/// times, further warnings for that feature are silenced. If [verbose] is true,
169+
/// all deprecation warnings are printed instead.
170+
///
153171
/// If [sourceMap] is passed, it's passed a [SingleMapping] that indicates which
154172
/// sections of the source file(s) correspond to which in the resulting CSS.
155173
/// It's called immediately before this method returns, and only if compilation
@@ -186,6 +204,8 @@ String compileString(String source,
186204
OutputStyle? style,
187205
Importer? importer,
188206
Object? url,
207+
bool quietDeps = false,
208+
bool verbose = false,
189209
void sourceMap(SingleMapping map)?,
190210
bool charset = true,
191211
@Deprecated("Use syntax instead.") bool indented = false}) {
@@ -202,6 +222,8 @@ String compileString(String source,
202222
style: style,
203223
importer: importer,
204224
url: url,
225+
quietDeps: quietDeps,
226+
verbose: verbose,
205227
sourceMap: sourceMap != null,
206228
charset: charset);
207229
result.sourceMap.andThen(sourceMap);
@@ -221,6 +243,8 @@ Future<String> compileAsync(String path,
221243
Iterable<String>? loadPaths,
222244
Iterable<AsyncCallable>? functions,
223245
OutputStyle? style,
246+
bool quietDeps = false,
247+
bool verbose = false,
224248
void sourceMap(SingleMapping map)?}) async {
225249
logger ??= Logger.stderr(color: color);
226250
var result = await c.compileAsync(path,
@@ -232,6 +256,8 @@ Future<String> compileAsync(String path,
232256
packageConfig: packageConfig),
233257
functions: functions,
234258
style: style,
259+
quietDeps: quietDeps,
260+
verbose: verbose,
235261
sourceMap: sourceMap != null);
236262
result.sourceMap.andThen(sourceMap);
237263
return result.css;
@@ -253,6 +279,8 @@ Future<String> compileStringAsync(String source,
253279
OutputStyle? style,
254280
AsyncImporter? importer,
255281
Object? url,
282+
bool quietDeps = false,
283+
bool verbose = false,
256284
void sourceMap(SingleMapping map)?,
257285
bool charset = true,
258286
@Deprecated("Use syntax instead.") bool indented = false}) async {
@@ -269,6 +297,8 @@ Future<String> compileStringAsync(String source,
269297
style: style,
270298
importer: importer,
271299
url: url,
300+
quietDeps: quietDeps,
301+
verbose: verbose,
272302
sourceMap: sourceMap != null,
273303
charset: charset);
274304
result.sourceMap.andThen(sourceMap);

lib/src/async_compile.dart

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import 'importer.dart';
1515
import 'importer/node.dart';
1616
import 'io.dart';
1717
import 'logger.dart';
18+
import 'logger/terse.dart';
1819
import 'syntax.dart';
1920
import 'utils.dart';
2021
import 'visitor/async_evaluate.dart';
@@ -34,23 +35,29 @@ Future<CompileResult> compileAsync(String path,
3435
bool useSpaces = true,
3536
int? indentWidth,
3637
LineFeed? lineFeed,
38+
bool quietDeps = false,
39+
bool verbose = false,
3740
bool sourceMap = false,
3841
bool charset = true}) async {
42+
TerseLogger? terseLogger;
43+
if (!verbose) logger = terseLogger = TerseLogger(logger ?? Logger.stderr());
44+
3945
// If the syntax is different than the importer would default to, we have to
4046
// parse the file manually and we can't store it in the cache.
4147
Stylesheet? stylesheet;
4248
if (nodeImporter == null &&
4349
(syntax == null || syntax == Syntax.forPath(path))) {
4450
importCache ??= AsyncImportCache.none(logger: logger);
4551
stylesheet = (await importCache.importCanonical(
46-
FilesystemImporter('.'), p.toUri(canonicalize(path)), p.toUri(path)))!;
52+
FilesystemImporter('.'), p.toUri(canonicalize(path)),
53+
originalUrl: p.toUri(path)))!;
4754
} else {
4855
stylesheet = Stylesheet.parse(
4956
readFile(path), syntax ?? Syntax.forPath(path),
5057
url: p.toUri(path), logger: logger);
5158
}
5259

53-
return await _compileStylesheet(
60+
var result = await _compileStylesheet(
5461
stylesheet,
5562
logger,
5663
importCache,
@@ -61,8 +68,12 @@ Future<CompileResult> compileAsync(String path,
6168
useSpaces,
6269
indentWidth,
6370
lineFeed,
71+
quietDeps,
6472
sourceMap,
6573
charset);
74+
75+
terseLogger?.summarize(node: nodeImporter != null);
76+
return result;
6677
}
6778

6879
/// Like [compileStringAsync] in `lib/sass.dart`, but provides more options to
@@ -83,12 +94,17 @@ Future<CompileResult> compileStringAsync(String source,
8394
int? indentWidth,
8495
LineFeed? lineFeed,
8596
Object? url,
97+
bool quietDeps = false,
98+
bool verbose = false,
8699
bool sourceMap = false,
87100
bool charset = true}) async {
101+
TerseLogger? terseLogger;
102+
if (!verbose) logger = terseLogger = TerseLogger(logger ?? Logger.stderr());
103+
88104
var stylesheet =
89105
Stylesheet.parse(source, syntax ?? Syntax.scss, url: url, logger: logger);
90106

91-
return _compileStylesheet(
107+
var result = await _compileStylesheet(
92108
stylesheet,
93109
logger,
94110
importCache,
@@ -99,8 +115,12 @@ Future<CompileResult> compileStringAsync(String source,
99115
useSpaces,
100116
indentWidth,
101117
lineFeed,
118+
quietDeps,
102119
sourceMap,
103120
charset);
121+
122+
terseLogger?.summarize(node: nodeImporter != null);
123+
return result;
104124
}
105125

106126
/// Compiles [stylesheet] and returns its result.
@@ -117,6 +137,7 @@ Future<CompileResult> _compileStylesheet(
117137
bool useSpaces,
118138
int? indentWidth,
119139
LineFeed? lineFeed,
140+
bool quietDeps,
120141
bool sourceMap,
121142
bool charset) async {
122143
var evaluateResult = await evaluateAsync(stylesheet,
@@ -125,6 +146,7 @@ Future<CompileResult> _compileStylesheet(
125146
importer: importer,
126147
functions: functions,
127148
logger: logger,
149+
quietDeps: quietDeps,
128150
sourceMap: sourceMap);
129151

130152
var serializeResult = serialize(evaluateResult.stylesheet,

lib/src/async_import_cache.dart

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -162,8 +162,8 @@ Relative canonical URLs are deprecated and will eventually be disallowed.
162162
var tuple = await canonicalize(url,
163163
baseImporter: baseImporter, baseUrl: baseUrl, forImport: forImport);
164164
if (tuple == null) return null;
165-
var stylesheet =
166-
await importCanonical(tuple.item1, tuple.item2, tuple.item3);
165+
var stylesheet = await importCanonical(tuple.item1, tuple.item2,
166+
originalUrl: tuple.item3);
167167
if (stylesheet == null) return null;
168168
return Tuple2(tuple.item1, stylesheet);
169169
}
@@ -177,9 +177,12 @@ Relative canonical URLs are deprecated and will eventually be disallowed.
177177
/// into [canonicalUrl]. It's used to resolve a relative canonical URL, which
178178
/// importers may return for legacy reasons.
179179
///
180+
/// If [quiet] is `true`, this will disable logging warnings when parsing the
181+
/// newly imported stylesheet.
182+
///
180183
/// Caches the result of the import and uses cached results if possible.
181184
Future<Stylesheet?> importCanonical(AsyncImporter importer, Uri canonicalUrl,
182-
[Uri? originalUrl]) async {
185+
{Uri? originalUrl, bool quiet = false}) async {
183186
return await putIfAbsentAsync(_importCache, canonicalUrl, () async {
184187
var result = await importer.load(canonicalUrl);
185188
if (result == null) return null;
@@ -191,7 +194,7 @@ Relative canonical URLs are deprecated and will eventually be disallowed.
191194
url: originalUrl == null
192195
? canonicalUrl
193196
: originalUrl.resolveUri(canonicalUrl),
194-
logger: _logger);
197+
logger: quiet ? Logger.quiet : _logger);
195198
});
196199
}
197200

lib/src/compile.dart

Lines changed: 26 additions & 4 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: dcb7cfbedf1e1189808c0056debf6a68bd387dab
8+
// Checksum: 8e813f2ead6e78899ce820e279983278809a7ea5
99
//
1010
// ignore_for_file: unused_import
1111

@@ -25,6 +25,7 @@ import 'importer.dart';
2525
import 'importer/node.dart';
2626
import 'io.dart';
2727
import 'logger.dart';
28+
import 'logger/terse.dart';
2829
import 'syntax.dart';
2930
import 'utils.dart';
3031
import 'visitor/evaluate.dart';
@@ -44,23 +45,29 @@ CompileResult compile(String path,
4445
bool useSpaces = true,
4546
int? indentWidth,
4647
LineFeed? lineFeed,
48+
bool quietDeps = false,
49+
bool verbose = false,
4750
bool sourceMap = false,
4851
bool charset = true}) {
52+
TerseLogger? terseLogger;
53+
if (!verbose) logger = terseLogger = TerseLogger(logger ?? Logger.stderr());
54+
4955
// If the syntax is different than the importer would default to, we have to
5056
// parse the file manually and we can't store it in the cache.
5157
Stylesheet? stylesheet;
5258
if (nodeImporter == null &&
5359
(syntax == null || syntax == Syntax.forPath(path))) {
5460
importCache ??= ImportCache.none(logger: logger);
5561
stylesheet = importCache.importCanonical(
56-
FilesystemImporter('.'), p.toUri(canonicalize(path)), p.toUri(path))!;
62+
FilesystemImporter('.'), p.toUri(canonicalize(path)),
63+
originalUrl: p.toUri(path))!;
5764
} else {
5865
stylesheet = Stylesheet.parse(
5966
readFile(path), syntax ?? Syntax.forPath(path),
6067
url: p.toUri(path), logger: logger);
6168
}
6269

63-
return _compileStylesheet(
70+
var result = _compileStylesheet(
6471
stylesheet,
6572
logger,
6673
importCache,
@@ -71,8 +78,12 @@ CompileResult compile(String path,
7178
useSpaces,
7279
indentWidth,
7380
lineFeed,
81+
quietDeps,
7482
sourceMap,
7583
charset);
84+
85+
terseLogger?.summarize(node: nodeImporter != null);
86+
return result;
7687
}
7788

7889
/// Like [compileString] in `lib/sass.dart`, but provides more options to
@@ -93,12 +104,17 @@ CompileResult compileString(String source,
93104
int? indentWidth,
94105
LineFeed? lineFeed,
95106
Object? url,
107+
bool quietDeps = false,
108+
bool verbose = false,
96109
bool sourceMap = false,
97110
bool charset = true}) {
111+
TerseLogger? terseLogger;
112+
if (!verbose) logger = terseLogger = TerseLogger(logger ?? Logger.stderr());
113+
98114
var stylesheet =
99115
Stylesheet.parse(source, syntax ?? Syntax.scss, url: url, logger: logger);
100116

101-
return _compileStylesheet(
117+
var result = _compileStylesheet(
102118
stylesheet,
103119
logger,
104120
importCache,
@@ -109,8 +125,12 @@ CompileResult compileString(String source,
109125
useSpaces,
110126
indentWidth,
111127
lineFeed,
128+
quietDeps,
112129
sourceMap,
113130
charset);
131+
132+
terseLogger?.summarize(node: nodeImporter != null);
133+
return result;
114134
}
115135

116136
/// Compiles [stylesheet] and returns its result.
@@ -127,6 +147,7 @@ CompileResult _compileStylesheet(
127147
bool useSpaces,
128148
int? indentWidth,
129149
LineFeed? lineFeed,
150+
bool quietDeps,
130151
bool sourceMap,
131152
bool charset) {
132153
var evaluateResult = evaluate(stylesheet,
@@ -135,6 +156,7 @@ CompileResult _compileStylesheet(
135156
importer: importer,
136157
functions: functions,
137158
logger: logger,
159+
quietDeps: quietDeps,
138160
sourceMap: sourceMap);
139161

140162
var serializeResult = serialize(evaluateResult.stylesheet,

0 commit comments

Comments
 (0)