| // Generated by CoffeeScript 1.3.1 | ||
| /* | ||
| * less-detect | ||
| * https://github.com/excellenteasy/less-detect | ||
| * | ||
| * Copyright (c) 2012 David Pfahler | ||
| * Licensed under the MIT license. | ||
| */ | ||
| (function() { | ||
| 'use strict'; | ||
| var fs, glob, less, path, | ||
| __indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; }; | ||
| glob = require('glob-whatev'); | ||
| fs = require('fs'); | ||
| less = require('less'); | ||
| path = require('path'); | ||
| exports.detectDependencies = function(directories) { | ||
| var dir, files, _i, _len; | ||
| if (directories == null) { | ||
| directories = ['./']; | ||
| } | ||
| if (typeof directories === 'string') { | ||
| directories = [directories]; | ||
| } | ||
| for (_i = 0, _len = directories.length; _i < _len; _i++) { | ||
| dir = directories[_i]; | ||
| files = (files || []).concat(this.findAll(dir)); | ||
| } | ||
| files = this.cssToLess(files); | ||
| return files = this.stripImported(files, this.getImported(files)); | ||
| }; | ||
| exports.findAll = function(directory) { | ||
| if (/\/$/.test(directory)) { | ||
| directory = directory.replace(/\/$/, ''); | ||
| } | ||
| return glob.glob("" + directory + "/**/*.{less,css}"); | ||
| }; | ||
| exports.cssToLess = function(files) { | ||
| if (typeof files === 'string') { | ||
| files = [files]; | ||
| } | ||
| return files.map(function(filepath) { | ||
| if (/\.css$/.test(filepath)) { | ||
| return exports.rename(filepath); | ||
| } else { | ||
| return filepath; | ||
| } | ||
| }); | ||
| }; | ||
| exports.rename = function(filepath, newPath) { | ||
| fs.renameSync(filepath, newPath = newPath || filepath.replace(/\.css$/, '.less')); | ||
| return newPath; | ||
| }; | ||
| exports.getImported = function(files) { | ||
| var imported, parser; | ||
| if (typeof files === 'string') { | ||
| files = [files]; | ||
| } | ||
| imported = []; | ||
| parser = new less.Parser; | ||
| files.forEach(function(filepath) { | ||
| var dirname, lessSrc; | ||
| dirname = path.dirname(filepath); | ||
| lessSrc = fs.readFileSync(filepath, 'utf-8'); | ||
| return parser.parse(lessSrc, function(err, tree) { | ||
| var rule, _i, _len, _ref, _results; | ||
| if (err) { | ||
| throw new Error(err.message); | ||
| } | ||
| _ref = tree.rules; | ||
| _results = []; | ||
| for (_i = 0, _len = _ref.length; _i < _len; _i++) { | ||
| rule = _ref[_i]; | ||
| _results.push(rule.path ? imported.push(path.join(dirname, rule.path)) : void 0); | ||
| } | ||
| return _results; | ||
| }); | ||
| }); | ||
| return imported; | ||
| }; | ||
| exports.stripImported = function(files, imported) { | ||
| return files.filter(function(filepath) { | ||
| if (__indexOf.call(imported, filepath) >= 0) { | ||
| return false; | ||
| } else { | ||
| return true; | ||
| } | ||
| }); | ||
| }; | ||
| }).call(this); |
| ### | ||
| * less-detect | ||
| * https://github.com/excellenteasy/less-detect | ||
| * | ||
| * Copyright (c) 2012 David Pfahler | ||
| * Licensed under the MIT license. | ||
| ### | ||
| 'use strict'; | ||
| glob = require 'glob-whatev' | ||
| fs = require 'fs' | ||
| less = require 'less' | ||
| path = require 'path' | ||
| # returns an array of filepaths of less/css files | ||
| # in current directory (or otherwise specified) | ||
| # which are not imported in other files | ||
| exports.detectDependencies = (directories=['./']) -> | ||
| if typeof directories is 'string' then directories = [directories] | ||
| files = (files or []).concat(@findAll dir) for dir in directories | ||
| files = @cssToLess files | ||
| files = @stripImported files, @getImported(files) | ||
| # return both less and css files from directory | ||
| exports.findAll = (directory) -> | ||
| # remove trailing slash | ||
| if /\/$/.test(directory) then directory = directory.replace /\/$/, '' | ||
| return glob.glob("#{directory}/**/*.{less,css}") | ||
| # returns array of filespaths where .css files are converted to .less | ||
| exports.cssToLess = (files) -> | ||
| if typeof files is 'string' then files = [files] | ||
| files.map((filepath) -> if /\.css$/.test(filepath) then exports.rename(filepath) else filepath) | ||
| # return filepath of renamed file (css to less) and actually rename it | ||
| exports.rename = (filepath, newPath) -> | ||
| fs.renameSync(filepath, newPath = newPath or filepath.replace /\.css$/, '.less') | ||
| return newPath | ||
| # returns array of imported files as filepaths | ||
| exports.getImported = (files) -> | ||
| if typeof files is 'string' then files = [files] | ||
| # track imported filepaths in array | ||
| imported = [] | ||
| # less parser | ||
| parser = new less.Parser | ||
| files.forEach (filepath) -> | ||
| dirname = path.dirname filepath | ||
| lessSrc = fs.readFileSync(filepath, 'utf-8') | ||
| parser.parse lessSrc, (err, tree) -> | ||
| if err then throw new Error err.message | ||
| (imported.push path.join(dirname, rule.path) if rule.path) for rule in tree.rules | ||
| return imported | ||
| # return filtered array without imported files | ||
| exports.stripImported = (files, imported) -> | ||
| files.filter (filepath) -> | ||
| # check if filepath is in imported | ||
| if filepath in imported then false else true |
+5
-3
| { | ||
| "name": "importless", | ||
| "description": "Find stylesheet files (css and less) and strip away the @imported ones", | ||
| "version": "0.1.0", | ||
| "version": "0.1.1", | ||
| "homepage": "https://github.com/excellenteasy/importless", | ||
@@ -26,3 +26,4 @@ "author": { | ||
| "scripts": { | ||
| "test": "grunt test" | ||
| "test": "grunt test", | ||
| "prepublish": "coffee -o lib/ -c src/" | ||
| }, | ||
@@ -34,5 +35,6 @@ "dependencies": { | ||
| "devDependencies": { | ||
| "grunt": "~0.4.0a" | ||
| "grunt": "~0.4.0a", | ||
| "coffee-script": "~1.2.0" | ||
| }, | ||
| "keywords": [] | ||
| } |
+1
-1
@@ -6,3 +6,3 @@ # importless | ||
| ## Getting Started | ||
| Install the module with: `npm install less-detect` | ||
| Install the module with: `npm install importless` | ||
@@ -9,0 +9,0 @@ ```javascript |
| "use strict" | ||
| importless = require '../lib/importless' | ||
| importless = require '../src/importless' | ||
| fs = require 'fs' | ||
@@ -4,0 +4,0 @@ |
| ### | ||
| * less-detect | ||
| * https://github.com/excellenteasy/less-detect | ||
| * | ||
| * Copyright (c) 2012 David Pfahler | ||
| * Licensed under the MIT license. | ||
| ### | ||
| 'use strict'; | ||
| glob = require 'glob-whatev' | ||
| fs = require 'fs' | ||
| less = require 'less' | ||
| path = require 'path' | ||
| # returns an array of filepaths of less/css files | ||
| # in current directory (or otherwise specified) | ||
| # which are not imported in other files | ||
| exports.detectDependencies = (directories=['./']) -> | ||
| if typeof directories is 'string' then directories = [directories] | ||
| files = (files or []).concat(@findAll dir) for dir in directories | ||
| files = @cssToLess files | ||
| files = @stripImported files, @getImported(files) | ||
| # return both less and css files from directory | ||
| exports.findAll = (directory) -> | ||
| # remove trailing slash | ||
| if /\/$/.test(directory) then directory = directory.replace /\/$/, '' | ||
| return glob.glob("#{directory}/**/*.{less,css}") | ||
| # returns array of filespaths where .css files are converted to .less | ||
| exports.cssToLess = (files) -> | ||
| if typeof files is 'string' then files = [files] | ||
| files.map((filepath) -> if /\.css$/.test(filepath) then exports.rename(filepath) else filepath) | ||
| # return filepath of renamed file (css to less) and actually rename it | ||
| exports.rename = (filepath, newPath) -> | ||
| fs.renameSync(filepath, newPath = newPath or filepath.replace /\.css$/, '.less') | ||
| return newPath | ||
| # returns array of imported files as filepaths | ||
| exports.getImported = (files) -> | ||
| if typeof files is 'string' then files = [files] | ||
| # track imported filepaths in array | ||
| imported = [] | ||
| # less parser | ||
| parser = new less.Parser | ||
| files.forEach (filepath) -> | ||
| dirname = path.dirname filepath | ||
| lessSrc = fs.readFileSync(filepath, 'utf-8') | ||
| parser.parse lessSrc, (err, tree) -> | ||
| if err then throw new Error err.message | ||
| (imported.push path.join(dirname, rule.path) if rule.path) for rule in tree.rules | ||
| return imported | ||
| # return filtered array without imported files | ||
| exports.stripImported = (files, imported) -> | ||
| files.filter (filepath) -> | ||
| # check if filepath is in imported | ||
| if filepath in imported then false else true |
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
11188
33.27%11
10%126
250%2
100%1
Infinity%