Ensures CLI presents a warning when source map is set but target file is not.
authorJakub Pawlowicz <contact@jakubpawlowicz.com>
Wed, 19 Nov 2014 08:02:14 +0000 (08:02 +0000)
committerJakub Pawlowicz <contact@jakubpawlowicz.com>
Mon, 8 Dec 2014 09:39:15 +0000 (09:39 +0000)
bin/cleancss
test/binary-test.js

index 1424a36..6ebd15e 100755 (executable)
@@ -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);
index f1ea693..07140e9 100644 (file)
@@ -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 */');