forked from trufflesuite/truffle-migrate
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathresolverintercept.js
33 lines (26 loc) · 1.03 KB
/
resolverintercept.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
function ResolverIntercept(resolver) {
this.resolver = resolver;
this.cache = {};
};
ResolverIntercept.prototype.require = function(import_path) {
// TODO: Using the import path for relative files may result in multiple
// paths for the same file. This could return different objects since it won't be a cache hit.
if (this.cache[import_path]) {
return this.cache[import_path];
}
// Note, will error if nothing is found.
var resolved = this.resolver.require(import_path);
this.cache[import_path] = resolved;
// During migrations, we could be on a network that takes a long time to accept
// transactions (i.e., contract deployment close to block size). Because successful
// migration is more important than wait time in those cases, we'll synchronize "forever".
resolved.synchronization_timeout = 0;
return resolved;
};
ResolverIntercept.prototype.contracts = function() {
var self = this;
return Object.keys(this.cache).map(function(key) {
return self.cache[key];
});
};
module.exports = ResolverIntercept;