Skip to content

Instantly share code, notes, and snippets.

@ArtemAvramenko
Last active December 7, 2015 00:34
Show Gist options
  • Save ArtemAvramenko/aafa156df5a2f8956245 to your computer and use it in GitHub Desktop.
Save ArtemAvramenko/aafa156df5a2f8956245 to your computer and use it in GitHub Desktop.
Shams CommonJS modules
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