forked from codesandbox/codesandbox-client
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path_prefix.ts
More file actions
39 lines (30 loc) · 770 Bytes
/
_prefix.ts
File metadata and controls
39 lines (30 loc) · 770 Bytes
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
/*---------------------------------------------------------
* Copyright (C) Microsoft Corporation. All rights reserved.
*--------------------------------------------------------*/
'use strict';
interface IModule {
exports: any;
}
interface IModuleMap {
[path: string]: IModule;
}
interface IFactoryFunc {
(require: IFactoryRequireFunc, module: IModule, exports: any): void;
}
interface IFactoryRequireFunc {
(name: string): any;
}
let $map: IModuleMap = {};
function $load(name: string, factory: IFactoryFunc) {
let mod: IModule = {
exports: {}
};
let requireFunc: IFactoryRequireFunc = (mod) => {
if ($map[mod]) {
return $map[mod].exports;
}
return require(mod);
};
factory.call(this, requireFunc, mod, mod.exports);
$map[name] = mod;
}