How to use @parcel/ts-utils - 4 common examples

To help you get started, we’ve selected a few @parcel/ts-utils 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 parcel-bundler / parcel / packages / transformers / typescript-types / src / TSTypesTransformer.js View on Github external
);

    let opts: CompilerOptions = {
      ...config,
      // Always emit output
      noEmit: false,
      noEmitOnError: false,
      declaration: true,
      declarationMap: true,
      isolatedModules: false,
      emitDeclarationOnly: true,
      outFile: 'index.d.ts',
      moduleResolution: ts.ModuleResolutionKind.NodeJs,
    };

    let host = new CompilerHost(options.inputFS, ts);
    // $FlowFixMe
    let program = ts.createProgram([asset.filePath], opts, host);

    let includedFiles = program
      .getSourceFiles()
      .filter(file => path.normalize(file.fileName) !== asset.filePath)
      .map(file => ({filePath: file.fileName}));

    let mainModuleName = path
      .relative(program.getCommonSourceDirectory(), asset.filePath)
      .slice(0, -path.extname(asset.filePath).length);
    let moduleGraph = new TSModuleGraph(ts, mainModuleName);

    program.emit(undefined, undefined, undefined, true, {
      afterDeclarations: [
        // 1. Build module graph
github parcel-bundler / parcel / packages / validators / typescript / src / TypeScriptValidator.js View on Github external
async validate({asset, config, options}) {
    let ts = await options.packageManager.require('typescript', asset.filePath);

    // This should never happen...
    if (!config) return;

    let {baseDir, configHash, tsconfig} = config;
    if (tsconfig && !langServiceCache[configHash]) {
      let parsedCommandLine = ts.parseJsonConfigFileContent(
        tsconfig,
        ts.sys,
        baseDir,
      );

      langServiceCache[configHash] = ts.createLanguageService(
        new LanguageServiceHost(options.inputFS, ts, parsedCommandLine),
        ts.createDocumentRegistry(),
      );
    }

    if (!langServiceCache[configHash]) return;

    const diagnostics = langServiceCache[configHash].getSemanticDiagnostics(
      asset.filePath,
    );

    let validatorResult = {
      warnings: [],
      errors: [],
    };

    if (diagnostics.length > 0) {
github parcel-bundler / parcel / packages / transformers / typescript-tsc / src / TSCTransformer.js View on Github external
async loadConfig({config, options}) {
    await loadTSConfig(config, options);
  },
github parcel-bundler / parcel / packages / transformers / typescript-types / src / TSTypesTransformer.js View on Github external
async loadConfig({config, options}) {
    await loadTSConfig(config, options);
  },

@parcel/ts-utils

MIT
Latest version published 2 months ago

Package Health Score

92 / 100
Full package analysis