Skip to content

Commit 81586b2

Browse files
author
Sean McGivern
committed
Fix absolute paths
1 parent 7f07091 commit 81586b2

4 files changed

Lines changed: 28 additions & 4 deletions

File tree

Gruntfile.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
'use strict';
2+
function absolutePath(path) {
3+
return __dirname + '/' + path;
4+
}
25
module.exports = function (grunt) {
36
grunt.initConfig({
47
jshint: {
@@ -18,6 +21,15 @@ module.exports = function (grunt) {
1821
options: {
1922
sourceMap: true
2023
},
24+
absolute: {
25+
files: [{
26+
src: [
27+
'test/fixtures/input_one.css',
28+
'test/fixtures/input_two.css'
29+
].map(absolutePath),
30+
dest: absolutePath('tmp/absolute.css')
31+
}]
32+
},
2133
compress: {
2234
files: {
2335
'tmp/style.css': [

tasks/cssmin.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@ module.exports = function (grunt) {
3434

3535
options.target = file.dest;
3636

37+
var unCompiledCssString = availableFiles.map(function (file) {
38+
options.relativeTo = path.dirname(file);
39+
return grunt.file.read(file);
40+
}).join('');
41+
3742
try {
3843
compiled = new CleanCSS(options).minify(availableFiles);
3944
} catch (err) {
@@ -43,10 +48,6 @@ module.exports = function (grunt) {
4348

4449
var compiledCssString = compiled.styles;
4550

46-
var unCompiledCssString = availableFiles.map(function (file) {
47-
return grunt.file.read(file);
48-
}).join('');
49-
5051
if (options.sourceMap) {
5152
compiledCssString += '\n' + '/*# sourceMappingURL=' + path.basename(file.dest) + '.map */';
5253
grunt.file.write(file.dest + '.map', compiled.sourceMap.toString());

test/expected/absolute.css

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/test.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,15 @@ exports.cssmin = {
1818
var result = grunt.file.read('tmp/inline_import.css').replace(/\r\n/g,'').replace(/\n/g,'');
1919
test.equal(expect, result, 'should inline @import');
2020

21+
test.done();
22+
},
23+
absolute: function(test) {
24+
test.expect(1);
25+
26+
var expect = grunt.file.read('test/expected/absolute.css').replace(/\r\n/g,'').replace(/\n/g,'');
27+
var result = grunt.file.read('tmp/absolute.css').replace(/\r\n/g,'').replace(/\n/g,'');
28+
test.equal(expect, result, 'should perform the standard tasks when given absolute paths');
29+
2130
test.done();
2231
}
2332
};

0 commit comments

Comments
 (0)