-
Notifications
You must be signed in to change notification settings - Fork 9
/
index.js
34 lines (26 loc) · 852 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
var path = require('path');
var findParentDir = require('find-parent-dir');
var fs = require('fs');
function resolve(targetUrl, source) {
var packageRoot = findParentDir.sync(source, 'node_modules');
if (!packageRoot) {
return null;
}
var filePath = path.resolve(packageRoot, 'node_modules', targetUrl);
var isPotentiallyDirectory = !path.extname(filePath);
if (isPotentiallyDirectory) {
if (fs.existsSync(filePath + '.scss')) {
return filePath + '.scss';
}
if (fs.existsSync(filePath)) {
return path.resolve(filePath, 'index');
}
}
if (fs.existsSync(path.dirname(filePath))) {
return filePath;
}
return resolve(targetUrl, path.dirname(packageRoot));
}
module.exports = function importer (url, prev, done) {
return (url[ 0 ] === '~') ? { file: resolve(url.substr(1), prev) } : null;
};