How to use the tsconfig.readFile function in tsconfig

To help you get started, we’ve selected a few tsconfig examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github mazhlekov / tsc-resolve / build / tsc-resolve.js View on Github external
return tslib_1.__generator(this, function (_a) {
            switch (_a.label) {
                case 0:
                    if (!utils_1.endsWith(tsConfigFilePath, ".json")) {
                        tsConfigFilePath = path.join(tsConfigFilePath, utils_1.CONFIG_FILENAME);
                    }
                    return [4 /*yield*/, tsconfig.readFile(tsConfigFilePath)];
                case 1:
                    config = _a.sent();
                    utils_1.validateTsConfig(config);
                    outDir = path.resolve(path.dirname(tsConfigFilePath), config.compilerOptions.outDir);
                    jsFiles = utils_1.getJSFiles(outDir);
                    if (!jsFiles.length) {
                        throw new Error("No .js files found");
                    }
                    modules = Object.keys(config.compilerOptions.paths);
                    return [4 /*yield*/, Promise.all(jsFiles.map(function (filePath) {
                            var tsModules = [];
                            for (var _i = 0, modules_2 = modules; _i < modules_2.length; _i++) {
                                var moduleName = modules_2[_i];
                                var modulePath = utils_1.rtrim(config.compilerOptions.paths[moduleName][0], "*"); // Remove trailing *s
                                tsModules.push({ name: moduleName, path: modulePath });
                            }
github mazhlekov / tsc-resolve / src / tsc-resolve.ts View on Github external
export async function resolve(tsConfigFilePath: string) {
    if (!endsWith(tsConfigFilePath, ".json")) {
        tsConfigFilePath = path.join(tsConfigFilePath, CONFIG_FILENAME);
    }

    const config: any = await tsconfig.readFile(tsConfigFilePath);
    validateTsConfig(config);

    const outDir = path.resolve(path.dirname(tsConfigFilePath), config.compilerOptions.outDir);

    const jsFiles: string[] = getJSFiles(outDir);
    if (!jsFiles.length) {
        throw new Error("No .js files found");
    }
    const modules = Object.keys(config.compilerOptions.paths);
    await Promise.all(
        jsFiles.map((filePath: string) => {
            const tsModules: ITypescriptModule[] = [];
            for (const moduleName of modules) {
                const modulePath = rtrim(config.compilerOptions.paths[moduleName][0], "*"); // Remove trailing *s
                tsModules.push({ name: moduleName, path: modulePath });
            }

tsconfig

Resole and parse `tsconfig.json`, replicating to TypeScript's behaviour

MIT
Latest version published 7 years ago

Package Health Score

71 / 100
Full package analysis