How to use the tsconfig.parseFileSync 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 TypeStrong / atom-typescript / dist / main / tsconfig / tsconfig.js View on Github external
var dir = fs.lstatSync(pathOrSrcFile).isDirectory() ? pathOrSrcFile : path.dirname(pathOrSrcFile);
    var projectFile = tsconfig.resolveSync(dir);
    if (!projectFile) {
        throw errorWithDetails(new Error(exports.errors.GET_PROJECT_NO_PROJECT_FOUND), { projectFilePath: fsu.consistentPath(pathOrSrcFile), errorMessage: 'not found' });
    }
    var projectFileDirectory = path.dirname(projectFile) + path.sep;
    var projectSpec;
    var projectFileTextContent;
    try {
        projectFileTextContent = fs.readFileSync(projectFile, 'utf8');
    }
    catch (ex) {
        throw new Error(exports.errors.GET_PROJECT_FAILED_TO_OPEN_PROJECT_FILE);
    }
    try {
        projectSpec = tsconfig.parseFileSync(projectFileTextContent, projectFile, { resolvePaths: false });
    }
    catch (ex) {
        throw errorWithDetails(new Error(exports.errors.GET_PROJECT_JSON_PARSE_FAILED), { projectFilePath: fsu.consistentPath(projectFile), error: ex.message });
    }
    if (!projectSpec.atom) {
        projectSpec.atom = {
            rewriteTsconfig: false,
        };
    }
    if (projectSpec.filesGlob) {
        var prettyJSONProjectSpec = prettyJSON(projectSpec, detectIndent(projectFileTextContent).indent, detectNewline(projectFileTextContent));
        if (prettyJSONProjectSpec !== projectFileTextContent && projectSpec.atom.rewriteTsconfig) {
            fs.writeFileSync(projectFile, prettyJSONProjectSpec);
        }
    }
    var pkg = null;

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