read-tsconfig-up
Version:
Find up and read `tsconfig.json` file
35 lines (34 loc) • 1.26 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const path_1 = __importDefault(require("path"));
const find_up_1 = __importDefault(require("find-up"));
const read_tsconfig_1 = __importDefault(require("read-tsconfig"));
function readTsconfigUp(options) {
const opts = Object.assign({}, { cwd: process.cwd() }, options);
return find_up_1.default('tsconfig.json', opts).then((filepath) => {
return read_tsconfig_1.default({ cwd: path_1.default.dirname(filepath) }).then(tsconfig => ({
tsconfig,
path: filepath
}));
});
}
readTsconfigUp.sync = (options) => {
const opts = Object.assign({}, { cwd: process.cwd() }, options);
try {
const filepath = find_up_1.default.sync('tsconfig.json', opts);
const tsconfig = read_tsconfig_1.default.sync({ cwd: path_1.default.dirname(filepath) });
return {
tsconfig,
path: filepath
};
}
catch (error) {
throw error;
}
};
exports.default = readTsconfigUp;
module.exports = readTsconfigUp;
module.exports.default = readTsconfigUp;