Skip to content

Commit 4fae6ce

Browse files
Fixes #54 - rebasing is still on if output option is used.
1 parent e770db4 commit 4fae6ce

File tree

3 files changed

+46
-5
lines changed

3 files changed

+46
-5
lines changed

History.md

+5
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
[5.0.1 / 2021-xx-xx](https://github.com/jakubpawlowicz/clean-css-cli/compare/v5.0.0...5.0)
2+
==================
3+
4+
* Fixed issue [#54](https://github.com/jakubpawlowicz/clean-css-cli/issues/54) - rebasing is still on if output option is used.
5+
16
[5.0.0 / 2021-02-10](https://github.com/jakubpawlowicz/clean-css-cli/compare/4.3...v5.0.0)
27
==================
38

index.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,9 @@ function cli(process, beforeMinifyCallback) {
9292
level: { 1: true },
9393
output: inputOptions.output,
9494
rebase: inputOptions.withRebase ? true : false,
95-
rebaseTo: ('output' in inputOptions) && inputOptions.output.length > 0 ? path.dirname(path.resolve(inputOptions.output)) : (inputOptions.withRebase ? process.cwd() : undefined),
95+
rebaseTo: inputOptions.withRebase && ('output' in inputOptions) && inputOptions.output.length > 0 ?
96+
path.dirname(path.resolve(inputOptions.output)) :
97+
(inputOptions.withRebase ? process.cwd() : undefined),
9698
sourceMap: inputOptions.sourceMap,
9799
sourceMapInlineSources: inputOptions.sourceMapInlineSources
98100
};

test/binary-test.js

+38-4
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ vows.describe('cleancss')
248248
assert.equal(stdout, 'a{background:url(../partials/extra/down.gif) 0 0 no-repeat}');
249249
}
250250
}),
251-
'output': binaryContext('-o ./base1-min.css ./test/fixtures/partials-relative/base.css', {
251+
'output': binaryContext('--with-rebase -o ./base1-min.css ./test/fixtures/partials-relative/base.css', {
252252
'should rewrite path relative to current path': function () {
253253
var minimized = fs.readFileSync('./base1-min.css', 'utf-8');
254254
assert.equal(minimized, 'a{background:url(test/fixtures/partials/extra/down.gif) 0 0 no-repeat}');
@@ -301,13 +301,27 @@ vows.describe('cleancss')
301301
.addBatch({
302302
'complex import and skipped url rebasing': {
303303
'absolute': binaryContext('./test/fixtures/rebasing/assets/ui.css', {
304-
'should rebase urls correctly': function (error, stdout) {
304+
'should not rebase urls': function (error, stdout) {
305305
assert.isNull(error);
306306
assert.include(stdout, 'url(../images/glyphs.gif)');
307307
assert.include(stdout, 'url(../images/prev.gif)');
308308
assert.include(stdout, 'url(../images/next.gif)');
309309
}
310310
})
311+
},
312+
'complex import, skipped url rebasing, and output file': {
313+
'absolute': binaryContext('-o ./test/ui-no-rebase.min.css ./test/fixtures/rebasing/assets/ui.css', {
314+
'should not rebase urls': function () {
315+
var minimized = fs.readFileSync('./test/ui-no-rebase.min.css', 'utf-8');
316+
317+
assert.include(minimized, 'url(../images/glyphs.gif)');
318+
assert.include(minimized, 'url(../images/prev.gif)');
319+
assert.include(minimized, 'url(../images/next.gif)');
320+
},
321+
teardown: function () {
322+
deleteFile('test/ui-no-rebase.min.css');
323+
}
324+
})
311325
}
312326
})
313327
.addBatch({
@@ -545,7 +559,27 @@ vows.describe('cleancss')
545559
}
546560
})
547561
.addBatch({
548-
'source maps - output file with existing map': binaryContext('--source-map -o ./styles.min.css ./test/fixtures/source-maps/styles.css', {
562+
'source maps - output file with existing map and no rebasing': binaryContext('--source-map -o ./styles.min.css ./test/fixtures/source-maps/styles.css', {
563+
'includes right content in map file': function () {
564+
var sourceMap = new SourceMapConsumer(fs.readFileSync('./styles.min.css.map', 'utf-8'));
565+
assert.deepEqual(
566+
sourceMap.originalPositionFor({ line: 1, column: 1 }),
567+
{
568+
source: 'test/fixtures/source-maps/styles.css',
569+
line: 1,
570+
column: 0,
571+
name: null
572+
}
573+
);
574+
},
575+
'teardown': function () {
576+
deleteFile('styles.min.css');
577+
deleteFile('styles.min.css.map');
578+
}
579+
})
580+
})
581+
.addBatch({
582+
'source maps - output file with existing map': binaryContext('--source-map --with-rebase -o ./styles.min.css ./test/fixtures/source-maps/styles.css', {
549583
'includes right content in map file': function () {
550584
var sourceMap = new SourceMapConsumer(fs.readFileSync('./styles.min.css.map', 'utf-8'));
551585
assert.deepEqual(
@@ -565,7 +599,7 @@ vows.describe('cleancss')
565599
})
566600
})
567601
.addBatch({
568-
'source maps - output file for existing map in different folder': binaryContext('--source-map -o ./styles-relative.min.css ./test/fixtures/source-maps/relative.css', {
602+
'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', {
569603
'includes right content in map file': function () {
570604
var sourceMap = new SourceMapConsumer(fs.readFileSync('./styles-relative.min.css.map', 'utf-8'));
571605
assert.deepEqual(

0 commit comments

Comments
 (0)