diff --git a/README.md b/README.md index 403440e..862988e 100644 --- a/README.md +++ b/README.md @@ -43,6 +43,7 @@ $ npm install consign * Test driven * Fast, Light-weight with no external dependencies * Highly configurable + * Passes in relative path to included module as last argument ## Options diff --git a/lib/consign.js b/lib/consign.js index 7265f36..b81a381 100644 --- a/lib/consign.js +++ b/lib/consign.js @@ -240,6 +240,7 @@ Consign.prototype.into = function(object) { for (var a in arguments) { args.push(arguments[a]); } + args.push(this._getRelativeTo(script)); if ('function' === typeof mod) { mod = mod.apply(mod, args); diff --git a/package-lock.json b/package-lock.json index 7e80895..6d233ce 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,7 +1,8 @@ { "name": "consign", - "version": "0.1.6", + "version": "0.1.7", "lockfileVersion": 1, + "requires": true, "dependencies": { "commander": { "version": "2.3.0", @@ -13,7 +14,10 @@ "version": "2.0.0", "resolved": "https://registry.npmjs.org/debug/-/debug-2.0.0.tgz", "integrity": "sha1-ib2d9nMrUSVrxnBTQrugLtEhMe8=", - "dev": true + "dev": true, + "requires": { + "ms": "0.6.2" + } }, "diff": { "version": "1.0.8", @@ -31,7 +35,12 @@ "version": "3.2.3", "resolved": "https://registry.npmjs.org/glob/-/glob-3.2.3.tgz", "integrity": "sha1-4xPusknHr/qlxHUoaw4RW1mDlGc=", - "dev": true + "dev": true, + "requires": { + "graceful-fs": "2.0.3", + "inherits": "2.0.3", + "minimatch": "0.2.14" + } }, "graceful-fs": { "version": "2.0.3", @@ -56,6 +65,10 @@ "resolved": "https://registry.npmjs.org/jade/-/jade-0.26.3.tgz", "integrity": "sha1-jxDXl32NefL2/4YqgbBRPMslaGw=", "dev": true, + "requires": { + "commander": "0.6.1", + "mkdirp": "0.3.0" + }, "dependencies": { "commander": { "version": "0.6.1", @@ -87,7 +100,11 @@ "version": "0.2.14", "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-0.2.14.tgz", "integrity": "sha1-x054BXT2PG+aCQ6Q775u9TpqdWo=", - "dev": true + "dev": true, + "requires": { + "lru-cache": "2.7.3", + "sigmund": "1.0.1" + } }, "minimist": { "version": "0.0.8", @@ -99,13 +116,26 @@ "version": "0.5.0", "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.0.tgz", "integrity": "sha1-HXMHam35hs2TROFecfzAWkyavxI=", - "dev": true + "dev": true, + "requires": { + "minimist": "0.0.8" + } }, "mocha": { "version": "1.21.5", "resolved": "https://registry.npmjs.org/mocha/-/mocha-1.21.5.tgz", "integrity": "sha1-fFiwkXTfl25DSiOx6NY5hz/FKek=", - "dev": true + "dev": true, + "requires": { + "commander": "2.3.0", + "debug": "2.0.0", + "diff": "1.0.8", + "escape-string-regexp": "1.0.2", + "glob": "3.2.3", + "growl": "1.8.1", + "jade": "0.26.3", + "mkdirp": "0.5.0" + } }, "ms": { "version": "0.6.2", diff --git a/test/into.js b/test/into.js index e9e2bad..c2d8627 100644 --- a/test/into.js +++ b/test/into.js @@ -74,5 +74,14 @@ module.exports = function(consign, assert) { assert.equal(app.controllers.one.run, true); }); + it('Should pass in the relative path to the loaded item as the last argument', function() { + var app = {}; + consign(options) + .include('controllers') + .into(app) + ; + + assert.equal(app.controllers.two.relativePath, './controllers/two.js'); + }); }; diff --git a/test/test-app/controllers/two.js b/test/test-app/controllers/two.js index 4b76c5b..996ecaa 100644 --- a/test/test-app/controllers/two.js +++ b/test/test-app/controllers/two.js @@ -6,6 +6,7 @@ * @license MIT */ -module.exports = function(app) { +module.exports = function(app, relativePath) { + if (relativePath) this.relativePath = relativePath; return this; }; \ No newline at end of file