New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More

lessless

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

lessless - npm Package Compare versions

Comparing version 0.2.10 to 0.2.11

@@ -1,6 +0,13 @@

/* lessless version 0.2.10 copyright Dave Geddes (@geddesign) MIT license */
/*
lessless.js
copyright Dave Geddes (@geddesign)
MIT license
*/
var less = require('less'), fs = require('fs'), diveSync = require("diveSync");
var less = require('less'),
fs = require('fs'),
diveSync = require("diveSync");
/* Generate a CSS file based on a LESS file. Optionally pass an array of paths to use for looking up @imports */
function createCSS(lessFile, styledirs) {

@@ -12,13 +19,14 @@ styledirs = styledirs || [];

var data = fs.readFileSync(lessFile);
var parser = new (less.Parser)({
var parser = new(less.Parser)({
// Specify search paths for @import directives. Combine with these common defaults
paths: styledirs.concat(['.', './css'])
});
parser.parse(data.toString(), function (e, tree) {
parser.parse(data.toString(), function(e, tree) {
var cssFile = lessFile.substr(0, lessFile.lastIndexOf('.')) + '.css';
fs.writeFileSync(cssFile, tree.toCSS({compress:true}));
fs.writeFileSync(cssFile, tree.toCSS({
compress: true
}));
console.log('created CSS file: ', cssFile);
});
}
catch (err) {
} catch (err) {
console.log("ERROR: ", err);

@@ -39,4 +47,3 @@ }

}
}
catch (err) {
} catch (err) {
console.log("ERROR: ", err);

@@ -47,2 +54,3 @@ }

/* replace sytlesheet/less with stylesheet */
function stripLessRel(contents) {

@@ -53,2 +61,3 @@ return contents.replace(/stylesheet\/less/g, "stylesheet");

/* replace .less with .css */
function replaceLessExtension(contents) {

@@ -59,2 +68,3 @@ return contents.replace(/\.less\b/g, ".css");

/* strip less.js from the web page (no longer needed after compiling less to css) */
function stripLessJS(contents) {

@@ -64,4 +74,4 @@ return contents.replace(/<script.*?\bless\b[^"']*?\.js.*?<\/script>/g, "");

function ensureArray(a){
if (!(a instanceof Array)){
function ensureArray(a) {
if (!(a instanceof Array)) {
a = [a];

@@ -73,42 +83,34 @@ }

function optimizeProject(directory, styledirs, stripExtensions) {
directory = directory || process.cwd();
directory = stripTrailing(directory || process.cwd(), '/');
stripExtensions = ensureArray(stripExtensions || ['html']);
styledirs = ensureArray(styledirs);
console.log('optimizing LESS in: ', directory);
diveSync(directory,
//ignore node_modules
{filter:function (path, dir) {
//ignore node_modules
{
filter: function(path, dir) {
return path.indexOf('node_modules') === -1;
}},
function (err, file) {
if (err) throw err;
var extension = file.split('.').pop();
if (extension === 'less') {
createCSS(file, styledirs);
}
else if (stripExtensions.indexOf(extension) !== -1) {
adjustLinks(file);
}
}
);
}, function(err, file) {
if (err) throw err;
var extension = file.split('.').pop();
if (extension === 'less') {
createCSS(file, styledirs);
} else if (stripExtensions.indexOf(extension) !== -1) {
adjustLinks(file);
}
});
}
function stripTrailing(str, char) {
return str.substr(-1) === '/' ? str.substr(0, str.length - 1) : str;
}
module.exports = {
createCSS:createCSS,
adjustLinks:adjustLinks,
stripLessRel:stripLessRel,
replaceLessExtension:replaceLessExtension,
stripLessJS:stripLessJS,
optimizeProject:optimizeProject
};
createCSS: createCSS,
adjustLinks: adjustLinks,
stripLessRel: stripLessRel,
replaceLessExtension: replaceLessExtension,
stripLessJS: stripLessJS,
optimizeProject: optimizeProject
};

@@ -10,3 +10,3 @@ {

],
"version": "0.2.10",
"version": "0.2.11",
"repository": {

@@ -13,0 +13,0 @@ "type": "git",

@@ -33,3 +33,3 @@ var buster = require('buster')

after(function () {
//fs.unlinkSync('test/testpaths.css');
fs.unlinkSync('test/testpaths.css');
});

@@ -43,18 +43,2 @@

describe('importing files with same name but different paths', function(){
before(function () {
var testfile = 'test/testnames.less';
lessless.createCSS(testfile);
});
after(function () {
//fs.unlinkSync('test/testnames.css');
});
it('should create CSS file, correctly importing both files with the same name', function () {
var file = fs.readFileSync('test/testnames.css');
expect(file).toBeDefined();
});
});
describe('adjusting LESS links', function(){

@@ -64,4 +48,4 @@ var origHTML, testFile = "test/test.html";

describe('replacing stylesheet/less with stylesheet', function(){
it('should start with 1', function(){
var html = '<link rel="stylesheet/less" type="text/css" href="stylesheet1.less" media="all">';
it('should start with 1', function(){
var html = '<link rel="stylesheet/less" type="text/css" href="stylesheet1.less" media="all">';
expect(html).toMatch(/stylesheet\/less/g);

@@ -68,0 +52,0 @@ //make the change