[Pkg-javascript-commits] [less.js] 130/285: Fix the sourcemap options to default to the correct directories

Jonas Smedegaard dr at jones.dk
Mon Oct 26 23:23:47 UTC 2015


This is an automated email from the git hooks/post-receive script.

js pushed a commit to annotated tag v2.0.0
in repository less.js.

commit c07531a46fe147519e663220a3efb3073320ce5b
Author: Luke Page <luke.a.page at gmail.com>
Date:   Sat Sep 20 02:59:24 2014 +0100

    Fix the sourcemap options to default to the correct directories
---
 bin/lessc                     | 60 +++++++++++++++++++++++++++----------------
 lib/less/source-map-output.js |  2 +-
 2 files changed, 39 insertions(+), 23 deletions(-)

diff --git a/bin/lessc b/bin/lessc
index 18b42f7..8c485b9 100755
--- a/bin/lessc
+++ b/bin/lessc
@@ -29,6 +29,7 @@ var options = {
     modifyVariables: '',
     urlArgs: ''
 };
+var sourceMapOptions = {};
 var continueProcessing = true,
     currentErrorcode;
 
@@ -150,20 +151,19 @@ args = args.filter(function (arg) {
             }
             break;
         case 'source-map':
-            if (!match[2]) {
-                options.sourceMap = true;
-            } else {
-                options.sourceMap = match[2];
+            options.sourceMap = true;
+            if (match[2]) {
+                sourceMapOptions.sourceMapFilename = match[2];
             }
             break;
         case 'source-map-rootpath':
             if (checkArgFunc(arg, match[2])) {
-                options.sourceMapRootpath = match[2];
+                sourceMapOptions.sourceMapRootpath = match[2];
             }
             break;
         case 'source-map-basepath':
             if (checkArgFunc(arg, match[2])) {
-                options.sourceMapBasepath = match[2];
+                sourceMapOptions.sourceMapBasepath = match[2];
             }
             break;
         case 'source-map-map-inline':
@@ -171,11 +171,11 @@ args = args.filter(function (arg) {
             options.sourceMap = true;
             break;
         case 'source-map-less-inline':
-            options.outputSourceFiles = true;
+            sourceMapOptions.outputSourceFiles = true;
             break;
         case 'source-map-url':
             if (checkArgFunc(arg, match[2])) {
-                options.sourceMapURL = match[2];
+                sourceMapOptions.sourceMapURL = match[2];
             }
             break;
         case 'rp':
@@ -249,22 +249,40 @@ if (input && input != '-') {
 var output = args[2];
 var outputbase = args[2];
 if (output) {
-    options.sourceMapOutputFilename = output;
     output = path.resolve(process.cwd(), output);
     if (warningMessages) {
         console.log(warningMessages);
     }
 }
 
-options.sourceMapBasepath = options.sourceMapBasepath || (input ? path.dirname(input) : process.cwd());
+sourceMapOptions.sourceMapBasepath = options.sourceMapBasepath || (input ? path.dirname(input) : process.cwd());
 
-if (options.sourceMap === true) {
-    if (!output && !sourceMapFileInline) {
-        console.log("the sourcemap option only has an optional filename if the css filename is given");
-        return;
+if (options.sourceMap) {
+    if (!sourceMapOptions.sourceMapFilename) {
+        if (!output && !sourceMapFileInline) {
+            console.log("the sourcemap option only has an optional filename if the css filename is given");
+            console.log("consider adding --source-map-map-inline which embeds the sourcemap into the css");
+            return;
+        }
+        // its in the same directory, so always just the basename
+        sourceMapOptions.sourceMapOutputFilename = path.basename(output);
+        sourceMapOptions.sourceMapFullFilename = output + ".map";
+        // its in the same directory, so always just the basename
+        sourceMapOptions.sourceMapFilename = path.basename(sourceMapOptions.sourceMapFullFilename);
+    } else if (options.sourceMap && !sourceMapFileInline) {
+        var mapFilename = path.resolve(process.cwd(), sourceMapOptions.sourceMapFilename),
+            mapDir = path.dirname(mapFilename),
+            outputDir = path.dirname(output);
+        // find the path from the map to the output file
+        sourceMapOptions.sourceMapOutputFilename = path.join(
+            path.relative(mapDir, outputDir), path.basename(output));
+
+        // make the sourcemap filename point to the sourcemap relative to the css file output directory
+        sourceMapOptions.sourceMapFullFilename = sourceMapOptions.sourceMapFilename;
+        sourceMapOptions.sourceMapFilename = path.join(
+            path.relative(outputDir, mapDir), path.basename(sourceMapOptions.sourceMapFullFilename));
+        console.log(sourceMapOptions.sourceMapFile);
     }
-    options.sourceMapFullFilename = options.sourceMapOutputFilename + ".map";
-    options.sourceMap = path.basename(options.sourceMapFullFilename);
 }
 
 if (! input) {
@@ -299,7 +317,7 @@ if (options.depends) {
 
 if (!sourceMapFileInline) {
     var writeSourceMap = function(output) {
-        var filename = options.sourceMapFullFilename || options.sourceMapFilename;
+        var filename = sourceMapOptions.sourceMapFullFilename || sourceMapOptions.sourceMapFilename;
         ensureDirectory(filename);
         fs.writeFileSync(filename, output, 'utf8');
     };
@@ -338,13 +356,11 @@ var parseLessFile = function (e, data) {
     if (options.lint) {
         options.sourceMap = false;
     }
-    options.sourceMapFilename = options.sourceMap;
-    options.sourceMapRootpath = options.sourceMapRootpath || "";
-    options.sourceMapFileInline = sourceMapFileInline;
+    sourceMapOptions.sourceMapRootpath = options.sourceMapRootpath || "";
+    sourceMapOptions.sourceMapFileInline = sourceMapFileInline;
 
     if (options.sourceMap) {
-        // todo seperate options - no need to send them to less any more?
-        options.sourceMap = options;
+        options.sourceMap = sourceMapOptions;
     }
 
     options.plugins = pluginManager;
diff --git a/lib/less/source-map-output.js b/lib/less/source-map-output.js
index 5f4c9de..c8fd807 100644
--- a/lib/less/source-map-output.js
+++ b/lib/less/source-map-output.js
@@ -128,7 +128,7 @@ module.exports = function (environment) {
             if (!this._sourceMapFileInline) {
                 this.sourceMap = sourceMapContent;
             } else {
-                sourceMapURL = "data:application/json;base64," + environment.encodeBase64(sourceMapContent);
+                sourceMapURL = "data:application/json;base64," + environment.encodeBase64(null, sourceMapContent);
             }
 
             if (sourceMapURL) {

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/less.js.git



More information about the Pkg-javascript-commits mailing list