From c58a7b61412db84db9bc8420b38b9f567ad467dc Mon Sep 17 00:00:00 2001 From: Jakub Pawlowicz Date: Sun, 15 Mar 2015 15:50:01 +0000 Subject: [PATCH] Changes internal representation of all paths. Paths has to be either: * relative to root path if referencing a local file * absolute for all URLs. --- lib/imports/inliner.js | 2 +- lib/selectors/tokenizer.js | 7 +++---- lib/utils/input-source-map-tracker.js | 3 ++- lib/utils/source-reader.js | 5 ++--- test/binary-test.js | 2 +- test/source-map-test.js | 2 +- 6 files changed, 10 insertions(+), 11 deletions(-) diff --git a/lib/imports/inliner.js b/lib/imports/inliner.js index 44a695ea..8414bfd1 100644 --- a/lib/imports/inliner.js +++ b/lib/imports/inliner.js @@ -315,7 +315,7 @@ function inlineLocalResource(importedFile, mediaQuery, context) { }, context); importedData = rewriter.process(importedData); } - importedData = context.sourceTracker.store(path.resolve(context.relativeTo, fullPath), importedData); + importedData = context.sourceTracker.store(path.relative(context.root, fullPath), importedData); if (mediaQuery.length > 0) importedData = '@media ' + mediaQuery + '{' + importedData + '}'; diff --git a/lib/selectors/tokenizer.js b/lib/selectors/tokenizer.js index 27cbac66..c5acc518 100644 --- a/lib/selectors/tokenizer.js +++ b/lib/selectors/tokenizer.js @@ -56,10 +56,9 @@ function relativePathResolver(context) { rebaseTo = path.dirname(rebaseTo); return function (relativeTo, sourcePath) { - if (relativeTo) - sourcePath = path.resolve(path.dirname(relativeTo), sourcePath); - - return path.relative(rebaseTo, sourcePath); + return relativeTo != sourcePath ? + path.normalize(path.join(path.dirname(relativeTo), sourcePath)) : + sourcePath; }; } diff --git a/lib/utils/input-source-map-tracker.js b/lib/utils/input-source-map-tracker.js index 286b1091..21a40c62 100644 --- a/lib/utils/input-source-map-tracker.js +++ b/lib/utils/input-source-map-tracker.js @@ -63,8 +63,9 @@ function fromSource(self, data, whenDone, context) { } else { var sourceFile = context.files[context.files.length - 1]; var sourceDir = sourceFile ? path.dirname(sourceFile) : self.options.relativeTo; + var fullPathToSourceFile = path.join(self.options.root, sourceDir || '', sourceMapFile); - var inputMapData = fs.readFileSync(path.join(sourceDir || '', sourceMapFile), 'utf-8'); + var inputMapData = fs.readFileSync(fullPathToSourceFile, 'utf-8'); self.maps[sourceFile || undefined] = new SourceMapConsumer(inputMapData); } } diff --git a/lib/utils/source-reader.js b/lib/utils/source-reader.js index bc9c95e3..3c273f94 100644 --- a/lib/utils/source-reader.js +++ b/lib/utils/source-reader.js @@ -52,9 +52,8 @@ function fromHash(outerContext, sources) { styles = rewriter.process(styles); if (outerContext.options.sourceMap && inputSourceMap) { - var absoluteSource = path.resolve(source); - styles = outerContext.sourceTracker.store(absoluteSource, styles); - outerContext.inputSourceMapTracker.trackLoaded(absoluteSource, inputSourceMap); + styles = outerContext.sourceTracker.store(source, styles); + outerContext.inputSourceMapTracker.trackLoaded(source, inputSourceMap); } data.push(styles); diff --git a/test/binary-test.js b/test/binary-test.js index 48ba90cd..2c4317af 100644 --- a/test/binary-test.js +++ b/test/binary-test.js @@ -454,7 +454,7 @@ exports.commandsSuite = vows.describe('binary commands').addBatch({ assert.deepEqual( sourceMap.originalPositionFor({ line: 1, column: 1 }), { - source: '/fixtures/reset.css', + source: 'fixtures/reset.css', line: 4, column: 0, name: null diff --git a/test/source-map-test.js b/test/source-map-test.js index 6bea37c8..f19a92e7 100644 --- a/test/source-map-test.js +++ b/test/source-map-test.js @@ -506,7 +506,7 @@ vows.describe('source-map') }, 'should have 2 mappings to styles.less file': function (minified) { var stylesSource = minified.sourceMap._mappings._array.filter(function (mapping) { - return mapping.source == 'styles.less'; + return mapping.source == path.join('test', 'fixtures', 'source-maps', 'styles.less'); }); assert.lengthOf(stylesSource, 2); } -- 2.34.1