Last active
December 7, 2015 00:34
-
-
Save ArtemAvramenko/aafa156df5a2f8956245 to your computer and use it in GitHub Desktop.
Shams CommonJS modules
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var module: { exports }; | |
var exports = { | |
sham: (() => { | |
var sham = <{ | |
(moduleName: string): void; | |
modules: { [moduleName: string]: { exports } }; | |
}>(moduleName => { | |
exports = { sham }; | |
module = sham.modules[moduleName] = { exports }; | |
}); | |
sham.modules = {}; | |
return sham; | |
})() | |
}; | |
var require = function (oldRequire: (moduleName: string) => any) { | |
return (moduleName: string) => | |
exports.sham.modules[moduleName].exports || oldRequire(moduleName); | |
} (require); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment