當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript compiler-cli.performCompilation函數代碼示例

本文整理匯總了TypeScript中@angular/compiler-cli.performCompilation函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript performCompilation函數的具體用法?TypeScript performCompilation怎麽用?TypeScript performCompilation使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了performCompilation函數的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: compileAndCheck

 function compileAndCheck(
     mockDirs: {[fileName: string]: string}[],
     overrideOptions: ng.CompilerOptions = {}): ng.Diagnostics {
   const fileNames: string[] = [];
   mockDirs.forEach((dir) => {
     Object.keys(dir).forEach((fileName) => {
       if (fileName.endsWith('.ts')) {
         fileNames.push(path.resolve(basePath, fileName));
       }
       write(fileName, dir[fileName]);
     });
   });
   const options: ng.CompilerOptions = {
     basePath,
     'experimentalDecorators': true,
     'skipLibCheck': true,
     'strict': true,
     'types': [],
     'outDir': path.resolve(basePath, 'built'),
     'rootDir': basePath,
     'baseUrl': basePath,
     'declaration': true,
     'target': ts.ScriptTarget.ES5,
     'module': ts.ModuleKind.ES2015,
     'moduleResolution': ts.ModuleResolutionKind.NodeJs,
     'lib': [
       path.resolve(basePath, 'node_modules/typescript/lib/lib.es6.d.ts'),
       path.resolve(basePath, 'node_modules/typescript/lib/lib.dom.d.ts')
     ],
     'typeRoots': [path.resolve(basePath, 'node_modules/@types')], ...overrideOptions
   };
   const {diagnostics} = ng.performCompilation({rootNames: fileNames, options});
   return diagnostics;
 }
開發者ID:MarkPieszak,項目名稱:angular,代碼行數:34,代碼來源:check_types_spec.ts

示例2: main

function main(args: string[]) {
  const project = args[1];
  const [{options: tsOptions, bazelOpts, files, config}] = parseTsconfig(project);
  const {basePath} = calcProjectFileAndBasePath(project);
  const ngOptions = createNgCompilerOptions(basePath, config, tsOptions);

  const {diagnostics} = performCompilation(files, ngOptions);
  if (diagnostics.length) {
    console.error(formatDiagnostics(ngOptions, diagnostics));
  }
  return diagnostics.some(d => d.category === ts.DiagnosticCategory.Error) ? 1 : 0;
}
開發者ID:DanielKucal,項目名稱:angular,代碼行數:12,代碼來源:index.ts

示例3: compileAndCheck

 function compileAndCheck(
     mockDirs: MockFiles[], overrideOptions: ng.CompilerOptions = {}): ng.Diagnostics {
   testSupport.writeFiles(...mockDirs);
   const fileNames: string[] = [];
   mockDirs.forEach((dir) => {
     Object.keys(dir).forEach((fileName) => {
       if (fileName.endsWith('.ts')) {
         fileNames.push(path.resolve(testSupport.basePath, fileName));
       }
     });
   });
   const options = testSupport.createCompilerOptions(overrideOptions);
   const {diagnostics} = ng.performCompilation({rootNames: fileNames, options});
   return diagnostics;
 }
開發者ID:robwormald,項目名稱:angular,代碼行數:15,代碼來源:check_types_spec.ts

示例4: main

function main(args: string[]) {
  const [{options, bazelOpts, files, config}] = parseTsconfig(args[1]);
  const ngOptions: {expectedOut: string[]} = (config as any).angularCompilerOptions;

  const parsedArgs = require('minimist')(args);
  const project = parsedArgs.p || parsedArgs.project || '.';

  const projectDir = fs.lstatSync(project).isFile() ? path.dirname(project) : project;

  // file names in tsconfig are resolved relative to this absolute path
  const basePath = path.resolve(process.cwd(), projectDir);
  const result = performCompilation(basePath, files, options, ngOptions, undefined);

  if (result === 0) {
    // Ensure that expected output files exist.
    if (ngOptions && ngOptions.expectedOut) {
      for (const out of ngOptions.expectedOut) {
        fs.appendFileSync(out, '', 'utf-8');
      }
    }
  }

  return result;
}
開發者ID:fourcube,項目名稱:angular,代碼行數:24,代碼來源:index.ts

示例5: compile


//.........這裏部分代碼省略.........
    try {
      const sourceFile = ngHost.getSourceFile(importedFilePath, ts.ScriptTarget.Latest);
      if (sourceFile && sourceFile.moduleName) {
        return sourceFile.moduleName;
      }
    } catch (err) {
      // File does not exist or parse error. Ignore this case and continue onto the
      // other methods of resolving the module below.
    }
    if ((compilerOpts.module === ts.ModuleKind.UMD || compilerOpts.module === ts.ModuleKind.AMD) &&
        ngHost.amdModuleName) {
      return ngHost.amdModuleName({ fileName: importedFilePath } as ts.SourceFile);
    }
    const result = relativeToRootDirs(importedFilePath, compilerOpts.rootDirs).replace(EXT, '');
    if (result.startsWith(NODE_MODULES)) {
      return result.substr(NODE_MODULES.length);
    }
    return bazelOpts.workspaceName + '/' + result;
  }

  ngHost.toSummaryFileName = (fileName: string, referringSrcFileName: string) => path.posix.join(
      bazelOpts.workspaceName,
      relativeToRootDirs(fileName, compilerOpts.rootDirs).replace(EXT, ''));
  if (allDepsCompiledWithBazel) {
    // Note: The default implementation would work as well,
    // but we can be faster as we know how `toSummaryFileName` works.
    // Note: We can't do this if some deps have been compiled with the command line,
    // as that has a different implementation of fromSummaryFileName / toSummaryFileName
    ngHost.fromSummaryFileName = (fileName: string, referringLibFileName: string) => {
      const workspaceRelative = fileName.split('/').splice(1).join('/');
      return resolveNormalizedPath(bazelBin, workspaceRelative) + '.d.ts';
    };
  }
  // Patch a property on the ngHost that allows the resourceNameToModuleName function to
  // report better errors.
  (ngHost as any).reportMissingResource = (resourceName: string) => {
    console.error(`\nAsset not found:\n  ${resourceName}`);
    console.error('Check that it\'s included in the `assets` attribute of the `ng_module` rule.\n');
  };

  const emitCallback: ng.TsEmitCallback = ({
    program,
    targetSourceFile,
    writeFile,
    cancellationToken,
    emitOnlyDtsFiles,
    customTransformers = {},
  }) =>
      tsickle.emitWithTsickle(
          program, bazelHost, bazelHost, compilerOpts, targetSourceFile, writeFile,
          cancellationToken, emitOnlyDtsFiles, {
            beforeTs: customTransformers.before,
            afterTs: customTransformers.after,
          });

  if (!gatherDiagnostics) {
    gatherDiagnostics = (program) =>
        gatherDiagnosticsForInputsOnly(compilerOpts, bazelOpts, program);
  }
  const {diagnostics, emitResult, program} = ng.performCompilation({
    rootNames: files,
    options: compilerOpts,
    host: ngHost, emitCallback,
    mergeEmitResultsCallback: tsickle.mergeEmitResults, gatherDiagnostics
  });
  const tsickleEmitResult = emitResult as tsickle.EmitResult;
  let externs = '/** @externs */\n';
  if (!diagnostics.length) {
    if (bazelOpts.tsickleGenerateExterns) {
      externs += tsickle.getGeneratedExterns(tsickleEmitResult.externs);
    }
    if (bazelOpts.manifest) {
      const manifest = constructManifest(tsickleEmitResult.modulesManifest, bazelHost);
      fs.writeFileSync(bazelOpts.manifest, manifest);
    }
  }

  // If compilation fails unexpectedly, performCompilation returns no program.
  // Make sure not to crash but report the diagnostics.
  if (!program) return {program, diagnostics};

  if (!bazelOpts.nodeModulesPrefix) {
    // If there is no node modules, then metadata.json should be emitted since
    // there is no other way to obtain the information
    generateMetadataJson(program.getTsProgram(), files, compilerOpts.rootDirs, bazelBin, tsHost);
  }

  if (bazelOpts.tsickleExternsPath) {
    // Note: when tsickleExternsPath is provided, we always write a file as a
    // marker that compilation succeeded, even if it's empty (just containing an
    // @externs).
    fs.writeFileSync(bazelOpts.tsickleExternsPath, externs);
  }

  for (let i = 0; i < writtenExpectedOuts.length; i++) {
    originalWriteFile(writtenExpectedOuts[i], '', false);
  }

  return {program, diagnostics};
}
開發者ID:KaneFreeman,項目名稱:angular,代碼行數:101,代碼來源:index.ts

示例6: compile


//.........這裏部分代碼省略.........
    const match = NGC_GEN_FILES.exec(fileName);
    if (match) {
      const [, file, suffix, ext] = match;
      // Performance: skip looking for files other than .d.ts or .ts
      if (ext !== '.ts' && ext !== '.d.ts') return false;
      if (suffix.indexOf('ngstyle') >= 0) {
        // Look for foo.css on disk
        fileName = file;
      } else {
        // Look for foo.d.ts or foo.ts on disk
        fileName = file + (ext || '');
      }
    }
    return tsHost.fileExists(fileName);
  };

  function generatedFileModuleResolver(
      moduleName: string, containingFile: string,
      compilerOptions: ts.CompilerOptions): ts.ResolvedModuleWithFailedLookupLocations {
    return ts.resolveModuleName(
        moduleName, containingFile, compilerOptions, generatedFileModuleResolverHost);
  }

  const bazelHost = new CompilerHost(
      files, compilerOpts, bazelOpts, tsHost, fileLoader, allowNonHermeticReads,
      generatedFileModuleResolver);
  const origBazelHostFileExist = bazelHost.fileExists;
  bazelHost.fileExists = (fileName: string) => {
    if (NGC_ASSETS.test(fileName)) {
      return tsHost.fileExists(fileName);
    }
    return origBazelHostFileExist.call(bazelHost, fileName);
  };

  const ngHost = ng.createCompilerHost({options: compilerOpts, tsHost: bazelHost});

  ngHost.fileNameToModuleName = (importedFilePath: string, containingFilePath: string) =>
      relativeToRootDirs(importedFilePath, compilerOpts.rootDirs).replace(EXT, '');
  ngHost.toSummaryFileName = (fileName: string, referringSrcFileName: string) =>
      ngHost.fileNameToModuleName(fileName, referringSrcFileName);
  if (allDepsCompiledWithBazel) {
    // Note: The default implementation would work as well,
    // but we can be faster as we know how `toSummaryFileName` works.
    // Note: We can't do this if some deps have been compiled with the command line,
    // as that has a different implementation of fromSummaryFileName / toSummaryFileName
    ngHost.fromSummaryFileName = (fileName: string, referringLibFileName: string) =>
        path.resolve(bazelBin, fileName) + '.d.ts';
  }

  const emitCallback: ng.TsEmitCallback = ({
    program,
    targetSourceFile,
    writeFile,
    cancellationToken,
    emitOnlyDtsFiles,
    customTransformers = {},
  }) =>
      tsickle.emitWithTsickle(
          program, bazelHost, bazelHost, compilerOpts, targetSourceFile, writeFile,
          cancellationToken, emitOnlyDtsFiles, {
            beforeTs: customTransformers.before,
            afterTs: [
              ...(customTransformers.after || []),
              fixUmdModuleDeclarations((sf: ts.SourceFile) => bazelHost.amdModuleName(sf)),
            ],
          });

  if (!gatherDiagnostics) {
    gatherDiagnostics = (program) =>
        gatherDiagnosticsForInputsOnly(compilerOpts, bazelOpts, program);
  }
  const {diagnostics, emitResult, program} = ng.performCompilation(
      {rootNames: files, options: compilerOpts, host: ngHost, emitCallback, gatherDiagnostics});
  const tsickleEmitResult = emitResult as tsickle.EmitResult;
  let externs = '/** @externs */\n';
  if (diagnostics.length) {
    console.error(ng.formatDiagnostics(compilerOpts, diagnostics));
  } else {
    if (bazelOpts.tsickleGenerateExterns) {
      externs += tsickle.getGeneratedExterns(tsickleEmitResult.externs);
    }
    if (bazelOpts.manifest) {
      const manifest = constructManifest(tsickleEmitResult.modulesManifest, bazelHost);
      fs.writeFileSync(bazelOpts.manifest, manifest);
    }
  }

  if (bazelOpts.tsickleExternsPath) {
    // Note: when tsickleExternsPath is provided, we always write a file as a
    // marker that compilation succeeded, even if it's empty (just containing an
    // @externs).
    fs.writeFileSync(bazelOpts.tsickleExternsPath, externs);
  }

  for (const missing of writtenExpectedOuts) {
    originalWriteFile(missing, '', false);
  }

  return {program, diagnostics};
}
開發者ID:cartant,項目名稱:angular,代碼行數:101,代碼來源:index.ts


注:本文中的@angular/compiler-cli.performCompilation函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。