<commit_before>import 'fetch';
import url from 'url';
import sass from 'sass.js';

let urlBase;

// intercept file loading requests (@import directive) from libsass
sass.importer((request, done) => {
  const importUrl = url.resolve(urlBase, request.current + '.scss');
  fetch(importUrl)
    .then(response => response.text())
    .then(content => done({ content }));
});

const compile = scss => {
  return new Promise((resolve, reject) => {
    sass.compile(scss, result => {
      if (result.status === 0) {
        const style = document.createElement('style');
        style.textContent = result.text;
        style.setAttribute('type', 'text/css');
        document.getElementsByTagName('head')[0].appendChild(style);
        resolve('');
      } else {
        reject(result.formatted);
      }
    });
  });
};

const scssFetch = load => {
  urlBase = load.address;
  // fetch initial scss file
  return fetch(urlBase)
    .then(response => response.text())
    .then(compile);
};

export default scssFetch;<commit_msg>- Added file uri scheme support<commit_after>import 'fetch';
import url from 'url';
import sass from 'sass.js';

let urlBase;

// intercept file loading requests (@import directive) from libsass
sass.importer((request, done) => {
  const importUrl = url.resolve(urlBase, request.current + '.scss');
  fetch(importUrl)
    .then(response => response.text())
    .then(content => done({ content }));
});

const compile = scss => {
  return new Promise((resolve, reject) => {
    sass.compile(scss, result => {
      if (result.status === 0) {
        const style = document.createElement('style');
        style.textContent = result.text;
        style.setAttribute('type', 'text/css');
        document.getElementsByTagName('head')[0].appendChild(style);
        resolve('');
      } else {
        reject(result.formatted);
      }
    });
  });
};

const scssFetch = load => {
    urlBase = load.address;

    if (urlBase.indexOf('file://') > -1) {
        return new Promise((resolve, reject) => {
            let url = urlBase.slice('file://'.length);
            fs.readFile(url, 'utf8', (err, data) => {
                console.log(data);

                if (err) {
                    reject(err);
                }
                else {
                    resolve(data);
                }
            });
        }).then(compile);
    }
    else {
        // fetch initial scss file
        return fetch(urlBase)
        .then(response => response.text())
        .then(compile);
    }
};

export default scssFetch;
{'fraction_non_alphanumeric': 0.15595611285266459, 'fraction_numerical': 0.0023510971786833857, 'mean_word_length': 2.4176706827309236, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 22, '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': '1025222', 'n_tokens_mistral': 759, 'n_tokens_neox': 744, 'n_words': 172}