Created
March 10, 2016 12:49
-
-
Save callumacrae/3a85a09b278af01cb0ac to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'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