Comparing version 2.0.0-3 to 2.0.0
@@ -27,3 +27,3 @@ import { LocationInfo } from "./resolver"; | ||
export interface ContainerInternalApi { | ||
resolve(id: Id, previousDependencyPath?: LocationInfo[], previouslySearchedContainers?: string[]): Instance; | ||
resolve(id: Id, previousDependencyPath?: LocationInfo[], previouslySearchedContainers?: string[], previouslyResolvableIds?: Set<Id>): Instance; | ||
getDebugInfo(): DebugInfo; | ||
@@ -30,0 +30,0 @@ visiblePathToContainer(targetContainer: string): string[] | undefined; |
@@ -25,3 +25,3 @@ "use strict"; | ||
const internal = { | ||
resolve(formattedModulePath, previousDependencyPath = [], previouslySearchedContainers = []) { | ||
resolve(formattedModulePath, previousDependencyPath = [], previouslySearchedContainers = [], previouslyResolvableIds = new Set()) { | ||
const fullComponentPath = modules_1.parseModulePath(formattedModulePath); | ||
@@ -41,2 +41,3 @@ const { parentModulePath, componentId } = modules_1.splitModulePath(fullComponentPath); | ||
previouslySearchedContainers, | ||
previouslyResolvableIds, | ||
})[componentId]; | ||
@@ -43,0 +44,0 @@ }, |
@@ -32,3 +32,3 @@ import Visibility from "./visibility"; | ||
} | ||
export { createRootModuleRegistration, createRegistrationApi, cacheInstance, getSubModule, getRegistration, exists, formatModulePath, parseModulePath, splitModulePath, getParentPath, joinModulePath, isPathEqual }; | ||
export { createRootModuleRegistration, createRegistrationApi, cacheInstance, getSubModule, getRegistration, exists, formatModulePath, parseModulePath, splitModulePath, getParentPath, joinModulePath, isPathEqual, getAllResolvableIds }; | ||
declare function createRootModuleRegistration(): ModuleRegistration; | ||
@@ -49,1 +49,2 @@ declare function getSubModule(currentModuleReg: ModuleRegistration, modulePath: ModulePath): ModuleRegistration | undefined; | ||
declare function isPathEqual(modulePath1: ModulePath, modulePath2: ModulePath): boolean; | ||
declare function getAllResolvableIds(mod: Module): Set<Id>; |
@@ -185,1 +185,9 @@ "use strict"; | ||
exports.isPathEqual = isPathEqual; | ||
function getAllResolvableIds(mod) { | ||
const s = new Set(); | ||
Object.getOwnPropertyNames(mod.factories).forEach(id => s.add(id)); | ||
Object.getOwnPropertyNames(mod.instances).forEach(id => s.add(id)); | ||
Object.getOwnPropertyNames(mod.modules).forEach(id => s.add(id)); | ||
return s; | ||
} | ||
exports.getAllResolvableIds = getAllResolvableIds; |
@@ -8,3 +8,3 @@ import { Id, ComponentRegistration, ModuleRegistration, ModulePath, Instance } from "./modules"; | ||
} | ||
export default function createResolver({containerName, forComponent, parentContainer, rootModuleReg, fromModuleReg, previousDependencyPath, previouslySearchedContainers}: { | ||
export default function createResolver({containerName, forComponent, parentContainer, rootModuleReg, fromModuleReg, previousDependencyPath, previouslySearchedContainers, previouslyResolvableIds}: { | ||
containerName: string; | ||
@@ -17,2 +17,3 @@ forComponent: ComponentRegistration; | ||
previouslySearchedContainers: string[]; | ||
previouslyResolvableIds: Set<Id>; | ||
}): Resolver; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
// tslint:disable-next-line no-var-requires | ||
const leven = require("leven"); | ||
const modules_1 = require("./modules"); | ||
const lifetimes_1 = require("./lifetimes"); | ||
const visibility_1 = require("./visibility"); | ||
function createResolver({ containerName, forComponent, parentContainer, rootModuleReg, fromModuleReg, previousDependencyPath = [], previouslySearchedContainers = [], }) { | ||
function createResolver({ containerName, forComponent, parentContainer, rootModuleReg, fromModuleReg, previousDependencyPath = [], previouslySearchedContainers = [], previouslyResolvableIds = new Set(), }) { | ||
const intoModulePath = forComponent.modulePath; | ||
@@ -29,6 +31,13 @@ const isVisibleFrom = visibility_1.forRootModule(rootModuleReg); | ||
]; | ||
const resolvableIds = new Set([ | ||
...modules_1.getAllResolvableIds(fromModuleReg.module), | ||
...previouslyResolvableIds, | ||
]); | ||
if (!parentContainer) { | ||
throw new Error(`Nothing registered for '${formattedModulePath}' in containers: '${searchedContainers.join(" -> ")}'.` + ` Trying to resolve: '${formatDepPath(dependencyPath)}'.`); | ||
const typoSuggestions = getCloselyMatchingIds(id, resolvableIds); | ||
throw new Error(`Nothing registered for '${formattedModulePath}' in containers: '${searchedContainers.join(" -> ")}'.` + | ||
` Trying to resolve: '${formatDepPath(dependencyPath)}'.` + | ||
typoSuggestions); | ||
} | ||
return parentContainer.resolve(id, previousDependencyPath, searchedContainers); | ||
return parentContainer.resolve(id, previousDependencyPath, searchedContainers, resolvableIds); | ||
} | ||
@@ -61,2 +70,3 @@ if (!isVisible(componentModulePath)) { | ||
previouslySearchedContainers, | ||
previouslyResolvableIds, | ||
}); | ||
@@ -79,2 +89,3 @@ } | ||
previouslySearchedContainers, | ||
previouslyResolvableIds, | ||
}); | ||
@@ -107,1 +118,15 @@ const instance = factory(resolver); | ||
} | ||
function getCloselyMatchingIds(id, ids) { | ||
const closeIds = []; | ||
ids.forEach(otherId => { | ||
if (leven(id, otherId) <= 3) { | ||
closeIds.push(otherId); | ||
} | ||
}); | ||
return closeIds.length === 0 | ||
? "" | ||
: " " + | ||
(closeIds.length === 1 | ||
? `Did you mean: ${closeIds[0]}?` | ||
: `Did you mean one of: ${closeIds}?`); | ||
} |
{ | ||
"name": "di-hard", | ||
"version": "2.0.0-3", | ||
"version": "2.0.0", | ||
"description": "Dependency injection", | ||
@@ -41,7 +41,10 @@ "main": "./dist", | ||
"prepush": "npm test", | ||
"prepublish": "npm test && npm run build" | ||
"prepublishOnly": "npm test && npm run build" | ||
}, | ||
"dependencies": {}, | ||
"dependencies": { | ||
"leven": "^2.1.0" | ||
}, | ||
"devDependencies": { | ||
"@mft/eslint-config-momentumft": "^3.1.3", | ||
"@types/leven": "^2.1.1", | ||
"@types/node": "^8.0.34", | ||
@@ -48,0 +51,0 @@ "ava": "^0.22.0", |
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
42289
713
0
1
10
+ Addedleven@^2.1.0
+ Addedleven@2.1.0(transitive)