Changes internal representation of all paths.
authorJakub Pawlowicz <contact@jakubpawlowicz.com>
Sun, 15 Mar 2015 15:50:01 +0000 (15:50 +0000)
committerJakub Pawlowicz <contact@jakubpawlowicz.com>
Sun, 15 Mar 2015 15:50:01 +0000 (15:50 +0000)
Paths has to be either:

* relative to root path if referencing a local file
* absolute for all URLs.

lib/imports/inliner.js
lib/selectors/tokenizer.js
lib/utils/input-source-map-tracker.js
lib/utils/source-reader.js
test/binary-test.js
test/source-map-test.js

index 44a695e..8414bfd 100644 (file)
@@ -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 + '}';
index 27cbac6..c5acc51 100644 (file)
@@ -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;
   };
 }
 
index 286b109..21a40c6 100644 (file)
@@ -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);
       }
     }
index bc9c95e..3c273f9 100644 (file)
@@ -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);
index 48ba90c..2c4317a 100644 (file)
@@ -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
index 6bea37c..f19a92e 100644 (file)
@@ -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);
       }