Skip to content

Instantly share code, notes, and snippets.

@callumacrae
Created March 10, 2016 12:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save callumacrae/3a85a09b278af01cb0ac to your computer and use it in GitHub Desktop.
Save callumacrae/3a85a09b278af01cb0ac to your computer and use it in GitHub Desktop.
'use strict';
var path = require('path');
var findup = require('findup-sync');
var cache = {};
function sassNpmImporter(url, prev, done) {
// Fall back to old URL
var newUrl = url;
try {
if (cache[url]) {
newUrl = cache[url];
return;
}
if (!/^(?:@[^/]+\/)?[^/]+$/.test(url)) {
return;
}
var modulePath = findup(path.join('node_modules', url), {
cwd: path.dirname(prev),
nocase: true
});
var moduleJson = require(path.join(modulePath, 'package.json'));
newUrl = path.join(modulePath, moduleJson.mainSass);
} catch (e) {
// Ignore error
} finally {
cache[url] = newUrl;
done({ file: newUrl });
}
}
module.exports = sassNpmImporter;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment