UNPKG

@omlet/cli

Version:

Omlet (https://omlet.dev) is a component analytics tool that uses a CLI to scan your codebase to detect components and their usage. Get real usage insights from customizable charts to measure adoption across all projects and identify opportunities to impr

59 lines (58 loc) 2.02 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.PathResolutionMap = exports.PathResolutionEntryType = void 0; var PathResolutionEntryType; (function (PathResolutionEntryType) { PathResolutionEntryType["Export"] = "export"; PathResolutionEntryType["Alias"] = "alias"; PathResolutionEntryType["Import"] = "import"; })(PathResolutionEntryType = exports.PathResolutionEntryType || (exports.PathResolutionEntryType = {})); class PathResolutionMap { constructor(entryType) { this.aliases = {}; this.entryType = entryType; this.entrySourcePaths = {}; } hasEntry(name) { var _a, _b; return ((_b = (_a = this.aliases[name]) === null || _a === void 0 ? void 0 : _a.size) !== null && _b !== void 0 ? _b : 0) > 0; } getEntry(name) { const patterns = this.aliases[name]; if (patterns) { return this.aliases[name] && { name, patterns: [...this.aliases[name]], type: this.entryType, sourcePath: this.entrySourcePaths[name], }; } } entries() { return Object.entries(this.aliases).map(([name, patterns]) => ({ name, patterns: [...patterns], sourcePath: this.entrySourcePaths[name], type: this.entryType, })); } addMapping(name, paths, sourcePath) { if (!this.aliases[name]) { this.aliases[name] = new Set(); } this.entrySourcePaths[name] = sourcePath; const pathArray = Array.isArray(paths) ? paths : [paths]; for (const p of pathArray) { this.aliases[name].add(p); } } merge(...others) { for (const config of others) { for (const entry of config.entries()) { this.addMapping(entry.name, entry.patterns, entry.sourcePath); } } return this; } } exports.PathResolutionMap = PathResolutionMap;