npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@retailmenot/roux-sass-importer

v4.2.0

Published

A node-sass custom importer for Roux ecosystem ingredients.

Downloads

31

Readme

@retailmenot/roux-sass-importer

A node-sass custom importer for ingredients in the [Roux][Roux ecosystem].

Build Status Coverage Status

Installation

npm install @retailmenot/roux-sass-importer

Usage

This importer makes it possible to import Sass from an ingredient by specifying the pantry and ingredient name only:

@import "@namespace/pantry/an-ingredient";
@import "another-pantry/another-ingredient";

Create an importer and pass it to node-sass as follows:

var sass = require('node-sass');
var rouxSassImporter = require('@retailmenot/roux-sass-importer');

var importer = rouxSassImporter(sass.NULL, {
  pantries: {
    '@namespace/pantry': somePantryInstance,
    // This will be initialized and cached across calls to the
    // importer
    '@namespace/pantry2': '/path/to/pantry2'
  },
  pantrySearchPaths: [
    path.resolve('node_modules'),
    path.resolve('some/other/path')
  ]
});

sass.render({
  file: 'path/to/your/file.scss',
  importer: importer
},
function(err, result){
  console.log(result && result.css.toString());
});

If passing only a path, and you have nested the pantry entry, please ensure that you have correctly noted that in your package.json, per the roux README.

Relative @import paths

An important note regarding how relative @import paths are resolved:

If the import path can be parsed by roux.parseIngredientPath, then the importer will try to look up the corresponding Sass entry point for that ingredient by instantiating the pantry with roux.initialize. If successful, the import path is resolved to the entry point, otherwise an error is returned. This means that relative file system paths which look like ingredient paths will not work.

Ideally, if we couldn't find the pantry in any of the pantrySearchPaths, we would not return an error, but instead tell node-sass to resolve the import path in the default manner. Unfortunately, this is not possible due to a bug in either node-sass or libsass.

The upshot of this is that relative paths should begin with ./ or ../. These will never be parseable as ingredient paths, so they will be handed off to node-sass to resolve.

CSS De-duplicating

An important note on deduping output in the CSS:

The importer will keep track of which ingredient files have already been imported. It will do so for imports matching an ingredient's entrypoint, as well as relative imports from within any sass file inside of a known pantry. Whenever an import for the same file is encountered, the importer will return empty file contents to prevent duplicate CSS from showing up in the compiled output.

API

This module exports a function that accepts an optional config object and returns a node-sass custom importer. The importer only handles import paths matching the following patterns:

  • @<namespace>/<pantry>/<ingredient>
  • <pantry>/<ingredient>

If the import path matches one of the above, the importer attempts to look up the Sass entry point for the named pantry and ingredient. If successful, an absolute path to the entry point is returned (possibly asynchronously).

If the pantry is not found, an Error is returned. If the pantry is found but does not contain the named ingredient, an Error is returned. If both the pantry and ingredient are found but the ingredient does not have a Sass entry point, an Error is returned.

The importer maintains a cache of pantries it looks up. The cache can be primed by means of the optional config.pantries parameter. If the named pantry is cached, the above process completes synchronously. If not cached, the pantry is looked up in the locations named by config.pantrySearchPaths. The first matching pantry found is cached and the above process performed.

  • NODE_SASS_NULL - The object to return when node-sass should do its thing. You should pass require('node-sass').NULL from your webpack config in the repo that's consuming this module.
  • config - optional config object for the importer
  • config.pantries - optional primed cache of pantries, defaults to {}
  • config.pantrySearchPaths - optional array of paths to search for pantries not found in the cache, defaults to ['$CWD/node_modules']