Comparing version 2.1.0 to 3.0.0
14
index.js
@@ -5,2 +5,4 @@ const Module = require('module'); | ||
const mappings = new Map(); | ||
const namespaceMappings = new Map(); | ||
const path = require('path'); | ||
@@ -14,2 +16,11 @@ Module._load = function(moduleName, module) { | ||
} | ||
if (moduleName.indexOf('::') > -1) { | ||
console.log('from the _load cwd', process.cwd()); | ||
console.log('from the _load __dirname', __dirname); | ||
const [ namespace, moduleToLoad ] = moduleName.split('::'); | ||
console.log('namespace', namespace); | ||
const modulePath = path.join(process.cwd(), namespaceMappings.get(namespace), moduleToLoad); | ||
console.log('modulePath', modulePath); | ||
return defaultLoad(modulePath); | ||
} | ||
if (mappings.has(moduleName)) { | ||
@@ -39,3 +50,6 @@ return mappings.get(moduleName); | ||
Module._load = defaultLoad; | ||
}, | ||
namespace: function(name, pathStart) { | ||
namespaceMappings.set(name, pathStart); | ||
} | ||
} |
{ | ||
"name": "fuxor", | ||
"version": "2.1.0", | ||
"version": "3.0.0", | ||
"description": "Simple dependency injection by overriding require", | ||
@@ -9,2 +9,5 @@ "main": "index.js", | ||
"dependency inject", | ||
"dependency injection", | ||
"namespacing", | ||
"namespace", | ||
"ioc", | ||
@@ -11,0 +14,0 @@ "test", |
@@ -158,1 +158,14 @@ const test = require('tap').test; | ||
}); | ||
test('Add folder to namespace', function (t) { | ||
fuxor.clear(); | ||
fuxor.namespace('app', './test/app'); | ||
const app = require('app::sample'); | ||
const nested = require('app::nested'); | ||
const example = require('app::nested/example'); | ||
t.ok(app() === true, 'method should return'); | ||
t.ok(nested() === false, 'module should be the correct one'); | ||
t.ok(example() === 'example', 'method should return'); | ||
t.end(); | ||
}); |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
8538
13
213