From 0e15a2614bc22404a4e17e51d44ad49a899f566c Mon Sep 17 00:00:00 2001 From: Jakub Pawlowicz Date: Thu, 11 Feb 2021 08:07:14 +0100 Subject: [PATCH] Fixes #54 - rebasing is still on if output option is used. --- History.md | 5 +++++ index.js | 4 +++- test/binary-test.js | 42 ++++++++++++++++++++++++++++++++++++++---- 3 files changed, 46 insertions(+), 5 deletions(-) diff --git a/History.md b/History.md index cd88bc4..d4adedb 100644 --- a/History.md +++ b/History.md @@ -1,3 +1,8 @@ +[5.0.1 / 2021-xx-xx](https://github.com/jakubpawlowicz/clean-css-cli/compare/v5.0.0...5.0) +================== + +* Fixed issue [#54](https://github.com/jakubpawlowicz/clean-css-cli/issues/54) - rebasing is still on if output option is used. + [5.0.0 / 2021-02-10](https://github.com/jakubpawlowicz/clean-css-cli/compare/4.3...v5.0.0) ================== diff --git a/index.js b/index.js index f69d15b..c252f6c 100644 --- a/index.js +++ b/index.js @@ -92,7 +92,9 @@ function cli(process, beforeMinifyCallback) { level: { 1: true }, output: inputOptions.output, rebase: inputOptions.withRebase ? true : false, - rebaseTo: ('output' in inputOptions) && inputOptions.output.length > 0 ? path.dirname(path.resolve(inputOptions.output)) : (inputOptions.withRebase ? process.cwd() : undefined), + rebaseTo: inputOptions.withRebase && ('output' in inputOptions) && inputOptions.output.length > 0 ? + path.dirname(path.resolve(inputOptions.output)) : + (inputOptions.withRebase ? process.cwd() : undefined), sourceMap: inputOptions.sourceMap, sourceMapInlineSources: inputOptions.sourceMapInlineSources }; diff --git a/test/binary-test.js b/test/binary-test.js index 75fabd5..d602c8a 100644 --- a/test/binary-test.js +++ b/test/binary-test.js @@ -248,7 +248,7 @@ vows.describe('cleancss') assert.equal(stdout, 'a{background:url(../partials/extra/down.gif) 0 0 no-repeat}'); } }), - 'output': binaryContext('-o ./base1-min.css ./test/fixtures/partials-relative/base.css', { + 'output': binaryContext('--with-rebase -o ./base1-min.css ./test/fixtures/partials-relative/base.css', { 'should rewrite path relative to current path': function () { var minimized = fs.readFileSync('./base1-min.css', 'utf-8'); assert.equal(minimized, 'a{background:url(test/fixtures/partials/extra/down.gif) 0 0 no-repeat}'); @@ -301,13 +301,27 @@ vows.describe('cleancss') .addBatch({ 'complex import and skipped url rebasing': { 'absolute': binaryContext('./test/fixtures/rebasing/assets/ui.css', { - 'should rebase urls correctly': function (error, stdout) { + 'should not rebase urls': function (error, stdout) { assert.isNull(error); assert.include(stdout, 'url(../images/glyphs.gif)'); assert.include(stdout, 'url(../images/prev.gif)'); assert.include(stdout, 'url(../images/next.gif)'); } }) + }, + 'complex import, skipped url rebasing, and output file': { + 'absolute': binaryContext('-o ./test/ui-no-rebase.min.css ./test/fixtures/rebasing/assets/ui.css', { + 'should not rebase urls': function () { + var minimized = fs.readFileSync('./test/ui-no-rebase.min.css', 'utf-8'); + + assert.include(minimized, 'url(../images/glyphs.gif)'); + assert.include(minimized, 'url(../images/prev.gif)'); + assert.include(minimized, 'url(../images/next.gif)'); + }, + teardown: function () { + deleteFile('test/ui-no-rebase.min.css'); + } + }) } }) .addBatch({ @@ -545,7 +559,27 @@ vows.describe('cleancss') } }) .addBatch({ - 'source maps - output file with existing map': binaryContext('--source-map -o ./styles.min.css ./test/fixtures/source-maps/styles.css', { + 'source maps - output file with existing map and no rebasing': binaryContext('--source-map -o ./styles.min.css ./test/fixtures/source-maps/styles.css', { + 'includes right content in map file': function () { + var sourceMap = new SourceMapConsumer(fs.readFileSync('./styles.min.css.map', 'utf-8')); + assert.deepEqual( + sourceMap.originalPositionFor({ line: 1, column: 1 }), + { + source: 'test/fixtures/source-maps/styles.css', + line: 1, + column: 0, + name: null + } + ); + }, + 'teardown': function () { + deleteFile('styles.min.css'); + deleteFile('styles.min.css.map'); + } + }) + }) + .addBatch({ + 'source maps - output file with existing map': binaryContext('--source-map --with-rebase -o ./styles.min.css ./test/fixtures/source-maps/styles.css', { 'includes right content in map file': function () { var sourceMap = new SourceMapConsumer(fs.readFileSync('./styles.min.css.map', 'utf-8')); assert.deepEqual( @@ -565,7 +599,7 @@ vows.describe('cleancss') }) }) .addBatch({ - 'source maps - output file for existing map in different folder': binaryContext('--source-map -o ./styles-relative.min.css ./test/fixtures/source-maps/relative.css', { + 'source maps - output file for existing map in different folder': binaryContext('--source-map --with-rebase -o ./styles-relative.min.css ./test/fixtures/source-maps/relative.css', { 'includes right content in map file': function () { var sourceMap = new SourceMapConsumer(fs.readFileSync('./styles-relative.min.css.map', 'utf-8')); assert.deepEqual(