tslint-to-eslint-config
Version:
Converts your TSLint configuration to the closest reasonable ESLint equivalent.
63 lines • 2.39 kB
JavaScript
;
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.importer = void 0;
const path = __importStar(require("path"));
const utils_1 = require("../utils");
const importer = async (dependencies, moduleName) => {
const pathAttempts = [path.join(dependencies.getCwd(), moduleName), moduleName];
const importFile = async (filePath) => {
if (!filePath.endsWith(".json")) {
return await dependencies.nativeImporter(filePath);
}
if (!(await dependencies.fileSystem.fileExists(filePath))) {
return undefined;
}
const rawJsonContents = await dependencies.fileSystem.readFile(filePath);
if (rawJsonContents instanceof Error) {
return rawJsonContents;
}
try {
return (0, utils_1.parseJson)(rawJsonContents);
}
catch (error) {
return error;
}
};
for (const pathAttempt of pathAttempts) {
try {
const result = await importFile(pathAttempt);
if (result) {
return result;
}
}
catch (_a) { }
}
return new Error(`Could not find '${moduleName}' after trying: ${pathAttempts
.map((attempt) => `'${attempt}'`)
.join(", ")}`);
};
exports.importer = importer;
//# sourceMappingURL=importer.js.map