From f23ea43168bbc4e3f638c8b2e1d1be869db82dea Mon Sep 17 00:00:00 2001 From: Slava Kim Date: Thu, 25 Jun 2015 16:59:00 -0700 Subject: [PATCH] Fix files' display paths for compiled Less in sourcemaps --- packages/less/plugin/compile-less.js | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/packages/less/plugin/compile-less.js b/packages/less/plugin/compile-less.js index 8476265e9b..2b3469ab37 100644 --- a/packages/less/plugin/compile-less.js +++ b/packages/less/plugin/compile-less.js @@ -40,10 +40,22 @@ _.extend(LessCompiler.prototype, { var mains = []; var cacheMisses = []; + function decodeFilePath (filePath) { + var match = filePath.match(/^{(.*)}\/(.*)$/); + if (! match) + throw new Error('Failed to decode Less path: ' + filePath); + + if (match[1] === '') { + // app + return match[2]; + } + + return 'packages/' + match[1] + '/' + match[2]; + } + inputFiles.forEach(function (inputFile) { var packageName = inputFile.getPackageName(); var pathInPackage = inputFile.getPathInPackage(); - // XXX BBP think about windows slashes var absoluteImportPath = packageName === null ? ('{}/' + pathInPackage) : ('{' + packageName + '}/' + pathInPackage); @@ -79,12 +91,18 @@ _.extend(LessCompiler.prototype, { } catch (e) { inputFile.error({ message: e.message, - sourcePath: e.filename, // XXX BBP this has {} and stuff, is that OK? + sourcePath: decodeFilePath(e.filename), line: e.line, column: e.column }); return; // go on to next file } + + if (output.map) { + var map = JSON.parse(output.map); + map.sources = map.sources.map(decodeFilePath); + output.map = JSON.stringify(map); + } cacheEntry = { hashes: {}, css: output.css,