<commit_before>glob = require('glob')
path = require('path')

module.exports = function(url, prev, done) {
  this.prev_list = this.prev_list || []

  if(!glob.hasMagic(url)) {
    // normal url, resolve to an import of the file
    if(url.indexOf('|prev=') === 0) {
      // if there is a |prev keyword, resolve file relative to that file.. so if
      // you do @import |prev=~|foo.sass, it will resolve to ~/foo.sass
      var prev_dir = null
      var prev_re = /^\|prev=([^\|]*?)\|/
      var matches = url.match(prev_re)

      if(matches.length) {
        prev_dir = path.dirname(matches[1])
        url = url.replace(prev_re, '')
        url = path.resolve(prev_dir, url)
        return done({file: url})

      }
    } else {
      return done({file: url})
    }
  }

  // url is a glob, like foo/*.sass, resolve to importing all matching files, so
  // if there is foo/1.sass and foo/2.sass, it will import both of those files
  glob(url, {cwd: path.dirname(prev)}, function (err, files) {
    var ret = {
      contents: "\n"
    }

    files.forEach(function(file) {
      // import all the matched files, passing through the current file. this is
      // because if you didn't, the path will resolve relative to foo/*.sass,
      // which will fail since that is not an actual path.
      ret.contents += '@import "|prev=' + prev + '|' + file + "\";\n"
    })

    done(ret)
  })<commit_msg>return done<commit_after>glob = require('glob')
path = require('path')

module.exports = function(url, prev, done) {
  this.prev_list = this.prev_list || []

  if(!glob.hasMagic(url)) {
    // normal url, resolve to an import of the file
    if(url.indexOf('|prev=') === 0) {
      // if there is a |prev keyword, resolve file relative to that file.. so if
      // you do @import |prev=~|foo.sass, it will resolve to ~/foo.sass
      var prev_dir = null
      var prev_re = /^\|prev=([^\|]*?)\|/
      var matches = url.match(prev_re)

      if(matches.length) {
        prev_dir = path.dirname(matches[1])
        url = url.replace(prev_re, '')
        url = path.resolve(prev_dir, url)
        return done({file: url})

      }
    } else {
      return done({file: url})
    }
  }

  // url is a glob, like foo/*.sass, resolve to importing all matching files, so
  // if there is foo/1.sass and foo/2.sass, it will import both of those files
  glob(url, {cwd: path.dirname(prev)}, function (err, files) {
    var ret = {
      contents: "\n"
    }

    files.forEach(function(file) {
      // import all the matched files, passing through the current file. this is
      // because if you didn't, the path will resolve relative to foo/*.sass,
      // which will fail since that is not an actual path.
      ret.contents += '@import "|prev=' + prev + '|' + file + "\";\n"
    })

    return done(ret)
  })
{'fraction_non_alphanumeric': 0.1500177746178457, 'fraction_numerical': 0.0028439388553146107, 'mean_word_length': 2.4358974358974357, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3531882', 'n_tokens_mistral': 927, 'n_tokens_neox': 906, 'n_words': 294}