Skip to content

Commit

Permalink
Fix absolute paths
Browse files Browse the repository at this point in the history
  • Loading branch information
Sean McGivern committed Apr 6, 2015
1 parent 7f07091 commit 4deac5b
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 0 deletions.
13 changes: 13 additions & 0 deletions Gruntfile.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
'use strict';
var path = require('path');
function absolutePath(file) {
return path.join(__dirname, file);
}
module.exports = function (grunt) {
grunt.initConfig({
jshint: {
Expand All @@ -18,6 +22,15 @@ module.exports = function (grunt) {
options: {
sourceMap: true
},
absolute: {
files: [{
src: [
'test/fixtures/input_one.css',
'test/fixtures/input_two.css'
].map(absolutePath),
dest: absolutePath('tmp/absolute.css')
}]
},
compress: {
files: {
'tmp/style.css': [
Expand Down
1 change: 1 addition & 0 deletions tasks/cssmin.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ module.exports = function (grunt) {
var compiled = '';

options.target = file.dest;
options.relativeTo = path.dirname(availableFiles[0]);

try {
compiled = new CleanCSS(options).minify(availableFiles);
Expand Down
2 changes: 2 additions & 0 deletions test/expected/absolute.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,15 @@ exports.cssmin = {
var result = grunt.file.read('tmp/inline_import.css').replace(/\r\n/g,'').replace(/\n/g,'');
test.equal(expect, result, 'should inline @import');

test.done();
},
absolute: function(test) {
test.expect(1);

var expect = grunt.file.read('test/expected/absolute.css').replace(/\r\n/g,'').replace(/\n/g,'');
var result = grunt.file.read('tmp/absolute.css').replace(/\r\n/g,'').replace(/\n/g,'');
test.equal(expect, result, 'should perform the standard tasks when given absolute paths');

test.done();
}
};

1 comment on commit 4deac5b

@ryno1234
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are we overwriting the relativeTo property of options here without checking for its existence first?

Please sign in to comment.