数通智联化工云平台
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

82 lines
2.6 KiB

2 years ago
"use strict";
2 years ago
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.getExtensionDescription = exports.ExplorerBase = void 0;
const path_1 = __importDefault(require("path"));
const util_js_1 = require("./util.js");
/**
* @internal
*/
2 years ago
class ExplorerBase {
2 years ago
#loadingMetaConfig = false;
config;
loadCache;
searchCache;
constructor(options) {
this.config = options;
if (options.cache) {
this.loadCache = new Map();
this.searchCache = new Map();
}
this.#validateConfig();
2 years ago
}
2 years ago
set loadingMetaConfig(value) {
this.#loadingMetaConfig = value;
2 years ago
}
2 years ago
#validateConfig() {
const config = this.config;
for (const place of config.searchPlaces) {
const extension = path_1.default.extname(place);
const loader = this.config.loaders[extension || 'noExt'] ??
this.config.loaders['default'];
if (loader === undefined) {
throw new Error(`Missing loader for ${getExtensionDescription(place)}.`);
}
if (typeof loader !== 'function') {
throw new Error(`Loader for ${getExtensionDescription(place)} is not a function: Received ${typeof loader}.`);
}
}
2 years ago
}
2 years ago
clearLoadCache() {
if (this.loadCache) {
this.loadCache.clear();
}
2 years ago
}
2 years ago
clearSearchCache() {
if (this.searchCache) {
this.searchCache.clear();
}
2 years ago
}
2 years ago
clearCaches() {
this.clearLoadCache();
this.clearSearchCache();
2 years ago
}
2 years ago
toCosmiconfigResult(filepath, config) {
if (config === null) {
return null;
}
if (config === undefined) {
return { filepath, config: undefined, isEmpty: true };
}
if (this.config.applyPackagePropertyPathToConfiguration ||
this.#loadingMetaConfig) {
config = (0, util_js_1.getPropertyByPath)(config, this.config.packageProp);
}
if (config === undefined) {
return { filepath, config: undefined, isEmpty: true };
}
return { config, filepath };
2 years ago
}
}
exports.ExplorerBase = ExplorerBase;
2 years ago
/**
* @internal
*/
function getExtensionDescription(extension) {
/* istanbul ignore next -- @preserve */
return extension ? `extension "${extension}"` : 'files without extensions';
2 years ago
}
2 years ago
exports.getExtensionDescription = getExtensionDescription;
2 years ago
//# sourceMappingURL=ExplorerBase.js.map