From: Jakub Pawlowicz Date: Sun, 7 Dec 2014 11:54:08 +0000 (+0000) Subject: Fixes rebasing input source map sources. X-Git-Url: https://git.ndcode.org/public/gitweb.cgi?a=commitdiff_plain;h=1f55663b7a6e24188ad9089db2fefd205ce56434;p=clean-css.git Fixes rebasing input source map sources. * It's been broken in case if a target file exists. --- diff --git a/lib/selectors/source-map-stringifier.js b/lib/selectors/source-map-stringifier.js index 0837252c..ddffc2e5 100644 --- a/lib/selectors/source-map-stringifier.js +++ b/lib/selectors/source-map-stringifier.js @@ -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; } diff --git a/test/source-map-test.js b/test/source-map-test.js index 860fb5d9..2ec4afc4 100644 --- a/test/source-map-test.js +++ b/test/source-map-test.js @@ -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) {