• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

TypeScript typescript.resolveNormalizedPath函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了TypeScript中@bazel/typescript.resolveNormalizedPath函数的典型用法代码示例。如果您正苦于以下问题:TypeScript resolveNormalizedPath函数的具体用法?TypeScript resolveNormalizedPath怎么用?TypeScript resolveNormalizedPath使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了resolveNormalizedPath函数的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。

示例1: generateMetadataJson

/**
 * Generate metadata.json for the specified `files`. By default, metadata.json
 * is only generated by the compiler if --flatModuleOutFile is specified. But
 * if compiled under blaze, we want the metadata to be generated for each
 * Angular component.
 */
function generateMetadataJson(
    program: ts.Program, files: string[], rootDirs: string[], bazelBin: string,
    tsHost: ts.CompilerHost) {
  const collector = new ng.MetadataCollector();
  for (let i = 0; i < files.length; i++) {
    const file = files[i];
    const sourceFile = program.getSourceFile(file);
    if (sourceFile) {
      const metadata = collector.getMetadata(sourceFile);
      if (metadata) {
        const relative = relativeToRootDirs(file, rootDirs);
        const shortPath = relative.replace(EXT, '.metadata.json');
        const outFile = resolveNormalizedPath(bazelBin, shortPath);
        const data = JSON.stringify(metadata);
        tsHost.writeFile(outFile, data, false, undefined, []);
      }
    }
  }
}
开发者ID:KaneFreeman,项目名称:angular,代码行数:25,代码来源:index.ts


示例2: compile

export function compile({allowNonHermeticReads, allDepsCompiledWithBazel = true, compilerOpts,
                         tsHost, bazelOpts, files, inputs, expectedOuts, gatherDiagnostics}: {
  allowNonHermeticReads: boolean,
  allDepsCompiledWithBazel?: boolean,
  compilerOpts: ng.CompilerOptions,
  tsHost: ts.CompilerHost, inputs?: {[path: string]: string},
  bazelOpts: BazelOptions,
  files: string[],
  expectedOuts: string[], gatherDiagnostics?: (program: ng.Program) => ng.Diagnostics
}): {diagnostics: ng.Diagnostics, program: ng.Program} {
  let fileLoader: FileLoader;

  if (bazelOpts.maxCacheSizeMb !== undefined) {
    const maxCacheSizeBytes = bazelOpts.maxCacheSizeMb * (1 << 20);
    fileCache.setMaxCacheSize(maxCacheSizeBytes);
  } else {
    fileCache.resetMaxCacheSize();
  }

  if (inputs) {
    fileLoader = new CachedFileLoader(fileCache, allowNonHermeticReads);
    // Resolve the inputs to absolute paths to match TypeScript internals
    const resolvedInputs: {[path: string]: string} = {};
    const inputKeys = Object.keys(inputs);
    for (let i = 0; i < inputKeys.length; i++) {
      const key = inputKeys[i];
      resolvedInputs[resolveNormalizedPath(key)] = inputs[key];
    }
    fileCache.updateCache(resolvedInputs);
  } else {
    fileLoader = new UncachedFileLoader();
  }

  if (!bazelOpts.es5Mode) {
    compilerOpts.annotateForClosureCompiler = true;
    compilerOpts.annotationsAs = 'static fields';
  }

  // Detect from compilerOpts whether the entrypoint is being invoked in Ivy mode.
  const isInIvyMode = compilerOpts.enableIvy === 'ngtsc' || compilerOpts.enableIvy === 'tsc';

  // Disable downleveling and Closure annotation if in Ivy mode.
  if (isInIvyMode) {
    // In pass-through mode for TypeScript, we want to turn off decorator transpilation entirely.
    // This causes ngc to be have exactly like tsc.
    if (compilerOpts.enableIvy === 'tsc') {
      compilerOpts.annotateForClosureCompiler = false;
    }
    compilerOpts.annotationsAs = 'decorators';
  }

  if (!compilerOpts.rootDirs) {
    throw new Error('rootDirs is not set!');
  }
  const bazelBin = compilerOpts.rootDirs.find(rootDir => BAZEL_BIN.test(rootDir));
  if (!bazelBin) {
    throw new Error(`Couldn't find bazel bin in the rootDirs: ${compilerOpts.rootDirs}`);
  }

  const writtenExpectedOuts = [...expectedOuts];

  const originalWriteFile = tsHost.writeFile.bind(tsHost);
  tsHost.writeFile =
      (fileName: string, content: string, writeByteOrderMark: boolean,
       onError?: (message: string) => void, sourceFiles?: ts.SourceFile[]) => {
        const relative = relativeToRootDirs(fileName.replace(/\\/g, '/'), [compilerOpts.rootDir]);
        const expectedIdx = writtenExpectedOuts.findIndex(o => o === relative);
        if (expectedIdx >= 0) {
          writtenExpectedOuts.splice(expectedIdx, 1);
          originalWriteFile(fileName, content, writeByteOrderMark, onError, sourceFiles);
        }
      };

  // Patch fileExists when resolving modules, so that CompilerHost can ask TypeScript to
  // resolve non-existing generated files that don't exist on disk, but are
  // synthetic and added to the `programWithStubs` based on real inputs.
  const generatedFileModuleResolverHost = Object.create(tsHost);
  generatedFileModuleResolverHost.fileExists = (fileName: string) => {
    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);
  }
//.........这里部分代码省略.........
开发者ID:KaneFreeman,项目名称:angular,代码行数:101,代码来源:index.ts


示例3: resolveNormalizedPath

 ngHost.fromSummaryFileName = (fileName: string, referringLibFileName: string) => {
   const workspaceRelative = fileName.split('/').splice(1).join('/');
   return resolveNormalizedPath(bazelBin, workspaceRelative) + '.d.ts';
 };
开发者ID:KaneFreeman,项目名称:angular,代码行数:4,代码来源:index.ts


示例4: runOneBuild

export function runOneBuild(args: string[], inputs?: {[path: string]: string}): boolean {
  if (args[0] === '-p') args.shift();
  // Strip leading at-signs, used to indicate a params file
  const project = args[0].replace(/^@+/, '');

  const [parsedOptions, errors] = parseTsconfig(project);
  if (errors && errors.length) {
    console.error(ng.formatDiagnostics(errors));
    return false;
  }
  const {options: tsOptions, bazelOpts, files, config} = parsedOptions;
  const angularCompilerOptions: {[k: string]: unknown} = config['angularCompilerOptions'] || {};

  // Allow Bazel users to control some of the bazel options.
  // Since TypeScript's "extends" mechanism applies only to "compilerOptions"
  // we have to repeat some of their logic to get the user's "angularCompilerOptions".
  if (config['extends']) {
    // Load the user's config file
    // Note: this doesn't handle recursive extends so only a user's top level
    // `angularCompilerOptions` will be considered. As this code is going to be
    // removed with Ivy, the added complication of handling recursive extends
    // is likely not needed.
    let userConfigFile = resolveNormalizedPath(path.dirname(project), config['extends']);
    if (!userConfigFile.endsWith('.json')) userConfigFile += '.json';
    const {config: userConfig, error} = ts.readConfigFile(userConfigFile, ts.sys.readFile);
    if (error) {
      console.error(ng.formatDiagnostics([error]));
      return false;
    }

    // All user angularCompilerOptions values that a user has control
    // over should be collected here
    if (userConfig.angularCompilerOptions) {
      angularCompilerOptions['diagnostics'] =
          angularCompilerOptions['diagnostics'] || userConfig.angularCompilerOptions.diagnostics;
      angularCompilerOptions['trace'] =
          angularCompilerOptions['trace'] || userConfig.angularCompilerOptions.trace;

      angularCompilerOptions['disableExpressionLowering'] =
          angularCompilerOptions['disableExpressionLowering'] ||
          userConfig.angularCompilerOptions.disableExpressionLowering;
      angularCompilerOptions['disableTypeScriptVersionCheck'] =
          angularCompilerOptions['disableTypeScriptVersionCheck'] ||
          userConfig.angularCompilerOptions.disableTypeScriptVersionCheck;

      angularCompilerOptions['i18nOutLocale'] = angularCompilerOptions['i18nOutLocale'] ||
          userConfig.angularCompilerOptions.i18nOutLocale;
      angularCompilerOptions['i18nOutFormat'] = angularCompilerOptions['i18nOutFormat'] ||
          userConfig.angularCompilerOptions.i18nOutFormat;
      angularCompilerOptions['i18nOutFile'] =
          angularCompilerOptions['i18nOutFile'] || userConfig.angularCompilerOptions.i18nOutFile;

      angularCompilerOptions['i18nInFormat'] =
          angularCompilerOptions['i18nInFormat'] || userConfig.angularCompilerOptions.i18nInFormat;
      angularCompilerOptions['i18nInLocale'] =
          angularCompilerOptions['i18nInLocale'] || userConfig.angularCompilerOptions.i18nInLocale;
      angularCompilerOptions['i18nInFile'] =
          angularCompilerOptions['i18nInFile'] || userConfig.angularCompilerOptions.i18nInFile;

      angularCompilerOptions['i18nInMissingTranslations'] =
          angularCompilerOptions['i18nInMissingTranslations'] ||
          userConfig.angularCompilerOptions.i18nInMissingTranslations;
      angularCompilerOptions['i18nUseExternalIds'] = angularCompilerOptions['i18nUseExternalIds'] ||
          userConfig.angularCompilerOptions.i18nUseExternalIds;

      angularCompilerOptions['preserveWhitespaces'] =
          angularCompilerOptions['preserveWhitespaces'] ||
          userConfig.angularCompilerOptions.preserveWhitespaces;

      angularCompilerOptions.createExternalSymbolFactoryReexports =
          angularCompilerOptions.createExternalSymbolFactoryReexports ||
          userConfig.angularCompilerOptions.createExternalSymbolFactoryReexports;
    }
  }

  const expectedOuts = config['angularCompilerOptions']['expectedOut'];

  const {basePath} = ng.calcProjectFileAndBasePath(project);
  const compilerOpts = ng.createNgCompilerOptions(basePath, config, tsOptions);
  const tsHost = ts.createCompilerHost(compilerOpts, true);
  const {diagnostics} = compile({
    allDepsCompiledWithBazel: ALL_DEPS_COMPILED_WITH_BAZEL,
    compilerOpts,
    tsHost,
    bazelOpts,
    files,
    inputs,
    expectedOuts
  });
  if (diagnostics.length) {
    console.error(ng.formatDiagnostics(diagnostics));
  }
  return diagnostics.every(d => d.category !== ts.DiagnosticCategory.Error);
}
开发者ID:marclaval,项目名称:angular,代码行数:94,代码来源:index.ts



注:本文中的@bazel/typescript.resolveNormalizedPath函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
TypeScript typescript.FileCache类代码示例发布时间:2022-05-28
下一篇:
TypeScript typescript.parseTsconfig函数代码示例发布时间:2022-05-28
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap