* Fixed issue [#65](https://github.com/GoalSmashers/clean-css/issues/65) - full color name / hex shortening.
* Fixed issue [#84](https://github.com/GoalSmashers/clean-css/issues/84) - support for @import with media queries.
+* Fixed issue [#124](https://github.com/GoalSmashers/clean-css/issues/124) - raise error on broken imports.
* Fixed issue [#126](https://github.com/GoalSmashers/clean-css/issues/126) - proper CSS expressions handling.
* Fixed issue [#130](https://github.com/GoalSmashers/clean-css/issues/130) - better code modularity.
* Fixed issue [#135](https://github.com/GoalSmashers/clean-css/issues/135) - require node.js 0.8+.
var fullPath = path.resolve(path.join(relativeTo, importedFile));
- if (fs.existsSync(fullPath) && fs.statSync(fullPath).isFile() && options.visited.indexOf(fullPath) == -1) {
- options.visited.push(fullPath);
-
- var importedData = fs.readFileSync(fullPath, 'utf8');
- var importRelativeTo = path.dirname(fullPath);
- importedData = rebaseRelativeURLs(importedData, importRelativeTo, options._baseRelativeTo);
-
- var inlinedData = process(importedData, {
- root: options.root,
- relativeTo: importRelativeTo,
- _baseRelativeTo: options.baseRelativeTo,
- visited: options.visited
- });
- return mediaQuery.length > 0 ?
- '@media ' + mediaQuery + '{' + inlinedData + '}' :
- inlinedData;
- } else {
+ if (!fs.existsSync(fullPath) || !fs.statSync(fullPath).isFile())
+ throw new Error('Broken @import declaration of "' + importedFile + '"');
+
+ if (options.visited.indexOf(fullPath) != -1)
return '';
- }
+
+ options.visited.push(fullPath);
+
+ var importedData = fs.readFileSync(fullPath, 'utf8');
+ var importRelativeTo = path.dirname(fullPath);
+ importedData = rebaseRelativeURLs(importedData, importRelativeTo, options._baseRelativeTo);
+
+ var inlinedData = process(importedData, {
+ root: options.root,
+ relativeTo: importRelativeTo,
+ _baseRelativeTo: options.baseRelativeTo,
+ visited: options.visited
+ });
+ return mediaQuery.length > 0 ?
+ '@media ' + mediaQuery + '{' + inlinedData + '}' :
+ inlinedData;
};
var rebaseRelativeURLs = function(data, fromBase, toBase) {
}),
'no relative to path': binaryContext('./test/data/partials-absolute/base.css', {
'should not be able to resolve it fully': function(error, stdout) {
- assert.equal(stdout, '.sub{padding:0}.base{margin:0}');
+ assert.equal(stdout, '');
+ assert.notEqual(error, null);
}
}),
'relative to path': binaryContext('-r ./test/data ./test/data/partials-absolute/base.css', {
var lineBreak = process.platform == 'win32' ? '\r\n' : '\n';
var cssContext = function(groups, options) {
var context = {};
- var clean = function(cleanedCSS) {
+ var clean = function(expectedCSS) {
return function(css) {
- assert.equal(cleanCSS.process(css, options), cleanedCSS);
+ var cleanedCSS = null;
+ try {
+ cleanedCSS = cleanCSS.process(css, options);
+ } catch (e) {
+ // swallow - cleanedCSS is set to null and that's the new expected value
+ }
+
+ assert.equal(cleanedCSS, expectedCSS);
};
};
'@import': cssContext({
'empty': [
"@import url();",
- ""
+ null
],
'of an unknown file': [
"@import url('fake.css');",
- ""
+ null
],
'of a http file': "@import url(http://pro.goalsmashers.com/test.css);",
'of a https file': [
'of a remote file via // url with media': "@import url(//pro.goalsmashers.com/test.css) screen,tv;",
'of a directory': [
"@import url(test/data/partials);",
- ""
+ null
],
'of a real file': [
"@import url(test/data/partials/one.css);",
'@import with absolute paths': cssContext({
'of an unknown file': [
"@import url(/fake.css);",
- ""
+ null
],
'of a real file': [
"@import url(/partials/one.css);",