-
Notifications
You must be signed in to change notification settings - Fork 2
/
node.js
55 lines (42 loc) · 1.77 KB
/
node.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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
var debug = require('debug')('sass-composer:importer:node');
var path = require('path');
var extend = require('extend');
var resolve = require('resolve');
/**
* Resolve a module or file name using node's resolve method
* @param {Object} ctx
* @param {string} [ctx.entry] The path of the entry file
* @param {string} [ctx.parent] The path of the currently executing file
* @param {string} [ctx.file] The path of the file being resolved
* @param {string} [ctx.contents] The contents of the file being resolved
* @param {function(Error, Object)} done
*/
module.exports = function(ctx, done) {
//we don't need to resolve the entry file because it should already be an actual file
if (!ctx.parent) {
debug('skipped: %s (entry)', ctx.file);
return done(null, ctx);
}
var options = extend({
//start looking in the directory of the "currently executing" stylesheet
basedir: path.resolve(path.dirname(ctx.entry), path.dirname(ctx.parent)),
//look for SASS and CSS files
extensions: ['.scss', '.sass', '.css'],
//allow packages to define a SASS entry file using the "main.scss", "main.sass" or "main.css" keys
packageFilter: function(pkg) {
pkg.main = pkg['main.scss'] || pkg['main.sass'] || pkg['main.css'] || pkg['style'];
return pkg;
}
});
resolve(ctx.file, options, function(err, file) {
if (err) {
var humanError = new Error('Cannot find module "' + ctx.file+ '" from "' + ctx.parent + '"');
humanError.previous = err;
return done(humanError, null);
}
debug('resolved: %s => %s', ctx.file, file);
ctx.original = ctx.file;
ctx.file = file;
done(null, ctx);
});
};