-
Notifications
You must be signed in to change notification settings - Fork 8
/
index.js
40 lines (33 loc) · 916 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
35
36
37
38
39
40
'use strict'
var path = require('path')
var callerPath = require('caller-path')
var resolvePath = require('resolve')
function attachCb (promise, cb) {
if (cb) {
promise.then(
function (result) { cb(null, result) },
function (err) { cb(err) }
)
}
return promise
}
module.exports = function load (filename, cb) {
if (typeof filename === 'object' && filename._options) {
return require('./plugin')(filename, cb)
}
var basedir = path.dirname(callerPath())
var resolved = new Promise(function (resolve, reject) {
resolvePath(filename, { basedir: basedir }, function (err, fullpath) {
if (err) return reject(err)
resolve(fullpath)
})
})
return attachCb(resolved.then(require), cb)
}
Object.defineProperty(module.exports, 'createStream', {
configurable: true,
enumerable: true,
get: function () {
return require('./plugin').createStream
}
})