Skip to content

Commit fd989f6

Browse files
committed
Add a deprecation warning for @import's that resolved .css files
This is the first to removing native CSS imports. Like Ruby Sass, Dart Sass will not implement this behaviour. This is blocking compatibility between Node Sass and Dart Sass. This is a non-standard behaviour which is constant source of confusion. We had originally planned to removed this behaviour when the module system was ready. However that has feature has been delayed and people are continuing to be tripped up by this behaviour.
1 parent b9662fc commit fd989f6

File tree

3 files changed

+16
-3
lines changed

3 files changed

+16
-3
lines changed

src/context.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,14 @@ namespace Sass {
365365
// process the resolved entry
366366
else if (resolved.size() == 1) {
367367
bool use_cache = c_importers.size() == 0;
368+
if (resolved[0].deprecated) {
369+
// emit deprecation warning when import resolves to a .css file
370+
deprecated(
371+
"Including .css files with @import is non-standard behaviour which will be removed in future versions of LibSass.",
372+
"Use a custom importer to maintain this behaviour. Check your implementations documentation on how to create a custom importer.",
373+
true, pstate
374+
);
375+
}
368376
// use cache for the resource loading
369377
if (use_cache && sheets.count(resolved[0].abs_path)) return resolved[0];
370378
// try to read the content of the resolved file entry

src/file.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -354,13 +354,13 @@ namespace Sass {
354354
for(auto ext : d_exts) {
355355
rel_path = join_paths(base, "_" + name + ext);
356356
abs_path = join_paths(root, rel_path);
357-
if (file_exists(abs_path)) includes.push_back({{ rel_path, root }, abs_path });
357+
if (file_exists(abs_path)) includes.push_back({{ rel_path, root }, abs_path, true });
358358
}
359359
// next test plain name with d_exts
360360
for(auto ext : d_exts) {
361361
rel_path = join_paths(base, name + ext);
362362
abs_path = join_paths(root, rel_path);
363-
if (file_exists(abs_path)) includes.push_back({{ rel_path, root }, abs_path });
363+
if (file_exists(abs_path)) includes.push_back({{ rel_path, root }, abs_path, true });
364364
}
365365
// nothing found
366366
return includes;

src/file.hpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,14 @@ namespace Sass {
8989
public:
9090
// resolved absolute path
9191
std::string abs_path;
92+
// is a deprecated file type
93+
bool deprecated;
9294
public:
95+
Include(const Importer& imp, std::string abs_path, bool deprecated)
96+
: Importer(imp), abs_path(abs_path), deprecated(deprecated)
97+
{ }
9398
Include(const Importer& imp, std::string abs_path)
94-
: Importer(imp), abs_path(abs_path)
99+
: Importer(imp), abs_path(abs_path), deprecated(false)
95100
{ }
96101
};
97102

0 commit comments

Comments
 (0)