import { isNil, isFalse, isNotNil } from '@angular-ru/cdk/utils';

function checkIsNodeEnvironment() {
    if (isNil(require)) {
        throw new Error(`This code can be running only Node.js environments. `);
    }
    return true;
}

checkIsNodeEnvironment();
const path$1 = require('path');
const fs = require('fs');
function resolveTsConfigPath(tsConfigPath, relative) {
    let resolvedPath = path$1.isAbsolute(tsConfigPath)
        ? tsConfigPath
        : path$1.resolve(relative !== null && relative !== void 0 ? relative : '.', tsConfigPath);
    resolvedPath = resolvedPath.endsWith('.json') ? resolvedPath : `${resolvedPath}.json`;
    if (isFalse(fs.existsSync(resolvedPath))) {
        throw new Error(`Not found tsconfig file by path: ${resolvedPath}`);
    }
    return resolvedPath;
}

checkIsNodeEnvironment();
const path = require('path');
function exposeTsCompilerOptionsByTsConfig(tsConfigPath, relative) {
    const resolvedPath = resolveTsConfigPath(tsConfigPath, relative);
    const tsconfig = require(resolvedPath);
    const compilerOptions = tsconfig.compilerOptions;
    const shouldBeDiscoverPathsInParentTsConfig = isNil(compilerOptions === null || compilerOptions === void 0 ? void 0 : compilerOptions.paths) && isNotNil(tsconfig.extends);
    if (shouldBeDiscoverPathsInParentTsConfig) {
        const parentTsConfigPath = path.resolve(path.dirname(resolvedPath), tsconfig.extends);
        return exposeTsCompilerOptionsByTsConfig(parentTsConfigPath);
    }
    return compilerOptions !== null && compilerOptions !== void 0 ? compilerOptions : {};
}

/**
 * Generated bundle index. Do not edit.
 */

export { checkIsNodeEnvironment, exposeTsCompilerOptionsByTsConfig, resolveTsConfigPath };
//# sourceMappingURL=angular-ru-cdk-nodejs.mjs.map
