-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodule.js
executable file
·52 lines (47 loc) · 1.74 KB
/
module.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
"use strict"
require.$$modules = {}
require.$$current = function () {
var href = window.location.href
var searchIndex = href.indexOf("?")
var hashIndex = href.indexOf("#")
var pathnameEnd = searchIndex > -1 ? searchIndex : hashIndex > -1 ? hashIndex : href.length
try {
throw new Error
} catch (e) {
var error = e
}
var src = error.stack.match(/^(?:(?!^Error|\/module\/module\.js).)*$/m).toString().match(/((?:file|https|http):\/\/.+)(?::\d+){2}/)[1] || href.slice(0, pathnameEnd)
return src.replace(/\.js$/, "")
}
window.module = {
get exports() {
return require.$$modules[require.$$current()]
},
set exports(value) {
require.$$modules[require.$$current()] = value
},
}
function getAlias(path, name) {
return path ? path + '/node_modules/' + name : path;
}
function require(name) {
if (name.indexOf('.') === -1) {
var relative = require.$$current();
var absolute = getAlias(relative, name);
var path = absolute;
while (absolute && !(absolute in require.$$modules)) {
var slashIndex = path.lastIndexOf("/");
path = slashIndex > -1 ? path.slice(0, slashIndex) : null;
absolute = getAlias(path, name);
}
} else {
var relative = require.$$current()
var slashIndex = relative.lastIndexOf("/")
var path = slashIndex > -1 ? relative.slice(0, slashIndex + 1) : "./"
var absolute = (path + name).replace(/\/\.\//g, "/")
var dotdot = /\/[^\/]+?\/\.{2}/
while (dotdot.test(absolute)) absolute = absolute.replace(dotdot, "")
}
if (absolute in require.$$modules) return require.$$modules[absolute]
else throw new Error("Module does not exist: " + absolute)
}