Fixes generating relative paths to mapped source files.
authorJakub Pawlowicz <contact@jakubpawlowicz.com>
Mon, 1 Dec 2014 21:26:20 +0000 (21:26 +0000)
committerJakub Pawlowicz <contact@jakubpawlowicz.com>
Mon, 8 Dec 2014 09:42:55 +0000 (09:42 +0000)
lib/selectors/source-map-stringifier.js
test/source-map-test.js

index 1e54d1e..7d33c2f 100644 (file)
@@ -1,4 +1,5 @@
 var path = require('path');
+var fs = require('fs');
 var url = require('url');
 
 var SourceMapGenerator = require('source-map').SourceMapGenerator;
@@ -18,7 +19,9 @@ function Rebuilder(options, restoreCallback, inputMapTracker) {
     this.rebaseTo = path.resolve(options.root);
     this.resolvePath = this.rootPathResolver;
   } else if (options.target) {
-    this.rebaseTo = path.dirname(path.resolve(process.cwd(), options.target));
+    this.rebaseTo = path.resolve(process.cwd(), options.target);
+    if (!fs.existsSync(this.rebaseTo)) // options.target is a file yet to be created
+      this.rebaseTo = path.dirname(this.rebaseTo);
     this.resolvePath = this.relativePathResolver;
   }
 }
index 4cb7005..4ac736d 100644 (file)
@@ -409,19 +409,19 @@ vows.describe('source-map')
       }
     },
     'complex but partial input map referenced by path': {
-      'topic': new CleanCSS({ sourceMap: true }).minify('@import url(test/data/source-maps/no-map-import.css);'),
+      'topic': new CleanCSS({ sourceMap: true, target: process.cwd() }).minify('@import url(test/data/source-maps/no-map-import.css);'),
       'should have 4 mappings': function (minified) {
         assert.equal(4, minified.sourceMap._mappings.length);
       },
       'should have 2 mappings to .less file': function (minified) {
         var fromLess = minified.sourceMap._mappings.filter(function (mapping) {
-          return mapping.source == 'styles.less';
+          return mapping.source == path.join('test', 'data', 'source-maps', 'styles.less');
         });
         assert.equal(2, fromLess.length);
       },
       'should have 2 mappings to .css file': function (minified) {
         var fromCSS = minified.sourceMap._mappings.filter(function (mapping) {
-          return mapping.source.indexOf('no-map.css') > 0;
+          return mapping.source == path.join('test', 'data', 'source-maps', 'no-map.css');
         });
         assert.equal(2, fromCSS.length);
       }