import cssSelectorExtract from 'css-selector-extract';
import path from 'path';

export default class SelectorImporter {
  /**
   * Import packages from the `node_modules` directory.
   * @param {Object} options - Configuration options.
   */
  constructor(options = {}) {
    const defaultOptions = {
      cwd: process.cwd()
    };
    this.options = Object.assign(defaultOptions, options);
  }

  /**
   * Synchronously resolve the path to a node-sass import url.
   * @param {string} url - Import url from node-sass.
   * @return {string} Fully resolved import url or null.
   */
  resolveSync(url) {
    const cleanUrl = this.cleanUrl(url);
    const urlVariants = this.urlVariants(cleanUrl);
    let file = null;
    // Find a url variant that can be resolved.
    urlVariants.some(urlVariant => {
      try {
        const resolvedPath = resolve.sync(urlVariant, {
          basedir: this.options.cwd,
          packageFilter: pkg => this.resolveFilter(pkg)
        });
        if (resolvedPath) {
          file = resolvedPath;
          return true;
        }
      } catch (e) {}
      return false;
    });
    return file;
  }

  /**
   * Asynchronously resolve the path to a node-sass import url.
   * @param {string} url - Import url from node-sass.
   * @return {Promise} Promise for a fully resolved import url.
   */
  resolve(url) {
    return new Promise((promiseResolve) => {
      promiseResolve(this.resolveSync(url));
    });
  }
}

@@ -1129,24 +1129,1179 @@
  file;%0A  %7D%0A%0A
+  parseUrl(url) %7B%0A    // Find selectors in the import url and%0A    // return a cleaned up url and the selectors.%0A    let cleanUrl = this.cleanUrl(url);%0A    let selectorFilters;%0A    const selectorFiltersMatch = url.match(/%7B(%5B%5E%7D%5D+)%7D/);%0A    if (selectorFiltersMatch) %7B%0A      cleanUrl = url.replace(/(%5Cr%5Cn%7C%5Cn%7C%5Cr)/gm, ' ').split(' from ')%5B1%5D.trim();%0A      // Create an array with selectors and replacement as one value.%0A      selectorFilters = selectorFiltersMatch%5B1%5D.split(',')%0A        // Trim unnecessary whitespace.%0A        .map(Function.prototype.call, String.prototype.trim)%0A        // Split selectors and replacement selectors into an array.%0A        .map((currentValue, index) =%3E currentValue.split(' as ')%0A          .map(Function.prototype.call, String.prototype.trim));%0A    %7D%0A    return %7B cleanUrl, selectorFilters %7D;%0A  %7D%0A%0A  /**%0A   * Clean a node sass import url.%0A   * @param %7Bstring%7D url - Import url from node-sass.%0A   * @return %7Bstring%7D Cleaned url.%0A   */%0A  cleanUrl(url) %7B%0A    // Remove tilde symbol from the beginning%0A    // of urls (except home %22~/%22 directory).%0A    const re = new RegExp(%60%5E~(?!$%7Bpath.sep%7D)%60);%0A    return url.replace(re, '');%0A  %7D%0A%0A
   /**%0A   * A

add parseUrl and cleanUrl methods