From 8b79c916905758130df58e050077e8ee9754e182 Mon Sep 17 00:00:00 2001 From: Jakub Pawlowicz Date: Mon, 13 Apr 2015 21:51:04 +0100 Subject: [PATCH] Fixes #487 - source map paths under Windows. Apparently there's a bug in `source-map` library which does not normalize paths in `source` field to proper URL format. Thus source maps generated on Windows have backslashes instead of forward slashes. We correct it manually to get same output on all platforms. --- History.md | 1 + lib/stringifier/source-maps.js | 4 ++ test/source-map-test.js | 92 +++++++++++++++++----------------- 3 files changed, 51 insertions(+), 46 deletions(-) diff --git a/History.md b/History.md index 6a06dc83..123ab8a6 100644 --- a/History.md +++ b/History.md @@ -12,6 +12,7 @@ * Fixed issue [#446](https://github.com/jakubpawlowicz/clean-css/issues/446) - `list-style` fuzzy matching. * Fixed issue [#468](https://github.com/jakubpawlowicz/clean-css/issues/468) - bumps `source-map` to 0.4.x. * Fixed issue [#480](https://github.com/jakubpawlowicz/clean-css/issues/480) - extracting uppercase property names. +* Fixed issue [#487](https://github.com/jakubpawlowicz/clean-css/issues/487) - source map paths under Windows. * Fixed issue [#490](https://github.com/jakubpawlowicz/clean-css/issues/490) - vendor prefixed multivalue `background`. * Fixed issue [#500](https://github.com/jakubpawlowicz/clean-css/issues/500) - merging duplicate adjacent properties. * Fixed issue [#507](https://github.com/jakubpawlowicz/clean-css/issues/507) - merging longhands into many shorthands. diff --git a/lib/stringifier/source-maps.js b/lib/stringifier/source-maps.js index 7d0f0430..193e027d 100644 --- a/lib/stringifier/source-maps.js +++ b/lib/stringifier/source-maps.js @@ -1,6 +1,7 @@ var SourceMapGenerator = require('source-map').SourceMapGenerator; var all = require('./helpers').all; +var isWindows = process.platform == 'win32'; var unknownSource = '$stdin'; function store(element, context) { @@ -37,6 +38,9 @@ function trackAllMappings(element, context) { function trackMapping(mapping, context) { var source = mapping[2] || unknownSource; + if (isWindows) + source = source.replace(/\\/g, '/'); + context.outputMap.addMapping({ generated: { line: context.line, diff --git a/test/source-map-test.js b/test/source-map-test.js index 07f5c55a..da4318b9 100644 --- a/test/source-map-test.js +++ b/test/source-map-test.js @@ -430,7 +430,7 @@ vows.describe('source-map') generatedColumn: 0, originalLine: 1, originalColumn: 4, - source: path.join('test', 'fixtures', 'source-maps', 'styles.less'), + source: 'test/fixtures/source-maps/styles.less', name: null }; assert.deepEqual(minified.sourceMap._mappings._array[0], mapping); @@ -441,7 +441,7 @@ vows.describe('source-map') generatedColumn: 6, originalLine: 2, originalColumn: 2, - source: path.join('test', 'fixtures', 'source-maps', 'styles.less'), + source: 'test/fixtures/source-maps/styles.less', name: null }; assert.deepEqual(minified.sourceMap._mappings._array[1], mapping); @@ -452,7 +452,7 @@ vows.describe('source-map') generatedColumn: 12, originalLine: 2, originalColumn: 2, - source: path.join('test', 'fixtures', 'source-maps', 'styles.less'), + source: 'test/fixtures/source-maps/styles.less', name: null }; assert.deepEqual(minified.sourceMap._mappings._array[2], mapping); @@ -471,7 +471,7 @@ vows.describe('source-map') generatedColumn: 0, originalLine: 1, originalColumn: 4, - source: path.join('source-maps', 'styles.less'), + source: 'source-maps/styles.less', name: null }; assert.deepEqual(minified.sourceMap._mappings._array[0], mapping); @@ -482,7 +482,7 @@ vows.describe('source-map') generatedColumn: 6, originalLine: 2, originalColumn: 2, - source: path.join('source-maps', 'styles.less'), + source: 'source-maps/styles.less', name: null }; assert.deepEqual(minified.sourceMap._mappings._array[1], mapping); @@ -493,7 +493,7 @@ vows.describe('source-map') generatedColumn: 12, originalLine: 2, originalColumn: 2, - source: path.join('source-maps', 'styles.less'), + source: 'source-maps/styles.less', name: null }; assert.deepEqual(minified.sourceMap._mappings._array[2], mapping); @@ -512,7 +512,7 @@ vows.describe('source-map') generatedColumn: 0, originalLine: 1, originalColumn: 4, - source: path.join('fixtures', 'source-maps', 'styles.less'), + source: 'fixtures/source-maps/styles.less', name: null }; assert.deepEqual(minified.sourceMap._mappings._array[0], mapping); @@ -523,7 +523,7 @@ vows.describe('source-map') generatedColumn: 6, originalLine: 2, originalColumn: 2, - source: path.join('fixtures', 'source-maps', 'styles.less'), + source: 'fixtures/source-maps/styles.less', name: null }; assert.deepEqual(minified.sourceMap._mappings._array[1], mapping); @@ -534,7 +534,7 @@ vows.describe('source-map') generatedColumn: 12, originalLine: 2, originalColumn: 2, - source: path.join('fixtures', 'source-maps', 'styles.less'), + source: 'fixtures/source-maps/styles.less', name: null }; assert.deepEqual(minified.sourceMap._mappings._array[2], mapping); @@ -631,13 +631,13 @@ vows.describe('source-map') }, 'has 3 mappings to .less file': function (minified) { var fromLess = minified.sourceMap._mappings._array.filter(function (mapping) { - return mapping.source == path.join('test', 'fixtures', 'source-maps', 'styles.less'); + return mapping.source == 'test/fixtures/source-maps/styles.less'; }); assert.lengthOf(fromLess, 3); }, 'has 3 mappings to .css file': function (minified) { var fromCSS = minified.sourceMap._mappings._array.filter(function (mapping) { - return mapping.source == path.join('test', 'fixtures', 'source-maps', 'no-map.css'); + return mapping.source == 'test/fixtures/source-maps/no-map.css'; }); assert.lengthOf(fromCSS, 3); } @@ -669,7 +669,7 @@ vows.describe('source-map') generatedColumn: 0, originalLine: 2, originalColumn: 8, - source: path.join('test', 'fixtures', 'source-maps', 'nested', 'once.less'), + source: 'test/fixtures/source-maps/nested/once.less', name: null }; assert.deepEqual(minified.sourceMap._mappings._array[0], mapping); @@ -680,7 +680,7 @@ vows.describe('source-map') generatedColumn: 14, originalLine: 3, originalColumn: 4, - source: path.join('test', 'fixtures', 'source-maps', 'nested', 'once.less'), + source: 'test/fixtures/source-maps/nested/once.less', name: null }; assert.deepEqual(minified.sourceMap._mappings._array[1], mapping); @@ -691,7 +691,7 @@ vows.describe('source-map') generatedColumn: 20, originalLine: 3, originalColumn: 4, - source: path.join('test', 'fixtures', 'source-maps', 'nested', 'once.less'), + source: 'test/fixtures/source-maps/nested/once.less', name: null }; assert.deepEqual(minified.sourceMap._mappings._array[2], mapping); @@ -710,7 +710,7 @@ vows.describe('source-map') generatedColumn: 0, originalLine: 3, originalColumn: 4, - source: path.join('test', 'fixtures', 'source-maps', 'nested', 'twice.less'), + source: 'test/fixtures/source-maps/nested/twice.less', name: null }; assert.deepEqual(minified.sourceMap._mappings._array[0], mapping); @@ -721,7 +721,7 @@ vows.describe('source-map') generatedColumn: 11, originalLine: 4, originalColumn: 6, - source: path.join('test', 'fixtures', 'source-maps', 'nested', 'twice.less'), + source: 'test/fixtures/source-maps/nested/twice.less', name: null }; assert.deepEqual(minified.sourceMap._mappings._array[1], mapping); @@ -732,7 +732,7 @@ vows.describe('source-map') generatedColumn: 17, originalLine: 4, originalColumn: 6, - source: path.join('test', 'fixtures', 'source-maps', 'nested', 'twice.less'), + source: 'test/fixtures/source-maps/nested/twice.less', name: null }; assert.deepEqual(minified.sourceMap._mappings._array[2], mapping); @@ -1058,7 +1058,7 @@ vows.describe('source-map') generatedColumn: 0, originalLine: 1, originalColumn: 0, - source: path.join('test', 'fixtures', 'source-maps', 'some.less'), + source: 'test/fixtures/source-maps/some.less', name: null }; assert.deepEqual(minified.sourceMap._mappings._array[0], mapping); @@ -1069,7 +1069,7 @@ vows.describe('source-map') generatedColumn: 4, originalLine: 2, originalColumn: 8, - source: path.join('test', 'fixtures', 'source-maps', 'nested', 'once.less'), + source: 'test/fixtures/source-maps/nested/once.less', name: null }; assert.deepEqual(minified.sourceMap._mappings._array[1], mapping); @@ -1080,7 +1080,7 @@ vows.describe('source-map') generatedColumn: 18, originalLine: 2, originalColumn: 2, - source: path.join('test', 'fixtures', 'source-maps', 'some.less'), + source: 'test/fixtures/source-maps/some.less', name: null }; assert.deepEqual(minified.sourceMap._mappings._array[2], mapping); @@ -1091,7 +1091,7 @@ vows.describe('source-map') generatedColumn: 24, originalLine: 2, originalColumn: 2, - source: path.join('test', 'fixtures', 'source-maps', 'some.less'), + source: 'test/fixtures/source-maps/some.less', name: null }; assert.deepEqual(minified.sourceMap._mappings._array[3], mapping); @@ -1102,7 +1102,7 @@ vows.describe('source-map') generatedColumn: 28, originalLine: 1, originalColumn: 4, - source: path.join('test', 'fixtures', 'source-maps', 'styles.less'), + source: 'test/fixtures/source-maps/styles.less', name: null }; assert.deepEqual(minified.sourceMap._mappings._array[4], mapping); @@ -1113,7 +1113,7 @@ vows.describe('source-map') generatedColumn: 34, originalLine: 2, originalColumn: 2, - source: path.join('test', 'fixtures', 'source-maps', 'styles.less'), + source: 'test/fixtures/source-maps/styles.less', name: null }; assert.deepEqual(minified.sourceMap._mappings._array[5], mapping); @@ -1124,7 +1124,7 @@ vows.describe('source-map') generatedColumn: 40, originalLine: 2, originalColumn: 2, - source: path.join('test', 'fixtures', 'source-maps', 'styles.less'), + source: 'test/fixtures/source-maps/styles.less', name: null }; assert.deepEqual(minified.sourceMap._mappings._array[6], mapping); @@ -1160,9 +1160,9 @@ vows.describe('source-map') }); assert.deepEqual(sources, [ - path.join('fixtures', 'source-maps', 'some.less'), - path.join('fixtures', 'source-maps', 'nested', 'once.less'), - path.join('fixtures', 'source-maps', 'styles.less') + 'fixtures/source-maps/some.less', + 'fixtures/source-maps/nested/once.less', + 'fixtures/source-maps/styles.less' ]); } } @@ -1243,8 +1243,8 @@ vows.describe('source-map') }, 'has embedded sources': function (minified) { assert.deepEqual(JSON.parse(minified.sourceMap.toString()).sources, [ - path.join('test', 'fixtures', 'partials', 'one.css'), - path.join('test', 'fixtures', 'partials', 'three.css') + 'test/fixtures/partials/one.css', + 'test/fixtures/partials/three.css' ]); }, 'has embedded sources content': function (minified) { @@ -1263,8 +1263,8 @@ vows.describe('source-map') }, 'has embedded sources': function (minified) { assert.deepEqual(JSON.parse(minified.sourceMap.toString()).sources, [ - path.join('test', 'fixtures', 'partials', 'one.css'), - path.join('test', 'fixtures', 'partials', 'three.css') + 'test/fixtures/partials/one.css', + 'test/fixtures/partials/three.css' ]); }, 'has embedded sources content': function (minified) { @@ -1438,9 +1438,9 @@ vows.describe('source-map') }, 'has embedded sources': function (minified) { assert.deepEqual(JSON.parse(minified.sourceMap.toString()).sources, [ - path.join('test', 'fixtures', 'source-maps', 'some.less'), - path.join('test', 'fixtures', 'source-maps', 'nested', 'once.less'), - path.join('test', 'fixtures', 'source-maps', 'styles.less') + 'test/fixtures/source-maps/some.less', + 'test/fixtures/source-maps/nested/once.less', + 'test/fixtures/source-maps/styles.less' ]); }, 'has embedded sources content': function (minified) { @@ -1473,9 +1473,9 @@ vows.describe('source-map') }, 'has embedded sources': function (minified) { assert.deepEqual(JSON.parse(minified.sourceMap.toString()).sources, [ - path.join('fixtures', 'source-maps', 'some.less'), - path.join('fixtures', 'source-maps', 'nested', 'once.less'), - path.join('fixtures', 'source-maps', 'styles.less') + 'fixtures/source-maps/some.less', + 'fixtures/source-maps/nested/once.less', + 'fixtures/source-maps/styles.less' ]); }, 'has embedded sources content': function (minified) { @@ -1508,9 +1508,9 @@ vows.describe('source-map') }, 'has embedded sources': function (minified) { assert.deepEqual(JSON.parse(minified.sourceMap.toString()).sources, [ - path.join('test', 'fixtures', 'source-maps', 'some.less'), - path.join('test', 'fixtures', 'source-maps', 'nested', 'once.less'), - path.join('test', 'fixtures', 'source-maps', 'styles.less') + 'test/fixtures/source-maps/some.less', + 'test/fixtures/source-maps/nested/once.less', + 'test/fixtures/source-maps/styles.less' ]); }, 'has embedded sources content': function (minified) { @@ -1543,9 +1543,9 @@ vows.describe('source-map') }, 'has embedded sources': function (minified) { assert.deepEqual(JSON.parse(minified.sourceMap.toString()).sources, [ - path.join('test', 'fixtures', 'source-maps', 'some.less'), - path.join('test', 'fixtures', 'source-maps', 'nested', 'once.less'), - path.join('test', 'fixtures', 'source-maps', 'styles.less') + 'test/fixtures/source-maps/some.less', + 'test/fixtures/source-maps/nested/once.less', + 'test/fixtures/source-maps/styles.less' ]); }, 'has embedded sources content': function (minified) { @@ -1581,7 +1581,7 @@ vows.describe('source-map') 'has embedded sources': function (minified) { assert.deepEqual(JSON.parse(minified.sourceMap.toString()).sources, [ 'http://127.0.0.1/some.less', - path.join('test', 'fixtures', 'source-maps', 'nested', 'once.less'), + 'test/fixtures/source-maps/nested/once.less', 'http://127.0.0.1/styles.less' ]); }, @@ -1629,7 +1629,7 @@ vows.describe('source-map') 'has embedded sources': function (minified) { assert.deepEqual(JSON.parse(minified.sourceMap.toString()).sources, [ 'http://127.0.0.1/some.less', - path.join('test', 'fixtures', 'source-maps', 'nested', 'once.less'), + 'test/fixtures/source-maps/nested/once.less', 'http://127.0.0.1/styles.less' ]); }, @@ -1674,7 +1674,7 @@ vows.describe('source-map') 'has embedded sources': function (minified) { assert.deepEqual(JSON.parse(minified.sourceMap.toString()).sources, [ 'http://127.0.0.1/some.less', - path.join('test', 'fixtures', 'source-maps', 'nested', 'once.less'), + 'test/fixtures/source-maps/nested/once.less', 'http://127.0.0.1/styles.less' ]); }, -- 2.34.1