Ember Resolver is the default module-based resolver for Ember CLI applications that handles module lookup and dependency resolution. It converts Ember's naming conventions into actual classes, functions, and templates, enabling the framework to resolve dependencies like routes, models, components, and templates across different module systems.
npm install ember-resolverimport Resolver from "ember-resolver";For modular imports:
import Resolver, { ModuleRegistry } from "ember-resolver";For string utilities and configuration:
import { dasherize, classify, underscore, decamelize, setStrings, getStrings, getString } from "ember-resolver/string";CommonJS:
const Resolver = require("ember-resolver");import Resolver from "ember-resolver";
// Create a resolver instance
const resolver = Resolver.create({
namespace: {
modulePrefix: "my-app"
}
});
// Resolve a module by fullName
const componentClass = resolver.resolve("component:my-component");
// Parse Ember naming conventions
const parsedName = resolver.parseName("route:posts/index");
// Returns: { type: "route", name: "posts/index", fullNameWithoutType: "posts/index", ... }
// Static resolver with explicit modules
const StaticResolver = Resolver.withModules({
"my-app/components/hello": HelloComponent,
"my-app/routes/application": ApplicationRoute
});Ember Resolver is built around several key components:
Main module resolution functionality that converts Ember naming conventions into actual module references. Essential for Ember application bootstrapping and dependency injection.
class Resolver {
static create(props: object): Resolver;
static withModules(explicitModules: object): typeof Resolver;
resolve(fullName: string): any;
parseName(fullName: string): ParsedName;
normalize(fullName: string): string;
}
interface ParsedName {
parsedName: true;
fullName: string;
prefix: string;
type: string;
fullNameWithoutType: string;
name: string;
root: object;
resolveMethodName: string;
}Module registry system for managing available modules and providing lookup capabilities. Supports both dynamic RequireJS-based registries and static module collections.
class ModuleRegistry {
constructor(entries?: object): ModuleRegistry;
moduleNames(): string[];
has(moduleName: string): boolean;
get(...args: any[]): any;
}High-performance cached string transformation utilities for converting between different naming conventions used throughout Ember applications.
function dasherize(str: string): string;
function classify(str: string): string;
function underscore(str: string): string;
function decamelize(str: string): string;
function setStrings(strings: object): void;
function getStrings(): object;
function getString(name: string): any;interface Resolver {
moduleBasedResolver: boolean;
pluralizedTypes: Record<string, string>;
moduleNameLookupPatterns: Function[];
addModules(modules: Record<string, unknown>): void;
makeToString(factory: any, fullName: string): string;
shouldWrapInClassFactory(module: any, parsedName: ParsedName): boolean;
pluralize(type: string): string;
prefix(parsedName: ParsedName): string;
findModuleName(parsedName: ParsedName): string;
chooseModuleName(moduleName: string): string;
knownForType(type: string): object;
translateToContainerFullname(type: string, moduleName: string): string;
}