How to use the typescript.sys function in typescript

To help you get started, we’ve selected a few typescript 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 pikapkg / builders / packages / plugin-ts-standard-pkg / src / index.ts View on Github external
const read = tsc.sys.readFile(file);
    // See https://github.com/Microsoft/TypeScript/blob/a757e8428410c2196886776785c16f8f0c2a62d9/src/compiler/sys.ts#L203 :
    // `readFile` returns `undefined` in case the file does not exist!
    if (!read) {
      throw new Error(`ENOENT: no such file or directory, open '${configPath}'`);
    }
    return read;
  });
  // In case of an error, we cannot go further - the config is malformed.
  if (loaded.error) {
    throw new Error(JSON.stringify(loaded.error, null, 4));
  }

  // Second step: Parse the config, resolving all potential references.
  const basePath = path.dirname(configPath); // equal to "getDirectoryPath" from ts, at least in our case.
  const parsedConfig = tsc.parseJsonConfigFileContent(loaded.config, tsc.sys, basePath);
  // In case the config is present, it already contains possibly merged entries from following the
  // 'extends' entry, thus it is not required to follow it manually.
  // This procedure does NOT throw, but generates a list of errors that can/should be evaluated.
  if (parsedConfig.errors.length > 0) {
    const formattedErrors = formatTscParserErrors(parsedConfig.errors);
    throw new Error(`Some errors occurred while attempting to read from ${configPath}: ${formattedErrors}`);
  }
  return parsedConfig.options;
}
github mgechev / ngast / static-reflector-factory.ts View on Github external
const createProgram = (configFile: string, projectDirectory?: string): ts.Program => {
  if (projectDirectory === undefined) {
    projectDirectory = path.dirname(configFile);
  }

  const { config } = ts.readConfigFile(configFile, ts.sys.readFile);
  const parseConfigHost: ts.ParseConfigHost = {
    fileExists: fs.existsSync,
    readDirectory: ts.sys.readDirectory,
    readFile: (file) => fs.readFileSync(file, 'utf8'),
    useCaseSensitiveFileNames: true,
  };
  const parsed = ts.parseJsonConfigFileContent(config, parseConfigHost, projectDirectory);
  const host = ts.createCompilerHost(parsed.options, true);
  const program = ts.createProgram(parsed.fileNames, parsed.options, host);

  return program;
};
github palantir / tslint / src / linter.ts View on Github external
public static createProgram(
        configFile: string,
        projectDirectory: string = path.dirname(configFile),
    ): ts.Program {
        const config = ts.readConfigFile(configFile, ts.sys.readFile);
        if (config.error !== undefined) {
            throw new FatalError(
                ts.formatDiagnostics([config.error], {
                    getCanonicalFileName: f => f,
                    getCurrentDirectory: process.cwd,
                    getNewLine: () => "\n",
                }),
            );
        }
        const parseConfigHost: ts.ParseConfigHost = {
            fileExists: fs.existsSync,
            readDirectory: ts.sys.readDirectory,
            readFile: file => fs.readFileSync(file, "utf8"),
            useCaseSensitiveFileNames: true,
        };
        const parsed = ts.parseJsonConfigFileContent(
github mgechev / ngast / demo / create-program.ts View on Github external
export const createProgramFromTsConfig = (configFile: string): ts.Program => {
  const projectDirectory = dirname(configFile);
  const { config } = ts.readConfigFile(configFile, ts.sys.readFile);

  const parseConfigHost: ts.ParseConfigHost = {
    fileExists: existsSync,
    readDirectory: ts.sys.readDirectory,
    readFile: (file) => readFileSync(file, 'utf8'),
    useCaseSensitiveFileNames: true,
  };
  const parsed = ts.parseJsonConfigFileContent(config, parseConfigHost, projectDirectory);
  parsed.options.baseUrl = parsed.options.baseUrl || projectDirectory;
  normalizeOptions(parsed.options, configFile);
  const host = ts.createCompilerHost(parsed.options, true);
  const program = ts.createProgram(parsed.fileNames, parsed.options, host);

  return program;
};
github artsy / reaction / scripts / find-unused-fields.ts View on Github external
getScriptFileNames: () => sourceFiles,
      getScriptVersion: _ => "0",
      getScriptSnapshot: fileName => {
        if (!fs.existsSync(fileName)) {
          return undefined
        }

        return ts.ScriptSnapshot.fromString(
          fs.readFileSync(fileName).toString()
        )
      },
      getCurrentDirectory: () => process.cwd(),
      getCompilationSettings: () => options,
      getDefaultLibFileName: opts => ts.getDefaultLibFilePath(opts),
      fileExists: ts.sys.fileExists,
      readFile: ts.sys.readFile,
      readDirectory: ts.sys.readDirectory,
    },
    ts.createDocumentRegistry()
  )
}
github Bobris / bobril-build / tscomp.js View on Github external
function reportDiagnostic(diagnostic) {
	var output = "";
	if (diagnostic.file) {
		var loc = diagnostic.file.getLineAndCharacterOfPosition(diagnostic.start);
		output += diagnostic.file.fileName + "(" + (loc.line+1) + "," + (loc.character+1) + "): ";
	}
	var category = ts.DiagnosticCategory[diagnostic.category].toLowerCase();
	output += category + " TS" + diagnostic.code + ": " + ts.flattenDiagnosticMessageText(diagnostic.messageText, ts.sys.newLine) + ts.sys.newLine;
	ts.sys.write(output);
}
github bfwg / angular-spring-starter / frontend / node_modules / @angular / tsc-wrapped / src / compiler_host.js View on Github external
        getCurrentDirectory: function () { return ts.sys.getCurrentDirectory(); },
        getNewLine: function () { return ts.sys.newLine; },
github daviddbarrero / Ionic-4-firebase / node_modules / @angular / compiler-cli / src / perform_watch.js View on Github external
listener(FileChangeEvent.Change, path);
                        break;
                    case 'unlink':
                    case 'add':
                        listener(FileChangeEvent.CreateDelete, path);
                        break;
                    case 'unlinkDir':
                    case 'addDir':
                        listener(FileChangeEvent.CreateDeleteDir, path);
                        break;
                }
            });
            watcher.on('ready', ready);
            return { close: function () { return watcher.close(); }, ready: ready };
        },
        setTimeout: (ts.sys.clearTimeout && ts.sys.setTimeout) || setTimeout,
        clearTimeout: (ts.sys.setTimeout && ts.sys.clearTimeout) || clearTimeout,
    };
}
exports.createPerformWatchHost = createPerformWatchHost;
github microsoft / TypeScript-Sublime-Plugin / clients / sublime / TypeScript / editorServices.js View on Github external
LSHost.prototype.directoryExists = function (path) {
        return ts.sys.directoryExists(path);
    };
    /**