Fixes rebasing input source map sources.
authorJakub Pawlowicz <contact@jakubpawlowicz.com>
Sun, 7 Dec 2014 11:54:08 +0000 (11:54 +0000)
committerJakub Pawlowicz <contact@jakubpawlowicz.com>
Mon, 8 Dec 2014 09:42:55 +0000 (09:42 +0000)
* It's been broken in case if a target file exists.

lib/selectors/source-map-stringifier.js
test/source-map-test.js

index 0837252..ddffc2e 100644 (file)
@@ -20,7 +20,7 @@ function Rebuilder(options, restoreCallback, inputMapTracker) {
     this.resolvePath = this.rootPathResolver;
   } else if (options.target) {
     this.rebaseTo = path.resolve(process.cwd(), options.target);
-    if (!fs.existsSync(this.rebaseTo)) // options.target is a file yet to be created
+    if (!fs.existsSync(this.rebaseTo) || fs.statSync(this.rebaseTo).isFile())
       this.rebaseTo = path.dirname(this.rebaseTo);
     this.resolvePath = this.relativePathResolver;
   }
index 860fb5d..2ec4afc 100644 (file)
@@ -462,6 +462,18 @@ vows.describe('source-map')
         assert.equal(2, fromCSS.length);
       }
     },
+    'complex input map with an existing file as target': {
+      'topic': new CleanCSS({ sourceMap: true, target: path.join(process.cwd(), 'test', 'data', 'source-maps', 'styles.css') }).minify('@import url(test/data/source-maps/styles.css);'),
+      'should have 2 mappings': function (minified) {
+        assert.equal(2, minified.sourceMap._mappings.length);
+      },
+      'should have 2 mappings to styles.less file': function (minified) {
+        var stylesSource = minified.sourceMap._mappings.filter(function (mapping) {
+          return mapping.source == 'styles.less';
+        });
+        assert.equal(2, stylesSource.length);
+      },
+    },
     'nested once': {
       'topic': new CleanCSS({ sourceMap: true }).minify('@import url(test/data/source-maps/nested/once.css);'),
       'should have 2 mappings': function (minified) {