From 84f30d7a7f985aacf880464343607b75d666550e Mon Sep 17 00:00:00 2001 From: Dexter Miguel Date: Mon, 5 Oct 2015 23:22:15 -0400 Subject: [PATCH] Lazy loading of imported packages has been implemented --- gulpfile.js | 4 ++-- index.js | 8 ++++++-- tests/nwire.js | 6 +++--- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/gulpfile.js b/gulpfile.js index 27f3243..d5e91ff 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -11,5 +11,5 @@ gulp.task('test', function() { }); gulp.task('watch:test', function(){ - gulp.watch('index.js', ["test"]); -}); \ No newline at end of file + gulp.watch(['index.js', "tests/**/*"], ["test"]); +}); diff --git a/index.js b/index.js index d42f4cf..b36f14e 100644 --- a/index.js +++ b/index.js @@ -64,7 +64,11 @@ module.exports = function nwire(config, callback) { if (!skipNeeds) { self.packages[dependencyName] = load(dependencyName, skip); - imports[dependencyName] = self.packages[dependencyName]; + Object.defineProperty(imports, dependencyName, { + get: function(){ + return self.packages[dependencyName]; + } + }); } }); @@ -91,4 +95,4 @@ module.exports = function nwire(config, callback) { if (!callback) throw err; callback(err); } -} \ No newline at end of file +} diff --git a/tests/nwire.js b/tests/nwire.js index 75eca99..569c498 100644 --- a/tests/nwire.js +++ b/tests/nwire.js @@ -81,9 +81,9 @@ describe('nwire application', function() { }); describe('leech package', function(){ - it('has a consumed package', function(){ + it('should not have packages', function(){ var app = wire(configurationFixture); - expect(_.size(app.packages.leech.imports)).to.equal(1); + expect(_.size(app.packages.leech.imports)).to.equal(0); }); it('has the consumed seed package', function(){ @@ -100,4 +100,4 @@ describe('leech package', function(){ var app = wire(circularConfigurationFixture); expect(app.packages.leech.imports.seed.dummyFn).to.not.be.undefined; }); -}); \ No newline at end of file +});