From: Jakub Pawlowicz Date: Wed, 19 Nov 2014 08:02:14 +0000 (+0000) Subject: Ensures CLI presents a warning when source map is set but target file is not. X-Git-Url: https://git.ndcode.org/public/gitweb.cgi?a=commitdiff_plain;h=a2b6b9417c64b4f4a05e3a7fa7d294992bba4ea6;p=clean-css.git Ensures CLI presents a warning when source map is set but target file is not. --- diff --git a/bin/cleancss b/bin/cleancss index 1424a367..6ebd15ec 100755 --- a/bin/cleancss +++ b/bin/cleancss @@ -108,6 +108,11 @@ if (commands.args.length > 0) { }); } +if (cleanOptions.sourceMap && !cleanOptions.target) { + outputFeedback(['Source maps will not be built because you have not specified an output file.'], true); + cleanOptions.sourceMap = false; +} + // ... and do the magic! if (options.sources) { var data = options.sources @@ -143,7 +148,7 @@ function minify(data) { if (this.errors.length > 0) process.exit(1); - if (minified.sourceMap && options.target) { + if (minified.sourceMap) { var mapFilename = path.basename(options.target) + '.map'; output(minified.styles + '/*# sourceMappingURL=' + mapFilename + ' */'); outputMap(minified.sourceMap, mapFilename); diff --git a/test/binary-test.js b/test/binary-test.js index f1ea6934..07140e99 100644 --- a/test/binary-test.js +++ b/test/binary-test.js @@ -339,6 +339,14 @@ exports.commandsSuite = vows.describe('binary commands').addBatch({ }) }, 'source maps': { + 'no target file': binaryContext('--source-map ./test/data/reset.css', { + 'warns about source map not being build': function (error, stdout, stderr) { + assert.include(stderr, 'Source maps will not be built because you have not specified an output file.'); + }, + 'does not include map in stdout': function (error, stdout) { + assert.notInclude(stdout, '/*# sourceMappingURL'); + } + }), 'output file': binaryContext('--source-map -o ./reset.min.css ./test/data/reset.css', { 'includes map in minified file': function() { assert.include(readFile('./reset.min.css'), '/*# sourceMappingURL=reset.min.css.map */');