How to use the tsconfig.resolveSync 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 blakeembrey / typescript-simple-loader / src / typescript-simple-loader.ts View on Github external
function createInstance (loader: WebPackLoader, options: Options): LoaderInstance {
  const context = loader.context
  const rootFile = loader.resourcePath
  const files: FilesMap = {}
  const ignoreWarnings = arrify(options.ignoreWarnings).map(Number)

  // Allow custom TypeScript compilers to be used.
  const TS: typeof ts = require(options.compiler || 'typescript')

  // Allow `configFile` option to override `tsconfig.json` lookup.
  const configFile = options.configFile ?
    resolve(context, options.configFile) :
    tsconfig.resolveSync(context)

  const config = readConfig(configFile, loader, TS)

  // Emit configuration errors.
  config.errors.forEach((error: ts.Diagnostic) => {
    loader.emitError(formatDiagnostic(error, TS))
  })

  const serviceHost: ts.LanguageServiceHost = {
    getScriptFileNames (): string[] {
      // Return an array of all file names. We can't return just the default
      // files because webpack may have traversed through a regular JS file
      // back to a TypeScript file and if we don't have that file in the array,
      // TypeScript will give us a file not found compilation error.
      return config.fileNames.concat(Object.keys(files))
    },
github whitecolor / ts-node-dev / lib / compiler.js View on Github external
init: function(options) {
    var project = options['project']
    compiler.log = options.log
    compiler.tsConfigPath =
      resolveSync(cwd, typeof project === 'string' ? project : undefined) || ''

    var originalJsHandler = require.extensions['.js']
    require.extensions['.ts'] = empty
    require.extensions['.tsx'] = empty
    tmpDir = options['cache-directory']
      ? path.resolve(options['cache-directory'])
      : fs.mkdtempSync(path.join(os.tmpdir(), '.ts-node'))
    var compilerOptionsArg =
      options['compilerOptions'] || options['compiler-options']
    var compilerOptions
    if (compilerOptionsArg) {
      try {
        compilerOptions = JSON.parse(compilerOptionsArg)
      } catch (e) {
        console.log(
          'Could not parse compilerOptions',
github valor-software / ngm-cli / src / utils / submodules-resolution.ts View on Github external
function isModuleRoot(dir: string) {
  if (fs.existsSync(path.join(dir, pkgFileName))) {
    return !!tsconfig.resolveSync(dir);
  }
  return false;
}
github TypeStrong / atom-typescript / dist / main / tsconfig / tsconfig.js View on Github external
function getProjectSync(pathOrSrcFile) {
    if (!fs.existsSync(pathOrSrcFile)) {
        throw new Error(exports.errors.GET_PROJECT_INVALID_PATH);
    }
    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) {
github s-panferov / tygen / packages / docscript-react / ignore / cli / generate.ts View on Github external
export function handler(argv: GenerateCommand) {
	let manifest = resolveManifestSync()
	let tsconfigPath = tsconfig.resolveSync(argv.sourceDir)

	if (!tsconfigPath) {
		throw new Error('Cannot resolve tsconfig.json in sourceDir')
	}

	let { files, compilerOptions } = tsconfig.loadSync(tsconfigPath)

	let tsCompilerOptions = helpers.rawToTsCompilerOptions(compilerOptions, process.cwd(), ts)
	let ctx = helpers.generateFiles(files, manifest.package, tsCompilerOptions)

	ctx.generateForeignModules(argv.deepForeign)

	let writer = new DocWriter(ctx)
	writer.ensureDir(argv.docDir)
	writer
		.writeModules(path.join(argv.docDir, 'generated'), !argv.withoutSearch)

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