<commit_before>'use strict';

var sassJs = require('sass.js'),
    q = require('q'),
    _ = require('lodash'),
    path = require('path'),

    getNodeModuleDir = require('./lib/get-node-module-dir'),
    getResolvedPath = require('./lib/get-resolved-path'),
    getPathVariations = require('./lib/get-path-variations'),
    readFile = require('./lib/read-file');

module.exports = function (content) {
    var callback = this.async();
    var self = this;

    sassJs.importer(function (request, done) {
        // Adapted from
        // eslint-disable-next-line max-len 
        // https://github.com/amiramw/grunt-contrib-sassjs/blob/a65f869df967a4e417c4260fd93239e4f0bc55ee/tasks/sass.js#L11
        if (request.path) {
            done();
        } else if (request.resolved) {
            var resolvedPath = getResolvedPath(request),
                pathVariations = getPathVariations(resolvedPath),

                ostensibleNodeModuleName = _.first(request.current.split(path.sep)),
                rootNodeModulesDir = getRootNodeModulesDir(ostensibleNodeModuleName);

            if (rootNodeModulesDir) {
                Array.prototype.push.apply(
                    pathVariations,
                    getPathVariations(path.join(rootNodeModulesDir, request.current))
                );
            }

            q.all(_.map(pathVariations, function (pathVariation) {
                self.addDependency(pathVariation);
                return readFile(pathVariation)
                    .then(function (fileContents) {
                        return {
                            path: pathVariation,
                            content: fileContents
                        };
                    })
                    .catch(function (err) {
                        /**
                         * ENOENT happens when the file does not exist. That is expected,
                         * because we only expect one of the many path variations to exist.
                         * EISDIR happens when a path variation is also the name of a directory.
                         * This also does not need to be a problem if there's a different path
                         * variation is that is a valid file name.
                         */
                        if (err.code === 'ENOENT' || err.code === 'EISDIR') {
                            return null;
                        }
                        throw err;
                    });
            })).then(function (files) {
                done(_(files).compact().first());
            }).catch(function (err) {
                done({ error: JSON.stringify(err) });
            });
        } else {
            done();<commit_msg>Add dependencies when files are actually found<commit_after>'use strict';

var sassJs = require('sass.js'),
    q = require('q'),
    _ = require('lodash'),
    path = require('path'),

    getNodeModuleDir = require('./lib/get-node-module-dir'),
    getResolvedPath = require('./lib/get-resolved-path'),
    getPathVariations = require('./lib/get-path-variations'),
    readFile = require('./lib/read-file');

module.exports = function (content) {
    var callback = this.async();
    var self = this;

    sassJs.importer(function (request, done) {
        // Adapted from
        // eslint-disable-next-line max-len 
        // https://github.com/amiramw/grunt-contrib-sassjs/blob/a65f869df967a4e417c4260fd93239e4f0bc55ee/tasks/sass.js#L11
        if (request.path) {
            done();
        } else if (request.resolved) {
            var resolvedPath = getResolvedPath(request),
                pathVariations = getPathVariations(resolvedPath),

                ostensibleNodeModuleName = _.first(request.current.split(path.sep)),
                rootNodeModulesDir = getRootNodeModulesDir(ostensibleNodeModuleName);

            if (rootNodeModulesDir) {
                Array.prototype.push.apply(
                    pathVariations,
                    getPathVariations(path.join(rootNodeModulesDir, request.current))
                );
            }

            q.all(_.map(pathVariations, function (pathVariation) {
                return readFile(pathVariation)
                    .then(function (fileContents) {
                        self.addDependency(pathVariation);
                        return {
                            path: pathVariation,
                            content: fileContents
                        };
                    })
                    .catch(function (err) {
                        /**
                         * ENOENT happens when the file does not exist. That is expected,
                         * because we only expect one of the many path variations to exist.
                         * EISDIR happens when a path variation is also the name of a directory.
                         * This also does not need to be a problem if there's a different path
                         * variation is that is a valid file name.
                         */
                        if (err.code === 'ENOENT' || err.code === 'EISDIR') {
                            return null;
                        }
                        throw err;
                    });
            })).then(function (files) {
                done(_(files).compact().first());
            }).catch(function (err) {
                done({ error: JSON.stringify(err) });
            });
        } else {
            done();
{'fraction_non_alphanumeric': 0.10368199303901814, 'fraction_numerical': 0.009891921597362154, 'mean_word_length': 1.4212860310421287, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2901534', 'n_tokens_mistral': 1423, 'n_tokens_neox': 1328, 'n_words': 301}