Closed ghost closed 11 years ago
LGTM. Only thought I have is that this could be transparent to the end user. Is there any advantage of having them pass in a cache versus simply creating a new cache for every unique invocation of required? That seems to be the real behavior you are going for.
If you build up a dependency graph incrementally for multiple files, the cache should persist across that logical session but not across multiple sessions globally since that could introduce bugs when there are multiple separate instances in the same program. Only the end user knows what the instances are. Another approach would be to not use required(file, cb)
, but instead do:
var r = required()
r.require(file, cb)
where required()
would create the cache.
Instead of using a global to store the cache, these commits let you pass in the cache as an optional parameter. With the global cache, multiple calls to
required()
can interfere even when the bundles should be separate.