当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript posix.relative方法代码示例

本文整理汇总了TypeScript中path.posix.relative方法的典型用法代码示例。如果您正苦于以下问题:TypeScript posix.relative方法的具体用法?TypeScript posix.relative怎么用?TypeScript posix.relative使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在path.posix的用法示例。


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

示例1:

        .map(match => {
          const relativePath = path.posix.relative(slashedDirname, match);

          return path.posix.dirname(match) === slashedDirname
            ? `./${relativePath}`
            : relativePath;
        })
开发者ID:Volune,项目名称:jest,代码行数:7,代码来源:helpers.ts

示例2: Buffer

    return this._getBundles().then((bundles) => {
      let sharedDepsBundle = (this.shell)
          ? this.urlFromPath(this.shell)
          : this.sharedBundleUrl;
      let sharedDeps = bundles.get(sharedDepsBundle) || [];
      let promises = [];

      if (this.shell) {
        let shellFile = this.analyzer.getFile(this.shell);
        console.assert(shellFile != null);
        let newShellContent = this._addSharedImportsToShell(bundles);
        shellFile.contents = new Buffer(newShellContent);
      }

      for (let fragment of this.allFragments) {
        let fragmentUrl = this.urlFromPath(fragment);
        let addedImports = (fragment === this.shell && this.shell)
            ? []
            : [path.relative(path.dirname(fragmentUrl), sharedDepsBundle)];
        let excludes = (fragment === this.shell && this.shell)
            ? []
            : sharedDeps.concat(sharedDepsBundle);

        promises.push(new Promise((resolve, reject) => {
          let vulcanize = new Vulcanize({
            abspath: null,
            fsResolver: this.analyzer.resolver,
            addedImports: addedImports,
            stripExcludes: excludes,
            inlineScripts: true,
            inlineCss: true,
            inputUrl: fragmentUrl,
          });
          vulcanize.process(null, (err, doc) => {
            if (err) {
              reject(err);
            } else {
              resolve({
                url: fragment,
                contents: doc,
              });
            }
          });
        }));
      }
      // vulcanize the shared bundle
      if (!this.shell && sharedDeps && sharedDeps.length !== 0) {
        logger.info(`generating shared bundle`);
        promises.push(this._generateSharedBundle(sharedDeps));
      }
      return Promise.all(promises).then((bundles) => {
        // convert {url,contents}[] into a Map
        let contentsMap = new Map();
        for (let bundle of bundles) {
          contentsMap.set(bundle.url, bundle.contents);
        }
        return contentsMap;
      });
    });
开发者ID:honzalo,项目名称:polymer-cli,代码行数:59,代码来源:bundle.ts

示例3: relativeToRootDirs

export function relativeToRootDirs(filePath: string, rootDirs: string[]): string {
  if (!filePath) return filePath;
  // NB: the rootDirs should have been sorted longest-first
  for (let i = 0; i < rootDirs.length; i++) {
    const dir = rootDirs[i];
    const rel = path.posix.relative(dir, filePath);
    if (rel.indexOf('.') != 0) return rel;
  }
  return filePath;
}
开发者ID:KaneFreeman,项目名称:angular,代码行数:10,代码来源:index.ts

示例4: resolveBazelFilePath

/**
 * Resolves a given path to the associated relative path if the current process runs within
 * Bazel. We need to use the wrapped NodeJS resolve logic in order to properly handle the given
 * runfiles files which are only part of the runfile manifest on Windows.
 */
function resolveBazelFilePath(fileName: string): string {
  // If the CLI has been launched through the NodeJS Bazel rules, we need to resolve the
  // actual file paths because otherwise this script won't work on Windows where runfiles
  // are not available in the working directory. In order to resolve the real path for the
  // runfile, we need to use `require.resolve` which handles runfiles properly on Windows.
  if (process.env['BAZEL_TARGET']) {
    return path.posix.relative(process.cwd(), require.resolve(fileName));
  }

  return fileName;
}
开发者ID:foresthz,项目名称:angular,代码行数:16,代码来源:cli.ts

示例5: relativePathBetween

export function relativePathBetween(from: string, to: string): string|null {
  let relative = path.posix.relative(path.dirname(from), to).replace(TS_DTS_EXTENSION, '');

  if (relative === '') {
    return null;
  }

  // path.relative() does not include the leading './'.
  if (!relative.startsWith('.')) {
    relative = `./${relative}`;
  }

  return relative;
}
开发者ID:Polatouche,项目名称:angular,代码行数:14,代码来源:path.ts

示例6: getRelativeUrl

export function getRelativeUrl(
    fromUrl: ConvertedDocumentUrl, toUrl: ConvertedDocumentUrl): string {
  // Error: Expects two package-root-relative URLs to compute a relative path
  if (!fromUrl.startsWith('./') || !toUrl.startsWith('./')) {
    throw new Error(
        `paths relative to package root expected (actual: ` +
        `from="${fromUrl}", to="${toUrl}")`);
  }
  let moduleJsUrl = path.relative(path.dirname(fromUrl), toUrl);
  // Correct URL format to add './' preface if none exists
  if (!moduleJsUrl.startsWith('.') && !moduleJsUrl.startsWith('/')) {
    moduleJsUrl = './' + moduleJsUrl;
  }
  return moduleJsUrl;
}
开发者ID:,项目名称:,代码行数:15,代码来源:

示例7: urlFromPath

export function urlFromPath(root: string, target: string): string {
  target = posixifyPath(target);
  root = posixifyPath(root);

  const relativePath = path.posix.relative(root, target);

  // The startsWith(root) check is important on Windows because of the case
  // where paths have different drive letters.  The startsWith('../') will
  // catch the general not-in-root case.
  if (!target.startsWith(root) || relativePath.startsWith('../')) {
    throw new Error(`target path is not in root: ${target} (${root})`);
  }

  return encodeURI(relativePath);
}
开发者ID:chrisekelley,项目名称:polymer-build,代码行数:15,代码来源:path-transformers.ts

示例8: checkModuleDeps

export function checkModuleDeps(
    sf: ts.SourceFile, tc: ts.TypeChecker, allowedDeps: string[],
    rootDir: string, skipGoogSchemeDepsChecking: boolean,
    ignoredFilesPrefixes: string[] = []): ts.Diagnostic[] {
  function stripExt(fn: string) {
    return fn.replace(/(\.d)?\.tsx?$/, '');
  }
  const allowedMap: {[fileName: string]: boolean} = {};
  for (const d of allowedDeps) allowedMap[stripExt(d)] = true;

  const result: ts.Diagnostic[] = [];
  for (const stmt of sf.statements) {
    if (stmt.kind !== ts.SyntaxKind.ImportDeclaration &&
        stmt.kind !== ts.SyntaxKind.ExportDeclaration) {
      continue;
    }
    const id = stmt as ts.ImportDeclaration | ts.ExportDeclaration;
    const modSpec = id.moduleSpecifier;
    if (!modSpec) continue;  // E.g. a bare "export {x};"

    if (ts.isStringLiteral(modSpec) && modSpec.text.startsWith('goog:') &&
        skipGoogSchemeDepsChecking) {
      continue;
    }

    const sym = tc.getSymbolAtLocation(modSpec);
    if (!sym || !sym.declarations || sym.declarations.length < 1) {
      continue;
    }
    // Module imports can only have one declaration location.
    const declFileName = sym.declarations[0].getSourceFile().fileName;
    if (allowedMap[stripExt(declFileName)]) continue;
    if (ignoredFilesPrefixes.some(p => declFileName.startsWith(p))) continue;
    const importName = path.posix.relative(rootDir, declFileName);
    result.push({
      file: sf,
      start: modSpec.getStart(),
      length: modSpec.getEnd() - modSpec.getStart(),
      messageText: `transitive dependency on ${importName} not allowed. ` +
          `Please add the BUILD target to your rule's deps.`,
      category: ts.DiagnosticCategory.Error,
      // semantics are close enough, needs taze.
      code: TS_ERR_CANNOT_FIND_MODULE,
    });
  }
  return result;
}
开发者ID:ramyothman,项目名称:testdashboard,代码行数:47,代码来源:strict_deps.ts

示例9: urlFromPath

export function urlFromPath(
    root: LocalFsPath, target: LocalFsPath): PackageRelativeUrl {
  const targetPosix = posixifyPath(target);
  const rootPosix = posixifyPath(root);

  const relativePath = path.posix.relative(rootPosix, targetPosix);

  // The startsWith(root) check is important on Windows because of the case
  // where paths have different drive letters.  The startsWith('../') will
  // catch the general not-in-root case.
  if (!targetPosix.startsWith(posixifyPath(root)) ||
      relativePath.startsWith('../')) {
    throw new Error(`target path is not in root: ${target} (${root})`);
  }

  return encodeURI(relativePath) as PackageRelativeUrl;
}
开发者ID:MehdiRaash,项目名称:tools,代码行数:17,代码来源:path-transformers.ts

示例10: generate

  generate(): ts.SourceFile {
    const relativeEntryPoint = './' +
        path.posix.relative(path.posix.dirname(this.flatIndexPath), this.entryPoint)
            .replace(/\.tsx?$/, '');

    const contents = `/**
 * Generated bundle index. Do not edit.
 */

export * from '${relativeEntryPoint}';
`;
    const genFile = ts.createSourceFile(
        this.flatIndexPath, contents, ts.ScriptTarget.ES2015, true, ts.ScriptKind.TS);
    if (this.moduleName !== null) {
      genFile.moduleName = this.moduleName;
    }
    return genFile;
  }
开发者ID:cyrilletuzi,项目名称:angular,代码行数:18,代码来源:flat_index_generator.ts


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