forked from dominictarr/noderify
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpack.js
More file actions
50 lines (47 loc) · 1.17 KB
/
pack.js
File metadata and controls
50 lines (47 loc) · 1.17 KB
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
function prelude (content, deps, entry) {
var cache = {}
function load (file) {
var d = deps[file]
if(cache[file]) return cache[file].exports
if(!d) return require(file)
var fn = content[d[0]] //the actual module
var module = cache[file] = {exports: {}, parent: file !== entry}
cache[file] = module
var resolved = require('path').resolve(file)
var dirname = require('path').dirname(resolved)
fn(
function (m) {
if(!d[1][m]) return require(m)
else return load (d[1][m])
},
module,
module.exports,
dirname,
resolved
)
return cache[file].exports
}
return load(entry)
}
module.exports = function (content, deps, entry) {
return (
'('+prelude.toString()+')('
+ (function () {
var s = '{\n'
for(var k in content) {
s += [
JSON.stringify(k)+':\n',
'function (require, module, exports, __dirname, __filename) {\n',
content[k],
'\n},\n'
].join('')
}
return s+'\n}\n'
})()
+ ',\n'
+ JSON.stringify(deps, null, 2)
+ ',\n'
+ JSON.stringify(entry)
+ ')'
)
}