Skip to content

Commit c98b9d5

Browse files
jmooringbep
authored andcommitted
Add args.SilenceDependencyDeprecations option
1 parent 1360e27 commit c98b9d5

File tree

3 files changed

+95
-8
lines changed

3 files changed

+95
-8
lines changed

‎options.go‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ const (
4646
// Usually triggered by the @warn directive.
4747
LogEventTypeWarning LogEventType = iota
4848

49-
// Events trigered for usage of deprecated Sass features.
49+
// Events triggered for usage of deprecated Sass features.
5050
LogEventTypeDeprecated
5151

5252
// Triggered by the @debug directive.
@@ -143,6 +143,11 @@ type Args struct {
143143
// Deprecation IDs to silence, e.g. "import".
144144
SilenceDeprecations []string
145145

146+
// Whether to silence deprecation warnings from dependencies, where a
147+
// dependency is considered any file transitively imported through a load
148+
// path. This does not apply to @warn or @debug rules.
149+
SilenceDependencyDeprecations bool
150+
146151
sassOutputStyle embeddedsass.OutputStyle
147152
sassSourceSyntax embeddedsass.Syntax
148153

‎transpiler.go‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Copyright 2024 Bjørn Erik Pedersen
22
// SPDX-License-Identifier: MIT
33

4-
// Package godartsass provides a Go API for the Dass Sass Embedded protocol.
4+
// Package godartsass provides a Go API for the Dart Sass Embedded protocol.
55
//
66
// Use the Start function to create and start a new thread safe transpiler.
77
// Close it when done.
@@ -33,7 +33,7 @@ const defaultDartSassBinaryFilename = "sass"
3333
var ErrShutdown = errors.New("connection is shut down")
3434

3535
// Start creates and starts a new SCSS transpiler that communicates with the
36-
// Dass Sass Embedded protocol via Stdin and Stdout.
36+
// Dart Sass Embedded protocol via Stdin and Stdout.
3737
//
3838
// Closing the transpiler will shut down the process.
3939
//
@@ -195,7 +195,7 @@ func (t *Transpiler) Close() error {
195195
}
196196

197197
// Execute transpiles the string Source given in Args into CSS.
198-
// If Dart Sass resturns a "compile failure", the error returned will be
198+
// If Dart Sass returns a "compile failure", the error returned will be
199199
// of type SassError.
200200
func (t *Transpiler) Execute(args Args) (Result, error) {
201201
var result Result
@@ -219,6 +219,7 @@ func (t *Transpiler) Execute(args Args) (Result, error) {
219219
SourceMap: args.EnableSourceMap,
220220
SourceMapIncludeSources: args.SourceMapIncludeSources,
221221
SilenceDeprecation: args.SilenceDeprecations,
222+
QuietDeps: args.SilenceDependencyDeprecations,
222223
},
223224
}
224225

‎transpiler_test.go‎

Lines changed: 85 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ func TestTranspilerVariants(t *testing.T) {
6565
name: "main",
6666
content: `
6767
#main
68-
color: blue
68+
color: blue
6969
`,
7070
sourceSyntax: godartsass.SourceSyntaxSASS,
7171
}
@@ -101,7 +101,7 @@ body
101101
{"Error in ImportResolver.Load", godartsass.Options{}, godartsass.Args{Source: "@import \"colors\";", ImportResolver: testImportResolver{name: "colors", failOnLoad: true}}, false},
102102
{"Invalid OutputStyle", godartsass.Options{}, godartsass.Args{Source: "a", OutputStyle: "asdf"}, false},
103103
{"Invalid SourceSyntax", godartsass.Options{}, godartsass.Args{Source: "a", SourceSyntax: "asdf"}, false},
104-
{"Erro logging", godartsass.Options{}, godartsass.Args{Source: `@error "foo";`}, false},
104+
{"Error logging", godartsass.Options{}, godartsass.Args{Source: `@error "foo";`}, false},
105105
} {
106106
test := test
107107
c.Run(test.name, func(c *qt.C) {
@@ -236,6 +236,87 @@ div { p { color: $moo; } }`
236236
c.Assert(result.CSS, qt.Equals, "div p{color:#f442d1}")
237237
}
238238

239+
func TestSilenceDependencyDeprecations(t *testing.T) {
240+
dir1 := t.TempDir()
241+
headings := filepath.Join(dir1, "_headings.scss")
242+
243+
err := os.WriteFile(headings, []byte(`
244+
@use "sass:color";
245+
h1 { color: rgb(color.channel(#aaa, "red", $space: rgb), 0, 0); }
246+
h2 { color: rgb(color.red(#bbb), 0, 0); } // deprecated
247+
`), 0o644)
248+
if err != nil {
249+
t.Fatalf("Failed to write file: %v", err)
250+
}
251+
252+
c := qt.New(t)
253+
src := `
254+
@use "sass:color";
255+
@use "headings";
256+
h3 { color: rgb(color.channel(#ccc, "red", $space: rgb), 0, 0); }
257+
`
258+
259+
args := godartsass.Args{
260+
OutputStyle: godartsass.OutputStyleCompressed,
261+
IncludePaths: []string{dir1},
262+
}
263+
264+
tests := []struct {
265+
name string
266+
src string
267+
silenceDependencyDeprecations bool
268+
expectedLogMessage string
269+
expectedResult string
270+
}{
271+
{
272+
name: "A",
273+
src: src,
274+
silenceDependencyDeprecations: false,
275+
expectedLogMessage: "color.red() is deprecated",
276+
expectedResult: "h1{color:#a00}h2{color:#b00}h3{color:#c00}",
277+
},
278+
{
279+
name: "B",
280+
src: src,
281+
silenceDependencyDeprecations: true,
282+
expectedLogMessage: "",
283+
expectedResult: "h1{color:#a00}h2{color:#b00}h3{color:#c00}",
284+
},
285+
{
286+
name: "C",
287+
src: src + "h4 { color: rgb(0, color.green(#ddd), 0); }",
288+
silenceDependencyDeprecations: true,
289+
expectedLogMessage: "color.green() is deprecated",
290+
expectedResult: "h1{color:#a00}h2{color:#b00}h3{color:#c00}h4{color:#0d0}",
291+
},
292+
}
293+
294+
for _, tt := range tests {
295+
t.Run(tt.name, func(t *testing.T) {
296+
args.Source = tt.src
297+
args.SilenceDependencyDeprecations = tt.silenceDependencyDeprecations
298+
logMessage := ""
299+
transpiler, clean := newTestTranspiler(c, godartsass.Options{
300+
LogEventHandler: func(e godartsass.LogEvent) {
301+
logMessage = e.Message
302+
},
303+
})
304+
defer clean()
305+
306+
result, err := transpiler.Execute(args)
307+
c.Assert(err, qt.IsNil)
308+
309+
if tt.expectedLogMessage == "" {
310+
c.Assert(logMessage, qt.Equals, "")
311+
} else {
312+
c.Assert(logMessage, qt.Contains, tt.expectedLogMessage)
313+
}
314+
315+
c.Assert(result.CSS, qt.Equals, tt.expectedResult)
316+
})
317+
}
318+
}
319+
239320
func TestTranspilerParallel(t *testing.T) {
240321
c := qt.New(t)
241322
transpiler, clean := newTestTranspiler(c, godartsass.Options{})
@@ -400,9 +481,9 @@ func BenchmarkTranspiler(b *testing.B) {
400481
padding: 0;
401482
list-style: none;
402483
}
403-
484+
404485
li { display: inline-block; }
405-
486+
406487
a {
407488
display: block;
408489
padding: 6px 12px;

0 commit comments

Comments
 (0)