Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save unknownbrackets/1176345 to your computer and use it in GitHub Desktop.
Save unknownbrackets/1176345 to your computer and use it in GitHub Desktop.
less - Don't use require.paths, just use relative paths in require().
From a755238aa8a2c679cf8c26851f1c2509bbeb7805 Mon Sep 17 00:00:00 2001
From: Unknown W. Brackets <checkins@unknownbrackets.org>
Date: Sun, 28 Aug 2011 00:06:56 -0700
Subject: [PATCH] Don't use require.paths, just use relative paths in require().
---
bin/lessc | 3 ++-
lib/less/functions.js | 2 +-
lib/less/index.js | 15 ++++++---------
lib/less/parser.js | 2 +-
lib/less/tree.js | 4 ++--
lib/less/tree/alpha.js | 2 +-
lib/less/tree/anonymous.js | 2 +-
lib/less/tree/call.js | 2 +-
lib/less/tree/color.js | 2 +-
lib/less/tree/comment.js | 2 +-
lib/less/tree/dimension.js | 2 +-
lib/less/tree/directive.js | 2 +-
lib/less/tree/element.js | 2 +-
lib/less/tree/expression.js | 2 +-
lib/less/tree/import.js | 2 +-
lib/less/tree/javascript.js | 2 +-
lib/less/tree/keyword.js | 2 +-
lib/less/tree/mixin.js | 2 +-
lib/less/tree/operation.js | 2 +-
lib/less/tree/quoted.js | 2 +-
lib/less/tree/rule.js | 2 +-
lib/less/tree/ruleset.js | 2 +-
lib/less/tree/selector.js | 2 +-
lib/less/tree/url.js | 2 +-
lib/less/tree/value.js | 2 +-
lib/less/tree/variable.js | 2 +-
26 files changed, 33 insertions(+), 35 deletions(-)
diff --git a/bin/lessc b/bin/lessc
index 1e3c961..1243488 100755
--- a/bin/lessc
+++ b/bin/lessc
@@ -4,7 +4,8 @@ var path = require('path'),
fs = require('fs'),
sys = require('sys');
-require.paths.unshift(path.join(__dirname, '..', 'lib'));
+var path_joiner = process.platform === 'win32' ? ';' : ':';
+process.env.NODE_PATH = path.join(__dirname, '..', 'lib') + (process.env.NODE_PATH ? path_joiner + process.env.NODE_PATH : '');
var less = require('less');
var args = process.argv.slice(1);
diff --git a/lib/less/functions.js b/lib/less/functions.js
index fc9d86f..96dcc8c 100644
--- a/lib/less/functions.js
+++ b/lib/less/functions.js
@@ -182,4 +182,4 @@ function clamp(val) {
return Math.min(1, Math.max(0, val));
}
-})(require('less/tree'));
+})(require('./tree'));
diff --git a/lib/less/index.js b/lib/less/index.js
index a333f63..7a78317 100644
--- a/lib/less/index.js
+++ b/lib/less/index.js
@@ -2,13 +2,11 @@ var path = require('path'),
sys = require('sys'),
fs = require('fs');
-require.paths.unshift(path.join(__dirname, '..'));
-
var less = {
version: [1, 1, 3],
- Parser: require('less/parser').Parser,
- importer: require('less/parser').importer,
- tree: require('less/tree'),
+ Parser: require('./parser').Parser,
+ importer: require('./parser').importer,
+ tree: require('./tree'),
render: function (input, options, callback) {
options = options || {};
@@ -81,7 +79,7 @@ var less = {
'call', 'url', 'alpha', 'import',
'mixin', 'comment', 'anonymous', 'value', 'javascript'
].forEach(function (n) {
- require(path.join('less', 'tree', n));
+ require('./tree/' + n);
});
less.Parser.importer = function (file, paths, callback) {
@@ -117,7 +115,7 @@ less.Parser.importer = function (file, paths, callback) {
}
}
-require('less/functions');
+require('./functions');
for (var k in less) { exports[k] = less[k] }
@@ -135,5 +133,4 @@ function stylize(str, style) {
return '\033[' + styles[style][0] + 'm' + str +
'\033[' + styles[style][1] + 'm';
}
-less.stylize = stylize;
-
+less.stylize = stylize;
\ No newline at end of file
diff --git a/lib/less/parser.js b/lib/less/parser.js
index 7e02bdc..9b6df64 100644
--- a/lib/less/parser.js
+++ b/lib/less/parser.js
@@ -2,7 +2,7 @@ var less, tree;
if (typeof(window) === 'undefined') {
less = exports,
- tree = require('less/tree');
+ tree = require('./tree');
} else {
if (typeof(window.less) === 'undefined') { window.less = {} }
less = window.less,
diff --git a/lib/less/tree.js b/lib/less/tree.js
index eb08aa4..4c471c0 100644
--- a/lib/less/tree.js
+++ b/lib/less/tree.js
@@ -1,10 +1,10 @@
-require('less/tree').find = function (obj, fun) {
+require('./tree').find = function (obj, fun) {
for (var i = 0, r; i < obj.length; i++) {
if (r = fun.call(obj, obj[i])) { return r }
}
return null;
};
-require('less/tree').jsify = function (obj) {
+require('./tree').jsify = function (obj) {
if (Array.isArray(obj.value) && (obj.value.length > 1)) {
return '[' + obj.value.map(function (v) { return v.toCSS(false) }).join(', ') + ']';
} else {
diff --git a/lib/less/tree/alpha.js b/lib/less/tree/alpha.js
index 551ccba..139ae92 100644
--- a/lib/less/tree/alpha.js
+++ b/lib/less/tree/alpha.js
@@ -14,4 +14,4 @@ tree.Alpha.prototype = {
}
};
-})(require('less/tree'));
+})(require('../tree'));
diff --git a/lib/less/tree/anonymous.js b/lib/less/tree/anonymous.js
index 89840d0..460c9ec 100644
--- a/lib/less/tree/anonymous.js
+++ b/lib/less/tree/anonymous.js
@@ -10,4 +10,4 @@ tree.Anonymous.prototype = {
eval: function () { return this }
};
-})(require('less/tree'));
+})(require('../tree'));
diff --git a/lib/less/tree/call.js b/lib/less/tree/call.js
index 4a72932..c6ea5d0 100644
--- a/lib/less/tree/call.js
+++ b/lib/less/tree/call.js
@@ -42,4 +42,4 @@ tree.Call.prototype = {
}
};
-})(require('less/tree'));
+})(require('../tree'));
diff --git a/lib/less/tree/color.js b/lib/less/tree/color.js
index bb7646a..37ce178 100644
--- a/lib/less/tree/color.js
+++ b/lib/less/tree/color.js
@@ -98,4 +98,4 @@ tree.Color.prototype = {
};
-})(require('less/tree'));
+})(require('../tree'));
diff --git a/lib/less/tree/comment.js b/lib/less/tree/comment.js
index 2d95dff..f4a3384 100644
--- a/lib/less/tree/comment.js
+++ b/lib/less/tree/comment.js
@@ -11,4 +11,4 @@ tree.Comment.prototype = {
eval: function () { return this }
};
-})(require('less/tree'));
+})(require('../tree'));
diff --git a/lib/less/tree/dimension.js b/lib/less/tree/dimension.js
index 41f3ca2..33560d7 100644
--- a/lib/less/tree/dimension.js
+++ b/lib/less/tree/dimension.js
@@ -31,4 +31,4 @@ tree.Dimension.prototype = {
}
};
-})(require('less/tree'));
+})(require('../tree'));
diff --git a/lib/less/tree/directive.js b/lib/less/tree/directive.js
index fbe9a93..0e8df24 100644
--- a/lib/less/tree/directive.js
+++ b/lib/less/tree/directive.js
@@ -30,4 +30,4 @@ tree.Directive.prototype = {
rulesets: function () { return tree.Ruleset.prototype.rulesets.apply(this.ruleset) }
};
-})(require('less/tree'));
+})(require('../tree'));
diff --git a/lib/less/tree/element.js b/lib/less/tree/element.js
index 27cf822..0003a0f 100644
--- a/lib/less/tree/element.js
+++ b/lib/less/tree/element.js
@@ -32,4 +32,4 @@ tree.Combinator.prototype.toCSS = function (env) {
}[this.value];
};
-})(require('less/tree'));
+})(require('../tree'));
diff --git a/lib/less/tree/expression.js b/lib/less/tree/expression.js
index f638a1b..405a2ac 100644
--- a/lib/less/tree/expression.js
+++ b/lib/less/tree/expression.js
@@ -20,4 +20,4 @@ tree.Expression.prototype = {
}
};
-})(require('less/tree'));
+})(require('../tree'));
diff --git a/lib/less/tree/import.js b/lib/less/tree/import.js
index 2a95120..2f74bcb 100644
--- a/lib/less/tree/import.js
+++ b/lib/less/tree/import.js
@@ -74,4 +74,4 @@ tree.Import.prototype = {
}
};
-})(require('less/tree'));
+})(require('../tree'));
diff --git a/lib/less/tree/javascript.js b/lib/less/tree/javascript.js
index 4ec66b9..772a31d 100644
--- a/lib/less/tree/javascript.js
+++ b/lib/less/tree/javascript.js
@@ -47,5 +47,5 @@ tree.JavaScript.prototype = {
}
};
-})(require('less/tree'));
+})(require('../tree'));
diff --git a/lib/less/tree/keyword.js b/lib/less/tree/keyword.js
index a4431ba..01635b2 100644
--- a/lib/less/tree/keyword.js
+++ b/lib/less/tree/keyword.js
@@ -6,4 +6,4 @@ tree.Keyword.prototype = {
toCSS: function () { return this.value }
};
-})(require('less/tree'));
+})(require('../tree'));
diff --git a/lib/less/tree/mixin.js b/lib/less/tree/mixin.js
index 24cb8e4..86f8a18 100644
--- a/lib/less/tree/mixin.js
+++ b/lib/less/tree/mixin.js
@@ -103,4 +103,4 @@ tree.mixin.Definition.prototype = {
}
};
-})(require('less/tree'));
+})(require('../tree'));
diff --git a/lib/less/tree/operation.js b/lib/less/tree/operation.js
index d2e4d57..1ce22fb 100644
--- a/lib/less/tree/operation.js
+++ b/lib/less/tree/operation.js
@@ -29,4 +29,4 @@ tree.operate = function (op, a, b) {
}
};
-})(require('less/tree'));
+})(require('../tree'));
diff --git a/lib/less/tree/quoted.js b/lib/less/tree/quoted.js
index 6ddfa40..38a3f13 100644
--- a/lib/less/tree/quoted.js
+++ b/lib/less/tree/quoted.js
@@ -26,4 +26,4 @@ tree.Quoted.prototype = {
}
};
-})(require('less/tree'));
+})(require('../tree'));
diff --git a/lib/less/tree/rule.js b/lib/less/tree/rule.js
index 18cc49b..911cde6 100644
--- a/lib/less/tree/rule.js
+++ b/lib/less/tree/rule.js
@@ -35,4 +35,4 @@ tree.Shorthand.prototype = {
eval: function () { return this }
};
-})(require('less/tree'));
+})(require('../tree'));
diff --git a/lib/less/tree/ruleset.js b/lib/less/tree/ruleset.js
index cc9a60a..bd7845c 100644
--- a/lib/less/tree/ruleset.js
+++ b/lib/less/tree/ruleset.js
@@ -209,4 +209,4 @@ tree.Ruleset.prototype = {
}
}
};
-})(require('less/tree'));
+})(require('../tree'));
diff --git a/lib/less/tree/selector.js b/lib/less/tree/selector.js
index ddc6842..69eda89 100644
--- a/lib/less/tree/selector.js
+++ b/lib/less/tree/selector.js
@@ -39,4 +39,4 @@ tree.Selector.prototype.toCSS = function (env) {
}).join('');
};
-})(require('less/tree'));
+})(require('../tree'));
diff --git a/lib/less/tree/url.js b/lib/less/tree/url.js
index f427070..50540c0 100644
--- a/lib/less/tree/url.js
+++ b/lib/less/tree/url.js
@@ -22,4 +22,4 @@ tree.URL.prototype = {
}
};
-})(require('less/tree'));
+})(require('../tree'));
diff --git a/lib/less/tree/value.js b/lib/less/tree/value.js
index 922096c..3c1eb29 100644
--- a/lib/less/tree/value.js
+++ b/lib/less/tree/value.js
@@ -21,4 +21,4 @@ tree.Value.prototype = {
}
};
-})(require('less/tree'));
+})(require('../tree'));
diff --git a/lib/less/tree/variable.js b/lib/less/tree/variable.js
index 10f7c08..902859f 100644
--- a/lib/less/tree/variable.js
+++ b/lib/less/tree/variable.js
@@ -21,4 +21,4 @@ tree.Variable.prototype = {
}
};
-})(require('less/tree'));
+})(require('../tree'));
--
1.7.3.1.msysgit.0
@Sequoia
Copy link

Sequoia commented Oct 7, 2011

Thank you thank you for this fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment