Skip to content

Commit 1bc4326

Browse files
authored
Merge pull request #717 from Medienplanet24/master
Fix: Add scssphp 2.x compatibility while maintaining backward compatibility
2 parents e1c8b92 + 07d6250 commit 1bc4326

File tree

4 files changed

+31
-8
lines changed

4 files changed

+31
-8
lines changed

.semver

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
:major: 4
33
:minor: 0
4-
:patch: 1
4+
:patch: 2
55
:special: ''
66
:metadata: ''

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## Unreleased
99

10+
## [4.0.2] - 2026-02-14
11+
12+
- Add scssphp 2.x compatibility while maintaining backward compatibility, [#715]
13+
- Use `CompilationResult::getIncludedFiles()` for scssphp 2.x, fall back to `Compiler::getParsedFiles()` for scssphp 1.x
14+
15+
[4.0.2]: https://github.com/mrclay/minify/compare/4.0.1...4.0.2
16+
[#715]: https://github.com/mrclay/minify/issues/715
17+
1018
## [4.0.1] - 2025-02-03
1119

1220
- Recommend against use, [#711]

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
"firephp/firephp-core": "~0.4.0",
4747
"meenie/javascript-packer": "~1.1",
4848
"phpunit/phpunit": "^8",
49-
"scssphp/scssphp": "^1.12",
49+
"scssphp/scssphp": "^1.12|^2.0",
5050
"tedivm/jshrink": "~1.1.0"
5151
},
5252
"suggest": {

lib/Minify/ScssCssSource.php

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -151,18 +151,33 @@ private function compile($filename)
151151
// and will treat the @import line as css import
152152
$scss->setImportPaths(dirname($filename));
153153

154-
$css = $scss->compileString(file_get_contents($filename), $filename)->getCss();
154+
$result = $scss->compileString(file_get_contents($filename), $filename);
155+
$css = $result->getCss();
155156
$elapsed = round((microtime(true) - $start), 4);
156157

157158
$v = Version::VERSION;
158159
$ts = date('r', (int) $start);
159160
$css = "/* compiled by scssphp $v on $ts ({$elapsed}s) */\n\n" . $css;
160161

161-
$imports = $scss->getParsedFiles();
162-
163-
$updated = 0;
164-
foreach ($imports as $mtime) {
165-
$updated = max($updated, $mtime);
162+
// scssphp 2.x removed Compiler::getParsedFiles(), use CompilationResult::getIncludedFiles() instead
163+
// scssphp 1.x uses Compiler::getParsedFiles() which returns [file => mtime]
164+
if (method_exists($scss, 'getParsedFiles')) {
165+
// scssphp 1.x
166+
$imports = $scss->getParsedFiles();
167+
$updated = 0;
168+
foreach ($imports as $mtime) {
169+
$updated = max($updated, $mtime);
170+
}
171+
} else {
172+
// scssphp 2.x: getIncludedFiles() returns file paths only
173+
$includedFiles = $result->getIncludedFiles();
174+
$imports = array();
175+
$updated = 0;
176+
foreach ($includedFiles as $file) {
177+
$mtime = filemtime($file);
178+
$imports[$file] = $mtime;
179+
$updated = max($updated, $mtime);
180+
}
166181
}
167182

168183
return array(

0 commit comments

Comments
 (0)