Skip to content

Commit

Permalink
Use relative path to a file in source map (fixes #7)
Browse files Browse the repository at this point in the history
  • Loading branch information
lahmatiy committed Dec 11, 2018
1 parent f79854f commit 5be1848
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 4 deletions.
6 changes: 5 additions & 1 deletion HISTORY.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
## 1.1.0 (Spetember 10, 2017)
## next

- Changed used path to a file in generated source map to relative path (#7)

## 1.1.0 (September 10, 2017)

- Bumped `CSSO` to `3.2.0`
- Added `--watch` option to run CLI in watch mode (@rijkvanzanten, #4)
Expand Down
7 changes: 4 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,7 @@ function minifyStream(options) {
readFromStream(inputStream, function(source) {
var time = process.hrtime();
var mem = process.memoryUsage().heapUsed;
var relInputFilename = path.relative(process.cwd(), options.inputFile);
var sourceMap = resolveSourceMap(source, options.inputMap, options.map, options.inputFile, options.outputFile);
var sourceMapAnnotation = '';
var result;
Expand All @@ -262,7 +263,7 @@ function minifyStream(options) {
try {
var minifyFunc = options.declarationList ? csso.minifyBlock : csso.minify;
result = minifyFunc(source, {
filename: options.inputFile,
filename: relInputFilename,
sourceMap: sourceMap.output,
usage: options.usageData,
restructure: options.restructure,
Expand Down Expand Up @@ -294,7 +295,7 @@ function minifyStream(options) {
if (sourceMap.input) {
result.map.applySourceMap(
new SourceMapConsumer(sourceMap.input),
options.inputFile
relInputFilename
);
}

Expand Down Expand Up @@ -328,7 +329,7 @@ function minifyStream(options) {
if (options.statistics) {
var timeDiff = process.hrtime(time);
showStat(
path.relative(process.cwd(), options.inputFile),
relInputFilename,
source.length,
result.css.length,
sourceMap.inputFile,
Expand Down
10 changes: 10 additions & 0 deletions test/basic.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,13 @@ it('should read from file', function() {
return run(__dirname + '/fixture/1.css')
.output(fs.readFileSync(__dirname + '/fixture/1.min.css', 'utf-8') + '\n');
});

it('should use relative paths in source map', function() {
return run(__dirname + '/fixture/1.css', '--map', 'inline')
.output(function(res) {
var expected = fs.readFileSync(__dirname + '/fixture/1.min.css.map', 'utf-8');
var actual = Buffer.from(String(res).match(/data:application\/json;base64,(.+)/)[1], 'base64').toString('utf-8') + '\n';

assert.equal(actual, expected);
});
});
1 change: 1 addition & 0 deletions test/fixture/1.min.css.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 5be1848

Please sign in to comment.