Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 24 additions & 2 deletions lib/less/parser.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
var less, tree;
var less, tree, resolveNpmFile;

// Node.js does not have a header file added which defines less
if (less === undefined) {
less = exports;
tree = require('./tree');
resolveNpmFile = require('resolve').sync;
less.mode = 'node';
}
//
Expand Down Expand Up @@ -82,6 +83,27 @@ less.Parser = function Parser(env) {
callback(e, root, importedPreviously, fullPath);
};

if (importOptions.npm) {
path = resolveNpmFile(path.replace(/\.less$/, ''), {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ForbesLindesay mind removing the regex/replace here? thx

basedir: currentFileInfo.currentDirectory,
extensions: ['.less', '.css'],
packageFilter: function packageFilter(info, pkgdir) {
// no style field, keep info unchanged
if (!info.style) {
return info;
}

// replace main
if (typeof info.style === 'string') {
info.main = info.style;
return info;
}

return info;
},
paths: process.env.NODE_PATH ? process.env.NODE_PATH.split(':') : []

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think on Windows separator is ;.

});
}
if (less.Parser.importer) {
less.Parser.importer(path, currentFileInfo, fileParsedFunc, env);
} else {
Expand Down Expand Up @@ -1660,7 +1682,7 @@ less.Parser = function Parser(env) {
},

importOption: function() {
var opt = $re(/^(less|css|multiple|once|inline|reference)/);
var opt = $re(/^(less|css|multiple|once|inline|reference|npm)/);
if (opt) {
return opt[1];
}
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@
"request": ">=2.33.0",
"mkdirp": "~0.3.5",
"clean-css": "2.1.x",
"source-map": "0.1.x"
"source-map": "0.1.x",
"resolve": "0.6.2"
},
"devDependencies": {
"diff": "~1.0",
Expand Down