How to use the stylus/lib/utils.lookupIndex function in stylus

To help you get started, we’ve selected a few stylus examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github mockingbot / ibot / scripts / stylus-enhanced-evaluator.js View on Github external
// Literal
  if (/\.css(?:"|$)/.test(path)) {
    literal = true
    if (!imported.once && !this.includeCSS) {
      return imported
    }
  }

  // support optional .styl
  if (!literal && !/\.styl$/i.test(path)) path += ".styl"

  // Lookup
  found = utils.find(path, this.paths, this.filename)
  if (!found) {
    found = utils.lookupIndex(name, this.paths, this.filename)
  }
  /*****************************************************************************
   * THIS IS THE ONLY BLOCK THAT DIFFERS FROM THE ACTUAL STYLUS IMPLEMENTATION. *
   *****************************************************************************/
  // if still not found, so maybe it ref to a module file in node_modules
  if (!found) {
    path = urlToRequest(path)
    let pathComponents = this.filename.split(sep)
    if (pathComponents.indexOf("components") > -1) {
      const pkgDir = pathComponents
        .slice(0, pathComponents.indexOf("components") + 2)
        .join(sep)
      found = [resolve.sync(path, { extensions: [".styl"], basedir: pkgDir })]
    }
  }
  // Throw if import failed
github shama / stylus-loader / lib / evaluator.js View on Github external
}

  // support optional .styl
  if (!literal && !/\.styl$/i.test(path)) path += '.styl';

  /*****************************************************************************
  * THIS IS THE ONLY BLOCK THAT DIFFERS FROM THE ACTUAL STYLUS IMPLEMENTATION. *
  *****************************************************************************/
  // Lookup
  var dirname = this.paths[this.paths.length - 1];
  found = this.cache.find(path, dirname);
  index = this.cache.isIndex(path, dirname);
  if (!found) {
    found = utils.find(path, this.paths, this.filename);
    if (!found) {
      found = utils.lookupIndex(name, this.paths, this.filename);
      index = true;
    }
  }

  // Throw if import failed
  if (!found) throw new Error('failed to locate @' + nodeName + ' file ' + path);

  var block = new nodes.Block;

  for (var i = 0, len = found.length; i < len; ++i) {
    block.push(importFile.call(this, imported, found[i], literal, index));
  }

  return block;
}
github shama / stylus-loader / lib / pathcache.js View on Github external
var stylusIndex = function(context, path) {
    // Stylus calls the argument name. If it exists it should match the name
    // of a module in node_modules.
    if (!path) {
      return null;
    }

    var paths = options.paths.concat(context);
    var found = utils.lookupIndex(path, paths, options.filename);
    if (found) {
      return {path: normalizePaths(found), index: true};
    }
  };
github chenckang / react-json-pretty / example / node_modules / stylus-loader / lib / pathcache.js View on Github external
function(context, path) {
      // Stylus calls the argument name. If it exists it should match the name
      // of a module in node_modules.
      if (!path) {
        return null;
      }

      var found = utils.lookupIndex(path, options.paths, options.filename);
      if (found) {
        return {path: normalizePaths(found), index: true};
      }
    },
    // Fallback to resolving with webpack's configured resovler.