UNPKG

dependency-injection-cat

Version:

DI Cat is a truly clean DI-container, which allows you not to pollute your business logic with decorators from DI/IOC libraries!

41 lines (40 loc) 1.73 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.PathResolverCache = void 0; var PathResolver_1 = require("./PathResolver"); var upath_1 = __importDefault(require("upath")); var fs_1 = __importDefault(require("fs")); var constants_1 = require("./constants"); var PathResolverCache = /** @class */ (function () { function PathResolverCache() { } PathResolverCache.getAbsolutePathWithExtension = function (sourceFilePath, targetPath) { var resolved = PathResolver_1.PathResolver.resolve(sourceFilePath, targetPath); if (!upath_1.default.isAbsolute(resolved)) { return resolved; } var cached = this.cache[resolved]; if (cached !== undefined) { return cached; } var candidatesFilePath = constants_1.extensionsToResolve.map(function (it) { return upath_1.default.resolve("" + resolved + it); }); if (constants_1.extensionsToResolve.includes(upath_1.default.extname(resolved))) { candidatesFilePath.unshift(resolved); } var pathWithExtension = candidatesFilePath.find(function (it) { return fs_1.default.existsSync(it); }); if (pathWithExtension === undefined) { throw new Error("Can not resolve file " + targetPath); } this.cache[resolved] = pathWithExtension; return pathWithExtension; }; PathResolverCache.clearCache = function () { this.cache = {}; }; PathResolverCache.cache = {}; return PathResolverCache; }()); exports.PathResolverCache = PathResolverCache;