Skip to content

Commit

Permalink
Fixes #54 - rebasing is still on if output option is used.
Browse files Browse the repository at this point in the history
  • Loading branch information
jakubpawlowicz committed Feb 11, 2021
1 parent 417b248 commit 0e15a26
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 5 deletions.
5 changes: 5 additions & 0 deletions History.md
Original file line number Diff line number Diff line change
@@ -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)
==================

Expand Down
4 changes: 3 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
};
Expand Down
42 changes: 38 additions & 4 deletions test/binary-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}');
Expand Down Expand Up @@ -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({
Expand Down Expand Up @@ -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(
Expand All @@ -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(
Expand Down

0 comments on commit 0e15a26

Please sign in to comment.