From 0a4e8ba51b064a449128b885fe133118a618b0ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rouven=20We=C3=9Fling?= Date: Mon, 26 Oct 2020 12:08:26 +0100 Subject: [PATCH 1/5] Import individual lodash methods --- sass-graph.js | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/sass-graph.js b/sass-graph.js index e3a272d..ae2d572 100644 --- a/sass-graph.js +++ b/sass-graph.js @@ -2,7 +2,13 @@ var fs = require('fs'); var path = require('path'); -var _ = require('lodash'); +var includes = require('lodash/includes'); +var each = require('lodash/each'); +var intersection = require('lodash/intersection'); +var map = require('lodash/map'); +var uniq = require('lodash/uniq'); +var filter = require('lodash/filter'); +var concat = require('lodash/concat'); var glob = require('glob'); var parseImports = require('./parse-imports'); @@ -45,13 +51,13 @@ function Graph(options, dir) { this.exclude = options.exclude instanceof RegExp ? options.exclude : null; this.index = {}; this.follow = options.follow || false; - this.loadPaths = _(options.loadPaths).map(function(p) { + this.loadPaths = map(options.loadPaths, function(p) { return path.resolve(p); - }).value(); + }); if (dir) { var graph = this; - _.each(glob.sync(dir+'/**/*.@('+this.extensions.join('|')+')', { dot: true, nodir: true, follow: this.follow }), function(file) { + each(glob.sync(dir+'/**/*.@('+this.extensions.join('|')+')', { dot: true, nodir: true, follow: this.follow }), function(file) { try { graph.addFile(path.resolve(file)); } catch (e) {} @@ -76,7 +82,7 @@ Graph.prototype.addFile = function(filepath, parent) { var i, length = imports.length, loadPaths, resolved; for (i = 0; i < length; i++) { - loadPaths = _([cwd, this.dir]).concat(this.loadPaths).filter().uniq().value(); + loadPaths = uniq(filter(concat([cwd, this.dir], this.loadPaths))); resolved = resolveSassPath(imports[i], loadPaths, this.extensions); if (!resolved) continue; @@ -84,7 +90,7 @@ Graph.prototype.addFile = function(filepath, parent) { if (this.exclude !== null && this.exclude.test(resolved)) continue; // recurse into dependencies if not already enumerated - if (!_.includes(entry.imports, resolved)) { + if (!includes(entry.imports, resolved)) { entry.imports.push(resolved); this.addFile(fs.realpathSync(resolved), filepath); } @@ -92,7 +98,7 @@ Graph.prototype.addFile = function(filepath, parent) { // add link back to parent if (parent) { - resolvedParent = _(parent).intersection(this.loadPaths).value(); + resolvedParent = intersection(parent, this.loadPaths); if (resolvedParent) { resolvedParent = parent.substr(parent.indexOf(resolvedParent)); @@ -134,7 +140,7 @@ Graph.prototype.visit = function(filepath, callback, edgeCallback, visited) { var i, length = edges.length; for (i = 0; i < length; i++) { - if (!_.includes(visited, edges[i])) { + if (!includes(visited, edges[i])) { visited.push(edges[i]); callback(edges[i], this.index[edges[i]]); this.visit(edges[i], callback, edgeCallback, visited); From 55e98bf4aa0100eccf2030246e9d61279120993a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rouven=20We=C3=9Fling?= Date: Mon, 26 Oct 2020 12:20:14 +0100 Subject: [PATCH 2/5] Replace lodash/map with Array.prototype.map --- sass-graph.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/sass-graph.js b/sass-graph.js index ae2d572..ae31ac3 100644 --- a/sass-graph.js +++ b/sass-graph.js @@ -5,7 +5,6 @@ var path = require('path'); var includes = require('lodash/includes'); var each = require('lodash/each'); var intersection = require('lodash/intersection'); -var map = require('lodash/map'); var uniq = require('lodash/uniq'); var filter = require('lodash/filter'); var concat = require('lodash/concat'); @@ -51,7 +50,7 @@ function Graph(options, dir) { this.exclude = options.exclude instanceof RegExp ? options.exclude : null; this.index = {}; this.follow = options.follow || false; - this.loadPaths = map(options.loadPaths, function(p) { + this.loadPaths = (options.loadPaths || []).map(function(p) { return path.resolve(p); }); From de1e4ac269f5f4db1e24c1b52e0cee34139d0741 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rouven=20We=C3=9Fling?= Date: Mon, 26 Oct 2020 12:22:11 +0100 Subject: [PATCH 3/5] Replace lodash/concat with Array.prototype.concat --- sass-graph.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/sass-graph.js b/sass-graph.js index ae31ac3..6ed1557 100644 --- a/sass-graph.js +++ b/sass-graph.js @@ -7,7 +7,6 @@ var each = require('lodash/each'); var intersection = require('lodash/intersection'); var uniq = require('lodash/uniq'); var filter = require('lodash/filter'); -var concat = require('lodash/concat'); var glob = require('glob'); var parseImports = require('./parse-imports'); @@ -81,7 +80,7 @@ Graph.prototype.addFile = function(filepath, parent) { var i, length = imports.length, loadPaths, resolved; for (i = 0; i < length; i++) { - loadPaths = uniq(filter(concat([cwd, this.dir], this.loadPaths))); + loadPaths = uniq(filter([cwd, this.dir].concat(this.loadPaths))); resolved = resolveSassPath(imports[i], loadPaths, this.extensions); if (!resolved) continue; From b64c23988e4adbc30efdb595996ecdf5e8cd5341 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rouven=20We=C3=9Fling?= Date: Mon, 26 Oct 2020 13:53:52 +0100 Subject: [PATCH 4/5] Replace lodash/each with Array.prototype.forEach --- sass-graph.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/sass-graph.js b/sass-graph.js index 6ed1557..c630ccc 100644 --- a/sass-graph.js +++ b/sass-graph.js @@ -3,7 +3,6 @@ var fs = require('fs'); var path = require('path'); var includes = require('lodash/includes'); -var each = require('lodash/each'); var intersection = require('lodash/intersection'); var uniq = require('lodash/uniq'); var filter = require('lodash/filter'); @@ -55,7 +54,7 @@ function Graph(options, dir) { if (dir) { var graph = this; - each(glob.sync(dir+'/**/*.@('+this.extensions.join('|')+')', { dot: true, nodir: true, follow: this.follow }), function(file) { + glob.sync(dir+'/**/*.@('+this.extensions.join('|')+')', { dot: true, nodir: true, follow: this.follow }).forEach(function(file) { try { graph.addFile(path.resolve(file)); } catch (e) {} From 955a09dbb96bdf50ff7a49c1d99bbd3f27a78999 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rouven=20We=C3=9Fling?= Date: Mon, 26 Oct 2020 13:55:18 +0100 Subject: [PATCH 5/5] Replace lodash/filter with Array.prototype.filter --- sass-graph.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/sass-graph.js b/sass-graph.js index c630ccc..6254a17 100644 --- a/sass-graph.js +++ b/sass-graph.js @@ -5,10 +5,13 @@ var path = require('path'); var includes = require('lodash/includes'); var intersection = require('lodash/intersection'); var uniq = require('lodash/uniq'); -var filter = require('lodash/filter'); var glob = require('glob'); var parseImports = require('./parse-imports'); +function identity (value) { + return value; +} + // resolve a sass module to a path function resolveSassPath(sassPath, loadPaths, extensions) { // trim sass file extensions @@ -79,7 +82,7 @@ Graph.prototype.addFile = function(filepath, parent) { var i, length = imports.length, loadPaths, resolved; for (i = 0; i < length; i++) { - loadPaths = uniq(filter([cwd, this.dir].concat(this.loadPaths))); + loadPaths = uniq([cwd, this.dir].concat(this.loadPaths).filter(identity)); resolved = resolveSassPath(imports[i], loadPaths, this.extensions); if (!resolved) continue;