How to use the stylus/lib/utils.find 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 shama / stylus-loader / lib / pathcache.js View on Github external
var stylusFile = function(context, path) {
    // Stylus adds .styl to paths for normal "paths" lookup if it isn't there.
    if (!/.styl$/.test(path)) {
      path += '.styl';
    }

    var paths = options.paths.concat(context);
    var found = utils.find(path, paths, options.filename)
    if (found) {
      return normalizePaths(found);
    }
  };
github mockingbot / ibot / scripts / stylus-enhanced-evaluator.js View on Github external
return imported
  }

  // 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 })]
    }
github shama / stylus-loader / lib / evaluator.js View on Github external
return imported;
    }
  }

  // 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 chenckang / react-json-pretty / example / node_modules / stylus-loader / lib / pathcache.js View on Github external
function(context, path) {
      // Stylus adds .styl to paths for normal "paths" lookup if it isn't there.
      if (!/.styl$/.test(path)) {
        path += '.styl';
      }

      var found = utils.find(path, options.paths, options.filename)
      if (found) {
        return normalizePaths(found);
      }
    },
    // Stylus's normal resolver for node_modules packages. Cannot locate paths