-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathload.js
38 lines (32 loc) · 923 Bytes
/
load.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
const { Loader } = require('./loader')
const assert = require('nanoassert')
/**
* Load module specified at `target` calling `callback(null, exports)` if the
* target is a node module, `callback(null, archive)` if the target is an
* archive, or `callback(err)` if an error occurs.
* @param {String} target
* @param {?(Object)} opts
* @param {?(Map)} opts.cache
* @param {?(String)} opts.cwd
* @param {?(Object)} opts.storage
* @param {Function} callback
* @return {Target}
*/
function load(target, opts, callback) {
if ('function' === typeof opts) {
callback = opts
}
if (!opts || 'object' !== typeof opts) {
opts = {}
}
opts = Object.assign({ cwd: process.cwd() }, opts) // copy
assert('function' === typeof callback, 'Callback must be a function.')
const loader = new Loader(opts)
return loader.load(target, opts, callback)
}
/**
* Module exports.
*/
module.exports = {
load
}